From d97dad7a869cda8e848565ebe586754edccd2da7 Mon Sep 17 00:00:00 2001 From: Jan Borsodi Date: Wed, 22 Sep 2010 20:59:13 +0200 Subject: [PATCH] Initial work on the Class Create dialog. --- apps/openmw/mwgui/class.cpp | 183 ++++++++++++++++++ apps/openmw/mwgui/class.hpp | 43 ++++ extern/mygui_3.0.1/CMakeLists.txt | 1 + .../openmw_chargen_create_class_layout.xml | 70 +++++++ 4 files changed, 297 insertions(+) create mode 100644 extern/mygui_3.0.1/openmw_resources/openmw_chargen_create_class_layout.xml diff --git a/apps/openmw/mwgui/class.cpp b/apps/openmw/mwgui/class.cpp index 7c56c553d..6a0e3967f 100644 --- a/apps/openmw/mwgui/class.cpp +++ b/apps/openmw/mwgui/class.cpp @@ -12,6 +12,8 @@ using namespace MWGui; +/* PickClassDialog */ + PickClassDialog::PickClassDialog(MWWorld::Environment& environment, MyGUI::IntSize gameWindowSize) : Layout("openmw_chargen_class_layout.xml") , environment(environment) @@ -221,3 +223,184 @@ void PickClassDialog::updateStats() classImage->setImageTexture(std::string("textures\\levelup\\") + currentClassId + ".dds"); } + + +/* CreateClassDialog */ + +CreateClassDialog::CreateClassDialog(MWWorld::Environment& environment, MyGUI::IntSize gameWindowSize) + : Layout("openmw_chargen_create_class_layout.xml") + , environment(environment) +{ + // Centre dialog + MyGUI::IntCoord coord = mMainWidget->getCoord(); + coord.left = (gameWindowSize.width - coord.width)/2; + coord.top = (gameWindowSize.height - coord.height)/2; + mMainWidget->setCoord(coord); + + WindowManager *wm = environment.mWindowManager; + setText("SpecializationT", wm->getGameSettingString("sChooseClassMenu1", "Specialization")); + getWidget(specializationName, "SpecializationName"); + + setText("FavoriteAttributesT", wm->getGameSettingString("sChooseClassMenu2", "Favorite Attributes:")); + getWidget(favoriteAttribute0, "FavoriteAttribute0"); + getWidget(favoriteAttribute1, "FavoriteAttribute1"); + favoriteAttribute0->setWindowManager(wm); + favoriteAttribute1->setWindowManager(wm); + + setText("MajorSkillT", wm->getGameSettingString("sChooseClassMenu3", "Major Skills:")); + getWidget(majorSkill0, "MajorSkill0"); + getWidget(majorSkill1, "MajorSkill1"); + getWidget(majorSkill2, "MajorSkill2"); + getWidget(majorSkill3, "MajorSkill3"); + getWidget(majorSkill4, "MajorSkill4"); + majorSkill0->setWindowManager(wm); + majorSkill1->setWindowManager(wm); + majorSkill2->setWindowManager(wm); + majorSkill3->setWindowManager(wm); + majorSkill4->setWindowManager(wm); + + setText("MinorSkillT", wm->getGameSettingString("sChooseClassMenu4", "Minor Skills:")); + getWidget(minorSkill0, "MinorSkill0"); + getWidget(minorSkill1, "MinorSkill1"); + getWidget(minorSkill2, "MinorSkill2"); + getWidget(minorSkill3, "MinorSkill3"); + getWidget(minorSkill4, "MinorSkill4"); + minorSkill0->setWindowManager(wm); + minorSkill1->setWindowManager(wm); + minorSkill2->setWindowManager(wm); + minorSkill3->setWindowManager(wm); + minorSkill4->setWindowManager(wm); + + setText("LabelT", wm->getGameSettingString("sName", "")); + getWidget(editName, "EditName"); + + // TODO: These buttons should be managed by a Dialog class + MyGUI::ButtonPtr descriptionButton; + getWidget(descriptionButton, "DescriptionButton"); + descriptionButton->eventMouseButtonClick = MyGUI::newDelegate(this, &CreateClassDialog::onDescriptionClicked); + + MyGUI::ButtonPtr backButton; + getWidget(backButton, "BackButton"); + backButton->eventMouseButtonClick = MyGUI::newDelegate(this, &CreateClassDialog::onBackClicked); + + MyGUI::ButtonPtr okButton; + getWidget(okButton, "OKButton"); + okButton->eventMouseButtonClick = MyGUI::newDelegate(this, &CreateClassDialog::onOkClicked); + + updateStats(); +} + +void CreateClassDialog::setNextButtonShow(bool shown) +{ + MyGUI::ButtonPtr descriptionButton; + getWidget(descriptionButton, "DescriptionButton"); + + MyGUI::ButtonPtr backButton; + getWidget(backButton, "BackButton"); + + MyGUI::ButtonPtr okButton; + getWidget(okButton, "OKButton"); + + // TODO: All hardcoded coords for buttons are temporary, will be replaced with a dynamic system. + if (shown) + { + okButton->setCaption("Next"); + + // Adjust back button when next is shown + descriptionButton->setCoord(MyGUI::IntCoord(207 - 18, 158, 143, 23)); + backButton->setCoord(MyGUI::IntCoord(356 - 18, 158, 53, 23)); + okButton->setCoord(MyGUI::IntCoord(417 - 18, 158, 42 + 18, 23)); + } + else + { + okButton->setCaption("OK"); + descriptionButton->setCoord(MyGUI::IntCoord(207, 158, 143, 23)); + backButton->setCoord(MyGUI::IntCoord(356, 158, 53, 23)); + okButton->setCoord(MyGUI::IntCoord(417, 158, 42, 23)); + } +} + +void CreateClassDialog::open() +{ + updateStats(); + setVisible(true); +} + + +//void CreateClassDialog::setClassId(const std::string &classId) +//{ +// currentClassId = classId; +// classList->setIndexSelected(MyGUI::ITEM_NONE); +// size_t count = classList->getItemCount(); +// for (size_t i = 0; i < count; ++i) +// { +// if (boost::iequals(*classList->getItemDataAt(i), classId)) +// { +// classList->setIndexSelected(i); +// break; +// } +// } +// +// updateStats(); +//} + +// widget controls + +void CreateClassDialog::onDescriptionClicked(MyGUI::Widget* _sender) +{ + // TODO: Show description dialog +} + +void CreateClassDialog::onOkClicked(MyGUI::Widget* _sender) +{ + eventDone(); +} + +void CreateClassDialog::onBackClicked(MyGUI::Widget* _sender) +{ + eventBack(); +} + +// update widget content + +void CreateClassDialog::updateStats() +{ + if (currentClassId.empty()) + return; + WindowManager *wm = environment.mWindowManager; + ESMS::ESMStore &store = environment.mWorld->getStore(); + const ESM::Class *klass = store.classes.find(currentClassId); + + ESM::Class::Specialization specialization = static_cast(klass->data.specialization); + + static const char *specIds[3] = { + "sSpecializationCombat", + "sSpecializationMagic", + "sSpecializationStealth" + }; + specializationName->setCaption(wm->getGameSettingString(specIds[specialization], specIds[specialization])); + + favoriteAttribute0->setAttributeId(klass->data.attribute[0]); + favoriteAttribute1->setAttributeId(klass->data.attribute[1]); + + Widgets::MWSkillPtr majorSkills[5] = { + majorSkill0, + majorSkill1, + majorSkill2, + majorSkill3, + majorSkill4 + }; + Widgets::MWSkillPtr minorSkills[5] = { + minorSkill0, + minorSkill1, + minorSkill2, + minorSkill3, + minorSkill4 + }; + + for (int i = 0; i < 5; ++i) + { + majorSkills[i]->setSkillNumber(klass->data.skills[i][0]); + minorSkills[i]->setSkillNumber(klass->data.skills[i][1]); + } +} diff --git a/apps/openmw/mwgui/class.hpp b/apps/openmw/mwgui/class.hpp index 35b18f63f..5e8e80510 100644 --- a/apps/openmw/mwgui/class.hpp +++ b/apps/openmw/mwgui/class.hpp @@ -68,5 +68,48 @@ namespace MWGui std::string currentClassId; }; + + class CreateClassDialog : public OEngine::GUI::Layout + { + public: + CreateClassDialog(MWWorld::Environment& environment, MyGUI::IntSize gameWindowSize); + +// const std::string &getClassId() const { return currentClassId; } +// void setClassId(const std::string &classId); + + void setNextButtonShow(bool shown); + void open(); + + // Events + typedef delegates::CDelegate0 EventHandle_Void; + + /** Event : Back button clicked.\n + signature : void method()\n + */ + EventHandle_Void eventBack; + + /** Event : Dialog finished, OK button clicked.\n + signature : void method()\n + */ + EventHandle_Void eventDone; + + protected: + void onDescriptionClicked(MyGUI::Widget* _sender); + void onOkClicked(MyGUI::Widget* _sender); + void onBackClicked(MyGUI::Widget* _sender); + + private: + void updateStats(); + + MWWorld::Environment& environment; + + MyGUI::EditPtr editName; + MyGUI::StaticTextPtr specializationName; + Widgets::MWAttributePtr favoriteAttribute0, favoriteAttribute1; + Widgets::MWSkillPtr majorSkill0, majorSkill1, majorSkill2, majorSkill3, majorSkill4; + Widgets::MWSkillPtr minorSkill0, minorSkill1, minorSkill2, minorSkill3, minorSkill4; + + std::string currentClassId; + }; } #endif diff --git a/extern/mygui_3.0.1/CMakeLists.txt b/extern/mygui_3.0.1/CMakeLists.txt index f64c64327..7cf45433d 100644 --- a/extern/mygui_3.0.1/CMakeLists.txt +++ b/extern/mygui_3.0.1/CMakeLists.txt @@ -44,6 +44,7 @@ configure_file("${SDIR}/openmw_hud_layout.xml" "${DDIR}/openmw_hud_layout.xml" C configure_file("${SDIR}/openmw_text_input_layout.xml" "${DDIR}/openmw_text_input_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_chargen_race_layout.xml" "${DDIR}/openmw_chargen_race_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_chargen_class_layout.xml" "${DDIR}/openmw_chargen_class_layout.xml" COPYONLY) +configure_file("${SDIR}/openmw_chargen_create_class_layout.xml" "${DDIR}/openmw_chargen_create_class_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_chargen_birth_layout.xml" "${DDIR}/openmw_chargen_birth_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_inventory_window_layout.xml" "${DDIR}/openmw_inventory_window_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_layers.xml" "${DDIR}/openmw_layers.xml" COPYONLY) diff --git a/extern/mygui_3.0.1/openmw_resources/openmw_chargen_create_class_layout.xml b/extern/mygui_3.0.1/openmw_resources/openmw_chargen_create_class_layout.xml new file mode 100644 index 000000000..db937a59d --- /dev/null +++ b/extern/mygui_3.0.1/openmw_resources/openmw_chargen_create_class_layout.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +