Crude tab test in main menu (requires gui redesign for the additional tabs)
parent
11b86f8d8a
commit
eea3277b81
|
@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include <IGUIStaticText.h>
|
||||
#include <IGUIFont.h>
|
||||
#include <IGUIListBox.h>
|
||||
#include <IGUITabControl.h>
|
||||
// For IGameCallback
|
||||
#include "guiPauseMenu.h"
|
||||
#include "gettext.h"
|
||||
|
@ -81,6 +82,14 @@ enum
|
|||
GUI_ID_DELETE_WORLD_BUTTON,
|
||||
GUI_ID_CREATE_WORLD_BUTTON,
|
||||
GUI_ID_WORLD_LISTBOX,
|
||||
GUI_ID_TAB_CONTROL,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
TAB_SINGLEPLAYER=0,
|
||||
TAB_MULTIPLAYER,
|
||||
TAB_ADVANCED
|
||||
};
|
||||
|
||||
GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env,
|
||||
|
@ -92,7 +101,8 @@ GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env,
|
|||
GUIModalMenu(env, parent, id, menumgr),
|
||||
m_data(data),
|
||||
m_accepted(false),
|
||||
m_gamecallback(gamecallback)
|
||||
m_gamecallback(gamecallback),
|
||||
m_is_regenerating(false)
|
||||
{
|
||||
assert(m_data);
|
||||
this->env = env;
|
||||
|
@ -125,11 +135,14 @@ void GUIMainMenu::removeChildren()
|
|||
|
||||
void GUIMainMenu::regenerateGui(v2u32 screensize)
|
||||
{
|
||||
m_is_regenerating = true;
|
||||
/*
|
||||
Read stuff from elements into m_data
|
||||
*/
|
||||
readInput(m_data);
|
||||
|
||||
int active_tab = getTab();
|
||||
|
||||
/*
|
||||
Remove stuff
|
||||
*/
|
||||
|
@ -139,7 +152,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
|
|||
Calculate new sizes and positions
|
||||
*/
|
||||
|
||||
v2s32 size(620, 430);
|
||||
v2s32 size(620, 460);
|
||||
|
||||
core::rect<s32> rect(
|
||||
screensize.X/2 - size.X/2,
|
||||
|
@ -157,15 +170,29 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
|
|||
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
|
||||
*/
|
||||
|
||||
v2s32 topleft_client(40, 0);
|
||||
v2s32 size_client = size - v2s32(40, 0);
|
||||
|
||||
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
|
||||
{
|
||||
core::rect<s32> rect(0, 0, 300, 30);
|
||||
|
@ -182,6 +209,8 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
|
|||
Environment->addStaticText(text, rect, false, true, this, -1);
|
||||
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
|
||||
}
|
||||
if(getTab() != TAB_SINGLEPLAYER)
|
||||
{
|
||||
// Nickname + password
|
||||
{
|
||||
core::rect<s32> rect(0, 0, 110, 20);
|
||||
|
@ -238,6 +267,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
|
|||
Environment->addStaticText(wgettext("Leave address blank to start a local server."),
|
||||
rect, false, true, this, -1);
|
||||
}
|
||||
}
|
||||
{
|
||||
core::rect<s32> rect(0, 0, 250, 30);
|
||||
rect += topleft_client + v2s32(35, 150);
|
||||
|
@ -279,13 +309,11 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
|
|||
Environment->addButton(rect, this, GUI_ID_CHANGE_KEYS_BUTTON,
|
||||
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);
|
||||
|
@ -335,7 +363,10 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
|
|||
}
|
||||
e->setSelected(m_data->selected_world);
|
||||
}
|
||||
}
|
||||
changeCtype("C");
|
||||
|
||||
m_is_regenerating = false;
|
||||
}
|
||||
|
||||
void GUIMainMenu::drawMenu()
|
||||
|
@ -352,12 +383,13 @@ void GUIMainMenu::drawMenu()
|
|||
|
||||
{
|
||||
core::rect<s32> rect(0, 0, 620, 270);
|
||||
rect += AbsoluteRect.UpperLeftCorner;
|
||||
rect += AbsoluteRect.UpperLeftCorner + v2s32(0,30);
|
||||
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;
|
||||
driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
|
||||
}
|
||||
|
@ -367,6 +399,15 @@ void GUIMainMenu::drawMenu()
|
|||
|
||||
void GUIMainMenu::readInput(MainMenuData *dst)
|
||||
{
|
||||
if(getTab() == TAB_SINGLEPLAYER)
|
||||
{
|
||||
dst->name = L"singleplayer";
|
||||
dst->password = L"";
|
||||
dst->address = L"";
|
||||
dst->port = 30001;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT);
|
||||
if(e != NULL)
|
||||
|
@ -387,6 +428,7 @@ void GUIMainMenu::readInput(MainMenuData *dst)
|
|||
if(e != NULL)
|
||||
dst->port = e->getText();
|
||||
}
|
||||
}
|
||||
{
|
||||
gui::IGUIElement *e = getElementFromId(GUI_ID_CREATIVE_CB);
|
||||
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
|
||||
|
@ -461,6 +503,12 @@ bool GUIMainMenu::OnEvent(const SEvent& event)
|
|||
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)
|
||||
{
|
||||
switch(event.GUIEvent.Caller->getID())
|
||||
|
@ -554,3 +602,11 @@ void GUIMainMenu::deleteWorld(WorldSpec spec)
|
|||
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);
|
||||
void createNewWorld(std::wstring name, std::string gameid);
|
||||
void deleteWorld(WorldSpec spec);
|
||||
int getTab();
|
||||
|
||||
private:
|
||||
MainMenuData *m_data;
|
||||
|
@ -93,6 +94,8 @@ private:
|
|||
gui::IGUIElement* parent;
|
||||
s32 id;
|
||||
IMenuManager *menumgr;
|
||||
|
||||
bool m_is_regenerating;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -125,12 +125,12 @@ public:
|
|||
|
||||
protected:
|
||||
//bool m_force_regenerate_gui;
|
||||
v2u32 m_screensize_old;
|
||||
private:
|
||||
IMenuManager *m_menumgr;
|
||||
// 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;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue