1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 22:19:54 +00:00
openmw-tes3mp/apps/openmw/mwgui/textinput.cpp

85 lines
2.3 KiB
C++
Raw Normal View History

#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-17 22:56:48 +00:00
TextInputDialog::TextInputDialog()
: WindowModal("openmw_text_input.layout")
{
// Centre dialog
center();
2013-04-17 22:56:48 +00:00
getWidget(mTextEdit, "TextEdit");
mTextEdit->eventEditSelectAccept += newDelegate(this, &TextInputDialog::onTextAccepted);
2013-04-17 22:56:48 +00:00
MyGUI::Button* okButton;
getWidget(okButton, "OKButton");
okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TextInputDialog::onOkClicked);
2013-04-17 22:56:48 +00:00
// Make sure the edit box has focus
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
2013-04-17 22:56:48 +00:00
}
2013-04-17 22:56:48 +00:00
void TextInputDialog::setNextButtonShow(bool shown)
{
MyGUI::Button* okButton;
getWidget(okButton, "OKButton");
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-17 22:56:48 +00:00
void TextInputDialog::setTextLabel(const std::string &label)
{
setText("LabelT", label);
}
void TextInputDialog::onOpen()
2013-04-17 22:56:48 +00:00
{
WindowModal::onOpen();
2013-04-17 22:56:48 +00:00
// Make sure the edit box has focus
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
2013-04-17 22:56:48 +00:00
}
2013-04-17 22:56:48 +00:00
// widget controls
2013-04-17 22:56:48 +00:00
void TextInputDialog::onOkClicked(MyGUI::Widget* _sender)
{
if (mTextEdit->getCaption() == "")
2013-04-17 22:56:48 +00:00
{
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage37}");
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget (mTextEdit);
2013-04-17 22:56:48 +00:00
}
else
eventDone(this);
}
2013-04-17 22:56:48 +00:00
void TextInputDialog::onTextAccepted(MyGUI::Edit* _sender)
{
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-17 22:56:48 +00:00
2015-01-10 01:50:43 +00:00
std::string TextInputDialog::getTextInput() const
{
return mTextEdit->getCaption();
2015-01-10 01:50:43 +00:00
}
void TextInputDialog::setTextInput(const std::string &text)
{
mTextEdit->setCaption(text);
}
}