2010-07-17 12:01:47 +00:00
|
|
|
#include "window_manager.hpp"
|
2010-09-14 20:10:15 +00:00
|
|
|
#include "layouts.hpp"
|
2010-09-14 21:17:08 +00:00
|
|
|
#include "text_input.hpp"
|
2010-09-14 20:01:45 +00:00
|
|
|
#include "race.hpp"
|
2010-07-17 12:01:47 +00:00
|
|
|
|
2010-09-14 19:27:40 +00:00
|
|
|
#include "../mwmechanics/mechanicsmanager.hpp"
|
2010-09-15 12:48:19 +00:00
|
|
|
#include "../mwinput/inputmanager.hpp"
|
2010-09-14 19:27:40 +00:00
|
|
|
|
2010-07-20 19:10:51 +00:00
|
|
|
#include "console.hpp"
|
|
|
|
|
2010-07-17 12:01:47 +00:00
|
|
|
#include <assert.h>
|
2010-08-22 09:22:10 +00:00
|
|
|
#include <iostream>
|
2010-08-22 10:56:35 +00:00
|
|
|
#include <iterator>
|
2010-07-17 12:01:47 +00:00
|
|
|
|
|
|
|
using namespace MWGui;
|
|
|
|
|
2010-07-20 21:21:48 +00:00
|
|
|
WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment,
|
2010-07-21 08:28:58 +00:00
|
|
|
const Compiler::Extensions& extensions, bool newGame)
|
2010-09-14 19:27:40 +00:00
|
|
|
: environment(environment)
|
2010-09-14 21:17:08 +00:00
|
|
|
, nameDialog(nullptr)
|
2010-09-14 19:27:40 +00:00
|
|
|
, 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)
|
2010-07-17 12:01:47 +00:00
|
|
|
{
|
|
|
|
// 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;
|
2010-07-17 12:01:47 +00:00
|
|
|
|
|
|
|
hud = new HUD(w,h);
|
|
|
|
menu = new MainMenu(w,h);
|
|
|
|
map = new MapWindow();
|
2010-09-17 23:30:23 +00:00
|
|
|
stats = new StatsWindow (environment);
|
2010-09-15 11:15:58 +00:00
|
|
|
#if 0
|
2010-09-10 01:29:29 +00:00
|
|
|
inventory = new InventoryWindow ();
|
2010-09-15 11:15:58 +00:00
|
|
|
#endif
|
2010-07-20 21:21:48 +00:00
|
|
|
console = new Console(w,h, environment, extensions);
|
2010-07-17 12:01:47 +00:00
|
|
|
|
|
|
|
// The HUD is always on
|
|
|
|
hud->setVisible(true);
|
|
|
|
|
|
|
|
// Set up visibility
|
|
|
|
updateVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowManager::~WindowManager()
|
|
|
|
{
|
2010-07-20 19:10:51 +00:00
|
|
|
delete console;
|
2010-07-17 12:01:47 +00:00
|
|
|
delete hud;
|
|
|
|
delete map;
|
|
|
|
delete menu;
|
|
|
|
delete stats;
|
2010-09-15 11:15:58 +00:00
|
|
|
#if 0
|
2010-09-10 01:29:29 +00:00
|
|
|
delete inventory;
|
2010-09-15 11:15:58 +00:00
|
|
|
#endif
|
2010-09-12 12:06:10 +00:00
|
|
|
|
2010-09-14 21:17:08 +00:00
|
|
|
delete nameDialog;
|
2010-09-12 12:06:10 +00:00
|
|
|
delete raceDialog;
|
2010-07-17 12:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WindowManager::updateVisible()
|
|
|
|
{
|
|
|
|
// Start out by hiding everything except the HUD
|
|
|
|
map->setVisible(false);
|
|
|
|
menu->setVisible(false);
|
|
|
|
stats->setVisible(false);
|
2010-09-15 11:15:58 +00:00
|
|
|
#if 0
|
2010-09-10 01:29:29 +00:00
|
|
|
inventory->setVisible(false);
|
2010-09-15 11:15:58 +00:00
|
|
|
#endif
|
2010-07-20 19:10:51 +00:00
|
|
|
console->disable();
|
2010-07-17 12:01:47 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2010-09-14 21:17:08 +00:00
|
|
|
if (mode == GM_Name)
|
|
|
|
{
|
|
|
|
if (!nameDialog)
|
2010-09-15 17:37:06 +00:00
|
|
|
nameDialog = new TextInputDialog(environment, gui->getViewSize());
|
|
|
|
|
|
|
|
std::string sName = getGameSettingString("sName", "Name");
|
|
|
|
nameDialog->setTextLabel(sName);
|
|
|
|
nameDialog->setNextButtonShow(nameChosen);
|
2010-09-14 21:17:08 +00:00
|
|
|
nameDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onNameDialogDone);
|
2010-09-15 17:48:37 +00:00
|
|
|
nameDialog->open();
|
2010-09-14 21:17:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-14 19:27:40 +00:00
|
|
|
if (mode == GM_Race)
|
|
|
|
{
|
|
|
|
if (!raceDialog)
|
2010-09-15 19:48:10 +00:00
|
|
|
raceDialog = new RaceDialog(environment, gui->getViewSize());
|
2010-09-15 17:44:53 +00:00
|
|
|
raceDialog->setNextButtonShow(raceChosen);
|
2010-09-14 19:27:40 +00:00
|
|
|
raceDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onRaceDialogDone);
|
|
|
|
raceDialog->eventBack = MyGUI::newDelegate(this, &WindowManager::onRaceDialogBack);
|
2010-09-15 19:36:32 +00:00
|
|
|
raceDialog->open();
|
2010-09-14 19:27:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-17 12:01:47 +00:00
|
|
|
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 );
|
2010-09-15 11:15:58 +00:00
|
|
|
#if 0
|
2010-09-12 12:06:10 +00:00
|
|
|
// inventory -> setVisible( eff & GW_Inventory );
|
2010-09-15 11:15:58 +00:00
|
|
|
#endif
|
2010-09-14 19:55:41 +00:00
|
|
|
return;
|
2010-07-17 12:01:47 +00:00
|
|
|
}
|
|
|
|
|
2010-09-15 12:48:19 +00:00
|
|
|
// 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);
|
2010-07-17 12:01:47 +00:00
|
|
|
}
|
2010-07-26 09:15:38 +00:00
|
|
|
|
2010-07-27 13:59:41 +00:00
|
|
|
void WindowManager::setValue (const std::string& id, const MWMechanics::Stat<int>& value)
|
|
|
|
{
|
|
|
|
stats->setValue (id, value);
|
|
|
|
}
|
|
|
|
|
2010-09-18 16:04:53 +00:00
|
|
|
void WindowManager::setValue (const std::string& id, const MWMechanics::Stat<float>& value)
|
|
|
|
{
|
|
|
|
stats->setValue (id, value);
|
|
|
|
}
|
|
|
|
|
2010-07-28 16:48:01 +00:00
|
|
|
void WindowManager::setValue (const std::string& id, const MWMechanics::DynamicStat<int>& value)
|
|
|
|
{
|
|
|
|
stats->setValue (id, value);
|
|
|
|
hud->setValue (id, value);
|
|
|
|
}
|
2010-08-22 09:22:10 +00:00
|
|
|
|
2010-09-15 10:22:06 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2010-09-17 23:30:23 +00:00
|
|
|
void WindowManager::configureSkills (const std::set<int>& major, const std::set<int>& minor, const std::set<int>& misc)
|
|
|
|
{
|
|
|
|
stats->configureSkills (major, minor, misc);
|
|
|
|
}
|
|
|
|
|
2010-09-18 00:24:42 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2010-08-22 09:22:10 +00:00
|
|
|
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-08-22 09:22:10 +00:00
|
|
|
}
|
2010-09-14 17:33:40 +00:00
|
|
|
|
2010-09-15 20:22:27 +00:00
|
|
|
const std::string &WindowManager::getGameSettingString(const std::string &id, const std::string &default_)
|
2010-09-15 10:41:53 +00:00
|
|
|
{
|
|
|
|
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_;
|
2010-09-15 10:41:53 +00:00
|
|
|
}
|
|
|
|
|
2010-09-14 19:27:40 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-14 21:17:08 +00:00
|
|
|
void WindowManager::onNameDialogDone()
|
|
|
|
{
|
2010-09-15 17:44:53 +00:00
|
|
|
nameDialog->eventDone = MWGui::TextInputDialog::EventHandle_Void();
|
|
|
|
|
2010-09-15 10:44:43 +00:00
|
|
|
bool goNext = nameChosen; // Go to next dialog if name was previously chosen
|
2010-09-14 21:17:08 +00:00
|
|
|
nameChosen = true;
|
|
|
|
if (nameDialog)
|
|
|
|
{
|
|
|
|
nameDialog->setVisible(false);
|
|
|
|
environment.mMechanicsManager->setPlayerName(nameDialog->getTextInput());
|
|
|
|
}
|
|
|
|
|
|
|
|
updateCharacterGeneration();
|
|
|
|
|
|
|
|
if (reviewNext)
|
2010-09-15 12:48:19 +00:00
|
|
|
environment.mInputManager->setGuiMode(GM_Review);
|
2010-09-15 10:44:43 +00:00
|
|
|
else if (goNext)
|
2010-09-15 12:48:19 +00:00
|
|
|
environment.mInputManager->setGuiMode(GM_Race);
|
2010-09-15 11:10:47 +00:00
|
|
|
else
|
2010-09-15 12:48:19 +00:00
|
|
|
environment.mInputManager->setGuiMode(GM_Game);
|
2010-09-14 21:17:08 +00:00
|
|
|
}
|
|
|
|
|
2010-09-14 17:33:40 +00:00
|
|
|
void WindowManager::onRaceDialogDone()
|
|
|
|
{
|
2010-09-15 17:44:53 +00:00
|
|
|
raceDialog->eventDone = MWGui::RaceDialog::EventHandle_Void();
|
|
|
|
|
|
|
|
bool goNext = raceChosen; // Go to next dialog if race was previously chosen
|
2010-09-14 19:27:40 +00:00
|
|
|
raceChosen = true;
|
|
|
|
if (raceDialog)
|
|
|
|
{
|
|
|
|
raceDialog->setVisible(false);
|
2010-09-15 11:04:57 +00:00
|
|
|
environment.mMechanicsManager->setPlayerRace(raceDialog->getRaceId(), raceDialog->getGender() == RaceDialog::GM_Male);
|
2010-09-14 19:27:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateCharacterGeneration();
|
|
|
|
|
|
|
|
if (reviewNext)
|
2010-09-15 12:48:19 +00:00
|
|
|
environment.mInputManager->setGuiMode(GM_Review);
|
2010-09-15 10:44:43 +00:00
|
|
|
else if (goNext)
|
2010-09-15 12:48:19 +00:00
|
|
|
environment.mInputManager->setGuiMode(GM_Class);
|
2010-09-15 11:10:47 +00:00
|
|
|
else
|
2010-09-15 12:48:19 +00:00
|
|
|
environment.mInputManager->setGuiMode(GM_Game);
|
2010-09-14 17:33:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WindowManager::onRaceDialogBack()
|
|
|
|
{
|
2010-09-14 19:27:40 +00:00
|
|
|
if (raceDialog)
|
|
|
|
{
|
|
|
|
raceDialog->setVisible(false);
|
2010-09-15 11:04:57 +00:00
|
|
|
environment.mMechanicsManager->setPlayerRace(raceDialog->getRaceId(), raceDialog->getGender() == RaceDialog::GM_Male);
|
2010-09-14 19:27:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateCharacterGeneration();
|
|
|
|
|
2010-09-15 12:48:19 +00:00
|
|
|
environment.mInputManager->setGuiMode(GM_Name);
|
2010-09-14 17:33:40 +00:00
|
|
|
}
|