1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 04:49:54 +00:00
openmw-tes3mp/apps/openmw/mwgui/windowmanagerimp.cpp

1096 lines
31 KiB
C++
Raw Normal View History

#include "windowmanagerimp.hpp"
2012-08-12 12:07:48 +00:00
#include <cassert>
#include <iterator>
#include "MyGUI_UString.h"
#include <openengine/ogre/renderer.hpp>
#include <openengine/gui/manager.hpp>
#include <components/settings/settings.hpp>
#include <components/translation/translation.hpp>
2012-08-12 12:07:48 +00:00
#include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/inputmanager.hpp"
#include "../mwworld/ptr.hpp"
#include "../mwworld/cellstore.hpp"
#include "console.hpp"
#include "journalwindow.hpp"
#include "charactercreation.hpp"
#include "text_input.hpp"
#include "review.hpp"
2010-11-03 20:21:08 +00:00
#include "dialogue.hpp"
#include "dialogue_history.hpp"
#include "map_window.hpp"
#include "stats_window.hpp"
2011-06-14 16:29:55 +00:00
#include "messagebox.hpp"
2012-04-15 15:52:39 +00:00
#include "container.hpp"
2012-04-21 08:51:01 +00:00
#include "inventorywindow.hpp"
2012-04-14 15:47:44 +00:00
#include "tooltips.hpp"
2012-05-03 01:33:33 +00:00
#include "scrollwindow.hpp"
#include "bookwindow.hpp"
#include "list.hpp"
#include "hud.hpp"
#include "mainmenu.hpp"
#include "countdialog.hpp"
2012-05-17 15:15:44 +00:00
#include "tradewindow.hpp"
#include "spellbuyingwindow.hpp"
2012-09-26 16:30:47 +00:00
#include "travelwindow.hpp"
#include "settingswindow.hpp"
2012-05-23 03:28:25 +00:00
#include "confirmationdialog.hpp"
#include "alchemywindow.hpp"
#include "spellwindow.hpp"
#include "quickkeysmenu.hpp"
2012-09-11 14:37:54 +00:00
#include "loadingscreen.hpp"
2012-09-14 17:44:00 +00:00
#include "levelupdialog.hpp"
2012-09-18 16:29:03 +00:00
#include "waitdialog.hpp"
2012-09-22 22:36:20 +00:00
#include "spellcreationdialog.hpp"
#include "enchantingdialog.hpp"
2012-10-17 16:03:02 +00:00
#include "trainingwindow.hpp"
#include "imagebutton.hpp"
using namespace MWGui;
WindowManager::WindowManager(
2013-02-05 19:48:25 +00:00
const Compiler::Extensions& extensions, int fpsLevel, bool newGame, OEngine::Render::OgreRenderer *ogre,
2012-12-23 19:23:24 +00:00
const std::string& logpath, const std::string& cacheDir, bool consoleOnlyScripts,
Translation::Storage& translationDataStorage)
: mGuiManager(NULL)
2013-02-05 19:48:25 +00:00
, mRendering(ogre)
, mHud(NULL)
, mMap(NULL)
, mMenu(NULL)
, mStatsWindow(NULL)
2012-04-14 15:47:44 +00:00
, mToolTips(NULL)
, mMessageBoxManager(NULL)
, mConsole(NULL)
, mJournal(NULL)
, mDialogueWindow(NULL)
2012-05-03 01:33:33 +00:00
, mBookWindow(NULL)
, mScrollWindow(NULL)
, mCountDialog(NULL)
2012-05-17 15:15:44 +00:00
, mTradeWindow(NULL)
, mSpellBuyingWindow(NULL)
2012-09-26 16:30:47 +00:00
, mTravelWindow(NULL)
, mSettingsWindow(NULL)
2012-05-23 03:28:25 +00:00
, mConfirmationDialog(NULL)
, mAlchemyWindow(NULL)
, mSpellWindow(NULL)
2012-09-11 14:37:54 +00:00
, mLoadingScreen(NULL)
, mCharGen(NULL)
2012-09-18 16:29:03 +00:00
, mLevelupDialog(NULL)
, mWaitDialog(NULL)
2012-09-22 22:36:20 +00:00
, mSpellCreationDialog(NULL)
, mEnchantingDialog(NULL)
2012-10-17 16:03:02 +00:00
, mTrainingWindow(NULL)
, mPlayerName()
, mPlayerRaceId()
, mPlayerAttributes()
, mPlayerMajorSkills()
, mPlayerMinorSkills()
, mPlayerSkillValues()
, mPlayerHealth()
, mPlayerMagicka()
, mPlayerFatigue()
, mGui(NULL)
, mGarbageDialogs()
, mShown(GW_ALL)
, mAllowed(newGame ? GW_None : GW_ALL)
, mRestAllowed(newGame ? false : true)
, mShowFPSLevel(fpsLevel)
, mFPS(0.0f)
, mTriangleCount(0)
, mBatchCount(0)
, mCrosshairEnabled(Settings::Manager::getBool ("crosshair", "HUD"))
, mSubtitlesEnabled(Settings::Manager::getBool ("subtitles", "GUI"))
, mHudEnabled(true)
, mTranslationDataStorage (translationDataStorage)
{
// Set up the GUI system
2013-02-05 19:48:25 +00:00
mGuiManager = new OEngine::GUI::MyGUIManager(mRendering->getWindow(), mRendering->getScene(), false, logpath);
mGui = mGuiManager->getGui();
2010-11-03 20:21:08 +00:00
//Register own widgets with MyGUI
2012-03-22 14:10:29 +00:00
MyGUI::FactoryManager::getInstance().registerFactory<DialogueHistory>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSkill>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWAttribute>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSpell>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWEffectList>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSpellEffect>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWDynamicStat>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWList>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::HBox>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::VBox>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::AutoSizedTextBox>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::AutoSizedButton>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::ImageButton>("Widget");
2010-11-03 20:21:08 +00:00
MyGUI::LanguageManager::getInstance().eventRequestTag = MyGUI::newDelegate(this, &WindowManager::onRetrieveTag);
2011-01-01 21:53:34 +00:00
// Get size info from the Gui object
assert(mGui);
2012-03-21 12:32:32 +00:00
int w = MyGUI::RenderManager::getInstance().getViewSize().width;
int h = MyGUI::RenderManager::getInstance().getViewSize().height;
2011-01-01 21:53:34 +00:00
MyGUI::Widget* dragAndDropWidget = mGui->createWidgetT("Widget","",0,0,w,h,MyGUI::Align::Default,"DragAndDrop","DragAndDropWidget");
dragAndDropWidget->setVisible(false);
2012-05-18 15:58:33 +00:00
mDragAndDrop = new DragAndDrop();
2012-04-30 11:01:18 +00:00
mDragAndDrop->mIsOnDragAndDrop = false;
mDragAndDrop->mDraggedWidget = 0;
mDragAndDrop->mDragAndDropWidget = dragAndDropWidget;
mMenu = new MainMenu(w,h);
mMap = new MapWindow(*this, cacheDir);
mStatsWindow = new StatsWindow(*this);
mConsole = new Console(w,h, consoleOnlyScripts);
mJournal = new JournalWindow(*this);
2011-06-19 17:41:42 +00:00
mMessageBoxManager = new MessageBoxManager(this);
mInventoryWindow = new InventoryWindow(*this,mDragAndDrop);
mTradeWindow = new TradeWindow(*this);
mSpellBuyingWindow = new SpellBuyingWindow(*this);
2012-09-26 16:30:47 +00:00
mTravelWindow = new TravelWindow(*this);
2012-05-11 09:52:07 +00:00
mDialogueWindow = new DialogueWindow(*this);
mContainerWindow = new ContainerWindow(*this,mDragAndDrop);
mHud = new HUD(w,h, mShowFPSLevel, mDragAndDrop);
2012-04-15 19:14:14 +00:00
mToolTips = new ToolTips(this);
2012-05-03 01:33:33 +00:00
mScrollWindow = new ScrollWindow(*this);
mBookWindow = new BookWindow(*this);
mCountDialog = new CountDialog(*this);
mSettingsWindow = new SettingsWindow(*this);
2012-05-23 03:28:25 +00:00
mConfirmationDialog = new ConfirmationDialog(*this);
mAlchemyWindow = new AlchemyWindow(*this);
mSpellWindow = new SpellWindow(*this);
mQuickKeysMenu = new QuickKeysMenu(*this);
2012-09-14 17:44:00 +00:00
mLevelupDialog = new LevelupDialog(*this);
2012-09-18 16:29:03 +00:00
mWaitDialog = new WaitDialog(*this);
2012-09-22 22:36:20 +00:00
mSpellCreationDialog = new SpellCreationDialog(*this);
mEnchantingDialog = new EnchantingDialog(*this);
2012-10-17 16:03:02 +00:00
mTrainingWindow = new TrainingWindow(*this);
2013-02-05 19:48:25 +00:00
mLoadingScreen = new LoadingScreen(mRendering->getScene (), mRendering->getWindow (), *this);
2012-09-11 17:18:26 +00:00
mLoadingScreen->onResChange (w,h);
2012-09-11 14:37:54 +00:00
2012-08-12 23:26:15 +00:00
mInputBlocker = mGui->createWidget<MyGUI::Widget>("",0,0,w,h,MyGUI::Align::Default,"Windows","");
2013-01-12 05:36:48 +00:00
mHud->setVisible(mHudEnabled);
mCharGen = new CharacterCreation(this);
2011-01-01 21:53:34 +00:00
// Setup player stats
for (int i = 0; i < ESM::Attribute::Length; ++i)
{
2012-09-17 07:37:50 +00:00
mPlayerAttributes.insert(std::make_pair(ESM::Attribute::sAttributeIds[i], MWMechanics::Stat<int>()));
2011-01-01 21:53:34 +00:00
}
2011-01-01 21:53:34 +00:00
for (int i = 0; i < ESM::Skill::Length; ++i)
{
2012-09-17 07:37:50 +00:00
mPlayerSkillValues.insert(std::make_pair(ESM::Skill::sSkillIds[i], MWMechanics::Stat<float>()));
2011-01-01 21:53:34 +00:00
}
unsetSelectedSpell();
unsetSelectedWeapon();
if (newGame)
disallowAll ();
2011-01-01 21:53:34 +00:00
// Set up visibility
updateVisible();
}
WindowManager::~WindowManager()
{
delete mConsole;
2011-06-14 16:29:55 +00:00
delete mMessageBoxManager;
delete mHud;
delete mMap;
delete mMenu;
delete mStatsWindow;
delete mJournal;
2012-04-30 11:01:18 +00:00
delete mDialogueWindow;
delete mContainerWindow;
2012-04-21 08:51:01 +00:00
delete mInventoryWindow;
2012-04-14 15:47:44 +00:00
delete mToolTips;
delete mCharGen;
2012-04-30 11:01:18 +00:00
delete mDragAndDrop;
2012-05-16 12:28:57 +00:00
delete mBookWindow;
delete mScrollWindow;
2012-05-17 15:15:44 +00:00
delete mTradeWindow;
delete mSpellBuyingWindow;
2012-09-26 16:30:47 +00:00
delete mTravelWindow;
2012-05-23 03:28:25 +00:00
delete mSettingsWindow;
delete mConfirmationDialog;
delete mAlchemyWindow;
delete mSpellWindow;
2012-09-11 18:34:54 +00:00
delete mLoadingScreen;
2012-09-14 17:44:00 +00:00
delete mLevelupDialog;
2012-09-18 16:29:03 +00:00
delete mWaitDialog;
2012-09-22 22:36:20 +00:00
delete mSpellCreationDialog;
delete mEnchantingDialog;
2012-10-17 16:03:02 +00:00
delete mTrainingWindow;
2012-12-15 23:47:29 +00:00
delete mCountDialog;
delete mQuickKeysMenu;
2011-01-01 21:53:34 +00:00
cleanupGarbage();
2012-08-12 19:21:23 +00:00
delete mGuiManager;
}
void WindowManager::cleanupGarbage()
{
// Delete any dialogs which are no longer in use
if (!mGarbageDialogs.empty())
{
for (std::vector<OEngine::GUI::Layout*>::iterator it = mGarbageDialogs.begin(); it != mGarbageDialogs.end(); ++it)
{
delete *it;
}
mGarbageDialogs.clear();
}
}
void WindowManager::update()
{
cleanupGarbage();
2012-05-29 10:35:03 +00:00
mHud->setFPS(mFPS);
mHud->setTriangleCount(mTriangleCount);
mHud->setBatchCount(mBatchCount);
}
void WindowManager::updateVisible()
{
2011-01-01 21:53:34 +00:00
// Start out by hiding everything except the HUD
mMap->setVisible(false);
mMenu->setVisible(false);
mStatsWindow->setVisible(false);
mConsole->disable();
mJournal->setVisible(false);
2012-04-30 11:01:18 +00:00
mDialogueWindow->setVisible(false);
mContainerWindow->setVisible(false);
2012-04-21 08:51:01 +00:00
mInventoryWindow->setVisible(false);
mScrollWindow->setVisible(false);
mBookWindow->setVisible(false);
2012-05-17 19:15:48 +00:00
mTradeWindow->setVisible(false);
mSpellBuyingWindow->setVisible(false);
2012-09-26 16:30:47 +00:00
mTravelWindow->setVisible(false);
mSettingsWindow->setVisible(false);
mAlchemyWindow->setVisible(false);
mSpellWindow->setVisible(false);
mQuickKeysMenu->setVisible(false);
2012-09-15 15:12:42 +00:00
mLevelupDialog->setVisible(false);
2012-09-18 16:29:03 +00:00
mWaitDialog->setVisible(false);
2012-09-22 22:36:20 +00:00
mSpellCreationDialog->setVisible(false);
mEnchantingDialog->setVisible(false);
2012-10-17 16:03:02 +00:00
mTrainingWindow->setVisible(false);
2012-09-12 17:15:29 +00:00
mHud->setVisible(true);
2011-01-01 21:53:34 +00:00
// Mouse is visible whenever we're not in game mode
2012-03-21 12:32:32 +00:00
MyGUI::PointerManager::getInstance().setVisible(isGuiMode());
2012-05-23 10:23:35 +00:00
bool gameMode = !isGuiMode();
2012-08-12 23:26:15 +00:00
mInputBlocker->setVisible (gameMode);
2012-05-23 10:23:35 +00:00
if (gameMode)
2012-04-14 15:47:44 +00:00
mToolTips->enterGameMode();
else
mToolTips->enterGuiMode();
2012-08-12 23:26:15 +00:00
if (gameMode)
MyGUI::InputManager::getInstance ().setKeyFocusWidget (NULL);
setMinimapVisibility((mAllowed & GW_Map) && !mMap->pinned());
setWeaponVisibility((mAllowed & GW_Inventory) && !mInventoryWindow->pinned());
setSpellVisibility((mAllowed & GW_Magic) && !mSpellWindow->pinned());
setHMSVisibility((mAllowed & GW_Stats) && !mStatsWindow->pinned());
2012-05-23 10:23:35 +00:00
// If in game mode, don't show anything.
if (gameMode)
return;
GuiMode mode = mGuiModes.back();
2012-03-31 17:50:21 +00:00
switch(mode) {
case GM_QuickKeysMenu:
mQuickKeysMenu->setVisible (true);
break;
2012-03-31 17:50:21 +00:00
case GM_MainMenu:
mMenu->setVisible(true);
2012-03-31 17:50:21 +00:00
break;
case GM_Settings:
mSettingsWindow->setVisible(true);
break;
2012-03-31 17:50:21 +00:00
case GM_Console:
mConsole->enable();
2012-03-31 17:50:21 +00:00
break;
case GM_Scroll:
mScrollWindow->setVisible(true);
break;
case GM_Book:
mBookWindow->setVisible(true);
break;
case GM_Alchemy:
mAlchemyWindow->setVisible(true);
break;
2012-09-15 15:12:42 +00:00
case GM_Rest:
2012-09-18 16:29:03 +00:00
mWaitDialog->setVisible(true);
2012-09-15 15:12:42 +00:00
break;
case GM_RestBed:
mWaitDialog->setVisible(true);
mWaitDialog->bedActivated();
break;
case GM_Levelup:
2012-09-15 15:12:42 +00:00
mLevelupDialog->setVisible(true);
break;
2012-03-31 17:50:21 +00:00
case GM_Name:
case GM_Race:
case GM_Class:
case GM_ClassPick:
case GM_ClassCreate:
case GM_Birth:
case GM_ClassGenerate:
case GM_Review:
mCharGen->spawnDialog(mode);
break;
case GM_Inventory:
2012-03-31 19:29:46 +00:00
{
2012-03-31 17:50:21 +00:00
// 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 = mShown & mAllowed;
2012-03-31 17:50:21 +00:00
// Show the windows we want
mMap ->setVisible(eff & GW_Map);
mStatsWindow ->setVisible(eff & GW_Stats);
mInventoryWindow->setVisible(eff & GW_Inventory);
mSpellWindow ->setVisible(eff & GW_Magic);
2012-03-31 17:50:21 +00:00
break;
2011-06-19 17:10:44 +00:00
}
case GM_Container:
2012-04-30 11:01:18 +00:00
mContainerWindow->setVisible(true);
2012-04-21 08:51:01 +00:00
mInventoryWindow->setVisible(true);
break;
2012-03-31 17:50:21 +00:00
case GM_Dialogue:
2012-05-23 10:23:35 +00:00
mDialogueWindow->setVisible(true);
2012-03-31 17:50:21 +00:00
break;
2012-05-17 19:15:48 +00:00
case GM_Barter:
mInventoryWindow->setVisible(true);
mTradeWindow->setVisible(true);
break;
case GM_SpellBuying:
mSpellBuyingWindow->setVisible(true);
2012-09-08 22:17:03 +00:00
break;
2012-09-26 16:30:47 +00:00
case GM_Travel:
mTravelWindow->setVisible(true);
2012-10-06 15:52:46 +00:00
break;
2012-09-22 22:36:20 +00:00
case GM_SpellCreation:
mSpellCreationDialog->setVisible(true);
break;
case GM_Enchanting:
mEnchantingDialog->setVisible(true);
break;
2012-10-17 16:03:02 +00:00
case GM_Training:
mTrainingWindow->setVisible(true);
break;
2012-03-31 17:50:21 +00:00
case GM_InterMessageBox:
break;
case GM_Journal:
mJournal->setVisible(true);
break;
2012-09-12 17:15:29 +00:00
case GM_LoadingWallpaper:
mHud->setVisible(false);
MyGUI::PointerManager::getInstance().setVisible(false);
break;
case GM_Loading:
MyGUI::PointerManager::getInstance().setVisible(false);
break;
2012-09-25 00:35:50 +00:00
case GM_Video:
2012-09-25 00:54:29 +00:00
MyGUI::PointerManager::getInstance().setVisible(false);
2012-09-25 00:35:50 +00:00
mHud->setVisible(false);
break;
2012-03-31 17:50:21 +00:00
default:
// Unsupported mode, switch back to game
break;
}
}
void WindowManager::setValue (const std::string& id, const MWMechanics::Stat<int>& value)
{
mStatsWindow->setValue (id, value);
mCharGen->setValue(id, value);
static const char *ids[] =
{
"AttribVal1", "AttribVal2", "AttribVal3", "AttribVal4", "AttribVal5",
"AttribVal6", "AttribVal7", "AttribVal8"
};
static ESM::Attribute::AttributeID attributes[] =
{
ESM::Attribute::Strength,
ESM::Attribute::Intelligence,
ESM::Attribute::Willpower,
ESM::Attribute::Agility,
ESM::Attribute::Speed,
ESM::Attribute::Endurance,
ESM::Attribute::Personality,
ESM::Attribute::Luck
};
2010-11-01 17:56:09 +00:00
for (size_t i = 0; i < sizeof(ids)/sizeof(ids[0]); ++i)
{
if (id != ids[i])
continue;
mPlayerAttributes[attributes[i]] = value;
break;
}
}
void WindowManager::setValue (int parSkill, const MWMechanics::Stat<float>& value)
{
/// \todo Don't use the skill enum as a parameter type (we will have to drop it anyway, once we
/// allow custom skills.
mStatsWindow->setValue(static_cast<ESM::Skill::SkillEnum> (parSkill), value);
mCharGen->setValue(static_cast<ESM::Skill::SkillEnum> (parSkill), value);
mPlayerSkillValues[parSkill] = value;
}
2012-09-15 15:12:42 +00:00
void WindowManager::setValue (const std::string& id, const MWMechanics::DynamicStat<float>& value)
{
mStatsWindow->setValue (id, value);
mHud->setValue (id, value);
mCharGen->setValue(id, value);
if (id == "HBar")
{
mPlayerHealth = value;
mCharGen->setPlayerHealth (value);
}
else if (id == "MBar")
{
mPlayerMagicka = value;
mCharGen->setPlayerMagicka (value);
}
else if (id == "FBar")
{
mPlayerFatigue = value;
mCharGen->setPlayerFatigue (value);
}
}
#if 0
MWMechanics::DynamicStat<int> WindowManager::getValue(const std::string& id)
{
if(id == "HBar")
return layerHealth;
else if (id == "MBar")
return mPlayerMagicka;
else if (id == "FBar")
return mPlayerFatigue;
}
#endif
void WindowManager::setValue (const std::string& id, const std::string& value)
{
mStatsWindow->setValue (id, value);
if (id=="name")
mPlayerName = value;
else if (id=="race")
mPlayerRaceId = value;
}
2010-09-15 13:32:35 +00:00
void WindowManager::setValue (const std::string& id, int value)
{
mStatsWindow->setValue (id, value);
2010-09-15 13:32:35 +00:00
}
void WindowManager::setPlayerClass (const ESM::Class &class_)
{
mStatsWindow->setValue("class", class_.mName);
}
void WindowManager::configureSkills (const SkillList& major, const SkillList& minor)
{
mStatsWindow->configureSkills (major, minor);
mCharGen->configureSkills(major, minor);
mPlayerMajorSkills = major;
mPlayerMinorSkills = minor;
}
void WindowManager::setReputation (int reputation)
{
mStatsWindow->setReputation (reputation);
}
void WindowManager::setBounty (int bounty)
{
mStatsWindow->setBounty (bounty);
}
void WindowManager::updateSkillArea()
{
mStatsWindow->updateSkillArea();
}
void WindowManager::removeDialog(OEngine::GUI::Layout*dialog)
{
if (!dialog)
return;
dialog->setVisible(false);
mGarbageDialogs.push_back(dialog);
}
void WindowManager::messageBox (const std::string& message, const std::vector<std::string>& buttons)
{
2012-12-26 23:52:16 +00:00
if(buttons.empty()){
/* If there are no buttons, and there is a dialogue window open, messagebox goes to the dialogue window */
if(!mGuiModes.empty() && mGuiModes.back() == GM_Dialogue)
2012-12-26 23:52:16 +00:00
mDialogueWindow->addMessageBox(MyGUI::LanguageManager::getInstance().replaceTags(message));
else
2012-12-26 23:52:16 +00:00
mMessageBoxManager->createMessageBox(message);
2011-06-14 16:29:55 +00:00
}
2012-12-26 23:52:16 +00:00
2011-06-14 16:29:55 +00:00
else
{
mMessageBoxManager->createInteractiveMessageBox(message, buttons);
2012-05-23 10:23:35 +00:00
pushGuiMode(GM_InterMessageBox);
2010-08-22 10:56:35 +00:00
}
}
void WindowManager::enterPressed ()
{
mMessageBoxManager->enterPressed();
}
int WindowManager::readPressedButton ()
{
return mMessageBoxManager->readPressedButton();
}
2012-10-01 08:03:49 +00:00
std::string WindowManager::getGameSettingString(const std::string &id, const std::string &default_)
{
const ESM::GameSetting *setting =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().search(id);
2012-09-17 07:37:50 +00:00
if (setting && setting->mType == ESM::VT_String)
2012-09-30 20:23:49 +00:00
return setting->getString();
2010-09-15 20:22:27 +00:00
return default_;
}
2010-11-03 20:21:08 +00:00
void WindowManager::onDialogueWindowBye()
{
2012-04-30 11:01:18 +00:00
if (mDialogueWindow)
2010-11-03 20:21:08 +00:00
{
//FIXME set some state and stuff?
//removeDialog(dialogueWindow);
2012-04-30 11:01:18 +00:00
mDialogueWindow->setVisible(false);
2010-11-03 20:21:08 +00:00
}
removeGuiMode(GM_Dialogue);
2010-11-03 20:21:08 +00:00
}
void WindowManager::onFrame (float frameDuration)
{
mMessageBoxManager->onFrame(frameDuration);
2012-04-14 15:47:44 +00:00
mToolTips->onFrame(frameDuration);
2012-05-18 15:58:33 +00:00
if (mDragAndDrop->mIsOnDragAndDrop)
{
assert(mDragAndDrop->mDraggedWidget);
mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition());
}
2012-11-05 22:16:37 +00:00
mDialogueWindow->onFrame();
mInventoryWindow->onFrame();
mStatsWindow->onFrame();
mWaitDialog->onFrame(frameDuration);
mHud->onFrame(frameDuration);
2012-10-17 16:03:02 +00:00
mTrainingWindow->onFrame (frameDuration);
mTradeWindow->onFrame(frameDuration);
2012-10-17 16:03:02 +00:00
mTrainingWindow->checkReferenceAvailable();
mDialogueWindow->checkReferenceAvailable();
mTradeWindow->checkReferenceAvailable();
mSpellBuyingWindow->checkReferenceAvailable();
2012-09-22 22:36:20 +00:00
mSpellCreationDialog->checkReferenceAvailable();
2012-10-03 13:06:54 +00:00
mEnchantingDialog->checkReferenceAvailable();
mContainerWindow->checkReferenceAvailable();
mConsole->checkReferenceAvailable();
}
2012-03-16 16:09:31 +00:00
void WindowManager::changeCell(MWWorld::Ptr::CellStore* cell)
2012-03-10 15:05:12 +00:00
{
2012-11-05 12:07:59 +00:00
if (cell->mCell->isExterior())
2012-03-16 16:09:31 +00:00
{
2012-03-23 15:51:56 +00:00
std::string name;
2012-11-05 12:07:59 +00:00
if (cell->mCell->mName != "")
2012-09-20 15:30:09 +00:00
{
2012-11-05 12:07:59 +00:00
name = cell->mCell->mName;
2012-12-23 19:23:24 +00:00
mMap->addVisitedLocation ("#{sCell=" + name + "}", cell->mCell->getGridX (), cell->mCell->getGridY ());
2012-09-20 15:30:09 +00:00
}
2012-03-16 16:09:31 +00:00
else
{
const ESM::Region* region =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Region>().search(cell->mCell->mRegion);
2012-05-17 16:14:33 +00:00
if (region)
2012-09-17 07:37:50 +00:00
name = region->mName;
else
name = getGameSettingString("sDefaultCellname", "Wilderness");
}
2012-03-23 15:51:56 +00:00
2012-11-16 18:34:09 +00:00
mMap->cellExplored(cell->mCell->getGridX(), cell->mCell->getGridY());
2012-11-04 11:13:04 +00:00
mMap->setCellName( name );
mHud->setCellName( name );
2012-03-23 15:51:56 +00:00
mMap->setCellPrefix("Cell");
mHud->setCellPrefix("Cell");
2012-11-05 12:07:59 +00:00
mMap->setActiveCell( cell->mCell->getGridX(), cell->mCell->getGridY() );
mHud->setActiveCell( cell->mCell->getGridX(), cell->mCell->getGridY() );
2012-03-16 16:09:31 +00:00
}
else
{
2012-11-05 12:07:59 +00:00
mMap->setCellName( cell->mCell->mName );
mHud->setCellName( cell->mCell->mName );
mMap->setCellPrefix( cell->mCell->mName );
mHud->setCellPrefix( cell->mCell->mName );
2012-03-16 16:09:31 +00:00
}
2012-03-10 15:05:12 +00:00
}
2012-03-17 12:59:51 +00:00
void WindowManager::setInteriorMapTexture(const int x, const int y)
{
mMap->setActiveCell(x,y, true);
mHud->setActiveCell(x,y, true);
2012-03-17 12:59:51 +00:00
}
void WindowManager::setPlayerPos(const float x, const float y)
{
mMap->setPlayerPos(x,y);
mHud->setPlayerPos(x,y);
}
2012-03-23 14:00:48 +00:00
void WindowManager::setPlayerDir(const float x, const float y)
{
mMap->setPlayerDir(x,y);
mHud->setPlayerDir(x,y);
2012-03-23 14:00:48 +00:00
}
void WindowManager::setHMSVisibility(bool visible)
{
2012-08-27 17:18:55 +00:00
mHud->setHmsVisible (visible);
}
void WindowManager::setMinimapVisibility(bool visible)
{
2012-08-27 17:18:55 +00:00
mHud->setMinimapVisible (visible);
}
2012-03-29 17:45:19 +00:00
void WindowManager::toggleFogOfWar()
{
mMap->toggleFogOfWar();
mHud->toggleFogOfWar();
2012-03-29 17:45:19 +00:00
}
2012-04-13 11:17:50 +00:00
void WindowManager::setFocusObject(const MWWorld::Ptr& focus)
{
mToolTips->setFocusObject(focus);
}
2012-04-16 13:00:44 +00:00
void WindowManager::setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y)
{
mToolTips->setFocusObjectScreenCoords(min_x, min_y, max_x, max_y);
}
2012-04-16 13:00:44 +00:00
void WindowManager::toggleFullHelp()
{
mToolTips->toggleFullHelp();
}
bool WindowManager::getFullHelp() const
{
return mToolTips->getFullHelp();
}
2012-05-12 20:44:12 +00:00
void WindowManager::setWeaponVisibility(bool visible)
{
2012-08-27 17:18:55 +00:00
mHud->setWeapVisible (visible);
2012-05-12 20:44:12 +00:00
}
void WindowManager::setSpellVisibility(bool visible)
{
2012-08-27 17:18:55 +00:00
mHud->setSpellVisible (visible);
mHud->setEffectVisible (visible);
2012-05-12 20:44:12 +00:00
}
void WindowManager::setMouseVisible(bool visible)
{
MyGUI::PointerManager::getInstance().setVisible(visible);
}
void WindowManager::setDragDrop(bool dragDrop)
{
mToolTips->setEnabled(!dragDrop);
MWBase::Environment::get().getInputManager()->setDragDrop(dragDrop);
}
void WindowManager::onRetrieveTag(const MyGUI::UString& _tag, MyGUI::UString& _result)
{
2012-12-23 19:23:24 +00:00
std::string tag(_tag);
2012-12-23 19:23:24 +00:00
std::string tokenToFind = "sCell=";
size_t tokenLength = tokenToFind.length();
if (tag.substr(0, tokenLength) == tokenToFind)
{
_result = mTranslationDataStorage.translateCellName(tag.substr(tokenLength));
2012-12-23 19:23:24 +00:00
}
2012-05-24 01:50:02 +00:00
else
2012-12-23 19:23:24 +00:00
{
const ESM::GameSetting *setting =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(tag);
if (setting && setting->mType == ESM::VT_String)
_result = setting->getString();
else
_result = tag;
}
}
void WindowManager::processChangedSettings(const Settings::CategorySettingVector& changed)
{
mHud->setFpsLevel(Settings::Manager::getInt("fps", "HUD"));
2012-05-28 07:46:05 +00:00
mToolTips->setDelay(Settings::Manager::getFloat("tooltip delay", "GUI"));
bool changeRes = false;
2013-02-05 19:48:25 +00:00
bool windowRecreated = false;
for (Settings::CategorySettingVector::const_iterator it = changed.begin();
it != changed.end(); ++it)
{
if (it->first == "Video" && (
it->second == "resolution x"
|| it->second == "resolution y"))
{
changeRes = true;
}
2013-02-05 19:48:25 +00:00
else if (it->first == "Video" && it->second == "vsync")
windowRecreated = true;
else if (it->first == "HUD" && it->second == "crosshair")
mCrosshairEnabled = Settings::Manager::getBool ("crosshair", "HUD");
else if (it->first == "GUI" && it->second == "subtitles")
mSubtitlesEnabled = Settings::Manager::getBool ("subtitles", "GUI");
}
if (changeRes)
{
int x = Settings::Manager::getInt("resolution x", "Video");
int y = Settings::Manager::getInt("resolution y", "Video");
mHud->onResChange(x, y);
mConsole->onResChange(x, y);
mMenu->onResChange(x, y);
mSettingsWindow->center();
mAlchemyWindow->center();
mScrollWindow->center();
mBookWindow->center();
mQuickKeysMenu->center();
2012-09-10 12:10:01 +00:00
mSpellBuyingWindow->center();
2012-09-11 17:18:26 +00:00
mLoadingScreen->onResChange (x,y);
mDragAndDrop->mDragAndDropWidget->setSize(MyGUI::IntSize(x, y));
2012-08-12 23:26:15 +00:00
mInputBlocker->setSize(MyGUI::IntSize(x,y));
}
2013-02-05 19:48:25 +00:00
if (windowRecreated)
{
mGuiManager->updateWindow (mRendering->getWindow ());
mLoadingScreen->updateWindow (mRendering->getWindow ());
}
}
2012-05-23 10:23:35 +00:00
void WindowManager::pushGuiMode(GuiMode mode)
{
if (mode==GM_Inventory && mAllowed==GW_None)
2012-05-23 10:23:35 +00:00
return;
// If this mode already exists somewhere in the stack, just bring it to the front.
if (std::find(mGuiModes.begin(), mGuiModes.end(), mode) != mGuiModes.end())
{
mGuiModes.erase(std::find(mGuiModes.begin(), mGuiModes.end(), mode));
}
2012-05-23 10:23:35 +00:00
mGuiModes.push_back(mode);
bool gameMode = !isGuiMode();
MWBase::Environment::get().getInputManager()->changeInputMode(!gameMode);
updateVisible();
}
void WindowManager::popGuiMode()
{
2012-06-06 18:29:30 +00:00
if (!mGuiModes.empty())
2012-05-23 10:23:35 +00:00
mGuiModes.pop_back();
bool gameMode = !isGuiMode();
MWBase::Environment::get().getInputManager()->changeInputMode(!gameMode);
updateVisible();
}
void WindowManager::removeGuiMode(GuiMode mode)
{
std::vector<GuiMode>::iterator it = mGuiModes.begin();
while (it != mGuiModes.end())
{
if (*it == mode)
it = mGuiModes.erase(it);
else
++it;
}
bool gameMode = !isGuiMode();
MWBase::Environment::get().getInputManager()->changeInputMode(!gameMode);
updateVisible();
}
void WindowManager::setSelectedSpell(const std::string& spellId, int successChancePercent)
{
mHud->setSelectedSpell(spellId, successChancePercent);
const ESM::Spell* spell =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(spellId);
2012-09-17 07:37:50 +00:00
mSpellWindow->setTitle(spell->mName);
}
void WindowManager::setSelectedEnchantItem(const MWWorld::Ptr& item, int chargePercent)
{
mHud->setSelectedEnchantItem(item, chargePercent);
mSpellWindow->setTitle(MWWorld::Class::get(item).getName(item));
}
void WindowManager::setSelectedWeapon(const MWWorld::Ptr& item, int durabilityPercent)
{
mHud->setSelectedWeapon(item, durabilityPercent);
mInventoryWindow->setTitle(MWWorld::Class::get(item).getName(item));
}
void WindowManager::unsetSelectedSpell()
{
mHud->unsetSelectedSpell();
mSpellWindow->setTitle("#{sNone}");
}
void WindowManager::unsetSelectedWeapon()
{
mHud->unsetSelectedWeapon();
mInventoryWindow->setTitle("#{sSkillHandtohand}");
}
void WindowManager::getMousePosition(int &x, int &y)
{
const MyGUI::IntPoint& pos = MyGUI::InputManager::getInstance().getMousePosition();
x = pos.left;
y = pos.top;
}
void WindowManager::getMousePosition(float &x, float &y)
{
const MyGUI::IntPoint& pos = MyGUI::InputManager::getInstance().getMousePosition();
x = pos.left;
y = pos.top;
const MyGUI::IntSize& viewSize = MyGUI::RenderManager::getInstance().getViewSize();
x /= viewSize.width;
y /= viewSize.height;
}
bool WindowManager::getWorldMouseOver()
{
return mHud->getWorldMouseOver();
}
2012-07-30 10:37:46 +00:00
void WindowManager::executeInConsole (const std::string& path)
{
mConsole->executeFile (path);
}
void WindowManager::wmUpdateFps(float fps, unsigned int triangleCount, unsigned int batchCount)
{
mFPS = fps;
mTriangleCount = triangleCount;
mBatchCount = batchCount;
}
MyGUI::Gui* WindowManager::getGui() const { return mGui; }
MWGui::DialogueWindow* WindowManager::getDialogueWindow() { return mDialogueWindow; }
MWGui::ContainerWindow* WindowManager::getContainerWindow() { return mContainerWindow; }
MWGui::InventoryWindow* WindowManager::getInventoryWindow() { return mInventoryWindow; }
MWGui::BookWindow* WindowManager::getBookWindow() { return mBookWindow; }
MWGui::ScrollWindow* WindowManager::getScrollWindow() { return mScrollWindow; }
MWGui::CountDialog* WindowManager::getCountDialog() { return mCountDialog; }
MWGui::ConfirmationDialog* WindowManager::getConfirmationDialog() { return mConfirmationDialog; }
MWGui::TradeWindow* WindowManager::getTradeWindow() { return mTradeWindow; }
MWGui::SpellBuyingWindow* WindowManager::getSpellBuyingWindow() { return mSpellBuyingWindow; }
2012-09-26 16:30:47 +00:00
MWGui::TravelWindow* WindowManager::getTravelWindow() { return mTravelWindow; }
MWGui::SpellWindow* WindowManager::getSpellWindow() { return mSpellWindow; }
MWGui::Console* WindowManager::getConsole() { return mConsole; }
bool WindowManager::isAllowed (GuiWindow wnd) const
{
return mAllowed & wnd;
}
void WindowManager::allow (GuiWindow wnd)
{
mAllowed = (GuiWindow)(mAllowed | wnd);
if (wnd & GW_Inventory)
{
mBookWindow->setInventoryAllowed (true);
mScrollWindow->setInventoryAllowed (true);
}
updateVisible();
}
void WindowManager::disallowAll()
{
mAllowed = GW_None;
mBookWindow->setInventoryAllowed (false);
mScrollWindow->setInventoryAllowed (false);
updateVisible();
}
void WindowManager::toggleVisible (GuiWindow wnd)
{
mShown = (mShown & wnd) ? (GuiWindow) (mShown & ~wnd) : (GuiWindow) (mShown | wnd);
updateVisible();
}
bool WindowManager::isGuiMode() const
{
return !mGuiModes.empty();
}
MWGui::GuiMode WindowManager::getMode() const
{
if (mGuiModes.empty())
throw std::runtime_error ("getMode() called, but there is no active mode");
return mGuiModes.back();
}
std::map<int, MWMechanics::Stat<float> > WindowManager::getPlayerSkillValues()
{
return mPlayerSkillValues;
}
std::map<int, MWMechanics::Stat<int> > WindowManager::getPlayerAttributeValues()
{
return mPlayerAttributes;
}
WindowManager::SkillList WindowManager::getPlayerMinorSkills()
{
return mPlayerMinorSkills;
}
WindowManager::SkillList WindowManager::getPlayerMajorSkills()
{
return mPlayerMajorSkills;
}
2012-08-12 23:26:15 +00:00
void WindowManager::disallowMouse()
{
mInputBlocker->setVisible (true);
}
void WindowManager::allowMouse()
{
mInputBlocker->setVisible (!isGuiMode ());
}
void WindowManager::notifyInputActionBound ()
{
mSettingsWindow->updateControlsBox ();
allowMouse();
}
2012-08-27 17:18:55 +00:00
void WindowManager::showCrosshair (bool show)
{
mHud->setCrosshairVisible (show && mCrosshairEnabled);
2012-08-27 17:18:55 +00:00
}
2012-08-27 13:51:01 +00:00
void WindowManager::activateQuickKey (int index)
{
mQuickKeysMenu->activateQuickKey(index);
}
bool WindowManager::getSubtitlesEnabled ()
{
return mSubtitlesEnabled;
}
void WindowManager::toggleHud ()
{
mHudEnabled = !mHudEnabled;
mHud->setVisible (mHudEnabled);
}
2012-09-11 14:37:54 +00:00
void WindowManager::setLoadingProgress (const std::string& stage, int depth, int current, int total)
{
mLoadingScreen->setLoadingProgress (stage, depth, current, total);
}
2012-09-12 22:21:58 +00:00
void WindowManager::loadingDone ()
{
mLoadingScreen->loadingDone ();
}
2012-09-19 01:11:23 +00:00
bool WindowManager::getPlayerSleeping ()
{
return mWaitDialog->getSleeping();
}
2012-09-29 07:41:34 +00:00
void WindowManager::wakeUpPlayer()
{
mWaitDialog->wakeUp();
}
void WindowManager::addVisitedLocation(const std::string& name, int x, int y)
{
mMap->addVisitedLocation (name, x, y);
}
2012-09-22 22:36:20 +00:00
void WindowManager::startSpellMaking(MWWorld::Ptr actor)
{
mSpellCreationDialog->startSpellMaking (actor);
}
void WindowManager::startEnchanting (MWWorld::Ptr actor)
{
mEnchantingDialog->startEnchanting (actor);
}
2012-10-17 16:03:02 +00:00
void WindowManager::startTraining(MWWorld::Ptr actor)
{
mTrainingWindow->startTraining(actor);
}
const Translation::Storage& WindowManager::getTranslationDataStorage() const
{
return mTranslationDataStorage;
}