From d4b39cba9bd1be36b8daf4f6b50b9e3eaf2efb80 Mon Sep 17 00:00:00 2001 From: Uberi Date: Tue, 10 Dec 2013 01:58:53 -0500 Subject: [PATCH] WorldEdit GUI is now live! Currently under construction. --- worldedit_gui/depends.txt | 3 + worldedit_gui/functionality.lua | 179 ++++++++++++++++++ worldedit_gui/init.lua | 129 +++++++++++++ .../textures/inventory_plus_worldedit_gui.png | Bin 0 -> 2082 bytes 4 files changed, 311 insertions(+) create mode 100644 worldedit_gui/depends.txt create mode 100644 worldedit_gui/functionality.lua create mode 100644 worldedit_gui/init.lua create mode 100644 worldedit_gui/textures/inventory_plus_worldedit_gui.png diff --git a/worldedit_gui/depends.txt b/worldedit_gui/depends.txt new file mode 100644 index 0000000..dfaeee4 --- /dev/null +++ b/worldedit_gui/depends.txt @@ -0,0 +1,3 @@ +worldedit +worldedit_commands +inventory_plus? \ No newline at end of file diff --git a/worldedit_gui/functionality.lua b/worldedit_gui/functionality.lua new file mode 100644 index 0000000..d3e6021 --- /dev/null +++ b/worldedit_gui/functionality.lua @@ -0,0 +1,179 @@ +worldedit.register_gui_function("worldedit_gui_about", { + name = "About", + privs = {worldedit=1}, + on_select = function(name) + minetest.chatcommands["/about"].func(name, "") + end, +}) + +worldedit.register_gui_function("worldedit_gui_inspect", { + name = "Toggle Inspection", + privs = {worldedit=1}, + on_select = function(name) + minetest.chatcommands["/inspect"].func(name, worldedit.inspect[name] and "disable" or "enable") + end, +}) + +worldedit.register_gui_function("worldedit_gui_reset", { + name = "Reset Region", + privs = {worldedit=1}, + on_select = function(name) + minetest.chatcommands["/reset"].func(name, "") + end, +}) + +worldedit.register_gui_function("worldedit_gui_mark", { + name = "Mark Region", + privs = {worldedit=1}, + on_select = function(name) + minetest.chatcommands["/mark"].func(name, "") + end, +}) + +worldedit.register_gui_function("worldedit_gui_unmark", { + name = "Unmark Region", + privs = {worldedit=1}, + on_select = function(name) + minetest.chatcommands["/unmark"].func(name, "") + end, +}) + +worldedit.register_gui_function("worldedit_gui_pos1", { + name = "Position 1 Here", + privs = {worldedit=1}, + on_select = function(name) + minetest.chatcommands["/pos1"].func(name, "") + end, +}) + +worldedit.register_gui_function("worldedit_gui_pos2", { + name = "Position 2 Here", + privs = {worldedit=1}, + on_select = function(name) + minetest.chatcommands["/pos2"].func(name, "") + end, +}) + +worldedit.register_gui_function("worldedit_gui_p", { + name = "Get/Set Positions", + privs = {worldedit=1}, + get_formspec = function(name) + return "size[12,2]" .. + "button[0,0;2,0.5;worldedit_gui;Back]" .. + "label[2,0;WorldEdit GUI > Get/Set Positions]" .. + "button_exit[0,1;3,0.8;worldedit_gui_p_get;Get Positions]" .. + "button_exit[3,1;3,0.8;worldedit_gui_p_set;Set Positions]" .. + "button_exit[6,1;3,0.8;worldedit_gui_p_set1;Set Position 1]" .. + "button_exit[9,1;3,0.8;worldedit_gui_p_set2;Set Position 2]" + end, +}) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if fields.quit then + return false + end + + local name = player:get_player_name() + if fields.worldedit_gui_p_get then + minetest.chatcommands["/p"].func(name, "get") + return true + elseif fields.worldedit_gui_p_set then + minetest.chatcommands["/p"].func(name, "set") + return true + elseif fields.worldedit_gui_p_set1 then + minetest.chatcommands["/p"].func(name, "set1") + return true + elseif fields.worldedit_gui_p_set2 then + minetest.chatcommands["/p"].func(name, "set2") + return true + end + return false +end) + +worldedit.register_gui_function("worldedit_gui_fixedpos", { + name = "Fixed Positions", + privs = {worldedit=1}, + get_formspec = function(name) + local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] + return "size[6.5,4]" .. + "button[0,0;2,0.5;worldedit_gui;Back]" .. + "label[2,0;WorldEdit GUI > Fixed Positions]" .. + "label[0,1.2;Position 1]" .. + string.format("field[2,1.5;1.5,0.8;worldedit_gui_fixedpos_pos1x;Axis X;%s]", pos1 and pos1.x or "") .. + string.format("field[3.5,1.5;1.5,0.8;worldedit_gui_fixedpos_pos1y;Axis Y;%s]", pos1 and pos1.y or "") .. + string.format("field[5,1.5;1.5,0.8;worldedit_gui_fixedpos_pos1z;Axis Z;%s]", pos1 and pos1.z or "") .. + "label[0,2.2;Position 2]" .. + string.format("field[2,2.5;1.5,0.8;worldedit_gui_fixedpos_pos2x;Axis X;%s]", pos2 and pos2.x or "") .. + string.format("field[3.5,2.5;1.5,0.8;worldedit_gui_fixedpos_pos2y;Axis Y;%s]", pos2 and pos2.y or "") .. + string.format("field[5,2.5;1.5,0.8;worldedit_gui_fixedpos_pos2z;Axis Z;%s]", pos2 and pos2.z or "") .. + "button_exit[0,3.5;4,0.8;worldedit_gui_fixedpos_submit;Set Fixed Positions]" + end +}) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if fields.quit then + return false + end + + if fields.worldedit_gui_fixedpos_submit then + if tonumber(fields.worldedit_gui_fixedpos_pos1x) and tonumber(fields.worldedit_gui_fixedpos_pos1y) and tonumber(fields.worldedit_gui_fixedpos_pos1z) then + minetest.chatcommands["/fixedpos"].func(player:get_player_name(), string.format("set1 %d %d %d", + tonumber(fields.worldedit_gui_fixedpos_pos1x), tonumber(fields.worldedit_gui_fixedpos_pos1y), tonumber(fields.worldedit_gui_fixedpos_pos1z))) + end + if tonumber(fields.worldedit_gui_fixedpos_pos2x) and tonumber(fields.worldedit_gui_fixedpos_pos2y) and tonumber(fields.worldedit_gui_fixedpos_pos2z) then + minetest.chatcommands["/fixedpos"].func(player:get_player_name(), string.format("set2 %d %d %d", + tonumber(fields.worldedit_gui_fixedpos_pos2x), tonumber(fields.worldedit_gui_fixedpos_pos2y), tonumber(fields.worldedit_gui_fixedpos_pos2z))) + end + return true + end + return false +end) + +worldedit.register_gui_function("worldedit_gui_volume", { + name = "Region Volume", + privs = {worldedit=1}, + on_select = function(name) + minetest.chatcommands["/volume"].func(name, "") + end, +}) + +local search_nodes = {} +worldedit.register_gui_function("worldedit_gui_set", { + name = "Set Nodes", + privs = {worldedit=1}, + get_formspec = function(name) + local value = search_nodes[name] + local nodename + if value then + nodename = worldedit.normalize_nodename(value) + if nodename then + value = nodename + end + end + return "size[6,3]" .. + "button[0,0;2,0.5;worldedit_gui;Back]" .. + "label[2,0;WorldEdit GUI > Set Nodes]" .. + string.format("field[0.5,1.5;4,0.8;worldedit_gui_set_node;Name;%s]", value and minetest.formspec_escape(value) or "") .. + "button[4,1.17;2,0.8;worldedit_gui_set_search;Search]" .. + (nodename and string.format("item_image[4.5,2;1,1;%s]", nodename) or "image[4.5,2;1,1;unknown_node.png]") .. + "button_exit[0,2.5;4,0.8;worldedit_gui_set_submit;Set Nodes]" + end, +}) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if fields.quit then + return false + end + + local name = player:get_player_name() + if fields.worldedit_gui_set_search then + search_nodes[name] = fields.worldedit_gui_set_node + worldedit.show_page(name, "worldedit_gui_set") + return true + elseif fields.worldedit_gui_set_submit then + search_nodes[name] = fields.worldedit_gui_set_node + minetest.chatcommands["/set"].func(name, fields.worldedit_gui_set_node) + return true + end + return false +end) \ No newline at end of file diff --git a/worldedit_gui/init.lua b/worldedit_gui/init.lua new file mode 100644 index 0000000..82936d8 --- /dev/null +++ b/worldedit_gui/init.lua @@ -0,0 +1,129 @@ +--wip: make back buttons images in all screens +--wip: support unified_inventory, it even seems to have some sort of API now + +worldedit = worldedit or {} + +--[[ +Example: + + worldedit.register_gui_function("worldedit_gui_hollow_cylinder", { + name = "Make Hollow Cylinder", + privs = {worldedit=true}, + get_formspec = function(name) return "some formspec here" end, + on_select = function(name) print(name .. " clicked the button!") end, + }) + +Use `nil` for the `options` parameter to unregister the function associated with the given identifier. + +Use `nil` for the `get_formspec` field to denote that the function does not have its own screen. + +Use `nil` for the `privs` field to denote that no special privileges are required to use the function. + +If the identifier is already registered to another function, it will be replaced by the new one. +]] + +local pages = {} --mapping of identifiers to options +local identifiers = {} --ordered list of identifiers +worldedit.register_gui_function = function(identifier, options) + pages[identifier] = options + table.insert(identifiers, identifier) +end + +local get_formspec = function(name, identifier) + if pages[identifier] then + return pages[identifier].get_formspec(name) + end + return pages["worldedit_gui"].get_formspec(name) +end + +worldedit.show_page = function(name, page) + --wip + print("not implemented") +end + +--add button to inventory_plus if it is installed +if inventory_plus then + minetest.register_on_joinplayer(function(player) + --ensure player has permission to perform action + if minetest.check_player_privs(player:get_player_name(), {worldedit=true}) then + inventory_plus.register_button(player, "worldedit_gui", "WorldEdit") + end + end) + + --show the form when the button is pressed + minetest.register_on_player_receive_fields(function(player, formname, fields) + local name = player:get_player_name() + + --ensure player has permission to perform action + if not minetest.check_player_privs(name, {worldedit=true}) then + return false + end + + --check for showing of main GUI + local next_page = nil + if fields.worldedit_gui then --main page + worldedit.show_page(name, "worldedit_gui") + return true + end + return false + end) + + worldedit.show_page = function(name, page) + inventory_plus.set_inventory_formspec(minetest.get_player_by_name(name), get_formspec(name, page)) + end +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if fields.quit then + return false + end + + --check for WorldEdit GUI main formspec button selection + for identifier, entry in pairs(pages) do + if fields[identifier] then + local name = player:get_player_name() + + --ensure player has permission to perform action + if entry.privs and not minetest.check_player_privs(name, entry.privs) then + return false + end + if entry.on_select then + entry.on_select(name) + end + if entry.get_formspec then + worldedit.show_page(name, identifier) + end + return true + end + end + return false +end) + +worldedit.register_gui_function("worldedit_gui", { + name = "WorldEdit GUI", + get_formspec = function(name) + --create a form with all the buttons arranged in a grid + local buttons, x, y, index = {}, 0, 1, 0 + local width, height = 3, 0.8 + local columns = 5 + for i, identifier in pairs(identifiers) do + if identifier ~= "worldedit_gui" then + local entry = pages[identifier] + table.insert(buttons, string.format((entry.get_formspec and "button" or "button_exit") .. + "[%g,%g;%g,%g;%s;%s]", x, y, width, height, identifier, minetest.formspec_escape(entry.name))) + + index, x = index + 1, x + width + if index == columns then --row is full + x, y = 0, y + height + index = 0 + end + end + end + return string.format("size[%g,%g]", columns * width, y + 0.5) .. + (inventory_plus and "button[0,0;2,0.5;main;Back]" or "button_exit[0,0;2,0.5;main;Exit]") .. + "label[2,0;WorldEdit GUI]" .. + table.concat(buttons) + end, +}) + +dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/functionality.lua") \ No newline at end of file diff --git a/worldedit_gui/textures/inventory_plus_worldedit_gui.png b/worldedit_gui/textures/inventory_plus_worldedit_gui.png new file mode 100644 index 0000000000000000000000000000000000000000..b8975bf5b6ea4f6a1c14e8ca276da9779c57d95e GIT binary patch literal 2082 zcmV+-2;KLIP){z)@DdcG5>x&F8>m7cidDi>ux%vr*hJB&5D0zXZuc=e@0mOIo^yWwF|`j{XeA_^ zY#F>i=CZv8hEELmX)dJP-k6q0@D$*B{K8`a2>N<=;-Prjht5>gPa&nT>pLvGbZXJi?GyVqF zsGCs;fr3cGh4Fesz!{NiI_I-_^JY#t?L@p4l5v&op`{-|R|NZx~ zapT6f_kpV)T`ME`MHJ&A&0d3c+UEF0D`+Jx{xWnkg+MbDD|Xa`dI}fiZewYF3Ds_u zN3w5XQsG>=9;Y0k7jR$od(;*jS+-Ae;Vb36F9-O*S0BDuin$VnsDR)|P0C0#g0&W3 z`z$GF@D#7^wls`lX3Fx~sn@ZsC%n~mRI3&zP|eL#DOV5#YuR5Mneuop6tYl5_TmCj>Xc<9_uw;=U3cw1~8-fMmP!Z>2#0kb3nk^X! zXM@KXq5PA^!9H;Hqidxc5950Q07*ZgQW!-m%?XQFl2bWq-FeQF8*!qTnswx3g|A?? zZ3o_O6k%SI(-F=(s;w%$hLH6H9Hcc6qi{y#AQR++JWedmS+w@pRKJU_9dj#%phy@5 zSe5e1^dw8m$MV9N@gZ-{@&`Kv8hqcU(@SWy>xcoo!J#|jpsxrcMdjyBYFCx^oj@EG z2!jwKhQ3Q!<6Xwm(sG8PBA)V?Z_ZH&id=K%O>Y}FwqH`%WAl_&+N9pDbHUg}Xis6g zpnZk%!3!CH?QeoD{v8y<5)b!oVN?A!f+)vuJcL#rPC0(?)>YiF>c@u-*)N|Lp|z&d z>k|4QvgfpIUyuyENZ~A)RQ3UU@X?m!BgOO4^&o?fvbnpN={Tu<;~VR#YPwnK}O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