mirror of https://github.com/OpenMW/openmw.git
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.
parent
85ded0edc3
commit
481734ee20
@ -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();
|
||||
}
|
@ -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
|
@ -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>
|
@ -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 New Issue