1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2026-01-09 13:30:55 +00:00
openmw/apps/openmw/mwgui/textinput.cpp
2025-08-27 12:45:09 +02:00

101 lines
2.8 KiB
C++

#include "textinput.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
#include <MyGUI_Button.h>
#include <MyGUI_EditBox.h>
#include <MyGUI_UString.h>
#include <components/esm/refid.hpp>
namespace MWGui
{
TextInputDialog::TextInputDialog()
: WindowModal("openmw_text_input.layout")
{
// Centre dialog
center();
getWidget(mTextEdit, "TextEdit");
mTextEdit->eventEditSelectAccept += newDelegate(this, &TextInputDialog::onTextAccepted);
MyGUI::Button* okButton;
getWidget(okButton, "OKButton");
okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TextInputDialog::onOkClicked);
// Make sure the edit box has focus
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
mControllerButtons.mA = "#{Interface:OK}";
}
void TextInputDialog::setNextButtonShow(bool shown)
{
MyGUI::Button* okButton;
getWidget(okButton, "OKButton");
if (shown)
okButton->setCaption(
MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", {})));
else
okButton->setCaption(
MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", {})));
}
void TextInputDialog::setTextLabel(std::string_view label)
{
setText("LabelT", label);
}
void TextInputDialog::onOpen()
{
WindowModal::onOpen();
// Make sure the edit box has focus
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
}
// widget controls
void TextInputDialog::onOkClicked(MyGUI::Widget* /*sender*/)
{
if (mTextEdit->getCaption().empty())
{
MWBase::Environment::get().getWindowManager()->messageBox("#{sNotifyMessage37}");
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
}
else
eventDone(this);
}
void TextInputDialog::onTextAccepted(MyGUI::EditBox* sender)
{
onOkClicked(sender);
// To do not spam onTextAccepted() again and again
MWBase::Environment::get().getWindowManager()->injectKeyRelease(MyGUI::KeyCode::None);
}
std::string TextInputDialog::getTextInput() const
{
return mTextEdit->getCaption();
}
void TextInputDialog::setTextInput(const std::string& text)
{
mTextEdit->setCaption(text);
}
bool TextInputDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
{
if (arg.button == SDL_CONTROLLER_BUTTON_A)
{
onOkClicked(nullptr);
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
return true;
}
return false;
}
}