From 3109a8ea754ad7279635bb6a0c74293fefb2db3e Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Fri, 9 Dec 2022 13:01:33 +0300 Subject: [PATCH] Improved player name entry in high score dialog. Issue #165. --- SpaceCadetPinball/high_score.cpp | 18 +++++++++++++++--- SpaceCadetPinball/pb.cpp | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/SpaceCadetPinball/high_score.cpp b/SpaceCadetPinball/high_score.cpp index e2c48ce..db05c5d 100644 --- a/SpaceCadetPinball/high_score.cpp +++ b/SpaceCadetPinball/high_score.cpp @@ -145,7 +145,7 @@ void high_score::RenderHighScoreDialog() } } - bool unused_open = true; + bool unused_open = true, textBoxSubmit = false; if (ImGui::BeginPopupModal(pb::get_rc_string(Msg::HIGHSCORES_Caption), &unused_open, ImGuiWindowFlags_AlwaysAutoResize)) { if (ImGui::BeginTable("table1", 3, ImGuiTableFlags_Borders)) @@ -171,7 +171,19 @@ void high_score::RenderHighScoreDialog() offset = -1; score = DlgData.Entry.Score; ImGui::PushItemWidth(200); - ImGui::InputText("", DlgData.Entry.Name, IM_ARRAYSIZE(DlgData.Entry.Name)); + + static bool doubleFocus = false; + if (ImGui::IsWindowAppearing() || doubleFocus) + { + // Hack - set focus only works on the second time. + ImGui::SetKeyboardFocusHere(0); + doubleFocus ^= true; + } + if (ImGui::InputText("", DlgData.Entry.Name, IM_ARRAYSIZE(DlgData.Entry.Name), + ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) + { + textBoxSubmit = true; + } } else { @@ -185,7 +197,7 @@ void high_score::RenderHighScoreDialog() ImGui::EndTable(); } - if (ImGui::Button(pb::get_rc_string(Msg::HIGHSCORES_Ok))) + if (ImGui::Button(pb::get_rc_string(Msg::HIGHSCORES_Ok)) || textBoxSubmit) { if (dlg_enter_name) { diff --git a/SpaceCadetPinball/pb.cpp b/SpaceCadetPinball/pb.cpp index aea13ba..c4a93ae 100644 --- a/SpaceCadetPinball/pb.cpp +++ b/SpaceCadetPinball/pb.cpp @@ -562,7 +562,7 @@ void pb::end_game() if (position >= 0) { high_score_struct entry{ {0}, scores[i] }; - const char* playerName = "Player"; + const char* playerName; switch(scoreIndex[i]) {