From 0cc8f8439376576622e6eab6ef2b748761dc25a7 Mon Sep 17 00:00:00 2001 From: Jan Borsodi Date: Sun, 10 Oct 2010 02:43:44 +0200 Subject: [PATCH] Finished handling of Create Class dialog, now a new class is created and set in the mechanics manager. --- apps/openmw/mwgui/class.cpp | 45 ++++++++++++++++ apps/openmw/mwgui/class.hpp | 8 ++- apps/openmw/mwgui/window_manager.cpp | 80 ++++++++++++++++++++++++++-- apps/openmw/mwgui/window_manager.hpp | 6 +++ 4 files changed, 134 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwgui/class.cpp b/apps/openmw/mwgui/class.cpp index 032434298..f7e567031 100644 --- a/apps/openmw/mwgui/class.cpp +++ b/apps/openmw/mwgui/class.cpp @@ -525,6 +525,51 @@ CreateClassDialog::~CreateClassDialog() delete descDialog; } +std::string CreateClassDialog::getName() const +{ + return editName->getOnlyText(); +} + +std::string CreateClassDialog::getDescription() const +{ + return description; +} + +ESM::Class::Specialization CreateClassDialog::getSpecializationId() const +{ + return specializationId; +} + +std::vector CreateClassDialog::getFavoriteAttributes() const +{ + std::vector v; + v.push_back(favoriteAttribute0->getAttributeId()); + v.push_back(favoriteAttribute1->getAttributeId()); + return v; +} + +std::vector CreateClassDialog::getMajorSkills() const +{ + std::vector v; + v.push_back(majorSkill0->getSkillId()); + v.push_back(majorSkill1->getSkillId()); + v.push_back(majorSkill2->getSkillId()); + v.push_back(majorSkill3->getSkillId()); + v.push_back(majorSkill4->getSkillId()); + return v; +} + +std::vector CreateClassDialog::getMinorSkills() const +{ + std::vector v; + v.push_back(majorSkill0->getSkillId()); + v.push_back(majorSkill1->getSkillId()); + v.push_back(majorSkill2->getSkillId()); + v.push_back(majorSkill3->getSkillId()); + v.push_back(majorSkill4->getSkillId()); + return v; +} + void CreateClassDialog::setNextButtonShow(bool shown) { MyGUI::ButtonPtr descriptionButton; diff --git a/apps/openmw/mwgui/class.hpp b/apps/openmw/mwgui/class.hpp index aaf63becb..7f50a8b3e 100644 --- a/apps/openmw/mwgui/class.hpp +++ b/apps/openmw/mwgui/class.hpp @@ -288,8 +288,12 @@ namespace MWGui CreateClassDialog(MWWorld::Environment& environment, MyGUI::IntSize gameWindowSize); virtual ~CreateClassDialog(); -// const std::string &getClassId() const { return currentClassId; } -// void setClassId(const std::string &classId); + std::string getName() const; + std::string getDescription() const; + ESM::Class::Specialization getSpecializationId() const; + std::vector getFavoriteAttributes() const; + std::vector getMajorSkills() const; + std::vector getMinorSkills() const; void setNextButtonShow(bool shown); void open(); diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index da10f1dca..89bdb7b9e 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -25,6 +25,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment , generateClassQuestionDialog(nullptr) , generateClassResultDialog(nullptr) , pickClassDialog(nullptr) + , createClassDialog(nullptr) , birthSignDialog(nullptr) , nameChosen(false) , raceChosen(false) @@ -74,6 +75,7 @@ WindowManager::~WindowManager() delete generateClassQuestionDialog; delete generateClassResultDialog; delete pickClassDialog; + delete createClassDialog; delete birthSignDialog; } @@ -163,8 +165,12 @@ void WindowManager::updateVisible() if (mode == GM_ClassCreate) { - CreateClassDialog *ccd = new CreateClassDialog(environment, gui->getViewSize()); - ccd->open(); + if (createClassDialog) + delete createClassDialog; + createClassDialog = new CreateClassDialog(environment, gui->getViewSize()); + createClassDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onCreateClassDialogDone); + createClassDialog->eventBack = MyGUI::newDelegate(this, &WindowManager::onCreateClassDialogBack); + createClassDialog->open(); return; } @@ -439,6 +445,9 @@ void WindowManager::onClassQuestionChosen(MyGUI::Widget* _sender, int _index) void WindowManager::onGenerateClassBack() { + bool goNext = classChosen; // Go to next dialog if class was previously chosen + classChosen = true; + if (generateClassResultDialog) { generateClassResultDialog->setVisible(false); @@ -452,6 +461,9 @@ void WindowManager::onGenerateClassBack() void WindowManager::onGenerateClassDone() { + bool goNext = classChosen; // Go to next dialog if class was previously chosen + classChosen = true; + if (generateClassResultDialog) { generateClassResultDialog->setVisible(false); @@ -460,7 +472,12 @@ void WindowManager::onGenerateClassDone() updateCharacterGeneration(); - environment.mInputManager->setGuiMode(GM_Review); + if (reviewNext) + environment.mInputManager->setGuiMode(GM_Review); + else if (goNext) + environment.mInputManager->setGuiMode(GM_Birth); + else + environment.mInputManager->setGuiMode(GM_Game); } @@ -499,6 +516,63 @@ void WindowManager::onPickClassDialogBack() environment.mInputManager->setGuiMode(GM_Class); } +void WindowManager::onCreateClassDialogDone() +{ + createClassDialog->eventDone = MWGui::CreateClassDialog::EventHandle_Void(); + + bool goNext = classChosen; // Go to next dialog if class was previously chosen + classChosen = true; + if (createClassDialog) + { + createClassDialog->setVisible(false); + + // TODO: The ESM::Class should have methods to set these values to ensure correct data is assigned + 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); + } + + updateCharacterGeneration(); + + if (reviewNext) + environment.mInputManager->setGuiMode(GM_Review); + else if (goNext) + environment.mInputManager->setGuiMode(GM_Birth); + else + environment.mInputManager->setGuiMode(GM_Game); +} + +void WindowManager::onCreateClassDialogBack() +{ + if (pickClassDialog) + { + pickClassDialog->setVisible(false); + environment.mMechanicsManager->setPlayerClass(pickClassDialog->getClassId()); + } + + updateCharacterGeneration(); + + environment.mInputManager->setGuiMode(GM_Class); +} + void WindowManager::onBirthSignDialogDone() { birthSignDialog->eventDone = MWGui::BirthDialog::EventHandle_Void(); diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 82bf6ff5a..cf51e1aa6 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -48,6 +48,7 @@ namespace MWGui class ClassChoiceDialog; class GenerateClassResultDialog; class PickClassDialog; + class CreateClassDialog; class BirthDialog; class WindowManager @@ -69,6 +70,7 @@ namespace MWGui InfoBoxDialog *generateClassQuestionDialog; GenerateClassResultDialog *generateClassResultDialog; PickClassDialog *pickClassDialog; + CreateClassDialog *createClassDialog; BirthDialog *birthSignDialog; // Which dialogs have been shown, controls back/next/ok buttons @@ -213,6 +215,10 @@ namespace MWGui void onPickClassDialogDone(); void onPickClassDialogBack(); + // Character generation: Create Class dialog + void onCreateClassDialogDone(); + void onCreateClassDialogBack(); + // Character generation: Birth sign dialog void onBirthSignDialogDone(); void onBirthSignDialogBack();