2013-04-10 04:32:05 +00:00
|
|
|
#include "textinput.hpp"
|
|
|
|
|
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
|
2015-01-10 01:50:43 +00:00
|
|
|
#include <MyGUI_EditBox.h>
|
|
|
|
#include <MyGUI_Button.h>
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
namespace MWGui
|
2013-04-10 04:32:05 +00:00
|
|
|
{
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
TextInputDialog::TextInputDialog()
|
|
|
|
: WindowModal("openmw_text_input.layout")
|
|
|
|
{
|
|
|
|
// Centre dialog
|
|
|
|
center();
|
2013-04-10 04:32:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
getWidget(mTextEdit, "TextEdit");
|
|
|
|
mTextEdit->eventEditSelectAccept += newDelegate(this, &TextInputDialog::onTextAccepted);
|
2013-04-10 04:32:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
MyGUI::Button* okButton;
|
|
|
|
getWidget(okButton, "OKButton");
|
|
|
|
okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TextInputDialog::onOkClicked);
|
2013-04-10 04:32:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
// Make sure the edit box has focus
|
2019-06-08 23:08:09 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
2013-04-10 04:32:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void TextInputDialog::setNextButtonShow(bool shown)
|
|
|
|
{
|
|
|
|
MyGUI::Button* okButton;
|
|
|
|
getWidget(okButton, "OKButton");
|
2013-04-10 04:32:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
if (shown)
|
|
|
|
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", ""));
|
|
|
|
else
|
|
|
|
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", ""));
|
|
|
|
}
|
2013-04-10 04:32:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void TextInputDialog::setTextLabel(const std::string &label)
|
|
|
|
{
|
|
|
|
setText("LabelT", label);
|
|
|
|
}
|
|
|
|
|
2017-09-22 15:10:53 +00:00
|
|
|
void TextInputDialog::onOpen()
|
2013-04-17 22:56:48 +00:00
|
|
|
{
|
2017-09-22 15:10:53 +00:00
|
|
|
WindowModal::onOpen();
|
2013-04-17 22:56:48 +00:00
|
|
|
// Make sure the edit box has focus
|
2019-06-08 23:08:09 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
2013-04-10 04:32:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
// widget controls
|
2013-04-10 04:32:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void TextInputDialog::onOkClicked(MyGUI::Widget* _sender)
|
2013-04-10 04:32:05 +00:00
|
|
|
{
|
2017-08-19 10:31:25 +00:00
|
|
|
if (mTextEdit->getCaption() == "")
|
2013-04-17 22:56:48 +00:00
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage37}");
|
2019-06-08 23:08:09 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget (mTextEdit);
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
eventDone(this);
|
2013-04-10 04:32:05 +00:00
|
|
|
}
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void TextInputDialog::onTextAccepted(MyGUI::Edit* _sender)
|
2013-04-10 04:32:05 +00:00
|
|
|
{
|
2014-12-23 18:51:17 +00:00
|
|
|
onOkClicked(_sender);
|
2018-09-10 08:55:00 +00:00
|
|
|
|
|
|
|
// To do not spam onTextAccepted() again and again
|
|
|
|
MWBase::Environment::get().getWindowManager()->injectKeyRelease(MyGUI::KeyCode::None);
|
2013-04-10 04:32:05 +00:00
|
|
|
}
|
2013-04-17 22:56:48 +00:00
|
|
|
|
2015-01-10 01:50:43 +00:00
|
|
|
std::string TextInputDialog::getTextInput() const
|
|
|
|
{
|
2017-08-19 10:31:25 +00:00
|
|
|
return mTextEdit->getCaption();
|
2015-01-10 01:50:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextInputDialog::setTextInput(const std::string &text)
|
|
|
|
{
|
|
|
|
mTextEdit->setCaption(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-10 04:32:05 +00:00
|
|
|
}
|