From 8966c16ad298f94be1f4542afa6b081a1d286eda Mon Sep 17 00:00:00 2001 From: Kahrl Date: Fri, 23 Aug 2013 12:24:11 +0200 Subject: [PATCH] Add formspec table --- builtin/gamemgr.lua | 2 +- builtin/mainmenu.lua | 22 +- builtin/misc_helpers.lua | 51 +- builtin/modmgr.lua | 6 +- doc/lua_api.txt | 62 ++ doc/menu_lua_api.txt | 40 +- src/CMakeLists.txt | 1 + src/guiFormSpecMenu.cpp | 322 ++++---- src/guiFormSpecMenu.h | 33 +- src/guiTable.cpp | 1212 +++++++++++++++++++++++++++++ src/guiTable.h | 269 +++++++ src/script/lua_api/l_mainmenu.cpp | 22 +- src/script/lua_api/l_mainmenu.h | 2 + 13 files changed, 1798 insertions(+), 246 deletions(-) create mode 100644 src/guiTable.cpp create mode 100644 src/guiTable.h diff --git a/builtin/gamemgr.lua b/builtin/gamemgr.lua index 7a5e9790f..c99c2de21 100644 --- a/builtin/gamemgr.lua +++ b/builtin/gamemgr.lua @@ -31,7 +31,7 @@ end -------------------------------------------------------------------------------- function gamemgr.handle_games_buttons(fields) if fields["gamelist"] ~= nil then - local event = explode_textlist_event(fields["gamelist"]) + local event = engine.explode_textlist_event(fields["gamelist"]) gamemgr.selected_game = event.index end diff --git a/builtin/mainmenu.lua b/builtin/mainmenu.lua index d8c2b63ec..8ef306354 100644 --- a/builtin/mainmenu.lua +++ b/builtin/mainmenu.lua @@ -459,8 +459,8 @@ function tabbuilder.handle_multiplayer_buttons(fields) end if fields["favourites"] ~= nil then - local event = explode_textlist_event(fields["favourites"]) - if event.typ == "DCL" then + local event = engine.explode_textlist_event(fields["favourites"]) + if event.type == "DCL" then if event.index <= #menu.favorites then gamedata.address = menu.favorites[event.index].address gamedata.port = menu.favorites[event.index].port @@ -484,7 +484,7 @@ function tabbuilder.handle_multiplayer_buttons(fields) end end - if event.typ == "CHG" then + if event.type == "CHG" then if event.index <= #menu.favorites then local address = menu.favorites[event.index].address local port = menu.favorites[event.index].port @@ -586,12 +586,12 @@ function tabbuilder.handle_server_buttons(fields) local world_doubleclick = false if fields["srv_worlds"] ~= nil then - local event = explode_textlist_event(fields["srv_worlds"]) + local event = engine.explode_textlist_event(fields["srv_worlds"]) - if event.typ == "DCL" then + if event.type == "DCL" then world_doubleclick = true end - if event.typ == "CHG" then + if event.type == "CHG" then engine.setting_set("mainmenu_last_selected_world", filterlist.get_raw_index(worldlist,engine.get_textlist_index("srv_worlds"))) end @@ -737,13 +737,13 @@ function tabbuilder.handle_singleplayer_buttons(fields) local world_doubleclick = false if fields["sp_worlds"] ~= nil then - local event = explode_textlist_event(fields["sp_worlds"]) + local event = engine.explode_textlist_event(fields["sp_worlds"]) - if event.typ == "DCL" then + if event.type == "DCL" then world_doubleclick = true end - if event.typ == "CHG" then + if event.type == "CHG" then engine.setting_set("mainmenu_last_selected_world", filterlist.get_raw_index(worldlist,engine.get_textlist_index("sp_worlds"))) end @@ -813,8 +813,8 @@ end -------------------------------------------------------------------------------- function tabbuilder.handle_texture_pack_buttons(fields) if fields["TPs"] ~= nil then - local event = explode_textlist_event(fields["TPs"]) - if event.typ == "CHG" or event.typ=="DCL" then + local event = engine.explode_textlist_event(fields["TPs"]) + if event.type == "CHG" or event.type == "DCL" then local index = engine.get_textlist_index("TPs") engine.setting_set("mainmenu_last_selected_TP", index) diff --git a/builtin/misc_helpers.lua b/builtin/misc_helpers.lua index 097c65865..a7a8f6b1c 100644 --- a/builtin/misc_helpers.lua +++ b/builtin/misc_helpers.lua @@ -115,26 +115,6 @@ function math.hypot(x, y) return x * math.sqrt(1 + t * t) end --------------------------------------------------------------------------------- -function explode_textlist_event(text) - - local retval = {} - retval.typ = "INV" - - local parts = text:split(":") - - if #parts == 2 then - retval.typ = parts[1]:trim() - retval.index= tonumber(parts[2]:trim()) - - if type(retval.index) ~= "number" then - retval.typ = "INV" - end - end - - return retval -end - -------------------------------------------------------------------------------- function get_last_folder(text,count) local parts = text:split(DIR_DELIM) @@ -368,6 +348,37 @@ if minetest then end end +-------------------------------------------------------------------------------- +function tbl.explode_table_event(evt) + if evt ~= nil then + local parts = evt:split(":") + if #parts == 3 then + local t = parts[1]:trim() + local r = tonumber(parts[2]:trim()) + local c = tonumber(parts[3]:trim()) + if type(r) == "number" and type(c) == "number" and t ~= "INV" then + return {type=t, row=r, column=c} + end + end + end + return {type="INV", row=0, column=0} +end + +-------------------------------------------------------------------------------- +function tbl.explode_textlist_event(evt) + if evt ~= nil then + local parts = evt:split(":") + if #parts == 2 then + local t = parts[1]:trim() + local r = tonumber(parts[2]:trim()) + if type(r) == "number" and t ~= "INV" then + return {type=t, index=r} + end + end + end + return {type="INV", index=0} +end + -------------------------------------------------------------------------------- -- mainmenu only functions -------------------------------------------------------------------------------- diff --git a/builtin/modmgr.lua b/builtin/modmgr.lua index 13f81c6e0..f530ccc4a 100644 --- a/builtin/modmgr.lua +++ b/builtin/modmgr.lua @@ -572,7 +572,7 @@ function modmgr.handle_modmgr_buttons(fields) } if fields["modlist"] ~= nil then - local event = explode_textlist_event(fields["modlist"]) + local event = engine.explode_textlist_event(fields["modlist"]) modmgr.selected_mod = event.index end @@ -693,10 +693,10 @@ end -------------------------------------------------------------------------------- function modmgr.handle_configure_world_buttons(fields) if fields["world_config_modlist"] ~= nil then - local event = explode_textlist_event(fields["world_config_modlist"]) + local event = engine.explode_textlist_event(fields["world_config_modlist"]) modmgr.world_config_selected_mod = event.index - if event.typ == "DCL" then + if event.type == "DCL" then modmgr.world_config_enable_mod(nil) end end diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 1fae0ebbf..8bd83995e 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1011,6 +1011,7 @@ textlist[,;,;;,,...,;,;;,,...,;;;] ^ show a tabHEADER at specific position (ignores formsize) @@ -1043,6 +1044,57 @@ checkbox[,;;