From ad80886844746d1dd0d3e9e06992375416410b64 Mon Sep 17 00:00:00 2001 From: Mercury233 Date: Fri, 24 Apr 2020 10:43:24 +0800 Subject: [PATCH] auto trim hostname and port when joining host (#2286) --- gframe/game.h | 6 ++++++ gframe/menu_handler.cpp | 2 ++ 2 files changed, 8 insertions(+) diff --git a/gframe/game.h b/gframe/game.h index d8b222e332..adafc09f47 100644 --- a/gframe/game.h +++ b/gframe/game.h @@ -164,6 +164,12 @@ class Game { return focus && focus->hasType(type); } + void TrimText(irr::gui::IGUIElement* editbox) const { + irr::core::stringw text(editbox->getText()); + text.trim(); + editbox->setText(text.c_str()); + } + void OnResize(); recti Resize(s32 x, s32 y, s32 x2, s32 y2); recti ResizeSizeOnly(s32 x, s32 y, s32 x2, s32 y2); diff --git a/gframe/menu_handler.cpp b/gframe/menu_handler.cpp index d87efe29a0..a512369632 100644 --- a/gframe/menu_handler.cpp +++ b/gframe/menu_handler.cpp @@ -57,6 +57,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { } case BUTTON_JOIN_HOST: { bot_mode = false; + mainGame->TrimText(mainGame->ebJoinHost); + mainGame->TrimText(mainGame->ebJoinPort); char ip[20]; const wchar_t* pstr = mainGame->ebJoinHost->getText(); BufferIO::CopyWStr(pstr, ip, 16);