diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index c254dcaef..83960d64a 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -87,10 +87,18 @@ set(GAMEWORLD_HEADER ) source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER}) +set(GAMEMECHANICS + mwmechanics/mechanicsmanager.cpp) +set(GAMEMECHANICS_HEADER + mwmechanics/mechanicsmanager.hpp) +source_group(apps\\openmw\\mwmechanics FILES ${GAMEMECHANICS} ${GAMEMECHANICS_HEADER}) -set(OPENMW_CPP ${GAME} ${GAMEREND} ${GAMEINPUT} ${GAMESCRIPT} ${GAMESOUND} ${GAMEGUI} ${GAMEWORLD}) +set(OPENMW_CPP ${GAME} ${GAMEREND} ${GAMEINPUT} ${GAMESCRIPT} ${GAMESOUND} ${GAMEGUI} ${GAMEWORLD} + ${GAMEMECHANICS} + ) set(OPENMW_HEADER ${GAME_HEADER} ${GAMEREND_HEADER} ${GAMEINPUT_HEADER} ${GAMESCRIPT_HEADER} - ${GAMESOUND_HEADER} ${GAMEGUI_HEADER} ${GAMEWORLD_HEADER}) + ${GAMESOUND_HEADER} ${GAMEGUI_HEADER} ${GAMEWORLD_HEADER} ${GAMEMECHANICS_HEADER} + ) # Main executable add_executable(openmw diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 39cfd7e2b..374ca41a1 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -24,6 +24,8 @@ #include "mwworld/ptr.hpp" #include "mwworld/environment.hpp" +#include "mwmechanics/mechanicsmanager.hpp" + #include void OMW::Engine::executeLocalScripts() @@ -81,6 +83,7 @@ OMW::Engine::~Engine() delete mEnvironment.mWorld; delete mEnvironment.mSoundManager; delete mEnvironment.mGlobalScripts; + delete mEnvironment.mMechanicsManager; delete mScriptManager; delete mScriptContext; } @@ -196,8 +199,10 @@ void OMW::Engine::go() mEnvironment.mWindowManager = new MWGui::WindowManager(mGuiManager->getGui(), mEnvironment, mExtensions, mNewGame); + // Create sound system mEnvironment.mSoundManager = new MWSound::SoundManager; + // Create script system mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full, mEnvironment); mScriptContext->setExtensions (&mExtensions); @@ -207,6 +212,12 @@ void OMW::Engine::go() mEnvironment.mGlobalScripts = new MWScript::GlobalScripts (mEnvironment.mWorld->getStore(), *mScriptManager); + + // Create game mechanics system + mEnvironment.mMechanicsManager = new MWMechanics::MechanicsManager ( + mEnvironment.mWorld->getStore(), *mEnvironment.mWindowManager); + + mEnvironment.mMechanicsManager->configureGUI(); // Sets up the input system MWInput::MWInputManager input(mOgre, mEnvironment.mWorld->getPlayerPos(), diff --git a/apps/openmw/mwgui/mw_layouts.hpp b/apps/openmw/mwgui/mw_layouts.hpp index 33b1bd7de..6df5ee391 100644 --- a/apps/openmw/mwgui/mw_layouts.hpp +++ b/apps/openmw/mwgui/mw_layouts.hpp @@ -161,15 +161,6 @@ namespace MWGui setText("Race_str", "Race"); setText("Class_str", "Class"); - setText("Attrib1", "Strength"); - setText("Attrib2", "Intelligence"); - setText("Attrib3", "Willpower"); - setText("Attrib4", "Agility"); - setText("Attrib5", "Speed"); - setText("Attrib6", "Endurance"); - setText("Attrib7", "Personality"); - setText("Attrib8", "Luck"); - // These are just demo values, you should replace these with // real calls from outside the class later. setPlayerName("ThePlayer"); @@ -196,6 +187,24 @@ namespace MWGui { mMainWidget->setCaption(playerName); } + + /// Set label text for the value with the given ID. + void setLabel (const std::string& id, const std::string& label) + { + static const char *ids[] = + { + "Attrib1", "Attrib2", "Attrib3", "Attrib4", "Attrib5", "Attrib6", + "Attrib7", "Attrib8", + 0 + }; + + for (int i=0; ids[i]; ++i) + if (ids[i]==id) + { + setText (id, label); + break; + } + } }; } #endif diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 1cd70ec08..02a3e3561 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -84,3 +84,9 @@ void WindowManager::updateVisible() // All other modes are ignored } + +void WindowManager::setLabel (const std::string& id, const std::string& label) +{ + stats->setLabel (id, label); +} + diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 24021a6c6..d576c10b2 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -10,6 +10,8 @@ this class. */ +#include + namespace MyGUI { class Gui; @@ -134,6 +136,9 @@ namespace MWGui } MyGUI::Gui* getGui() const { return gui; } + + void setLabel (const std::string& id, const std::string& label); + ///< Set label text for the value with the given ID. }; } #endif diff --git a/apps/openmw/mwmechanics/mechanicsmanager.cpp b/apps/openmw/mwmechanics/mechanicsmanager.cpp new file mode 100644 index 000000000..2d28b03ac --- /dev/null +++ b/apps/openmw/mwmechanics/mechanicsmanager.cpp @@ -0,0 +1,43 @@ + +#include "mechanicsmanager.hpp" + +#include + +#include "../mwgui/window_manager.hpp" + +namespace MWMechanics +{ + MechanicsManager::MechanicsManager (const ESMS::ESMStore& store, + MWGui::WindowManager& windowManager) + : mStore (store), mWindowManager (windowManager) + { + + } + + void MechanicsManager::configureGUI() + { + const char *names[][2] = + { + { "Attrib1", "sAttributeStrength" }, + { "Attrib2", "sAttributeIntelligence" }, + { "Attrib3", "sAttributeWillpower" }, + { "Attrib4", "sAttributeAgility" }, + { "Attrib5", "sAttributeSpeed" }, + { "Attrib6", "sAttributeEndurance" }, + { "Attrib7", "sAttributePersonality" }, + { "Attrib8", "sAttributeLuck" }, + { 0, 0 } + }; + + for (int i=0; names[i][0]; ++i) + { +// This crashes because of encoding problems: +// std::string label = mStore.gameSettings.find (names[i][1])->str; + + std::string label = names[i][1]; // until the problem is fixed, use the GMST ID as label + + mWindowManager.setLabel (names[i][0], label); + } + } +} + diff --git a/apps/openmw/mwmechanics/mechanicsmanager.hpp b/apps/openmw/mwmechanics/mechanicsmanager.hpp new file mode 100644 index 000000000..c74495795 --- /dev/null +++ b/apps/openmw/mwmechanics/mechanicsmanager.hpp @@ -0,0 +1,30 @@ +#ifndef GAME_MWMECHANICS_PTR_H +#define GAME_MWMECHANICS_PTR_H + +namespace ESMS +{ + class ESMStore; +} + +namespace MWGui +{ + class WindowManager; +} + +namespace MWMechanics +{ + class MechanicsManager + { + const ESMS::ESMStore& mStore; + MWGui::WindowManager& mWindowManager; + + public: + + MechanicsManager (const ESMS::ESMStore& store, MWGui::WindowManager& windowManager); + + void configureGUI(); + }; +} + +#endif + diff --git a/apps/openmw/mwworld/environment.hpp b/apps/openmw/mwworld/environment.hpp index ab0989d49..0c6476d52 100644 --- a/apps/openmw/mwworld/environment.hpp +++ b/apps/openmw/mwworld/environment.hpp @@ -16,6 +16,11 @@ namespace MWGui class WindowManager; } +namespace MWMechanics +{ + class MechanicsManager; +} + namespace MWWorld { class World; @@ -25,13 +30,15 @@ namespace MWWorld { public: Environment() - : mWorld (0), mSoundManager (0), mGlobalScripts (0), mWindowManager (0), mFrameDuration (0) + : mWorld (0), mSoundManager (0), mGlobalScripts (0), mWindowManager (0), + mMechanicsManager (0), mFrameDuration (0) {} World *mWorld; MWSound::SoundManager *mSoundManager; MWScript::GlobalScripts *mGlobalScripts; MWGui::WindowManager *mWindowManager; + MWMechanics::MechanicsManager *mMechanicsManager; float mFrameDuration; }; } diff --git a/components/esm_store/reclists.hpp b/components/esm_store/reclists.hpp index 83181b687..ba099da94 100644 --- a/components/esm_store/reclists.hpp +++ b/components/esm_store/reclists.hpp @@ -75,6 +75,15 @@ namespace ESMS ref.load(esm); } + // Find the given object ID, or return NULL if not found. + const X* find(const std::string &id) const + { + std::string id2 = toLower (id); + if(list.find(id2) == list.end()) + return NULL; + return &list.find(id2)->second; + } + int getSize() { return list.size(); } };