aboutsummaryrefslogtreecommitdiff
path: root/games/devtest
diff options
context:
space:
mode:
authorVincent Robinson <robinsonvincent89@gmail.com>2021-12-30 12:54:47 -0800
committerGitHub <noreply@github.com>2021-12-30 12:54:47 -0800
commit544b9d5c72f690d6a729053616d26e023f7e0e28 (patch)
treee549d0a2eda19c5cfd76aee5bc077b95980a80e4 /games/devtest
parent4a16ab3585dafdf4d36b2807a1ee9507be64b363 (diff)
Add padding[] element to formspecs (#11821)
Diffstat (limited to 'games/devtest')
-rw-r--r--games/devtest/mods/testformspec/formspec.lua65
1 files changed, 59 insertions, 6 deletions
diff --git a/games/devtest/mods/testformspec/formspec.lua b/games/devtest/mods/testformspec/formspec.lua
index 501b5e354..c0db695b7 100644
--- a/games/devtest/mods/testformspec/formspec.lua
+++ b/games/devtest/mods/testformspec/formspec.lua
@@ -270,6 +270,16 @@ local scroll_fs =
--style_type[label;border=;bgcolor=]
--label[0.75,2;Reset]
+local window = {
+ sizex = 12,
+ sizey = 13,
+ positionx = 0.5,
+ positiony = 0.5,
+ anchorx = 0.5,
+ anchory = 0.5,
+ paddingx = 0.05,
+ paddingy = 0.05
+}
local pages = {
-- Real Coordinates
@@ -341,9 +351,28 @@ local pages = {
"size[12,13]real_coordinates[true]" ..
"container[0.5,1.5]" .. tabheaders_fs .. "container_end[]",
- -- Inv
+ -- Inv
"size[12,13]real_coordinates[true]" .. inv_style_fs,
+ -- Window
+ function()
+ return "formspec_version[3]" ..
+ string.format("size[%s,%s]position[%s,%s]anchor[%s,%s]padding[%s,%s]",
+ window.sizex, window.sizey, window.positionx, window.positiony,
+ window.anchorx, window.anchory, window.paddingx, window.paddingy) ..
+ string.format("field[0.5,0.5;2.5,0.5;sizex;X Size;%s]field[3.5,0.5;2.5,0.5;sizey;Y Size;%s]" ..
+ "field[0.5,1.5;2.5,0.5;positionx;X Position;%s]field[3.5,1.5;2.5,0.5;positiony;Y Position;%s]" ..
+ "field[0.5,2.5;2.5,0.5;anchorx;X Anchor;%s]field[3.5,2.5;2.5,0.5;anchory;Y Anchor;%s]" ..
+ "field[0.5,3.5;2.5,0.5;paddingx;X Padding;%s]field[3.5,3.5;2.5,0.5;paddingy;Y Padding;%s]" ..
+ "button[2,4.5;2.5,0.5;submit_window;Submit]",
+ window.sizex, window.sizey, window.positionx, window.positiony,
+ window.anchorx, window.anchory, window.paddingx, window.paddingy) ..
+ "field_close_on_enter[sizex;false]field_close_on_enter[sizey;false]" ..
+ "field_close_on_enter[positionx;false]field_close_on_enter[positiony;false]" ..
+ "field_close_on_enter[anchorx;false]field_close_on_enter[anchory;false]" ..
+ "field_close_on_enter[paddingx;false]field_close_on_enter[paddingy;false]"
+ end,
+
-- Animation
[[
formspec_version[3]
@@ -403,10 +432,14 @@ mouse control = true]
]],
}
-local function show_test_formspec(pname, page_id)
- page_id = page_id or 2
+local page_id = 2
+local function show_test_formspec(pname)
+ local page = pages[page_id]
+ if type(page) == "function" then
+ page = page()
+ end
- local fs = pages[page_id] .. "tabheader[0,0;8,0.65;maintabs;Real Coord,Styles,Noclip,Hypertext,Tabs,Invs,Anim,Model,ScrollC,Sound;" .. page_id .. ";false;false]"
+ local fs = page .. "tabheader[0,0;8,0.65;maintabs;Real Coord,Styles,Noclip,Hypertext,Tabs,Invs,Window,Anim,Model,ScrollC,Sound;" .. page_id .. ";false;false]"
minetest.show_formspec(pname, "testformspec:formspec", fs)
end
@@ -416,9 +449,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return false
end
-
if fields.maintabs then
- show_test_formspec(player:get_player_name(), tonumber(fields.maintabs))
+ page_id = tonumber(fields.maintabs)
+ show_test_formspec(player:get_player_name())
return true
end
@@ -434,6 +467,26 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
minetest.chat_send_player(player:get_player_name(), "Hypertext action received: " .. tostring(fields.hypertext))
return true
end
+
+ for name, value in pairs(fields) do
+ if window[name] then
+ print(name, window[name])
+ local num_val = tonumber(value) or 0
+
+ if name == "sizex" and num_val < 4 then
+ num_val = 6.5
+ elseif name == "sizey" and num_val < 5 then
+ num_val = 5.5
+ end
+
+ window[name] = num_val
+ print(name, window[name])
+ end
+ end
+
+ if fields.submit_window then
+ show_test_formspec(player:get_player_name())
+ end
end)
minetest.register_chatcommand("test_formspec", {
se end local function itremove(tbl, com) local i=1 while i <= #tbl do if tbl[i] == com then table.remove(tbl, i) else i = i + 1 end end end local function itkremove(tbl, ikey, com) local i=1 while i <= #tbl do if tbl[i][ikey] == com then table.remove(tbl, i) else i = i + 1 end end end local function setsection(tid, train, ts_id, ts, sigd) -- train if not train.il_sections then train.il_sections = {} end if not itkexist(train.il_sections, "ts_id", ts_id) then table.insert(train.il_sections, {ts_id = ts_id, origin = sigd}) end -- ts if not ts.trains then ts.trains = {} end if not itexist(ts.trains, tid) then table.insert(ts.trains, tid) end -- routes local tcbs = advtrains.interlocking.db.get_tcbs(sigd) -- route setting - clear route state if ts.route then --atdebug(tid,"enters",ts_id,"examining Routestate",ts.route) if not sigd_equal(ts.route.entry, sigd) then -- Train entered not from the route. Locate origin and cancel route! atwarn("Train",tid,"hit route",ts.route.rsn,"!") advtrains.interlocking.route.cancel_route_from(ts.route.origin) atwarn("Route was cancelled.") else -- train entered route regularily. Reset route and signal tcbs.route_committed = nil tcbs.route_comitted = nil -- TODO compatibility cleanup tcbs.aspect = nil tcbs.route_origin = nil advtrains.interlocking.update_signal_aspect(tcbs) if tcbs.signal and sigd_equal(ts.route.entry, ts.route.origin) then if tcbs.route_auto and tcbs.routeset then --atdebug("Resetting route (",ts.route.origin,")") advtrains.interlocking.route.update_route(ts.route.origin, tcbs) else tcbs.routeset = nil end end end ts.route = nil end if tcbs.signal then advtrains.interlocking.route.update_route(sigd, tcbs) end end local function freesection(tid, train, ts_id, ts) -- train if not train.il_sections then train.il_sections = {} end itkremove(train.il_sections, "ts_id", ts_id) -- ts if not ts.trains then ts.trains = {} end itremove(ts.trains, tid) if ts.route_post then advtrains.interlocking.route.free_route_locks(ts_id, ts.route_post.locks) if ts.route_post.next then --this does nothing when the train went the right way, because -- "route" info is already cleared. advtrains.interlocking.route.cancel_route_from(ts.route_post.next) end ts.route_post = nil end -- This must be delayed, because this code is executed in-between a train step -- TODO use luaautomation timers? minetest.after(0, advtrains.interlocking.route.update_waiting, "ts", ts_id) end -- This is regular operation -- The train is on a track and drives back and forth -- This sets the section for both directions, to be failsafe advtrains.tnc_register_on_enter(function(pos, id, train, index) local tcb = ildb.get_tcb(pos) if tcb then for connid=1,2 do local ts = tcb[connid].ts_id and ildb.get_ts(tcb[connid].ts_id) if ts then setsection(id, train, tcb[connid].ts_id, ts, {p=pos, s=connid}) end end end end) -- this time, of course, only clear the backside (cp connid) advtrains.tnc_register_on_leave(function(pos, id, train, index) local tcb = ildb.get_tcb(pos) if tcb and train.path_cp[index] then local connid = train.path_cp[index] local ts = tcb[connid].ts_id and ildb.get_ts(tcb[connid].ts_id) if ts then freesection(id, train, tcb[connid].ts_id, ts) end end end)