mirror of
https://github.com/mt-mods/unifieddyes.git
synced 2024-11-26 01:13:49 +01:00
eliminate most egregious string concats in color select form
build it into a table and return table.concat() instead of using foo = foo..bar or foo = bar..baz..meh everywhere
This commit is contained in:
parent
95f009a282
commit
997d703b94
63
init.lua
63
init.lua
@ -850,7 +850,6 @@ local color_button_size = ";0.75,0.75;"
|
|||||||
|
|
||||||
function unifieddyes.make_colored_square(hexcolor, colorname, showall, creative, painting_with, nodepalette, hp, v2, selindic, inv)
|
function unifieddyes.make_colored_square(hexcolor, colorname, showall, creative, painting_with, nodepalette, hp, v2, selindic, inv)
|
||||||
|
|
||||||
local form = ""
|
|
||||||
local dye = "dye:"..colorname
|
local dye = "dye:"..colorname
|
||||||
|
|
||||||
local overlay = ""
|
local overlay = ""
|
||||||
@ -875,7 +874,7 @@ function unifieddyes.make_colored_square(hexcolor, colorname, showall, creative,
|
|||||||
"tooltip["..colorname..";"..colorname.."]"
|
"tooltip["..colorname..";"..colorname.."]"
|
||||||
end
|
end
|
||||||
|
|
||||||
form = form.."image_button["..
|
local form = "image_button["..
|
||||||
(hp*hps)..","..(v2*vps+vs)..
|
(hp*hps)..","..(v2*vps+vs)..
|
||||||
color_button_size..
|
color_button_size..
|
||||||
"unifieddyes_white_square.png"..colorize..overlay..unavail_overlay..";"..
|
"unifieddyes_white_square.png"..colorize..overlay..unavail_overlay..";"..
|
||||||
@ -887,6 +886,9 @@ end
|
|||||||
|
|
||||||
function unifieddyes.show_airbrush_form(player)
|
function unifieddyes.show_airbrush_form(player)
|
||||||
if not player then return end
|
if not player then return end
|
||||||
|
|
||||||
|
local t = {}
|
||||||
|
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local painting_with = unifieddyes.player_selected_dye[player_name] or unifieddyes.player_current_dye[player_name]
|
local painting_with = unifieddyes.player_selected_dye[player_name] or unifieddyes.player_current_dye[player_name]
|
||||||
local creative = creative and creative.is_enabled_for(player_name)
|
local creative = creative and creative.is_enabled_for(player_name)
|
||||||
@ -894,7 +896,7 @@ function unifieddyes.show_airbrush_form(player)
|
|||||||
local nodepalette = "extended"
|
local nodepalette = "extended"
|
||||||
local showall = unifieddyes.player_showall[player_name]
|
local showall = unifieddyes.player_showall[player_name]
|
||||||
|
|
||||||
local base_form = "size[15,8.5]label[7,-0.25;Select a color:]"
|
t[1] = "size[15,8.5]label[7,-0.25;Select a color:]"
|
||||||
local selindic = "unifieddyes_select_overlay.png^unifieddyes_question.png]"
|
local selindic = "unifieddyes_select_overlay.png^unifieddyes_question.png]"
|
||||||
|
|
||||||
local last_right_click = unifieddyes.player_last_right_clicked[player_name]
|
local last_right_click = unifieddyes.player_last_right_clicked[player_name]
|
||||||
@ -903,15 +905,15 @@ function unifieddyes.show_airbrush_form(player)
|
|||||||
if last_right_click.def.palette == "unifieddyes_palette_colorwallmounted.png" then
|
if last_right_click.def.palette == "unifieddyes_palette_colorwallmounted.png" then
|
||||||
nodepalette = "wallmounted"
|
nodepalette = "wallmounted"
|
||||||
elseif last_right_click.def.palette == "unifieddyes_palette_extended.png" then
|
elseif last_right_click.def.palette == "unifieddyes_palette_extended.png" then
|
||||||
base_form = base_form.."label[0.5,8.25;(Right-clicked a node that supports all 256 colors, showing them all)]"
|
t[#t+1] = "label[0.5,8.25;(Right-clicked a node that supports all 256 colors, showing them all)]"
|
||||||
showall = true
|
showall = true
|
||||||
elseif last_right_click.def.palette ~= "unifieddyes_palette_extended.png" then
|
elseif last_right_click.def.palette ~= "unifieddyes_palette_extended.png" then
|
||||||
nodepalette = "old89"
|
nodepalette = "old89"
|
||||||
elseif not string.find(last_right_click.def.palette, "unifieddyes_palette_") then
|
elseif not string.find(last_right_click.def.palette, "unifieddyes_palette_") then
|
||||||
base_form = base_form.."label[0.5,8.25;(Right-clicked a node not supported by the Airbrush, showing all colors)]"
|
t[#t+1] = "label[0.5,8.25;(Right-clicked a node not supported by the Airbrush, showing all colors)]"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
base_form = base_form.."label[0.5,8.25;(Right-clicked a non-colorable node, showing all colors)]"
|
t[#t+1] = "label[0.5,8.25;(Right-clicked a non-colorable node, showing all colors)]"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -942,7 +944,7 @@ function unifieddyes.show_airbrush_form(player)
|
|||||||
local hexcolor = string.format("%02x", r2)..string.format("%02x", g2)..string.format("%02x", b2)
|
local hexcolor = string.format("%02x", r2)..string.format("%02x", g2)..string.format("%02x", b2)
|
||||||
local f
|
local f
|
||||||
f, selindic = unifieddyes.make_colored_square(hexcolor, val..hue..sat, showall, creative, painting_with, nodepalette, hp, v2, selindic, inv)
|
f, selindic = unifieddyes.make_colored_square(hexcolor, val..hue..sat, showall, creative, painting_with, nodepalette, hp, v2, selindic, inv)
|
||||||
base_form = base_form..f
|
t[#t+1] = f
|
||||||
end
|
end
|
||||||
|
|
||||||
if v > 3 then
|
if v > 3 then
|
||||||
@ -975,7 +977,7 @@ function unifieddyes.show_airbrush_form(player)
|
|||||||
local hexcolor = string.format("%02x", r3)..string.format("%02x", g3)..string.format("%02x", b3)
|
local hexcolor = string.format("%02x", r3)..string.format("%02x", g3)..string.format("%02x", b3)
|
||||||
local f
|
local f
|
||||||
f, selindic = unifieddyes.make_colored_square(hexcolor, val..hue..sat, showall, creative, painting_with, nodepalette, hp, v2, selindic, inv)
|
f, selindic = unifieddyes.make_colored_square(hexcolor, val..hue..sat, showall, creative, painting_with, nodepalette, hp, v2, selindic, inv)
|
||||||
base_form = base_form..f
|
t[#t+1] = f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -997,44 +999,49 @@ function unifieddyes.show_airbrush_form(player)
|
|||||||
|
|
||||||
local f
|
local f
|
||||||
f, selindic = unifieddyes.make_colored_square(hexgrey, grey, showall, creative, painting_with, nodepalette, hp, v2, selindic, inv)
|
f, selindic = unifieddyes.make_colored_square(hexgrey, grey, showall, creative, painting_with, nodepalette, hp, v2, selindic, inv)
|
||||||
base_form = base_form..f
|
t[#t+1] = f
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if not creative then
|
if not creative then
|
||||||
base_form = base_form..
|
t[#t+1] = "image[10.3,"
|
||||||
"image[10.3,"..(vps*5+vs)..color_button_size..
|
t[#t+1] = (vps*5+vs)
|
||||||
"unifieddyes_onhand_overlay.png]"..
|
t[#t+1] = color_button_size
|
||||||
"label[11.0,"..(vps*5.1+vs)..";Dyes on hand]"
|
t[#t+1] = "unifieddyes_onhand_overlay.png]label[11.0,"
|
||||||
|
t[#t+1] = (vps*5.1+vs)
|
||||||
|
t[#t+1] = ";Dyes on hand]"
|
||||||
end
|
end
|
||||||
|
|
||||||
base_form = base_form.."image[12.5,"..(vps*5+vs)..color_button_size..
|
t[#t+1] = "image[12.5,"
|
||||||
selindic.."label[13.2,"..(vps*5.1+vs)..";Your selection]"
|
t[#t+1] = (vps*5+vs)
|
||||||
|
t[#t+1] = color_button_size
|
||||||
|
t[#t+1] = selindic
|
||||||
|
t[#t+1] = "label[13.2,"
|
||||||
|
t[#t+1] = (vps*5.1+vs)
|
||||||
|
t[#t+1] = ";Your selection]"
|
||||||
|
|
||||||
base_form = base_form..
|
t[#t+1] = "button_exit[11,8;2,1;cancel;Cancel]button_exit[13,8;2,1;accept;Accept]"
|
||||||
"button_exit[11,8;2,1;cancel;Cancel]"..
|
|
||||||
"button_exit[13,8;2,1;accept;Accept]"
|
|
||||||
|
|
||||||
|
|
||||||
if last_right_click and last_right_click.def and last_right_click.def.palette and nodepalette ~= "extended" then
|
if last_right_click and last_right_click.def and last_right_click.def.palette and nodepalette ~= "extended" then
|
||||||
if showall then
|
if showall then
|
||||||
base_form = base_form..
|
t[#t+1] = "button[0.5,8;2,1;show_avail;Show Available]"
|
||||||
"button[0.5,8;2,1;show_avail;Show Available]"..
|
t[#t+1] = "label[2.5,8.25;(Currently showing all 256 colors)]"
|
||||||
"label[2.5,8.25;(Currently showing all 256 colors)]"
|
|
||||||
else
|
else
|
||||||
base_form = base_form..
|
t[#t+1] = "button[0.5,8;2,1;show_all;Show All Colors]"
|
||||||
"button[0.5,8;2,1;show_all;Show All Colors]"..
|
t[#t+1] = "label[2.5,8.25;(Currently only showing what the right-clicked node can use)]"
|
||||||
"label[2.5,8.25;(Currently only showing what the right-clicked node can use)]"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if painting_with then
|
if painting_with then
|
||||||
base_form = base_form..
|
t[#t+1] = "label[0.5,"
|
||||||
"label[0.5,"..(7.25+vs)..";Selected dye: "..
|
t[#t+1] = (7.25+vs)
|
||||||
painting_with.."]"
|
t[#t+1] = ";Selected dye: "
|
||||||
|
t[#t+1] = painting_with
|
||||||
|
t[#t+1] = "]"
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.show_formspec(player_name, "unifieddyes:dye_select_form", base_form)
|
minetest.show_formspec(player_name, "unifieddyes:dye_select_form", table.concat(t))
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_tool("unifieddyes:airbrush", {
|
minetest.register_tool("unifieddyes:airbrush", {
|
||||||
|
Loading…
Reference in New Issue
Block a user