Simplify setting existing text

This commit is contained in:
duncanspumpkin 2024-03-22 08:53:22 +00:00 committed by Gymnasiast
parent 3448926251
commit bd3ae5cbb9
No known key found for this signature in database
GPG Key ID: DBFFF47AB2CA3EDD
9 changed files with 17 additions and 30 deletions

View File

@ -25,7 +25,6 @@
#include <openrct2/entity/EntityRegistry.h>
#include <openrct2/interface/Widget.h>
#include <openrct2/localisation/Formatter.h>
#include <openrct2/localisation/Formatting.h>
#include <openrct2/localisation/StringIds.h>
#include <openrct2/sprites.h>
#include <openrct2/ui/UiContext.h>
@ -867,31 +866,22 @@ namespace OpenRCT2::Ui::Windows
return window.classification;
}
void WindowStartTextbox(
WindowBase& call_w, WidgetIndex call_widget, StringId existing_text, const char* existing_args, int32_t maxLength)
void WindowStartTextbox(const WindowBase& callW, WidgetIndex callWidget, u8string existingText, int32_t maxLength)
{
if (_usingWidgetTextBox)
WindowCancelTextbox();
_usingWidgetTextBox = true;
_currentTextBox.window.classification = call_w.classification;
_currentTextBox.window.number = call_w.number;
_currentTextBox.widget_index = call_widget;
_currentTextBox.window.classification = callW.classification;
_currentTextBox.window.number = callW.number;
_currentTextBox.widget_index = callWidget;
_textBoxFrameNo = 0;
WindowCloseByClass(WindowClass::Textinput);
// Clear the text input buffer
_textBoxInput.clear();
// Enter in the text input buffer any existing
// text.
if (existing_text != STR_NONE)
{
char tempBuf[TEXT_INPUT_SIZE]{};
size_t len = FormatStringLegacy(tempBuf, TEXT_INPUT_SIZE, existing_text, &existing_args);
_textBoxInput.assign(tempBuf, len);
}
_textBoxInput = existingText;
_textInput = ContextStartTextInput(_textBoxInput, maxLength);
}

View File

@ -76,8 +76,7 @@ namespace OpenRCT2::Ui::Windows
WindowBase* WindowGetListening();
WindowClass WindowGetClassification(const WindowBase& window);
void WindowStartTextbox(
WindowBase& call_w, WidgetIndex call_widget, StringId existing_text, const char* existing_args, int32_t maxLength);
void WindowStartTextbox(const WindowBase& callW, WidgetIndex callWidget, u8string existingText, int32_t maxLength);
void WindowCancelTextbox();
void WindowUpdateTextboxCaret();
void WindowUpdateTextbox();

View File

@ -653,8 +653,7 @@ namespace OpenRCT2::Ui::Windows
}
else if (widgetDesc->Type == "textbox")
{
auto* text = const_cast<char*>(widgetDesc->Text.c_str());
WindowStartTextbox(*this, widgetIndex, STR_STRING, text, widgetDesc->MaxLength + 1);
WindowStartTextbox(*this, widgetIndex, widgetDesc->Text, widgetDesc->MaxLength + 1);
}
}
}

View File

@ -422,7 +422,7 @@ static std::vector<Widget> _window_editor_object_selection_widgets = {
break;
}
case WIDX_FILTER_TEXT_BOX:
WindowStartTextbox(*this, widgetIndex, STR_STRING, _filter_string, sizeof(_filter_string));
WindowStartTextbox(*this, widgetIndex, _filter_string, sizeof(_filter_string));
break;
case WIDX_FILTER_CLEAR_BUTTON:
std::fill_n(_filter_string, sizeof(_filter_string), 0x00);

View File

@ -370,7 +370,7 @@ static Widget window_new_ride_widgets[] = {
SetPage(_currentTab);
break;
case WIDX_FILTER_TEXT_BOX:
WindowStartTextbox(*this, widgetIndex, STR_STRING, _filter.data(), kTextInputSize);
WindowStartTextbox(*this, widgetIndex, _filter, kTextInputSize);
break;
case WIDX_FILTER_CLEAR_BUTTON:
_filter.clear();

View File

@ -276,7 +276,7 @@ static Widget WindowSceneryBaseWidgets[] = {
Invalidate();
break;
case WIDX_FILTER_TEXT_BOX:
WindowStartTextbox(*this, widgetIndex, STR_STRING, _filteredSceneryTab.Filter.data(), kTextInputSize);
WindowStartTextbox(*this, widgetIndex, _filteredSceneryTab.Filter, kTextInputSize);
break;
case WIDX_FILTER_CLEAR_BUTTON:
_tabEntries[_activeTabIndex].Filter.clear();

View File

@ -131,7 +131,7 @@ static Widget _serverListWidgets[] = {
Close();
break;
case WIDX_PLAYER_NAME_INPUT:
WindowStartTextbox(*this, widgetIndex, STR_STRING, _playerName.c_str(), MaxPlayerNameLength);
WindowStartTextbox(*this, widgetIndex, _playerName, MaxPlayerNameLength);
break;
case WIDX_LIST:
{

View File

@ -95,19 +95,19 @@ static Widget _windowServerStartWidgets[] = {
Close();
break;
case WIDX_PORT_INPUT:
WindowStartTextbox(*this, widgetIndex, STR_STRING, _port, 6);
WindowStartTextbox(*this, widgetIndex, _port, 6);
break;
case WIDX_NAME_INPUT:
WindowStartTextbox(*this, widgetIndex, STR_STRING, _name, 64);
WindowStartTextbox(*this, widgetIndex, _name, 64);
break;
case WIDX_DESCRIPTION_INPUT:
WindowStartTextbox(*this, widgetIndex, STR_STRING, _description, MAX_SERVER_DESCRIPTION_LENGTH);
WindowStartTextbox(*this, widgetIndex, _description, MAX_SERVER_DESCRIPTION_LENGTH);
break;
case WIDX_GREETING_INPUT:
WindowStartTextbox(*this, widgetIndex, STR_STRING, _greeting, kChatInputSize);
WindowStartTextbox(*this, widgetIndex, _greeting, kChatInputSize);
break;
case WIDX_PASSWORD_INPUT:
WindowStartTextbox(*this, widgetIndex, STR_STRING, _password, 32);
WindowStartTextbox(*this, widgetIndex, _password, 32);
break;
case WIDX_MAXPLAYERS_INCREASE:
if (gConfigNetwork.Maxplayers < 255)

View File

@ -297,8 +297,7 @@ static Widget _trackListWidgets[] = {
}
break;
case WIDX_FILTER_STRING:
WindowStartTextbox(
*this, widgetIndex, STR_STRING, _filterString, sizeof(_filterString)); // TODO check this out
WindowStartTextbox(*this, widgetIndex, _filterString, sizeof(_filterString)); // TODO check this out
break;
case WIDX_FILTER_CLEAR:
// Keep the highlighted item selected