work-in-progress gui system updating + some settings system updating
authorPerttu Ahola <celeron55@gmail.com>
Thu, 23 Dec 2010 15:09:49 +0000 (17:09 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Thu, 23 Dec 2010 15:09:49 +0000 (17:09 +0200)
Makefile
src/guiPauseMenu.cpp
src/guiPauseMenu.h
src/guiTextInputMenu.cpp [new file with mode: 0644]
src/guiTextInputMenu.h [new file with mode: 0644]
src/main.cpp
src/mapblockobject.h
src/modalMenu.h
src/utility.h

index 25e58a99a7005e05741f87f80b1c4c52382d78a0..39ab170598f958fb2be13bfe063f1bdafecf7c73 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
 # It's usually sufficient to change just the target name and source file list\r
 # and be sure that CXX is set to a valid compiler\r
 TARGET = test\r
-SOURCE_FILES = guiInventoryMenu.cpp irrlichtwrapper.cpp guiPauseMenu.cpp defaultsettings.cpp mapnode.cpp tile.cpp voxel.cpp mapblockobject.cpp inventory.cpp debug.cpp serialization.cpp light.cpp filesys.cpp connection.cpp environment.cpp client.cpp server.cpp socket.cpp mapblock.cpp mapsector.cpp heightmap.cpp map.cpp player.cpp utility.cpp main.cpp test.cpp\r
+SOURCE_FILES = guiTextInputMenu.cpp guiInventoryMenu.cpp irrlichtwrapper.cpp guiPauseMenu.cpp defaultsettings.cpp mapnode.cpp tile.cpp voxel.cpp mapblockobject.cpp inventory.cpp debug.cpp serialization.cpp light.cpp filesys.cpp connection.cpp environment.cpp client.cpp server.cpp socket.cpp mapblock.cpp mapsector.cpp heightmap.cpp map.cpp player.cpp utility.cpp main.cpp test.cpp\r
 SOURCES = $(addprefix src/, $(SOURCE_FILES))\r
 BUILD_DIR = build\r
 OBJECTS = $(addprefix $(BUILD_DIR)/, $(SOURCE_FILES:.cpp=.o))\r
index ed4f0cd6f5bcb0685041656f60f5c56cfaf71f77..2a0b3cb0c653c8cf9aac8e8dce9cc3b18da5dadd 100644 (file)
@@ -17,7 +17,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
 */\r
 \r
-\r
 #include "guiPauseMenu.h"\r
 #include "debug.h"\r
 #include "serialization.h"\r
@@ -174,7 +173,7 @@ bool GUIPauseMenu::OnEvent(const SEvent& event)
                        }\r
                }\r
        }\r
-\r
+       \r
        return Parent ? Parent->OnEvent(event) : false;\r
 }\r
 \r
index 7c37af8efac7989336b84a717a7e50aba6403ff3..187d20edb29e1ad6e9dd4bb93f4b70595f145433 100644 (file)
@@ -17,7 +17,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
 */\r
 \r
-\r
 #ifndef GUIPAUSEMENU_HEADER\r
 #define GUIPAUSEMENU_HEADER\r
 \r
diff --git a/src/guiTextInputMenu.cpp b/src/guiTextInputMenu.cpp
new file mode 100644 (file)
index 0000000..8a9da34
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+Minetest-c55
+Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "guiTextInputMenu.h"
+#include "debug.h"
+#include "serialization.h"
+#include <string>
+
+GUITextInputMenu::GUITextInputMenu(gui::IGUIEnvironment* env,
+               gui::IGUIElement* parent, s32 id,
+               int *active_menu_count,
+               TextDest *dest,
+               std::wstring initial_text
+):
+       GUIModalMenu(env, parent, id, active_menu_count),
+       m_dest(dest),
+       m_initial_text(initial_text)
+{
+}
+
+GUITextInputMenu::~GUITextInputMenu()
+{
+       removeChildren();
+}
+
+void GUITextInputMenu::removeChildren()
+{
+       {
+               gui::IGUIElement *e = getElementFromId(256);
+               if(e != NULL)
+                       e->remove();
+       }
+       {
+               gui::IGUIElement *e = getElementFromId(257);
+               if(e != NULL)
+                       e->remove();
+       }
+}
+
+void GUITextInputMenu::regenerateGui(v2u32 screensize)
+{
+       std::wstring text;
+
+       {
+               gui::IGUIElement *e = getElementFromId(256);
+               if(e != NULL)
+               {
+                       text = e->getText();
+               }
+               else
+               {
+                       text = m_initial_text;
+                       m_initial_text = L"";
+               }
+       }
+
+       /*
+               Remove stuff
+       */
+       removeChildren();
+       
+       /*
+               Calculate new sizes and positions
+       */
+       core::rect<s32> rect(
+                       screensize.X/2 - 580/2,
+                       screensize.Y/2 - 300/2,
+                       screensize.X/2 + 580/2,
+                       screensize.Y/2 + 300/2
+       );
+       
+       DesiredRect = rect;
+       recalculateAbsolutePosition(false);
+
+       v2s32 size = rect.getSize();
+
+       /*
+               Add stuff
+       */
+       {
+               core::rect<s32> rect(0, 0, 300, 30);
+               rect = rect + v2s32(size.X/2-300/2, size.Y/2-30/2-25);
+               gui::IGUIElement *e = 
+               Environment->addEditBox(text.c_str(), rect, true, this, 256);
+               Environment->setFocus(e);
+       }
+       {
+               core::rect<s32> rect(0, 0, 140, 30);
+               rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+25);
+               Environment->addButton(rect, this, 257, L"Proceed");
+       }
+}
+
+void GUITextInputMenu::drawMenu()
+{
+       gui::IGUISkin* skin = Environment->getSkin();
+       if (!skin)
+               return;
+       video::IVideoDriver* driver = Environment->getVideoDriver();
+       
+       video::SColor bgcolor(140,0,0,0);
+       driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
+
+       gui::IGUIElement::draw();
+}
+
+bool GUITextInputMenu::OnEvent(const SEvent& event)
+{
+       if(event.EventType==EET_KEY_INPUT_EVENT)
+       {
+               if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
+               {
+                       quitMenu();
+                       return true;
+               }
+       }
+       if(event.EventType==EET_GUI_EVENT)
+       {
+               if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
+                               && isVisible())
+               {
+                       if(!canTakeFocus(event.GUIEvent.Element))
+                       {
+                               dstream<<"GUITextInputMenu: Not allowing focus change."
+                                               <<std::endl;
+                               // Returning true disables focus change
+                               return true;
+                       }
+               }
+               if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
+               {
+                       switch(event.GUIEvent.Caller->getID())
+                       {
+                       case 257:
+                               if(m_dest)
+                               {
+                                       gui::IGUIElement *e = getElementFromId(256);
+                                       if(e != NULL)
+                                       {
+                                               m_dest->gotText(e->getText());
+                                       }
+                                       delete m_dest;
+                               }
+                               quitMenu();
+                               break;
+                       }
+               }
+       }
+
+       return Parent ? Parent->OnEvent(event) : false;
+}
+
diff --git a/src/guiTextInputMenu.h b/src/guiTextInputMenu.h
new file mode 100644 (file)
index 0000000..2efc190
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+Minetest-c55
+Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#ifndef GUITEXTINPUTMENU_HEADER
+#define GUITEXTINPUTMENU_HEADER
+
+#include "common_irrlicht.h"
+#include "modalMenu.h"
+#include "utility.h"
+#include <string>
+
+struct TextDest
+{
+       virtual void gotText(std::wstring text) = 0;
+};
+
+class GUITextInputMenu : public GUIModalMenu
+{
+public:
+       GUITextInputMenu(gui::IGUIEnvironment* env,
+                       gui::IGUIElement* parent, s32 id,
+                       int *active_menu_count,
+                       TextDest *dest,
+                       std::wstring initial_text);
+       ~GUITextInputMenu();
+       
+       void removeChildren();
+       /*
+               Remove and re-add (or reposition) stuff
+       */
+       void regenerateGui(v2u32 screensize);
+
+       void drawMenu();
+
+       bool OnEvent(const SEvent& event);
+       
+private:
+       TextDest *m_dest;
+       std::wstring m_initial_text;
+};
+
+#endif
+
index 4d8a952ba406e615b962cca5ad47c9cd35b6d229..fe0bfb09cdd4407f1afe718408083ce8f098eb59 100644 (file)
@@ -224,11 +224,12 @@ TODO: Convert the text input system to use a modal menu... or something
 #include "constants.h"\r
 #include "strfnd.h"\r
 #include "porting.h"\r
-#include "guiPauseMenu.h"\r
 #include "irrlichtwrapper.h"\r
 #include "gettime.h"\r
 #include "porting.h"\r
+#include "guiPauseMenu.h"\r
 #include "guiInventoryMenu.h"\r
+#include "guiTextInputMenu.h"\r
 \r
 IrrlichtWrapper *g_irrlicht;\r
 \r
@@ -287,12 +288,6 @@ Queue<InventoryAction*> inventory_action_queue;
 // This is a copy of the inventory that the client's environment has\r
 Inventory local_inventory;\r
 \r
-std::wstring g_text_buffer;\r
-bool g_text_buffer_accepted = false;\r
-\r
-// When true, the mouse and keyboard are grabbed\r
-bool g_game_focused = true;\r
-\r
 /*\r
        Debug streams\r
 */\r
@@ -334,6 +329,15 @@ public:
        // This is the one method that we have to implement\r
        virtual bool OnEvent(const SEvent& event)\r
        {\r
+               /*\r
+                       React to nothing here if a menu is active\r
+               */\r
+               if(noMenuActive() == false)\r
+               {\r
+                       clearInput();\r
+                       return false;\r
+               }\r
+\r
                // Remember whether each key is down or up\r
                if(event.EventType == irr::EET_KEY_INPUT_EVENT)\r
                {\r
@@ -342,82 +346,46 @@ public:
                        if(event.KeyInput.PressedDown)\r
                        {\r
                                //dstream<<"Pressed key: "<<(char)event.KeyInput.Key<<std::endl;\r
-                               if(g_game_focused == false)\r
-                               {\r
-                                       s16 key = event.KeyInput.Key;\r
-                                       if(key == irr::KEY_RETURN || key == irr::KEY_ESCAPE)\r
-                                       {\r
-                                               g_text_buffer_accepted = true;\r
-                                       }\r
-                                       else if(key == irr::KEY_BACK)\r
-                                       {\r
-                                               if(g_text_buffer.size() > 0)\r
-                                                       g_text_buffer = g_text_buffer.substr\r
-                                                                       (0, g_text_buffer.size()-1);\r
-                                       }\r
-                                       else\r
-                                       {\r
-                                               wchar_t wc = event.KeyInput.Char;\r
-                                               if(wc != 0)\r
-                                                       g_text_buffer += wc;\r
-                                       }\r
-                               }\r
                                \r
-                               //if(pauseMenu != NULL)\r
+                               /*\r
+                                       Launch menus\r
+                               */\r
+\r
                                if(guienv != NULL && guiroot != NULL && g_device != NULL)\r
                                {\r
                                        if(event.KeyInput.Key == irr::KEY_ESCAPE)\r
                                        {\r
-                                               if(g_game_focused == true && noMenuActive())\r
-                                               {\r
-                                                       dstream<<DTIME<<"MyEventReceiver: "\r
-                                                                       <<"Launching pause menu"<<std::endl;\r
-                                                       // It will delete itself by itself\r
-                                                       GUIPauseMenu *menu = new\r
-                                                                       GUIPauseMenu(guienv, guiroot, -1, g_device,\r
-                                                                       &g_active_menu_count);\r
-                                                       menu->drop();\r
-                                                       return true;\r
-                                               }\r
+                                               dstream<<DTIME<<"MyEventReceiver: "\r
+                                                               <<"Launching pause menu"<<std::endl;\r
+                                               // It will delete itself by itself\r
+                                               (new GUIPauseMenu(guienv, guiroot, -1, g_device,\r
+                                                               &g_active_menu_count))->drop();\r
+                                               return true;\r
                                        }\r
-                               }\r
-\r
-                               //if(inventoryMenu != NULL)\r
-                               if(guienv != NULL && guiroot != NULL && g_device != NULL)\r
-                               {\r
                                        if(event.KeyInput.Key == irr::KEY_KEY_I)\r
                                        {\r
-                                               if(g_game_focused == true && noMenuActive())\r
-                                               {\r
-                                                       dstream<<DTIME<<"MyEventReceiver: "\r
-                                                                       <<"Launching inventory"<<std::endl;\r
-                                                       GUIInventoryMenu *inventoryMenu = new\r
-                                                                       GUIInventoryMenu(guienv, guiroot, -1,\r
-                                                                       &local_inventory, &inventory_action_queue,\r
-                                                                       &g_active_menu_count);\r
-                                                       inventoryMenu->drop();\r
-                                                       return true;\r
-                                               }\r
+                                               dstream<<DTIME<<"MyEventReceiver: "\r
+                                                               <<"Launching inventory"<<std::endl;\r
+                                               (new GUIInventoryMenu(guienv, guiroot, -1,\r
+                                                               &local_inventory, &inventory_action_queue,\r
+                                                               &g_active_menu_count))->drop();\r
+                                               return true;\r
                                        }\r
                                }\r
 \r
                                // Material selection\r
                                if(event.KeyInput.Key == irr::KEY_KEY_F)\r
                                {\r
-                                       if(g_game_focused == true)\r
-                                       {\r
-                                               if(g_selected_item < PLAYER_INVENTORY_SIZE-1)\r
-                                                       g_selected_item++;\r
-                                               else\r
-                                                       g_selected_item = 0;\r
-                                               dstream<<DTIME<<"Selected item: "\r
-                                                               <<g_selected_item<<std::endl;\r
-                                       }\r
+                                       if(g_selected_item < PLAYER_INVENTORY_SIZE-1)\r
+                                               g_selected_item++;\r
+                                       else\r
+                                               g_selected_item = 0;\r
+                                       dstream<<DTIME<<"Selected item: "\r
+                                                       <<g_selected_item<<std::endl;\r
                                }\r
 \r
                                // Viewing range selection\r
-                               if(event.KeyInput.Key == irr::KEY_KEY_R\r
-                                               && g_game_focused)\r
+                               if(event.KeyInput.Key == irr::KEY_KEY_R)\r
                                {\r
                                        JMutexAutoLock lock(g_range_mutex);\r
                                        if(g_viewing_range_all)\r
@@ -433,8 +401,7 @@ public:
                                }\r
 \r
                                // Print debug stacks\r
-                               if(event.KeyInput.Key == irr::KEY_KEY_P\r
-                                               && g_game_focused)\r
+                               if(event.KeyInput.Key == irr::KEY_KEY_P)\r
                                {\r
                                        dstream<<"-----------------------------------------"\r
                                                        <<std::endl;\r
@@ -508,10 +475,11 @@ public:
                return keyIsDown[keyCode];\r
        }\r
 \r
-       MyEventReceiver()\r
+       void clearInput()\r
        {\r
                for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)\r
                                keyIsDown[i] = false;\r
+               \r
                leftclicked = false;\r
                rightclicked = false;\r
                leftreleased = false;\r
@@ -522,6 +490,11 @@ public:
                right_active = false;\r
        }\r
 \r
+       MyEventReceiver()\r
+       {\r
+               clearInput();\r
+       }\r
+\r
        bool leftclicked;\r
        bool rightclicked;\r
        bool leftreleased;\r
@@ -574,17 +547,6 @@ public:
 \r
 InputHandler *g_input = NULL;\r
 \r
-void focusGame()\r
-{\r
-       g_input->clear();\r
-       g_game_focused = true;\r
-}\r
-\r
-void unFocusGame()\r
-{\r
-       g_game_focused = false;\r
-}\r
-\r
 class RealInputHandler : public InputHandler\r
 {\r
 public:\r
@@ -617,14 +579,10 @@ public:
        \r
        virtual bool getLeftClicked()\r
        {\r
-               if(g_game_focused == false)\r
-                       return false;\r
                return m_receiver->leftclicked;\r
        }\r
        virtual bool getRightClicked()\r
        {\r
-               if(g_game_focused == false)\r
-                       return false;\r
                return m_receiver->rightclicked;\r
        }\r
        virtual void resetLeftClicked()\r
@@ -638,14 +596,10 @@ public:
 \r
        virtual bool getLeftReleased()\r
        {\r
-               if(g_game_focused == false)\r
-                       return false;\r
                return m_receiver->leftreleased;\r
        }\r
        virtual bool getRightReleased()\r
        {\r
-               if(g_game_focused == false)\r
-                       return false;\r
                return m_receiver->rightreleased;\r
        }\r
        virtual void resetLeftReleased()\r
@@ -1015,11 +969,6 @@ private:
        Text input system\r
 */\r
 \r
-struct TextDest\r
-{\r
-       virtual void sendText(std::string text) = 0;\r
-};\r
-\r
 struct TextDestSign : public TextDest\r
 {\r
        TextDestSign(v3s16 blockpos, s16 id, Client *client)\r
@@ -1028,11 +977,12 @@ struct TextDestSign : public TextDest
                m_id = id;\r
                m_client = client;\r
        }\r
-       void sendText(std::string text)\r
+       void gotText(std::wstring text)\r
        {\r
+               std::string ntext = wide_to_narrow(text);\r
                dstream<<"Changing text of a sign object: "\r
-                               <<text<<std::endl;\r
-               m_client->sendSignText(m_blockpos, m_id, text);\r
+                               <<ntext<<std::endl;\r
+               m_client->sendSignText(m_blockpos, m_id, ntext);\r
        }\r
 \r
        v3s16 m_blockpos;\r
@@ -1040,39 +990,6 @@ struct TextDestSign : public TextDest
        Client *m_client;\r
 };\r
 \r
-struct TextInput\r
-{\r
-       TextDest *dest;\r
-       gui::IGUIStaticText* guitext;\r
-       /*std::wstring buffer;\r
-       bool buffer_accepted;*/\r
-\r
-       TextInput()\r
-       {\r
-               dest = NULL;\r
-               guitext = NULL;\r
-               //buffer_accepted = false;\r
-       }\r
-\r
-       void start(TextDest *a_dest)\r
-       {\r
-               unFocusGame();\r
-\r
-               guitext = guienv->addStaticText(L"",\r
-                               core::rect<s32>(150,100,550,120),\r
-                               true, // border?\r
-                               false, // wordwrap?\r
-                               NULL);\r
-\r
-               guitext->setDrawBackground(true);\r
-\r
-               g_text_buffer = L"";\r
-               g_text_buffer_accepted = false;\r
-\r
-               dest = a_dest;\r
-       }\r
-};\r
-\r
 int main(int argc, char *argv[])\r
 {\r
        /*\r
@@ -1318,15 +1235,18 @@ int main(int argc, char *argv[])
        {\r
                snprintf(connect_name, 100, "%s", cmd_args.get("address").c_str());\r
        }\r
-       else if(g_settings.get("address") != "" && is_yes(g_settings.get("host_game")) == false)\r
-       {\r
-               std::cout<<g_settings.get("address")<<std::endl;\r
-               snprintf(connect_name, 100, "%s", g_settings.get("address").c_str());\r
-       }\r
-       else\r
+       else if(is_yes(g_settings.get("host_game")) == false)\r
        {\r
-               std::cout<<"Address to connect to [empty = host a game]: ";\r
-               std::cin.getline(connect_name, 100);\r
+               if(g_settings.get("address") != "")\r
+               {\r
+                       std::cout<<g_settings.get("address")<<std::endl;\r
+                       snprintf(connect_name, 100, "%s", g_settings.get("address").c_str());\r
+               }\r
+               else\r
+               {\r
+                       std::cout<<"Address to connect to [empty = host a game]: ";\r
+                       std::cin.getline(connect_name, 100);\r
+               }\r
        }\r
        \r
        if(connect_name[0] == 0){\r
@@ -1545,9 +1465,6 @@ int main(int argc, char *argv[])
                Add some gui stuff\r
        */\r
 \r
-       // Text input system\r
-       TextInput text_input;\r
-       \r
        GUIQuickInventory *quick_inventory = new GUIQuickInventory\r
                        (guienv, NULL, v2s32(10, 70), 5, &local_inventory);\r
        \r
@@ -1559,15 +1476,9 @@ int main(int argc, char *argv[])
        guiroot = guienv->addStaticText(L"",\r
                        core::rect<s32>(0, 0, 10000, 10000));\r
        \r
-       // Pause menu\r
-       //pauseMenu = new GUIPauseMenu(guienv, root, -1, device);\r
-       \r
-       // Inventory menu\r
-       /*inventoryMenu = new GUIInventoryMenu(guienv, guiroot, -1, &local_inventory,\r
-                       &inventory_action_queue);*/\r
-\r
-       //pauseMenu->launch();\r
-       //inventoryMenu->launch();\r
+       // Test the text input system\r
+       /*(new GUITextInputMenu(guienv, guiroot, -1, &g_active_menu_count,\r
+                       NULL))->drop();*/\r
 \r
        // First line of debug text\r
        gui::IGUIStaticText *guitext = guienv->addStaticText(\r
@@ -1619,9 +1530,6 @@ int main(int argc, char *argv[])
                v2u32 screensize = driver->getScreenSize();\r
                core::vector2d<s32> displaycenter(screensize.X/2,screensize.Y/2);\r
                \r
-               /*pauseMenu->resizeGui();\r
-               inventoryMenu->resizeGui();*/\r
-\r
                // Hilight boxes collected during the loop and displayed\r
                core::list< core::aabbox3d<f32> > hilightboxes;\r
                \r
@@ -1652,7 +1560,6 @@ int main(int argc, char *argv[])
                        Viewing range\r
                */\r
                \r
-               //updateViewingRange(dtime, &client);\r
                updateViewingRange(busytime, &client);\r
                \r
                /*\r
@@ -1771,24 +1678,10 @@ int main(int argc, char *argv[])
                */\r
                g_input->step(dtime);\r
 \r
-               /*\r
-                       Special keys\r
-               */\r
-               /*if(g_esc_pressed)\r
-               {\r
-                       break;\r
-               }*/\r
-               /*if(g_i_pressed)\r
-               {\r
-                       inventoryMenu->setVisible(true);\r
-                       g_i_pressed = false;\r
-               }*/\r
-\r
                /*\r
                        Player speed control\r
                */\r
                \r
-               if(g_game_focused)\r
                {\r
                        /*bool a_up,\r
                        bool a_down,\r
@@ -1810,14 +1703,7 @@ int main(int argc, char *argv[])
                        );\r
                        client.setPlayerControl(control);\r
                }\r
-               else\r
-               {\r
-                       // Set every key to inactive\r
-                       PlayerControl control;\r
-                       client.setPlayerControl(control);\r
-               }\r
 \r
-               //timer1.stop();\r
                /*\r
                        Process environment\r
                */\r
@@ -1842,11 +1728,7 @@ int main(int argc, char *argv[])
                        Mouse and camera control\r
                */\r
                \r
-               if((device->isWindowActive()\r
-                               && g_game_focused\r
-                               && noMenuActive()\r
-                               )\r
-                               || random_input)\r
+               if((device->isWindowActive() && noMenuActive()) || random_input)\r
                {\r
                        if(!random_input)\r
                                device->getCursorControl()->setVisible(false);\r
@@ -1940,16 +1822,24 @@ int main(int argc, char *argv[])
                                if(selected_object->getTypeId() == MAPBLOCKOBJECT_TYPE_SIGN)\r
                                {\r
                                        dstream<<"Sign object right-clicked"<<std::endl;\r
+                                       \r
+                                       if(random_input == false)\r
+                                       {\r
+                                               // Get a new text for it\r
 \r
-                                       text_input.start(new TextDestSign(\r
-                                                       selected_object->getBlock()->getPos(),\r
-                                                       selected_object->getId(),\r
-                                                       &client));\r
+                                               TextDest *dest = new TextDestSign(\r
+                                                               selected_object->getBlock()->getPos(),\r
+                                                               selected_object->getId(),\r
+                                                               &client);\r
 \r
-                                       if(random_input)\r
-                                       {\r
-                                               g_text_buffer = L"ASD LOL 8)";\r
-                                               g_text_buffer_accepted = true;\r
+                                               SignObject *sign_object = (SignObject*)selected_object;\r
+\r
+                                               std::wstring wtext =\r
+                                                               narrow_to_wide(sign_object->getText());\r
+\r
+                                               (new GUITextInputMenu(guienv, guiroot, -1,\r
+                                                               &g_active_menu_count, dest,\r
+                                                               wtext))->drop();\r
                                        }\r
                                }\r
                                /*\r
@@ -2328,38 +2218,6 @@ int main(int argc, char *argv[])
                        delete a;\r
                }\r
 \r
-               if(text_input.guitext != NULL)\r
-               {\r
-                       /*wchar_t temptext[100];\r
-                       swprintf(temptext, 100,\r
-                                       SWPRINTF_CHARSTRING,\r
-                                       g_text_buffer.substr(0,99).c_str()\r
-                                       );*/\r
-                       text_input.guitext->setText(g_text_buffer.c_str());\r
-               }\r
-\r
-               /*\r
-                       Text input stuff\r
-               */\r
-               if(text_input.guitext != NULL && g_text_buffer_accepted)\r
-               {\r
-                       text_input.guitext->remove();\r
-                       text_input.guitext = NULL;\r
-                       \r
-                       if(text_input.dest != NULL)\r
-                       {\r
-                               std::string text = wide_to_narrow(g_text_buffer);\r
-                               dstream<<"Sending text: "<<text<<std::endl;\r
-                               text_input.dest->sendText(text);\r
-                               delete text_input.dest;\r
-                               text_input.dest = NULL;\r
-                       }\r
-\r
-                       focusGame();\r
-               }\r
-\r
-               //guiupdatetimer.stop();\r
-\r
                /*\r
                        Drawing begins\r
                */\r
index 30fa797f4928253cbd34bf40c22e1150c449c53c..a65ffd8e82b0df5a467aa1633bc8ad464c685e3e 100644 (file)
@@ -531,6 +531,11 @@ public:
                setBlockChanged();
        }
 
+       std::string getText()
+       {
+               return m_text;
+       }
+
        void setYaw(f32 yaw)
        {
                m_yaw = yaw;
index 3706d86dc08b5c0d32b47480457430197099443f..e2e8b29f640045c3e4b5418c7385cb756c7fbce5 100644 (file)
@@ -22,7 +22,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "common_irrlicht.h"
 
-//TODO: Change GUIElement private
+/*
+       Remember to drop() the menu after creating, so that it can
+       remove itself when it wants to.
+*/
+
 class GUIModalMenu : public gui::IGUIElement
 {
 public:
@@ -50,18 +54,6 @@ public:
                return (e && (e == this || isMyChild(e))) || m_allow_focus_removal;
        }
 
-       void quitMenu()
-       {
-               m_allow_focus_removal = true;
-               // This removes Environment's grab on us
-               Environment->removeFocus(this);
-               this->remove();
-       }
-
-       virtual void regenerateGui(v2u32 screensize) = 0;
-
-       virtual void drawMenu() = 0;
-
        void draw()
        {
                if(!IsVisible)
@@ -78,10 +70,25 @@ public:
                drawMenu();
        }
        
+       /*
+               This should be called when the menu wants to quit
+       */
+       void quitMenu()
+       {
+               m_allow_focus_removal = true;
+               // This removes Environment's grab on us
+               Environment->removeFocus(this);
+               this->remove();
+       }
+
+       virtual void regenerateGui(v2u32 screensize) = 0;
+       virtual void drawMenu() = 0;
        virtual bool OnEvent(const SEvent& event) { return false; };
        
 private:
        int *m_active_menu_count;
+       // This might be necessary to expose to the implementation if it
+       // wants to launch other menus
        bool m_allow_focus_removal;
        v2u32 m_screensize_old;
 };
index 4e2e132e95e13b23d9b918407445748ca2b3b386..bcdcd15509b4affbbaef125198d09bc843f1028b 100644 (file)
@@ -1009,10 +1009,11 @@ public:
        // Asks if empty
        bool getBoolAsk(std::string name, std::string question, bool def)
        {
-               std::string s = get(name);
-               if(s != "")
-                       return is_yes(s);
+               // If it is in settings
+               if(m_settings.find(name))
+                       return getBool(name);
                
+               std::string s;
                char templine[10];
                std::cout<<question<<" [y/N]: ";
                std::cin.getline(templine, 10);
@@ -1039,10 +1040,11 @@ public:
 
        u16 getU16Ask(std::string name, std::string question, u16 def)
        {
-               std::string s = get(name);
-               if(s != "")
-                       return stoi(s, 0, 65535);
+               // If it is in settings
+               if(m_settings.find(name))
+                       return getU16(name);
                
+               std::string s;
                char templine[10];
                std::cout<<question<<" ["<<def<<"]: ";
                std::cin.getline(templine, 10);