From 4b758376be54762274200b08bf60450c36ca3e64 Mon Sep 17 00:00:00 2001 From: Cris Mihalache Date: Mon, 30 Jan 2012 16:38:43 +0200 Subject: [PATCH 1/4] Created a class for char gen, and starting moving code to it --- .gitignore | 1 + apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwgui/mode.hpp | 9 ++ apps/openmw/mwgui/window_manager.cpp | 181 ++++----------------------- apps/openmw/mwgui/window_manager.hpp | 42 +++---- 5 files changed, 50 insertions(+), 185 deletions(-) diff --git a/.gitignore b/.gitignore index ada874bb2..139b5c2c4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ Docs/mainpage.hpp CMakeFiles */CMakeFiles CMakeCache.txt +data diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index e9e548c0e..14695fcf3 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -23,7 +23,7 @@ add_openmw_dir (mwinput add_openmw_dir (mwgui layouts text_input widgets race class birth review window_manager console dialogue - dialogue_history window_base stats_window messagebox journalwindow + dialogue_history window_base stats_window messagebox journalwindow character_creation ) add_openmw_dir (mwdialogue diff --git a/apps/openmw/mwgui/mode.hpp b/apps/openmw/mwgui/mode.hpp index 55f0952ce..34264568a 100644 --- a/apps/openmw/mwgui/mode.hpp +++ b/apps/openmw/mwgui/mode.hpp @@ -45,6 +45,15 @@ namespace MWGui GW_ALL = 0xFF }; + + // Character creation dialogs + enum CharGen + { + GEN_Name, + GEN_Race, + GEN_Class, + GEN_Sign + }; } #endif diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index d16611794..97d8f9b04 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -1,7 +1,6 @@ #include "window_manager.hpp" #include "layouts.hpp" #include "text_input.hpp" -#include "race.hpp" #include "class.hpp" #include "birth.hpp" #include "review.hpp" @@ -15,6 +14,7 @@ #include "console.hpp" #include "journalwindow.hpp" +#include "character_creation.hpp" #include #include @@ -25,13 +25,10 @@ using namespace MWGui; WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment, const Compiler::Extensions& extensions, int fpsLevel, bool newGame) : environment(environment) - , nameDialog(nullptr) - , raceDialog(nullptr) , dialogueWindow(nullptr) , classChoiceDialog(nullptr) , generateClassQuestionDialog(nullptr) , generateClassResultDialog(nullptr) - , pickClassDialog(nullptr) , createClassDialog(nullptr) , birthSignDialog(nullptr) , reviewDialog(nullptr) @@ -44,6 +41,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment { showFPSLevel = fpsLevel; + /// REMOVE creationStage = NotStarted; //Register own widgets with MyGUI @@ -68,6 +66,8 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment // The HUD is always on hud->setVisible(true); + mCharGen = new CharacterCreation(this); + // Setup player stats for (int i = 0; i < ESM::Attribute::Length; ++i) { @@ -102,13 +102,10 @@ WindowManager::~WindowManager() delete inventory; #endif - delete nameDialog; - delete raceDialog; delete dialogueWindow; delete classChoiceDialog; delete generateClassQuestionDialog; delete generateClassResultDialog; - delete pickClassDialog; delete createClassDialog; delete birthSignDialog; delete reviewDialog; @@ -129,6 +126,11 @@ void WindowManager::cleanupGarbage() } } +MWMechanics::MechanicsManager* WindowManager::getMechanicsManager() +{ + return environment.mMechanicsManager; +} + void WindowManager::update() { cleanupGarbage(); @@ -178,7 +180,7 @@ void WindowManager::updateVisible() gui->setVisiblePointer(isGuiMode()); // If in game mode, don't show anything. - if(mode == GM_Game) + if(mode == GM_Game) //Use a switch/case structure { return; } @@ -196,40 +198,21 @@ void WindowManager::updateVisible() return; } - if (mode == GM_Name) + if (mode == GM_Name) //Combine this with all char-gen related if statements { - if (nameDialog) - removeDialog(nameDialog); - nameDialog = new TextInputDialog(*this); - std::string sName = getGameSettingString("sName", "Name"); - nameDialog->setTextLabel(sName); - nameDialog->setTextInput(playerName); - nameDialog->setNextButtonShow(creationStage >= NameChosen); - nameDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onNameDialogDone); - nameDialog->open(); + mCharGen->spawnDialog(GM_Name); return; } - if (mode == GM_Race) + if (mode == GM_Race) //Combine this with all char-gen related if statements { - if (raceDialog) - removeDialog(raceDialog); - raceDialog = new RaceDialog(*this); - raceDialog->setNextButtonShow(creationStage >= RaceChosen); - raceDialog->setRaceId(playerRaceId); - raceDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onRaceDialogDone); - raceDialog->eventBack = MyGUI::newDelegate(this, &WindowManager::onRaceDialogBack); - raceDialog->open(); + mCharGen->spawnDialog(GM_Race); return; } if (mode == GM_Class) { - if (classChoiceDialog) - removeDialog(classChoiceDialog); - classChoiceDialog = new ClassChoiceDialog(*this); - classChoiceDialog->eventButtonSelected = MyGUI::newDelegate(this, &WindowManager::onClassChoice); - classChoiceDialog->open(); + mCharGen->spawnDialog(GM_Class); return; } @@ -246,14 +229,7 @@ void WindowManager::updateVisible() if (mode == GM_ClassPick) { - if (pickClassDialog) - removeDialog(pickClassDialog); - pickClassDialog = new PickClassDialog(*this); - pickClassDialog->setNextButtonShow(creationStage >= ClassChosen); - pickClassDialog->setClassId(playerClass.name); - pickClassDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onPickClassDialogDone); - pickClassDialog->eventBack = MyGUI::newDelegate(this, &WindowManager::onPickClassDialogBack); - pickClassDialog->open(); + mCharGen->spawnDialog(GM_ClassPick); return; } @@ -286,7 +262,7 @@ void WindowManager::updateVisible() if (reviewDialog) removeDialog(reviewDialog); reviewDialog = new ReviewDialog(*this); - reviewDialog->setPlayerName(playerName); + //reviewDialog->setPlayerName(playerName); //Move this to Chargen as part of refactoring reviewDialog->setRace(playerRaceId); reviewDialog->setClass(playerClass); reviewDialog->setBirthSign(playerBirthSignId); @@ -420,10 +396,10 @@ void WindowManager::setValue (const std::string& id, const MWMechanics::DynamicS void WindowManager::setValue (const std::string& id, const std::string& value) { stats->setValue (id, value); - if (id=="name") + /*if (id=="name") playerName = value; else if (id=="race") - playerRaceId = value; + playerRaceId = value;*/ //Move this to chargen } void WindowManager::setValue (const std::string& id, int value) @@ -505,49 +481,6 @@ const std::string &WindowManager::getGameSettingString(const std::string &id, co return default_; } -void WindowManager::onNameDialogDone(WindowBase* parWindow) -{ - if (nameDialog) - { - playerName = nameDialog->getTextInput(); - environment.mMechanicsManager->setPlayerName(playerName); - removeDialog(nameDialog); - } - - // Go to next dialog if name was previously chosen - if (creationStage == ReviewNext) - setGuiMode(GM_Review); - else if (creationStage >= NameChosen) - setGuiMode(GM_Race); - else - { - creationStage = NameChosen; - setGuiMode(GM_Game); - } -} - -void WindowManager::onRaceDialogDone(WindowBase* parWindow) -{ - if (raceDialog) - { - playerRaceId = raceDialog->getRaceId(); - if (!playerRaceId.empty()) - environment.mMechanicsManager->setPlayerRace(playerRaceId, raceDialog->getGender() == RaceDialog::GM_Male); - removeDialog(raceDialog); - } - - // Go to next dialog if race was previously chosen - if (creationStage == ReviewNext) - setGuiMode(GM_Review); - else if(creationStage >= RaceChosen) - setGuiMode(GM_Class); - else - { - creationStage = RaceChosen; - setGuiMode(GM_Game); - } -} - void WindowManager::onDialogueWindowBye() { if (dialogueWindow) @@ -558,44 +491,6 @@ void WindowManager::onDialogueWindowBye() setGuiMode(GM_Game); } -void WindowManager::onRaceDialogBack() -{ - if (raceDialog) - { - playerRaceId = raceDialog->getRaceId(); - if (!playerRaceId.empty()) - environment.mMechanicsManager->setPlayerRace(playerRaceId, raceDialog->getGender() == RaceDialog::GM_Male); - removeDialog(raceDialog); - } - - setGuiMode(GM_Name); -} - -void WindowManager::onClassChoice(int _index) -{ - if (classChoiceDialog) - { - removeDialog(classChoiceDialog); - } - - switch(_index) - { - case ClassChoiceDialog::Class_Generate: - setGuiMode(GM_ClassGenerate); - break; - case ClassChoiceDialog::Class_Pick: - setGuiMode(GM_ClassPick); - break; - case ClassChoiceDialog::Class_Create: - setGuiMode(GM_ClassCreate); - break; - case ClassChoiceDialog::Class_Back: - setGuiMode(GM_Race); - break; - - }; -} - void WindowManager::onFrame (float frameDuration) { mMessageBoxManager->onFrame(frameDuration); @@ -828,43 +723,9 @@ void WindowManager::onGenerateClassDone(WindowBase* parWindow) } } - -void WindowManager::onPickClassDialogDone(WindowBase* parWindow) +MWWorld::World* WindowManager::getWorld() { - if (pickClassDialog) - { - const std::string &classId = pickClassDialog->getClassId(); - if (!classId.empty()) - environment.mMechanicsManager->setPlayerClass(classId); - const ESM::Class *klass = environment.mWorld->getStore().classes.find(classId); - if (klass) - playerClass = *klass; - removeDialog(pickClassDialog); - } - - // Go to next dialog if class was previously chosen - if (creationStage == ReviewNext) - setGuiMode(GM_Review); - else if (creationStage >= ClassChosen) - setGuiMode(GM_Birth); - else - { - creationStage = ClassChosen; - setGuiMode(GM_Game); - } -} - -void WindowManager::onPickClassDialogBack() -{ - if (pickClassDialog) - { - const std::string classId = pickClassDialog->getClassId(); - if (!classId.empty()) - environment.mMechanicsManager->setPlayerClass(classId); - removeDialog(pickClassDialog); - } - - setGuiMode(GM_Class); + return environment.mWorld; } void WindowManager::onCreateClassDialogDone(WindowBase* parWindow) diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index a47e53fed..6af14d28e 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -32,6 +32,12 @@ namespace Compiler namespace MWWorld { class Environment; + class World; +} + +namespace MWMechanics +{ + class MechanicsManager; } namespace OEngine @@ -52,14 +58,13 @@ namespace MWGui class InventoryWindow; class Console; class JournalWindow; + class CharacterCreation; class TextInputDialog; class InfoBoxDialog; - class RaceDialog; class DialogueWindow; class ClassChoiceDialog; class GenerateClassResultDialog; - class PickClassDialog; class CreateClassDialog; class BirthDialog; class ReviewDialog; @@ -94,13 +99,12 @@ namespace MWGui JournalWindow* mJournal; // Character creation - TextInputDialog *nameDialog; - RaceDialog *raceDialog; + CharacterCreation* mCharGen; + DialogueWindow *dialogueWindow; ClassChoiceDialog *classChoiceDialog; InfoBoxDialog *generateClassQuestionDialog; GenerateClassResultDialog *generateClassResultDialog; - PickClassDialog *pickClassDialog; CreateClassDialog *createClassDialog; BirthDialog *birthSignDialog; ReviewDialog *reviewDialog; @@ -112,9 +116,9 @@ namespace MWGui std::string generateClass; // Various stats about player as needed by window manager - std::string playerName; ESM::Class playerClass; - std::string playerRaceId, playerBirthSignId; + std::string playerRaceId; ///REMOVE + std::string playerBirthSignId; std::map > playerAttributes; SkillList playerMajorSkills, playerMinorSkills; std::map > playerSkillValues; @@ -156,8 +160,6 @@ namespace MWGui // allowed settings. void updateVisible(); - void setGuiMode(GuiMode newMode); - int showFPSLevel; float mFPS; size_t mTriangleCount; @@ -169,6 +171,10 @@ namespace MWGui const Compiler::Extensions& extensions, int fpsLevel, bool newGame); virtual ~WindowManager(); + void setGuiMode(GuiMode newMode); + MWMechanics::MechanicsManager* getMechanicsManager(); + MWWorld::World* getWorld(); + /** * Should be called each frame to update windows/gui elements. * This could mean updating sizes of gui elements or opening @@ -280,27 +286,13 @@ namespace MWGui private: void onDialogueWindowBye(); - - // Character generation: Name dialog - void onNameDialogDone(WindowBase* parWindow); - - // Character generation: Race dialog - void onRaceDialogDone(WindowBase* parWindow); - void onRaceDialogBack(); - - // Character generation: Choose class process - void onClassChoice(int _index); - + // Character generation: Generate Class void showClassQuestionDialog(); void onClassQuestionChosen(int _index); void onGenerateClassBack(); void onGenerateClassDone(WindowBase* parWindow); - // Character generation: Pick Class dialog - void onPickClassDialogDone(WindowBase* parWindow); - void onPickClassDialogBack(); - // Character generation: Create Class dialog void onCreateClassDialogDone(WindowBase* parWindow); void onCreateClassDialogBack(); @@ -314,6 +306,7 @@ namespace MWGui void onReviewDialogBack(); void onReviewActivateDialog(int parDialog); + /// REMOVE enum CreationStageEnum { NotStarted, @@ -326,6 +319,7 @@ namespace MWGui // Which state the character creating is in, controls back/next/ok buttons CreationStageEnum creationStage; + /// /REMOVE }; template From d17ba6ce196c07382e4cf13c10a2f1ce4e8c75b2 Mon Sep 17 00:00:00 2001 From: Cris Mihalache Date: Mon, 30 Jan 2012 19:27:49 +0200 Subject: [PATCH 2/4] Forgot the CharacterCreation files --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwgui/charactercreation.cpp | 211 ++++++++++++++++++++++++ apps/openmw/mwgui/charactercreation.hpp | 84 ++++++++++ apps/openmw/mwgui/window_manager.cpp | 2 +- 4 files changed, 297 insertions(+), 2 deletions(-) create mode 100644 apps/openmw/mwgui/charactercreation.cpp create mode 100644 apps/openmw/mwgui/charactercreation.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 14695fcf3..2fafee229 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -23,7 +23,7 @@ add_openmw_dir (mwinput add_openmw_dir (mwgui layouts text_input widgets race class birth review window_manager console dialogue - dialogue_history window_base stats_window messagebox journalwindow character_creation + dialogue_history window_base stats_window messagebox journalwindow charactercreation ) add_openmw_dir (mwdialogue diff --git a/apps/openmw/mwgui/charactercreation.cpp b/apps/openmw/mwgui/charactercreation.cpp new file mode 100644 index 000000000..73cf7b577 --- /dev/null +++ b/apps/openmw/mwgui/charactercreation.cpp @@ -0,0 +1,211 @@ +#include "charactercreation.hpp" + +#include "text_input.hpp" +#include "race.hpp" +#include "class.hpp" +#include "birth.hpp" +#include "review.hpp" +#include "dialogue.hpp" + +#include "mode.hpp" + +using namespace MWGui; + +CharacterCreation::CharacterCreation(WindowManager* _wm) + : nameDialog(0) + , raceDialog(0) + , dialogueWindow(0) + , classChoiceDialog(0) + , generateClassQuestionDialog(0) + , generateClassResultDialog(0) + , pickClassDialog(0) + , createClassDialog(0) + , birthSignDialog(0) + , reviewDialog(0) + , wm(_wm) +{ + creationStage = NotStarted; +} + +void CharacterCreation::spawnDialog(const char id) +{ + //Switch this out with a switch/case structure + if(id == GM_Name) + { + if(nameDialog) + wm->removeDialog(nameDialog); + nameDialog = new TextInputDialog(*wm); + nameDialog->setTextLabel(wm->getGameSettingString("sName", "Name")); + nameDialog->setTextInput(playerName); + nameDialog->setNextButtonShow(creationStage >= NameChosen); + nameDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onNameDialogDone); + nameDialog->open(); + return; + } + + if(id == GM_Race) + { + if (raceDialog) + wm->removeDialog(raceDialog); + raceDialog = new RaceDialog(*wm); + raceDialog->setNextButtonShow(creationStage >= RaceChosen); + raceDialog->setRaceId(playerRaceId); + raceDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onRaceDialogDone); + raceDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onRaceDialogBack); + raceDialog->open(); + return; + } + + if(id == GM_Class) + { + if (classChoiceDialog) + wm->removeDialog(classChoiceDialog); + classChoiceDialog = new ClassChoiceDialog(*wm); + classChoiceDialog->eventButtonSelected = MyGUI::newDelegate(this, &CharacterCreation::onClassChoice); + classChoiceDialog->open(); + return; + } + + if(id == GM_ClassPick) + { + if (pickClassDialog) + wm->removeDialog(pickClassDialog); + pickClassDialog = new PickClassDialog(*wm); + pickClassDialog->setNextButtonShow(creationStage >= ClassChosen); + pickClassDialog->setClassId(playerClass.name); + pickClassDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onPickClassDialogDone); + pickClassDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onPickClassDialogBack); + pickClassDialog->open(); + return; + } +} + +void CharacterCreation::onPickClassDialogDone(WindowBase* parWindow) +{ + if (pickClassDialog) + { + const std::string &classId = pickClassDialog->getClassId(); + if (!classId.empty()) + wm->getMechanicsManager()->setPlayerClass(classId); + const ESM::Class *klass = wm->getWorld()->getStore().classes.find(classId); + if (klass) + playerClass = *klass; + wm->removeDialog(pickClassDialog); + } + + if (creationStage == ReviewNext) + wm->setGuiMode(GM_Review); + else if (creationStage >= ClassChosen) + wm->setGuiMode(GM_Birth); + else + { + creationStage = ClassChosen; + wm->setGuiMode(GM_Game); + } +} + +void CharacterCreation::onPickClassDialogBack() +{ + if (pickClassDialog) + { + const std::string classId = pickClassDialog->getClassId(); + if (!classId.empty()) + wm->getMechanicsManager()->setPlayerClass(classId); + wm->removeDialog(pickClassDialog); + } + + wm->setGuiMode(GM_Class); +} + +void CharacterCreation::onClassChoice(int _index) +{ + if (classChoiceDialog) + { + wm->removeDialog(classChoiceDialog); + } + + switch(_index) + { + case ClassChoiceDialog::Class_Generate: + wm->setGuiMode(GM_ClassGenerate); + break; + case ClassChoiceDialog::Class_Pick: + wm->setGuiMode(GM_ClassPick); + break; + case ClassChoiceDialog::Class_Create: + wm->setGuiMode(GM_ClassCreate); + break; + case ClassChoiceDialog::Class_Back: + wm->setGuiMode(GM_Race); + break; + + }; +} + +void CharacterCreation::onNameDialogDone(WindowBase* parWindow) +{ + if (nameDialog) + { + playerName = nameDialog->getTextInput(); + wm->getMechanicsManager()->setPlayerName(playerName); + wm->removeDialog(nameDialog); + } + + if (creationStage == ReviewNext) + wm->setGuiMode(GM_Review); + else if (creationStage >= NameChosen) + wm->setGuiMode(GM_Race); + else + { + creationStage = NameChosen; + wm->setGuiMode(GM_Game); + } +} + +void CharacterCreation::onRaceDialogBack() +{ + if (raceDialog) + { + playerRaceId = raceDialog->getRaceId(); + if (!playerRaceId.empty()) + wm->getMechanicsManager()->setPlayerRace(playerRaceId, raceDialog->getGender() == RaceDialog::GM_Male); + wm->removeDialog(raceDialog); + } + + wm->setGuiMode(GM_Name); +} + +void CharacterCreation::onRaceDialogDone(WindowBase* parWindow) +{ + if (raceDialog) + { + playerRaceId = raceDialog->getRaceId(); + if (!playerRaceId.empty()) + wm->getMechanicsManager()->setPlayerRace(playerRaceId, raceDialog->getGender() == RaceDialog::GM_Male); + wm->removeDialog(raceDialog); + } + + if (creationStage == ReviewNext) + wm->setGuiMode(GM_Review); + else if(creationStage >= RaceChosen) + wm->setGuiMode(GM_Class); + else + { + creationStage = RaceChosen; + wm->setGuiMode(GM_Game); + } +} + +CharacterCreation::~CharacterCreation() +{ + delete nameDialog; + delete raceDialog; + delete dialogueWindow; + delete classChoiceDialog; + delete generateClassQuestionDialog; + delete generateClassResultDialog; + delete pickClassDialog; + delete createClassDialog; + delete birthSignDialog; + delete reviewDialog; +} diff --git a/apps/openmw/mwgui/charactercreation.hpp b/apps/openmw/mwgui/charactercreation.hpp new file mode 100644 index 000000000..b9ce884c7 --- /dev/null +++ b/apps/openmw/mwgui/charactercreation.hpp @@ -0,0 +1,84 @@ +#ifndef CHARACTER_CREATION_HPP +#define CHARACTER_CREATION_HPP + +#include "window_manager.hpp" + +#include "../mwmechanics/mechanicsmanager.hpp" +#include "../mwworld/world.hpp" +#include + +namespace MWGui +{ + class WindowManager; + class WindowBase; + + class TextInputDialog; + class InfoBoxDialog; + class RaceDialog; + class DialogueWindow; + class ClassChoiceDialog; + class GenerateClassResultDialog; + class PickClassDialog; + class CreateClassDialog; + class BirthDialog; + class ReviewDialog; + class MessageBoxManager; + + class CharacterCreation + { + public: + CharacterCreation(WindowManager* _wm); + ~CharacterCreation(); + + //Show a dialog + void spawnDialog(const char id); + + private: + WindowManager* wm; + + //Dialogs + TextInputDialog *nameDialog; + RaceDialog *raceDialog; + DialogueWindow *dialogueWindow; + ClassChoiceDialog *classChoiceDialog; + InfoBoxDialog *generateClassQuestionDialog; + GenerateClassResultDialog *generateClassResultDialog; + PickClassDialog *pickClassDialog; + CreateClassDialog *createClassDialog; + BirthDialog *birthSignDialog; + ReviewDialog *reviewDialog; + + //Player data + std::string playerName; + std::string playerRaceId; + ESM::Class playerClass; + + ////Dialog events + //Name dialog + void onNameDialogDone(WindowBase* parWindow); + + //Race dialog + void onRaceDialogDone(WindowBase* parWindow); + void onRaceDialogBack(); + + //Class dialog(s) + void onClassChoice(int _index); + void onPickClassDialogDone(WindowBase* parWindow); + void onPickClassDialogBack(); + + enum CreationStageEnum + { + NotStarted, + NameChosen, + RaceChosen, + ClassChosen, + BirthSignChosen, + ReviewNext + }; + + // Which state the character creating is in, controls back/next/ok buttons + CreationStageEnum creationStage; + }; +} + +#endif diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 97d8f9b04..728f414ba 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -14,7 +14,7 @@ #include "console.hpp" #include "journalwindow.hpp" -#include "character_creation.hpp" +#include "charactercreation.hpp" #include #include From ed5892eb5caba735f760bd34a4b1795a8af269fc Mon Sep 17 00:00:00 2001 From: Cris Mihalache Date: Mon, 30 Jan 2012 21:53:17 +0200 Subject: [PATCH 3/4] Finished moving the bulk of character creation code --- apps/openmw/mwgui/charactercreation.cpp | 429 +++++++++++++++++--- apps/openmw/mwgui/charactercreation.hpp | 117 +++++- apps/openmw/mwgui/mode.hpp | 9 - apps/openmw/mwgui/window_manager.cpp | 501 +----------------------- apps/openmw/mwgui/window_manager.hpp | 152 ++----- 5 files changed, 533 insertions(+), 675 deletions(-) diff --git a/apps/openmw/mwgui/charactercreation.cpp b/apps/openmw/mwgui/charactercreation.cpp index 73cf7b577..86c7a6758 100644 --- a/apps/openmw/mwgui/charactercreation.cpp +++ b/apps/openmw/mwgui/charactercreation.cpp @@ -11,7 +11,7 @@ using namespace MWGui; -CharacterCreation::CharacterCreation(WindowManager* _wm) +CharacterCreation::CharacterCreation(WindowManager* _wm, MWWorld::Environment* _environment) : nameDialog(0) , raceDialog(0) , dialogueWindow(0) @@ -23,76 +23,176 @@ CharacterCreation::CharacterCreation(WindowManager* _wm) , birthSignDialog(0) , reviewDialog(0) , wm(_wm) + , environment(_environment) { creationStage = NotStarted; } void CharacterCreation::spawnDialog(const char id) { - //Switch this out with a switch/case structure - if(id == GM_Name) - { - if(nameDialog) - wm->removeDialog(nameDialog); - nameDialog = new TextInputDialog(*wm); - nameDialog->setTextLabel(wm->getGameSettingString("sName", "Name")); - nameDialog->setTextInput(playerName); - nameDialog->setNextButtonShow(creationStage >= NameChosen); - nameDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onNameDialogDone); - nameDialog->open(); - return; - } - - if(id == GM_Race) - { - if (raceDialog) - wm->removeDialog(raceDialog); - raceDialog = new RaceDialog(*wm); - raceDialog->setNextButtonShow(creationStage >= RaceChosen); - raceDialog->setRaceId(playerRaceId); - raceDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onRaceDialogDone); - raceDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onRaceDialogBack); - raceDialog->open(); - return; - } - - if(id == GM_Class) + switch (id) { - if (classChoiceDialog) - wm->removeDialog(classChoiceDialog); - classChoiceDialog = new ClassChoiceDialog(*wm); - classChoiceDialog->eventButtonSelected = MyGUI::newDelegate(this, &CharacterCreation::onClassChoice); - classChoiceDialog->open(); - return; - } - - if(id == GM_ClassPick) - { - if (pickClassDialog) - wm->removeDialog(pickClassDialog); - pickClassDialog = new PickClassDialog(*wm); - pickClassDialog->setNextButtonShow(creationStage >= ClassChosen); - pickClassDialog->setClassId(playerClass.name); - pickClassDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onPickClassDialogDone); - pickClassDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onPickClassDialogBack); - pickClassDialog->open(); - return; + case GM_Name: + if(nameDialog) + wm->removeDialog(nameDialog); + nameDialog = new TextInputDialog(*wm); + nameDialog->setTextLabel(wm->getGameSettingString("sName", "Name")); + nameDialog->setTextInput(playerName); + nameDialog->setNextButtonShow(creationStage >= NameChosen); + nameDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onNameDialogDone); + nameDialog->open(); + break; + + case GM_Race: + if (raceDialog) + wm->removeDialog(raceDialog); + raceDialog = new RaceDialog(*wm); + raceDialog->setNextButtonShow(creationStage >= RaceChosen); + raceDialog->setRaceId(playerRaceId); + raceDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onRaceDialogDone); + raceDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onRaceDialogBack); + raceDialog->open(); + break; + + case GM_Class: + if (classChoiceDialog) + wm->removeDialog(classChoiceDialog); + classChoiceDialog = new ClassChoiceDialog(*wm); + classChoiceDialog->eventButtonSelected = MyGUI::newDelegate(this, &CharacterCreation::onClassChoice); + classChoiceDialog->open(); + break; + + case GM_ClassPick: + if (pickClassDialog) + wm->removeDialog(pickClassDialog); + pickClassDialog = new PickClassDialog(*wm); + pickClassDialog->setNextButtonShow(creationStage >= ClassChosen); + pickClassDialog->setClassId(playerClass.name); + pickClassDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onPickClassDialogDone); + pickClassDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onPickClassDialogBack); + pickClassDialog->open(); + break; + + case GM_Birth: + if (birthSignDialog) + wm->removeDialog(birthSignDialog); + birthSignDialog = new BirthDialog(*wm); + birthSignDialog->setNextButtonShow(creationStage >= BirthSignChosen); + birthSignDialog->setBirthId(playerBirthSignId); + birthSignDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onBirthSignDialogDone); + birthSignDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onBirthSignDialogBack); + birthSignDialog->open(); + break; + + case GM_ClassCreate: + if (createClassDialog) + wm->removeDialog(createClassDialog); + createClassDialog = new CreateClassDialog(*wm); + createClassDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onCreateClassDialogDone); + createClassDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onCreateClassDialogBack); + createClassDialog->open(); + break; + case GM_ClassGenerate: + generateClassStep = 0; + generateClass = ""; + generateClassSpecializations[0] = 0; + generateClassSpecializations[1] = 0; + generateClassSpecializations[2] = 0; + showClassQuestionDialog(); + break; + case GM_Review: + if (reviewDialog) + wm->removeDialog(reviewDialog); + reviewDialog = new ReviewDialog(*wm); + reviewDialog->setPlayerName(playerName); + reviewDialog->setRace(playerRaceId); + reviewDialog->setClass(playerClass); + reviewDialog->setBirthSign(playerBirthSignId); + + reviewDialog->setHealth(wm->getValue("HBar")); + reviewDialog->setMagicka(wm->getValue("MBar")); + reviewDialog->setFatigue(wm->getValue("FBar")); + + { + std::map >::iterator end = playerAttributes.end(); + for (std::map >::iterator it = playerAttributes.begin(); it != end; ++it) + { + reviewDialog->setAttribute(it->first, it->second); + } + } + + { + std::map >::iterator end = playerSkillValues.end(); + for (std::map >::iterator it = playerSkillValues.begin(); it != end; ++it) + { + reviewDialog->setSkillValue(it->first, it->second); + } + reviewDialog->configureSkills(playerMajorSkills, playerMinorSkills); + } + + reviewDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onReviewDialogDone); + reviewDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onReviewDialogBack); + reviewDialog->eventActivateDialog = MyGUI::newDelegate(this, &CharacterCreation::onReviewActivateDialog); + reviewDialog->open(); + break; } } +void CharacterCreation::onReviewDialogDone(WindowBase* parWindow) +{ + if (reviewDialog) + wm->removeDialog(reviewDialog); + + wm->setGuiMode(GM_Game); +} + +void CharacterCreation::onReviewDialogBack() +{ + if (reviewDialog) + wm->removeDialog(reviewDialog); + + wm->setGuiMode(GM_Birth); +} + +void CharacterCreation::onReviewActivateDialog(int parDialog) +{ + if (reviewDialog) + wm->removeDialog(reviewDialog); + creationStage = ReviewNext; + + switch(parDialog) + { + case ReviewDialog::NAME_DIALOG: + wm->setGuiMode(GM_Name); + break; + case ReviewDialog::RACE_DIALOG: + wm->setGuiMode(GM_Race); + break; + case ReviewDialog::CLASS_DIALOG: + wm->setGuiMode(GM_Class); + break; + case ReviewDialog::BIRTHSIGN_DIALOG: + wm->setGuiMode(GM_Birth); + }; +} + void CharacterCreation::onPickClassDialogDone(WindowBase* parWindow) { if (pickClassDialog) { const std::string &classId = pickClassDialog->getClassId(); if (!classId.empty()) - wm->getMechanicsManager()->setPlayerClass(classId); - const ESM::Class *klass = wm->getWorld()->getStore().classes.find(classId); + environment->mMechanicsManager->setPlayerClass(classId); + const ESM::Class *klass = environment->mWorld->getStore().classes.find(classId); if (klass) + { playerClass = *klass; + wm->setPlayerClass(playerClass); + } wm->removeDialog(pickClassDialog); } + //TODO This bit gets repeated a few times; wrap it in a function if (creationStage == ReviewNext) wm->setGuiMode(GM_Review); else if (creationStage >= ClassChosen) @@ -110,7 +210,7 @@ void CharacterCreation::onPickClassDialogBack() { const std::string classId = pickClassDialog->getClassId(); if (!classId.empty()) - wm->getMechanicsManager()->setPlayerClass(classId); + environment->mMechanicsManager->setPlayerClass(classId); wm->removeDialog(pickClassDialog); } @@ -147,7 +247,8 @@ void CharacterCreation::onNameDialogDone(WindowBase* parWindow) if (nameDialog) { playerName = nameDialog->getTextInput(); - wm->getMechanicsManager()->setPlayerName(playerName); + wm->setValue("name", playerName); + environment->mMechanicsManager->setPlayerName(playerName); wm->removeDialog(nameDialog); } @@ -168,7 +269,7 @@ void CharacterCreation::onRaceDialogBack() { playerRaceId = raceDialog->getRaceId(); if (!playerRaceId.empty()) - wm->getMechanicsManager()->setPlayerRace(playerRaceId, raceDialog->getGender() == RaceDialog::GM_Male); + environment->mMechanicsManager->setPlayerRace(playerRaceId, raceDialog->getGender() == RaceDialog::GM_Male); wm->removeDialog(raceDialog); } @@ -180,8 +281,9 @@ void CharacterCreation::onRaceDialogDone(WindowBase* parWindow) if (raceDialog) { playerRaceId = raceDialog->getRaceId(); + wm->setValue("race", playerRaceId); if (!playerRaceId.empty()) - wm->getMechanicsManager()->setPlayerRace(playerRaceId, raceDialog->getGender() == RaceDialog::GM_Male); + environment->mMechanicsManager->setPlayerRace(playerRaceId, raceDialog->getGender() == RaceDialog::GM_Male); wm->removeDialog(raceDialog); } @@ -196,6 +298,225 @@ void CharacterCreation::onRaceDialogDone(WindowBase* parWindow) } } +void CharacterCreation::onBirthSignDialogDone(WindowBase* parWindow) +{ + if (birthSignDialog) + { + playerBirthSignId = birthSignDialog->getBirthId(); + wm->setBirthSign(playerBirthSignId); + if (!playerBirthSignId.empty()) + environment->mMechanicsManager->setPlayerBirthsign(playerBirthSignId); + wm->removeDialog(birthSignDialog); + } + + if (creationStage >= BirthSignChosen) + wm->setGuiMode(GM_Review); + else + { + creationStage = BirthSignChosen; + wm->setGuiMode(GM_Game); + } +} + +void CharacterCreation::onBirthSignDialogBack() +{ + if (birthSignDialog) + { + environment->mMechanicsManager->setPlayerBirthsign(birthSignDialog->getBirthId()); + wm->removeDialog(birthSignDialog); + } + + wm->setGuiMode(GM_Class); +} + +void CharacterCreation::onCreateClassDialogDone(WindowBase* parWindow) +{ + if (createClassDialog) + { + ESM::Class klass; + klass.name = createClassDialog->getName(); + klass.description = createClassDialog->getDescription(); + klass.data.specialization = createClassDialog->getSpecializationId(); + klass.data.isPlayable = 0x1; + + std::vector attributes = createClassDialog->getFavoriteAttributes(); + assert(attributes.size() == 2); + klass.data.attribute[0] = attributes[0]; + klass.data.attribute[1] = attributes[1]; + + std::vector majorSkills = createClassDialog->getMajorSkills(); + std::vector minorSkills = createClassDialog->getMinorSkills(); + assert(majorSkills.size() >= sizeof(klass.data.skills)/sizeof(klass.data.skills[0])); + assert(minorSkills.size() >= sizeof(klass.data.skills)/sizeof(klass.data.skills[0])); + for (size_t i = 0; i < sizeof(klass.data.skills)/sizeof(klass.data.skills[0]); ++i) + { + klass.data.skills[i][1] = majorSkills[i]; + klass.data.skills[i][0] = minorSkills[i]; + } + environment->mMechanicsManager->setPlayerClass(klass); + playerClass = klass; + wm->setPlayerClass(klass); + + wm->removeDialog(createClassDialog); + } + + if (creationStage == ReviewNext) + wm->setGuiMode(GM_Review); + else if (creationStage >= ClassChosen) + wm->setGuiMode(GM_Birth); + else + { + creationStage = ClassChosen; + wm->setGuiMode(GM_Game); + } +} + +void CharacterCreation::onCreateClassDialogBack() +{ + if (createClassDialog) + wm->removeDialog(createClassDialog); + + wm->setGuiMode(GM_Class); +} + +void CharacterCreation::onClassQuestionChosen(int _index) +{ + if (generateClassQuestionDialog) + wm->removeDialog(generateClassQuestionDialog); + if (_index < 0 || _index >= 3) + { + wm->setGuiMode(GM_Class); + return; + } + + ESM::Class::Specialization specialization = generateClassSteps[generateClassStep].specializations[_index]; + if (specialization == ESM::Class::Stealth) + ++generateClassSpecializations[0]; + else if (specialization == ESM::Class::Combat) + ++generateClassSpecializations[1]; + else if (specialization == ESM::Class::Magic) + ++generateClassSpecializations[2]; + ++generateClassStep; + showClassQuestionDialog(); +} + +void CharacterCreation::showClassQuestionDialog() +{ + if (generateClassStep == generateClassSteps.size()) + { + static boost::array classes = { { + {"Acrobat", {6, 2, 2}}, + {"Agent", {6, 1, 3}}, + {"Archer", {3, 5, 2}}, + {"Archer", {5, 5, 0}}, + {"Assassin", {6, 3, 1}}, + {"Barbarian", {3, 6, 1}}, + {"Bard", {3, 3, 3}}, + {"Battlemage", {1, 3, 6}}, + {"Crusader", {1, 6, 3}}, + {"Healer", {3, 1, 6}}, + {"Knight", {2, 6, 2}}, + {"Monk", {5, 3, 2}}, + {"Nightblade", {4, 2, 4}}, + {"Pilgrim", {5, 2, 3}}, + {"Rogue", {3, 4, 3}}, + {"Rogue", {4, 4, 2}}, + {"Rogue", {5, 4, 1}}, + {"Scout", {2, 5, 3}}, + {"Sorcerer", {2, 2, 6}}, + {"Spellsword", {2, 4, 4}}, + {"Spellsword", {5, 1, 4}}, + {"Witchhunter", {2, 3, 5}}, + {"Witchhunter", {5, 0, 5}} + } }; + + int match = -1; + for (unsigned i = 0; i < classes.size(); ++i) + { + if (generateClassSpecializations[0] == classes[i].points[0] && + generateClassSpecializations[1] == classes[i].points[1] && + generateClassSpecializations[2] == classes[i].points[2]) + { + match = i; + generateClass = classes[i].id; + break; + } + } + + if (match == -1) + { + if (generateClassSpecializations[0] >= 7) + generateClass = "Thief"; + else if (generateClassSpecializations[1] >= 7) + generateClass = "Warrior"; + else if (generateClassSpecializations[2] >= 7) + generateClass = "Mage"; + else + { + std::cerr << "Failed to deduce class from chosen answers in generate class dialog" << std::endl; + generateClass = "Thief"; + } + } + + if (generateClassResultDialog) + wm->removeDialog(generateClassResultDialog); + generateClassResultDialog = new GenerateClassResultDialog(*wm); + generateClassResultDialog->setClassId(generateClass); + generateClassResultDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onGenerateClassBack); + generateClassResultDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onGenerateClassDone); + generateClassResultDialog->open(); + return; + } + + if (generateClassStep > generateClassSteps.size()) + { + wm->setGuiMode(GM_Class); + return; + } + + if (generateClassQuestionDialog) + wm->removeDialog(generateClassQuestionDialog); + generateClassQuestionDialog = new InfoBoxDialog(*wm); + + InfoBoxDialog::ButtonList buttons; + generateClassQuestionDialog->setText(generateClassSteps[generateClassStep].text); + buttons.push_back(generateClassSteps[generateClassStep].buttons[0]); + buttons.push_back(generateClassSteps[generateClassStep].buttons[1]); + buttons.push_back(generateClassSteps[generateClassStep].buttons[2]); + generateClassQuestionDialog->setButtons(buttons); + generateClassQuestionDialog->eventButtonSelected = MyGUI::newDelegate(this, &CharacterCreation::onClassQuestionChosen); + generateClassQuestionDialog->open(); +} + +void CharacterCreation::onGenerateClassBack() +{ + if(creationStage < ClassChosen) + creationStage = ClassChosen; + + if (generateClassResultDialog) + wm->removeDialog(generateClassResultDialog); + environment->mMechanicsManager->setPlayerClass(generateClass); + + wm->setGuiMode(GM_Class); +} + +void CharacterCreation::onGenerateClassDone(WindowBase* parWindow) +{ + if (generateClassResultDialog) + wm->removeDialog(generateClassResultDialog); + environment->mMechanicsManager->setPlayerClass(generateClass); + + if (creationStage == ReviewNext) + wm->setGuiMode(GM_Review); + else if (creationStage >= ClassChosen) + wm->setGuiMode(GM_Birth); + else + { + creationStage = ClassChosen; + wm->setGuiMode(GM_Game); + } +} + CharacterCreation::~CharacterCreation() { delete nameDialog; diff --git a/apps/openmw/mwgui/charactercreation.hpp b/apps/openmw/mwgui/charactercreation.hpp index b9ce884c7..23111b126 100644 --- a/apps/openmw/mwgui/charactercreation.hpp +++ b/apps/openmw/mwgui/charactercreation.hpp @@ -4,6 +4,7 @@ #include "window_manager.hpp" #include "../mwmechanics/mechanicsmanager.hpp" +#include "../mwmechanics/stat.hpp" #include "../mwworld/world.hpp" #include @@ -27,7 +28,9 @@ namespace MWGui class CharacterCreation { public: - CharacterCreation(WindowManager* _wm); + typedef std::vector SkillList; + + CharacterCreation(WindowManager* _wm, MWWorld::Environment* _environment); ~CharacterCreation(); //Show a dialog @@ -35,6 +38,7 @@ namespace MWGui private: WindowManager* wm; + MWWorld::Environment* environment; //Dialogs TextInputDialog *nameDialog; @@ -51,7 +55,16 @@ namespace MWGui //Player data std::string playerName; std::string playerRaceId; + std::string playerBirthSignId; ESM::Class playerClass; + std::map > playerAttributes; + SkillList playerMajorSkills, playerMinorSkills; + std::map > playerSkillValues; + + //Class generation vars + unsigned generateClassStep; // Keeps track of current step in Generate Class dialog + unsigned generateClassSpecializations[3]; // A counter for each specialization which is increased when an answer is chosen + std::string generateClass; // In order: Stealth, Combat, Magic ////Dialog events //Name dialog @@ -61,10 +74,25 @@ namespace MWGui void onRaceDialogDone(WindowBase* parWindow); void onRaceDialogBack(); - //Class dialog(s) + //Class dialogs void onClassChoice(int _index); void onPickClassDialogDone(WindowBase* parWindow); void onPickClassDialogBack(); + void onCreateClassDialogDone(WindowBase* parWindow); + void onCreateClassDialogBack(); + void showClassQuestionDialog(); + void onClassQuestionChosen(int _index); + void onGenerateClassBack(); + void onGenerateClassDone(WindowBase* parWindow); + + //Birthsign dialog + void onBirthSignDialogDone(WindowBase* parWindow); + void onBirthSignDialogBack(); + + //Review dialog + void onReviewDialogDone(WindowBase* parWindow); + void onReviewDialogBack(); + void onReviewActivateDialog(int parDialog); enum CreationStageEnum { @@ -76,9 +104,88 @@ namespace MWGui ReviewNext }; - // Which state the character creating is in, controls back/next/ok buttons - CreationStageEnum creationStage; - }; + CreationStageEnum creationStage; // Which state the character creating is in, controls back/next/ok buttons + }; + + struct Step + { + const char* text; + const char* buttons[3]; + ESM::Class::Specialization specializations[3]; // The specialization for each answer + }; + + static boost::array generateClassSteps = { { + // Question 1 + {"On a clear day you chance upon a strange animal, its legs trapped in a hunter's clawsnare. Judging from the bleeding, it will not survive long.", + {"Draw your dagger, mercifully endings its life with a single thrust.", + "Use herbs from your pack to put it to sleep.", + "Do not interfere in the natural evolution of events, but rather take the opportunity to learn more about a strange animal that you have never seen before."}, + {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} + }, + // Question 2 + {"One Summer afternoon your father gives you a choice of chores.", + {"Work in the forge with him casting iron for a new plow.", + "Gather herbs for your mother who is preparing dinner.", + "Go catch fish at the stream using a net and line."}, + {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} + }, + // Question 3 + {"Your cousin has given you a very embarrassing nickname and, even worse, likes to call you it in front of your friends. You asked him to stop, but he finds it very amusing to watch you blush.", + {"Beat up your cousin, then tell him that if he ever calls you that nickname again, you will bloody him worse than this time.", + "Make up a story that makes your nickname a badge of honor instead of something humiliating.", + "Make up an even more embarrassing nickname for him and use it constantly until he learns his lesson."}, + {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} + }, + // Question 4 + {"There is a lot of heated discussion at the local tavern over a grouped of people called 'Telepaths'. They have been hired by certain City-State kings. Rumor has it these Telepaths read a person's mind and tell their lord whether a follower is telling the truth or not.", + {"This is a terrible practice. A person's thoughts are his own and no one, not even a king, has the right to make such an invasion into another human's mind.", + "Loyal followers to the king have nothing to fear from a Telepath. It is important to have a method of finding assassins and spies before it is too late.", + "In these times, it is a necessary evil. Although you do not necessarily like the idea, a Telepath could have certain advantages during a time of war or in finding someone innocent of a crime."}, + {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} + }, + // Question 5 + {"Your mother sends you to the market with a list of goods to buy. After you finish you find that by mistake a shopkeeper has given you too much money back in exchange for one of the items.", + {"Return to the store and give the shopkeeper his hard-earned money, explaining to him the mistake?", + "Decide to put the extra money to good use and purchase items that would help your family?", + "Pocket the extra money, knowing that shopkeepers in general tend to overcharge customers anyway?"}, + {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} + }, + // Question 6 + {"While in the market place you witness a thief cut a purse from a noble. Even as he does so, the noble notices and calls for the city guards. In his haste to get away, the thief drops the purse near you. Surprisingly no one seems to notice the bag of coins at your feet.", + {"Pick up the bag and signal to the guard, knowing that the only honorable thing to do is return the money to its rightful owner.", + "Leave the bag there, knowing that it is better not to get involved.", + "Pick up the bag and pocket it, knowing that the extra windfall will help your family in times of trouble."}, + {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} + }, + // Question 7 + {"Your father sends you on a task which you loathe, cleaning the stables. On the way there, pitchfork in hand, you run into your friend from the homestead near your own. He offers to do it for you, in return for a future favor of his choosing.", + {"Decline his offer, knowing that your father expects you to do the work, and it is better not to be in debt.", + "Ask him to help you, knowing that two people can do the job faster than one, and agree to help him with one task of his choosing in the future.", + "Accept his offer, reasoning that as long as the stables are cleaned, it matters not who does the cleaning."}, + {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} + }, + // Question 8 + {"Your mother asks you to help fix the stove. While you are working, a very hot pipe slips its mooring and falls towards her.", + {"Position yourself between the pipe and your mother.", + "Grab the hot pipe and try to push it away.", + "Push your mother out of the way."}, + {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} + }, + // Question 9 + {"While in town the baker gives you a sweetroll. Delighted, you take it into an alley to enjoy only to be intercepted by a gang of three other kids your age. The leader demands the sweetroll, or else he and his friends will beat you and take it.", + {"Drop the sweetroll and step on it, then get ready for the fight.", + "Give him the sweetroll now without argument, knowing that later this afternoon you will have all your friends with you and can come and take whatever he owes you.", + "Act like you're going to give him the sweetroll, but at the last minute throw it in the air, hoping that they'll pay attention to it long enough for you to get a shot in on the leader."}, + {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} + }, + // Question 10 + {"Entering town you find that you are witness to a very well-dressed man running from a crowd. He screams to you for help. The crowd behind him seem very angry.", + {"Rush to the town's aid immediately, despite your lack of knowledge of the circumstances.", + "Stand aside and allow the man and the mob to pass, realizing it is probably best not to get involved.", + "Rush to the man's aid immediately, despite your lack of knowledge of the circumstances."}, + {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} + } + } }; } #endif diff --git a/apps/openmw/mwgui/mode.hpp b/apps/openmw/mwgui/mode.hpp index 34264568a..55f0952ce 100644 --- a/apps/openmw/mwgui/mode.hpp +++ b/apps/openmw/mwgui/mode.hpp @@ -45,15 +45,6 @@ namespace MWGui GW_ALL = 0xFF }; - - // Character creation dialogs - enum CharGen - { - GEN_Name, - GEN_Race, - GEN_Class, - GEN_Sign - }; } #endif diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 728f414ba..e6e920b6e 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -1,8 +1,6 @@ #include "window_manager.hpp" #include "layouts.hpp" #include "text_input.hpp" -#include "class.hpp" -#include "birth.hpp" #include "review.hpp" #include "dialogue.hpp" #include "dialogue_history.hpp" @@ -26,12 +24,6 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment const Compiler::Extensions& extensions, int fpsLevel, bool newGame) : environment(environment) , dialogueWindow(nullptr) - , classChoiceDialog(nullptr) - , generateClassQuestionDialog(nullptr) - , generateClassResultDialog(nullptr) - , createClassDialog(nullptr) - , birthSignDialog(nullptr) - , reviewDialog(nullptr) , gui(_gui) , mode(GM_Game) , nextMode(GM_Game) @@ -41,9 +33,6 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment { showFPSLevel = fpsLevel; - /// REMOVE - creationStage = NotStarted; - //Register own widgets with MyGUI MyGUI::FactoryManager::getInstance().registerFactory("Widget"); @@ -56,9 +45,6 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment menu = new MainMenu(w,h); map = new MapWindow(); stats = new StatsWindow(*this); -#if 0 - inventory = new InventoryWindow (); -#endif console = new Console(w,h, environment, extensions); mJournal = new JournalWindow(*this); mMessageBoxManager = new MessageBoxManager(this); @@ -66,7 +52,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment // The HUD is always on hud->setVisible(true); - mCharGen = new CharacterCreation(this); + mCharGen = new CharacterCreation(this, &environment); // Setup player stats for (int i = 0; i < ESM::Attribute::Length; ++i) @@ -98,17 +84,9 @@ WindowManager::~WindowManager() delete menu; delete stats; delete mJournal; -#if 0 - delete inventory; -#endif - delete dialogueWindow; - delete classChoiceDialog; - delete generateClassQuestionDialog; - delete generateClassResultDialog; - delete createClassDialog; - delete birthSignDialog; - delete reviewDialog; + + delete mCharGen; cleanupGarbage(); } @@ -126,11 +104,6 @@ void WindowManager::cleanupGarbage() } } -MWMechanics::MechanicsManager* WindowManager::getMechanicsManager() -{ - return environment.mMechanicsManager; -} - void WindowManager::update() { cleanupGarbage(); @@ -170,9 +143,6 @@ void WindowManager::updateVisible() map->setVisible(false); menu->setVisible(false); stats->setVisible(false); -#if 0 - inventory->setVisible(false); -#endif console->disable(); mJournal->setVisible(false); @@ -198,100 +168,10 @@ void WindowManager::updateVisible() return; } - if (mode == GM_Name) //Combine this with all char-gen related if statements - { - mCharGen->spawnDialog(GM_Name); - return; - } - - if (mode == GM_Race) //Combine this with all char-gen related if statements - { - mCharGen->spawnDialog(GM_Race); - return; - } - - if (mode == GM_Class) - { - mCharGen->spawnDialog(GM_Class); - return; - } - - if (mode == GM_ClassGenerate) + //There must be a more elegant solution + if (mode == GM_Name || mode == GM_Race || mode == GM_Class || mode == GM_ClassPick || mode == GM_ClassCreate || mode == GM_Birth || mode == GM_ClassGenerate || mode == GM_Review) { - generateClassStep = 0; - generateClass = ""; - generateClassSpecializations[0] = 0; - generateClassSpecializations[1] = 0; - generateClassSpecializations[2] = 0; - showClassQuestionDialog(); - return; - } - - if (mode == GM_ClassPick) - { - mCharGen->spawnDialog(GM_ClassPick); - return; - } - - if (mode == GM_ClassCreate) - { - if (createClassDialog) - removeDialog(createClassDialog); - createClassDialog = new CreateClassDialog(*this); - createClassDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onCreateClassDialogDone); - createClassDialog->eventBack = MyGUI::newDelegate(this, &WindowManager::onCreateClassDialogBack); - createClassDialog->open(); - return; - } - - if (mode == GM_Birth) - { - if (birthSignDialog) - removeDialog(birthSignDialog); - birthSignDialog = new BirthDialog(*this); - birthSignDialog->setNextButtonShow(creationStage >= BirthSignChosen); - birthSignDialog->setBirthId(playerBirthSignId); - birthSignDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onBirthSignDialogDone); - birthSignDialog->eventBack = MyGUI::newDelegate(this, &WindowManager::onBirthSignDialogBack); - birthSignDialog->open(); - return; - } - - if (mode == GM_Review) - { - if (reviewDialog) - removeDialog(reviewDialog); - reviewDialog = new ReviewDialog(*this); - //reviewDialog->setPlayerName(playerName); //Move this to Chargen as part of refactoring - reviewDialog->setRace(playerRaceId); - reviewDialog->setClass(playerClass); - reviewDialog->setBirthSign(playerBirthSignId); - - reviewDialog->setHealth(playerHealth); - reviewDialog->setMagicka(playerMagicka); - reviewDialog->setFatigue(playerFatigue); - - { - std::map >::iterator end = playerAttributes.end(); - for (std::map >::iterator it = playerAttributes.begin(); it != end; ++it) - { - reviewDialog->setAttribute(it->first, it->second); - } - } - - { - std::map >::iterator end = playerSkillValues.end(); - for (std::map >::iterator it = playerSkillValues.begin(); it != end; ++it) - { - reviewDialog->setSkillValue(it->first, it->second); - } - reviewDialog->configureSkills(playerMajorSkills, playerMinorSkills); - } - - reviewDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onReviewDialogDone); - reviewDialog->eventBack = MyGUI::newDelegate(this, &WindowManager::onReviewDialogBack); - reviewDialog->eventActivateDialog = MyGUI::newDelegate(this, &WindowManager::onReviewActivateDialog); - reviewDialog->open(); + mCharGen->spawnDialog(mode); return; } @@ -306,9 +186,6 @@ void WindowManager::updateVisible() // Show the windows we want map -> setVisible( (eff & GW_Map) != 0 ); stats -> setVisible( (eff & GW_Stats) != 0 ); -#if 0 - // inventory -> setVisible( eff & GW_Inventory ); -#endif return; } @@ -338,7 +215,6 @@ void WindowManager::updateVisible() return; } - // 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. @@ -393,13 +269,23 @@ void WindowManager::setValue (const std::string& id, const MWMechanics::DynamicS playerFatigue = value; } +MWMechanics::DynamicStat WindowManager::getValue(const std::string& id) +{ + if(id == "HBar") + return playerHealth; + else if (id == "MBar") + return playerMagicka; + else if (id == "FBar") + return playerFatigue; +} + void WindowManager::setValue (const std::string& id, const std::string& value) { stats->setValue (id, value); - /*if (id=="name") + if (id=="name") playerName = value; else if (id=="race") - playerRaceId = value;*/ //Move this to chargen + playerRaceId = value; } void WindowManager::setValue (const std::string& id, int value) @@ -496,357 +382,6 @@ void WindowManager::onFrame (float frameDuration) mMessageBoxManager->onFrame(frameDuration); } -namespace MWGui -{ - - struct Step - { - const char* text; - const char* buttons[3]; - // The specialization for each answer - ESM::Class::Specialization specializations[3]; - }; - - static boost::array generateClassSteps = { { - // Question 1 - {"On a clear day you chance upon a strange animal, its legs trapped in a hunter's clawsnare. Judging from the bleeding, it will not survive long.", - {"Draw your dagger, mercifully endings its life with a single thrust.", - "Use herbs from your pack to put it to sleep.", - "Do not interfere in the natural evolution of events, but rather take the opportunity to learn more about a strange animal that you have never seen before."}, - {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} - }, - // Question 2 - {"One Summer afternoon your father gives you a choice of chores.", - {"Work in the forge with him casting iron for a new plow.", - "Gather herbs for your mother who is preparing dinner.", - "Go catch fish at the stream using a net and line."}, - {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} - }, - // Question 3 - {"Your cousin has given you a very embarrassing nickname and, even worse, likes to call you it in front of your friends. You asked him to stop, but he finds it very amusing to watch you blush.", - {"Beat up your cousin, then tell him that if he ever calls you that nickname again, you will bloody him worse than this time.", - "Make up a story that makes your nickname a badge of honor instead of something humiliating.", - "Make up an even more embarrassing nickname for him and use it constantly until he learns his lesson."}, - {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} - }, - // Question 4 - {"There is a lot of heated discussion at the local tavern over a grouped of people called 'Telepaths'. They have been hired by certain City-State kings. Rumor has it these Telepaths read a person's mind and tell their lord whether a follower is telling the truth or not.", - {"This is a terrible practice. A person's thoughts are his own and no one, not even a king, has the right to make such an invasion into another human's mind.", - "Loyal followers to the king have nothing to fear from a Telepath. It is important to have a method of finding assassins and spies before it is too late.", - "In these times, it is a necessary evil. Although you do not necessarily like the idea, a Telepath could have certain advantages during a time of war or in finding someone innocent of a crime."}, - {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} - }, - // Question 5 - {"Your mother sends you to the market with a list of goods to buy. After you finish you find that by mistake a shopkeeper has given you too much money back in exchange for one of the items.", - {"Return to the store and give the shopkeeper his hard-earned money, explaining to him the mistake?", - "Decide to put the extra money to good use and purchase items that would help your family?", - "Pocket the extra money, knowing that shopkeepers in general tend to overcharge customers anyway?"}, - {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} - }, - // Question 6 - {"While in the market place you witness a thief cut a purse from a noble. Even as he does so, the noble notices and calls for the city guards. In his haste to get away, the thief drops the purse near you. Surprisingly no one seems to notice the bag of coins at your feet.", - {"Pick up the bag and signal to the guard, knowing that the only honorable thing to do is return the money to its rightful owner.", - "Leave the bag there, knowing that it is better not to get involved.", - "Pick up the bag and pocket it, knowing that the extra windfall will help your family in times of trouble."}, - {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} - }, - // Question 7 - {"Your father sends you on a task which you loathe, cleaning the stables. On the way there, pitchfork in hand, you run into your friend from the homestead near your own. He offers to do it for you, in return for a future favor of his choosing.", - {"Decline his offer, knowing that your father expects you to do the work, and it is better not to be in debt.", - "Ask him to help you, knowing that two people can do the job faster than one, and agree to help him with one task of his choosing in the future.", - "Accept his offer, reasoning that as long as the stables are cleaned, it matters not who does the cleaning."}, - {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} - }, - // Question 8 - {"Your mother asks you to help fix the stove. While you are working, a very hot pipe slips its mooring and falls towards her.", - {"Position yourself between the pipe and your mother.", - "Grab the hot pipe and try to push it away.", - "Push your mother out of the way."}, - {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} - }, - // Question 9 - {"While in town the baker gives you a sweetroll. Delighted, you take it into an alley to enjoy only to be intercepted by a gang of three other kids your age. The leader demands the sweetroll, or else he and his friends will beat you and take it.", - {"Drop the sweetroll and step on it, then get ready for the fight.", - "Give him the sweetroll now without argument, knowing that later this afternoon you will have all your friends with you and can come and take whatever he owes you.", - "Act like you're going to give him the sweetroll, but at the last minute throw it in the air, hoping that they'll pay attention to it long enough for you to get a shot in on the leader."}, - {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} - }, - // Question 10 - {"Entering town you find that you are witness to a very well-dressed man running from a crowd. He screams to you for help. The crowd behind him seem very angry.", - {"Rush to the town's aid immediately, despite your lack of knowledge of the circumstances.", - "Stand aside and allow the man and the mob to pass, realizing it is probably best not to get involved.", - "Rush to the man's aid immediately, despite your lack of knowledge of the circumstances."}, - {ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth} - } - } }; -} - -void WindowManager::showClassQuestionDialog() -{ - if (generateClassStep == generateClassSteps.size()) - { - - static boost::array classes = { { - {"Acrobat", {6, 2, 2}}, - {"Agent", {6, 1, 3}}, - {"Archer", {3, 5, 2}}, - {"Archer", {5, 5, 0}}, - {"Assassin", {6, 3, 1}}, - {"Barbarian", {3, 6, 1}}, - {"Bard", {3, 3, 3}}, - {"Battlemage", {1, 3, 6}}, - {"Crusader", {1, 6, 3}}, - {"Healer", {3, 1, 6}}, - {"Knight", {2, 6, 2}}, - {"Monk", {5, 3, 2}}, - {"Nightblade", {4, 2, 4}}, - {"Pilgrim", {5, 2, 3}}, - {"Rogue", {3, 4, 3}}, - {"Rogue", {4, 4, 2}}, - {"Rogue", {5, 4, 1}}, - {"Scout", {2, 5, 3}}, - {"Sorcerer", {2, 2, 6}}, - {"Spellsword", {2, 4, 4}}, - {"Spellsword", {5, 1, 4}}, - {"Witchhunter", {2, 3, 5}}, - {"Witchhunter", {5, 0, 5}} - } }; - - int match = -1; - for (unsigned i = 0; i < classes.size(); ++i) - { - if (generateClassSpecializations[0] == classes[i].points[0] && - generateClassSpecializations[1] == classes[i].points[1] && - generateClassSpecializations[2] == classes[i].points[2]) - { - match = i; - generateClass = classes[i].id; - break; - } - } - - if (match == -1) - { - if (generateClassSpecializations[0] >= 7) - generateClass = "Thief"; - else if (generateClassSpecializations[1] >= 7) - generateClass = "Warrior"; - else if (generateClassSpecializations[2] >= 7) - generateClass = "Mage"; - else - { - std::cerr - << "Failed to deduce class from chosen answers in generate class dialog" - << std::endl; - generateClass = "Thief"; - } - } - - if (generateClassResultDialog) - removeDialog(generateClassResultDialog); - generateClassResultDialog = new GenerateClassResultDialog(*this); - generateClassResultDialog->setClassId(generateClass); - generateClassResultDialog->eventBack = MyGUI::newDelegate(this, &WindowManager::onGenerateClassBack); - generateClassResultDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onGenerateClassDone); - generateClassResultDialog->open(); - return; - } - - if (generateClassStep > generateClassSteps.size()) - { - setGuiMode(GM_Class); - return; - } - - if (generateClassQuestionDialog) - removeDialog(generateClassQuestionDialog); - generateClassQuestionDialog = new InfoBoxDialog(*this); - - InfoBoxDialog::ButtonList buttons; - generateClassQuestionDialog->setText(generateClassSteps[generateClassStep].text); - buttons.push_back(generateClassSteps[generateClassStep].buttons[0]); - buttons.push_back(generateClassSteps[generateClassStep].buttons[1]); - buttons.push_back(generateClassSteps[generateClassStep].buttons[2]); - generateClassQuestionDialog->setButtons(buttons); - generateClassQuestionDialog->eventButtonSelected = MyGUI::newDelegate(this, &WindowManager::onClassQuestionChosen); - generateClassQuestionDialog->open(); -} - -void WindowManager::onClassQuestionChosen(int _index) -{ - if (generateClassQuestionDialog) - removeDialog(generateClassQuestionDialog); - if (_index < 0 || _index >= 3) - { - setGuiMode(GM_Class); - return; - } - - ESM::Class::Specialization specialization = generateClassSteps[generateClassStep].specializations[_index]; - if (specialization == ESM::Class::Stealth) - ++generateClassSpecializations[0]; - else if (specialization == ESM::Class::Combat) - ++generateClassSpecializations[1]; - else if (specialization == ESM::Class::Magic) - ++generateClassSpecializations[2]; - ++generateClassStep; - showClassQuestionDialog(); -} - -void WindowManager::onGenerateClassBack() -{ - if(creationStage < ClassChosen) - creationStage = ClassChosen; - - if (generateClassResultDialog) - removeDialog(generateClassResultDialog); - environment.mMechanicsManager->setPlayerClass(generateClass); - - setGuiMode(GM_Class); -} - -void WindowManager::onGenerateClassDone(WindowBase* parWindow) -{ - if (generateClassResultDialog) - removeDialog(generateClassResultDialog); - environment.mMechanicsManager->setPlayerClass(generateClass); - - // Go to next dialog if class was previously chosen - if (creationStage == ReviewNext) - setGuiMode(GM_Review); - else if (creationStage >= ClassChosen) - setGuiMode(GM_Birth); - else - { - creationStage = ClassChosen; - setGuiMode(GM_Game); - } -} - -MWWorld::World* WindowManager::getWorld() -{ - return environment.mWorld; -} - -void WindowManager::onCreateClassDialogDone(WindowBase* parWindow) -{ - if (createClassDialog) - { - ESM::Class klass; - klass.name = createClassDialog->getName(); - klass.description = createClassDialog->getDescription(); - klass.data.specialization = createClassDialog->getSpecializationId(); - klass.data.isPlayable = 0x1; - - std::vector attributes = createClassDialog->getFavoriteAttributes(); - assert(attributes.size() == 2); - klass.data.attribute[0] = attributes[0]; - klass.data.attribute[1] = attributes[1]; - - std::vector majorSkills = createClassDialog->getMajorSkills(); - std::vector minorSkills = createClassDialog->getMinorSkills(); - assert(majorSkills.size() >= sizeof(klass.data.skills)/sizeof(klass.data.skills[0])); - assert(minorSkills.size() >= sizeof(klass.data.skills)/sizeof(klass.data.skills[0])); - for (size_t i = 0; i < sizeof(klass.data.skills)/sizeof(klass.data.skills[0]); ++i) - { - klass.data.skills[i][1] = majorSkills[i]; - klass.data.skills[i][0] = minorSkills[i]; - } - environment.mMechanicsManager->setPlayerClass(klass); - playerClass = klass; - - removeDialog(createClassDialog); - } - - // Go to next dialog if class was previously chosen - if (creationStage == ReviewNext) - setGuiMode(GM_Review); - else if (creationStage >= ClassChosen) - setGuiMode(GM_Birth); - else - { - creationStage = ClassChosen; - setGuiMode(GM_Game); - } -} - -void WindowManager::onCreateClassDialogBack() -{ - if (createClassDialog) - removeDialog(createClassDialog); - - setGuiMode(GM_Class); -} - -void WindowManager::onBirthSignDialogDone(WindowBase* parWindow) -{ - if (birthSignDialog) - { - playerBirthSignId = birthSignDialog->getBirthId(); - if (!playerBirthSignId.empty()) - environment.mMechanicsManager->setPlayerBirthsign(playerBirthSignId); - removeDialog(birthSignDialog); - } - - // Go to next dialog if birth sign was previously chosen - if (creationStage >= BirthSignChosen) - setGuiMode(GM_Review); - else - { - creationStage = BirthSignChosen; - setGuiMode(GM_Game); - } -} - -void WindowManager::onBirthSignDialogBack() -{ - if (birthSignDialog) - { - environment.mMechanicsManager->setPlayerBirthsign(birthSignDialog->getBirthId()); - removeDialog(birthSignDialog); - } - - setGuiMode(GM_Class); -} - -void WindowManager::onReviewDialogDone(WindowBase* parWindow) -{ - if (reviewDialog) - removeDialog(reviewDialog); - - setGuiMode(GM_Game); -} - -void WindowManager::onReviewDialogBack() -{ - if (reviewDialog) - removeDialog(reviewDialog); - - setGuiMode(GM_Birth); -} - -void WindowManager::onReviewActivateDialog(int parDialog) -{ - if (reviewDialog) - removeDialog(reviewDialog); - creationStage = ReviewNext; - - switch(parDialog) - { - case ReviewDialog::NAME_DIALOG: - setGuiMode(GM_Name); - break; - case ReviewDialog::RACE_DIALOG: - setGuiMode(GM_Race); - break; - case ReviewDialog::CLASS_DIALOG: - setGuiMode(GM_Class); - break; - case ReviewDialog::BIRTHSIGN_DIALOG: - setGuiMode(GM_Birth); - }; -} - const ESMS::ESMStore& WindowManager::getStore() const { return environment.mWorld->getStore(); diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 6af14d28e..83a56a7b3 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -8,7 +8,7 @@ MyGUI should be initialized separately before creating instances of this class. - */ +**/ #include #include @@ -63,11 +63,6 @@ namespace MWGui class TextInputDialog; class InfoBoxDialog; class DialogueWindow; - class ClassChoiceDialog; - class GenerateClassResultDialog; - class CreateClassDialog; - class BirthDialog; - class ReviewDialog; class MessageBoxManager; struct ClassPoint @@ -92,59 +87,32 @@ namespace MWGui MainMenu *menu; StatsWindow *stats; MessageBoxManager *mMessageBoxManager; -#if 0 - InventoryWindow *inventory; -#endif Console *console; JournalWindow* mJournal; - - // Character creation + DialogueWindow *dialogueWindow; + CharacterCreation* mCharGen; - DialogueWindow *dialogueWindow; - ClassChoiceDialog *classChoiceDialog; - InfoBoxDialog *generateClassQuestionDialog; - GenerateClassResultDialog *generateClassResultDialog; - CreateClassDialog *createClassDialog; - BirthDialog *birthSignDialog; - ReviewDialog *reviewDialog; - - // Keeps track of current step in Generate Class dialogs - unsigned generateClassStep; - // A counter for each specialization which is increased when an answer is chosen, in order: Stealth, Combat, Magic - unsigned generateClassSpecializations[3]; - std::string generateClass; - // Various stats about player as needed by window manager ESM::Class playerClass; - std::string playerRaceId; ///REMOVE + std::string playerName; + std::string playerRaceId; std::string playerBirthSignId; std::map > playerAttributes; SkillList playerMajorSkills, playerMinorSkills; std::map > playerSkillValues; MWMechanics::DynamicStat playerHealth, playerMagicka, playerFatigue; - // Gui - MyGUI::Gui *gui; - - // Current gui mode - GuiMode mode; - - /** - * Next mode to activate in update(). - */ - GuiMode nextMode; - /** - * Whether a mode change is needed in update(). - * Will use @a nextMode as the new mode. - */ - bool needModeChange; + + MyGUI::Gui *gui; // Gui + GuiMode mode; // Current gui mode + GuiMode nextMode; // Next mode to activate in update() + bool needModeChange; //Whether a mode change is needed in update() [will use nextMode] std::vector garbageDialogs; void cleanupGarbage(); - // Currently shown windows in inventory mode - GuiWindow shown; + GuiWindow shown; // Currently shown windows in inventory mode /* Currently ALLOWED windows in inventory mode. This is used at the start of the game, when windows are enabled one by one @@ -156,9 +124,7 @@ namespace MWGui */ GuiWindow allowed; - // Update visibility of all windows based on mode, shown and - // allowed settings. - void updateVisible(); + void updateVisible(); // Update visibility of all windows based on mode, shown and allowed settings int showFPSLevel; float mFPS; @@ -166,14 +132,10 @@ namespace MWGui size_t mBatchCount; public: - /// The constructor needs the main Gui object - WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment, - const Compiler::Extensions& extensions, int fpsLevel, bool newGame); + WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment, const Compiler::Extensions& extensions, int fpsLevel, bool newGame); virtual ~WindowManager(); void setGuiMode(GuiMode newMode); - MWMechanics::MechanicsManager* getMechanicsManager(); - MWWorld::World* getWorld(); /** * Should be called each frame to update windows/gui elements. @@ -196,8 +158,7 @@ namespace MWGui GuiMode getMode() const { return mode; } - // Everything that is not game mode is considered "gui mode" - bool isGuiMode() const { return getMode() != GM_Game; } + bool isGuiMode() const { return getMode() != GM_Game; } // Everything that is not game mode is considered "gui mode" // Disallow all inventory mode windows void disallowAll() @@ -222,53 +183,30 @@ namespace MWGui mBatchCount = batchCount; } - void setValue (const std::string& id, const MWMechanics::Stat& value); - ///< Set value for the given ID. + MWMechanics::DynamicStat getValue(const std::string& id); - void setValue(const ESM::Skill::SkillEnum parSkill, const MWMechanics::Stat& value); ///< Set value for the given ID. - + void setValue (const std::string& id, const MWMechanics::Stat& value); + void setValue(const ESM::Skill::SkillEnum parSkill, const MWMechanics::Stat& value); 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 setValue (const std::string& id, int value); - ///< set value for the given ID. - - void setPlayerClass (const ESM::Class &class_); - ///< set current class of player - - void configureSkills (const SkillList& major, const SkillList& minor); - ///< configure skill groups, each set contains the skill ID for that group. - - void setFactions (const FactionList& factions); - ///< set faction and rank to display on stat window, use an empty vector to disable - void setBirthSign (const std::string &signId); - ///< set birth sign to display on stat window, use an empty string to disable. - - void setReputation (int reputation); - ///< set the current reputation value - - void setBounty (int bounty); - ///< set the current bounty value - - void updateSkillArea(); - ///< update display of skills, factions, birth sign, reputation and bounty + void setPlayerClass (const ESM::Class &class_); ///< set current class of player + void configureSkills (const SkillList& major, const SkillList& minor); ///< configure skill groups, each set contains the skill ID for that group. + void setFactions (const FactionList& factions); ///< set faction and rank to display on stat window, use an empty vector to disable + void setBirthSign (const std::string &signId); ///< set birth sign to display on stat window, use an empty string to disable. + void setReputation (int reputation); ///< set the current reputation value + void setBounty (int bounty); ///< set the current bounty value + void updateSkillArea(); ///< update display of skills, factions, birth sign, reputation and bounty + template - void removeDialog(T*& dialog); - ///< Casts to OEngine::GUI::Layout and calls removeDialog, then resets pointer to nullptr. - - void removeDialog(OEngine::GUI::Layout* dialog); - ///< Hides dialog and schedules dialog to be deleted. + void removeDialog(T*& dialog); ///< Casts to OEngine::GUI::Layout and calls removeDialog, then resets pointer to nullptr. + void removeDialog(OEngine::GUI::Layout* dialog); ///< Hides dialog and schedules dialog to be deleted. void messageBox (const std::string& message, const std::vector& buttons); - - int readPressedButton (); - ///< returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox) + int readPressedButton (); ///< returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox) void onFrame (float frameDuration); @@ -286,40 +224,6 @@ namespace MWGui private: void onDialogueWindowBye(); - - // Character generation: Generate Class - void showClassQuestionDialog(); - void onClassQuestionChosen(int _index); - void onGenerateClassBack(); - void onGenerateClassDone(WindowBase* parWindow); - - // Character generation: Create Class dialog - void onCreateClassDialogDone(WindowBase* parWindow); - void onCreateClassDialogBack(); - - // Character generation: Birth sign dialog - void onBirthSignDialogDone(WindowBase* parWindow); - void onBirthSignDialogBack(); - - // Character generation: Review dialog - void onReviewDialogDone(WindowBase* parWindow); - void onReviewDialogBack(); - void onReviewActivateDialog(int parDialog); - - /// REMOVE - enum CreationStageEnum - { - NotStarted, - NameChosen, - RaceChosen, - ClassChosen, - BirthSignChosen, - ReviewNext - }; - - // Which state the character creating is in, controls back/next/ok buttons - CreationStageEnum creationStage; - /// /REMOVE }; template From 4bc7051741cb6b23249aa6134451251fa375e61d Mon Sep 17 00:00:00 2001 From: Cris Mihalache Date: Thu, 2 Feb 2012 18:31:28 +0200 Subject: [PATCH 4/4] Finished refactoring, brought CharacterCreation up to standards --- apps/openmw/mwgui/charactercreation.cpp | 497 ++++++++++++------------ apps/openmw/mwgui/charactercreation.hpp | 70 ++-- apps/openmw/mwgui/window_manager.hpp | 101 +++-- 3 files changed, 332 insertions(+), 336 deletions(-) diff --git a/apps/openmw/mwgui/charactercreation.cpp b/apps/openmw/mwgui/charactercreation.cpp index 86c7a6758..9fd6870b0 100644 --- a/apps/openmw/mwgui/charactercreation.cpp +++ b/apps/openmw/mwgui/charactercreation.cpp @@ -6,26 +6,25 @@ #include "birth.hpp" #include "review.hpp" #include "dialogue.hpp" - #include "mode.hpp" using namespace MWGui; CharacterCreation::CharacterCreation(WindowManager* _wm, MWWorld::Environment* _environment) - : nameDialog(0) - , raceDialog(0) - , dialogueWindow(0) - , classChoiceDialog(0) - , generateClassQuestionDialog(0) - , generateClassResultDialog(0) - , pickClassDialog(0) - , createClassDialog(0) - , birthSignDialog(0) - , reviewDialog(0) - , wm(_wm) - , environment(_environment) + : mNameDialog(0) + , mRaceDialog(0) + , mDialogueWindow(0) + , mClassChoiceDialog(0) + , mGenerateClassQuestionDialog(0) + , mGenerateClassResultDialog(0) + , mPickClassDialog(0) + , mCreateClassDialog(0) + , mBirthSignDialog(0) + , mReviewDialog(0) + , mWM(_wm) + , mEnvironment(_environment) { - creationStage = NotStarted; + mCreationStage = CSE_NotStarted; } void CharacterCreation::spawnDialog(const char id) @@ -33,210 +32,210 @@ void CharacterCreation::spawnDialog(const char id) switch (id) { case GM_Name: - if(nameDialog) - wm->removeDialog(nameDialog); - nameDialog = new TextInputDialog(*wm); - nameDialog->setTextLabel(wm->getGameSettingString("sName", "Name")); - nameDialog->setTextInput(playerName); - nameDialog->setNextButtonShow(creationStage >= NameChosen); - nameDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onNameDialogDone); - nameDialog->open(); + if(mNameDialog) + mWM->removeDialog(mNameDialog); + mNameDialog = new TextInputDialog(*mWM); + mNameDialog->setTextLabel(mWM->getGameSettingString("sName", "Name")); + mNameDialog->setTextInput(mPlayerName); + mNameDialog->setNextButtonShow(mCreationStage >= CSE_NameChosen); + mNameDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onNameDialogDone); + mNameDialog->open(); break; case GM_Race: - if (raceDialog) - wm->removeDialog(raceDialog); - raceDialog = new RaceDialog(*wm); - raceDialog->setNextButtonShow(creationStage >= RaceChosen); - raceDialog->setRaceId(playerRaceId); - raceDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onRaceDialogDone); - raceDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onRaceDialogBack); - raceDialog->open(); + if (mRaceDialog) + mWM->removeDialog(mRaceDialog); + mRaceDialog = new RaceDialog(*mWM); + mRaceDialog->setNextButtonShow(mCreationStage >= CSE_RaceChosen); + mRaceDialog->setRaceId(mPlayerRaceId); + mRaceDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onRaceDialogDone); + mRaceDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onRaceDialogBack); + mRaceDialog->open(); break; case GM_Class: - if (classChoiceDialog) - wm->removeDialog(classChoiceDialog); - classChoiceDialog = new ClassChoiceDialog(*wm); - classChoiceDialog->eventButtonSelected = MyGUI::newDelegate(this, &CharacterCreation::onClassChoice); - classChoiceDialog->open(); + if (mClassChoiceDialog) + mWM->removeDialog(mClassChoiceDialog); + mClassChoiceDialog = new ClassChoiceDialog(*mWM); + mClassChoiceDialog->eventButtonSelected = MyGUI::newDelegate(this, &CharacterCreation::onClassChoice); + mClassChoiceDialog->open(); break; case GM_ClassPick: - if (pickClassDialog) - wm->removeDialog(pickClassDialog); - pickClassDialog = new PickClassDialog(*wm); - pickClassDialog->setNextButtonShow(creationStage >= ClassChosen); - pickClassDialog->setClassId(playerClass.name); - pickClassDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onPickClassDialogDone); - pickClassDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onPickClassDialogBack); - pickClassDialog->open(); + if (mPickClassDialog) + mWM->removeDialog(mPickClassDialog); + mPickClassDialog = new PickClassDialog(*mWM); + mPickClassDialog->setNextButtonShow(mCreationStage >= CSE_ClassChosen); + mPickClassDialog->setClassId(mPlayerClass.name); + mPickClassDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onPickClassDialogDone); + mPickClassDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onPickClassDialogBack); + mPickClassDialog->open(); break; case GM_Birth: - if (birthSignDialog) - wm->removeDialog(birthSignDialog); - birthSignDialog = new BirthDialog(*wm); - birthSignDialog->setNextButtonShow(creationStage >= BirthSignChosen); - birthSignDialog->setBirthId(playerBirthSignId); - birthSignDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onBirthSignDialogDone); - birthSignDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onBirthSignDialogBack); - birthSignDialog->open(); + if (mBirthSignDialog) + mWM->removeDialog(mBirthSignDialog); + mBirthSignDialog = new BirthDialog(*mWM); + mBirthSignDialog->setNextButtonShow(mCreationStage >= CSE_BirthSignChosen); + mBirthSignDialog->setBirthId(mPlayerBirthSignId); + mBirthSignDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onBirthSignDialogDone); + mBirthSignDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onBirthSignDialogBack); + mBirthSignDialog->open(); break; case GM_ClassCreate: - if (createClassDialog) - wm->removeDialog(createClassDialog); - createClassDialog = new CreateClassDialog(*wm); - createClassDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onCreateClassDialogDone); - createClassDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onCreateClassDialogBack); - createClassDialog->open(); + if (mCreateClassDialog) + mWM->removeDialog(mCreateClassDialog); + mCreateClassDialog = new CreateClassDialog(*mWM); + mCreateClassDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onCreateClassDialogDone); + mCreateClassDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onCreateClassDialogBack); + mCreateClassDialog->open(); break; case GM_ClassGenerate: - generateClassStep = 0; - generateClass = ""; - generateClassSpecializations[0] = 0; - generateClassSpecializations[1] = 0; - generateClassSpecializations[2] = 0; + mGenerateClassStep = 0; + mGenerateClass = ""; + mGenerateClassSpecializations[0] = 0; + mGenerateClassSpecializations[1] = 0; + mGenerateClassSpecializations[2] = 0; showClassQuestionDialog(); break; case GM_Review: - if (reviewDialog) - wm->removeDialog(reviewDialog); - reviewDialog = new ReviewDialog(*wm); - reviewDialog->setPlayerName(playerName); - reviewDialog->setRace(playerRaceId); - reviewDialog->setClass(playerClass); - reviewDialog->setBirthSign(playerBirthSignId); - - reviewDialog->setHealth(wm->getValue("HBar")); - reviewDialog->setMagicka(wm->getValue("MBar")); - reviewDialog->setFatigue(wm->getValue("FBar")); + if (mReviewDialog) + mWM->removeDialog(mReviewDialog); + mReviewDialog = new ReviewDialog(*mWM); + mReviewDialog->setPlayerName(mPlayerName); + mReviewDialog->setRace(mPlayerRaceId); + mReviewDialog->setClass(mPlayerClass); + mReviewDialog->setBirthSign(mPlayerBirthSignId); + + mReviewDialog->setHealth(mWM->getValue("HBar")); + mReviewDialog->setMagicka(mWM->getValue("MBar")); + mReviewDialog->setFatigue(mWM->getValue("FBar")); { - std::map >::iterator end = playerAttributes.end(); - for (std::map >::iterator it = playerAttributes.begin(); it != end; ++it) + std::map >::iterator end = mPlayerAttributes.end(); + for (std::map >::iterator it = mPlayerAttributes.begin(); it != end; ++it) { - reviewDialog->setAttribute(it->first, it->second); + mReviewDialog->setAttribute(it->first, it->second); } } { - std::map >::iterator end = playerSkillValues.end(); - for (std::map >::iterator it = playerSkillValues.begin(); it != end; ++it) + std::map >::iterator end = mPlayerSkillValues.end(); + for (std::map >::iterator it = mPlayerSkillValues.begin(); it != end; ++it) { - reviewDialog->setSkillValue(it->first, it->second); + mReviewDialog->setSkillValue(it->first, it->second); } - reviewDialog->configureSkills(playerMajorSkills, playerMinorSkills); + mReviewDialog->configureSkills(mPlayerMajorSkills, mPlayerMinorSkills); } - reviewDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onReviewDialogDone); - reviewDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onReviewDialogBack); - reviewDialog->eventActivateDialog = MyGUI::newDelegate(this, &CharacterCreation::onReviewActivateDialog); - reviewDialog->open(); + mReviewDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onReviewDialogDone); + mReviewDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onReviewDialogBack); + mReviewDialog->eventActivateDialog = MyGUI::newDelegate(this, &CharacterCreation::onReviewActivateDialog); + mReviewDialog->open(); break; } } void CharacterCreation::onReviewDialogDone(WindowBase* parWindow) { - if (reviewDialog) - wm->removeDialog(reviewDialog); + if (mReviewDialog) + mWM->removeDialog(mReviewDialog); - wm->setGuiMode(GM_Game); + mWM->setGuiMode(GM_Game); } void CharacterCreation::onReviewDialogBack() { - if (reviewDialog) - wm->removeDialog(reviewDialog); + if (mReviewDialog) + mWM->removeDialog(mReviewDialog); - wm->setGuiMode(GM_Birth); + mWM->setGuiMode(GM_Birth); } void CharacterCreation::onReviewActivateDialog(int parDialog) { - if (reviewDialog) - wm->removeDialog(reviewDialog); - creationStage = ReviewNext; + if (mReviewDialog) + mWM->removeDialog(mReviewDialog); + mCreationStage = CSE_ReviewNext; switch(parDialog) { case ReviewDialog::NAME_DIALOG: - wm->setGuiMode(GM_Name); + mWM->setGuiMode(GM_Name); break; case ReviewDialog::RACE_DIALOG: - wm->setGuiMode(GM_Race); + mWM->setGuiMode(GM_Race); break; case ReviewDialog::CLASS_DIALOG: - wm->setGuiMode(GM_Class); + mWM->setGuiMode(GM_Class); break; case ReviewDialog::BIRTHSIGN_DIALOG: - wm->setGuiMode(GM_Birth); + mWM->setGuiMode(GM_Birth); }; } void CharacterCreation::onPickClassDialogDone(WindowBase* parWindow) { - if (pickClassDialog) + if (mPickClassDialog) { - const std::string &classId = pickClassDialog->getClassId(); + const std::string &classId = mPickClassDialog->getClassId(); if (!classId.empty()) - environment->mMechanicsManager->setPlayerClass(classId); - const ESM::Class *klass = environment->mWorld->getStore().classes.find(classId); + mEnvironment->mMechanicsManager->setPlayerClass(classId); + const ESM::Class *klass = mEnvironment->mWorld->getStore().classes.find(classId); if (klass) { - playerClass = *klass; - wm->setPlayerClass(playerClass); + mPlayerClass = *klass; + mWM->setPlayerClass(mPlayerClass); } - wm->removeDialog(pickClassDialog); + mWM->removeDialog(mPickClassDialog); } //TODO This bit gets repeated a few times; wrap it in a function - if (creationStage == ReviewNext) - wm->setGuiMode(GM_Review); - else if (creationStage >= ClassChosen) - wm->setGuiMode(GM_Birth); + if (mCreationStage == CSE_ReviewNext) + mWM->setGuiMode(GM_Review); + else if (mCreationStage >= CSE_ClassChosen) + mWM->setGuiMode(GM_Birth); else { - creationStage = ClassChosen; - wm->setGuiMode(GM_Game); + mCreationStage = CSE_ClassChosen; + mWM->setGuiMode(GM_Game); } } void CharacterCreation::onPickClassDialogBack() { - if (pickClassDialog) + if (mPickClassDialog) { - const std::string classId = pickClassDialog->getClassId(); + const std::string classId = mPickClassDialog->getClassId(); if (!classId.empty()) - environment->mMechanicsManager->setPlayerClass(classId); - wm->removeDialog(pickClassDialog); + mEnvironment->mMechanicsManager->setPlayerClass(classId); + mWM->removeDialog(mPickClassDialog); } - wm->setGuiMode(GM_Class); + mWM->setGuiMode(GM_Class); } void CharacterCreation::onClassChoice(int _index) { - if (classChoiceDialog) + if (mClassChoiceDialog) { - wm->removeDialog(classChoiceDialog); + mWM->removeDialog(mClassChoiceDialog); } switch(_index) { case ClassChoiceDialog::Class_Generate: - wm->setGuiMode(GM_ClassGenerate); + mWM->setGuiMode(GM_ClassGenerate); break; case ClassChoiceDialog::Class_Pick: - wm->setGuiMode(GM_ClassPick); + mWM->setGuiMode(GM_ClassPick); break; case ClassChoiceDialog::Class_Create: - wm->setGuiMode(GM_ClassCreate); + mWM->setGuiMode(GM_ClassCreate); break; case ClassChoiceDialog::Class_Back: - wm->setGuiMode(GM_Race); + mWM->setGuiMode(GM_Race); break; }; @@ -244,108 +243,108 @@ void CharacterCreation::onClassChoice(int _index) void CharacterCreation::onNameDialogDone(WindowBase* parWindow) { - if (nameDialog) + if (mNameDialog) { - playerName = nameDialog->getTextInput(); - wm->setValue("name", playerName); - environment->mMechanicsManager->setPlayerName(playerName); - wm->removeDialog(nameDialog); + mPlayerName = mNameDialog->getTextInput(); + mWM->setValue("name", mPlayerName); + mEnvironment->mMechanicsManager->setPlayerName(mPlayerName); + mWM->removeDialog(mNameDialog); } - if (creationStage == ReviewNext) - wm->setGuiMode(GM_Review); - else if (creationStage >= NameChosen) - wm->setGuiMode(GM_Race); + if (mCreationStage == CSE_ReviewNext) + mWM->setGuiMode(GM_Review); + else if (mCreationStage >= CSE_NameChosen) + mWM->setGuiMode(GM_Race); else { - creationStage = NameChosen; - wm->setGuiMode(GM_Game); + mCreationStage = CSE_NameChosen; + mWM->setGuiMode(GM_Game); } } void CharacterCreation::onRaceDialogBack() { - if (raceDialog) + if (mRaceDialog) { - playerRaceId = raceDialog->getRaceId(); - if (!playerRaceId.empty()) - environment->mMechanicsManager->setPlayerRace(playerRaceId, raceDialog->getGender() == RaceDialog::GM_Male); - wm->removeDialog(raceDialog); + mPlayerRaceId = mRaceDialog->getRaceId(); + if (!mPlayerRaceId.empty()) + mEnvironment->mMechanicsManager->setPlayerRace(mPlayerRaceId, mRaceDialog->getGender() == RaceDialog::GM_Male); + mWM->removeDialog(mRaceDialog); } - wm->setGuiMode(GM_Name); + mWM->setGuiMode(GM_Name); } void CharacterCreation::onRaceDialogDone(WindowBase* parWindow) { - if (raceDialog) + if (mRaceDialog) { - playerRaceId = raceDialog->getRaceId(); - wm->setValue("race", playerRaceId); - if (!playerRaceId.empty()) - environment->mMechanicsManager->setPlayerRace(playerRaceId, raceDialog->getGender() == RaceDialog::GM_Male); - wm->removeDialog(raceDialog); + mPlayerRaceId = mRaceDialog->getRaceId(); + mWM->setValue("race", mPlayerRaceId); + if (!mPlayerRaceId.empty()) + mEnvironment->mMechanicsManager->setPlayerRace(mPlayerRaceId, mRaceDialog->getGender() == RaceDialog::GM_Male); + mWM->removeDialog(mRaceDialog); } - if (creationStage == ReviewNext) - wm->setGuiMode(GM_Review); - else if(creationStage >= RaceChosen) - wm->setGuiMode(GM_Class); + if (mCreationStage == CSE_ReviewNext) + mWM->setGuiMode(GM_Review); + else if(mCreationStage >= CSE_RaceChosen) + mWM->setGuiMode(GM_Class); else { - creationStage = RaceChosen; - wm->setGuiMode(GM_Game); + mCreationStage = CSE_RaceChosen; + mWM->setGuiMode(GM_Game); } } void CharacterCreation::onBirthSignDialogDone(WindowBase* parWindow) { - if (birthSignDialog) + if (mBirthSignDialog) { - playerBirthSignId = birthSignDialog->getBirthId(); - wm->setBirthSign(playerBirthSignId); - if (!playerBirthSignId.empty()) - environment->mMechanicsManager->setPlayerBirthsign(playerBirthSignId); - wm->removeDialog(birthSignDialog); + mPlayerBirthSignId = mBirthSignDialog->getBirthId(); + mWM->setBirthSign(mPlayerBirthSignId); + if (!mPlayerBirthSignId.empty()) + mEnvironment->mMechanicsManager->setPlayerBirthsign(mPlayerBirthSignId); + mWM->removeDialog(mBirthSignDialog); } - if (creationStage >= BirthSignChosen) - wm->setGuiMode(GM_Review); + if (mCreationStage >= CSE_BirthSignChosen) + mWM->setGuiMode(GM_Review); else { - creationStage = BirthSignChosen; - wm->setGuiMode(GM_Game); + mCreationStage = CSE_BirthSignChosen; + mWM->setGuiMode(GM_Game); } } void CharacterCreation::onBirthSignDialogBack() { - if (birthSignDialog) + if (mBirthSignDialog) { - environment->mMechanicsManager->setPlayerBirthsign(birthSignDialog->getBirthId()); - wm->removeDialog(birthSignDialog); + mEnvironment->mMechanicsManager->setPlayerBirthsign(mBirthSignDialog->getBirthId()); + mWM->removeDialog(mBirthSignDialog); } - wm->setGuiMode(GM_Class); + mWM->setGuiMode(GM_Class); } void CharacterCreation::onCreateClassDialogDone(WindowBase* parWindow) { - if (createClassDialog) + if (mCreateClassDialog) { ESM::Class klass; - klass.name = createClassDialog->getName(); - klass.description = createClassDialog->getDescription(); - klass.data.specialization = createClassDialog->getSpecializationId(); + klass.name = mCreateClassDialog->getName(); + klass.description = mCreateClassDialog->getDescription(); + klass.data.specialization = mCreateClassDialog->getSpecializationId(); klass.data.isPlayable = 0x1; - std::vector attributes = createClassDialog->getFavoriteAttributes(); + std::vector attributes = mCreateClassDialog->getFavoriteAttributes(); assert(attributes.size() == 2); klass.data.attribute[0] = attributes[0]; klass.data.attribute[1] = attributes[1]; - std::vector majorSkills = createClassDialog->getMajorSkills(); - std::vector minorSkills = createClassDialog->getMinorSkills(); + std::vector majorSkills = mCreateClassDialog->getMajorSkills(); + std::vector minorSkills = mCreateClassDialog->getMinorSkills(); assert(majorSkills.size() >= sizeof(klass.data.skills)/sizeof(klass.data.skills[0])); assert(minorSkills.size() >= sizeof(klass.data.skills)/sizeof(klass.data.skills[0])); for (size_t i = 0; i < sizeof(klass.data.skills)/sizeof(klass.data.skills[0]); ++i) @@ -353,56 +352,56 @@ void CharacterCreation::onCreateClassDialogDone(WindowBase* parWindow) klass.data.skills[i][1] = majorSkills[i]; klass.data.skills[i][0] = minorSkills[i]; } - environment->mMechanicsManager->setPlayerClass(klass); - playerClass = klass; - wm->setPlayerClass(klass); + mEnvironment->mMechanicsManager->setPlayerClass(klass); + mPlayerClass = klass; + mWM->setPlayerClass(klass); - wm->removeDialog(createClassDialog); + mWM->removeDialog(mCreateClassDialog); } - if (creationStage == ReviewNext) - wm->setGuiMode(GM_Review); - else if (creationStage >= ClassChosen) - wm->setGuiMode(GM_Birth); + if (mCreationStage == CSE_ReviewNext) + mWM->setGuiMode(GM_Review); + else if (mCreationStage >= CSE_ClassChosen) + mWM->setGuiMode(GM_Birth); else { - creationStage = ClassChosen; - wm->setGuiMode(GM_Game); + mCreationStage = CSE_ClassChosen; + mWM->setGuiMode(GM_Game); } } void CharacterCreation::onCreateClassDialogBack() { - if (createClassDialog) - wm->removeDialog(createClassDialog); + if (mCreateClassDialog) + mWM->removeDialog(mCreateClassDialog); - wm->setGuiMode(GM_Class); + mWM->setGuiMode(GM_Class); } void CharacterCreation::onClassQuestionChosen(int _index) { - if (generateClassQuestionDialog) - wm->removeDialog(generateClassQuestionDialog); + if (mGenerateClassQuestionDialog) + mWM->removeDialog(mGenerateClassQuestionDialog); if (_index < 0 || _index >= 3) { - wm->setGuiMode(GM_Class); + mWM->setGuiMode(GM_Class); return; } - ESM::Class::Specialization specialization = generateClassSteps[generateClassStep].specializations[_index]; + ESM::Class::Specialization specialization = sGenerateClassSteps[mGenerateClassStep].mSpecializations[_index]; if (specialization == ESM::Class::Stealth) - ++generateClassSpecializations[0]; + ++mGenerateClassSpecializations[0]; else if (specialization == ESM::Class::Combat) - ++generateClassSpecializations[1]; + ++mGenerateClassSpecializations[1]; else if (specialization == ESM::Class::Magic) - ++generateClassSpecializations[2]; - ++generateClassStep; + ++mGenerateClassSpecializations[2]; + ++mGenerateClassStep; showClassQuestionDialog(); } void CharacterCreation::showClassQuestionDialog() { - if (generateClassStep == generateClassSteps.size()) + if (mGenerateClassStep == sGenerateClassSteps.size()) { static boost::array classes = { { {"Acrobat", {6, 2, 2}}, @@ -433,100 +432,100 @@ void CharacterCreation::showClassQuestionDialog() int match = -1; for (unsigned i = 0; i < classes.size(); ++i) { - if (generateClassSpecializations[0] == classes[i].points[0] && - generateClassSpecializations[1] == classes[i].points[1] && - generateClassSpecializations[2] == classes[i].points[2]) + if (mGenerateClassSpecializations[0] == classes[i].points[0] && + mGenerateClassSpecializations[1] == classes[i].points[1] && + mGenerateClassSpecializations[2] == classes[i].points[2]) { match = i; - generateClass = classes[i].id; + mGenerateClass = classes[i].id; break; } } if (match == -1) { - if (generateClassSpecializations[0] >= 7) - generateClass = "Thief"; - else if (generateClassSpecializations[1] >= 7) - generateClass = "Warrior"; - else if (generateClassSpecializations[2] >= 7) - generateClass = "Mage"; + if (mGenerateClassSpecializations[0] >= 7) + mGenerateClass = "Thief"; + else if (mGenerateClassSpecializations[1] >= 7) + mGenerateClass = "Warrior"; + else if (mGenerateClassSpecializations[2] >= 7) + mGenerateClass = "Mage"; else { std::cerr << "Failed to deduce class from chosen answers in generate class dialog" << std::endl; - generateClass = "Thief"; + mGenerateClass = "Thief"; } } - if (generateClassResultDialog) - wm->removeDialog(generateClassResultDialog); - generateClassResultDialog = new GenerateClassResultDialog(*wm); - generateClassResultDialog->setClassId(generateClass); - generateClassResultDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onGenerateClassBack); - generateClassResultDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onGenerateClassDone); - generateClassResultDialog->open(); + if (mGenerateClassResultDialog) + mWM->removeDialog(mGenerateClassResultDialog); + mGenerateClassResultDialog = new GenerateClassResultDialog(*mWM); + mGenerateClassResultDialog->setClassId(mGenerateClass); + mGenerateClassResultDialog->eventBack = MyGUI::newDelegate(this, &CharacterCreation::onGenerateClassBack); + mGenerateClassResultDialog->eventDone = MyGUI::newDelegate(this, &CharacterCreation::onGenerateClassDone); + mGenerateClassResultDialog->open(); return; } - if (generateClassStep > generateClassSteps.size()) + if (mGenerateClassStep > sGenerateClassSteps.size()) { - wm->setGuiMode(GM_Class); + mWM->setGuiMode(GM_Class); return; } - if (generateClassQuestionDialog) - wm->removeDialog(generateClassQuestionDialog); - generateClassQuestionDialog = new InfoBoxDialog(*wm); + if (mGenerateClassQuestionDialog) + mWM->removeDialog(mGenerateClassQuestionDialog); + mGenerateClassQuestionDialog = new InfoBoxDialog(*mWM); InfoBoxDialog::ButtonList buttons; - generateClassQuestionDialog->setText(generateClassSteps[generateClassStep].text); - buttons.push_back(generateClassSteps[generateClassStep].buttons[0]); - buttons.push_back(generateClassSteps[generateClassStep].buttons[1]); - buttons.push_back(generateClassSteps[generateClassStep].buttons[2]); - generateClassQuestionDialog->setButtons(buttons); - generateClassQuestionDialog->eventButtonSelected = MyGUI::newDelegate(this, &CharacterCreation::onClassQuestionChosen); - generateClassQuestionDialog->open(); + mGenerateClassQuestionDialog->setText(sGenerateClassSteps[mGenerateClassStep].mText); + buttons.push_back(sGenerateClassSteps[mGenerateClassStep].mButtons[0]); + buttons.push_back(sGenerateClassSteps[mGenerateClassStep].mButtons[1]); + buttons.push_back(sGenerateClassSteps[mGenerateClassStep].mButtons[2]); + mGenerateClassQuestionDialog->setButtons(buttons); + mGenerateClassQuestionDialog->eventButtonSelected = MyGUI::newDelegate(this, &CharacterCreation::onClassQuestionChosen); + mGenerateClassQuestionDialog->open(); } void CharacterCreation::onGenerateClassBack() { - if(creationStage < ClassChosen) - creationStage = ClassChosen; + if(mCreationStage < CSE_ClassChosen) + mCreationStage = CSE_ClassChosen; - if (generateClassResultDialog) - wm->removeDialog(generateClassResultDialog); - environment->mMechanicsManager->setPlayerClass(generateClass); + if (mGenerateClassResultDialog) + mWM->removeDialog(mGenerateClassResultDialog); + mEnvironment->mMechanicsManager->setPlayerClass(mGenerateClass); - wm->setGuiMode(GM_Class); + mWM->setGuiMode(GM_Class); } void CharacterCreation::onGenerateClassDone(WindowBase* parWindow) { - if (generateClassResultDialog) - wm->removeDialog(generateClassResultDialog); - environment->mMechanicsManager->setPlayerClass(generateClass); - - if (creationStage == ReviewNext) - wm->setGuiMode(GM_Review); - else if (creationStage >= ClassChosen) - wm->setGuiMode(GM_Birth); + if (mGenerateClassResultDialog) + mWM->removeDialog(mGenerateClassResultDialog); + mEnvironment->mMechanicsManager->setPlayerClass(mGenerateClass); + + if (mCreationStage == CSE_ReviewNext) + mWM->setGuiMode(GM_Review); + else if (mCreationStage >= CSE_ClassChosen) + mWM->setGuiMode(GM_Birth); else { - creationStage = ClassChosen; - wm->setGuiMode(GM_Game); + mCreationStage = CSE_ClassChosen; + mWM->setGuiMode(GM_Game); } } CharacterCreation::~CharacterCreation() { - delete nameDialog; - delete raceDialog; - delete dialogueWindow; - delete classChoiceDialog; - delete generateClassQuestionDialog; - delete generateClassResultDialog; - delete pickClassDialog; - delete createClassDialog; - delete birthSignDialog; - delete reviewDialog; + delete mNameDialog; + delete mRaceDialog; + delete mDialogueWindow; + delete mClassChoiceDialog; + delete mGenerateClassQuestionDialog; + delete mGenerateClassResultDialog; + delete mPickClassDialog; + delete mCreateClassDialog; + delete mBirthSignDialog; + delete mReviewDialog; } diff --git a/apps/openmw/mwgui/charactercreation.hpp b/apps/openmw/mwgui/charactercreation.hpp index 23111b126..ea38cb8fe 100644 --- a/apps/openmw/mwgui/charactercreation.hpp +++ b/apps/openmw/mwgui/charactercreation.hpp @@ -37,34 +37,34 @@ namespace MWGui void spawnDialog(const char id); private: - WindowManager* wm; - MWWorld::Environment* environment; - //Dialogs - TextInputDialog *nameDialog; - RaceDialog *raceDialog; - DialogueWindow *dialogueWindow; - ClassChoiceDialog *classChoiceDialog; - InfoBoxDialog *generateClassQuestionDialog; - GenerateClassResultDialog *generateClassResultDialog; - PickClassDialog *pickClassDialog; - CreateClassDialog *createClassDialog; - BirthDialog *birthSignDialog; - ReviewDialog *reviewDialog; + TextInputDialog* mNameDialog; + RaceDialog* mRaceDialog; + DialogueWindow* mDialogueWindow; + ClassChoiceDialog* mClassChoiceDialog; + InfoBoxDialog* mGenerateClassQuestionDialog; + GenerateClassResultDialog* mGenerateClassResultDialog; + PickClassDialog* mPickClassDialog; + CreateClassDialog* mCreateClassDialog; + BirthDialog* mBirthSignDialog; + ReviewDialog* mReviewDialog; + + WindowManager* mWM; + MWWorld::Environment* mEnvironment; //Player data - std::string playerName; - std::string playerRaceId; - std::string playerBirthSignId; - ESM::Class playerClass; - std::map > playerAttributes; - SkillList playerMajorSkills, playerMinorSkills; - std::map > playerSkillValues; + std::string mPlayerName; + std::string mPlayerRaceId; + std::string mPlayerBirthSignId; + ESM::Class mPlayerClass; + std::map > mPlayerAttributes; + SkillList mPlayerMajorSkills, mPlayerMinorSkills; + std::map > mPlayerSkillValues; //Class generation vars - unsigned generateClassStep; // Keeps track of current step in Generate Class dialog - unsigned generateClassSpecializations[3]; // A counter for each specialization which is increased when an answer is chosen - std::string generateClass; // In order: Stealth, Combat, Magic + unsigned mGenerateClassStep; // Keeps track of current step in Generate Class dialog + unsigned mGenerateClassSpecializations[3]; // A counter for each specialization which is increased when an answer is chosen + std::string mGenerateClass; // In order: Stealth, Combat, Magic ////Dialog events //Name dialog @@ -94,27 +94,27 @@ namespace MWGui void onReviewDialogBack(); void onReviewActivateDialog(int parDialog); - enum CreationStageEnum + enum CSE //Creation Stage Enum { - NotStarted, - NameChosen, - RaceChosen, - ClassChosen, - BirthSignChosen, - ReviewNext + CSE_NotStarted, + CSE_NameChosen, + CSE_RaceChosen, + CSE_ClassChosen, + CSE_BirthSignChosen, + CSE_ReviewNext }; - CreationStageEnum creationStage; // Which state the character creating is in, controls back/next/ok buttons + CSE mCreationStage; // Which state the character creating is in, controls back/next/ok buttons }; struct Step { - const char* text; - const char* buttons[3]; - ESM::Class::Specialization specializations[3]; // The specialization for each answer + const char* mText; + const char* mButtons[3]; + ESM::Class::Specialization mSpecializations[3]; // The specialization for each answer }; - static boost::array generateClassSteps = { { + static boost::array sGenerateClassSteps = { { // Question 1 {"On a clear day you chance upon a strange animal, its legs trapped in a hunter's clawsnare. Judging from the bleeding, it will not survive long.", {"Draw your dagger, mercifully endings its life with a single thrust.", diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 83a56a7b3..2ff56f6bf 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -80,58 +80,6 @@ namespace MWGui typedef std::vector FactionList; typedef std::vector SkillList; - private: - MWWorld::Environment& environment; - HUD *hud; - MapWindow *map; - MainMenu *menu; - StatsWindow *stats; - MessageBoxManager *mMessageBoxManager; - Console *console; - JournalWindow* mJournal; - DialogueWindow *dialogueWindow; - - CharacterCreation* mCharGen; - - // Various stats about player as needed by window manager - ESM::Class playerClass; - std::string playerName; - std::string playerRaceId; - std::string playerBirthSignId; - std::map > playerAttributes; - SkillList playerMajorSkills, playerMinorSkills; - std::map > playerSkillValues; - MWMechanics::DynamicStat playerHealth, playerMagicka, playerFatigue; - - - MyGUI::Gui *gui; // Gui - GuiMode mode; // Current gui mode - GuiMode nextMode; // Next mode to activate in update() - bool needModeChange; //Whether a mode change is needed in update() [will use nextMode] - - std::vector garbageDialogs; - void cleanupGarbage(); - - GuiWindow shown; // Currently shown windows in inventory mode - - /* Currently ALLOWED windows in inventory mode. This is used at - the start of the game, when windows are enabled one by one - through script commands. You can manipulate this through using - allow() and disableAll(). - - The setting should also affect visibility of certain HUD - elements, but this is not done yet. - */ - GuiWindow allowed; - - void updateVisible(); // Update visibility of all windows based on mode, shown and allowed settings - - int showFPSLevel; - float mFPS; - size_t mTriangleCount; - size_t mBatchCount; - - public: WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment, const Compiler::Extensions& extensions, int fpsLevel, bool newGame); virtual ~WindowManager(); @@ -222,6 +170,55 @@ namespace MWGui const ESMS::ESMStore& getStore() const; private: + MWWorld::Environment& environment; + HUD *hud; + MapWindow *map; + MainMenu *menu; + StatsWindow *stats; + MessageBoxManager *mMessageBoxManager; + Console *console; + JournalWindow* mJournal; + DialogueWindow *dialogueWindow; + + CharacterCreation* mCharGen; + + // Various stats about player as needed by window manager + ESM::Class playerClass; + std::string playerName; + std::string playerRaceId; + std::string playerBirthSignId; + std::map > playerAttributes; + SkillList playerMajorSkills, playerMinorSkills; + std::map > playerSkillValues; + MWMechanics::DynamicStat playerHealth, playerMagicka, playerFatigue; + + + MyGUI::Gui *gui; // Gui + GuiMode mode; // Current gui mode + GuiMode nextMode; // Next mode to activate in update() + bool needModeChange; //Whether a mode change is needed in update() [will use nextMode] + + std::vector garbageDialogs; + void cleanupGarbage(); + + GuiWindow shown; // Currently shown windows in inventory mode + + /* Currently ALLOWED windows in inventory mode. This is used at + the start of the game, when windows are enabled one by one + through script commands. You can manipulate this through using + allow() and disableAll(). + + The setting should also affect visibility of certain HUD + elements, but this is not done yet. + */ + GuiWindow allowed; + + void updateVisible(); // Update visibility of all windows based on mode, shown and allowed settings + + int showFPSLevel; + float mFPS; + size_t mTriangleCount; + size_t mBatchCount; void onDialogueWindowBye(); };