2012-08-10 13:15:48 +00:00
|
|
|
#include "mainmenu.hpp"
|
|
|
|
|
|
|
|
#include "../mwbase/environment.hpp"
|
2012-08-12 16:11:09 +00:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2013-02-26 18:37:47 +00:00
|
|
|
#include "../mwbase/soundmanager.hpp"
|
2013-05-15 15:54:18 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
#include "../mwbase/journal.hpp"
|
|
|
|
#include "../mwbase/dialoguemanager.hpp"
|
2013-11-16 10:07:23 +00:00
|
|
|
#include "../mwbase/statemanager.hpp"
|
2012-08-10 13:15:48 +00:00
|
|
|
|
2013-11-05 18:50:24 +00:00
|
|
|
#include "savegamedialog.hpp"
|
|
|
|
|
2012-08-10 13:15:48 +00:00
|
|
|
namespace MWGui
|
|
|
|
{
|
|
|
|
|
|
|
|
MainMenu::MainMenu(int w, int h)
|
|
|
|
: OEngine::GUI::Layout("openmw_mainmenu.layout")
|
2013-11-18 14:52:25 +00:00
|
|
|
, mButtonBox(0), mWidth (w), mHeight (h)
|
2012-08-11 15:26:01 +00:00
|
|
|
{
|
2013-11-18 14:52:25 +00:00
|
|
|
updateMenu();
|
2012-08-11 15:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::onResChange(int w, int h)
|
2012-08-10 13:15:48 +00:00
|
|
|
{
|
2013-11-18 14:52:25 +00:00
|
|
|
mWidth = w;
|
|
|
|
mHeight = h;
|
|
|
|
|
|
|
|
updateMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::setVisible (bool visible)
|
|
|
|
{
|
|
|
|
if (visible)
|
|
|
|
updateMenu();
|
|
|
|
|
|
|
|
OEngine::GUI::Layout::setVisible (visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::onButtonClicked(MyGUI::Widget *sender)
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getSoundManager()->playSound("Menu Click", 1.f, 1.f);
|
|
|
|
if (sender == mButtons["return"])
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getSoundManager ()->resumeSounds (MWBase::SoundManager::Play_TypeSfx);
|
|
|
|
MWBase::Environment::get().getWindowManager ()->removeGuiMode (GM_MainMenu);
|
|
|
|
}
|
|
|
|
else if (sender == mButtons["options"])
|
|
|
|
MWBase::Environment::get().getWindowManager ()->pushGuiMode (GM_Settings);
|
|
|
|
else if (sender == mButtons["exitgame"])
|
|
|
|
MWBase::Environment::get().getStateManager()->requestQuit();
|
|
|
|
else if (sender == mButtons["newgame"])
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getStateManager()->newGame();
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (sender == mButtons["loadgame"])
|
|
|
|
{
|
|
|
|
MWGui::SaveGameDialog* dialog = new MWGui::SaveGameDialog();
|
|
|
|
dialog->setLoadOrSave(true);
|
|
|
|
dialog->setVisible(true);
|
|
|
|
}
|
|
|
|
else if (sender == mButtons["savegame"])
|
|
|
|
{
|
|
|
|
MWGui::SaveGameDialog* dialog = new MWGui::SaveGameDialog();
|
|
|
|
dialog->setLoadOrSave(false);
|
|
|
|
dialog->setVisible(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::updateMenu()
|
|
|
|
{
|
|
|
|
setCoord(0,0, mWidth, mHeight);
|
2012-08-10 13:15:48 +00:00
|
|
|
|
|
|
|
|
2012-08-11 15:26:01 +00:00
|
|
|
if (mButtonBox)
|
|
|
|
MyGUI::Gui::getInstance ().destroyWidget(mButtonBox);
|
|
|
|
|
2013-01-03 00:09:03 +00:00
|
|
|
mButtonBox = mMainWidget->createWidget<MyGUI::Widget>("", MyGUI::IntCoord(0, 0, 0, 0), MyGUI::Align::Default);
|
2012-08-10 13:15:48 +00:00
|
|
|
int curH = 0;
|
|
|
|
|
2013-11-18 14:52:25 +00:00
|
|
|
MWBase::StateManager::State state = MWBase::Environment::get().getStateManager()->getState();
|
|
|
|
|
2013-01-03 00:09:03 +00:00
|
|
|
std::vector<std::string> buttons;
|
2013-11-18 14:52:25 +00:00
|
|
|
|
|
|
|
if (state==MWBase::StateManager::State_Running)
|
|
|
|
buttons.push_back("return");
|
|
|
|
|
2013-05-15 15:54:18 +00:00
|
|
|
buttons.push_back("newgame");
|
2013-11-18 14:52:25 +00:00
|
|
|
|
|
|
|
/// \todo hide, if no saved game is available
|
2013-11-15 09:29:53 +00:00
|
|
|
buttons.push_back("loadgame");
|
2013-11-18 14:52:25 +00:00
|
|
|
|
|
|
|
if (state==MWBase::StateManager::State_Running)
|
|
|
|
buttons.push_back("savegame");
|
|
|
|
|
2013-01-03 00:09:03 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-11-18 14:52:25 +00:00
|
|
|
mButtonBox->setCoord (mWidth/2 - maxwidth/2, mHeight/2 - curH/2, maxwidth, curH);
|
2013-11-05 18:50:24 +00:00
|
|
|
|
2012-08-10 13:15:48 +00:00
|
|
|
}
|
|
|
|
}
|