From 0032c2783254c69fc6ffe111beca1e50bc0500fe Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Thu, 10 Dec 2020 15:52:14 +0100 Subject: [PATCH] Improve chat message --- init.lua | 85 ++++++++++++++++++++--------------------- locale/craftguide.fr.tr | 2 +- locale/template | 2 +- 3 files changed, 44 insertions(+), 45 deletions(-) diff --git a/init.lua b/init.lua index 5aa9d22..6eaf971 100644 --- a/init.lua +++ b/init.lua @@ -558,6 +558,46 @@ function craftguide.get_search_filters() return search_filters end +local function weird_desc(str) + return not true_str(str) or find(str, "\n") or not find(str, "%u") +end + +local function toupper(str) + return str:gsub("%f[%w]%l", upper):gsub("_", " ") +end + +local function snip(str, limit) + return #str > limit and sprintf("%s...", sub(str, 1, limit - 3)) or str +end + +local function get_desc(item, lang_code) + if sub(item, 1, 1) == "_" then + item = sub(item, 2) + end + + local def = reg_items[item] + + if def then + local desc = def.description + desc = lang_code and translate(lang_code, desc) or desc + + if true_str(desc) then + desc = desc:trim():match("[^\n]*") + + if not find(desc, "%u") then + desc = toupper(desc) + end + + return desc + + elseif true_str(item) then + return toupper(match(item, ":(.*)")) + end + end + + return S("Unknown Item (@1)", item) +end + local function item_has_groups(item_groups, groups) for i = 1, #groups do local group = groups[i] @@ -886,7 +926,7 @@ local function craft_stack(player, pname, data, _f) local count = stackcount * scrbar_val local stack = ItemStack(sprintf("%s %s", stackname, count)) - local message = clr("#ff0", sprintf("%s x %s", count, stackname)) + local message = clr("#ff0", sprintf("%s x %s", count, get_desc(stackname))) if inv:room_for_item("main", stack) then inv:add_item("main", stack) @@ -959,46 +999,6 @@ local function is_fav(favs, query_item) return fav, i end -local function weird_desc(str) - return not true_str(str) or find(str, "\n") or not find(str, "%u") -end - -local function toupper(str) - return str:gsub("%f[%w]%l", upper):gsub("_", " ") -end - -local function snip(str, limit) - return #str > limit and sprintf("%s...", sub(str, 1, limit - 3)) or str -end - -local function get_desc(item, lang_code) - if sub(item, 1, 1) == "_" then - item = sub(item, 2) - end - - local def = reg_items[item] - - if def then - local desc = def.description - desc = lang_code and translate(lang_code, desc) or desc - - if true_str(desc) then - desc = desc:trim():match("[^\n]*") - - if not find(desc, "%u") then - desc = toupper(desc) - end - - return desc - - elseif true_str(item) then - return toupper(match(item, ":(.*)")) - end - end - - return S("Unknown Item (@1)", item) -end - local function get_tooltip(item, info) local tooltip @@ -1393,8 +1393,7 @@ local function get_export_fs(fs, data, panel, is_recipe, is_usage, max_stacks_rc sprintf("scrollbaroptions[min=1;max=%u;smallstep=1]", min(craft_max, stack_max)), fmt("scrollbar", _ROWS + 8.1, _H, 3, 0.35, sprintf("scrbar_%s", name), stack_fs), fmt("button", _ROWS + 8.1, _H + 0.4, 3, 0.7, sprintf("craft_%s", name), - sprintf("%s", stack_fs == 1 and ES"Craft stack" or - sprintf(ES"Craft %u stacks", stack_fs)))) + sprintf("%s", sprintf(ES"Craft %u stack(s)", stack_fs)))) end local function get_rcp_extra(fs, data, panel, is_recipe, is_usage) diff --git a/locale/craftguide.fr.tr b/locale/craftguide.fr.tr index 7c1e950..b961635 100644 --- a/locale/craftguide.fr.tr +++ b/locale/craftguide.fr.tr @@ -62,6 +62,6 @@ Unmark this item=Enlever des favoris. Cannot mark this item. Limit of bookmarks reached.=Impossible de mettre cet item en favori. Limite des favoris atteinte. Only drop if using one of these tools: @1=Tombe seulement si détruit avec un de ces outils : @1 Only drop if using this tool: @1=Tombe seulement si détruit avec cet outil : @1 -Craft this stack=Fabriquer cet objet +Craft @1 stack(s)=Fabriquer @1 objet(s) @1 added in your inventory=@1 mis dans votre inventaire @1 crafted=@1 fabriqué(s) diff --git a/locale/template b/locale/template index 3d77e16..34dba47 100644 --- a/locale/template +++ b/locale/template @@ -62,6 +62,6 @@ Unmark this item= Cannot mark this item. Limit of bookmarks reached.= Only drop if using one of these tools: @1= Only drop if using this tool: @1= -Craft this stack= +Craft @1 stack(s)= @1 added in your inventory= @1 crafted=