From 212b29f90e3dfd2a458d1cba0f5b9e615fbe807d Mon Sep 17 00:00:00 2001 From: Zhilkin Serg Date: Wed, 4 Dec 2024 16:47:19 +0300 Subject: [PATCH] Fixes to score menu --- data/raw/keybindings.json | 14 ++++++++++++++ src/scores_ui.cpp | 31 ++++++++++++++++++++----------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/data/raw/keybindings.json b/data/raw/keybindings.json index 5ef4601f89e2f..98328721ff176 100644 --- a/data/raw/keybindings.json +++ b/data/raw/keybindings.json @@ -4861,6 +4861,20 @@ { "input_method": "keyboard_code", "mod": [ "ctrl" ], "key": "y" } ] }, + { + "type": "keybinding", + "id": "TOGGLE_MONSTER_GROUP", + "category": "SCORE_UI", + "name": "Toggle monster group", + "bindings": [ { "input_method": "keyboard_any", "key": "m" } ] + }, + { + "type": "keybinding", + "id": "TOGGLE_NPC_GROUP", + "category": "SCORE_UI", + "name": "Toggle NPC group", + "bindings": [ { "input_method": "keyboard_any", "key": "n" } ] + }, { "type": "keybinding", "id": "HELP_KEYBINDINGS", diff --git a/src/scores_ui.cpp b/src/scores_ui.cpp index 46b5610514d41..8a13d9ad1dcc0 100644 --- a/src/scores_ui.cpp +++ b/src/scores_ui.cpp @@ -76,8 +76,11 @@ class scores_ui_impl : public cataimgui::window scores_ui_tab_enum selected_tab = scores_ui_tab_enum::achievements; scores_ui_tab_enum switch_tab = scores_ui_tab_enum::num_tabs; - size_t window_width = ImGui::GetMainViewport()->Size.x / 3.0 * 2.0; - size_t window_height = ImGui::GetMainViewport()->Size.y / 3.0 * 2.0; + size_t window_width = ImGui::GetMainViewport()->Size.x * 8 / 9; + size_t window_height = ImGui::GetMainViewport()->Size.y * 8 / 9; + + bool monster_group_collapsed = false; + bool npc_group_collapsed = false; protected: void draw_controls() override; @@ -85,11 +88,13 @@ class scores_ui_impl : public cataimgui::window void scores_ui::draw_scores_ui() { - input_context ctxt; + input_context ctxt( "SCORE_UI" ); scores_ui_impl p_impl; ctxt.register_navigate_ui_list(); ctxt.register_leftright(); + ctxt.register_action( "TOGGLE_MONSTER_GROUP" ); + ctxt.register_action( "TOGGLE_NPC_GROUP" ); ctxt.register_action( "NEXT_TAB" ); ctxt.register_action( "PREV_TAB" ); ctxt.register_action( "SELECT" ); @@ -197,7 +202,7 @@ void scores_ui_impl::draw_kills_text() } if( ImGui::CollapsingHeader( string_format( _( "Monster kills (%d):" ), monster_kills ).c_str(), - ImGuiTreeNodeFlags_DefaultOpen ) ) { + monster_group_collapsed ? ImGuiTreeNodeFlags_None : ImGuiTreeNodeFlags_DefaultOpen ) ) { if( monster_kills == 0 ) { ImGui::TextWrapped( "%s", _( "You haven't killed any monsters yet!" ) ); } else { @@ -219,7 +224,7 @@ void scores_ui_impl::draw_kills_text() } } if( ImGui::CollapsingHeader( string_format( _( "NPC kills (%d):" ), npc_kills ).c_str(), - ImGuiTreeNodeFlags_DefaultOpen ) ) { + npc_group_collapsed ? ImGuiTreeNodeFlags_None : ImGuiTreeNodeFlags_DefaultOpen ) ) { if( npc_kills == 0 ) { ImGui::TextWrapped( "%s", _( "You haven't killed any NPCs yet!" ) ); } else { @@ -242,22 +247,26 @@ void scores_ui_impl::draw_controls() if( last_action == "QUIT" ) { return; + } else if( last_action == "TOGGLE_MONSTER_GROUP" ) { + monster_group_collapsed = !monster_group_collapsed; + } else if( last_action == "TOGGLE_NPC_GROUP" ) { + npc_group_collapsed = !npc_group_collapsed; } else if( last_action == "UP" ) { - ImGui::SetKeyboardFocusHere( -1 ); + ImGui::SetScrollY( ImGui::GetScrollY() - ImGui::GetTextLineHeightWithSpacing() ); } else if( last_action == "DOWN" ) { - ImGui::SetKeyboardFocusHere( 1 ); + ImGui::SetScrollY( ImGui::GetScrollY() + ImGui::GetTextLineHeightWithSpacing() ); } else if( last_action == "NEXT_TAB" || last_action == "RIGHT" ) { + ImGui::SetScrollY( 0 ); switch_tab = selected_tab; ++switch_tab; } else if( last_action == "PREV_TAB" || last_action == "LEFT" ) { + ImGui::SetScrollY( 0 ); switch_tab = selected_tab; --switch_tab; } else if( last_action == "PAGE_UP" ) { - ImGui::SetWindowFocus(); // Dumb hack! Clear our focused item so listbox selection isn't nav highlighted. - ImGui::SetScrollY( ImGui::GetScrollY() - ( window_height / 5.0f ) ); + ImGui::SetScrollY( ImGui::GetScrollY() - window_height ); } else if( last_action == "PAGE_DOWN" ) { - ImGui::SetWindowFocus(); // Dumb hack! Clear our focused item so listbox selection isn't nav highlighted. - ImGui::SetScrollY( ImGui::GetScrollY() + ( window_height / 5.0f ) ); + ImGui::SetScrollY( ImGui::GetScrollY() + window_height ); } ImGuiTabItemFlags_ flags = ImGuiTabItemFlags_None;