diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index f4598ddc0..8abac820c 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -35,6 +35,7 @@ source_group(apps\\openmw\\mwinput FILES ${GAMEINPUT} ${GAMEINPUT_HEADER}) set(GAMEGUI_HEADER mwgui/layouts.hpp + mwgui/text_input.hpp mwgui/race.hpp mwgui/window_manager.hpp mwgui/console.hpp @@ -42,6 +43,7 @@ set(GAMEGUI_HEADER set(GAMEGUI mwgui/window_manager.cpp mwgui/console.cpp + mwgui/text_input.cpp mwgui/race.cpp ) source_group(apps\\openmw\\mwgui FILES ${GAMEGUI_HEADER} ${GAMEGUI}) diff --git a/apps/openmw/mwgui/text_input.cpp b/apps/openmw/mwgui/text_input.cpp new file mode 100644 index 000000000..463f0baf8 --- /dev/null +++ b/apps/openmw/mwgui/text_input.cpp @@ -0,0 +1,45 @@ +#include "text_input.hpp" +#include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" + +using namespace MWGui; + +TextInputDialog::TextInputDialog(MWWorld::Environment& environment, const std::string &label, bool showNext, MyGUI::IntSize size) + : Layout("openmw_text_input_layout.xml") + , environment(environment) +{ + // Centre dialog + MyGUI::IntCoord coord = mMainWidget->getCoord(); + coord.left = (size.width - coord.width)/2; + coord.top = (size.height - coord.height)/2; + mMainWidget->setCoord(coord); + + setText("LabelT", label); + + getWidget(textEdit, "TextEdit"); +// 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)); + } +} + +// widget controls + +void TextInputDialog::onOkClicked(MyGUI::Widget* _sender) +{ + eventDone(); +} + +void TextInputDialog::onTextAccepted(MyGUI::Edit* _sender) +{ + eventDone(); +} diff --git a/apps/openmw/mwgui/text_input.hpp b/apps/openmw/mwgui/text_input.hpp new file mode 100644 index 000000000..5f9d7745c --- /dev/null +++ b/apps/openmw/mwgui/text_input.hpp @@ -0,0 +1,45 @@ +#ifndef MWGUI_TEXT_INPUT_H +#define MWGUI_TEXT_INPUT_H + +#include + +namespace MWWorld +{ + class Environment; +} + +/* + */ + +namespace MWGui +{ + using namespace MyGUI; + + typedef delegates::CDelegate0 EventHandle_Void; + + class TextInputDialog : public OEngine::GUI::Layout + { + public: + TextInputDialog(MWWorld::Environment& environment, const std::string &label, bool showNext, MyGUI::IntSize size); + + std::string getTextInput() const { return textEdit ? textEdit->getOnlyText() : ""; } + void setTextInput(const std::string &text) { if (textEdit) textEdit->setOnlyText(text); } + + // Events + + /** Event : Dialog finished, OK button clicked.\n + signature : void method()\n + */ + EventHandle_Void eventDone; + + protected: + void onOkClicked(MyGUI::Widget* _sender); + void onTextAccepted(MyGUI::Edit* _sender); + + private: + MWWorld::Environment& environment; + + MyGUI::EditPtr textEdit; + }; +} +#endif diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 25fc70978..f704c16ad 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -1,5 +1,6 @@ #include "window_manager.hpp" #include "layouts.hpp" +#include "text_input.hpp" #include "race.hpp" #include "../mwmechanics/mechanicsmanager.hpp" @@ -15,6 +16,7 @@ using namespace MWGui; WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment, const Compiler::Extensions& extensions, bool newGame) : environment(environment) + , nameDialog(nullptr) , raceDialog(nullptr) , nameChosen(false) , raceChosen(false) @@ -54,6 +56,7 @@ WindowManager::~WindowManager() delete stats; delete inventory; + delete nameDialog; delete raceDialog; } @@ -88,6 +91,15 @@ void WindowManager::updateVisible() return; } + if (mode == GM_Name) + { + if (!nameDialog) + nameDialog = new TextInputDialog(environment, "Name", nameChosen, gui->getViewSize()); + nameDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onNameDialogDone); + nameDialog->setVisible(true); + return; + } + if (mode == GM_Race) { if (!raceDialog) @@ -151,6 +163,25 @@ void WindowManager::updateCharacterGeneration() } } +void WindowManager::onNameDialogDone() +{ + nameChosen = true; + if (nameDialog) + { + nameDialog->setVisible(false); + environment.mMechanicsManager->setPlayerName(nameDialog->getTextInput()); + } + delete nameDialog; + nameDialog = nullptr; + + updateCharacterGeneration(); + + if (reviewNext) + setMode(GM_Review); + else if (raceChosen) + setMode(GM_Race); +} + void WindowManager::onRaceDialogDone() { raceChosen = true; diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index b20efb5d3..2dcbb848d 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -39,6 +39,7 @@ namespace MWGui class InventoryWindow; class Console; + class TextInputDialog; class RaceDialog; enum GuiMode @@ -88,6 +89,7 @@ namespace MWGui Console *console; // Character creation + TextInputDialog *nameDialog; RaceDialog *raceDialog; // Which dialogs have been shown, controls back/next/ok buttons @@ -168,6 +170,10 @@ namespace MWGui void updateCharacterGeneration(); void checkCharacterGeneration(GuiMode mode); + // Character generation: Name dialog + void onNameDialogDone(); + + // Character generation: Race dialog void onRaceDialogDone(); void onRaceDialogBack(); }; diff --git a/extern/mygui_3.0.1/CMakeLists.txt b/extern/mygui_3.0.1/CMakeLists.txt index 25568e6a6..b819ef033 100644 --- a/extern/mygui_3.0.1/CMakeLists.txt +++ b/extern/mygui_3.0.1/CMakeLists.txt @@ -34,12 +34,14 @@ configure_file("${SDIR}/mwgui.png" "${DDIR}/mwgui.png" COPYONLY) configure_file("${SDIR}/openmw_box.skin.xml" "${DDIR}/openmw_box.skin.xml" COPYONLY) configure_file("${SDIR}/openmw_button.skin.xml" "${DDIR}/openmw_button.skin.xml" COPYONLY) configure_file("${SDIR}/openmw_list.skin.xml" "${DDIR}/openmw_list.skin.xml" COPYONLY) +configure_file("${SDIR}/openmw_edit.skin.xml" "${DDIR}/openmw_edit.skin.xml" COPYONLY) configure_file("${SDIR}/openmw_console_layout.xml" "${DDIR}/openmw_console_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_console.skin.xml" "${DDIR}/openmw_console.skin.xml" COPYONLY) configure_file("${SDIR}/openmw.font.xml" "${DDIR}/openmw.font.xml" COPYONLY) configure_file("${SDIR}/openmw_hud_box.skin.xml" "${DDIR}/openmw_hud_box.skin.xml" COPYONLY) configure_file("${SDIR}/openmw_hud_energybar.skin.xml" "${DDIR}/openmw_hud_energybar.skin.xml" COPYONLY) configure_file("${SDIR}/openmw_hud_layout.xml" "${DDIR}/openmw_hud_layout.xml" COPYONLY) +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_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/core.xml b/extern/mygui_3.0.1/openmw_resources/core.xml index 7fab9bce5..3d4d5ba3b 100644 --- a/extern/mygui_3.0.1/openmw_resources/core.xml +++ b/extern/mygui_3.0.1/openmw_resources/core.xml @@ -12,6 +12,7 @@ + diff --git a/extern/mygui_3.0.1/openmw_resources/openmw_edit.skin.xml b/extern/mygui_3.0.1/openmw_resources/openmw_edit.skin.xml new file mode 100644 index 000000000..482e4a7b2 --- /dev/null +++ b/extern/mygui_3.0.1/openmw_resources/openmw_edit.skin.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/extern/mygui_3.0.1/openmw_resources/openmw_text_input_layout.xml b/extern/mygui_3.0.1/openmw_resources/openmw_text_input_layout.xml new file mode 100644 index 000000000..195a233aa --- /dev/null +++ b/extern/mygui_3.0.1/openmw_resources/openmw_text_input_layout.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + +