From e89090a282c1ac494f38363528032a4a05ca4ce5 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Sat, 14 Dec 2024 00:56:47 +0000 Subject: [PATCH] Make suggested changes --- src/help.cpp | 178 ++++++++++++++++++++++++++++++++++++--------------- src/help.h | 8 +-- 2 files changed, 130 insertions(+), 56 deletions(-) diff --git a/src/help.cpp b/src/help.cpp index 6cb8325206ce8..78f4a2b458127 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -101,24 +101,26 @@ std::string help_window::get_dir_grid() return movement; } -std::string help_window::get_note_colors() +void help_window::note_colors() { - std::string text = _( "Note colors: " ); + ImGui::Text( _( "Note colors: " ) ); + ImGui::SameLine( 0.f, 0.f ); for( const auto &color_pair : get_note_color_names() ) { // The color index is not translatable, but the name is. //~ %1$s: note color abbreviation, %2$s: note color name - text += string_format( pgettext( "note color", "%1$s:%2$s, " ), - colorize( color_pair.first, color_pair.second.color ), - color_pair.second.name ); + cataimgui::TextColoredParagraph( c_white, string_format( pgettext( "note color", "%1$s:%2$s, " ), + colorize( color_pair.first, color_pair.second.color ), + color_pair.second.name ) ); + // TODO: Has a stray comma at the end + ImGui::SameLine( 0.f, 0.f ); } - - return text; } help_window::help_window() : cataimgui::window( "help", ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse ) { + // TODO: ImGui auto arrow key handling doesn't work with ImTui ctxt = input_context( "DISPLAY_HELP", keyboard_mode::keychar ); ctxt.register_action( "QUIT" ); ctxt.register_action( "CONFIRM" ); @@ -155,7 +157,7 @@ void help_window::draw_category_selection() //~ Help menu header format_title( _( "Help" ) ); // Split the categories in half - if( ImGui::BeginTable( "Category Options", 3, ImGuiTableFlags_None ) ) { + if( ImGui::BeginTable( "Category Options", 2, ImGuiTableFlags_None ) ) { ImGui::TableSetupColumn( "Left Column", ImGuiTableColumnFlags_WidthStretch, static_cast( window_width / 2.0f ) ); ImGui::TableSetupColumn( "Right Column", ImGuiTableColumnFlags_WidthStretch, @@ -166,7 +168,6 @@ void help_window::draw_category_selection() auto jt = data.help_categories.begin(); std::advance( jt, half_size ); for( auto it = data.help_categories.begin(); it != half_it; it++, jt++ ) { - ImGui::TableNextRow(); ImGui::TableNextColumn(); draw_category_option( it->first, it->second ); ImGui::TableNextColumn(); @@ -199,46 +200,111 @@ void help_window::draw_category_option( const int &option, const help_category & } } -std::string help_window::seperator( int length, char c ) -{ - std::string ret = ""; - ret += std::string( length, c ); - ret += ""; - return ret; -} - void help_window::format_title( const std::string translated_category_name ) { - cataimgui::PushMonoFont(); if( get_option( "SCREEN_READER_MODE" ) ) { - cataimgui::draw_colored_text( translated_category_name ); + cataimgui::TextColoredParagraph( c_white, translated_category_name ); ImGui::NewLine(); return; } - std::string row3 = "║ "; - row3 += translated_category_name; - row3 += " ║"; - std::string div = seperator( remove_color_tags( row3 ).length() - 4, '=' ); - cataimgui::draw_colored_text( div ); - cataimgui::draw_colored_text( row3 ); - cataimgui::draw_colored_text( div ); - cataimgui::draw_colored_text( seperator( TERMX, '_' ) ); - ImGui::NewLine(); + const float title_length = ImGui::CalcTextSize( remove_color_tags( + translated_category_name ).c_str() ).x; + cataimgui::PushMonoFont(); + const int sep_len = std::ceil( ( title_length / ImGui::CalcTextSize( "═" ).x ) + 2 ); + ImGui::PushStyleColor( ImGuiCol_Text, c_light_blue ); + + ImGui::Text( "╔" ); + ImGui::SameLine( 0.f, 0.f ); + for( int i = sep_len; i > 0; i-- ) { + ImGui::Text( "═" ); + ImGui::SameLine( 0.f, 0.f ); + } + ImGui::Text( "╗" ); + // Using the matching box character doesn't look good bc there's forced(?) y spacing on NewLine + ImGui::Text( "┇ " ); + ImGui::SameLine( 0.f, 0.f ); + ImGui::PopStyleColor(); ImGui::PopFont(); + cataimgui::TextColoredParagraph( c_white, translated_category_name ); + cataimgui::PushMonoFont(); + ImGui::SameLine( 0.f, 0.f ); + ImGui::PushStyleColor( ImGuiCol_Text, c_light_blue ); + ImGui::Text( " ┇" ); + ImGui::Text( "╚" ); + ImGui::SameLine( 0.f, 0.f ); + for( int i = sep_len; i > 0; i-- ) { + ImGui::Text( "═" ); + ImGui::SameLine( 0.f, 0.f ); + } + ImGui::Text( "╝" ); + ImGui::PopStyleColor(); + ImGui::PopFont(); + ImGui::NewLine(); + ImGui::PushStyleColor( ImGuiCol_Separator, c_light_blue ); + ImGui::Separator(); + ImGui::PopStyleColor(); + ImGui::NewLine(); } +//void help_window::format_subtitle( const std::string translated_category_name ) +//{ +// if( get_option( "SCREEN_READER_MODE" ) ) { +// cataimgui::TextColoredParagraph( c_white, translated_category_name ); +// ImGui::NewLine(); +// return; +// } +// const float title_length = ImGui::CalcTextSize( remove_color_tags( +// translated_category_name ).c_str() ).x; +// cataimgui::PushMonoFont(); +// const int sep_len = std::ceil( ( title_length / ImGui::CalcTextSize( "═" ).x ) + 4 ); +// ImGui::PushStyleColor( ImGuiCol_Text, c_light_blue ); +// for( int i = sep_len; i > 0; i-- ) { +// ImGui::Text( "▁" ); +// ImGui::SameLine( 0.f, 0.f ); +// } +// ImGui::NewLine(); +// // Using the matching box character doesn't look good bc there's forced(?) y spacing on NewLine +// ImGui::Text( "▏ " ); +// ImGui::SameLine( 0.f, 0.f ); +// ImGui::PopStyleColor(); +// ImGui::PopFont(); +// cataimgui::TextColoredParagraph( c_white, translated_category_name ); +// cataimgui::PushMonoFont(); +// ImGui::SameLine( 0.f, 0.f ); +// ImGui::PushStyleColor( ImGuiCol_Text, c_light_blue ); +// ImGui::Text( " ▕" ); +// for( int i = sep_len; i > 0; i-- ) { +// ImGui::Text( "▔" ); +// ImGui::SameLine( 0.f, 0.f ); +// } +// ImGui::PopStyleColor(); +// ImGui::PopFont(); +// ImGui::NewLine(); +// ImGui::PushStyleColor( ImGuiCol_Separator, c_light_blue ); +// ImGui::Separator(); +// ImGui::PopStyleColor(); +//} + void help_window::draw_category() { const help_category &cat = data.help_categories[loaded_option]; format_title( cat.name.translated() ); + // Use a table so we can scroll the category paragraphs without the title if( ImGui::BeginTable( "HELP_PARAGRAPHS", 1, ImGuiTableFlags_ScrollY ) ) { ImGui::TableNextRow(); ImGui::TableNextColumn(); - for( const translation ¶graph : cat.paragraphs ) { - std::string translated_paragraph = paragraph.translated(); - parse_tags_help_window( translated_paragraph ); - cataimgui::draw_colored_text( translated_paragraph, wrap_width ); + for( const std::string &translated_paragraph : translated_paragraphs ) { + if( translated_paragraph == "" ) { + note_colors(); + continue; + } else if( translated_paragraph == "" ) { + static const std::string dir_grid = get_dir_grid(); + cataimgui::draw_colored_text( dir_grid, wrap_width ); + continue; + } + cataimgui::TextColoredParagraph( c_white, translated_paragraph ); + ImGui::NewLine(); ImGui::NewLine(); } ImGui::EndTable(); @@ -246,29 +312,31 @@ void help_window::draw_category() } // Would ideally be merged with parse_tags()? -void help_window::parse_tags_help_window( std::string &translated_line ) +void help_window::parse_tags_help_window() { - if( translated_line == "" ) { - translated_line = get_note_colors(); - } else if( translated_line == "" ) { - translated_line = get_dir_grid(); - } - size_t pos = translated_line.find( "", pos, 1 ); - - std::string action = translated_line.substr( pos + 7, pos2 - pos - 7 ); - std::string replace = "" + - press_x( look_up_action( action ), "", "" ) + ""; - - if( replace.empty() ) { - debugmsg( "Help json: Unknown action: %s", action ); - } else { - translated_line = string_replace( - translated_line, "", replace ); + for( std::string &translated_paragraph : translated_paragraphs ) { + if( translated_paragraph == "" ) { + continue; + } else if( translated_paragraph == "" ) { + continue; } + size_t pos = translated_paragraph.find( "", pos, 1 ); + + std::string action = translated_paragraph.substr( pos + 7, pos2 - pos - 7 ); + std::string replace = "" + + press_x( look_up_action( action ), "", "" ) + ""; + + if( replace.empty() ) { + debugmsg( "Help json: Unknown action: %s", action ); + } else { + translated_paragraph = string_replace( translated_paragraph, "", + replace ); + } - pos = translated_line.find( " translated_paragraphs; + void parse_tags_help_window(); void draw_category(); - void parse_tags_help_window( std::string &translated_line ); - static std::string get_note_colors(); - static std::string get_dir_grid(); + void note_colors(); + std::string get_dir_grid(); }; std::string get_hint();