1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 21:49:56 +00:00
openmw-tes3mp/apps/openmw/mwgui/window_manager.cpp

291 lines
7.4 KiB
C++
Raw Normal View History

#include "window_manager.hpp"
2010-09-14 20:10:15 +00:00
#include "layouts.hpp"
#include "text_input.hpp"
#include "race.hpp"
#include "../mwmechanics/mechanicsmanager.hpp"
#include "../mwinput/inputmanager.hpp"
2010-07-20 19:10:51 +00:00
#include "console.hpp"
#include <assert.h>
#include <iostream>
2010-08-22 10:56:35 +00:00
#include <iterator>
using namespace MWGui;
WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment,
const Compiler::Extensions& extensions, bool newGame)
: environment(environment)
, nameDialog(nullptr)
, raceDialog(nullptr)
, nameChosen(false)
, raceChosen(false)
, classChosen(false)
, birthChosen(false)
, reviewNext(false)
, gui(_gui)
, mode(GM_Game)
, shown(GW_ALL)
, allowed(newGame ? GW_None : GW_ALL)
{
// Get size info from the Gui object
assert(gui);
2010-08-30 10:19:45 +00:00
int w = gui->getViewSize().width;
int h = gui->getViewSize().height;
hud = new HUD(w,h);
menu = new MainMenu(w,h);
map = new MapWindow();
stats = new StatsWindow (environment);
#if 0
inventory = new InventoryWindow ();
#endif
console = new Console(w,h, environment, extensions);
// The HUD is always on
hud->setVisible(true);
// Set up visibility
updateVisible();
}
WindowManager::~WindowManager()
{
2010-07-20 19:10:51 +00:00
delete console;
delete hud;
delete map;
delete menu;
delete stats;
#if 0
delete inventory;
#endif
delete nameDialog;
delete raceDialog;
}
void WindowManager::updateVisible()
{
// Start out by hiding everything except the HUD
map->setVisible(false);
menu->setVisible(false);
stats->setVisible(false);
#if 0
inventory->setVisible(false);
#endif
2010-07-20 19:10:51 +00:00
console->disable();
// Mouse is visible whenever we're not in game mode
gui->setVisiblePointer(isGuiMode());
// If in game mode, don't show anything.
if(mode == GM_Game)
{
return;
}
if(mode == GM_MainMenu)
{
// Enable the main menu
menu->setVisible(true);
return;
}
2010-07-20 19:10:51 +00:00
if(mode == GM_Console)
{
console->enable();
return;
}
if (mode == GM_Name)
{
if (!nameDialog)
nameDialog = new TextInputDialog(environment, gui->getViewSize());
std::string sName = getGameSettingString("sName", "Name");
nameDialog->setTextLabel(sName);
nameDialog->setNextButtonShow(nameChosen);
nameDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onNameDialogDone);
nameDialog->open();
return;
}
if (mode == GM_Race)
{
if (!raceDialog)
2010-09-15 19:48:10 +00:00
raceDialog = new RaceDialog(environment, gui->getViewSize());
raceDialog->setNextButtonShow(raceChosen);
raceDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onRaceDialogDone);
raceDialog->eventBack = MyGUI::newDelegate(this, &WindowManager::onRaceDialogBack);
raceDialog->open();
return;
}
if(mode == GM_Inventory)
{
// Ah, inventory mode. First, compute the effective set of
// windows to show. This is controlled both by what windows the
// user has opened/closed (the 'shown' variable) and by what
// windows we are allowed to show (the 'allowed' var.)
int eff = shown & allowed;
// Show the windows we want
2010-09-15 11:16:54 +00:00
map -> setVisible( (eff & GW_Map) != 0 );
stats -> setVisible( (eff & GW_Stats) != 0 );
#if 0
// inventory -> setVisible( eff & GW_Inventory );
#endif
2010-09-14 19:55:41 +00:00
return;
}
// Unsupported mode, switch back to game
// Note: The call will eventually end up this method again but
// will stop at the check if(mode == GM_Game) above.
environment.mInputManager->setGuiMode(GM_Game);
}
void WindowManager::setValue (const std::string& id, const MWMechanics::Stat<int>& value)
{
stats->setValue (id, value);
}
void WindowManager::setValue (const std::string& id, const MWMechanics::Stat<float>& value)
{
stats->setValue (id, value);
}
void WindowManager::setValue (const std::string& id, const MWMechanics::DynamicStat<int>& value)
{
stats->setValue (id, value);
hud->setValue (id, value);
}
void WindowManager::setValue (const std::string& id, const std::string& value)
{
stats->setValue (id, value);
}
2010-09-15 13:32:35 +00:00
void WindowManager::setValue (const std::string& id, int value)
{
stats->setValue (id, value);
}
void WindowManager::configureSkills (const std::set<int>& major, const std::set<int>& minor, const std::set<int>& misc)
{
stats->configureSkills (major, minor, misc);
}
void WindowManager::configureFactions (const std::vector<std::string>& factions)
{
stats->configureFactions (factions);
}
void WindowManager::configureBirthSign (const std::string &signId)
{
stats->configureBirthSign (signId);
}
void WindowManager::setReputation (int reputation)
{
stats->setReputation (reputation);
}
void WindowManager::setBounty (int bounty)
{
stats->setBounty (bounty);
}
void WindowManager::updateSkillArea()
{
stats->updateSkillArea();
}
void WindowManager::messageBox (const std::string& message, const std::vector<std::string>& buttons)
{
std::cout << "message box: " << message << std::endl;
if (!buttons.empty())
2010-08-22 10:56:35 +00:00
{
std::cout << "buttons: ";
std::copy (buttons.begin(), buttons.end(), std::ostream_iterator<std::string> (std::cout, ", "));
std::cout << std::endl;
}
}
2010-09-15 20:22:27 +00:00
const std::string &WindowManager::getGameSettingString(const std::string &id, const std::string &default_)
{
const ESM::GameSetting *setting = environment.mWorld->getStore().gameSettings.search(id);
if (setting && setting->type == ESM::VT_String)
return setting->str;
2010-09-15 20:22:27 +00:00
return default_;
}
void WindowManager::updateCharacterGeneration()
{
if (raceDialog)
{
// TOOD: Uncomment when methods in mechanics manager is implemented
//raceDialog->setRace(environment.mMechanicsManager->getPlayerRace());
//raceDialog->setGender(environment.mMechanicsManager->getPlayerMale() ? RaceDialog::GM_Male : RaceDialog::GM_Female);
// TODO: Face/Hair
}
}
void WindowManager::onNameDialogDone()
{
nameDialog->eventDone = MWGui::TextInputDialog::EventHandle_Void();
bool goNext = nameChosen; // Go to next dialog if name was previously chosen
nameChosen = true;
if (nameDialog)
{
nameDialog->setVisible(false);
environment.mMechanicsManager->setPlayerName(nameDialog->getTextInput());
}
updateCharacterGeneration();
if (reviewNext)
environment.mInputManager->setGuiMode(GM_Review);
else if (goNext)
environment.mInputManager->setGuiMode(GM_Race);
else
environment.mInputManager->setGuiMode(GM_Game);
}
void WindowManager::onRaceDialogDone()
{
raceDialog->eventDone = MWGui::RaceDialog::EventHandle_Void();
bool goNext = raceChosen; // Go to next dialog if race was previously chosen
raceChosen = true;
if (raceDialog)
{
raceDialog->setVisible(false);
environment.mMechanicsManager->setPlayerRace(raceDialog->getRaceId(), raceDialog->getGender() == RaceDialog::GM_Male);
}
updateCharacterGeneration();
if (reviewNext)
environment.mInputManager->setGuiMode(GM_Review);
else if (goNext)
environment.mInputManager->setGuiMode(GM_Class);
else
environment.mInputManager->setGuiMode(GM_Game);
}
void WindowManager::onRaceDialogBack()
{
if (raceDialog)
{
raceDialog->setVisible(false);
environment.mMechanicsManager->setPlayerRace(raceDialog->getRaceId(), raceDialog->getGender() == RaceDialog::GM_Male);
}
updateCharacterGeneration();
environment.mInputManager->setGuiMode(GM_Name);
}