From d17ba6ce196c07382e4cf13c10a2f1ce4e8c75b2 Mon Sep 17 00:00:00 2001 From: Cris Mihalache Date: Mon, 30 Jan 2012 19:27:49 +0200 Subject: [PATCH] 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