Last commit's cleanup

This commit is contained in:
Jean-Patrick Guerrero 2021-11-30 03:52:18 +01:00
parent 95b0434f95
commit 80b675f817
3 changed files with 14 additions and 9 deletions

View File

@ -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()

View File

@ -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

View File

@ -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("<global size=16><center><b>%s</b></center>", 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("<global size=16><tag name=action color=#fff hovercolor=%s>" ..
"<center><b><action name=ok>OK</action></b></center>", colors.yellow))
end