From 9971b8c3e66fc83d3488703aa1d1ad34fa4d4e63 Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Mon, 4 Jul 2022 00:54:22 +0200 Subject: [PATCH] Improve get_desc() --- src/gui.lua | 27 ++++++++++++++------------- src/styles.lua | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/gui.lua b/src/gui.lua index af2d6d5..85e74ee 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -41,21 +41,21 @@ local function snip(str, limit) return fmt("%s...", sub(str, 1, limit - 3)) end -local function get_desc(item) +local function get_desc(item, lang_code) if sub(item, 1, 1) == "_" then item = sub(item, 2) end local def = reg_items[item] - if not def then return S("Unknown Item (@1)", item) end - local desc = def.description + local desc = ItemStack(item):get_short_description() + desc = translate(lang_code, desc) if true_str(desc) then - desc = desc:trim():match("[^\n]*"):gsub("_", " ") + desc = desc:trim():gsub("_", " ") if not find(desc, "%u") then desc = toupper(desc) @@ -750,7 +750,7 @@ local function get_inventory_fs(player, data, fs) show_popup(fs, data) end -local function get_tooltip(item, info, pos) +local function get_tooltip(item, info, pos, lang_code) local tooltip if info.groups then @@ -768,7 +768,7 @@ local function get_tooltip(item, info, pos) tooltip = S("Any item belonging to the groups: @1", groupstr) end else - tooltip = info.meta_desc or get_desc(item) + tooltip = info.meta_desc or get_desc(item, lang_code) end local function add(str) @@ -786,7 +786,7 @@ local function get_tooltip(item, info, pos) if info.replace then for i = 1, #info.replace.items do local rpl = ItemStack(info.replace.items[i]):get_name() - local desc = clr("#ff0", get_desc(rpl)) + local desc = clr("#ff0", get_desc(rpl, lang_code)) if info.replace.type == "cooking" then tooltip = add(S("Replaced by @1 on smelting", desc)) @@ -813,12 +813,13 @@ local function get_tooltip(item, info, pos) if several then for i = 1, #info.tools do - names = fmt("%s\t\t- %s\n", names, clr("#ff0", get_desc(info.tools[i]))) + names = fmt("%s\t\t- %s\n", names, clr("#ff0", get_desc(info.tools[i], lang_code))) end tooltip = add(S("Only drop if using one of these tools: @1", sub(names, 1, -2))) else - tooltip = add(S("Only drop if using this tool: @1", clr("#ff0", get_desc(info.tools[1])))) + tooltip = add(S("Only drop if using this tool: @1", + clr("#ff0", get_desc(info.tools[1], lang_code)))) end end @@ -926,7 +927,7 @@ local function get_output_fs(fs, data, rcp, is_recipe, shapeless, right, btn_siz } if next(infos) then - fs(get_tooltip(_name, infos, pos)) + fs(get_tooltip(_name, infos, pos, data.lang_code)) end end @@ -1068,7 +1069,7 @@ local function get_grid_fs(fs, data, rcp, is_recipe) } if next(infos) then - fs(get_tooltip(btn_name, infos)) + fs(get_tooltip(btn_name, infos, nil, data.lang_code)) end end @@ -1181,7 +1182,7 @@ local function get_header(fs, data) fs(fmt("tooltip[exit;%s]", ES"Back to item list")) local desc_lim, name_lim = 34, 35 - local desc = translate(data.lang_code, get_desc(data.query_item)) + local desc = get_desc(data.query_item, data.lang_code) desc = ESC(desc) local tech_name = data.query_item local X = data.inv_width + 0.95 @@ -1405,7 +1406,7 @@ local function get_items_fs(fs, data, player, full_height) fs(fmt("style_type[image_button;fgimg=%s;fgimg_hovered=%s]", hover_texture, PNG.tab_small_hover)) else fs(fmt([[style_type[image_button;bgimg=%s;bgimg_hovered=%s; - bgimg_middle=16,0,-16,-16;padding=-16,0,16,16] ]], hover_texture, PNG.tab_small_hover)) + bgimg_middle=14,0,-14,-14;padding=-14,0,14,14] ]], hover_texture, PNG.tab_small_hover)) end fs(fmt("style_type[image_button;noclip=true;font_size=16;textcolor=%s;content_offset=0;sound=i3_tab]", diff --git a/src/styles.lua b/src/styles.lua index a994703..0ded16b 100644 --- a/src/styles.lua +++ b/src/styles.lua @@ -111,13 +111,13 @@ local fs_elements = { tooltip = "tooltip[%f,%f;%f,%f;%s]", button = "button[%f,%f;%f,%f;%s;%s]", checkbox = "checkbox[%f,%f;%s;%s;%s]", + slot = "image[%f,%f;%f,%f;i3_slot.png]", item_image = "item_image[%f,%f;%f,%f;%s]", hypertext = "hypertext[%f,%f;%f,%f;%s;%s]", bg9 = "background9[%f,%f;%f,%f;%s;false;%u]", scrollbar = "scrollbar[%f,%f;%f,%f;%s;%s;%u]", model = "model[%f,%f;%f,%f;%s;%s;%s;%s;%s;%s;%s]", image_button = "image_button[%f,%f;%f,%f;%s;%s;%s]", - slot = "image[%f,%f;%f,%f;i3_slot.png;60,-60,60,-60]", animated_image = "animated_image[%f,%f;%f,%f;;%s;%u;%u]", item_image_button = "item_image_button[%f,%f;%f,%f;%s;%s;%s]", }