forked from mirror/openmw-tes3mp
Implemented a general text input dialog which can be used to get text input from the player. Used the text input dialog to implement the name dialog for the character creation.
This commit is contained in:
parent
85ded0edc3
commit
481734ee20
9 changed files with 179 additions and 0 deletions
|
@ -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})
|
||||
|
|
45
apps/openmw/mwgui/text_input.cpp
Normal file
45
apps/openmw/mwgui/text_input.cpp
Normal file
|
@ -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();
|
||||
}
|
45
apps/openmw/mwgui/text_input.hpp
Normal file
45
apps/openmw/mwgui/text_input.hpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
#ifndef MWGUI_TEXT_INPUT_H
|
||||
#define MWGUI_TEXT_INPUT_H
|
||||
|
||||
#include <openengine/gui/layout.hpp>
|
||||
|
||||
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
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
2
extern/mygui_3.0.1/CMakeLists.txt
vendored
2
extern/mygui_3.0.1/CMakeLists.txt
vendored
|
@ -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)
|
||||
|
|
1
extern/mygui_3.0.1/openmw_resources/core.xml
vendored
1
extern/mygui_3.0.1/openmw_resources/core.xml
vendored
|
@ -12,6 +12,7 @@
|
|||
<List file="openmw_windows.skin.xml" group="General"/>
|
||||
<List file="openmw_button.skin.xml" group="General"/>
|
||||
<List file="openmw_list.skin.xml" group="General"/>
|
||||
<List file="openmw_edit.skin.xml" group="General"/>
|
||||
<List file="openmw_box.skin.xml" group="General"/>
|
||||
<List file="openmw_progress.skin.xml" group="General"/>
|
||||
<List file="openmw_hud_energybar.skin.xml" group="General"/>
|
||||
|
|
29
extern/mygui_3.0.1/openmw_resources/openmw_edit.skin.xml
vendored
Normal file
29
extern/mygui_3.0.1/openmw_resources/openmw_edit.skin.xml
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<MyGUI type="Skin">
|
||||
<!-- Text edit widget -->
|
||||
<Skin name = "MW_TextEditClient" size = "10 10">
|
||||
<Property key="FontName" value = "MyGUI_CoreFont.18"/>
|
||||
<Property key="FontHeight" value = "18" />
|
||||
<Property key="AlignText" value = "ALIGN_LEFT ALIGN_VCENTER" />
|
||||
<Property key="Colour" value = "0.6 0.6 0.6" />
|
||||
|
||||
<BasisSkin type="EditText" offset = "0 0 10 10" align = "Stretch"/>
|
||||
</Skin>
|
||||
<Skin name = "MW_TextEdit" size = "512 20" texture="mwgui.png">
|
||||
<BasisSkin type="SubSkin" offset = "0 0 512 2" align = "ALIGN_TOP ALIGN_HSTRETCH">
|
||||
<State name="normal" offset = "2 2 512 2"/>
|
||||
</BasisSkin>
|
||||
<BasisSkin type="SubSkin" offset = "0 2 2 16" align = "ALIGN_LEFT ALIGN_VSTRETCH">
|
||||
<State name="normal" offset = "2 4 2 16"/>
|
||||
</BasisSkin>
|
||||
<BasisSkin type="SubSkin" offset = "510 2 2 16" align = "ALIGN_RIGHT ALIGN_VSTRETCH">
|
||||
<State name="normal" offset = "512 4 2 16"/>
|
||||
</BasisSkin>
|
||||
<BasisSkin type="SubSkin" offset = "0 18 512 2" align = "ALIGN_BOTTOM ALIGN_HSTRETCH">
|
||||
<State name="normal" offset = "2 20 512 2"/>
|
||||
</BasisSkin>
|
||||
|
||||
<Child type="Widget" skin="MW_TextEditClient" offset = "2 2 508 18" align = "Stretch" name = "Client"/>
|
||||
</Skin>
|
||||
</MyGUI>
|
18
extern/mygui_3.0.1/openmw_resources/openmw_text_input_layout.xml
vendored
Normal file
18
extern/mygui_3.0.1/openmw_resources/openmw_text_input_layout.xml
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<MyGUI type="Layout">
|
||||
<!-- correct size is 320 97, adjust when skin is changed to a dialog -->
|
||||
<Widget type="Window" skin="MW_Window" layer="Windows" position="0 0 328 127" name="_Main">
|
||||
|
||||
<!-- Appearance -->
|
||||
<Widget type="StaticText" skin="ProgressText" position="10 12 300 18" name="LabelT" align="ALIGN_LEFT ALIGN_TOP">
|
||||
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
|
||||
</Widget>
|
||||
<Widget type="Edit" skin="MW_TextEdit" position="10 28 300 30" name="TextEdit" align="ALIGN_LEFT ALIGN_TOP"/>
|
||||
|
||||
<!-- Dialog buttons -->
|
||||
<Widget type="Button" skin="MW_Button" position="264 60 42 23" name="OKButton">
|
||||
<Property key="Widget_Caption" value="OK"/>
|
||||
</Widget>
|
||||
</Widget>
|
||||
</MyGUI>
|
Loading…
Reference in a new issue