]> git.lizzy.rs Git - worldedit.git/commitdiff
The WorldEdit GUI now has no hard dependencies.
authorUberi <azhang9@gmail.com>
Mon, 30 Dec 2013 19:27:47 +0000 (14:27 -0500)
committerUberi <azhang9@gmail.com>
Mon, 30 Dec 2013 19:27:47 +0000 (14:27 -0500)
README.md
Tutorial.md
worldedit_gui/depends.txt
worldedit_gui/init.lua

index 0133e0117158bc3748deefe5704f4989170268cd..62d245a66b7ebdaf4df43da3202ac2e6d79aa212 100644 (file)
--- 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
 -------------
index 3ffc5ce705c274bf214c84c83070ea3950826b35..abe554ad379bfcc79f7dae422255a6de3547ac6a 100644 (file)
@@ -9,7 +9,6 @@ Let's start with a few assumptions:
 * You have WorldEdit installed as a mod.\r
   * If using Windows, [MODSTER](https://forum.minetest.net/viewtopic.php?pid=101463) makes installing mods totally painless.\r
   * Simply download the file, extract the archive, and move it to the correct mod folder for Minetest.\r
-  * 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).\r
   * See the installation instructions in [README](README.md) if you need more details.\r
 * You are familiar with the basics of the game.\r
   * How to walk, jump, and climb.\r
@@ -38,7 +37,7 @@ Walk away from the node you just punched. Now, punch another node. A black cube
 \r
 ### WorldEdit GUI\r
 \r
-Open the main WorldEdit GUI from your inventory screen.\r
+Open the main WorldEdit GUI from your inventory screen. The icon looks like a globe with a red dot in the center.\r
 \r
 Press the "Get/Set Positions" button. On the new screen, press the "Set Position 1" button. The inventory screen should close.\r
 \r
index 299d946cf3708cb6ef53efdbcbc16815d30477b2..d603ac9cac5f778c133cd84d5a68bc8c612ce827 100644 (file)
@@ -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
index 9373cf8bebabe1df3a1fbe1599f5c4bfd32d97f1..80e5a29cbba2d5db1969f0c128775656d41de54e 100644 (file)
@@ -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
+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)
-               minetest.log("error", "WorldEdit GUI cannot be shown, requires unified_inventory or inventory_plus")
+               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", {