From bf62a057639aadafb643ebecf1b8fc1f87053090 Mon Sep 17 00:00:00 2001 From: moxian Date: Wed, 25 Dec 2024 22:38:41 -0800 Subject: [PATCH] Add imgui demo to the debug menu --- src/debug_menu.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++ src/debug_menu.h | 1 + 2 files changed, 66 insertions(+) diff --git a/src/debug_menu.cpp b/src/debug_menu.cpp index 9c67132912bef..ed8566922a552 100644 --- a/src/debug_menu.cpp +++ b/src/debug_menu.cpp @@ -272,6 +272,7 @@ std::string enum_to_string( debug_menu::debug_menu case debug_menu::debug_menu_index::EDIT_FACTION: return "EDIT_FACTION"; case debug_menu::debug_menu_index::WRITE_CITY_LIST: return "WRITE_CITY_LIST"; case debug_menu::debug_menu_index::TALK_TOPIC: return "TALK_TOPIC"; + case debug_menu::debug_menu_index::IMGUI_DEMO: return "IMGUI_DEMO"; // *INDENT-ON* case debug_menu::debug_menu_index::last: break; @@ -900,6 +901,7 @@ static int info_uilist( bool display_all_entries = true ) { uilist_entry( debug_menu_index::TEST_MAP_EXTRA_DISTRIBUTION, true, 'e', _( "Test map extra list" ) ) }, { uilist_entry( debug_menu_index::GENERATE_EFFECT_LIST, true, 'L', _( "Generate effect list" ) ) }, { uilist_entry( debug_menu_index::WRITE_CITY_LIST, true, 'C', _( "Write city list to cities.output" ) ) }, + { uilist_entry( debug_menu_index::IMGUI_DEMO, true, 'u', _( "Open ImGui demo screen" ) ) }, }; uilist_initializer.insert( uilist_initializer.begin(), debug_only_options.begin(), debug_only_options.end() ); @@ -3775,6 +3777,65 @@ static void wind_speed() } } +class demo_ui : public cataimgui::window +{ + public: + demo_ui(); + void init(); + void run(); + + protected: + void draw_controls() override; + cataimgui::bounds get_bounds() override; + void on_resized() override { + init(); + }; +}; +demo_ui::demo_ui() : cataimgui::window( _( "ImGui Demo Screen" ) ){} +cataimgui::bounds demo_ui::get_bounds() +{ + return { 0.0f, 0.0f, 0.0f, 0.0f }; +} +void demo_ui::draw_controls() +{ +#ifndef TUI + ImGui::ShowDemoWindow(); +#endif +} +void demo_ui::init() +{ + // The demo makes it's own screen. Don't get in the way + force_to_back = true; +} + +void demo_ui::run() +{ + init(); + + input_context ctxt( "HELP_KEYBINDINGS" ); + ctxt.register_action( "QUIT" ); + ctxt.register_action( "SELECT" ); + ctxt.register_action( "MOUSE_MOVE" ); + ctxt.register_action( "ANY_INPUT" ); + ctxt.register_action( "HELP_KEYBINDINGS" ); + std::string action; + + ui_manager::redraw(); + + while( is_open ) { + ui_manager::redraw(); + action = ctxt.handle_input( 5 ); + if( action == "QUIT" ) { + break; + } + } +} + +static void run_imgui_demo(){ + demo_ui demo; + demo.run(); +} + static void write_city_list() { write_to_file( "cities.output", [&]( std::ostream & testfile ) { @@ -4338,6 +4399,10 @@ void debug() write_city_list(); break; + case debug_menu_index::IMGUI_DEMO: + run_imgui_demo(); + break; + case debug_menu_index::TALK_TOPIC: display_talk_topic(); break; diff --git a/src/debug_menu.h b/src/debug_menu.h index 3bd1ec8649de2..13d4c0acbc8ab 100644 --- a/src/debug_menu.h +++ b/src/debug_menu.h @@ -113,6 +113,7 @@ enum class debug_menu_index : int { EDIT_FACTION, WRITE_CITY_LIST, TALK_TOPIC, + IMGUI_DEMO, last };