diff --git a/apps/openmw/mwgui/race.cpp b/apps/openmw/mwgui/race.cpp index 5d8e90298..b0722d36c 100644 --- a/apps/openmw/mwgui/race.cpp +++ b/apps/openmw/mwgui/race.cpp @@ -13,7 +13,7 @@ using namespace MWGui; -RaceDialog::RaceDialog(MWWorld::Environment& environment, bool showNext) +RaceDialog::RaceDialog(MWWorld::Environment& environment) : Layout("openmw_chargen_race_layout.xml") , environment(environment) , genderIndex(0) @@ -78,20 +78,38 @@ RaceDialog::RaceDialog(MWWorld::Environment& environment, bool showNext) MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); okButton->eventMouseButtonClick = MyGUI::newDelegate(this, &RaceDialog::onOkClicked); - if (showNext) - { - okButton->setCaption("Next"); - - // Adjust back button when next is shown - backButton->setCoord(backButton->getCoord() - MyGUI::IntPoint(18, 0)); - okButton->setCoord(okButton->getCoord() + MyGUI::IntCoord(-18, 0, 18, 0)); - } updateRaces(); updateSkills(); updateSpellPowers(); } +void RaceDialog::setNextButtonShow(bool shown) +{ + 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 + backButton->setCoord(MyGUI::IntCoord(471 - 18, 397, 53, 23)); + okButton->setCoord(MyGUI::IntCoord(532 - 18, 397 + 18, 42, 23)); + } + else + { + okButton->setCaption("ok"); + backButton->setCoord(MyGUI::IntCoord(471, 397, 53, 23)); + okButton->setCoord(MyGUI::IntCoord(532, 397, 42, 23)); + } +} + + void RaceDialog::setRaceId(const std::string &raceId) { currentRaceId = raceId; diff --git a/apps/openmw/mwgui/race.hpp b/apps/openmw/mwgui/race.hpp index 655f74ed4..98e1dd1fe 100644 --- a/apps/openmw/mwgui/race.hpp +++ b/apps/openmw/mwgui/race.hpp @@ -26,7 +26,7 @@ namespace MWGui class RaceDialog : public OEngine::GUI::Layout { public: - RaceDialog(MWWorld::Environment& environment, bool showNext); + RaceDialog(MWWorld::Environment& environment); enum Gender { @@ -44,6 +44,8 @@ namespace MWGui // setFace() // setHair() + void setNextButtonShow(bool shown); + // Events /** Event : Back button clicked.\n diff --git a/apps/openmw/mwgui/text_input.cpp b/apps/openmw/mwgui/text_input.cpp index fa6f0078e..b81b00c93 100644 --- a/apps/openmw/mwgui/text_input.cpp +++ b/apps/openmw/mwgui/text_input.cpp @@ -4,7 +4,7 @@ using namespace MWGui; -TextInputDialog::TextInputDialog(MWWorld::Environment& environment, const std::string &label, bool showNext, MyGUI::IntSize size) +TextInputDialog::TextInputDialog(MWWorld::Environment& environment, MyGUI::IntSize size) : Layout("openmw_text_input_layout.xml") , environment(environment) { @@ -14,27 +14,39 @@ TextInputDialog::TextInputDialog(MWWorld::Environment& environment, const std::s coord.top = (size.height - coord.height)/2; mMainWidget->setCoord(coord); - setText("LabelT", label); - getWidget(textEdit, "TextEdit"); -// textEdit->eventEditSelectAccept = newDelegate(this, &TextInputDialog::onTextAccepted); + textEdit->eventEditSelectAccept = newDelegate(this, &TextInputDialog::onTextAccepted); // TODO: These buttons should be managed by a Dialog class MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); okButton->eventMouseButtonClick = MyGUI::newDelegate(this, &TextInputDialog::onOkClicked); - if (showNext) - { - okButton->setCaption("Next"); - - // Adjust back button when next is shown - okButton->setCoord(okButton->getCoord() + MyGUI::IntCoord(-18, 0, 18, 0)); - } // Make sure the edit box has focus MyGUI::InputManager::getInstance().setKeyFocusWidget(textEdit); } +void TextInputDialog::setNextButtonShow(bool shown) +{ + MyGUI::ButtonPtr okButton; + getWidget(okButton, "OKButton"); + if (shown) + { + okButton->setCaption("Next"); + okButton->setCoord(MyGUI::IntCoord(264 - 18, 60, 42 + 18, 23)); + } + else + { + okButton->setCaption("OK"); + okButton->setCoord(MyGUI::IntCoord(264, 60, 42, 23)); + } +} + +void TextInputDialog::setTextLabel(const std::string &label) +{ + setText("LabelT", label); +} + // widget controls void TextInputDialog::onOkClicked(MyGUI::Widget* _sender) diff --git a/apps/openmw/mwgui/text_input.hpp b/apps/openmw/mwgui/text_input.hpp index 5f9d7745c..34312575b 100644 --- a/apps/openmw/mwgui/text_input.hpp +++ b/apps/openmw/mwgui/text_input.hpp @@ -20,11 +20,14 @@ namespace MWGui class TextInputDialog : public OEngine::GUI::Layout { public: - TextInputDialog(MWWorld::Environment& environment, const std::string &label, bool showNext, MyGUI::IntSize size); + TextInputDialog(MWWorld::Environment& environment, MyGUI::IntSize size); std::string getTextInput() const { return textEdit ? textEdit->getOnlyText() : ""; } void setTextInput(const std::string &text) { if (textEdit) textEdit->setOnlyText(text); } + void setNextButtonShow(bool shown); + void setTextLabel(const std::string &label); + // Events /** Event : Dialog finished, OK button clicked.\n diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 16c2dec21..fbd545bb3 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -101,10 +101,11 @@ void WindowManager::updateVisible() if (mode == GM_Name) { if (!nameDialog) - { - std::string sName = getGameSettingString("sName", "Name"); - nameDialog = new TextInputDialog(environment, sName, nameChosen, gui->getViewSize()); - } + nameDialog = new TextInputDialog(environment, gui->getViewSize()); + + std::string sName = getGameSettingString("sName", "Name"); + nameDialog->setTextLabel(sName); + nameDialog->setNextButtonShow(nameChosen); nameDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onNameDialogDone); nameDialog->setVisible(true); return; @@ -113,7 +114,8 @@ void WindowManager::updateVisible() if (mode == GM_Race) { if (!raceDialog) - raceDialog = new RaceDialog (environment, raceChosen); + raceDialog = new RaceDialog(environment); + nameDialog->setNextButtonShow(raceChosen); raceDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onRaceDialogDone); raceDialog->eventBack = MyGUI::newDelegate(this, &WindowManager::onRaceDialogBack); raceDialog->setVisible(true); @@ -194,8 +196,6 @@ void WindowManager::onNameDialogDone() nameDialog->setVisible(false); environment.mMechanicsManager->setPlayerName(nameDialog->getTextInput()); } - delete nameDialog; - nameDialog = nullptr; updateCharacterGeneration(); @@ -216,8 +216,6 @@ void WindowManager::onRaceDialogDone() raceDialog->setVisible(false); environment.mMechanicsManager->setPlayerRace(raceDialog->getRaceId(), raceDialog->getGender() == RaceDialog::GM_Male); } - delete raceDialog; - raceDialog = nullptr; updateCharacterGeneration(); @@ -236,8 +234,6 @@ void WindowManager::onRaceDialogBack() raceDialog->setVisible(false); environment.mMechanicsManager->setPlayerRace(raceDialog->getRaceId(), raceDialog->getGender() == RaceDialog::GM_Male); } - delete raceDialog; - raceDialog = nullptr; updateCharacterGeneration();