mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 15:52:55 +01:00
* clear _playerName * Change _playerName to a u8string * Explicitly set underlying string ptr on change
This commit is contained in:
@@ -33,6 +33,8 @@
|
|||||||
# define WHEIGHT_MAX 800
|
# define WHEIGHT_MAX 800
|
||||||
# define ITEM_HEIGHT (3 + 9 + 3)
|
# define ITEM_HEIGHT (3 + 9 + 3)
|
||||||
|
|
||||||
|
constexpr size_t MaxPlayerNameLength = 32;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
WIDX_BACKGROUND,
|
WIDX_BACKGROUND,
|
||||||
@@ -76,7 +78,7 @@ void JoinServer(std::string address);
|
|||||||
class ServerListWindow final : public Window
|
class ServerListWindow final : public Window
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
char _playerName[32 + 1] = {};
|
u8string _playerName;
|
||||||
ServerList _serverList;
|
ServerList _serverList;
|
||||||
std::future<std::tuple<std::vector<ServerListEntry>, StringId>> _fetchFuture;
|
std::future<std::tuple<std::vector<ServerListEntry>, StringId>> _fetchFuture;
|
||||||
uint32_t _numPlayersOnline = 0;
|
uint32_t _numPlayersOnline = 0;
|
||||||
@@ -90,7 +92,8 @@ public:
|
|||||||
|
|
||||||
void OnOpen() override
|
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;
|
widgets = window_server_list_widgets;
|
||||||
InitScrollWidgets();
|
InitScrollWidgets();
|
||||||
no_list_items = 0;
|
no_list_items = 0;
|
||||||
@@ -106,8 +109,6 @@ public:
|
|||||||
|
|
||||||
WindowSetResize(*this, WWIDTH_MIN, WHEIGHT_MIN, WWIDTH_MAX, WHEIGHT_MAX);
|
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());
|
no_list_items = static_cast<uint16_t>(_serverList.GetCount());
|
||||||
|
|
||||||
ServerListFetchServersBegin();
|
ServerListFetchServersBegin();
|
||||||
@@ -117,6 +118,7 @@ public:
|
|||||||
{
|
{
|
||||||
_serverList = {};
|
_serverList = {};
|
||||||
_fetchFuture = {};
|
_fetchFuture = {};
|
||||||
|
ConfigSaveDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseUp(WidgetIndex widgetIndex) override
|
void OnMouseUp(WidgetIndex widgetIndex) override
|
||||||
@@ -127,7 +129,7 @@ public:
|
|||||||
Close();
|
Close();
|
||||||
break;
|
break;
|
||||||
case WIDX_PLAYER_NAME_INPUT:
|
case WIDX_PLAYER_NAME_INPUT:
|
||||||
WindowStartTextbox(*this, widgetIndex, STR_STRING, _playerName, 63);
|
WindowStartTextbox(*this, widgetIndex, STR_STRING, _playerName.c_str(), MaxPlayerNameLength);
|
||||||
break;
|
break;
|
||||||
case WIDX_LIST:
|
case WIDX_LIST:
|
||||||
{
|
{
|
||||||
@@ -267,7 +269,7 @@ public:
|
|||||||
if (text.empty())
|
if (text.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::string temp = static_cast<std::string>(text);
|
auto temp = u8string{ text };
|
||||||
|
|
||||||
switch (widgetIndex)
|
switch (widgetIndex)
|
||||||
{
|
{
|
||||||
@@ -275,14 +277,9 @@ public:
|
|||||||
if (_playerName == text)
|
if (_playerName == text)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
text.copy(_playerName, sizeof(_playerName));
|
_playerName = temp;
|
||||||
|
|
||||||
// Don't allow empty player names
|
|
||||||
if (_playerName[0] != '\0')
|
|
||||||
{
|
|
||||||
gConfigNetwork.PlayerName = _playerName;
|
gConfigNetwork.PlayerName = _playerName;
|
||||||
ConfigSaveDefault();
|
window_server_list_widgets[WIDX_PLAYER_NAME_INPUT].string = const_cast<utf8*>(_playerName.c_str());
|
||||||
}
|
|
||||||
|
|
||||||
InvalidateWidget(WIDX_PLAYER_NAME_INPUT);
|
InvalidateWidget(WIDX_PLAYER_NAME_INPUT);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1973,7 +1973,7 @@ void TextinputCancel()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WindowStartTextbox(
|
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)
|
if (gUsingWidgetTextBox)
|
||||||
WindowCancelTextbox();
|
WindowCancelTextbox();
|
||||||
|
|||||||
@@ -723,7 +723,7 @@ void WindowMoveAndSnap(WindowBase& w, ScreenCoordsXY newWindowCoords, int32_t sn
|
|||||||
int32_t WindowCanResize(const WindowBase& w);
|
int32_t WindowCanResize(const WindowBase& w);
|
||||||
|
|
||||||
void WindowStartTextbox(
|
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 WindowCancelTextbox();
|
||||||
void WindowUpdateTextboxCaret();
|
void WindowUpdateTextboxCaret();
|
||||||
void WindowUpdateTextbox();
|
void WindowUpdateTextbox();
|
||||||
|
|||||||
Reference in New Issue
Block a user