From 9dffa75a15dc95f7b123f4b8b62f9a7d9655473f Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 15 Sep 2010 12:22:06 +0200 Subject: [PATCH] handle name change during character creation --- apps/openmw/engine.cpp | 3 +-- apps/openmw/mwgui/layouts.hpp | 8 ++++++-- apps/openmw/mwgui/window_manager.cpp | 5 +++++ apps/openmw/mwgui/window_manager.hpp | 3 +++ apps/openmw/mwmechanics/mechanicsmanager.cpp | 20 ++++++++++++++------ apps/openmw/mwmechanics/mechanicsmanager.hpp | 15 +++++---------- apps/openmw/mwrender/playerpos.hpp | 12 ++++++++++++ 7 files changed, 46 insertions(+), 20 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index bcb2d7f599..e3a3488315 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -256,8 +256,7 @@ void OMW::Engine::go() *mScriptManager); // Create game mechanics system - mEnvironment.mMechanicsManager = new MWMechanics::MechanicsManager ( - mEnvironment.mWorld->getStore(), *mEnvironment.mWindowManager); + mEnvironment.mMechanicsManager = new MWMechanics::MechanicsManager (mEnvironment); // Create dialog system mEnvironment.mDialogueManager = new MWDialogue::DialogueManager (mEnvironment); diff --git a/apps/openmw/mwgui/layouts.hpp b/apps/openmw/mwgui/layouts.hpp index 8ab5331615..b1d3e15f2d 100644 --- a/apps/openmw/mwgui/layouts.hpp +++ b/apps/openmw/mwgui/layouts.hpp @@ -214,8 +214,6 @@ namespace MWGui // These are just demo values, you should replace these with // real calls from outside the class later. - setPlayerName("ThePlayer"); - setText("LevelText", "5"); setText("RaceText", "Wood Elf"); setText("ClassText", "Pilgrim"); @@ -269,6 +267,12 @@ namespace MWGui setBar (id, id + "T", value.getCurrent(), value.getModified()); } } + + void setValue (const std::string& id, const std::string& value) + { + if (id=="name") + setPlayerName (value); + } }; class InventoryWindow : public OEngine::GUI::Layout diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index f704c16ade..cee739ead1 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -140,6 +140,11 @@ void WindowManager::setValue (const std::string& id, const MWMechanics::DynamicS hud->setValue (id, value); } +void WindowManager::setValue (const std::string& id, const std::string& value) +{ + stats->setValue (id, value); +} + void WindowManager::messageBox (const std::string& message, const std::vector& buttons) { std::cout << "message box: " << message << std::endl; diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 2dcbb848d8..fe2aa16eb6 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -164,6 +164,9 @@ namespace MWGui void setValue (const std::string& id, const MWMechanics::DynamicStat& value); ///< Set value for the given ID. + void setValue (const std::string& id, const std::string& value); + ///< set value for the given ID. + void messageBox (const std::string& message, const std::vector& buttons); private: diff --git a/apps/openmw/mwmechanics/mechanicsmanager.cpp b/apps/openmw/mwmechanics/mechanicsmanager.cpp index f0aa156523..836a340ad5 100644 --- a/apps/openmw/mwmechanics/mechanicsmanager.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanager.cpp @@ -6,12 +6,13 @@ #include "../mwgui/window_manager.hpp" #include "../mwworld/class.hpp" +#include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" namespace MWMechanics { - MechanicsManager::MechanicsManager (const ESMS::ESMStore& store, - MWGui::WindowManager& windowManager) - : mStore (store), mWindowManager (windowManager) + MechanicsManager::MechanicsManager (MWWorld::Environment& environment) + : mEnvironment (environment), mSetName (true) { } @@ -68,7 +69,7 @@ namespace MWMechanics { mWatchedCreature.mAttributes[i] = stats.mAttributes[i]; - mWindowManager.setValue (attributeNames[i], stats.mAttributes[i]); + mEnvironment.mWindowManager->setValue (attributeNames[i], stats.mAttributes[i]); } } @@ -78,15 +79,22 @@ namespace MWMechanics { mWatchedCreature.mDynamic[i] = stats.mDynamic[i]; - mWindowManager.setValue (dynamicNames[i], stats.mDynamic[i]); + mEnvironment.mWindowManager->setValue (dynamicNames[i], stats.mDynamic[i]); } } } + + if (mSetName) + { + mEnvironment.mWindowManager->setValue ("name", mEnvironment.mWorld->getPlayerPos().getName()); + mSetName = false; + } } void MechanicsManager::setPlayerName (const std::string& name) { - + mEnvironment.mWorld->getPlayerPos().setName (name); + mSetName = true; } void MechanicsManager::setPlayerRace (const std::string& race, bool male) diff --git a/apps/openmw/mwmechanics/mechanicsmanager.hpp b/apps/openmw/mwmechanics/mechanicsmanager.hpp index 8955e464b6..fffc0611f8 100644 --- a/apps/openmw/mwmechanics/mechanicsmanager.hpp +++ b/apps/openmw/mwmechanics/mechanicsmanager.hpp @@ -7,29 +7,24 @@ #include "creaturestats.hpp" -namespace ESMS +namespace MWWorld { - struct ESMStore; -} - -namespace MWGui -{ - class WindowManager; + class Environment; } namespace MWMechanics { class MechanicsManager { - const ESMS::ESMStore& mStore; - MWGui::WindowManager& mWindowManager; + MWWorld::Environment& mEnvironment; std::set mActors; MWWorld::Ptr mWatched; CreatureStats mWatchedCreature; + bool mSetName; public: - MechanicsManager (const ESMS::ESMStore& store, MWGui::WindowManager& windowManager); + MechanicsManager (MWWorld::Environment& environment); void configureGUI(); diff --git a/apps/openmw/mwrender/playerpos.hpp b/apps/openmw/mwrender/playerpos.hpp index 59a0e1b41f..59cc942ddd 100644 --- a/apps/openmw/mwrender/playerpos.hpp +++ b/apps/openmw/mwrender/playerpos.hpp @@ -24,12 +24,14 @@ namespace MWRender MWWorld::Ptr::CellStore *mCellStore; Ogre::Camera *camera; MWWorld::World& mWorld; + std::string mName; public: PlayerPos(Ogre::Camera *cam, const ESM::NPC *player, MWWorld::World& world) : mCellStore (0), camera(cam), mWorld (world) { mPlayer.base = player; + mName = player->name; mPlayer.ref.pos.pos[0] = mPlayer.ref.pos.pos[1] = mPlayer.ref.pos.pos[2] = 0; } @@ -73,6 +75,16 @@ namespace MWRender MWWorld::Ptr ptr (&mPlayer, mCellStore); return ptr; } + + void setName (const std::string& name) + { + mName = name; + } + + std::string getName() const + { + return mName; + } }; } #endif