diff --git a/src/callbacks.lua b/src/callbacks.lua index 57c55a1..01fa155 100644 --- a/src/callbacks.lua +++ b/src/callbacks.lua @@ -5,7 +5,7 @@ IMPORT("vec_eq", "vec_round") IMPORT("reg_items", "reg_aliases") IMPORT("sort", "copy", "insert", "remove", "indexof") IMPORT("S", "min", "random", "translate", "ItemStack") -IMPORT("fmt", "find", "match", "sub", "lower", "split") +IMPORT("fmt", "find", "match", "sub", "lower", "split", "toupper") IMPORT("msg", "is_fav", "pos_to_str", "str_to_pos", "add_hud_waypoint", "play_sound", "spawn_item") IMPORT("search", "get_sorting_idx", "sort_inventory", "sort_by_category", "get_recipes", "get_detached_inv") IMPORT("valid_item", "get_stack", "craft_stack", "clean_name", "compressible", "check_privs", "safe_teleport") @@ -184,10 +184,15 @@ i3.new_tab("inventory", { local bagstack = bag:get_stack("main", 1) local meta = bagstack:get_meta() local desc = translate(data.lang_code, bagstack:get_description()) - local str = desc:match("(.*)%(+") or desc + local fill = split(desc, "(")[2] local newname = fields.bag_newname:gsub("([%(%)])", "") + newname = toupper(newname:trim()) - meta:set_string("description", desc:gsub(str:trim(), newname)) + if fill then + newname = fmt("%s (%s", newname, fill) + end + + meta:set_string("description", newname) bag:set_stack("main", 1, bagstack) data.bag = bagstack:to_string() diff --git a/src/common.lua b/src/common.lua index a4c63d5..b4ca38e 100644 --- a/src/common.lua +++ b/src/common.lua @@ -19,7 +19,7 @@ function core.is_creative_enabled(name) return core.check_player_privs(name, {creative = true}) or old_is_creative_enabled(name) end -local S = core.get_translator "i3" +local S = core.get_translator"i3" local ES = function(...) return core.formspec_escape(S(...)) end local function is_num(x) @@ -71,8 +71,8 @@ end local function get_bag_description(data, stack) local desc = translate(data.lang_code, stack:get_description()) - desc = desc:match("(.*)%(+") or desc - desc = ESC(toupper(desc:trim())) + desc = split(desc, "(")[1] or desc + desc = toupper(desc:trim()) return desc end diff --git a/src/gui.lua b/src/gui.lua index e492cfd..1cf22ad 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -403,7 +403,7 @@ local function get_container(fs, data, player, yoffset, ctn_len, award_list, awa local h, m, yy = unpack(v[bag_size]) local bagstack = bag:get_stack("main", 1) - local desc = get_bag_description(data, bagstack) + local desc = ESC(get_bag_description(data, bagstack)) fs("image", 0.5, yextra + 1.85, 0.6, 0.6, PNG.arrow_content) fs(fmt("style[bg_content;bgimg=%s;fgimg=i3_blank.png;bgimg_middle=10,%u;sound=]", @@ -414,12 +414,12 @@ local function get_container(fs, data, player, yoffset, ctn_len, award_list, awa fs("hypertext", 1.3, yextra + 0.8, 4.3, 0.6, "content", fmt("
%s
", desc)) fs("image_button", 5.22, yextra + 0.835, 0.25, 0.25, "", "bag_rename", "") - fs(fmt("tooltip[%s;%s]", "bag_rename", ES"Rename bag")) + fs(fmt("tooltip[%s;%s]", "bag_rename", ES"Rename the bag")) else fs("box", 1.7, yextra + 0.82, 2.6, 0.4, "#707070") fs(fmt("field[1.8,%f;2.5,0.4;bag_newname;;%s]", yextra + 0.82, desc), "field_close_on_enter[bag_newname;false]") - fs("hypertext", 4.4, yextra + 0.88, 0.8, 0.5, "confirm_rename", + fs("hypertext", 4.4, yextra + 0.88, 0.8, 0.6, "confirm_rename", fmt("" .. "
OK
", colors.yellow)) end