From 7e490e72139fbfe12535c71b27228dd82ef0250b Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 23 Dec 2010 17:09:49 +0200 Subject: work-in-progress gui system updating + some settings system updating --- src/main.cpp | 296 ++++++++++++++++------------------------------------------- 1 file changed, 77 insertions(+), 219 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 4d8a952ba..fe0bfb09c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -224,11 +224,12 @@ TODO: Convert the text input system to use a modal menu... or something #include "constants.h" #include "strfnd.h" #include "porting.h" -#include "guiPauseMenu.h" #include "irrlichtwrapper.h" #include "gettime.h" #include "porting.h" +#include "guiPauseMenu.h" #include "guiInventoryMenu.h" +#include "guiTextInputMenu.h" IrrlichtWrapper *g_irrlicht; @@ -287,12 +288,6 @@ Queue inventory_action_queue; // This is a copy of the inventory that the client's environment has Inventory local_inventory; -std::wstring g_text_buffer; -bool g_text_buffer_accepted = false; - -// When true, the mouse and keyboard are grabbed -bool g_game_focused = true; - /* Debug streams */ @@ -334,6 +329,15 @@ public: // This is the one method that we have to implement virtual bool OnEvent(const SEvent& event) { + /* + React to nothing here if a menu is active + */ + if(noMenuActive() == false) + { + clearInput(); + return false; + } + // Remember whether each key is down or up if(event.EventType == irr::EET_KEY_INPUT_EVENT) { @@ -342,82 +346,46 @@ public: if(event.KeyInput.PressedDown) { //dstream<<"Pressed key: "<<(char)event.KeyInput.Key< 0) - g_text_buffer = g_text_buffer.substr - (0, g_text_buffer.size()-1); - } - else - { - wchar_t wc = event.KeyInput.Char; - if(wc != 0) - g_text_buffer += wc; - } - } - //if(pauseMenu != NULL) + /* + Launch menus + */ + if(guienv != NULL && guiroot != NULL && g_device != NULL) { if(event.KeyInput.Key == irr::KEY_ESCAPE) { - if(g_game_focused == true && noMenuActive()) - { - dstream<drop(); - return true; - } + dstream<drop(); + return true; } - } - - //if(inventoryMenu != NULL) - if(guienv != NULL && guiroot != NULL && g_device != NULL) - { if(event.KeyInput.Key == irr::KEY_KEY_I) { - if(g_game_focused == true && noMenuActive()) - { - dstream<drop(); - return true; - } + dstream<drop(); + return true; } } // Material selection if(event.KeyInput.Key == irr::KEY_KEY_F) { - if(g_game_focused == true) - { - if(g_selected_item < PLAYER_INVENTORY_SIZE-1) - g_selected_item++; - else - g_selected_item = 0; - dstream<clear(); - g_game_focused = true; -} - -void unFocusGame() -{ - g_game_focused = false; -} - class RealInputHandler : public InputHandler { public: @@ -617,14 +579,10 @@ public: virtual bool getLeftClicked() { - if(g_game_focused == false) - return false; return m_receiver->leftclicked; } virtual bool getRightClicked() { - if(g_game_focused == false) - return false; return m_receiver->rightclicked; } virtual void resetLeftClicked() @@ -638,14 +596,10 @@ public: virtual bool getLeftReleased() { - if(g_game_focused == false) - return false; return m_receiver->leftreleased; } virtual bool getRightReleased() { - if(g_game_focused == false) - return false; return m_receiver->rightreleased; } virtual void resetLeftReleased() @@ -1015,11 +969,6 @@ private: Text input system */ -struct TextDest -{ - virtual void sendText(std::string text) = 0; -}; - struct TextDestSign : public TextDest { TextDestSign(v3s16 blockpos, s16 id, Client *client) @@ -1028,11 +977,12 @@ struct TextDestSign : public TextDest m_id = id; m_client = client; } - void sendText(std::string text) + void gotText(std::wstring text) { + std::string ntext = wide_to_narrow(text); dstream<<"Changing text of a sign object: " - <sendSignText(m_blockpos, m_id, text); + <sendSignText(m_blockpos, m_id, ntext); } v3s16 m_blockpos; @@ -1040,39 +990,6 @@ struct TextDestSign : public TextDest Client *m_client; }; -struct TextInput -{ - TextDest *dest; - gui::IGUIStaticText* guitext; - /*std::wstring buffer; - bool buffer_accepted;*/ - - TextInput() - { - dest = NULL; - guitext = NULL; - //buffer_accepted = false; - } - - void start(TextDest *a_dest) - { - unFocusGame(); - - guitext = guienv->addStaticText(L"", - core::rect(150,100,550,120), - true, // border? - false, // wordwrap? - NULL); - - guitext->setDrawBackground(true); - - g_text_buffer = L""; - g_text_buffer_accepted = false; - - dest = a_dest; - } -}; - int main(int argc, char *argv[]) { /* @@ -1318,15 +1235,18 @@ int main(int argc, char *argv[]) { snprintf(connect_name, 100, "%s", cmd_args.get("address").c_str()); } - else if(g_settings.get("address") != "" && is_yes(g_settings.get("host_game")) == false) - { - std::cout<addStaticText(L"", core::rect(0, 0, 10000, 10000)); - // Pause menu - //pauseMenu = new GUIPauseMenu(guienv, root, -1, device); - - // Inventory menu - /*inventoryMenu = new GUIInventoryMenu(guienv, guiroot, -1, &local_inventory, - &inventory_action_queue);*/ - - //pauseMenu->launch(); - //inventoryMenu->launch(); + // Test the text input system + /*(new GUITextInputMenu(guienv, guiroot, -1, &g_active_menu_count, + NULL))->drop();*/ // First line of debug text gui::IGUIStaticText *guitext = guienv->addStaticText( @@ -1619,9 +1530,6 @@ int main(int argc, char *argv[]) v2u32 screensize = driver->getScreenSize(); core::vector2d displaycenter(screensize.X/2,screensize.Y/2); - /*pauseMenu->resizeGui(); - inventoryMenu->resizeGui();*/ - // Hilight boxes collected during the loop and displayed core::list< core::aabbox3d > hilightboxes; @@ -1652,7 +1560,6 @@ int main(int argc, char *argv[]) Viewing range */ - //updateViewingRange(dtime, &client); updateViewingRange(busytime, &client); /* @@ -1771,24 +1678,10 @@ int main(int argc, char *argv[]) */ g_input->step(dtime); - /* - Special keys - */ - /*if(g_esc_pressed) - { - break; - }*/ - /*if(g_i_pressed) - { - inventoryMenu->setVisible(true); - g_i_pressed = false; - }*/ - /* Player speed control */ - if(g_game_focused) { /*bool a_up, bool a_down, @@ -1810,14 +1703,7 @@ int main(int argc, char *argv[]) ); client.setPlayerControl(control); } - else - { - // Set every key to inactive - PlayerControl control; - client.setPlayerControl(control); - } - //timer1.stop(); /* Process environment */ @@ -1842,11 +1728,7 @@ int main(int argc, char *argv[]) Mouse and camera control */ - if((device->isWindowActive() - && g_game_focused - && noMenuActive() - ) - || random_input) + if((device->isWindowActive() && noMenuActive()) || random_input) { if(!random_input) device->getCursorControl()->setVisible(false); @@ -1940,16 +1822,24 @@ int main(int argc, char *argv[]) if(selected_object->getTypeId() == MAPBLOCKOBJECT_TYPE_SIGN) { dstream<<"Sign object right-clicked"<getBlock()->getPos(), - selected_object->getId(), - &client)); + TextDest *dest = new TextDestSign( + selected_object->getBlock()->getPos(), + selected_object->getId(), + &client); - if(random_input) - { - g_text_buffer = L"ASD LOL 8)"; - g_text_buffer_accepted = true; + SignObject *sign_object = (SignObject*)selected_object; + + std::wstring wtext = + narrow_to_wide(sign_object->getText()); + + (new GUITextInputMenu(guienv, guiroot, -1, + &g_active_menu_count, dest, + wtext))->drop(); } } /* @@ -2328,38 +2218,6 @@ int main(int argc, char *argv[]) delete a; } - if(text_input.guitext != NULL) - { - /*wchar_t temptext[100]; - swprintf(temptext, 100, - SWPRINTF_CHARSTRING, - g_text_buffer.substr(0,99).c_str() - );*/ - text_input.guitext->setText(g_text_buffer.c_str()); - } - - /* - Text input stuff - */ - if(text_input.guitext != NULL && g_text_buffer_accepted) - { - text_input.guitext->remove(); - text_input.guitext = NULL; - - if(text_input.dest != NULL) - { - std::string text = wide_to_narrow(g_text_buffer); - dstream<<"Sending text: "<sendText(text); - delete text_input.dest; - text_input.dest = NULL; - } - - focusGame(); - } - - //guiupdatetimer.stop(); - /* Drawing begins */ -- cgit v1.2.3