Made the main menu a bit more unique looking
authorPerttu Ahola <celeron55@gmail.com>
Sat, 23 Apr 2011 21:11:23 +0000 (00:11 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sat, 23 Apr 2011 21:11:23 +0000 (00:11 +0300)
data/menulogo.png [new file with mode: 0644]
src/game.cpp
src/guiMainMenu.cpp
src/guiMainMenu.h
src/main.cpp

diff --git a/data/menulogo.png b/data/menulogo.png
new file mode 100644 (file)
index 0000000..76595c4
Binary files /dev/null and b/data/menulogo.png differ
index 9a0fd312b2727487df109f068807e7b2b124e6d7..c806034f2e0b58abff34d97bb167d1795b78c3c3 100644 (file)
@@ -652,15 +652,33 @@ void the_game(
                gui_loadingtext->remove();
                return;
        }
+
+       /*
+               Attempt to connect to the server
+       */
        
        dstream<<DTIME<<"Connecting to server at ";
        connect_address.print(&dstream);
        dstream<<std::endl;
        client.connect(connect_address);
+
+       bool could_connect = false;
        
        try{
-               while(client.connectedAndInitialized() == false)
+               float time_counter = 0.0;
+               for(;;)
                {
+                       if(client.connectedAndInitialized())
+                       {
+                               could_connect = true;
+                               break;
+                       }
+                       // Wait for 10 seconds
+                       if(time_counter >= 10.0)
+                       {
+                               break;
+                       }
+
                        // Update screen
                        driver->beginScene(true, true, video::SColor(255,0,0,0));
                        guienv->drawAll();
@@ -675,12 +693,15 @@ void the_game(
                        
                        // Delay a bit
                        sleep_ms(100);
+                       time_counter += 0.1;
                }
        }
        catch(con::PeerNotFoundException &e)
+       {}
+
+       if(could_connect == false)
        {
                std::cout<<DTIME<<"Timed out."<<std::endl;
-               //return 0;
                error_message = L"Connection timed out.";
                gui_loadingtext->remove();
                return;
index 6c5d6553cd98607482c1dcff9c320ceeb74f7109..04341fe227f81dc18463f29e2803f56351257f05 100644 (file)
@@ -64,6 +64,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
        std::wstring text_address;
        std::wstring text_port;
        bool creative_mode;
+       bool enable_damage;
 
        {
                gui::IGUIElement *e = getElementFromId(258);
@@ -93,6 +94,13 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
                else
                        creative_mode = m_data->creative_mode;
        }
+       {
+               gui::IGUIElement *e = getElementFromId(261);
+               if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
+                       enable_damage = ((gui::IGUICheckBox*)e)->isChecked();
+               else
+                       enable_damage = m_data->enable_damage;
+       }
 
        /*
                Remove stuff
@@ -102,32 +110,51 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
        /*
                Calculate new sizes and positions
        */
+       
+       v2s32 size(620, 430);
+
        core::rect<s32> rect(
-                       screensize.X/2 - 580/2,
-                       screensize.Y/2 - 300/2,
-                       screensize.X/2 + 580/2,
-                       screensize.Y/2 + 300/2
+                       screensize.X/2 - size.X/2,
+                       screensize.Y/2 - size.Y/2,
+                       screensize.X/2 + size.X/2,
+                       screensize.Y/2 + size.Y/2
        );
-       
+
        DesiredRect = rect;
        recalculateAbsolutePosition(false);
 
-       v2s32 size = rect.getSize();
+       //v2s32 size = rect.getSize();
 
        /*
                Add stuff
        */
 
+       /*
+               Client section
+       */
+
+       v2s32 topleft_client(40, 0);
+       v2s32 size_client = size - v2s32(40, 0);
+       
+       {
+               core::rect<s32> rect(0, 0, 20, 125);
+               rect += topleft_client + v2s32(-15, 60);
+               const wchar_t *text = L"C\nL\nI\nE\nN\nT";
+               //gui::IGUIStaticText *t =
+               Environment->addStaticText(text, rect, false, true, this, -1);
+               //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
+       }
+
        // Nickname
        {
                core::rect<s32> rect(0, 0, 100, 20);
-               rect = rect + v2s32(size.X/2 - 250, size.Y/2 - 100 + 6);
+               rect += topleft_client + v2s32(40, 50+6);
                const wchar_t *text = L"Nickname";
                Environment->addStaticText(text, rect, false, true, this, -1);
        }
        {
                core::rect<s32> rect(0, 0, 250, 30);
-               rect = rect + v2s32(size.X/2 - 130, size.Y/2 - 100);
+               rect += topleft_client + v2s32(160, 50);
                gui::IGUIElement *e = 
                Environment->addEditBox(text_name.c_str(), rect, true, this, 258);
                if(text_name == L"")
@@ -136,13 +163,13 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
        // Address + port
        {
                core::rect<s32> rect(0, 0, 100, 20);
-               rect = rect + v2s32(size.X/2 - 250, size.Y/2 - 50 + 6);
+               rect += topleft_client + v2s32(40, 100+6);
                const wchar_t *text = L"Address + Port";
                Environment->addStaticText(text, rect, false, true, this, -1);
        }
        {
                core::rect<s32> rect(0, 0, 250, 30);
-               rect = rect + v2s32(size.X/2 - 130, size.Y/2 - 50);
+               rect += topleft_client + v2s32(160, 100);
                gui::IGUIElement *e = 
                Environment->addEditBox(text_address.c_str(), rect, true, this, 256);
                if(text_name != L"")
@@ -150,37 +177,56 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
        }
        {
                core::rect<s32> rect(0, 0, 100, 30);
-               rect = rect + v2s32(size.X/2 - 130 + 250 + 20, size.Y/2 - 50);
+               //rect += topleft_client + v2s32(160+250+20, 125);
+               rect += topleft_client + v2s32(size_client.X-40-100, 100);
                Environment->addEditBox(text_port.c_str(), rect, true, this, 257);
        }
        {
                core::rect<s32> rect(0, 0, 400, 20);
-               rect = rect + v2s32(size.X/2 - 130, size.Y/2 - 50 + 35);
+               rect += topleft_client + v2s32(160, 100+35);
                const wchar_t *text = L"Leave address blank to start a local server.";
                Environment->addStaticText(text, rect, false, true, this, -1);
        }
-       // Server parameters
+       // Start game button
        {
-               core::rect<s32> rect(0, 0, 100, 20);
-               rect = rect + v2s32(size.X/2 - 250, size.Y/2 + 25 + 6);
-               const wchar_t *text = L"Server params";
+               core::rect<s32> rect(0, 0, 180, 30);
+               //rect += topleft_client + v2s32(size_client.X/2-180/2, 225-30/2);
+               rect += topleft_client + v2s32(size_client.X-180-40, 150+25);
+               Environment->addButton(rect, this, 257, L"Start Game / Connect");
+       }
+
+       /*
+               Server section
+       */
+
+       v2s32 topleft_server(40, 250);
+       v2s32 size_server = size - v2s32(40, 0);
+       
+       {
+               core::rect<s32> rect(0, 0, 20, 125);
+               rect += topleft_server + v2s32(-15, 40);
+               const wchar_t *text = L"S\nE\nR\nV\nE\nR";
+               //gui::IGUIStaticText *t =
                Environment->addStaticText(text, rect, false, true, this, -1);
+               //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
        }
+
+       // Server parameters
        {
                core::rect<s32> rect(0, 0, 250, 30);
-               rect = rect + v2s32(size.X/2 - 130, size.Y/2 + 25);
+               rect += topleft_server + v2s32(40, 30);
                Environment->addCheckBox(creative_mode, rect, this, 259, L"Creative Mode");
        }
-       // Start game button
        {
-               core::rect<s32> rect(0, 0, 180, 30);
-               rect = rect + v2s32(size.X/2-180/2, size.Y/2-30/2 + 100);
-               Environment->addButton(rect, this, 257, L"Start Game / Connect");
+               core::rect<s32> rect(0, 0, 250, 30);
+               rect += topleft_server + v2s32(40, 60);
+               Environment->addCheckBox(enable_damage, rect, this, 261, L"Enable Damage");
        }
        // Map delete button
        {
                core::rect<s32> rect(0, 0, 130, 30);
-               rect = rect + v2s32(size.X/2-130/2+200, size.Y/2-30/2 + 100);
+               //rect += topleft_server + v2s32(size_server.X-40-130, 100+25);
+               rect += topleft_server + v2s32(40, 100+25);
                Environment->addButton(rect, this, 260, L"Delete map");
        }
 }
@@ -192,8 +238,22 @@ void GUIMainMenu::drawMenu()
                return;
        video::IVideoDriver* driver = Environment->getVideoDriver();
        
+       /*video::SColor bgcolor(140,0,0,0);
+       driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);*/
+
        video::SColor bgcolor(140,0,0,0);
-       driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
+
+       {
+               core::rect<s32> rect(0, 0, 620, 230);
+               rect += AbsoluteRect.UpperLeftCorner;
+               driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
+       }
+
+       {
+               core::rect<s32> rect(0, 250, 620, 430);
+               rect += AbsoluteRect.UpperLeftCorner;
+               driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
+       }
 
        gui::IGUIElement::draw();
 }
@@ -220,6 +280,11 @@ void GUIMainMenu::acceptInput()
                if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
                        m_data->creative_mode = ((gui::IGUICheckBox*)e)->isChecked();
        }
+       {
+               gui::IGUIElement *e = getElementFromId(261);
+               if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
+                       m_data->enable_damage = ((gui::IGUICheckBox*)e)->isChecked();
+       }
        
        m_accepted = true;
 }
index 010d0bf6d975e71dc27b2c29d1bd7e69a39226c9..d003599c42a48d0e7a3bd63d4c78d5b787273233 100644 (file)
@@ -31,6 +31,7 @@ struct MainMenuData
 {
        MainMenuData():
                creative_mode(false),
+               enable_damage(false),
                delete_map(false)
        {}
        // These are in the native format of the gui elements
@@ -38,6 +39,7 @@ struct MainMenuData
        std::wstring port;
        std::wstring name;
        bool creative_mode;
+       bool enable_damage;
        // If map deletion is requested, this is set to true
        bool delete_map;
 };
index 0426b6a49dd7fa03a2c34c1ba2717b3f8cac2d1b..429b769f7b28081ffa1270e1753d237b1f3c0b2c 100644 (file)
@@ -164,6 +164,9 @@ TODO: A setting for enabling bilinear filtering for textures
 \r
 TODO: Better control of draw_control.wanted_max_blocks\r
 \r
+TODO: Get player texture (and some others) from the specified texture\r
+      directory\r
+\r
 Configuration:\r
 --------------\r
 \r
@@ -886,6 +889,53 @@ void SpeedTests()
        }\r
 }\r
 \r
+void drawMenuBackground(video::IVideoDriver* driver)\r
+{\r
+       core::dimension2d<u32> screensize = driver->getScreenSize();\r
+               \r
+       video::ITexture *bgtexture =\r
+                       driver->getTexture(porting::getDataPath("mud.png").c_str());\r
+       if(bgtexture)\r
+       {\r
+               s32 texturesize = 128;\r
+               s32 tiled_y = screensize.Height / texturesize + 1;\r
+               s32 tiled_x = screensize.Width / texturesize + 1;\r
+               \r
+               for(s32 y=0; y<tiled_y; y++)\r
+               for(s32 x=0; x<tiled_x; x++)\r
+               {\r
+                       core::rect<s32> rect(0,0,texturesize,texturesize);\r
+                       rect += v2s32(x*texturesize, y*texturesize);\r
+                       driver->draw2DImage(bgtexture, rect,\r
+                               core::rect<s32>(core::position2d<s32>(0,0),\r
+                               core::dimension2di(bgtexture->getSize())),\r
+                               NULL, NULL, true);\r
+               }\r
+       }\r
+       \r
+       video::ITexture *logotexture =\r
+                       driver->getTexture(porting::getDataPath("menulogo.png").c_str());\r
+       if(logotexture)\r
+       {\r
+               v2s32 logosize(logotexture->getOriginalSize().Width,\r
+                               logotexture->getOriginalSize().Height);\r
+               logosize *= 4;\r
+\r
+               video::SColor bgcolor(255,50,50,50);\r
+               core::rect<s32> bgrect(0, screensize.Height-logosize.Y-20,\r
+                               screensize.Width, screensize.Height);\r
+               driver->draw2DRectangle(bgcolor, bgrect, NULL);\r
+\r
+               core::rect<s32> rect(0,0,logosize.X,logosize.Y);\r
+               rect += v2s32(screensize.Width/2,screensize.Height-10-logosize.Y);\r
+               rect -= v2s32(logosize.X/2, 0);\r
+               driver->draw2DImage(logotexture, rect,\r
+                       core::rect<s32>(core::position2d<s32>(0,0),\r
+                       core::dimension2di(logotexture->getSize())),\r
+                       NULL, NULL, true);\r
+       }\r
+}\r
+\r
 int main(int argc, char *argv[])\r
 {\r
        /*\r
@@ -1303,6 +1353,7 @@ int main(int argc, char *argv[])
                                menudata.name = narrow_to_wide(playername);\r
                                menudata.port = narrow_to_wide(itos(port));\r
                                menudata.creative_mode = g_settings.getBool("creative_mode");\r
+                               menudata.enable_damage = g_settings.getBool("enable_damage");\r
 \r
                                GUIMainMenu *menu =\r
                                                new GUIMainMenu(guienv, guiroot, -1, \r
@@ -1332,7 +1383,11 @@ int main(int argc, char *argv[])
 \r
                                        //driver->beginScene(true, true, video::SColor(255,0,0,0));\r
                                        driver->beginScene(true, true, video::SColor(255,128,128,128));\r
+\r
+                                       drawMenuBackground(driver);\r
+\r
                                        guienv->drawAll();\r
+                                       \r
                                        driver->endScene();\r
                                }\r
                                \r
@@ -1358,8 +1413,8 @@ int main(int argc, char *argv[])
                                int newport = stoi(wide_to_narrow(menudata.port));\r
                                if(newport != 0)\r
                                        port = newport;\r
-                               //port = stoi(wide_to_narrow(menudata.port));\r
                                g_settings.set("creative_mode", itos(menudata.creative_mode));\r
+                               g_settings.set("enable_damage", itos(menudata.enable_damage));\r
                                \r
                                // Check for valid parameters, restart menu if invalid.\r
                                if(playername == "")\r