From 8c0b61194cb00e362bf59a40bb5e3868c0bed922 Mon Sep 17 00:00:00 2001 From: Uberi Date: Mon, 30 Dec 2013 14:27:47 -0500 Subject: [PATCH] The WorldEdit GUI now has no hard dependencies. --- README.md | 10 ++----- Tutorial.md | 3 +- worldedit_gui/depends.txt | 3 +- worldedit_gui/init.lua | 61 ++++++++++++++++++++++++++++++++++----- 4 files changed, 59 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 0133e01..62d245a 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,6 @@ For more information, see the [forum topic](https://forum.minetest.net/viewtopic Installing ---------- -In order to use the WorldEdit GUI, you must have one of the following mods installed: - -* [Unified Inventory](https://forum.minetest.net/viewtopic.php?id=3933) (RECOMMENDED) -* [Inventory++](https://forum.minetest.net/viewtopic.php?id=6204) - -Installation of Unified Inventory is highly recommended. If neither of these mods are installed, the WorldEdit GUI will not be available, though the rest of WorldEdit will work fine. If you are using Windows, consider installing this mod using [MODSTER](https://forum.minetest.net/viewtopic.php?id=6497), a super simple mod installer that will take care of everything for you. If you are using MODSTER, skip directly to step 6 in the instructions below. @@ -57,7 +51,9 @@ This mod supports Minetest versions 0.4.8 and newer. Older versions of WorldEdit WorldEdit works quite well with other mods, and does not have any known mod conflicts. -WorldEdit GUI requires either [Unified Inventory](https://forum.minetest.net/viewtopic.php?id=3933) or [Inventory++](https://forum.minetest.net/viewtopic.php?id=6204) to be installed in order to use it. This is optional but highly recommended. +WorldEdit GUI works with [Unified Inventory](https://forum.minetest.net/viewtopic.php?id=3933) and [Inventory++](https://forum.minetest.net/viewtopic.php?id=6204), but these are not required to use the mod. + +If you use any other inventory manager mods, note that they may conflict with the WorldEdit GUI. If this is the case, it may be necessary to disable them. WorldEdit API ------------- diff --git a/Tutorial.md b/Tutorial.md index 3ffc5ce..abe554a 100644 --- a/Tutorial.md +++ b/Tutorial.md @@ -9,7 +9,6 @@ Let's start with a few assumptions: * You have WorldEdit installed as a mod. * If using Windows, [MODSTER](https://forum.minetest.net/viewtopic.php?pid=101463) makes installing mods totally painless. * Simply download the file, extract the archive, and move it to the correct mod folder for Minetest. - * If you want to use the WorldEdit GUI, you have installed either [Unified Inventory](https://forum.minetest.net/viewtopic.php?id=3933) (recommended), or [Inventory++](https://forum.minetest.net/viewtopic.php?id=6204). * See the installation instructions in [README](README.md) if you need more details. * You are familiar with the basics of the game. * How to walk, jump, and climb. @@ -38,7 +37,7 @@ Walk away from the node you just punched. Now, punch another node. A black cube ### WorldEdit GUI -Open the main WorldEdit GUI from your inventory screen. +Open the main WorldEdit GUI from your inventory screen. The icon looks like a globe with a red dot in the center. Press the "Get/Set Positions" button. On the new screen, press the "Set Position 1" button. The inventory screen should close. diff --git a/worldedit_gui/depends.txt b/worldedit_gui/depends.txt index 299d946..d603ac9 100644 --- a/worldedit_gui/depends.txt +++ b/worldedit_gui/depends.txt @@ -1,4 +1,5 @@ worldedit worldedit_commands unified_inventory? -inventory_plus? \ No newline at end of file +inventory_plus? +creative? \ No newline at end of file diff --git a/worldedit_gui/init.lua b/worldedit_gui/init.lua index 9373cf8..80e5a29 100644 --- a/worldedit_gui/init.lua +++ b/worldedit_gui/init.lua @@ -1,7 +1,5 @@ worldedit = worldedit or {} ---wip: simply add a button to the player inventory if unified_inventory AND inventory++ are both not installed - --[[ Example: @@ -69,7 +67,8 @@ local get_formspec = function(name, identifier) return worldedit.pages["worldedit_gui"].get_formspec(name) --default to showing main page if an unknown page is given end -if unified_inventory then +--implement worldedit.show_page(name, page) in different ways depending on the available APIs +if unified_inventory then --unified inventory installed local old_func = worldedit.register_gui_function worldedit.register_gui_function = function(identifier, options) old_func(identifier, options) @@ -96,7 +95,7 @@ if unified_inventory then worldedit.show_page = function(name, page) minetest.get_player_by_name(name):set_inventory_formspec(get_formspec(name, page)) end -elseif inventory_plus then +elseif inventory_plus then --inventory++ installed minetest.register_on_joinplayer(function(player) inventory_plus.register_button(player, "worldedit_gui", "WorldEdit") end) @@ -121,11 +120,57 @@ elseif inventory_plus then worldedit.show_page = function(name, page) inventory_plus.set_inventory_formspec(minetest.get_player_by_name(name), get_formspec(name, page)) end -else - worldedit.show_page = function(name, page) - minetest.log("error", "WorldEdit GUI cannot be shown, requires unified_inventory or inventory_plus") +else --fallback button + local player_formspecs = {} + + local update_main_formspec = function(name) + local formspec = player_formspecs[name] + if not formspec then + return + end + local player = minetest.get_player_by_name(name) + if minetest.setting_getbool("creative_mode") and creative_inventory then --creative_inventory is active + formspec = formspec .. "image_button[6,0;1,1;inventory_plus_worldedit_gui.png;worldedit_gui;]" + else + formspec = formspec .. "image_button[0,0;1,1;inventory_plus_worldedit_gui.png;worldedit_gui;]" + end + player:set_inventory_formspec(formspec) + end + + minetest.register_on_joinplayer(function(player) + local name = player:get_player_name() + minetest.after(1, function() + player_formspecs[name] = player:get_inventory_formspec() + minetest.after(0.01, function() + update_main_formspec(name) + end) + end) + end) + + minetest.register_on_leaveplayer(function(player) + player_formspecs[player:get_player_name()] = nil + end) + + minetest.register_on_player_receive_fields(function(player, formname, fields) + local name = player:get_player_name() + if fields.worldedit_gui then --main page + worldedit.show_page(name, "worldedit_gui") + return true + elseif fields.worldedit_gui_exit then --return to original page + update_main_formspec(name) + return true + else --deal with creative_inventory setting the formspec on every single message + minetest.after(0.01,function() + update_main_formspec(name) + end) + return false --continue processing in creative inventory + end + end) + + worldedit.show_page = function(name, page) + local player = minetest.get_player_by_name(name) + player:set_inventory_formspec(get_formspec(name, page)) end - minetest.log("error", "WorldEdit GUI is unavailable, requires unified_inventory or inventory_plus") end worldedit.register_gui_function("worldedit_gui", {