Skip to content

Commit

Permalink
Add imgui demo to the debug menu
Browse files Browse the repository at this point in the history
  • Loading branch information
moxian committed Dec 26, 2024
1 parent 0f016e4 commit bf62a05
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ std::string enum_to_string<debug_menu::debug_menu_index>( 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;
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/debug_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ enum class debug_menu_index : int {
EDIT_FACTION,
WRITE_CITY_LIST,
TALK_TOPIC,
IMGUI_DEMO,
last
};

Expand Down

0 comments on commit bf62a05

Please sign in to comment.