1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-22 23:33:04 +01:00

Fix #19935: Part of old multiplayer name remains when entering a shorter name (#20004)

* clear _playerName

* Change _playerName to a u8string

* Explicitly set underlying string ptr on change
This commit is contained in:
Chase
2023-04-26 15:34:39 +08:00
committed by GitHub
parent c96762517f
commit d6ebeca483
3 changed files with 13 additions and 16 deletions

View File

@@ -33,6 +33,8 @@
# define WHEIGHT_MAX 800
# define ITEM_HEIGHT (3 + 9 + 3)
constexpr size_t MaxPlayerNameLength = 32;
enum
{
WIDX_BACKGROUND,
@@ -76,7 +78,7 @@ void JoinServer(std::string address);
class ServerListWindow final : public Window
{
private:
char _playerName[32 + 1] = {};
u8string _playerName;
ServerList _serverList;
std::future<std::tuple<std::vector<ServerListEntry>, StringId>> _fetchFuture;
uint32_t _numPlayersOnline = 0;
@@ -90,7 +92,8 @@ public:
void OnOpen() override
{
window_server_list_widgets[WIDX_PLAYER_NAME_INPUT].string = _playerName;
_playerName = gConfigNetwork.PlayerName;
window_server_list_widgets[WIDX_PLAYER_NAME_INPUT].string = const_cast<utf8*>(_playerName.c_str());
widgets = window_server_list_widgets;
InitScrollWidgets();
no_list_items = 0;
@@ -106,8 +109,6 @@ public:
WindowSetResize(*this, WWIDTH_MIN, WHEIGHT_MIN, WWIDTH_MAX, WHEIGHT_MAX);
SafeStrCpy(_playerName, gConfigNetwork.PlayerName.c_str(), sizeof(_playerName));
no_list_items = static_cast<uint16_t>(_serverList.GetCount());
ServerListFetchServersBegin();
@@ -117,6 +118,7 @@ public:
{
_serverList = {};
_fetchFuture = {};
ConfigSaveDefault();
}
void OnMouseUp(WidgetIndex widgetIndex) override
@@ -127,7 +129,7 @@ public:
Close();
break;
case WIDX_PLAYER_NAME_INPUT:
WindowStartTextbox(*this, widgetIndex, STR_STRING, _playerName, 63);
WindowStartTextbox(*this, widgetIndex, STR_STRING, _playerName.c_str(), MaxPlayerNameLength);
break;
case WIDX_LIST:
{
@@ -267,7 +269,7 @@ public:
if (text.empty())
return;
std::string temp = static_cast<std::string>(text);
auto temp = u8string{ text };
switch (widgetIndex)
{
@@ -275,14 +277,9 @@ public:
if (_playerName == text)
return;
text.copy(_playerName, sizeof(_playerName));
// Don't allow empty player names
if (_playerName[0] != '\0')
{
gConfigNetwork.PlayerName = _playerName;
ConfigSaveDefault();
}
_playerName = temp;
gConfigNetwork.PlayerName = _playerName;
window_server_list_widgets[WIDX_PLAYER_NAME_INPUT].string = const_cast<utf8*>(_playerName.c_str());
InvalidateWidget(WIDX_PLAYER_NAME_INPUT);
break;

View File

@@ -1973,7 +1973,7 @@ void TextinputCancel()
}
void WindowStartTextbox(
WindowBase& call_w, WidgetIndex call_widget, StringId existing_text, char* existing_args, int32_t maxLength)
WindowBase& call_w, WidgetIndex call_widget, StringId existing_text, const char* existing_args, int32_t maxLength)
{
if (gUsingWidgetTextBox)
WindowCancelTextbox();

View File

@@ -723,7 +723,7 @@ void WindowMoveAndSnap(WindowBase& w, ScreenCoordsXY newWindowCoords, int32_t sn
int32_t WindowCanResize(const WindowBase& w);
void WindowStartTextbox(
WindowBase& call_w, WidgetIndex call_widget, StringId existing_text, char* existing_args, int32_t maxLength);
WindowBase& call_w, WidgetIndex call_widget, StringId existing_text, const char* existing_args, int32_t maxLength);
void WindowCancelTextbox();
void WindowUpdateTextboxCaret();
void WindowUpdateTextbox();