Crude tab test in main menu (requires gui redesign for the additional tabs)

This commit is contained in:
Perttu Ahola 2012-03-13 08:50:03 +02:00
parent 11b86f8d8a
commit eea3277b81
3 changed files with 189 additions and 130 deletions

@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <IGUIStaticText.h> #include <IGUIStaticText.h>
#include <IGUIFont.h> #include <IGUIFont.h>
#include <IGUIListBox.h> #include <IGUIListBox.h>
#include <IGUITabControl.h>
// For IGameCallback // For IGameCallback
#include "guiPauseMenu.h" #include "guiPauseMenu.h"
#include "gettext.h" #include "gettext.h"
@ -81,6 +82,14 @@ enum
GUI_ID_DELETE_WORLD_BUTTON, GUI_ID_DELETE_WORLD_BUTTON,
GUI_ID_CREATE_WORLD_BUTTON, GUI_ID_CREATE_WORLD_BUTTON,
GUI_ID_WORLD_LISTBOX, GUI_ID_WORLD_LISTBOX,
GUI_ID_TAB_CONTROL,
};
enum
{
TAB_SINGLEPLAYER=0,
TAB_MULTIPLAYER,
TAB_ADVANCED
}; };
GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env, GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env,
@ -92,7 +101,8 @@ GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env,
GUIModalMenu(env, parent, id, menumgr), GUIModalMenu(env, parent, id, menumgr),
m_data(data), m_data(data),
m_accepted(false), m_accepted(false),
m_gamecallback(gamecallback) m_gamecallback(gamecallback),
m_is_regenerating(false)
{ {
assert(m_data); assert(m_data);
this->env = env; this->env = env;
@ -125,10 +135,13 @@ void GUIMainMenu::removeChildren()
void GUIMainMenu::regenerateGui(v2u32 screensize) void GUIMainMenu::regenerateGui(v2u32 screensize)
{ {
m_is_regenerating = true;
/* /*
Read stuff from elements into m_data Read stuff from elements into m_data
*/ */
readInput(m_data); readInput(m_data);
int active_tab = getTab();
/* /*
Remove stuff Remove stuff
@ -139,7 +152,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
Calculate new sizes and positions Calculate new sizes and positions
*/ */
v2s32 size(620, 430); v2s32 size(620, 460);
core::rect<s32> rect( core::rect<s32> rect(
screensize.X/2 - size.X/2, screensize.X/2 - size.X/2,
@ -157,15 +170,29 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
Add stuff Add stuff
*/ */
v2s32 topleft_client(40, 30);
v2s32 size_client = size - v2s32(40, 0);
v2s32 topleft_server(40, 320);
v2s32 size_server = size - v2s32(40, 0);
/* /*
Client section Client section
*/ */
v2s32 topleft_client(40, 0);
v2s32 size_client = size - v2s32(40, 0);
changeCtype(""); changeCtype("");
// Tabs
{
core::rect<s32> rect(0, 0, size_client.X, 30);
rect += topleft_client + v2s32(0, -30);
gui::IGUITabControl *e = Environment->addTabControl(
rect, this, true, true, GUI_ID_TAB_CONTROL);
e->addTab(L"Singleplayer");
e->addTab(L"Multiplayer");
e->addTab(L"Advanced");
e->setActiveTab(active_tab);
}
// Version // Version
{ {
core::rect<s32> rect(0, 0, 300, 30); core::rect<s32> rect(0, 0, 300, 30);
@ -182,61 +209,64 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
Environment->addStaticText(text, rect, false, true, this, -1); Environment->addStaticText(text, rect, false, true, this, -1);
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
} }
// Nickname + password if(getTab() != TAB_SINGLEPLAYER)
{ {
core::rect<s32> rect(0, 0, 110, 20); // Nickname + password
rect += topleft_client + v2s32(35, 50+6); {
Environment->addStaticText(wgettext("Name/Password"), core::rect<s32> rect(0, 0, 110, 20);
rect, false, true, this, -1); rect += topleft_client + v2s32(35, 50+6);
} Environment->addStaticText(wgettext("Name/Password"),
changeCtype("C"); rect, false, true, this, -1);
{ }
core::rect<s32> rect(0, 0, 230, 30); changeCtype("C");
rect += topleft_client + v2s32(160, 50); {
gui::IGUIElement *e = core::rect<s32> rect(0, 0, 230, 30);
Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT); rect += topleft_client + v2s32(160, 50);
if(m_data->name == L"") gui::IGUIElement *e =
Environment->setFocus(e); Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT);
} if(m_data->name == L"")
{ Environment->setFocus(e);
core::rect<s32> rect(0, 0, 120, 30); }
rect += topleft_client + v2s32(size_client.X-60-100, 50); {
gui::IGUIEditBox *e = core::rect<s32> rect(0, 0, 120, 30);
Environment->addEditBox(L"", rect, true, this, 264); rect += topleft_client + v2s32(size_client.X-60-100, 50);
e->setPasswordBox(true); gui::IGUIEditBox *e =
if(m_data->name != L"" && m_data->address != L"") Environment->addEditBox(L"", rect, true, this, 264);
Environment->setFocus(e); e->setPasswordBox(true);
if(m_data->name != L"" && m_data->address != L"")
Environment->setFocus(e);
} }
changeCtype(""); changeCtype("");
// Address + port // Address + port
{ {
core::rect<s32> rect(0, 0, 110, 20); core::rect<s32> rect(0, 0, 110, 20);
rect += topleft_client + v2s32(35, 100+6); rect += topleft_client + v2s32(35, 100+6);
Environment->addStaticText(wgettext("Address/Port"), Environment->addStaticText(wgettext("Address/Port"),
rect, false, true, this, -1); rect, false, true, this, -1);
} }
changeCtype("C"); changeCtype("C");
{ {
core::rect<s32> rect(0, 0, 230, 30); core::rect<s32> rect(0, 0, 230, 30);
rect += topleft_client + v2s32(160, 100); rect += topleft_client + v2s32(160, 100);
gui::IGUIElement *e = gui::IGUIElement *e =
Environment->addEditBox(m_data->address.c_str(), rect, true, this, GUI_ID_ADDRESS_INPUT); Environment->addEditBox(m_data->address.c_str(), rect, true, this, GUI_ID_ADDRESS_INPUT);
if(m_data->name != L"" && m_data->address == L"") if(m_data->name != L"" && m_data->address == L"")
Environment->setFocus(e); Environment->setFocus(e);
} }
{ {
core::rect<s32> rect(0, 0, 120, 30); core::rect<s32> rect(0, 0, 120, 30);
//rect += topleft_client + v2s32(160+250+20, 125); //rect += topleft_client + v2s32(160+250+20, 125);
rect += topleft_client + v2s32(size_client.X-60-100, 100); rect += topleft_client + v2s32(size_client.X-60-100, 100);
Environment->addEditBox(m_data->port.c_str(), rect, true, this, GUI_ID_PORT_INPUT); Environment->addEditBox(m_data->port.c_str(), rect, true, this, GUI_ID_PORT_INPUT);
} }
changeCtype(""); changeCtype("");
{ {
core::rect<s32> rect(0, 0, 400, 20); core::rect<s32> rect(0, 0, 400, 20);
rect += topleft_client + v2s32(160, 100+35); rect += topleft_client + v2s32(160, 100+35);
Environment->addStaticText(wgettext("Leave address blank to start a local server."), Environment->addStaticText(wgettext("Leave address blank to start a local server."),
rect, false, true, this, -1); rect, false, true, this, -1);
}
} }
{ {
core::rect<s32> rect(0, 0, 250, 30); core::rect<s32> rect(0, 0, 250, 30);
@ -279,63 +309,64 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
Environment->addButton(rect, this, GUI_ID_CHANGE_KEYS_BUTTON, Environment->addButton(rect, this, GUI_ID_CHANGE_KEYS_BUTTON,
wgettext("Change keys")); wgettext("Change keys"));
} }
/* if(getTab() != TAB_MULTIPLAYER)
Server section
*/
v2s32 topleft_server(40, 290);
v2s32 size_server = size - v2s32(40, 0);
// SERVER
{ {
core::rect<s32> rect(0, 0, 20, 125); /*
rect += topleft_server + v2s32(-15, 15); Server section
const wchar_t *text = L"S\nE\nR\nV\nE\nR"; */
//gui::IGUIStaticText *t = // SERVER
Environment->addStaticText(text, rect, false, true, this, -1); {
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); core::rect<s32> rect(0, 0, 20, 125);
} rect += topleft_server + v2s32(-15, 15);
// Server parameters const wchar_t *text = L"S\nE\nR\nV\nE\nR";
{ //gui::IGUIStaticText *t =
core::rect<s32> rect(0, 0, 250, 30); Environment->addStaticText(text, rect, false, true, this, -1);
rect += topleft_server + v2s32(20+250+20, 20); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
Environment->addCheckBox(m_data->creative_mode, rect, this, GUI_ID_CREATIVE_CB, }
wgettext("Creative Mode")); // Server parameters
} {
{ core::rect<s32> rect(0, 0, 250, 30);
core::rect<s32> rect(0, 0, 250, 30); rect += topleft_server + v2s32(20+250+20, 20);
rect += topleft_server + v2s32(20+250+20, 40); Environment->addCheckBox(m_data->creative_mode, rect, this, GUI_ID_CREATIVE_CB,
Environment->addCheckBox(m_data->enable_damage, rect, this, GUI_ID_DAMAGE_CB, wgettext("Creative Mode"));
wgettext("Enable Damage")); }
} {
// Delete world button core::rect<s32> rect(0, 0, 250, 30);
{ rect += topleft_server + v2s32(20+250+20, 40);
core::rect<s32> rect(0, 0, 130, 30); Environment->addCheckBox(m_data->enable_damage, rect, this, GUI_ID_DAMAGE_CB,
rect += topleft_server + v2s32(20+250+20, 90); wgettext("Enable Damage"));
Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON, }
wgettext("Delete world")); // Delete world button
} {
// Create world button core::rect<s32> rect(0, 0, 130, 30);
{ rect += topleft_server + v2s32(20+250+20, 90);
core::rect<s32> rect(0, 0, 130, 30); Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON,
rect += topleft_server + v2s32(20+250+20+140, 90); wgettext("Delete world"));
Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON, }
wgettext("Create world")); // Create world button
} {
// World selection listbox core::rect<s32> rect(0, 0, 130, 30);
{ rect += topleft_server + v2s32(20+250+20+140, 90);
core::rect<s32> rect(0, 0, 250, 120); Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON,
rect += topleft_server + v2s32(20, 10); wgettext("Create world"));
gui::IGUIListBox *e = Environment->addListBox(rect, this, }
GUI_ID_WORLD_LISTBOX); // World selection listbox
e->setDrawBackground(true); {
for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin(); core::rect<s32> rect(0, 0, 250, 120);
i != m_data->worlds.end(); i++){ rect += topleft_server + v2s32(20, 10);
e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str()); gui::IGUIListBox *e = Environment->addListBox(rect, this,
GUI_ID_WORLD_LISTBOX);
e->setDrawBackground(true);
for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin();
i != m_data->worlds.end(); i++){
e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str());
}
e->setSelected(m_data->selected_world);
} }
e->setSelected(m_data->selected_world);
} }
changeCtype("C"); changeCtype("C");
m_is_regenerating = false;
} }
void GUIMainMenu::drawMenu() void GUIMainMenu::drawMenu()
@ -352,12 +383,13 @@ void GUIMainMenu::drawMenu()
{ {
core::rect<s32> rect(0, 0, 620, 270); core::rect<s32> rect(0, 0, 620, 270);
rect += AbsoluteRect.UpperLeftCorner; rect += AbsoluteRect.UpperLeftCorner + v2s32(0,30);
driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect); driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
} }
if(getTab() != TAB_MULTIPLAYER)
{ {
core::rect<s32> rect(0, 290, 620, 430); core::rect<s32> rect(0, 320, 620, 460);
rect += AbsoluteRect.UpperLeftCorner; rect += AbsoluteRect.UpperLeftCorner;
driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect); driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
} }
@ -367,25 +399,35 @@ void GUIMainMenu::drawMenu()
void GUIMainMenu::readInput(MainMenuData *dst) void GUIMainMenu::readInput(MainMenuData *dst)
{ {
if(getTab() == TAB_SINGLEPLAYER)
{ {
gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT); dst->name = L"singleplayer";
if(e != NULL) dst->password = L"";
dst->name = e->getText(); dst->address = L"";
dst->port = 30001;
} }
else
{ {
gui::IGUIElement *e = getElementFromId(264); {
if(e != NULL) gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT);
dst->password = e->getText(); if(e != NULL)
} dst->name = e->getText();
{ }
gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT); {
if(e != NULL) gui::IGUIElement *e = getElementFromId(264);
dst->address = e->getText(); if(e != NULL)
} dst->password = e->getText();
{ }
gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT); {
if(e != NULL) gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT);
dst->port = e->getText(); if(e != NULL)
dst->address = e->getText();
}
{
gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT);
if(e != NULL)
dst->port = e->getText();
}
} }
{ {
gui::IGUIElement *e = getElementFromId(GUI_ID_CREATIVE_CB); gui::IGUIElement *e = getElementFromId(GUI_ID_CREATIVE_CB);
@ -461,6 +503,12 @@ bool GUIMainMenu::OnEvent(const SEvent& event)
return true; return true;
} }
} }
if(event.GUIEvent.EventType==gui::EGET_TAB_CHANGED)
{
if(!m_is_regenerating)
regenerateGui(m_screensize_old);
return true;
}
if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED) if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
{ {
switch(event.GUIEvent.Caller->getID()) switch(event.GUIEvent.Caller->getID())
@ -553,4 +601,12 @@ void GUIMainMenu::deleteWorld(WorldSpec spec)
m_data->delete_world_spec = spec; m_data->delete_world_spec = spec;
quitMenu(); quitMenu();
} }
int GUIMainMenu::getTab()
{
gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
return ((gui::IGUITabControl*)e)->getActiveTab();
return TAB_ADVANCED; // Default to advanced
}

@ -83,6 +83,7 @@ public:
bool OnEvent(const SEvent& event); bool OnEvent(const SEvent& event);
void createNewWorld(std::wstring name, std::string gameid); void createNewWorld(std::wstring name, std::string gameid);
void deleteWorld(WorldSpec spec); void deleteWorld(WorldSpec spec);
int getTab();
private: private:
MainMenuData *m_data; MainMenuData *m_data;
@ -93,6 +94,8 @@ private:
gui::IGUIElement* parent; gui::IGUIElement* parent;
s32 id; s32 id;
IMenuManager *menumgr; IMenuManager *menumgr;
bool m_is_regenerating;
}; };
#endif #endif

@ -125,12 +125,12 @@ public:
protected: protected:
//bool m_force_regenerate_gui; //bool m_force_regenerate_gui;
v2u32 m_screensize_old;
private: private:
IMenuManager *m_menumgr; IMenuManager *m_menumgr;
// This might be necessary to expose to the implementation if it // This might be necessary to expose to the implementation if it
// wants to launch other menus // wants to launch other menus
bool m_allow_focus_removal; bool m_allow_focus_removal;
v2u32 m_screensize_old;
}; };