From 69a96497e27a1c499e91807c14113015a24e42fd Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Thu, 23 Sep 2021 21:08:36 +0800 Subject: [PATCH 01/20] [WIP] Itemslot and inventory formspec overhaul. --- mods/HUD/mcl_formspec/init.lua | 68 ++++-- .../textures/mcl_formspec_itemslot.png | Bin 231 -> 505 bytes mods/HUD/mcl_inventory/init.lua | 214 +++++++++++++----- .../mcl_inventory_empty_armor_slot_boots.png | Bin 102 -> 1160 bytes .../mcl_inventory_player_preview_box9.png | Bin 0 -> 2129 bytes mods/ITEMS/mcl_chests/init.lua | 43 ++-- 6 files changed, 230 insertions(+), 95 deletions(-) create mode 100644 mods/HUD/mcl_inventory/textures/mcl_inventory_player_preview_box9.png diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index 8ddc90c1d..4e7e9eaaf 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -6,10 +6,9 @@ local sf = string.format mcl_formspec = {} mcl_formspec.label_color = "#313131" - mcl_formspec.label_size = tonumber(minetest.settings:get("mcl_label_font_size")) or 24 - -mcl_formspec.apply_label_size = sf("style_type[label;font_size=%s]", mcl_formspec.label_size) +mcl_formspec.style_label = sf("style_type[label;font_size=%f]", mcl_formspec.label_size) +mcl_formspec.style_label_reset = "style_type[label;font=;font_size=;noclip=]" function mcl_formspec.get_itemslot_bg(x, y, w, h) local out = "" @@ -22,22 +21,65 @@ function mcl_formspec.get_itemslot_bg(x, y, w, h) end --This function will replace mcl_formspec.get_itemslot_bg then every formspec will be upgrade to version 4 -local function get_slot(x, y, size) - local t = "image["..x-size..","..y-size..";".. 1+(size*2)..",".. 1+(size*2)..";mcl_formspec_itemslot.png]" - return t +-- Roughly 8 pixels (outer itemslot) out of 64 pixels. +mcl_formspec.itemslot_border_size = 0.0625 +mcl_formspec.itemslot_spacing_size = 0 + +-- resize factor for roughly 56 pixels (inner itemslot) to become 64 pixels (which is 1 formspec unit). +function mcl_formspec.get_factor(border) + local border = border or mcl_formspec.itemslot_border_size + return 1 / (1 - 2 * border) -- assuming default border values, 64 / 56 end -mcl_formspec.itemslot_border_size = 0.05 +function mcl_formspec.get_between(border, spacing, factor) + local border = border or mcl_formspec.itemslot_border_size + local spacing = spacing or mcl_formspec.itemslot_spacing_size + local factor = factor or mcl_formspec.get_factor(border) + return spacing + 2 * border * factor +end -function mcl_formspec.get_itemslot_bg_v4(x, y, w, h, size) - if not size then - size = mcl_formspec.itemslot_border_size - end +function mcl_formspec.itemslot_unit(n, border, spacing, factor) + local n = n or 1 + local border = border or mcl_formspec.itemslot_border_size + local spacing = spacing or mcl_formspec.itemslot_spacing_size + local factor = factor or mcl_formspec.get_factor(border) + return n + n * mcl_formspec.get_between(border, spacing, factor) +end + +mcl_formspec.style_list_reset = "style_type[list;noclip=;size=;spacing=]" +function mcl_formspec.get_style_list(border, spacing) + local border = border or mcl_formspec.itemslot_border_size + local spacing = spacing or mcl_formspec.itemslot_spacing_size + return table.concat{ + "style_type[list;", + "spacing=", mcl_formspec.get_between(border, spacing), + "]", + } +end + +local function create_itemslot_bg(i, j, x, y, iu, border, spacing, factor) + local iu = iu or mcl_formspec.itemslot_unit(1, border, spacing, factor) + local img_x = x + i * iu - (factor * border) + local img_y = y + j * iu - (factor * border) + return table.concat{ + "image[", + img_x, ",", img_y, ";", + factor, ",", factor, ";", + "mcl_formspec_itemslot.png", + "]", + } +end + +function mcl_formspec.create_itemslot_bg(x, y, w, h, iu, border, spacing, factor) + local iu = iu or mcl_formspec.itemslot_unit(1, border, spacing, factor) + local border = border or mcl_formspec.itemslot_border_size + local spacing = spacing or mcl_formspec.itemslot_spacing_size + local factor = factor or mcl_formspec.get_factor(border, spacing) local out = "" for i = 0, w - 1, 1 do for j = 0, h - 1, 1 do - out = out .. get_slot(x+i+(i*0.25), y+j+(j*0.25), size) + out = out .. create_itemslot_bg(i, j, x, y, iu, border, spacing, factor) end end return out -end \ No newline at end of file +end diff --git a/mods/HUD/mcl_formspec/textures/mcl_formspec_itemslot.png b/mods/HUD/mcl_formspec/textures/mcl_formspec_itemslot.png index 84958ecd4234850d627aa868c382df5d322d0f8c..94deca755931c7326121327f548ece7e9db32fb2 100644 GIT binary patch literal 505 zcmVEX>4Tx04R}tkv&MmKpe$iQ>7{`4i*t{$k2*|1yK=4twIqhlv<%x2a`)bgeDD1 zii@M*T5#}VvFhOBtgC~oAP9bdxVbqgx=4xtOA0MwJUH&hyL*qjcYshYGu7-E160j2 z(uug3&8>)mS9GHvA&ej@F;kySrIPR*U-$6w^)AMo3h_Dds6iJbe&o9B@*C%(!vfC?8=3SRahO;vwz1sCtYoOflf)54)hJ)c zx~y>C;;fddta(rV!eCxoUgA2T(>lN54hX`2A*`ukQ~WRQz#UG_cQvY9ME?Q^sKtQHTQA)0A#4E(&UMY%W6p8zu4+aZ^0}!q#P)Cl!yQ$UV_AkcF2l1QQXr9PYNV;BmUc*^ zLQIk-DfNviO&Zjp8#UypJlLU`8_O{l;#{~%5)xfPlU<5*31MkGL_{~?I~O|QmLp!H zK;%v^Wr8!pf0EzI_L0G7WX_gQBO>gcu38~4=EZ?l8D-sJ1|T#qZgv#-A@|sR04pG9 zN0|c~tZ6@8>_*StlA{3xb_RX+7kOXQ_~;TvY(p|6K#($tQKsa~PNc#CKoyy@DDNOZ zX55h^t4Ic$Kp!DC);JxuY<$k+sDO`276+Rm6|htdfBoYc=%H$2YG&Eo!iv=`OV(^T zXV2@*RToz`&+Z;xyoQ8^MGlXM618v<97!v=c!^RV>5ea0-a-qbFt zzsMg@f1`^UAEcI@-_$Vcz8oDcXnkjFF#|DH0&!mi(9pb?r65&axM+}@$q*O#yz#LiQ=YMKP65AR1* zj*4RQ`S7>;<>=+;<>=+;<>=+;<>)_mH1YFLfAA;v9rJ!v#0rq`dH?_cglR)VP)S2W zAaHVTW@&6?004NLeUUv#!$2IxU(-reDh?JDaR^wQEQpFYY88r5A=C=3I+$Gg1x*@~ z6c{8WR>`wc+8{=5|44bLsJaL#<%(t=9#;jm!#8bo(RnsY7 zNV}|Z-r}s4Dy(@={=!gJUs>il%^}3Ge~2YW5TT%gB1*6krBx@zLX!4l9{$0GUm}-6 zt|AyY7Ep!;x#0)@gWug+xycDPDHH=bUL5CR1PJZ|^{V51A3IL{1n@rtS9;4|t^qTj zq*q&7_arywHZK$in z4RCM>jOHnO-Q(Sz?Y;ebrrF;QC~b0y{_8Qx0000sNkl002ovPDHLk FV1npNAfx~Q delta 73 zcmeC+Oq-zW%%JP(;uuoFn0$cC?O?sYF-^Y+ zaB^>EX>4U6ba`-PAZ2)IW&i+q+U;0fa>Kk0eCH{81Ogxl@;LmR=?!}PE-2Zt6DLuU z@2#~amMl@k0t+s{xcQ%dFZVBe#Fy+s)SOC69-mM`;fjmw-#+s^ANR~Hd_Kjg6gx1Mh+yTBF_m6uZR={A~Va{-{`gTmwBE997>;w>u zi#Q+oMLLW%-dPf0I|2*|DDa6SQX;R+N)&`M2&zEN61af@ijfCEau7-2CL@nv8}BIX zu^johkEH^Bq9jppQ>22d5F+wNLq-nOC^5tsQ`DGaiPa@ZA;pxECR=k=MT167s+zTE z&5}coIc3c`ms|@M!IF$66)m}xQY&oM;A*URyJAGGjhnR4VoOb1Zl%?Z^y#6;p1Stj zORs~6j4j3m6oo&%BpwPPF6o0KVXec)_5~z zzoZ*Xm{9aX=}Dg$P7@6_h&vKxo=G^mb$ND;)}EUZot#| z2JQ)(Ne33~r1Yh8*#po8OU^E&=lR!|yZ1NV!8^dckNYdv9s>WTxVx)y{w(gdq;L;e z@iFdij(r>RNBaL1bN9)EALqM!o$x=8yZbbrT*n%#$BH(qN$7R<3UQfO_h=z9Yg@x4 zXF(KmV`t#XjEc&vz1pulP!{sO?;(e4#gTP!s?ZyYd0#7s${kZ^iCtli%{9T;&M2&L zErDHGa}`|Ee$o7Ga$0?96sHm(wU`AH0zkuv)l)0788pKf_|f!}WysrU+m-$ErTNo1 zdPOsT828)!-8zcZY2Q5ncxgV)j@npTn5FeFCMk4$G)^G{TN`QDgW{c<1}{`a=yQ(R zr$$KjnjL@_hb0m1W%IS~oU!aS-1q_d`hb^HTLfUxKUNqv2=)%}Ii)Jw|4|1frCOM?yMKmiQy4FsG!U>qR6gzzyS?m|Rn(C=l+9Rfnq4Ke#}`-Il~nkdP= z42@;4mvgmv|Fm8{O!U#hs{6HM8Ch82J2ETB6t-JvdypxecBTM5a%C^tTe^UwBVo>T zL3&-3UYYKS|5x01SNy-?zPsZ875Cj0|Nl?_|2+Lx!?!Aixm8iO?CC&}*rMoes;IhE zv7V}^rz)BnL6lJG4@t7h3P~DP971~#MVHFhs%RrujawB>5aS8rP(_2WRndTK7;x%M zn}NceFb)tGAUqd|GEPaH?gnIQ;vf<$7YvRBr03E+X$>! zGTe$?uqmEn%qrBA%Q<1!h+Ueep3yUD5Nv`_gAekl;1{ij zvrM_QSE)V0>YRR0ReeF{wsQw2HhU7|n3@?qF*d*}dn7}_-ghw46&2aLf<6^JKMH*r zv1B3az`Gw6I4K7j)=GKXKz}1D?&n?q%tp9HAn^g3NvfW^kOLmtrLSE3&7SS?{6cDf5qCgycWjo5FXR5vxu5LU zejI!EZ4G&j{c~E};{J(izlyi}8qW2&yVnW-^L%&z$Ul#u8EzE7`Y#CMXrE0}ejfk; z0fcEoLr_UWLm+T+Z)Rz1WdHzpoPCi!NW(xJ#b47(RVoe^6mbYxoh*ooIBFG&P$AR` ztvZ-o`UOoIk`xz5!L{Jv$70pN#aUMeS3wZ`0C973Qgo3L|JM{+#CUMrk9YSTckck9 zR$`hJ7zZ@nHk0v~n9i({8WR>`wc+8{=5|44bLsJaL#<%(t=9#;jm! z#8bo(RnsY7NV}|Z-r}s4Dy(@={=!gJUs>il%^}3Gh$To6p`d~yO0W^7RVT$llJ;XB z{=tS{B9}t0A{aRqP=*G%;RpYN-`!fd$q6?p6azY59Oq*M2<`&)s^fegJ5K!s@IM1r zddpv~0W+VZS6f=-2 Date: Thu, 30 Sep 2021 04:16:02 +0800 Subject: [PATCH 02/20] [WIP] better crafting formspec values. --- mods/HUD/mcl_inventory/init.lua | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index d39fc89b7..db630e225 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -157,17 +157,22 @@ local function set_inventory(player, armor_change_only) -- included, the crafting output itemslot will protrude out of the inner -- inventory dialog and look awkward. So we deviate from MC for the sake of -- looking nicer. - local crafting_label_height = 0.09375 -- eyeballed value - local crafting_label_spacing = 0.35 -- eyeballed value - local crafting_x = padding + mcl_formspec.itemslot_unit(5) - 0.25 * mcl_formspec.itemslot_unit(1) - local crafting_y = padding + crafting_label_height + crafting_label_spacing - local crafting_length = mcl_formspec.itemslot_unit(2) - local crafting_arrow_spacing = 0.09375 -- eyeballed value - local crafting_arrow_length = mcl_formspec.itemslot_unit(1) + -- NOTE: text usually depends on eyeballed values due to how minetest + -- handles them. e.g.: labels are verically aligned to "center" (which is + -- also affected by padding of the font) in the new coordinate system. + local crafting_x = padding + 5 * iu - 0.25 * iu -- 0.25 * iu offset for nicer spacing, see notes. + local crafting_label_x = crafting_x - bu + local crafting_label_height = 0.625 -- eyeballed value. + local crafting_label_y = padding + 0.25 * crafting_label_height -- should be 0.5 * crafting_label_height, see notes. + --local crafting_x = ... -- see above + local crafting_y = padding + crafting_label_height + local crafting_length = 2 * iu + local crafting_arrow_spacing = 0.078125 -- eyeballed value + local crafting_arrow_y = crafting_y + iu / 2 + local crafting_arrow_length = iu local crafting_formspec = table.concat{ - -- NOTE: labels are "center" aligned in the new coordinate system. "label[", - crafting_x, ",", padding + crafting_label_height / 2, ";", + crafting_label_x, ",", crafting_label_y, ";", F(C(mcl_formspec.label_color, S("Crafting"))), "]", mcl_formspec.create_itemslot_bg(crafting_x, crafting_y, 2, 2), @@ -176,15 +181,15 @@ local function set_inventory(player, armor_change_only) "2,2", "]", "image[", - crafting_x + crafting_length + crafting_arrow_spacing, ",", crafting_y + crafting_arrow_length / 2, ";", + crafting_x + crafting_length + crafting_arrow_spacing, ",", crafting_arrow_y, ";", "1,1;crafting_formspec_arrow.png", "]", mcl_formspec.create_itemslot_bg( - crafting_x + crafting_length + crafting_arrow_length + 2 * crafting_arrow_spacing, crafting_y + crafting_arrow_length / 2, + crafting_x + crafting_length + crafting_arrow_length + 2 * crafting_arrow_spacing, crafting_arrow_y, 1, 1 ), "list[current_player;craftpreview;", - crafting_x + crafting_length + crafting_arrow_length + 2 * crafting_arrow_spacing, ",", crafting_y + crafting_arrow_length / 2, ";", + crafting_x + crafting_length + crafting_arrow_length + 2 * crafting_arrow_spacing, ",", crafting_arrow_y, ";", "1,1;", "]", } -- 2.40.1 From c9813cbd7c0631e9619134b6eb5df40476522702 Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Thu, 30 Sep 2021 09:46:04 +0800 Subject: [PATCH 03/20] [WIP] Use units in more places. --- mods/HUD/mcl_formspec/init.lua | 34 +++++++++++++++++++++------------ mods/HUD/mcl_inventory/init.lua | 15 ++++++--------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index 4e7e9eaaf..90c4043ba 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -1,13 +1,17 @@ -local string = string -local table = table - -local sf = string.format +local minetest, string, table = + minetest, string, table mcl_formspec = {} +local mcl_formspec = mcl_formspec +mcl_formspec.padding = 0.375 + +-------------------------------------------------------------------------------- +-- Label -- +-------------------------------------------------------------------------------- mcl_formspec.label_color = "#313131" mcl_formspec.label_size = tonumber(minetest.settings:get("mcl_label_font_size")) or 24 -mcl_formspec.style_label = sf("style_type[label;font_size=%f]", mcl_formspec.label_size) +mcl_formspec.style_label = string.format("style_type[label;font_size=%f]", mcl_formspec.label_size) mcl_formspec.style_label_reset = "style_type[label;font=;font_size=;noclip=]" function mcl_formspec.get_itemslot_bg(x, y, w, h) @@ -20,6 +24,10 @@ function mcl_formspec.get_itemslot_bg(x, y, w, h) return out end +-------------------------------------------------------------------------------- +-- Itemslot -- +-------------------------------------------------------------------------------- + --This function will replace mcl_formspec.get_itemslot_bg then every formspec will be upgrade to version 4 -- Roughly 8 pixels (outer itemslot) out of 64 pixels. mcl_formspec.itemslot_border_size = 0.0625 @@ -30,12 +38,13 @@ function mcl_formspec.get_factor(border) local border = border or mcl_formspec.itemslot_border_size return 1 / (1 - 2 * border) -- assuming default border values, 64 / 56 end +mcl_formspec.itemslot_bu = mcl_formspec.get_factor(border) * border -- border unit function mcl_formspec.get_between(border, spacing, factor) local border = border or mcl_formspec.itemslot_border_size local spacing = spacing or mcl_formspec.itemslot_spacing_size local factor = factor or mcl_formspec.get_factor(border) - return spacing + 2 * border * factor + return spacing + 2 * factor * border end function mcl_formspec.itemslot_unit(n, border, spacing, factor) @@ -45,6 +54,7 @@ function mcl_formspec.itemslot_unit(n, border, spacing, factor) local factor = factor or mcl_formspec.get_factor(border) return n + n * mcl_formspec.get_between(border, spacing, factor) end +mcl_formspec.itemslot_iu = mcl_formspec.itemslot_unit() -- itemslot unit mcl_formspec.style_list_reset = "style_type[list;noclip=;size=;spacing=]" function mcl_formspec.get_style_list(border, spacing) @@ -57,10 +67,9 @@ function mcl_formspec.get_style_list(border, spacing) } end -local function create_itemslot_bg(i, j, x, y, iu, border, spacing, factor) - local iu = iu or mcl_formspec.itemslot_unit(1, border, spacing, factor) - local img_x = x + i * iu - (factor * border) - local img_y = y + j * iu - (factor * border) +local function create_itemslot_bg(i, j, x, y, iu, bu, factor) + local img_x = x + i * iu - bu + local img_y = y + j * iu - bu return table.concat{ "image[", img_x, ",", img_y, ";", @@ -70,8 +79,9 @@ local function create_itemslot_bg(i, j, x, y, iu, border, spacing, factor) } end -function mcl_formspec.create_itemslot_bg(x, y, w, h, iu, border, spacing, factor) - local iu = iu or mcl_formspec.itemslot_unit(1, border, spacing, factor) +function mcl_formspec.create_itemslot_bg(x, y, w, h, iu, bu, border, spacing, factor) + local iu = iu or mcl_formspec.itemslot_iu or mcl_formspec.itemslot_unit(1, border, spacing, factor) + local bu = bu or mcl_formspec.itemslot_bu or local border = border or mcl_formspec.itemslot_border_size local spacing = spacing or mcl_formspec.itemslot_spacing_size local factor = factor or mcl_formspec.get_factor(border, spacing) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index db630e225..71e0649ef 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -1,10 +1,14 @@ -local minetest, mcl_formspec = - minetest, mcl_formspec +local minetest, math, table, mcl_formspec = + minetest, math, table, mcl_formspec local S = minetest.get_translator(minetest.get_current_modname()) local F = minetest.formspec_escape local C = minetest.colorize +local padding = mcl_formspec.padding +local bu = mcl_formspec.itemslot_bu +local iu = mcl_formspec.itemslot_iu + mcl_inventory = {} --local mod_player = minetest.get_modpath("mcl_player") @@ -65,13 +69,6 @@ local function set_inventory(player, armor_change_only) inv:set_width("craft", 2) inv:set_size("craft", 4) - local padding = 0.375 - local border = mcl_formspec.itemslot_border_size - local spacing = mcl_formspec.itemslot_spacing_size - local factor = mcl_formspec.get_factor(border) - local bu = factor * border - local iu = mcl_formspec.itemslot_unit() - -- Armor slots formspec local armor_slots = {"helmet", "chestplate", "leggings", "boots"} local armor_slots_formspec = "" -- 2.40.1 From 79eefe415328dfdf6755ed5611c17e17c2113f6c Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Thu, 30 Sep 2021 10:19:11 +0800 Subject: [PATCH 04/20] [WIP] better parameter handling for mcl_formspec.create_itemslot_bg(). --- mods/HUD/mcl_formspec/init.lua | 9 +++++++-- mods/HUD/mcl_inventory/init.lua | 8 ++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index 90c4043ba..5f94ffae8 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -80,11 +80,16 @@ local function create_itemslot_bg(i, j, x, y, iu, bu, factor) end function mcl_formspec.create_itemslot_bg(x, y, w, h, iu, bu, border, spacing, factor) - local iu = iu or mcl_formspec.itemslot_iu or mcl_formspec.itemslot_unit(1, border, spacing, factor) - local bu = bu or mcl_formspec.itemslot_bu or + local iu = iu or mcl_formspec.itemslot_iu + local bu = bu or mcl_formspec.itemslot_bu + if border and spacing and factor then + iu = mcl_formspec.itemslot_unit(1, border, spacing, factor) + bu = factor * border + end local border = border or mcl_formspec.itemslot_border_size local spacing = spacing or mcl_formspec.itemslot_spacing_size local factor = factor or mcl_formspec.get_factor(border, spacing) + local out = "" for i = 0, w - 1, 1 do for j = 0, h - 1, 1 do diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 71e0649ef..f1a0b9180 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -77,7 +77,7 @@ local function set_inventory(player, armor_change_only) local y = padding + b * iu armor_slots_formspec = table.concat{ armor_slots_formspec, - mcl_formspec.create_itemslot_bg(padding, y, 1, 1, iu), + mcl_formspec.create_itemslot_bg(padding, y, 1, 1), } if inv:get_stack("armor", a+1):is_empty() then @@ -140,7 +140,7 @@ local function set_inventory(player, armor_change_only) local left_hand_y = padding + ppreview_height - iu local left_hand_formspec = table.concat{ -- left hand presupport - mcl_formspec.create_itemslot_bg(left_hand_x, left_hand_y, 1, 1, iu), + mcl_formspec.create_itemslot_bg(left_hand_x, left_hand_y, 1, 1), "list[current_player;armor;", left_hand_x, ",", left_hand_y, ";", "1,1;4", @@ -192,8 +192,8 @@ local function set_inventory(player, armor_change_only) } local inventory_formspec = table.concat{ - mcl_formspec.create_itemslot_bg(padding, 2 * padding + 4 * iu, 9, 3, iu), - mcl_formspec.create_itemslot_bg(padding, 3 * padding + 7 * iu, 9, 1, iu), + mcl_formspec.create_itemslot_bg(padding, 2 * padding + 4 * iu, 9, 3), + mcl_formspec.create_itemslot_bg(padding, 3 * padding + 7 * iu, 9, 1), "list[current_player;main;", padding, ",", 2 * padding + 4 * iu, ";", "9,3;9", -- 2.40.1 From 520c35feaa91bdf6e1ec1862f1a33ada5632d75d Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Thu, 30 Sep 2021 10:19:44 +0800 Subject: [PATCH 05/20] [WIP] add crafting_arrow_x. --- mods/HUD/mcl_inventory/init.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index f1a0b9180..8e35c0b10 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -165,6 +165,7 @@ local function set_inventory(player, armor_change_only) local crafting_y = padding + crafting_label_height local crafting_length = 2 * iu local crafting_arrow_spacing = 0.078125 -- eyeballed value + local crafting_arrow_x = crafting_x + crafting_length + crafting_arrow_spacing local crafting_arrow_y = crafting_y + iu / 2 local crafting_arrow_length = iu local crafting_formspec = table.concat{ @@ -178,15 +179,15 @@ local function set_inventory(player, armor_change_only) "2,2", "]", "image[", - crafting_x + crafting_length + crafting_arrow_spacing, ",", crafting_arrow_y, ";", + crafting_arrow_x, ",", crafting_arrow_y, ";", "1,1;crafting_formspec_arrow.png", "]", mcl_formspec.create_itemslot_bg( - crafting_x + crafting_length + crafting_arrow_length + 2 * crafting_arrow_spacing, crafting_arrow_y, + crafting_arrow_x + crafting_arrow_length + crafting_arrow_spacing, crafting_arrow_y, 1, 1 ), "list[current_player;craftpreview;", - crafting_x + crafting_length + crafting_arrow_length + 2 * crafting_arrow_spacing, ",", crafting_arrow_y, ";", + crafting_arrow_x + crafting_arrow_length + crafting_arrow_spacing, ",", crafting_arrow_y, ";", "1,1;", "]", } -- 2.40.1 From badfe23a9635d69ed0b07668bd1fb2afc11c2383 Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Thu, 30 Sep 2021 10:19:59 +0800 Subject: [PATCH 06/20] [WIP] fix incorrect setting name, 3d_player_preview. --- mods/HUD/mcl_inventory/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 8e35c0b10..56278532b 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -111,7 +111,7 @@ local function set_inventory(player, armor_change_only) "mcl_inventory_player_preview_box9.png;false;3", "]", } - if minetest.settings:get_bool("3d_ppreview", true) then + if minetest.settings:get_bool("3d_player_preview", true) then ppreview_formspec = table.concat{ ppreview_formspec, -- TODO: model is offsetted to the right. investigate. -- 2.40.1 From 0226aaf8d805a031fa382951568845e21b62ebf8 Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Thu, 30 Sep 2021 14:10:06 +0800 Subject: [PATCH 07/20] [WIP] remove crafting_label_x. too specific. --- mods/HUD/mcl_inventory/init.lua | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 56278532b..4cc1999d5 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -157,11 +157,9 @@ local function set_inventory(player, armor_change_only) -- NOTE: text usually depends on eyeballed values due to how minetest -- handles them. e.g.: labels are verically aligned to "center" (which is -- also affected by padding of the font) in the new coordinate system. - local crafting_x = padding + 5 * iu - 0.25 * iu -- 0.25 * iu offset for nicer spacing, see notes. - local crafting_label_x = crafting_x - bu local crafting_label_height = 0.625 -- eyeballed value. - local crafting_label_y = padding + 0.25 * crafting_label_height -- should be 0.5 * crafting_label_height, see notes. - --local crafting_x = ... -- see above + local crafting_label_y = padding + 0.25 * crafting_label_height -- 0.25 * crafting_label_height for nicer text spacing, see notes. + local crafting_x = padding + 5 * iu - 0.25 * iu -- 0.25 * iu offset for nicer crafting formspec spacing, see notes. local crafting_y = padding + crafting_label_height local crafting_length = 2 * iu local crafting_arrow_spacing = 0.078125 -- eyeballed value @@ -170,7 +168,7 @@ local function set_inventory(player, armor_change_only) local crafting_arrow_length = iu local crafting_formspec = table.concat{ "label[", - crafting_label_x, ",", crafting_label_y, ";", + crafting_x - bu, ",", crafting_label_y, ";", F(C(mcl_formspec.label_color, S("Crafting"))), "]", mcl_formspec.create_itemslot_bg(crafting_x, crafting_y, 2, 2), -- 2.40.1 From d24fbe1a8e1095991b9b3dca74320ec053587554 Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Thu, 30 Sep 2021 19:48:02 +0800 Subject: [PATCH 08/20] [WIP] better parameter handling for mcl_formspec.create_itemslot_bg(). --- mods/HUD/mcl_formspec/init.lua | 43 ++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index 5f94ffae8..d58d44756 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -79,21 +79,44 @@ local function create_itemslot_bg(i, j, x, y, iu, bu, factor) } end -function mcl_formspec.create_itemslot_bg(x, y, w, h, iu, bu, border, spacing, factor) - local iu = iu or mcl_formspec.itemslot_iu - local bu = bu or mcl_formspec.itemslot_bu - if border and spacing and factor then - iu = mcl_formspec.itemslot_unit(1, border, spacing, factor) - bu = factor * border +function mcl_formspec.create_itemslot_bg(x, y, w, h, def) + -- Optional params: def + -- Params: + -- (x, y, w, h, def*) + -- def params: + -- { + -- < iu = ..., bu = ... >* + -- < border = ..., spacing = ..., factor = ..., >* + -- } + -- or { + -- < iu = ..., bu = ... >* + -- border = nil, spacing = nil, < factor = ..., >* + -- } + -- * indicates that the argument (or set of arguments) may be nil. + local iu, bu, border, spacing, factor + if def then + if def.border and def.spacing and def.factor then + iu = mcl_formspec.itemslot_unit(1, border, spacing, factor) + bu = factor * border + else + iu = def.iu or mcl_formspec.itemslot_iu + bu = def.bu or mcl_formspec.itemslot_bu + end + border = def.border or mcl_formspec.itemslot_border_size + spacing = def.spacing or mcl_formspec.itemslot_spacing_size + factor = def.factor or mcl_formspec.get_factor(border, spacing) + else + iu = mcl_formspec.itemslot_iu + bu = mcl_formspec.itemslot_bu + border = mcl_formspec.itemslot_border_size + spacing = mcl_formspec.itemslot_spacing_size + factor = mcl_formspec.get_factor(border, spacing) end - local border = border or mcl_formspec.itemslot_border_size - local spacing = spacing or mcl_formspec.itemslot_spacing_size - local factor = factor or mcl_formspec.get_factor(border, spacing) local out = "" for i = 0, w - 1, 1 do for j = 0, h - 1, 1 do - out = out .. create_itemslot_bg(i, j, x, y, iu, border, spacing, factor) + out = out .. create_itemslot_bg(i, j, x, y, iu, bu, factor) end end return out -- 2.40.1 From ad232fbf66a9f3eb4c772a5be3eeb49be2b5c15a Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Thu, 30 Sep 2021 19:50:44 +0800 Subject: [PATCH 09/20] [WIP] fix incorrect border reference. --- mods/HUD/mcl_formspec/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index d58d44756..0b655289a 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -38,7 +38,7 @@ function mcl_formspec.get_factor(border) local border = border or mcl_formspec.itemslot_border_size return 1 / (1 - 2 * border) -- assuming default border values, 64 / 56 end -mcl_formspec.itemslot_bu = mcl_formspec.get_factor(border) * border -- border unit +mcl_formspec.itemslot_bu = mcl_formspec.get_factor(mcl_formspec.itemslot_border_size) * mcl_formspec.itemslot_border_size -- border unit function mcl_formspec.get_between(border, spacing, factor) local border = border or mcl_formspec.itemslot_border_size -- 2.40.1 From f09db9098c575229bb3287e716f2110b22de7010 Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Thu, 30 Sep 2021 20:28:20 +0800 Subject: [PATCH 10/20] [WIP] rename style variables. --- mods/HUD/mcl_formspec/init.lua | 9 +++++---- mods/HUD/mcl_inventory/init.lua | 4 ++-- mods/ITEMS/mcl_chests/init.lua | 8 ++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index 0b655289a..90a0bd1bf 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -11,8 +11,8 @@ mcl_formspec.padding = 0.375 -------------------------------------------------------------------------------- mcl_formspec.label_color = "#313131" mcl_formspec.label_size = tonumber(minetest.settings:get("mcl_label_font_size")) or 24 -mcl_formspec.style_label = string.format("style_type[label;font_size=%f]", mcl_formspec.label_size) -mcl_formspec.style_label_reset = "style_type[label;font=;font_size=;noclip=]" +mcl_formspec.label_style = string.format("style_type[label;font_size=%f]", mcl_formspec.label_size) +mcl_formspec.label_style_reset = "style_type[label;font=;font_size=;noclip=]" function mcl_formspec.get_itemslot_bg(x, y, w, h) local out = "" @@ -56,8 +56,7 @@ function mcl_formspec.itemslot_unit(n, border, spacing, factor) end mcl_formspec.itemslot_iu = mcl_formspec.itemslot_unit() -- itemslot unit -mcl_formspec.style_list_reset = "style_type[list;noclip=;size=;spacing=]" -function mcl_formspec.get_style_list(border, spacing) +function mcl_formspec.get_itemslot_style(border, spacing) local border = border or mcl_formspec.itemslot_border_size local spacing = spacing or mcl_formspec.itemslot_spacing_size return table.concat{ @@ -66,6 +65,8 @@ function mcl_formspec.get_style_list(border, spacing) "]", } end +mcl_formspec.itemslot_style_reset = "style_type[list;noclip=;size=;spacing=]" +mcl_formspec.itemslot_style = mcl_formspec.get_itemslot_style() local function create_itemslot_bg(i, j, x, y, iu, bu, factor) local img_x = x + i * iu - bu diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 4cc1999d5..527cba46f 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -206,8 +206,8 @@ local function set_inventory(player, armor_change_only) local form = table.concat({ "formspec_version[4]", "size[", 2 * padding + 9 * iu - 2 * bu, ",", 4 * padding + 8 * iu - 2 * bu, "]", - mcl_formspec.style_label, - mcl_formspec.get_style_list(), + mcl_formspec.label_style, + mcl_formspec.itemslot_style, armor_slots_formspec, ppreview_formspec, diff --git a/mods/ITEMS/mcl_chests/init.lua b/mods/ITEMS/mcl_chests/init.lua index d7d40ac37..3976e4d6f 100644 --- a/mods/ITEMS/mcl_chests/init.lua +++ b/mods/ITEMS/mcl_chests/init.lua @@ -487,7 +487,7 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile table.concat({ "formspec_version[4]", "size[11.75,10.425]", - mcl_formspec.style_label, + mcl_formspec.label_size, "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", @@ -647,7 +647,7 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile table.concat({ "formspec_version[4]", "size[11.75,14.15]", - mcl_formspec.style_label, + mcl_formspec.label_style, "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", @@ -806,7 +806,7 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile table.concat({ "formspec_version[4]", "size[11.75,14.15]", - mcl_formspec.style_label, + mcl_formspec.label_style, "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", @@ -1167,7 +1167,7 @@ local function formspec_shulker_box(name) return table.concat({ "formspec_version[4]", "size[11.75,10.425]", - mcl_formspec.style_label, + mcl_formspec.label_style, "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", -- 2.40.1 From dcfe1753038ad3cf731bf5e756db1bec891871f1 Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Thu, 30 Sep 2021 20:49:35 +0800 Subject: [PATCH 11/20] [WIP] standardize more label measurements. --- mods/HUD/mcl_formspec/init.lua | 5 +++++ mods/HUD/mcl_inventory/init.lua | 32 +++++++++++--------------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index 90a0bd1bf..06453d075 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -5,12 +5,17 @@ mcl_formspec = {} local mcl_formspec = mcl_formspec mcl_formspec.padding = 0.375 +mcl_formspec.margin = 0.078125 -------------------------------------------------------------------------------- -- Label -- -------------------------------------------------------------------------------- + mcl_formspec.label_color = "#313131" mcl_formspec.label_size = tonumber(minetest.settings:get("mcl_label_font_size")) or 24 +-- NOTE: labels are vertically aligned to "center" (which is also affected by padding of the font) in the new coordinate system. +mcl_formspec.label_height = 0.625 +mcl_formspec.label_y_offset = 0.25 * mcl_formspec.label_height -- offset to counter the font padding. mcl_formspec.label_style = string.format("style_type[label;font_size=%f]", mcl_formspec.label_size) mcl_formspec.label_style_reset = "style_type[label;font=;font_size=;noclip=]" diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 527cba46f..a7d791116 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -5,10 +5,15 @@ local S = minetest.get_translator(minetest.get_current_modname()) local F = minetest.formspec_escape local C = minetest.colorize +local margin = mcl_formspec.margin local padding = mcl_formspec.padding local bu = mcl_formspec.itemslot_bu local iu = mcl_formspec.itemslot_iu +local label_color = mcl_formspec.label_color +local label_height = mcl_formspec.label_height +local label_y_offset = mcl_formspec.label_y_offset + mcl_inventory = {} --local mod_player = minetest.get_modpath("mcl_player") @@ -149,26 +154,14 @@ local function set_inventory(player, armor_change_only) } -- Crafting formspec - -- NOTE: according to screenshots from MC inventory dialog, crafting_x - -- doesn't need to offset 0.25 itemslot unit to the left, but if it's not - -- included, the crafting output itemslot will protrude out of the inner - -- inventory dialog and look awkward. So we deviate from MC for the sake of - -- looking nicer. - -- NOTE: text usually depends on eyeballed values due to how minetest - -- handles them. e.g.: labels are verically aligned to "center" (which is - -- also affected by padding of the font) in the new coordinate system. - local crafting_label_height = 0.625 -- eyeballed value. - local crafting_label_y = padding + 0.25 * crafting_label_height -- 0.25 * crafting_label_height for nicer text spacing, see notes. - local crafting_x = padding + 5 * iu - 0.25 * iu -- 0.25 * iu offset for nicer crafting formspec spacing, see notes. - local crafting_y = padding + crafting_label_height + local crafting_x = padding + 5 * iu + local crafting_y = padding + label_height local crafting_length = 2 * iu - local crafting_arrow_spacing = 0.078125 -- eyeballed value - local crafting_arrow_x = crafting_x + crafting_length + crafting_arrow_spacing + local crafting_arrow_x = crafting_x + crafting_length + margin local crafting_arrow_y = crafting_y + iu / 2 - local crafting_arrow_length = iu local crafting_formspec = table.concat{ "label[", - crafting_x - bu, ",", crafting_label_y, ";", + crafting_x - bu, ",", padding + label_y_offset, ";", F(C(mcl_formspec.label_color, S("Crafting"))), "]", mcl_formspec.create_itemslot_bg(crafting_x, crafting_y, 2, 2), @@ -180,12 +173,9 @@ local function set_inventory(player, armor_change_only) crafting_arrow_x, ",", crafting_arrow_y, ";", "1,1;crafting_formspec_arrow.png", "]", - mcl_formspec.create_itemslot_bg( - crafting_arrow_x + crafting_arrow_length + crafting_arrow_spacing, crafting_arrow_y, - 1, 1 - ), + mcl_formspec.create_itemslot_bg(crafting_arrow_x + 1 + margin + bu, crafting_arrow_y, 1, 1), "list[current_player;craftpreview;", - crafting_arrow_x + crafting_arrow_length + crafting_arrow_spacing, ",", crafting_arrow_y, ";", + crafting_arrow_x + 1 + margin + bu, ",", crafting_arrow_y, ";", "1,1;", "]", } -- 2.40.1 From 3cad45ed2e2ece02e4429ea42629256c0be96906 Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Thu, 30 Sep 2021 20:53:32 +0800 Subject: [PATCH 12/20] [WIP] obtain values at runtime. --- mods/HUD/mcl_inventory/init.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index a7d791116..9e78773da 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -5,15 +5,6 @@ local S = minetest.get_translator(minetest.get_current_modname()) local F = minetest.formspec_escape local C = minetest.colorize -local margin = mcl_formspec.margin -local padding = mcl_formspec.padding -local bu = mcl_formspec.itemslot_bu -local iu = mcl_formspec.itemslot_iu - -local label_color = mcl_formspec.label_color -local label_height = mcl_formspec.label_height -local label_y_offset = mcl_formspec.label_y_offset - mcl_inventory = {} --local mod_player = minetest.get_modpath("mcl_player") @@ -60,6 +51,15 @@ function return_fields(player, name) end local function set_inventory(player, armor_change_only) + local margin = mcl_formspec.margin + local padding = mcl_formspec.padding + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu + + local label_color = mcl_formspec.label_color + local label_height = mcl_formspec.label_height + local label_y_offset = mcl_formspec.label_y_offset + if minetest.is_creative_enabled(player:get_player_name()) then if armor_change_only then -- Stay on survival inventory plage if only the armor has been changed -- 2.40.1 From f43fa38003bc6f0dc070a3eea55cd5993e988b0c Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Thu, 30 Sep 2021 22:43:56 +0800 Subject: [PATCH 13/20] [WIP] localised names. --- mods/HUD/mcl_inventory/init.lua | 9 +++++---- mods/ITEMS/mcl_chests/init.lua | 8 +++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 9e78773da..b5355ae70 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -1,12 +1,13 @@ -local minetest, math, table, mcl_formspec = - minetest, math, table, mcl_formspec +local minetest, math, table, mcl_armor, mcl_formspec, mcl_player = + minetest, math, table, mcl_armor, mcl_formspec, mcl_player + +mcl_inventory = {} +local mcl_inventory = mcl_inventory local S = minetest.get_translator(minetest.get_current_modname()) local F = minetest.formspec_escape local C = minetest.colorize -mcl_inventory = {} - --local mod_player = minetest.get_modpath("mcl_player") --local mod_craftguide = minetest.get_modpath("mcl_craftguide") diff --git a/mods/ITEMS/mcl_chests/init.lua b/mods/ITEMS/mcl_chests/init.lua index 3976e4d6f..09627f3a6 100644 --- a/mods/ITEMS/mcl_chests/init.lua +++ b/mods/ITEMS/mcl_chests/init.lua @@ -1,11 +1,9 @@ +local minetest, math, string, table, mcl_formspec, mcl_util = + minetest, math, string, table, mcl_formspec, mcl_util + local S = minetest.get_translator(minetest.get_current_modname()) local F = minetest.formspec_escape local C = minetest.colorize - -local string = string -local table = table -local math = math - local sf = string.format local mod_doc = minetest.get_modpath("doc") -- 2.40.1 From 86f32ee1ae5d1cbab69579b24863d41c2abd41dd Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Fri, 1 Oct 2021 02:23:33 +0800 Subject: [PATCH 14/20] [WIP] Update chest and ender chest formspec. --- mods/HUD/mcl_formspec/init.lua | 11 +- mods/ITEMS/mcl_chests/init.lua | 297 ++++++++++++++++++++++++--------- 2 files changed, 225 insertions(+), 83 deletions(-) diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index 06453d075..30c35b588 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -4,9 +4,6 @@ local minetest, string, table = mcl_formspec = {} local mcl_formspec = mcl_formspec -mcl_formspec.padding = 0.375 -mcl_formspec.margin = 0.078125 - -------------------------------------------------------------------------------- -- Label -- -------------------------------------------------------------------------------- @@ -127,3 +124,11 @@ function mcl_formspec.create_itemslot_bg(x, y, w, h, def) end return out end + +-------------------------------------------------------------------------------- +-- Miscellaneous -- +-------------------------------------------------------------------------------- + +mcl_formspec.margin = 0.078125 +mcl_formspec.padding = 0.375 +mcl_formspec.padding_slim = mcl_formspec.padding - mcl_formspec.itemslot_bu diff --git a/mods/ITEMS/mcl_chests/init.lua b/mods/ITEMS/mcl_chests/init.lua index 09627f3a6..a41825a34 100644 --- a/mods/ITEMS/mcl_chests/init.lua +++ b/mods/ITEMS/mcl_chests/init.lua @@ -480,27 +480,59 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile name = S("Chest") end + local margin = mcl_formspec.margin + local padding = mcl_formspec.padding + local padding_slim = mcl_formspec.padding_slim + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu + + local label_color = mcl_formspec.label_color + local label_height = mcl_formspec.label_height + local label_y_offset = mcl_formspec.label_y_offset + + local chest_inv_location = sf("nodemeta:%d,%d,%d", pos.x, pos.y, pos.z) + local chest_formspec = table.concat{ + "label[", + padding - bu, ",", padding_slim + label_y_offset, ";", + F(C(mcl_formspec.label_color, name)), + "]", + mcl_formspec.create_itemslot_bg(padding, padding_slim + label_height, 9, 3), + "list[", chest_inv_location, ";main;", + padding, ",", padding_slim + label_height, ";", + "9,3;", + "]", + } + + local inventory_label_y = 2 * padding_slim + label_height + 3 * iu + local inventory_formspec = table.concat{ + "label[", + padding - bu, ",", inventory_label_y + label_y_offset, ";", + F(C(mcl_formspec.label_color, S("Crafting"))), + "]", + mcl_formspec.create_itemslot_bg(padding, inventory_label_y + label_height, 9, 3), + mcl_formspec.create_itemslot_bg(padding, inventory_label_y + 3 * iu + padding + label_height, 9, 1), + "list[current_player;main;", + padding, ",", inventory_label_y + label_height, ";", + "9,3;9", + "]", + "list[current_player;main;", + padding, ",", inventory_label_y + 3 * iu + padding + label_height, ";", + "9,1;", + "]", + } + minetest.show_formspec(clicker:get_player_name(), sf("mcl_chests:%s_%s_%s_%s", canonical_basename, pos.x, pos.y, pos.z), table.concat({ "formspec_version[4]", - "size[11.75,10.425]", - mcl_formspec.label_size, + "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 7 * iu + 2 * (padding_slim + label_height) - 2 * bu, "]", + mcl_formspec.label_style, + mcl_formspec.itemslot_style, - "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", + chest_formspec, + inventory_formspec, - mcl_formspec.create_itemslot_bg(0.375, 0.75, 9, 3), - sf("list[nodemeta:%s,%s,%s;main;0.375,0.75;9,3;]", pos.x, pos.y, pos.z), - - "label[0.375,4.7;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", - - mcl_formspec.create_itemslot_bg(0.375, 5.1, 9, 3), - "list[current_player;main;0.375,5.1;9,3;9]", - - mcl_formspec.create_itemslot_bg(0.375, 9.05, 9, 1), - "list[current_player;main;0.375,9.05;9,1;]", - - sf("listring[nodemeta:%s,%s,%s;main]", pos.x, pos.y, pos.z), + "listring[", chest_inv_location, ";main]", "listring[current_player;main]", }) ) @@ -640,37 +672,71 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile name = S("Large Chest") end + local margin = mcl_formspec.margin + local padding = mcl_formspec.padding + local padding_slim = mcl_formspec.padding_slim + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu + + local label_color = mcl_formspec.label_color + local label_height = mcl_formspec.label_height + local label_y_offset = mcl_formspec.label_y_offset + + local chest_inv_location = sf("nodemeta:%d,%d,%d", pos.x, pos.y, pos.z) + local chest_other_inv_location = sf("nodemeta:%d,%d,%d", pos_other.x, pos_other.y, pos_other.z) + local chest_formspec = table.concat{ + "label[", + padding - bu, ",", padding_slim + label_y_offset, ";", + F(C(mcl_formspec.label_color, name)), + "]", + mcl_formspec.create_itemslot_bg(padding, padding_slim + label_height, 9, 6), + "list[", chest_inv_location, ";main;", + padding, ",", padding_slim + label_height, ";", + "9,3;", + "]", + "list[", chest_other_inv_location, ";main;", + padding, ",", padding_slim + label_height + 3 * iu, ";", + "9,3;", + "]", + } + + local inventory_label_y = 2 * padding_slim + label_height + 6 * iu + local inventory_formspec = table.concat{ + "label[", + padding - bu, ",", inventory_label_y + label_y_offset, ";", + F(C(mcl_formspec.label_color, S("Crafting"))), + "]", + mcl_formspec.create_itemslot_bg(padding, inventory_label_y + label_height, 9, 3), + mcl_formspec.create_itemslot_bg(padding, inventory_label_y + 3 * iu + padding + label_height, 9, 1), + "list[current_player;main;", + padding, ",", inventory_label_y + label_height, ";", + "9,3;9", + "]", + "list[current_player;main;", + padding, ",", inventory_label_y + 3 * iu + padding + label_height, ";", + "9,1;", + "]", + } + minetest.show_formspec(clicker:get_player_name(), sf("mcl_chests:%s_%s_%s_%s", canonical_basename, pos.x, pos.y, pos.z), table.concat({ "formspec_version[4]", - "size[11.75,14.15]", + "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 10 * iu + 2 * (padding_slim + label_height) - 2 * bu, "]", mcl_formspec.label_style, + mcl_formspec.itemslot_style, - "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", + chest_formspec, + inventory_formspec, - mcl_formspec.create_itemslot_bg(0.375, 0.75, 9, 3), - sf("list[nodemeta:%s,%s,%s;main;0.375,0.75;9,3;]", pos.x, pos.y, pos.z), - - mcl_formspec.create_itemslot_bg(0.375, 4.5, 9, 3), - sf("list[nodemeta:%s,%s,%s;main;0.375,4.5;9,3;]", pos_other.x, pos_other.y, pos_other.z), - - "label[0.375,8.45;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", - - mcl_formspec.create_itemslot_bg(0.375, 8.825, 9, 3), - "list[current_player;main;0.375,8.825;9,3;9]", - - mcl_formspec.create_itemslot_bg(0.375, 12.775, 9, 1), - "list[current_player;main;0.375,12.775;9,1;]", - - --BEGIN OF LISTRING WORKAROUND + -- BEGIN listring workaround "listring[current_player;main]", - sf("listring[nodemeta:%s,%s,%s;input]", pos.x, pos.y, pos.z), - --END OF LISTRING WORKAROUND - "listring[current_player;main]".. - sf("listring[nodemeta:%s,%s,%s;main]", pos.x, pos.y, pos.z), + "listring[", chest_inv_location, ";input]", + -- END listring workaround "listring[current_player;main]", - sf("listring[nodemeta:%s,%s,%s;main]", pos_other.x, pos_other.y, pos_other.z), + "listring[", chest_inv_location, ";main]", + "listring[current_player;main]", + "listring[", chest_other_inv_location, ";main]", }) ) @@ -799,37 +865,71 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile name = S("Large Chest") end + local margin = mcl_formspec.margin + local padding = mcl_formspec.padding + local padding_slim = mcl_formspec.padding_slim + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu + + local label_color = mcl_formspec.label_color + local label_height = mcl_formspec.label_height + local label_y_offset = mcl_formspec.label_y_offset + + local chest_inv_location = sf("nodemeta:%d,%d,%d", pos.x, pos.y, pos.z) + local chest_other_inv_location = sf("nodemeta:%d,%d,%d", pos_other.x, pos_other.y, pos_other.z) + local chest_formspec = table.concat{ + "label[", + padding - bu, ",", padding_slim + label_y_offset, ";", + F(C(mcl_formspec.label_color, name)), + "]", + mcl_formspec.create_itemslot_bg(padding, padding_slim + label_height, 9, 6), + "list[", chest_other_inv_location, ";main;", + padding, ",", padding_slim + label_height, ";", + "9,3;", + "]", + "list[", chest_inv_location, ";main;", + padding, ",", padding_slim + label_height + 3 * iu, ";", + "9,3;", + "]", + } + + local inventory_label_y = 2 * padding_slim + label_height + 6 * iu + local inventory_formspec = table.concat{ + "label[", + padding - bu, ",", inventory_label_y + label_y_offset, ";", + F(C(mcl_formspec.label_color, S("Crafting"))), + "]", + mcl_formspec.create_itemslot_bg(padding, inventory_label_y + label_height, 9, 3), + mcl_formspec.create_itemslot_bg(padding, inventory_label_y + 3 * iu + padding + label_height, 9, 1), + "list[current_player;main;", + padding, ",", inventory_label_y + label_height, ";", + "9,3;9", + "]", + "list[current_player;main;", + padding, ",", inventory_label_y + 3 * iu + padding + label_height, ";", + "9,1;", + "]", + } + minetest.show_formspec(clicker:get_player_name(), sf("mcl_chests:%s_%s_%s_%s", canonical_basename, pos.x, pos.y, pos.z), table.concat({ "formspec_version[4]", - "size[11.75,14.15]", + "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 10 * iu + 2 * (padding_slim + label_height) - 2 * bu, "]", mcl_formspec.label_style, + mcl_formspec.itemslot_style, - "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", + chest_formspec, + inventory_formspec, - mcl_formspec.create_itemslot_bg(0.375, 0.75, 9, 3), - sf("list[nodemeta:%s,%s,%s;main;0.375,0.75;9,3;]", pos_other.x, pos_other.y, pos_other.z), - - mcl_formspec.create_itemslot_bg(0.375, 4.5, 9, 3), - sf("list[nodemeta:%s,%s,%s;main;0.375,4.5;9,3;]", pos.x, pos.y, pos.z), - - "label[0.375,8.45;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", - - mcl_formspec.create_itemslot_bg(0.375, 8.825, 9, 3), - "list[current_player;main;0.375,8.825;9,3;9]", - - mcl_formspec.create_itemslot_bg(0.375, 12.775, 9, 1), - "list[current_player;main;0.375,12.775;9,1;]", - - --BEGIN OF LISTRING WORKAROUND + -- BEGIN listring workaround "listring[current_player;main]", - sf("listring[nodemeta:%s,%s,%s;input]", pos.x, pos.y, pos.z), - --END OF LISTRING WORKAROUND - "listring[current_player;main]".. - sf("listring[nodemeta:%s,%s,%s;main]", pos_other.x, pos_other.y, pos_other.z), + "listring[", chest_inv_location, ";input]", + -- END listring workaround "listring[current_player;main]", - sf("listring[nodemeta:%s,%s,%s;main]", pos.x, pos.y, pos.z), + "listring[", chest_inv_location, ";main]", + "listring[current_player;main]", + "listring[", chest_other_inv_location, ";main]", }) ) @@ -1030,26 +1130,6 @@ minetest.register_node("mcl_chests:ender_chest", { end, }) -local formspec_ender_chest = table.concat({ - "formspec_version[4]", - "size[11.75,10.425]", - - "label[0.375,0.375;"..F(C(mcl_formspec.label_color, S("Ender Chest"))).."]", - - mcl_formspec.create_itemslot_bg(0.375, 0.75, 9, 3), - "list[current_player;enderchest;0.375,0.75;9,3;]", - - "label[0.375,4.7;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", - - mcl_formspec.create_itemslot_bg(0.375, 5.1, 9, 3), - "list[current_player;main;0.375,5.1;9,3;9]", - - mcl_formspec.create_itemslot_bg(0.375, 9.05, 9, 1), - "list[current_player;main;0.375,9.05;9,1;]", - - "listring[current_player;enderchest]", - "listring[current_player;main]", -}) minetest.register_node("mcl_chests:ender_chest_small", { @@ -1088,7 +1168,64 @@ minetest.register_node("mcl_chests:ender_chest_small", { -- won't open if there is no space from the top return false end - minetest.show_formspec(clicker:get_player_name(), "mcl_chests:ender_chest_"..clicker:get_player_name(), formspec_ender_chest) + + local margin = mcl_formspec.margin + local padding = mcl_formspec.padding + local padding_slim = mcl_formspec.padding_slim + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu + + local label_color = mcl_formspec.label_color + local label_height = mcl_formspec.label_height + local label_y_offset = mcl_formspec.label_y_offset + + local chest_formspec = table.concat{ + "label[", + padding - bu, ",", padding_slim + label_y_offset, ";", + F(C(mcl_formspec.label_color, S("Ender Chest"))), + "]", + mcl_formspec.create_itemslot_bg(padding, padding_slim + label_height, 9, 3), + "list[current_player;enderchest;", + padding, ",", padding_slim + label_height, ";", + "9,3;", + "]", + } + + local inventory_label_y = 2 * padding_slim + label_height + 3 * iu + local inventory_formspec = table.concat{ + "label[", + padding - bu, ",", inventory_label_y + label_y_offset, ";", + F(C(mcl_formspec.label_color, S("Crafting"))), + "]", + mcl_formspec.create_itemslot_bg(padding, inventory_label_y + label_height, 9, 3), + mcl_formspec.create_itemslot_bg(padding, inventory_label_y + 3 * iu + padding + label_height, 9, 1), + "list[current_player;main;", + padding, ",", inventory_label_y + label_height, ";", + "9,3;9", + "]", + "list[current_player;main;", + padding, ",", inventory_label_y + 3 * iu + padding + label_height, ";", + "9,1;", + "]", + } + + minetest.show_formspec(clicker:get_player_name(), + "mcl_chests:ender_chest_"..clicker:get_player_name(), + table.concat{ + "formspec_version[4]", + "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 7 * iu + 2 * (padding_slim + label_height) - 2 * bu, "]", + + mcl_formspec.label_style, + mcl_formspec.itemslot_style, + + chest_formspec, + inventory_formspec, + + "listring[current_player;enderchest]", + "listring[current_player;main]", + } + ) + player_chest_open(clicker, pos, "mcl_chests:ender_chest_small", {"mcl_chests_ender.png"}, node.param2, false, "mcl_chests_enderchest", "mcl_chests_chest") end, on_receive_fields = function(pos, formname, fields, sender) -- 2.40.1 From f488d87b4562ff4f0410ff1768a064c2305c0f5f Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Fri, 1 Oct 2021 11:58:00 +0800 Subject: [PATCH 15/20] [WIP] update shulker box formspec. --- mods/ITEMS/mcl_chests/init.lua | 61 +++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/mods/ITEMS/mcl_chests/init.lua b/mods/ITEMS/mcl_chests/init.lua index a41825a34..f59cbeba5 100644 --- a/mods/ITEMS/mcl_chests/init.lua +++ b/mods/ITEMS/mcl_chests/init.lua @@ -1299,27 +1299,58 @@ local function formspec_shulker_box(name) name = S("Shulker Box") end - return table.concat({ + local margin = mcl_formspec.margin + local padding = mcl_formspec.padding + local padding_slim = mcl_formspec.padding_slim + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu + + local label_color = mcl_formspec.label_color + local label_height = mcl_formspec.label_height + local label_y_offset = mcl_formspec.label_y_offset + + local shulker_box_formspec = table.concat{ + "label[", + padding - bu, ",", padding_slim + label_y_offset, ";", + F(C(mcl_formspec.label_color, name)), + "]", + mcl_formspec.create_itemslot_bg(padding, padding_slim + label_height, 9, 3), + "list[context;main;", + padding, ",", padding_slim + label_height, ";", + "9,3;", + "]", + } + + local inventory_label_y = 2 * padding_slim + label_height + 3 * iu + local inventory_formspec = table.concat{ + "label[", + padding - bu, ",", inventory_label_y + label_y_offset, ";", + F(C(mcl_formspec.label_color, S("Crafting"))), + "]", + mcl_formspec.create_itemslot_bg(padding, inventory_label_y + label_height, 9, 3), + mcl_formspec.create_itemslot_bg(padding, inventory_label_y + 3 * iu + padding + label_height, 9, 1), + "list[current_player;main;", + padding, ",", inventory_label_y + label_height, ";", + "9,3;9", + "]", + "list[current_player;main;", + padding, ",", inventory_label_y + 3 * iu + padding + label_height, ";", + "9,1;", + "]", + } + + return table.concat{ "formspec_version[4]", - "size[11.75,10.425]", + "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 7 * iu + 2 * (padding_slim + label_height) - 2 * bu, "]", mcl_formspec.label_style, + mcl_formspec.itemslot_style, - "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", - - mcl_formspec.create_itemslot_bg(0.375, 0.75, 9, 3), - "list[context;main;0.375,0.75;9,3;]", - - "label[0.375,4.7;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", - - mcl_formspec.create_itemslot_bg(0.375, 5.1, 9, 3), - "list[current_player;main;0.375,5.1;9,3;9]", - - mcl_formspec.create_itemslot_bg(0.375, 9.05, 9, 1), - "list[current_player;main;0.375,9.05;9,1;]", + shulker_box_formspec, + inventory_formspec, "listring[context;main]", "listring[current_player;main]", - }) + } end local function set_shulkerbox_meta(nmeta, imeta) -- 2.40.1 From 49e50d8e6a6ed507bc962fa428821adfe7e7dd75 Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Fri, 1 Oct 2021 11:58:28 +0800 Subject: [PATCH 16/20] [WIP] codestyle. --- mods/HUD/mcl_inventory/init.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index b5355ae70..a02c6b5a7 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -52,15 +52,6 @@ function return_fields(player, name) end local function set_inventory(player, armor_change_only) - local margin = mcl_formspec.margin - local padding = mcl_formspec.padding - local bu = mcl_formspec.itemslot_bu - local iu = mcl_formspec.itemslot_iu - - local label_color = mcl_formspec.label_color - local label_height = mcl_formspec.label_height - local label_y_offset = mcl_formspec.label_y_offset - if minetest.is_creative_enabled(player:get_player_name()) then if armor_change_only then -- Stay on survival inventory plage if only the armor has been changed @@ -71,6 +62,15 @@ local function set_inventory(player, armor_change_only) return end + local margin = mcl_formspec.margin + local padding = mcl_formspec.padding + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu + + local label_color = mcl_formspec.label_color + local label_height = mcl_formspec.label_height + local label_y_offset = mcl_formspec.label_y_offset + local inv = player:get_inventory() inv:set_width("craft", 2) inv:set_size("craft", 4) -- 2.40.1 From c815277b1623b57d45e35e3ac8e67c5723417ebd Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Sun, 3 Oct 2021 02:42:33 +0800 Subject: [PATCH 17/20] [WIP] codestyle. --- mods/HUD/mcl_inventory/init.lua | 46 ++------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index a02c6b5a7..915d95208 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -12,7 +12,7 @@ local C = minetest.colorize --local mod_craftguide = minetest.get_modpath("mcl_craftguide") -- Returns a single itemstack in the given inventory to the main inventory, or drop it when there's no space left -function return_item(itemstack, dropper, pos, inv) +local function return_item(itemstack, dropper, pos, inv) if dropper:is_player() then -- Return to main inventory if inv:room_for_item("main", itemstack) then @@ -40,7 +40,7 @@ function return_item(itemstack, dropper, pos, inv) end -- Return items in the given inventory list (name) to the main inventory, or drop them if there is no space left -function return_fields(player, name) +local function return_fields(player, name) local inv = player:get_inventory() local list = inv:get_list(name) if not list then return end @@ -233,48 +233,6 @@ local function set_inventory(player, armor_change_only) "listring[current_player;main]", }) - local form2 = "size[9,8.75]".. - --"background[-0.19,-0.25;9.41,9.49;crafting_formspec_bg.png]".. - ppreview_formspec.. - --armor - "list[current_player;armor;0,0;1,1;1]".. - "list[current_player;armor;0,1;1,1;2]".. - "list[current_player;armor;0,2;1,1;3]".. - "list[current_player;armor;0,3;1,1;4]".. - mcl_formspec.get_itemslot_bg(0,0,1,1).. - mcl_formspec.get_itemslot_bg(0,1,1,1).. - mcl_formspec.get_itemslot_bg(0,2,1,1).. - mcl_formspec.get_itemslot_bg(0,3,1,1).. - --armor_slot_imgs.. - -- craft and inventory - "label[0,4;"..F(C("#313131", S("Inventory"))).."]".. - "list[current_player;main;0,4.5;9,3;9]".. - "list[current_player;main;0,7.74;9,1;]".. - "label[4,0.5;"..F(C("#313131", S("Crafting"))).."]".. - "list[current_player;craft;4,1;2,2]".. - "list[current_player;craftpreview;7,1.5;1,1;]".. - mcl_formspec.get_itemslot_bg(0,4.5,9,3).. - mcl_formspec.get_itemslot_bg(0,7.74,9,1).. - mcl_formspec.get_itemslot_bg(4,1,2,2).. - mcl_formspec.get_itemslot_bg(7,1.5,1,1).. - -- crafting guide button - "image_button[4.5,3;1,1;craftguide_book.png;__mcl_craftguide;]".. - "tooltip[__mcl_craftguide;"..F(S("Recipe book")).."]".. - -- help button - "image_button[8,3;1,1;doc_button_icon_lores.png;__mcl_doc;]".. - "tooltip[__mcl_doc;"..F(S("Help")).."]".. - -- skins button - "image_button[3,3;1,1;mcl_skins_button.png;__mcl_skins;]".. - "tooltip[__mcl_skins;"..F(S("Select player skin")).."]".. - -- achievements button - "image_button[7,3;1,1;mcl_achievements_button.png;__mcl_achievements;]".. - "tooltip[__mcl_achievements;"..F(S("Achievements")).."]".. - -- for shortcuts - "listring[current_player;main]".. - "listring[current_player;armor]".. - "listring[current_player;main]" .. - "listring[current_player;craft]" .. - "listring[current_player;main]" player:set_inventory_formspec(form) end -- 2.40.1 From 3b39b0438421cd502bc422cf94b06a294206e56c Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Sun, 3 Oct 2021 02:46:54 +0800 Subject: [PATCH 18/20] [WIP] refactor mcl_inventory formspec. --- mods/HUD/mcl_formspec/init.lua | 12 ++ mods/HUD/mcl_inventory/init.lua | 321 +++++++++++++++++++------------- 2 files changed, 200 insertions(+), 133 deletions(-) diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index 30c35b588..d304f0f71 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -4,6 +4,9 @@ local minetest, string, table = mcl_formspec = {} local mcl_formspec = mcl_formspec +local F = minetest.formspec_escape +local C = minetest.colorize + -------------------------------------------------------------------------------- -- Label -- -------------------------------------------------------------------------------- @@ -16,6 +19,15 @@ mcl_formspec.label_y_offset = 0.25 * mcl_formspec.label_height -- offset to coun mcl_formspec.label_style = string.format("style_type[label;font_size=%f]", mcl_formspec.label_size) mcl_formspec.label_style_reset = "style_type[label;font=;font_size=;noclip=]" +function mcl_formspec.create_label(x, y, text) + return table.concat{ + "label[", + x - mcl_formspec.itemslot_bu, ",", y + mcl_formspec.label_y_offset, ";", + F(C(mcl_formspec.label_color, text)), + "]", + } +end + function mcl_formspec.get_itemslot_bg(x, y, w, h) local out = "" for i = 0, w - 1, 1 do diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 915d95208..8d8c19b14 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -51,6 +51,162 @@ local function return_fields(player, name) end end +function mcl_inventory.formspec_armor(x, y, extra) + -- extra params: + -- { inv=... } + local iu = mcl_formspec.itemslot_iu + + local formspec = table.concat{ + mcl_formspec.create_itemslot_bg(x, y, 1, 4), + "list[current_player;armor;", + x, ",", y, ";", + "1,4;", + "]", + } + + local armor_slots = {"helmet", "chestplate", "leggings", "boots"} + for a=1,4 do + if extra.inv:get_stack("armor", a+1):is_empty() then + formspec = table.concat{ + formspec, + "image[", + x, ",", y + (a - 1) * iu, ";", + "1,1;mcl_inventory_empty_armor_slot_", armor_slots[a], ".png", + "]" + } + end + end + + return formspec +end + +mcl_inventory.FORMSPEC_PLAYER_PREVIEW_WIDTH_FACTOR = 102 / 108 -- eyeballed value +function mcl_inventory.formspec_player_preview(x, y, extra) + -- extra params: + -- { player=... } + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu + + local width = mcl_inventory.FORMSPEC_PLAYER_PREVIEW_WIDTH_FACTOR * 3 * iu + local height = 4 * iu + local formspec = table.concat{ + "background9[", + x - bu, ",", y - bu, ";", + width, ",", height, ";", + "mcl_inventory_player_preview_box9.png;false;3", + "]", + } + if minetest.settings:get_bool("3d_player_preview", true) then + formspec = table.concat{ + formspec, + -- TODO: model is sometimes offsetted to the right due to an engine bug(or possibly a model bug). + mcl_player.get_player_formspec_model(extra.player, x - bu, y - bu, width, height, "") + } + else + formspec = table.concat{ + formspec, + -- TODO: better image size+centered. Or better, remove it. see #1869 + "image[", x, ",", y, ";", width, ",", height, ";", mcl_player.player_get_preview(extra.player), "]", + } + end + + return formspec +end + +function mcl_inventory.formspec_left_hand(x, y, extra) + -- extra params: + -- { inv=... } + -- TODO: implement left hand + -- NOTE: we're probably not using armor index #4, change as necessary. + if true then return "" end + + -- Left hand slot formspec + local formspec = table.concat{ + -- left hand presupport + mcl_formspec.create_itemslot_bg(x, y, 1, 1), + "list[current_player;armor;", + x, ",", y, ";", + "1,1;4", + "]", + + } + + if extra.inv:get_stack("armor", 5):is_empty() then + formspec = table.concat{ + formspec, + "image[", + x, ",", y, ";", + "1,1;mcl_inventory_empty_armor_slot_shield.png", + "]" + } + end + + return formspec +end + +function mcl_inventory.formspec_crafting(x, y, extra) + -- Optional params: extra + -- extra params: + -- { * } + local margin = mcl_formspec.margin + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu + + local length = 2 * iu + local arrow_x = x + length + margin + local arrow_y = y + iu / 2 + local output_x = arrow_x + 1 + margin + bu + local formspec = table.concat{ + (extra and extra.label_y) and mcl_formspec.create_label(x, extra.label_y, S("Crafting")) or "", + mcl_formspec.create_itemslot_bg(x, y, 2, 2), + "list[current_player;craft;", + x, ",", y, ";", + "2,2", + "]", + + "image[", + arrow_x, ",", arrow_y, ";", + "1,1;crafting_formspec_arrow.png", + "]", + + mcl_formspec.create_itemslot_bg(output_x, arrow_y, 1, 1), + "list[current_player;craftpreview;", + output_x, ",", arrow_y, ";", + "1,1;", + "]", + } + + return formspec +end + +function mcl_inventory.formspec_inventory(x, y, extra) + -- Optional params: extra + -- extra params: + -- { * * } + local iu = mcl_formspec.itemslot_iu + local formspec = table.concat{ + (extra and extra.label_y) and mcl_formspec.create_label(x, extra.label_y, S("Inventory")) or "", + mcl_formspec.create_itemslot_bg(x, y, 9, 3), + "list[current_player;main;", + x, ",", y, ";", + "9,3;9", + "]", + } + + if extra and extra.hotbar_y then + formspec = table.concat{ + formspec, + mcl_formspec.create_itemslot_bg(x, extra.hotbar_y, 9, 1), + "list[current_player;main;", + x, ",", extra.hotbar_y, ";", + "9,1;", + "]", + } + end + + return formspec +end + local function set_inventory(player, armor_change_only) if minetest.is_creative_enabled(player:get_player_name()) then if armor_change_only then @@ -62,150 +218,49 @@ local function set_inventory(player, armor_change_only) return end - local margin = mcl_formspec.margin - local padding = mcl_formspec.padding - local bu = mcl_formspec.itemslot_bu - local iu = mcl_formspec.itemslot_iu - - local label_color = mcl_formspec.label_color - local label_height = mcl_formspec.label_height - local label_y_offset = mcl_formspec.label_y_offset - local inv = player:get_inventory() inv:set_width("craft", 2) inv:set_size("craft", 4) - -- Armor slots formspec - local armor_slots = {"helmet", "chestplate", "leggings", "boots"} - local armor_slots_formspec = "" - for a=1,4 do - local b = a - 1 - local y = padding + b * iu - armor_slots_formspec = table.concat{ - armor_slots_formspec, - mcl_formspec.create_itemslot_bg(padding, y, 1, 1), - } + local padding = mcl_formspec.padding + local padding_slim = mcl_formspec.padding_slim + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu - if inv:get_stack("armor", a+1):is_empty() then - armor_slots_formspec = table.concat{ - armor_slots_formspec, - "image[", - padding, ",", y, ";", - "1,1;mcl_inventory_empty_armor_slot_", armor_slots[a], ".png", - "]" - } - end - - armor_slots_formspec = table.concat{ - armor_slots_formspec, - "list[current_player;armor;", - padding, ",", y, ";", - "1,1;", a, - "]", - } - end - - -- Player preview formspec - local ppreview_width_factor = 102 / 108 -- eyeballed value - local ppreview_width = ppreview_width_factor * 3 * iu - local ppreview_height = 4 * iu - local ppreview_x = padding + iu - local ppreview_formspec = table.concat{ - "background9[", - ppreview_x - bu, ",", padding - bu, ";", - ppreview_width, ",", ppreview_height, ";", - "mcl_inventory_player_preview_box9.png;false;3", - "]", - } - if minetest.settings:get_bool("3d_player_preview", true) then - ppreview_formspec = table.concat{ - ppreview_formspec, - -- TODO: model is offsetted to the right. investigate. - mcl_player.get_player_formspec_model( - player, - ppreview_x - bu, padding - bu, - ppreview_width, ppreview_height, - "" - ) - } - else - ppreview_formspec = table.concat{ - ppreview_formspec, - -- TODO: better image size+centered. - "image[", - ppreview_x, ",", padding, ";", - 3.5, ",", 4 + padding + 3 * between, ";", - mcl_player.player_get_preview(player), - "]", - } - end - - -- Left hand slot formspec - -- TODO: implement left hand - local left_hand_x = ppreview_x + ppreview_width - local left_hand_y = padding + ppreview_height - iu - local left_hand_formspec = table.concat{ - -- left hand presupport - mcl_formspec.create_itemslot_bg(left_hand_x, left_hand_y, 1, 1), - "list[current_player;armor;", - left_hand_x, ",", left_hand_y, ";", - "1,1;4", - "]", - - } - - -- Crafting formspec - local crafting_x = padding + 5 * iu - local crafting_y = padding + label_height - local crafting_length = 2 * iu - local crafting_arrow_x = crafting_x + crafting_length + margin - local crafting_arrow_y = crafting_y + iu / 2 - local crafting_formspec = table.concat{ - "label[", - crafting_x - bu, ",", padding + label_y_offset, ";", - F(C(mcl_formspec.label_color, S("Crafting"))), - "]", - mcl_formspec.create_itemslot_bg(crafting_x, crafting_y, 2, 2), - "list[current_player;craft;", - crafting_x, ",", crafting_y, ";", - "2,2", - "]", - "image[", - crafting_arrow_x, ",", crafting_arrow_y, ";", - "1,1;crafting_formspec_arrow.png", - "]", - mcl_formspec.create_itemslot_bg(crafting_arrow_x + 1 + margin + bu, crafting_arrow_y, 1, 1), - "list[current_player;craftpreview;", - crafting_arrow_x + 1 + margin + bu, ",", crafting_arrow_y, ";", - "1,1;", - "]", - } - - local inventory_formspec = table.concat{ - mcl_formspec.create_itemslot_bg(padding, 2 * padding + 4 * iu, 9, 3), - mcl_formspec.create_itemslot_bg(padding, 3 * padding + 7 * iu, 9, 1), - "list[current_player;main;", - padding, ",", 2 * padding + 4 * iu, ";", - "9,3;9", - "]", - "list[current_player;main;", - padding, ",", 3 * padding + 7 * iu, ";", - "9,1;", - "]", - } + local label_height = mcl_formspec.label_height local form = table.concat({ "formspec_version[4]", - "size[", 2 * padding + 9 * iu - 2 * bu, ",", 4 * padding + 8 * iu - 2 * bu, "]", + "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 2 * padding_slim + 8 * iu - 2 * bu, "]", + mcl_formspec.label_style, mcl_formspec.itemslot_style, - armor_slots_formspec, - ppreview_formspec, - left_hand_formspec, - -- buttons_formspec, - crafting_formspec, - inventory_formspec, + mcl_inventory.formspec_armor(padding, padding, { inv = inv }), + mcl_inventory.formspec_player_preview( + padding + iu, + padding, + { player = player } + ), + mcl_inventory.formspec_left_hand( + padding + iu + mcl_inventory.FORMSPEC_PLAYER_PREVIEW_WIDTH_FACTOR * 3 * iu, + padding + 3 * iu, + { inv = inv } + ), + + mcl_inventory.formspec_crafting( + padding + 5 * iu, + padding + label_height, + { label_y = padding } + ), + + -- mcl_inventory.formspec_buttons() + + mcl_inventory.formspec_inventory( + padding, + padding + padding_slim + 4 * iu, + { hotbar_y = padding + 2 * padding_slim + 7 * iu } + ), -- TODO: skins button -- "image_button[5.375,4.125;1,1;mcl_skins_button.png;__mcl_skins;]", -- 2.40.1 From 9d2320fd34f0cdbdb0ab96996e920258728af56c Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Sun, 3 Oct 2021 04:30:04 +0800 Subject: [PATCH 19/20] [WIP] refactor mcl_chests formspec. --- mods/ITEMS/mcl_chests/init.lua | 306 +++++++++++---------------------- 1 file changed, 101 insertions(+), 205 deletions(-) diff --git a/mods/ITEMS/mcl_chests/init.lua b/mods/ITEMS/mcl_chests/init.lua index f59cbeba5..fc7a717a0 100644 --- a/mods/ITEMS/mcl_chests/init.lua +++ b/mods/ITEMS/mcl_chests/init.lua @@ -1,6 +1,9 @@ local minetest, math, string, table, mcl_formspec, mcl_util = minetest, math, string, table, mcl_formspec, mcl_util +mcl_chests = {} +local mcl_chests = mcl_chests + local S = minetest.get_translator(minetest.get_current_modname()) local F = minetest.formspec_escape local C = minetest.colorize @@ -251,6 +254,21 @@ local function player_chest_close(player) open_chests[name] = nil end +function mcl_chests.formspec_storage(x, y, extra) + -- extra params: + -- { list_inv=..., * } + local formspec = table.concat{ + (extra.label_y and extra.label_text) and mcl_formspec.create_label(x, extra.label_y, extra.label_text) or "", + mcl_formspec.create_itemslot_bg(x, y, 9, 3), + "list[", extra.list_inv, ";", + x, ",", y, ";", + "9,3;", + "]", + } + + return formspec +end + -- This is a helper function to register both chests and trapped chests. Trapped chests will make use of the additional parameters local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tiles_table, hidden, mesecons, on_rightclick_addendum, on_rightclick_addendum_left, on_rightclick_addendum_right, drop, canonical_basename) -- START OF register_chest FUNCTION BODY @@ -480,59 +498,34 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile name = S("Chest") end - local margin = mcl_formspec.margin local padding = mcl_formspec.padding local padding_slim = mcl_formspec.padding_slim local bu = mcl_formspec.itemslot_bu local iu = mcl_formspec.itemslot_iu - local label_color = mcl_formspec.label_color local label_height = mcl_formspec.label_height - local label_y_offset = mcl_formspec.label_y_offset - - local chest_inv_location = sf("nodemeta:%d,%d,%d", pos.x, pos.y, pos.z) - local chest_formspec = table.concat{ - "label[", - padding - bu, ",", padding_slim + label_y_offset, ";", - F(C(mcl_formspec.label_color, name)), - "]", - mcl_formspec.create_itemslot_bg(padding, padding_slim + label_height, 9, 3), - "list[", chest_inv_location, ";main;", - padding, ",", padding_slim + label_height, ";", - "9,3;", - "]", - } - - local inventory_label_y = 2 * padding_slim + label_height + 3 * iu - local inventory_formspec = table.concat{ - "label[", - padding - bu, ",", inventory_label_y + label_y_offset, ";", - F(C(mcl_formspec.label_color, S("Crafting"))), - "]", - mcl_formspec.create_itemslot_bg(padding, inventory_label_y + label_height, 9, 3), - mcl_formspec.create_itemslot_bg(padding, inventory_label_y + 3 * iu + padding + label_height, 9, 1), - "list[current_player;main;", - padding, ",", inventory_label_y + label_height, ";", - "9,3;9", - "]", - "list[current_player;main;", - padding, ",", inventory_label_y + 3 * iu + padding + label_height, ";", - "9,1;", - "]", - } + local storage_list_inv = sf("nodemeta:%d,%d,%d;main", pos.x, pos.y, pos.z) minetest.show_formspec(clicker:get_player_name(), sf("mcl_chests:%s_%s_%s_%s", canonical_basename, pos.x, pos.y, pos.z), table.concat({ "formspec_version[4]", - "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 7 * iu + 2 * (padding_slim + label_height) - 2 * bu, "]", + "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 2 * label_height + 7 * iu + 2 * padding_slim - 2 * bu, "]", mcl_formspec.label_style, mcl_formspec.itemslot_style, - chest_formspec, - inventory_formspec, + mcl_chests.formspec_storage(padding, padding + label_height, { + list_inv = storage_list_inv, + label_y = padding, + label_text = name, + }), - "listring[", chest_inv_location, ";main]", + mcl_inventory.formspec_inventory(padding, padding + 2 * label_height + 3 * iu + padding_slim, { + hotbar_y = padding + 2 * label_height + 6 * iu + 2 * padding_slim, + label_y = padding + label_height + 3 * iu + padding_slim + }), + + "listring[", storage_list_inv, "]", "listring[current_player;main]", }) ) @@ -672,71 +665,47 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile name = S("Large Chest") end - local margin = mcl_formspec.margin local padding = mcl_formspec.padding local padding_slim = mcl_formspec.padding_slim local bu = mcl_formspec.itemslot_bu local iu = mcl_formspec.itemslot_iu - local label_color = mcl_formspec.label_color local label_height = mcl_formspec.label_height - local label_y_offset = mcl_formspec.label_y_offset - - local chest_inv_location = sf("nodemeta:%d,%d,%d", pos.x, pos.y, pos.z) - local chest_other_inv_location = sf("nodemeta:%d,%d,%d", pos_other.x, pos_other.y, pos_other.z) - local chest_formspec = table.concat{ - "label[", - padding - bu, ",", padding_slim + label_y_offset, ";", - F(C(mcl_formspec.label_color, name)), - "]", - mcl_formspec.create_itemslot_bg(padding, padding_slim + label_height, 9, 6), - "list[", chest_inv_location, ";main;", - padding, ",", padding_slim + label_height, ";", - "9,3;", - "]", - "list[", chest_other_inv_location, ";main;", - padding, ",", padding_slim + label_height + 3 * iu, ";", - "9,3;", - "]", - } - - local inventory_label_y = 2 * padding_slim + label_height + 6 * iu - local inventory_formspec = table.concat{ - "label[", - padding - bu, ",", inventory_label_y + label_y_offset, ";", - F(C(mcl_formspec.label_color, S("Crafting"))), - "]", - mcl_formspec.create_itemslot_bg(padding, inventory_label_y + label_height, 9, 3), - mcl_formspec.create_itemslot_bg(padding, inventory_label_y + 3 * iu + padding + label_height, 9, 1), - "list[current_player;main;", - padding, ",", inventory_label_y + label_height, ";", - "9,3;9", - "]", - "list[current_player;main;", - padding, ",", inventory_label_y + 3 * iu + padding + label_height, ";", - "9,1;", - "]", - } + local storage_list_inv_workaround = sf("nodemeta:%d,%d,%d;input", pos.x, pos.y, pos.z) + local storage_list_inv = sf("nodemeta:%d,%d,%d;main", pos.x, pos.y, pos.z) + local storage_list_inv_other = sf("nodemeta:%d,%d,%d;main", pos_other.x, pos_other.y, pos_other.z) minetest.show_formspec(clicker:get_player_name(), sf("mcl_chests:%s_%s_%s_%s", canonical_basename, pos.x, pos.y, pos.z), table.concat({ "formspec_version[4]", - "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 10 * iu + 2 * (padding_slim + label_height) - 2 * bu, "]", + "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 2 * label_height + 10 * iu + 2 * padding_slim - 2 * bu, "]", + mcl_formspec.label_style, mcl_formspec.itemslot_style, - chest_formspec, - inventory_formspec, + mcl_chests.formspec_storage(padding, padding + label_height, { + list_inv = storage_list_inv, + label_y = padding, + label_text = name, + }), + mcl_chests.formspec_storage(padding, padding + label_height + 3 * iu, { + list_inv = storage_list_inv_other, + }), + + mcl_inventory.formspec_inventory(padding, padding + 2 * label_height + 6 * iu + padding_slim, { + hotbar_y = padding + 2 * label_height + 9 * iu + 2 * padding_slim, + label_y = padding + label_height + 6 * iu + padding_slim + }), -- BEGIN listring workaround "listring[current_player;main]", - "listring[", chest_inv_location, ";input]", + "listring[", storage_list_inv_workaround, "]", -- END listring workaround "listring[current_player;main]", - "listring[", chest_inv_location, ";main]", + "listring[", storage_list_inv, "]", "listring[current_player;main]", - "listring[", chest_other_inv_location, ";main]", + "listring[", storage_list_inv_other, "]", }) ) @@ -849,87 +818,63 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile _mcl_blast_resistance = 2.5, _mcl_hardness = 2.5, - on_rightclick = function(pos, node, clicker) - local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "right") + on_rightclick = function(pos_other, node, clicker) + local pos = mcl_util.get_double_container_neighbor_pos(pos_other, node.param2, "right") if minetest.registered_nodes[minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z}).name].groups.opaque == 1 or minetest.registered_nodes[minetest.get_node({x = pos_other.x, y = pos_other.y + 1, z = pos_other.z}).name].groups.opaque == 1 then -- won't open if there is no space from the top return false end - local name = minetest.get_meta(pos_other):get_string("name") + local name = minetest.get_meta(pos):get_string("name") if name == "" then - name = minetest.get_meta(pos):get_string("name") + name = minetest.get_meta(pos_other):get_string("name") end if name == "" then name = S("Large Chest") end - local margin = mcl_formspec.margin local padding = mcl_formspec.padding local padding_slim = mcl_formspec.padding_slim local bu = mcl_formspec.itemslot_bu local iu = mcl_formspec.itemslot_iu - local label_color = mcl_formspec.label_color local label_height = mcl_formspec.label_height - local label_y_offset = mcl_formspec.label_y_offset - - local chest_inv_location = sf("nodemeta:%d,%d,%d", pos.x, pos.y, pos.z) - local chest_other_inv_location = sf("nodemeta:%d,%d,%d", pos_other.x, pos_other.y, pos_other.z) - local chest_formspec = table.concat{ - "label[", - padding - bu, ",", padding_slim + label_y_offset, ";", - F(C(mcl_formspec.label_color, name)), - "]", - mcl_formspec.create_itemslot_bg(padding, padding_slim + label_height, 9, 6), - "list[", chest_other_inv_location, ";main;", - padding, ",", padding_slim + label_height, ";", - "9,3;", - "]", - "list[", chest_inv_location, ";main;", - padding, ",", padding_slim + label_height + 3 * iu, ";", - "9,3;", - "]", - } - - local inventory_label_y = 2 * padding_slim + label_height + 6 * iu - local inventory_formspec = table.concat{ - "label[", - padding - bu, ",", inventory_label_y + label_y_offset, ";", - F(C(mcl_formspec.label_color, S("Crafting"))), - "]", - mcl_formspec.create_itemslot_bg(padding, inventory_label_y + label_height, 9, 3), - mcl_formspec.create_itemslot_bg(padding, inventory_label_y + 3 * iu + padding + label_height, 9, 1), - "list[current_player;main;", - padding, ",", inventory_label_y + label_height, ";", - "9,3;9", - "]", - "list[current_player;main;", - padding, ",", inventory_label_y + 3 * iu + padding + label_height, ";", - "9,1;", - "]", - } + local storage_list_inv_workaround = sf("nodemeta:%d,%d,%d;input", pos.x, pos.y, pos.z) + local storage_list_inv = sf("nodemeta:%d,%d,%d;main", pos.x, pos.y, pos.z) + local storage_list_inv_other = sf("nodemeta:%d,%d,%d;main", pos_other.x, pos_other.y, pos_other.z) minetest.show_formspec(clicker:get_player_name(), - sf("mcl_chests:%s_%s_%s_%s", canonical_basename, pos.x, pos.y, pos.z), + sf("mcl_chests:%s_%s_%s_%s", canonical_basename, pos_other.x, pos_other.y, pos_other.z), table.concat({ "formspec_version[4]", - "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 10 * iu + 2 * (padding_slim + label_height) - 2 * bu, "]", + "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 2 * label_height + 10 * iu + 2 * padding_slim - 2 * bu, "]", + mcl_formspec.label_style, mcl_formspec.itemslot_style, - chest_formspec, - inventory_formspec, + mcl_chests.formspec_storage(padding, padding + label_height, { + list_inv = storage_list_inv, + label_y = padding, + label_text = name, + }), + mcl_chests.formspec_storage(padding, padding + label_height + 3 * iu, { + list_inv = storage_list_inv_other, + }), + + mcl_inventory.formspec_inventory(padding, padding + 2 * label_height + 6 * iu + padding_slim, { + hotbar_y = padding + 2 * label_height + 9 * iu + 2 * padding_slim, + label_y = padding + label_height + 6 * iu + padding_slim + }), -- BEGIN listring workaround "listring[current_player;main]", - "listring[", chest_inv_location, ";input]", + "listring[", storage_list_inv_workaround, "]", -- END listring workaround "listring[current_player;main]", - "listring[", chest_inv_location, ";main]", + "listring[", storage_list_inv, "]", "listring[current_player;main]", - "listring[", chest_other_inv_location, ";main]", + "listring[", storage_list_inv_other, "]", }) ) @@ -1169,57 +1114,32 @@ minetest.register_node("mcl_chests:ender_chest_small", { return false end - local margin = mcl_formspec.margin local padding = mcl_formspec.padding local padding_slim = mcl_formspec.padding_slim local bu = mcl_formspec.itemslot_bu local iu = mcl_formspec.itemslot_iu - local label_color = mcl_formspec.label_color local label_height = mcl_formspec.label_height - local label_y_offset = mcl_formspec.label_y_offset - - local chest_formspec = table.concat{ - "label[", - padding - bu, ",", padding_slim + label_y_offset, ";", - F(C(mcl_formspec.label_color, S("Ender Chest"))), - "]", - mcl_formspec.create_itemslot_bg(padding, padding_slim + label_height, 9, 3), - "list[current_player;enderchest;", - padding, ",", padding_slim + label_height, ";", - "9,3;", - "]", - } - - local inventory_label_y = 2 * padding_slim + label_height + 3 * iu - local inventory_formspec = table.concat{ - "label[", - padding - bu, ",", inventory_label_y + label_y_offset, ";", - F(C(mcl_formspec.label_color, S("Crafting"))), - "]", - mcl_formspec.create_itemslot_bg(padding, inventory_label_y + label_height, 9, 3), - mcl_formspec.create_itemslot_bg(padding, inventory_label_y + 3 * iu + padding + label_height, 9, 1), - "list[current_player;main;", - padding, ",", inventory_label_y + label_height, ";", - "9,3;9", - "]", - "list[current_player;main;", - padding, ",", inventory_label_y + 3 * iu + padding + label_height, ";", - "9,1;", - "]", - } minetest.show_formspec(clicker:get_player_name(), "mcl_chests:ender_chest_"..clicker:get_player_name(), table.concat{ "formspec_version[4]", - "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 7 * iu + 2 * (padding_slim + label_height) - 2 * bu, "]", + "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 2 * label_height + 7 * iu + 2 * padding_slim - 2 * bu, "]", mcl_formspec.label_style, mcl_formspec.itemslot_style, - chest_formspec, - inventory_formspec, + mcl_chests.formspec_storage(padding, padding + label_height, { + list_inv = "current_player;enderchest", + label_y = padding, + label_text = S("Ender Chest"), + }), + + mcl_inventory.formspec_inventory(padding, padding + 2 * label_height + 3 * iu + padding_slim, { + hotbar_y = padding + 2 * label_height + 6 * iu + 2 * padding_slim, + label_y = padding + label_height + 3 * iu + padding_slim + }), "listring[current_player;enderchest]", "listring[current_player;main]", @@ -1299,54 +1219,30 @@ local function formspec_shulker_box(name) name = S("Shulker Box") end - local margin = mcl_formspec.margin local padding = mcl_formspec.padding local padding_slim = mcl_formspec.padding_slim local bu = mcl_formspec.itemslot_bu local iu = mcl_formspec.itemslot_iu - local label_color = mcl_formspec.label_color local label_height = mcl_formspec.label_height - local label_y_offset = mcl_formspec.label_y_offset - - local shulker_box_formspec = table.concat{ - "label[", - padding - bu, ",", padding_slim + label_y_offset, ";", - F(C(mcl_formspec.label_color, name)), - "]", - mcl_formspec.create_itemslot_bg(padding, padding_slim + label_height, 9, 3), - "list[context;main;", - padding, ",", padding_slim + label_height, ";", - "9,3;", - "]", - } - - local inventory_label_y = 2 * padding_slim + label_height + 3 * iu - local inventory_formspec = table.concat{ - "label[", - padding - bu, ",", inventory_label_y + label_y_offset, ";", - F(C(mcl_formspec.label_color, S("Crafting"))), - "]", - mcl_formspec.create_itemslot_bg(padding, inventory_label_y + label_height, 9, 3), - mcl_formspec.create_itemslot_bg(padding, inventory_label_y + 3 * iu + padding + label_height, 9, 1), - "list[current_player;main;", - padding, ",", inventory_label_y + label_height, ";", - "9,3;9", - "]", - "list[current_player;main;", - padding, ",", inventory_label_y + 3 * iu + padding + label_height, ";", - "9,1;", - "]", - } return table.concat{ "formspec_version[4]", - "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 7 * iu + 2 * (padding_slim + label_height) - 2 * bu, "]", + "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 2 * label_height + 7 * iu + 2 * padding_slim - 2 * bu, "]", + mcl_formspec.label_style, mcl_formspec.itemslot_style, - shulker_box_formspec, - inventory_formspec, + mcl_chests.formspec_storage(padding, padding + label_height, { + list_inv = "context;main", + label_y = padding, + label_text = name, + }), + + mcl_inventory.formspec_inventory(padding, padding + 2 * label_height + 3 * iu + padding_slim, { + hotbar_y = padding + 2 * label_height + 6 * iu + 2 * padding_slim, + label_y = padding + label_height + 3 * iu + padding_slim + }), "listring[context;main]", "listring[current_player;main]", -- 2.40.1 From aaa636b0f2a63af92a85f20eebdf01427c2b9508 Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Sun, 3 Oct 2021 04:30:30 +0800 Subject: [PATCH 20/20] [WIP] better paddings. --- mods/HUD/mcl_formspec/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index d304f0f71..321cc9aa3 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -142,5 +142,5 @@ end -------------------------------------------------------------------------------- mcl_formspec.margin = 0.078125 -mcl_formspec.padding = 0.375 -mcl_formspec.padding_slim = mcl_formspec.padding - mcl_formspec.itemslot_bu +mcl_formspec.padding = 0.5 +mcl_formspec.padding_slim = 0.25 -- 2.40.1