mirror of
https://github.com/minetest-mods/unified_inventory.git
synced 2024-12-30 20:50:23 +01:00
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the result would be more readable, or less messy, or at least makes the line shorter, assuming it looked like it really needed it to begin with. 2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive string concatenation into tables that then get concated only once, when their containing functions return the final formspec string. 3) In some places in the code, such tables were already being used, and were named "formspec", while others were named "fs". I settled on just one name, "formspec", as it's more readable, if longer. 4) There was a mix of styles of adding items to those tables: * Some places used line after line of `t[#t + 1] = foo/bar/baz`. * Others places used the form `t[1] = foo, t[2] = bar, ...`. * Still others used the form `t[n] = foo, t[n+1] = bar...`, with `n` being increased or reset every so often. Most of them should now be of the third form, with a few of the second.
This commit is contained in:
parent
694553e68b
commit
5ea0208ffe
27
bags.lua
27
bags.lua
@ -8,14 +8,14 @@ License: GPLv3
|
||||
local S = minetest.get_translator("unified_inventory")
|
||||
local F = minetest.formspec_escape
|
||||
local ui = unified_inventory
|
||||
local bags_inv_bg_prefix = "image[0.3,1.5;"..(ui.imgscale*8)..","
|
||||
local bags_inv_bg = "image[0.3,1.5;"..(ui.imgscale*8)..",%f;%s]"
|
||||
|
||||
ui.register_page("bags", {
|
||||
get_formspec = function(player)
|
||||
local player_name = player:get_player_name()
|
||||
return { formspec = table.concat({
|
||||
ui.style_full.standard_inv_bg,
|
||||
bags_inv_bg_prefix..ui.imgscale..";ui_bags_header.png]",
|
||||
string.format(bags_inv_bg, ui.imgscale, "ui_bags_header.png"),
|
||||
"label["..ui.style_full.form_header_x..","..ui.style_full.form_header_y..";" .. F(S("Bags")) .. "]",
|
||||
"button[0.6125,2.75;1.875,0.75;bag1;" .. F(S("Bag @1", 1)) .. "]",
|
||||
"button[3.1125,2.75;1.875,0.75;bag2;" .. F(S("Bag @1", 2)) .. "]",
|
||||
@ -49,30 +49,34 @@ for bag_i = 1, 4 do
|
||||
get_formspec = function(player)
|
||||
local stack = get_player_bag_stack(player, bag_i)
|
||||
local image = stack:get_definition().inventory_image
|
||||
local fs = {
|
||||
local formspec = {
|
||||
ui.style_full.standard_inv_bg,
|
||||
"image[9.2,0.4;1,1;" .. image .. "]",
|
||||
"label[0.3,0.65;" .. F(S("Bag @1", bag_i)) .. "]",
|
||||
"listcolors[#00000000;#00000000]",
|
||||
"listring[current_player;main]",
|
||||
}
|
||||
local n = 6
|
||||
|
||||
local slots = stack:get_definition().groups.bagslots
|
||||
if slots == 8 then
|
||||
fs[#fs + 1] = bags_inv_bg_prefix..ui.imgscale..";ui_bags_inv_small.png]"
|
||||
formspec[n] = string.format(bags_inv_bg, ui.imgscale, "ui_bags_inv_small.png")
|
||||
elseif slots == 16 then
|
||||
fs[#fs + 1] = bags_inv_bg_prefix..(ui.imgscale*2)..";ui_bags_inv_medium.png]"
|
||||
formspec[n] = string.format(bags_inv_bg, ui.imgscale*2, "ui_bags_inv_medium.png")
|
||||
elseif slots == 24 then
|
||||
fs[#fs + 1] = bags_inv_bg_prefix..(ui.imgscale*3)..";ui_bags_inv_large.png]"
|
||||
formspec[n] = string.format(bags_inv_bg, ui.imgscale*3, "ui_bags_inv_large.png")
|
||||
end
|
||||
fs[#fs + 1] = "list[current_player;bag" .. bag_i .. "contents;0.45,1.65;8,3;]"
|
||||
fs[#fs + 1] = "listring[current_name;bag" .. bag_i .. "contents]"
|
||||
formspec[n+1] = "list[current_player;bag" .. bag_i .. "contents;0.45,1.65;8,3;]"
|
||||
formspec[n+2] = "listring[current_name;bag" .. bag_i .. "contents]"
|
||||
n = n + 3
|
||||
|
||||
local player_name = player:get_player_name() -- For if statement.
|
||||
if ui.trash_enabled
|
||||
or ui.is_creative(player_name)
|
||||
or minetest.get_player_privs(player_name).give then
|
||||
fs[#fs + 1] = "image[7.8,0.25;"..ui.imgscale..","..ui.imgscale..";ui_trash_slot.png]"
|
||||
formspec[n] = "image[7.8,0.25;"..ui.imgscale..","..ui.imgscale..";ui_trash_slot.png]"
|
||||
.. "list[detached:trash;main;7.95,0.25;1,1;]"
|
||||
n = n + 1
|
||||
end
|
||||
local inv = player:get_inventory()
|
||||
for i = 1, 4 do
|
||||
@ -89,11 +93,12 @@ for bag_i = 1, 4 do
|
||||
end
|
||||
local img = def.inventory_image
|
||||
local label = F(S("Bag @1", i)) .. "\n" .. used .. "/" .. size
|
||||
fs[#fs + 1] = string.format("image_button[%f,0.4;1,1;%s;bag%i;%s]",
|
||||
formspec[n] = string.format("image_button[%f,0.4;1,1;%s;bag%i;%s]",
|
||||
(i + 1.35)*1.25, img, i, label)
|
||||
n = n + 1
|
||||
end
|
||||
end
|
||||
return { formspec = table.concat(fs) }
|
||||
return { formspec = table.concat(formspec) }
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
87
internal.lua
87
internal.lua
@ -68,7 +68,9 @@ function ui.get_formspec(player, page)
|
||||
|
||||
if ui.is_creative(player_name)
|
||||
and page == "craft" then -- add the "Refill" slot.
|
||||
formspec[n] = "image["..(ui_peruser.craft_x-2.5)..","..(ui_peruser.craft_y+2.5)..";"..ui.imgscale..","..ui.imgscale..";ui_single_slot.png]"
|
||||
formspec[n] = string.format("image[%f,%f;%f,%f;ui_single_slot.png]",
|
||||
ui_peruser.craft_x - 2.5, ui_peruser.craft_y + 2.5,
|
||||
ui.imgscale, ui.imgscale)
|
||||
n = n+1
|
||||
end
|
||||
|
||||
@ -100,21 +102,20 @@ function ui.get_formspec(player, page)
|
||||
|
||||
if def.type == "image" then
|
||||
if (def.condition == nil or def.condition(player) == true) then
|
||||
formspec[n] = "image_button["
|
||||
formspec[n+1] = ( ui_peruser.main_button_x + ui_peruser.btn_spc * (i - 1) - button_col * ui_peruser.btn_spc * 4)
|
||||
formspec[n+2] = ","..(ui_peruser.main_button_y + button_row * ui_peruser.btn_spc)..";"..ui_peruser.btn_size..","..ui_peruser.btn_size..";"
|
||||
formspec[n+3] = F(def.image)..";"
|
||||
formspec[n+4] = F(def.name)..";]"
|
||||
formspec[n+5] = "tooltip["..F(def.name)
|
||||
formspec[n+6] = ";"..(def.tooltip or "").."]"
|
||||
n = n+7
|
||||
formspec[n] = string.format("image_button[%f,%f;%f,%f;%s;%s;]",
|
||||
ui_peruser.main_button_x + ui_peruser.btn_spc * (i - 1) - button_col * ui_peruser.btn_spc * 4,
|
||||
ui_peruser.main_button_y + button_row * ui_peruser.btn_spc,
|
||||
ui_peruser.btn_size,ui_peruser.btn_size,
|
||||
F(def.image),
|
||||
F(def.name))
|
||||
formspec[n+1] = "tooltip["..F(def.name)..";"..(def.tooltip or "").."]"
|
||||
n = n+2
|
||||
else
|
||||
formspec[n] = "image["
|
||||
formspec[n+1] = ( ui_peruser.main_button_x + ui_peruser.btn_spc * (i - 1) - button_col * ui_peruser.btn_spc * 4)
|
||||
formspec[n+2] = ","..(ui_peruser.main_button_y + button_row * ui_peruser.btn_spc)..";"..ui_peruser.btn_size..","..ui_peruser.btn_size..";"
|
||||
formspec[n+3] = F(def.image).."^[colorize:#808080:alpha]"
|
||||
n = n+4
|
||||
|
||||
formspec[n] = string.format("image[%f,%f;%f,%f;%s^[colorize:#808080:alpha]",
|
||||
ui_peruser.main_button_x + ui_peruser.btn_spc * (i - 1) - button_col * ui_peruser.btn_spc * 4,
|
||||
ui_peruser.main_button_y + button_row * ui_peruser.btn_spc,
|
||||
ui_peruser.btn_size,ui_peruser.btn_size,def.image)
|
||||
n = n+1
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -133,23 +134,21 @@ function ui.get_formspec(player, page)
|
||||
-- Search box
|
||||
formspec[n] = "field_close_on_enter[searchbox;false]"
|
||||
|
||||
formspec[n+1] = "field["..ui_peruser.page_buttons_x..","..
|
||||
ui_peruser.page_buttons_y..";"..
|
||||
(ui_peruser.searchwidth - 0.1)..","..
|
||||
ui_peruser.btn_size..";searchbox;;"..
|
||||
F(ui.current_searchbox[player_name]) .. "]"
|
||||
formspec[n+2] = "image_button["..(ui_peruser.page_buttons_x + ui_peruser.searchwidth)..","..
|
||||
ui_peruser.page_buttons_y..";"..
|
||||
ui_peruser.btn_size..","..ui_peruser.btn_size..
|
||||
";ui_search_icon.png;searchbutton;]"..
|
||||
"tooltip[searchbutton;" ..F(S("Search")) .. "]"
|
||||
formspec[n+3] = "image_button["..(ui_peruser.page_buttons_x + ui_peruser.searchwidth + ui_peruser.btn_spc)..","..
|
||||
ui_peruser.page_buttons_y..";"..
|
||||
ui_peruser.btn_size..","..ui_peruser.btn_size..
|
||||
";ui_reset_icon.png;searchresetbutton;]"..
|
||||
"tooltip[searchresetbutton;" ..F(S("Reset search and display everything")) .. "]"
|
||||
formspec[n+1] = string.format("field[%f,%f;%f,%f;searchbox;;%s]",
|
||||
ui_peruser.page_buttons_x, ui_peruser.page_buttons_y,
|
||||
ui_peruser.searchwidth - 0.1, ui_peruser.btn_size,
|
||||
F(ui.current_searchbox[player_name]))
|
||||
formspec[n+2] = string.format("image_button[%f,%f;%f,%f;ui_search_icon.png;searchbutton;]",
|
||||
ui_peruser.page_buttons_x + ui_peruser.searchwidth, ui_peruser.page_buttons_y,
|
||||
ui_peruser.btn_size,ui_peruser.btn_size)
|
||||
formspec[n+3] = "tooltip[searchbutton;" ..F(S("Search")) .. "]"
|
||||
formspec[n+4] = string.format("image_button[%f,%f;%f,%f;ui_reset_icon.png;searchresetbutton;]",
|
||||
ui_peruser.page_buttons_x + ui_peruser.searchwidth + ui_peruser.btn_spc,
|
||||
ui_peruser.page_buttons_y,
|
||||
ui_peruser.btn_size, ui_peruser.btn_size)
|
||||
formspec[n+5] = "tooltip[searchresetbutton;"..F(S("Reset search and display everything")).."]"
|
||||
|
||||
n = n + 4
|
||||
n = n + 6
|
||||
|
||||
-- Controls to flip items pages
|
||||
|
||||
@ -169,15 +168,14 @@ function ui.get_formspec(player, page)
|
||||
|
||||
local bn = 0
|
||||
for _, b in pairs(btnlist) do
|
||||
formspec[n] = "image_button["..
|
||||
(ui_peruser.page_buttons_x + ui_peruser.btn_spc*bn)..","..
|
||||
(ui_peruser.page_buttons_y + ui_peruser.btn_spc)..";"..
|
||||
ui_peruser.btn_size..","..
|
||||
ui_peruser.btn_size..";"..
|
||||
b[1]..";"..b[2]..";]"..
|
||||
"tooltip["..b[2]..";"..F(S(b[3])).."]"
|
||||
formspec[n] = string.format("image_button[%f,%f;%f,%f;%s;%s;]",
|
||||
ui_peruser.page_buttons_x + ui_peruser.btn_spc*bn,
|
||||
ui_peruser.page_buttons_y + ui_peruser.btn_spc,
|
||||
ui_peruser.btn_size, ui_peruser.btn_size,
|
||||
b[1],b[2])
|
||||
formspec[n+1] = "tooltip["..b[2]..";"..F(S(b[3])).."]"
|
||||
bn = bn + 1
|
||||
n = n + 1
|
||||
n = n + 2
|
||||
end
|
||||
|
||||
local no_matches = S("No matching items")
|
||||
@ -230,14 +228,17 @@ function ui.get_formspec(player, page)
|
||||
end
|
||||
end
|
||||
end
|
||||
formspec[n] = "label["..ui_peruser.page_x..","..ui_peruser.form_header_y..";"..F(S("Page")) .. ": "
|
||||
.. S("@1 of @2",page2,pagemax).."]"
|
||||
formspec[n] = string.format("label[%f,%f;%s: %s]",
|
||||
ui_peruser.page_x, ui_peruser.form_header_y,
|
||||
F(S("Page")), S("@1 of @2",page2,pagemax))
|
||||
end
|
||||
n= n+1
|
||||
|
||||
if ui.activefilter[player_name] ~= "" then
|
||||
formspec[n] = "label["..ui_peruser.page_x..","..(ui_peruser.page_y - 0.65)..";" .. F(S("Filter")) .. ":]"
|
||||
formspec[n+1] = "label["..ui_peruser.page_x..","..(ui_peruser.page_y - 0.25)..";"..F(ui.activefilter[player_name]).."]"
|
||||
formspec[n] = string.format("label[%f,%f;%s:]",
|
||||
ui_peruser.page_x, ui_peruser.page_y - 0.65, F(S("Filter")))
|
||||
formspec[n+1] = string.format("label[%f,%f;%s]",
|
||||
ui_peruser.page_x, ui_peruser.page_y - 0.25, F(ui.activefilter[player_name]))
|
||||
end
|
||||
return table.concat(formspec, "")
|
||||
end
|
||||
|
108
register.lua
108
register.lua
@ -173,24 +173,32 @@ ui.register_page("craft", {
|
||||
local craftresultx = craftx + 5
|
||||
|
||||
local player_name = player:get_player_name()
|
||||
local formspec = "image["..craftx..","..crafty..";"..(ui.imgscale*6)..","..(ui.imgscale*3)..";ui_crafting_form.png]"
|
||||
formspec = formspec..perplayer_formspec.standard_inv_bg
|
||||
formspec = formspec.."label["..formheaderx..","..formheadery..";" ..F(S("Crafting")).."]"
|
||||
formspec = formspec.."listcolors[#00000000;#00000000]"
|
||||
formspec = formspec.."list[current_player;craftpreview;"..(craftresultx+0.15)..","..(crafty+0.15)..";1,1;]"
|
||||
formspec = formspec.."list[current_player;craft;"..(craftx+0.15)..","..(crafty+0.15)..";3,3;]"
|
||||
local formspec = {
|
||||
string.format("image[%f,%f;%f,%f;ui_crafting_form.png]", craftx, crafty, ui.imgscale*6, ui.imgscale*3),
|
||||
perplayer_formspec.standard_inv_bg,
|
||||
"label["..formheaderx..","..formheadery..";" ..F(S("Crafting")).."]",
|
||||
"listcolors[#00000000;#00000000]",
|
||||
"list[current_player;craftpreview;"..(craftresultx+0.15)..","..(crafty+0.15)..";1,1;]",
|
||||
"list[current_player;craft;"..(craftx+0.15)..","..(crafty+0.15)..";3,3;]",
|
||||
"listring[current_name;craft]",
|
||||
"listring[current_player;main]"
|
||||
}
|
||||
local n=#formspec+1
|
||||
|
||||
if ui.trash_enabled or ui.is_creative(player_name) or minetest.get_player_privs(player_name).give then
|
||||
formspec = formspec.."label["..(craftx+6.45)..","..(crafty + 2.4)..";" .. F(S("Trash:")) .. "]"
|
||||
formspec = formspec.."image["..(craftx+6.25)..","..(crafty + 2.5)..";"..ui.imgscale..","..ui.imgscale..";ui_trash_slot.png]"
|
||||
formspec = formspec.."list[detached:trash;main;"..(craftx+6.4)..","..(crafty + 2.65)..";1,1;]"
|
||||
formspec[n] = string.format("label[%f,%f;%s]", craftx + 6.45, crafty + 2.4, F(S("Trash:")))
|
||||
formspec[n+1] = string.format("image[%f,%f;%f,%f;ui_trash_slot.png]",
|
||||
craftx+6.25, crafty + 2.5, ui.imgscale, ui.imgscale)
|
||||
formspec[n+2] = string.format("list[detached:trash;main;%f,%f;1,1;]", craftx + 6.4, crafty + 2.65)
|
||||
n=n+3
|
||||
end
|
||||
formspec = formspec.."listring[current_name;craft]"
|
||||
formspec = formspec.."listring[current_player;main]"
|
||||
|
||||
if ui.is_creative(player_name) then
|
||||
formspec = formspec.."label["..(craftx-2.3)..","..(crafty + 2.4)..";" .. F(S("Refill:")) .. "]"
|
||||
formspec = formspec.."list[detached:"..F(player_name).."refill;main;"..(craftx-2.35)..","..(crafty + 2.65)..";1,1;]"
|
||||
formspec[n+1] = string.format("label[%f,%f;%s]", craftx - 2.3, crafty + 2.4,F(S("Refill:")))
|
||||
formspec[n+2] = string.format("list[detached:%s;refill;main;%f,%f;1,1;]",
|
||||
F(player_name), craftx - 2.35, crafty + 2.65)
|
||||
end
|
||||
return {formspec=formspec}
|
||||
return {formspec=table.concat(formspec)}
|
||||
end,
|
||||
})
|
||||
|
||||
@ -273,16 +281,19 @@ ui.register_page("craftguide", {
|
||||
|
||||
local player_name = player:get_player_name()
|
||||
local player_privs = minetest.get_player_privs(player_name)
|
||||
local fs = {
|
||||
local formspec = {
|
||||
perplayer_formspec.standard_inv_bg,
|
||||
"label["..formheaderx..","..formheadery..";" .. F(S("Crafting Guide")) .. "]",
|
||||
"listcolors[#00000000;#00000000]"
|
||||
}
|
||||
|
||||
local item_name = ui.current_item[player_name]
|
||||
if not item_name then
|
||||
return { formspec = table.concat(fs) }
|
||||
return { formspec = table.concat(formspec) }
|
||||
end
|
||||
|
||||
local n = 4
|
||||
|
||||
local item_name_shown
|
||||
if minetest.registered_items[item_name]
|
||||
and minetest.registered_items[item_name].description then
|
||||
@ -304,9 +315,10 @@ ui.register_page("craftguide", {
|
||||
end
|
||||
local has_give = player_privs.give or ui.is_creative(player_name)
|
||||
|
||||
fs[#fs + 1] = "image["..craftarrowx..","..crafty..";1.25,1.25;ui_crafting_arrow.png]"
|
||||
fs[#fs + 1] = string.format("textarea[%f,%f;10,1;;%s: %s;]",
|
||||
formspec[n] = "image["..craftarrowx..","..crafty..";1.25,1.25;ui_crafting_arrow.png]"
|
||||
formspec[n+1] = string.format("textarea[%f,%f;10,1;;%s: %s;]",
|
||||
craftx-2.3, perplayer_formspec.resultstr_y, F(role_text[dir]), item_name_shown)
|
||||
n = n + 2
|
||||
|
||||
local giveme_form = table.concat({
|
||||
"label[".. (give_x+0.1)..",".. (crafty + 2.7) .. ";" .. F(S("Give me:")) .. "]",
|
||||
@ -317,31 +329,33 @@ ui.register_page("craftguide", {
|
||||
|
||||
if not craft then
|
||||
-- No craft recipes available for this item.
|
||||
fs[#fs + 1] = "label["..(craftx+2.5)..","..(crafty+1.5)..";"
|
||||
.. F(no_recipe_text[dir]) .. "]"
|
||||
formspec[n] = string.format("label[%f,%f;%s]", craftx+2.5, crafty+1.5, F(no_recipe_text[dir]))
|
||||
local no_pos = dir == "recipe" and (craftx+2.5) or craftresultx
|
||||
local item_pos = dir == "recipe" and craftresultx or (craftx+2.5)
|
||||
fs[#fs + 1] = "image["..no_pos..","..crafty..";1.2,1.2;ui_no.png]"
|
||||
fs[#fs + 1] = stack_image_button(item_pos, crafty, 1.2, 1.2,
|
||||
formspec[n+1] = "image["..no_pos..","..crafty..";1.2,1.2;ui_no.png]"
|
||||
formspec[n+2] = stack_image_button(item_pos, crafty, 1.2, 1.2,
|
||||
"item_button_" .. other_dir[dir] .. "_", ItemStack(item_name))
|
||||
if has_give then
|
||||
fs[#fs + 1] = giveme_form
|
||||
formspec[n+3] = giveme_form
|
||||
end
|
||||
return { formspec = table.concat(fs) }
|
||||
return { formspec = table.concat(formspec) }
|
||||
else
|
||||
fs[#fs + 1] = stack_image_button(craftresultx, crafty, 1.2, 1.2,
|
||||
formspec[n] = stack_image_button(craftresultx, crafty, 1.2, 1.2,
|
||||
"item_button_" .. rdir .. "_", ItemStack(craft.output))
|
||||
fs[#fs + 1] = stack_image_button(craftx-2.3, crafty, 1.2, 1.2,
|
||||
formspec[n+1] = stack_image_button(craftx-2.3, crafty, 1.2, 1.2,
|
||||
"item_button_usage_", ItemStack(item_name))
|
||||
n = n + 2
|
||||
end
|
||||
|
||||
local craft_type = ui.registered_craft_types[craft.type] or
|
||||
ui.craft_type_defaults(craft.type, {})
|
||||
if craft_type.icon then
|
||||
fs[#fs + 1] = string.format("image[%f,%f;%f,%f;%s]",
|
||||
formspec[n] = string.format("image[%f,%f;%f,%f;%s]",
|
||||
craftarrowx+0.1, crafty + 0.95, 1, 1, craft_type.icon)
|
||||
n = n + 1
|
||||
end
|
||||
fs[#fs + 1] = "label["..(craftarrowx+0.15)..","..(crafty+0.2)..";" .. F(craft_type.description).."]"
|
||||
formspec[n] = string.format("label[%f,%f;%s]", craftarrowx+0.15, crafty+0.2, F(craft_type.description))
|
||||
n = n + 1
|
||||
|
||||
local display_size = craft_type.dynamic_display_size
|
||||
and craft_type.dynamic_display_size(craft)
|
||||
@ -384,42 +398,50 @@ ui.register_page("craftguide", {
|
||||
local xof = ((fx-1) * of + of) * bspc
|
||||
local yof = ((y-1) * of + 1) * bspc
|
||||
if item then
|
||||
fs[#fs + 1] = stack_image_button(
|
||||
formspec[n] = stack_image_button(
|
||||
xoffset - xof, crafty - 1.25 + yof, bsize, bsize,
|
||||
"item_button_recipe_",
|
||||
ItemStack(item))
|
||||
else
|
||||
-- Fake buttons just to make grid
|
||||
fs[#fs + 1] = string.format("image_button[%f,%f;%f,%f;ui_blank_image.png;;]",
|
||||
formspec[n] = string.format("image_button[%f,%f;%f,%f;ui_blank_image.png;;]",
|
||||
xoffset - xof, crafty - 1.25 + yof, bsize, bsize)
|
||||
end
|
||||
n = n + 1
|
||||
end
|
||||
end
|
||||
else
|
||||
-- Error
|
||||
fs[#fs + 1] = string.format("label[2,%f;%s]",
|
||||
formspec[n] = string.format("label[2,%f;%s]",
|
||||
crafty, F(S("This recipe is too@nlarge to be displayed.")))
|
||||
n = n + 1
|
||||
end
|
||||
|
||||
if craft_type.uses_crafting_grid and display_size.width <= 3 then
|
||||
fs[#fs + 1] = "label["..(give_x+0.1)..",".. (crafty + 1.7) .. ";" .. F(S("To craft grid:")) .. "]"
|
||||
.. "button[".. (give_x)..",".. (crafty + 1.9) .. ";0.75,0.5;craftguide_craft_1;1]"
|
||||
.. "button[".. (give_x+0.8)..",".. (crafty + 1.9) .. ";0.75,0.5;craftguide_craft_10;10]"
|
||||
.. "button[".. (give_x+1.6)..",".. (crafty + 1.9) .. ";0.75,0.5;craftguide_craft_max;" .. F(S("All")) .. "]"
|
||||
formspec[n] = "label["..(give_x+0.1)..",".. (crafty + 1.7) .. ";" .. F(S("To craft grid:")) .. "]"
|
||||
formspec[n+1] = "button[".. (give_x)..",".. (crafty + 1.9) .. ";0.75,0.5;craftguide_craft_1;1]"
|
||||
formspec[n+2] = "button[".. (give_x+0.8)..",".. (crafty + 1.9) .. ";0.75,0.5;craftguide_craft_10;10]"
|
||||
formspec[n+3] = "button[".. (give_x+1.6)..",".. (crafty + 1.9) .. ";0.75,0.5;craftguide_craft_max;" .. F(S("All")) .. "]"
|
||||
n = n + 4
|
||||
end
|
||||
|
||||
if has_give then
|
||||
fs[#fs + 1] = giveme_form
|
||||
formspec[n] = giveme_form
|
||||
n = n + 1
|
||||
end
|
||||
|
||||
if alternates and alternates > 1 then
|
||||
fs[#fs + 1] = "label["..(craftx+4).."," .. (crafty + 2.3) .. ";"
|
||||
.. F(S(recipe_text[dir], alternate, alternates)) .. "]"
|
||||
.. "image_button["..(craftarrowx+0.2).."," .. (crafty + 2.6) .. ";1.1,1.1;ui_left_icon.png;alternate_prev;]"
|
||||
.. "image_button["..(craftarrowx+1.35).."," .. (crafty + 2.6) .. ";1.1,1.1;ui_right_icon.png;alternate;]"
|
||||
.. "tooltip[alternate_prev;" .. F(prev_alt_text[dir]) .. "]"
|
||||
.. "tooltip[alternate;" .. F(next_alt_text[dir]) .. "]"
|
||||
formspec[n] = string.format("label[%f,%f;%s]",
|
||||
craftx+4, crafty + 2.3, F(S(recipe_text[dir], alternate, alternates)))
|
||||
formspec[n+1] = string.format("image_button[%f,%f;1.1,1.1;ui_left_icon.png;alternate_prev;]",
|
||||
craftarrowx+0.2, crafty + 2.6)
|
||||
formspec[n+2] = string.format("image_button[%f,%f;1.1,1.1;ui_right_icon.png;alternate;]",
|
||||
craftarrowx+1.35, crafty + 2.6)
|
||||
formspec[n+3] = "tooltip[alternate_prev;" .. F(prev_alt_text[dir]) .. "]"
|
||||
formspec[n+4] = "tooltip[alternate;" .. F(next_alt_text[dir]) .. "]"
|
||||
end
|
||||
return { formspec = table.concat(fs) }
|
||||
|
||||
return { formspec = table.concat(formspec) }
|
||||
end,
|
||||
})
|
||||
|
||||
|
@ -29,21 +29,24 @@ ui.register_page("waypoints", {
|
||||
if not waypoints_temp[player_name] then waypoints_temp[player_name] = {hud = 1} end
|
||||
|
||||
local waypoints = datastorage.get(player_name, "waypoints")
|
||||
local formspec = ui.style_full.standard_inv_bg..
|
||||
"label["..ui.style_full.form_header_x..","..ui.style_full.form_header_y..";" .. F(S("Waypoints")) .. "]"..
|
||||
local formspec = { ui.style_full.standard_inv_bg,
|
||||
string.format("label[%f,%f;%s]",
|
||||
ui.style_full.form_header_x, ui.style_full.form_header_y,
|
||||
F(S("Waypoints"))),
|
||||
"image["..wp_info_x..","..wp_info_y..";1,1;ui_waypoints_icon.png]"
|
||||
}
|
||||
local n=4
|
||||
|
||||
-- Tabs buttons:
|
||||
for i = 1, 5 do
|
||||
formspec = formspec ..
|
||||
"image_button["..ui.style_full.main_button_x..","..
|
||||
(wp_bottom_row - (5-i) * ui.style_full.btn_spc)..";"..
|
||||
ui.style_full.btn_size..","..ui.style_full.btn_size..";" ..
|
||||
(i == waypoints.selected and "ui_blue_icon_background.png^" or "") ..
|
||||
"ui_" .. i .. "_icon.png;" ..
|
||||
"select_waypoint" .. i .. ";]" ..
|
||||
"tooltip[select_waypoint" .. i .. ";"
|
||||
.. S("Select Waypoint #@1", i).."]"
|
||||
local sw="select_waypoint"..i
|
||||
formspec[n] = string.format("image_button[%f,%f;%f,%f;%sui_%i_icon.png;%s;]",
|
||||
ui.style_full.main_button_x, wp_bottom_row - (5-i) * ui.style_full.btn_spc,
|
||||
ui.style_full.btn_size, ui.style_full.btn_size,
|
||||
(i == waypoints.selected) and "ui_blue_icon_background.png^" or "",
|
||||
i, sw)
|
||||
formspec[n+1] = "tooltip["..sw..";"..S("Select Waypoint #@1", i).."]"
|
||||
n = n + 2
|
||||
end
|
||||
|
||||
local i = waypoints.selected or 1
|
||||
@ -63,44 +66,44 @@ ui.register_page("waypoints", {
|
||||
|
||||
local x = 4
|
||||
for _, b in pairs(btnlist) do
|
||||
formspec = formspec ..
|
||||
"image_button["..(wp_buttons_rj - ui.style_full.btn_spc * x)..","..
|
||||
wp_bottom_row..";"..
|
||||
ui.style_full.btn_size..","..ui.style_full.btn_size..";"..
|
||||
b[1]..";"..
|
||||
b[2]..i..";]"..
|
||||
"tooltip["..b[2]..i..";"..F(S(b[3], b[4] or "")).."]"
|
||||
formspec[n] = string.format("image_button[%f,%f;%f,%f;%s;%s%i;]",
|
||||
wp_buttons_rj - ui.style_full.btn_spc * x, wp_bottom_row,
|
||||
ui.style_full.btn_size, ui.style_full.btn_size,
|
||||
b[1], b[2], i)
|
||||
formspec[n+1] = "tooltip["..b[2]..i..";"..F(S(b[3], b[4] or "")).."]"
|
||||
x = x - 1
|
||||
n = n + 2
|
||||
end
|
||||
|
||||
-- Waypoint's info:
|
||||
formspec = formspec.."label["..wp_info_x..","..(wp_info_y+1.1)..";"
|
||||
formspec[n] = "label["..wp_info_x..","..(wp_info_y+1.1)..";"
|
||||
if waypoint.active then
|
||||
formspec = formspec ..F(S("Waypoint active")).."]"
|
||||
formspec[n+1] = F(S("Waypoint active")).."]"
|
||||
else
|
||||
formspec = formspec ..F(S("Waypoint inactive")).."]"
|
||||
formspec[n+1] = F(S("Waypoint inactive")).."]"
|
||||
end
|
||||
n = n + 2
|
||||
|
||||
if temp.edit then
|
||||
formspec = formspec ..
|
||||
"field["..(wp_buttons_rj - wp_edit_w - 0.1)..","..(wp_bottom_row - ui.style_full.btn_spc)..";"..
|
||||
wp_edit_w..","..ui.style_full.btn_size..";rename_box" .. i .. ";;"..
|
||||
(waypoint.name or default_name).."]" ..
|
||||
"image_button["..wp_buttons_rj..","..(wp_bottom_row - ui.style_full.btn_spc)..";"..
|
||||
ui.style_full.btn_size..","..ui.style_full.btn_size..";"..
|
||||
"ui_ok_icon.png;"..
|
||||
"confirm_rename"..i.. ";]"..
|
||||
"tooltip[confirm_rename" .. i .. ";"
|
||||
.. F(S("Finish editing")).."]"
|
||||
formspec[n] = string.format("field[%f,%f;%f,%f;rename_box%i;;%s]",
|
||||
wp_buttons_rj - wp_edit_w - 0.1, wp_bottom_row - ui.style_full.btn_spc,
|
||||
wp_edit_w, ui.style_full.btn_size, i, (waypoint.name or default_name))
|
||||
formspec[n+1] = string.format("image_button[%f,%f;%f,%f;ui_ok_icon.png;confirm_rename%i;]",
|
||||
wp_buttons_rj, wp_bottom_row - ui.style_full.btn_spc,
|
||||
ui.style_full.btn_size, ui.style_full.btn_size, i)
|
||||
formspec[n+2] = "tooltip[confirm_rename"..i..";"..F(S("Finish editing")).."]"
|
||||
n = n + 3
|
||||
end
|
||||
|
||||
formspec = formspec .. "label["..wp_info_x..","..(wp_info_y+1.6)..";"..F(S("World position"))..": " ..
|
||||
minetest.pos_to_string(waypoint.world_pos or vector.new()) .. "]" ..
|
||||
"label["..wp_info_x..","..(wp_info_y+2.10)..";"..F(S("Name"))..": ".. (waypoint.name or default_name) .. "]" ..
|
||||
"label["..wp_info_x..","..(wp_info_y+2.60)..";"..F(S("HUD text color"))..": " ..
|
||||
hud_colors[waypoint.color or 1][3] .. "]"
|
||||
formspec[n] = string.format("label[%f,%f;%s: %s]",
|
||||
wp_info_x, wp_info_y+1.6, F(S("World position")),
|
||||
minetest.pos_to_string(waypoint.world_pos or vector.new()))
|
||||
formspec[n+1] = string.format("label[%f,%f;%s: %s]",
|
||||
wp_info_x, wp_info_y+2.10, F(S("Name")), (waypoint.name or default_name))
|
||||
formspec[n+2] = string.format("label[%f,%f;%s: %s]",
|
||||
wp_info_x, wp_info_y+2.60, F(S("HUD text color")), hud_colors[waypoint.color or 1][3])
|
||||
|
||||
return {formspec=formspec}
|
||||
return {formspec=table.concat(formspec)}
|
||||
end,
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user