Skip to content

Commit

Permalink
use imgui input popups in some places
Browse files Browse the repository at this point in the history
  • Loading branch information
mqrause committed Nov 14, 2024
1 parent d416005 commit cc4bed6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 54 deletions.
17 changes: 7 additions & 10 deletions src/auto_note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
#include "flexbuffer_json.h"
#include "generic_factory.h"
#include "input_context.h"
#include "input_popup.h"
#include "json.h"
#include "map_extras.h"
#include "options.h"
#include "output.h"
#include "path_info.h"
#include "point.h"
#include "string_formatter.h"
#include "string_input_popup.h"
#include "translation.h"
#include "translations.h"
#include "ui.h"
Expand Down Expand Up @@ -510,16 +510,13 @@ void auto_note_manager_gui::show()
entry.second = false;
( bCharacter ? charwasChanged : globalwasChanged ) = true;
} else if( action == "CHANGE_MAPEXTRA_CHARACTER" ) {
string_input_popup custom_symbol_popup;
custom_symbol_popup
.title( _( "Enter a map extra custom symbol (empty to unset):" ) )
.width( 2 )
.query_string();

if( !custom_symbol_popup.canceled() ) {
const std::string &custom_symbol_str = custom_symbol_popup.text();
if( custom_symbol_str.empty() ) {
string_input_popup_imgui custom_symbol_popup( 17 );
custom_symbol_popup.set_label( _( "Enter a map extra custom symbol (empty to unset):" ) );
custom_symbol_popup.set_max_input_length( 2 );
const std::string &custom_symbol_str = custom_symbol_popup.query();

if( !custom_symbol_popup.cancelled() ) {
if( custom_symbol_str.empty() ) {
( bCharacter ? char_custom_symbol_cache : global_custom_symbol_cache ).erase( currentItem );
} else {
uilist ui_colors;
Expand Down
16 changes: 7 additions & 9 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
#include "input.h"
#include "input_context.h"
#include "input_enums.h"
#include "input_popup.h"
#include "inventory.h"
#include "item.h"
#include "item_category.h"
Expand Down Expand Up @@ -8551,15 +8552,12 @@ game::vmenu_ret game::list_items( const std::vector<map_item_stack> &item_list )
recalc_unread = highlight_unread_items;
} else if( action == "FILTER" ) {
ui.invalidate_ui();
string_input_popup()
.title( _( "Filter:" ) )
.width( 55 )
.description( item_filter_rule_string( item_filter_type::FILTER ) + "\n\n"
+ list_items_filter_history_help() )
.desc_color( c_white )
.identifier( "item_filter" )
.max_length( 256 )
.edit( sFilter );
string_input_popup_imgui imgui_popup( _( "Filter items" ), 70, sFilter );
imgui_popup.set_label( _( "Filter:" ) );
imgui_popup.set_description( item_filter_rule_string( item_filter_type::FILTER ) + "\n\n" +
list_items_filter_history_help(), c_white, true );
imgui_popup.set_identifier( "item_filter" );
sFilter = imgui_popup.query();
refilter = true;
addcategory = !sort_radius;
uistate.list_item_filter_active = !sFilter.empty();
Expand Down
36 changes: 11 additions & 25 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "game_constants.h"
#include "generic_factory.h"
#include "input_context.h"
#include "input_popup.h"
#include "json.h"
#include "lang_stats.h"
#include "line.h"
Expand Down Expand Up @@ -3754,31 +3755,16 @@ std::string options_manager::show( bool ingame, const bool world_options_only, b
const bool is_int = current_opt.getType() == "int";
const bool is_float = current_opt.getType() == "float";
const std::string old_opt_val = current_opt.getValueName();
const std::string opt_val = string_input_popup()
.title( current_opt.getMenuText() )
.width( 10 )
.text( old_opt_val )
.only_digits( is_int )
.query_string();
if( !opt_val.empty() && opt_val != old_opt_val ) {
if( is_float ) {
std::istringstream ssTemp( opt_val );
// This uses the current locale, to allow the users
// to use their own decimal format.
float tmpFloat;
ssTemp >> tmpFloat;
if( ssTemp ) {
current_opt.setValue( tmpFloat );

} else {
popup( _( "Invalid input: not a number" ) );
}
} else {
// option is of type "int": string_input_popup
// has taken care that the string contains
// only digits, parsing is done in setValue
current_opt.setValue( opt_val );
}
if( is_int ) {
number_input_popup<int> popup( 25, current_opt.value_as<int>() );
popup.set_label( current_opt.getMenuText() );
int num = popup.query();
current_opt.setValue( num );
} else {
number_input_popup<float> popup( 25, current_opt.value_as<float>() );
popup.set_label( current_opt.getMenuText() );
float num = popup.query();
current_opt.setValue( num );
}
}
}
Expand Down
21 changes: 11 additions & 10 deletions src/worldfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "enums.h"
#include "filesystem.h"
#include "input_context.h"
#include "input_popup.h"
#include "json.h"
#include "json_loader.h"
#include "mod_manager.h"
Expand Down Expand Up @@ -188,21 +189,21 @@ WORLD *worldfactory::make_new_world( bool show_prompt, const std::string &world_
static std::optional<std::string> prompt_world_name( const std::string &title,
const std::string &cur_worldname )
{
string_input_popup popup;
popup.max_length( max_worldname_len ).title( title ).text( cur_worldname );
string_input_popup_imgui popup( 50, cur_worldname );
popup.set_max_input_length( max_worldname_len );
popup.set_label( title );

input_context ctxt( "STRING_INPUT" );
popup.description( string_format(
_( "Press [<color_c_yellow>%s</color>] to randomize the world name." ),
ctxt.get_desc( "PICK_RANDOM_WORLDNAME", 1U ) ) );
popup.set_description( string_format(
_( "Press [<color_c_yellow>%s</color>] to randomize the world name." ),
ctxt.get_desc( "PICK_RANDOM_WORLDNAME", 1U ) ) );

popup.custom_actions.emplace_back( "PICK_RANDOM_WORLDNAME", translation() );
popup.add_callback( "PICK_RANDOM_WORLDNAME", [&popup]() {
popup.text( get_next_valid_worldname() );
popup.add_callback( { "PICK_RANDOM_WORLDNAME" }, [&popup]() {
popup.set_text( get_next_valid_worldname() );
return true;
} );
std::string message = popup.query_string();
return !popup.canceled() ? std::optional<std::string>( message ) : std::optional<std::string>();
std::string message = popup.query();
return message;
}

int worldfactory::show_worldgen_advanced( WORLD *world )
Expand Down

0 comments on commit cc4bed6

Please sign in to comment.