1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 21:32:42 +00:00
OpenMW/apps/openmw/mwgui/textinput.cpp

88 lines
2.4 KiB
C++
Raw Normal View History

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