forked from mirror/openmw-tes3mp
adjust availability of main menu items based on game state
This commit is contained in:
parent
f45cff8aff
commit
1c7a4d4b3a
2 changed files with 84 additions and 49 deletions
|
@ -15,56 +15,25 @@ namespace MWGui
|
|||
|
||||
MainMenu::MainMenu(int w, int h)
|
||||
: OEngine::GUI::Layout("openmw_mainmenu.layout")
|
||||
, mButtonBox(0)
|
||||
, mButtonBox(0), mWidth (w), mHeight (h)
|
||||
{
|
||||
onResChange(w,h);
|
||||
updateMenu();
|
||||
}
|
||||
|
||||
void MainMenu::onResChange(int w, int h)
|
||||
{
|
||||
setCoord(0,0,w,h);
|
||||
mWidth = w;
|
||||
mHeight = h;
|
||||
|
||||
updateMenu();
|
||||
}
|
||||
|
||||
if (mButtonBox)
|
||||
MyGUI::Gui::getInstance ().destroyWidget(mButtonBox);
|
||||
void MainMenu::setVisible (bool visible)
|
||||
{
|
||||
if (visible)
|
||||
updateMenu();
|
||||
|
||||
mButtonBox = mMainWidget->createWidget<MyGUI::Widget>("", MyGUI::IntCoord(0, 0, 0, 0), MyGUI::Align::Default);
|
||||
int curH = 0;
|
||||
|
||||
std::vector<std::string> buttons;
|
||||
buttons.push_back("return");
|
||||
buttons.push_back("newgame");
|
||||
buttons.push_back("loadgame");
|
||||
buttons.push_back("savegame");
|
||||
buttons.push_back("options");
|
||||
//buttons.push_back("credits");
|
||||
buttons.push_back("exitgame");
|
||||
|
||||
int maxwidth = 0;
|
||||
|
||||
mButtons.clear();
|
||||
for (std::vector<std::string>::iterator it = buttons.begin(); it != buttons.end(); ++it)
|
||||
{
|
||||
MWGui::ImageButton* button = mButtonBox->createWidget<MWGui::ImageButton>
|
||||
("ImageBox", MyGUI::IntCoord(0, curH, 0, 0), MyGUI::Align::Default);
|
||||
button->setProperty("ImageHighlighted", "textures\\menu_" + *it + "_over.dds");
|
||||
button->setProperty("ImageNormal", "textures\\menu_" + *it + ".dds");
|
||||
button->setProperty("ImagePushed", "textures\\menu_" + *it + "_pressed.dds");
|
||||
MyGUI::IntSize requested = button->getRequestedSize();
|
||||
button->eventMouseButtonClick += MyGUI::newDelegate(this, &MainMenu::onButtonClicked);
|
||||
mButtons[*it] = button;
|
||||
curH += requested.height;
|
||||
|
||||
if (requested.width > maxwidth)
|
||||
maxwidth = requested.width;
|
||||
}
|
||||
for (std::map<std::string, MWGui::ImageButton*>::iterator it = mButtons.begin(); it != mButtons.end(); ++it)
|
||||
{
|
||||
MyGUI::IntSize requested = it->second->getRequestedSize();
|
||||
it->second->setCoord((maxwidth-requested.width) / 2, it->second->getTop(), requested.width, requested.height);
|
||||
}
|
||||
|
||||
mButtonBox->setCoord (w/2 - maxwidth/2, h/2 - curH/2, maxwidth, curH);
|
||||
OEngine::GUI::Layout::setVisible (visible);
|
||||
}
|
||||
|
||||
void MainMenu::onButtonClicked(MyGUI::Widget *sender)
|
||||
|
@ -98,4 +67,61 @@ namespace MWGui
|
|||
}
|
||||
}
|
||||
|
||||
void MainMenu::updateMenu()
|
||||
{
|
||||
setCoord(0,0, mWidth, mHeight);
|
||||
|
||||
|
||||
if (mButtonBox)
|
||||
MyGUI::Gui::getInstance ().destroyWidget(mButtonBox);
|
||||
|
||||
mButtonBox = mMainWidget->createWidget<MyGUI::Widget>("", MyGUI::IntCoord(0, 0, 0, 0), MyGUI::Align::Default);
|
||||
int curH = 0;
|
||||
|
||||
MWBase::StateManager::State state = MWBase::Environment::get().getStateManager()->getState();
|
||||
|
||||
std::vector<std::string> buttons;
|
||||
|
||||
if (state==MWBase::StateManager::State_Running)
|
||||
buttons.push_back("return");
|
||||
|
||||
buttons.push_back("newgame");
|
||||
|
||||
/// \todo hide, if no saved game is available
|
||||
buttons.push_back("loadgame");
|
||||
|
||||
if (state==MWBase::StateManager::State_Running)
|
||||
buttons.push_back("savegame");
|
||||
|
||||
buttons.push_back("options");
|
||||
//buttons.push_back("credits");
|
||||
buttons.push_back("exitgame");
|
||||
|
||||
int maxwidth = 0;
|
||||
|
||||
mButtons.clear();
|
||||
for (std::vector<std::string>::iterator it = buttons.begin(); it != buttons.end(); ++it)
|
||||
{
|
||||
MWGui::ImageButton* button = mButtonBox->createWidget<MWGui::ImageButton>
|
||||
("ImageBox", MyGUI::IntCoord(0, curH, 0, 0), MyGUI::Align::Default);
|
||||
button->setProperty("ImageHighlighted", "textures\\menu_" + *it + "_over.dds");
|
||||
button->setProperty("ImageNormal", "textures\\menu_" + *it + ".dds");
|
||||
button->setProperty("ImagePushed", "textures\\menu_" + *it + "_pressed.dds");
|
||||
MyGUI::IntSize requested = button->getRequestedSize();
|
||||
button->eventMouseButtonClick += MyGUI::newDelegate(this, &MainMenu::onButtonClicked);
|
||||
mButtons[*it] = button;
|
||||
curH += requested.height;
|
||||
|
||||
if (requested.width > maxwidth)
|
||||
maxwidth = requested.width;
|
||||
}
|
||||
for (std::map<std::string, MWGui::ImageButton*>::iterator it = mButtons.begin(); it != mButtons.end(); ++it)
|
||||
{
|
||||
MyGUI::IntSize requested = it->second->getRequestedSize();
|
||||
it->second->setCoord((maxwidth-requested.width) / 2, it->second->getTop(), requested.width, requested.height);
|
||||
}
|
||||
|
||||
mButtonBox->setCoord (mWidth/2 - maxwidth/2, mHeight/2 - curH/2, maxwidth, curH);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,17 +7,26 @@ namespace MWGui
|
|||
|
||||
class MainMenu : public OEngine::GUI::Layout
|
||||
{
|
||||
public:
|
||||
MainMenu(int w, int h);
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
|
||||
void onResChange(int w, int h);
|
||||
public:
|
||||
|
||||
private:
|
||||
MyGUI::Widget* mButtonBox;
|
||||
MainMenu(int w, int h);
|
||||
|
||||
std::map<std::string, MWGui::ImageButton*> mButtons;
|
||||
void onResChange(int w, int h);
|
||||
|
||||
void onButtonClicked (MyGUI::Widget* sender);
|
||||
virtual void setVisible (bool visible);
|
||||
|
||||
private:
|
||||
|
||||
MyGUI::Widget* mButtonBox;
|
||||
|
||||
std::map<std::string, MWGui::ImageButton*> mButtons;
|
||||
|
||||
void onButtonClicked (MyGUI::Widget* sender);
|
||||
|
||||
void updateMenu();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue