From b1cbaa24fc1503092257de462f0cec401a348219 Mon Sep 17 00:00:00 2001 From: Vanessa Dannenberg Date: Wed, 24 Mar 2021 21:57:59 -0400 Subject: [PATCH] Allow any arbitrary hotbar size 1 to 32 * If user tries to set it to some length < 1 or > 32, it is capped at 1 or 32, respectively. * If user set it to something that doesn't evaluate to a number, it resets to 16. --- init.lua | 27 +++++++++++++++++---------- textures/gui_hb_bg_1.png | Bin 246 -> 295 bytes textures/gui_hb_bg_10.png | Bin 542 -> 0 bytes textures/gui_hb_bg_16.png | Bin 763 -> 0 bytes textures/gui_hb_bg_23.png | Bin 952 -> 0 bytes textures/gui_hb_bg_24.png | Bin 984 -> 0 bytes textures/gui_hb_bg_32.png | Bin 1203 -> 0 bytes textures/gui_hb_bg_8.png | Bin 479 -> 0 bytes 8 files changed, 17 insertions(+), 10 deletions(-) delete mode 100644 textures/gui_hb_bg_10.png delete mode 100644 textures/gui_hb_bg_16.png delete mode 100644 textures/gui_hb_bg_23.png delete mode 100644 textures/gui_hb_bg_24.png delete mode 100644 textures/gui_hb_bg_32.png delete mode 100644 textures/gui_hb_bg_8.png diff --git a/init.lua b/init.lua index 99484bd..f61b1a9 100644 --- a/init.lua +++ b/init.lua @@ -1,15 +1,22 @@ local mtver = minetest.get_version() -local maxslots = (string.sub(mtver.string, 1, 4) ~= "0.4.") and 32 or 23 local themename = dreambuilder_theme and dreambuilder_theme.name.."_" or "" +local base_img = themename.."gui_hb_bg_1.png" +local imgref_len = string.len(base_img) + 8 -- accounts for the stuff in the string.format() below. + +local hb_img = "" +for i = 0, 31 do + hb_img = string.format("%s:%04i,0="..base_img, hb_img, i*64) +end + local function validate_size(s) local size = s and tonumber(s) or 16 - if (size == 8 or size == 10 or size == 16 or size == 23 or size == 24 or size == 32) - and size <= maxslots then - return size - else - return 16 + if size < 1 then + size = 1 + elseif size > 32 then + size = 32 end + return size, ("[combine:"..(size*64).."x64"..string.sub(hb_img, 1, size*imgref_len)) end local hotbar_size_default = validate_size(minetest.settings:get("hotbar_size")) @@ -42,11 +49,11 @@ end load_hotbar_settings() minetest.register_on_joinplayer(function(player) - local hotbar_size = validate_size(get_hotbar_setting(player:get_player_name())) + local hotbar_size, img = validate_size(get_hotbar_setting(player:get_player_name())) player:hud_set_hotbar_itemcount(hotbar_size) minetest.after(0.5,function(hotbar_size) player:hud_set_hotbar_selected_image(themename.."gui_hotbar_selected.png") - player:hud_set_hotbar_image(themename.."gui_hb_bg_"..hotbar_size..".png") + player:hud_set_hotbar_image(img) end,hotbar_size) end) @@ -54,12 +61,12 @@ minetest.register_chatcommand("hotbar", { params = "[size]", description = "Sets the size of your hotbar", func = function(name, slots) - local hotbar_size = validate_size(tonumber(slots)) + local hotbar_size, img = validate_size(tonumber(slots)) player_hotbar_settings[name] = hotbar_size local player = minetest.get_player_by_name(name) player:hud_set_hotbar_itemcount(hotbar_size) minetest.chat_send_player(name, "[_] Hotbar size set to " ..hotbar_size.. ".") - player:hud_set_hotbar_image(themename.."gui_hb_bg_"..hotbar_size..".png") + player:hud_set_hotbar_image(img) save_hotbar_settings() end, }) diff --git a/textures/gui_hb_bg_1.png b/textures/gui_hb_bg_1.png index d2d02c0a0a5aa981865f3c54c410e1e17ee7d346..2e53a5b5ed7105f55a6d78e0dc8d58980eab347a 100644 GIT binary patch literal 295 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=?>t=`Ln>~)y}gn5kbyw!!*Y$h z6_=LSW_?Rw;Gbf|oXYTR!7HECpyaevWbNx)Dh}r&kH570`j3+d=p0Hw?$h~)y|a<`kbywk#s2|a zI)WQHgf<&{Pg`KkC8F8tXrkeIFZ|}T)#|(Vx?Ezs`eMWG_ny-x-(C~?^@iDH_9e5; zr(~C>AD+b~K22ris^>GO?yA1`e^qz;=ja6vjZCauA{r1fU;zt|9k9TG6HGQTsRG#` zsVM}N{kxk{cV*W12`eT2ujM9|+!kN*_l22f`xhpYNz$D8&!zN$9%1lw^>bP0l+XkK D$T3*2 diff --git a/textures/gui_hb_bg_10.png b/textures/gui_hb_bg_10.png deleted file mode 100644 index 555524ce95aee3678d97b7a566c43d8e5616c9ef..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 542 zcmeAS@N?(olHy`uVBq!ia0y~yV0r>%dvUM<$R z;&xlj7|w_$-ux-#K0f`bZ~~)y|Fvj*-(V_ zptp15EP*>6j91r1U1>4i)wrCWCuhmb2`O6=O45M35TJqi^^1b{wR2~lZr{Fh{notm zaxa!l_Op74Mts?I`K9BM`46k#+xFW{#gqpse_v`PYqR6bnKfJM>~~(e_uJSz4rEIc8tUXN?U)|3nLOCkY!Ns$-N?GT70u0NZ8ZW&t;ucLK6TjkIQTT diff --git a/textures/gui_hb_bg_23.png b/textures/gui_hb_bg_23.png deleted file mode 100644 index 51ba70febe289cc4d13b545e1310a8e9ced890bd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 952 zcmeAS@N?(olHy`uVBq!ia0y~yU|R-cdvUM<$(y^Mo@HQQuJ?3t45_&F_U6W1CIb=I zi|;#{R0Xx0?$t=GQZ zWS(1c$x|IS5%<2NLf~b!#rwU_FD}QcvgFdsy?*W1{C>v9*=y(fuiNt7?%Ze5U_536 zZC-9}Rm%%;BnwY4grPFZU|<*x1Ylyo7YKai=kkn;?^Vk`oq1cn-0J0$$$q$ry*D!N z?!H?cpZ4s_%Zb;buBY?kPxU3g;?>c!4v_y~Vf@KciRY{CNHl_EJzf1=);T3K0RZY> B!Uq5V diff --git a/textures/gui_hb_bg_24.png b/textures/gui_hb_bg_24.png deleted file mode 100644 index fb101a21d744b51861d72459ba6f306af1f0a11c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 984 zcmeAS@N?(olHy`uVBq!ia0y~yVEX`MdvUM<$=r>?hZq=`=X<(1hE&{odvjxMlc9v` z#q)x!-V1buI&aQwRlQ`%{bxd(OZcNXm&!_?zB>!lg#jFHSy|nwj!%E~=~?c(?6tQy zvs=AfGT9Fg@#U4@a`uV)+RpF&Zu2Vyk3z69U&QD7vGeO08)vV5U%qb3cf0eSw}z|F zExF{0hlsoPG8y911|DWP2&+W`#Oc1%x4x zbbuMmY7iJT3K$S0GOYaA)4$LBd8c~*)0w~Z%L%60OMb6kl)bN=JM;8z_o(c<^K38R mORd1Py!`(Q7D#eKB^B*;ENi^OL=C=z#64a8T-G@yGywqebmzkW diff --git a/textures/gui_hb_bg_32.png b/textures/gui_hb_bg_32.png deleted file mode 100644 index 57dd58808667ca328d9d1026ce0a4a97952c08a5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1203 zcmeAS@N?(olHy`uVBq!ia0y~y;B)}8y*Su_WWoL%TLuP}Do+>3kcwMxZ*9zNGL&$= zcwUgzdx4Hn=gpa|s+TOe|4b-((pBtr`|8xw=FC7{xIq1;KEChwuFu@Lr*ii1sMp`# zH2PV+Tr!zB;>#_+95(X-}%x%4P@$J3eOVjk;%Vn-Dt^VdfWX1wzz+d%qVR;1${onxq Xt1|&stK9A-fMh*g{an^LB{Ts5^12WB diff --git a/textures/gui_hb_bg_8.png b/textures/gui_hb_bg_8.png deleted file mode 100644 index 45e1ef26e444dd85c7f3ab8a269efb1ea806a564..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 479 zcmeAS@N?(olHy`uVBq!ia0y~yUzgP2%4QWWf10vn_qH=@cNc$K2@~CPd5^VjGkf-=kgLhhrtbRvYuUE9Pz{?d zFR_kgQDr!g&LYCl(7?nX0CXP{7lVTXBLjy90|Tb0!UEz%85mg^Fx6ra1zCfs7E=`F zBviGSqR7ris0E2Wm_6;_&52L0-3|Zzq@p+-5@eeu&sDp#(rx?Qy{eJv@+((;3+IQ2 h+vK_6@MdV3U(MtgcqMnoM~B5A5l>e?mvv4FO#qzIhNJ)h