2010-07-17 12:01:47 +00:00
|
|
|
#include "window_manager.hpp"
|
|
|
|
#include "mw_layouts.hpp"
|
|
|
|
|
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)
|
|
|
|
: 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-08-01 08:25:50 +00:00
|
|
|
stats = new StatsWindow (environment.mWorld->getStore());
|
2010-09-10 01:29:29 +00:00
|
|
|
inventory = new InventoryWindow ();
|
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-10 01:29:29 +00:00
|
|
|
delete inventory;
|
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-10 01:29:29 +00:00
|
|
|
inventory->setVisible(false);
|
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-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
|
|
|
|
map -> setVisible( eff & GW_Map );
|
|
|
|
stats -> setVisible( eff & GW_Stats );
|
2010-09-10 01:29:29 +00:00
|
|
|
inventory -> setVisible( eff & GW_Inventory );
|
2010-07-17 12:01:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// All other modes are ignored
|
|
|
|
}
|
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-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
|
|
|
|
|
|
|
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
|
|
|
}
|