Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new char popup edit boxes #39467

Merged
merged 4 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6884,6 +6884,11 @@ int Character::base_age() const
return init_age;
}

void Character::set_base_age( int age )
{
init_age = age;
}

void Character::mod_base_age( int mod )
{
init_age += mod;
Expand All @@ -6908,6 +6913,11 @@ int Character::base_height() const
return init_height;
}

void Character::set_base_height( int height )
{
init_height = height;
}

void Character::mod_base_height( int mod )
{
init_height += mod;
Expand Down
2 changes: 2 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -1581,12 +1581,14 @@ class Character : public Creature, public visitable<Character>
int get_bmr() const;
// age in years, determined at character creation
int base_age() const;
void set_base_age( int age );
void mod_base_age( int mod );
// age in years
int age() const;
std::string age_string() const;
// returns the height in cm
int base_height() const;
void set_base_height( int height );
void mod_base_height( int mod );
std::string height_string() const;
// returns the height of the player character in cm
Expand Down
69 changes: 43 additions & 26 deletions src/newcharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2295,9 +2295,9 @@ tab_direction set_description( avatar &you, const bool allow_reroll,
catacurses::window w_age;
const auto init_windows = [&]( ui_adaptor & ui ) {
w = catacurses::newwin( TERMY, TERMX, point_zero );
w_name = catacurses::newwin( 2, 42, point( 2, 5 ) );
w_name = catacurses::newwin( 3, 42, point( 2, 5 ) );
w_gender = catacurses::newwin( 2, 33, point( 46, 5 ) );
w_location = catacurses::newwin( 1, TERMX - 3, point( 2, 7 ) );
w_location = catacurses::newwin( 2, 60, point( 100, 5 ) );
w_stats = catacurses::newwin( 6, 20, point( 2, 9 ) );
w_traits = catacurses::newwin( TERMY - 10, 24, point( 22, 9 ) );
w_scenario = catacurses::newwin( 1, TERMX - 47, point( 46, 9 ) );
Expand Down Expand Up @@ -2326,7 +2326,7 @@ tab_direction set_description( avatar &you, const bool allow_reroll,
ctxt.register_action( "CHOOSE_LOCATION" );
ctxt.register_action( "REROLL_CHARACTER" );
ctxt.register_action( "REROLL_CHARACTER_WITH_SCENARIO" );
ctxt.register_action( "ANY_INPUT" );
ctxt.register_action( "CONFIRM" );
ctxt.register_action( "QUIT" );

uilist select_location;
Expand Down Expand Up @@ -2489,8 +2489,8 @@ tab_direction set_description( avatar &you, const bool allow_reroll,
if( !MAP_SHARING::isSharing() ) { // no random names when sharing maps
// NOLINTNEXTLINE(cata-use-named-point-constants)
fold_and_print( w_name, point( 0, 1 ), ( TERMX / 2 ), c_light_gray,
_( "Press <color_light_green>%s</color> to pick a random name." ),
ctxt.get_desc( "PICK_RANDOM_NAME" ) );
_( "Press <color_light_green>%s</color> to edit.\nPress <color_light_green>%s</color> to randomize description." ),
ctxt.get_desc( "CONFIRM" ), ctxt.get_desc( "PICK_RANDOM_NAME" ) );
}
wrefresh( w_name );

Expand All @@ -2510,13 +2510,13 @@ tab_direction set_description( avatar &you, const bool allow_reroll,
const std::string location_prompt = string_format(
_( "Press <color_light_green>%s</color> to select location." ),
ctxt.get_desc( "CHOOSE_LOCATION" ) );
const int prompt_offset = utf8_width( location_prompt );

werase( w_location );
// NOLINTNEXTLINE(cata-use-named-point-constants)
fold_and_print( w_location, point( 0, 1 ), ( TERMX / 2 ), c_light_gray, location_prompt );
mvwprintz( w_location, point( prompt_offset - 10, 0 ), c_light_gray, _( "Starting location:" ) );
mvwprintz( w_location, point( 0, 0 ), c_light_gray, _( "Starting location:" ) );
// ::find will return empty location if id was not found. Debug msg will be printed too.
mvwprintz( w_location, point( prompt_offset + utf8_width( _( "Starting location:" ) ) - 9, 0 ),
mvwprintz( w_location, point( utf8_width( _( "Starting location:" ) ) + 1, 0 ),
you.random_start_location ? c_red : c_light_green,
you.random_start_location ? remove_color_tags( random_start_location_text ) :
string_format( remove_color_tags( START_LOC_TEXT_TEMPLATE ),
Expand Down Expand Up @@ -2650,6 +2650,9 @@ tab_direction set_description( avatar &you, const bool allow_reroll,
if( !MAP_SHARING::isSharing() ) { // Don't allow random names when sharing maps. We don't need to check at the top as you won't be able to edit the name
you.pick_name();
KorGgenT marked this conversation as resolved.
Show resolved Hide resolved
}
you.set_base_age( rng( 16, 55 ) );
you.set_base_height( rng( 145, 200 ) );
you.male = one_in( 2 );
KorGgenT marked this conversation as resolved.
Show resolved Hide resolved
} else if( action == "CHANGE_GENDER" ) {
you.male = !you.male;
} else if( action == "CHOOSE_LOCATION" ) {
Expand All @@ -2665,28 +2668,42 @@ tab_direction set_description( avatar &you, const bool allow_reroll,
}
}
}
} else if( action == "ANY_INPUT" &&
} else if( action == "CONFIRM" &&
// Don't edit names when sharing maps
!MAP_SHARING::isSharing() && current_selector == char_creation::NAME ) {
const int ch = ctxt.get_raw_input().get_first_input();
utf8_wrapper wrap( you.name );
if( ch == KEY_BACKSPACE ) {
if( !wrap.empty() ) {
wrap.erase( wrap.length() - 1, 1 );
you.name = wrap.str();
!MAP_SHARING::isSharing() ) {

string_input_popup popup;
switch( current_selector ) {
case char_creation::NAME: {
popup.title( _( "Enter name. Cancel to delete all." ) )
.text( you.name )
.only_digits( false );
you.name = popup.query_string();
no_name_entered = you.name.empty();
break;
}
case char_creation::AGE: {
popup.title( _( "Enter age in years. Minimum 16, maximum 55" ) )
.text( string_format( "%d", you.base_age() ) )
.only_digits( true );
const int result = popup.query_int();
if( result != 0 ) {
you.set_base_age( clamp( popup.query_int(), 16, 55 ) );
}
break;
}
} else if( ch == KEY_F( 2 ) ) {
utf8_wrapper tmp( get_input_string_from_file() );
if( !tmp.empty() && tmp.length() + wrap.length() < 30 ) {
you.name.append( tmp.str() );
case char_creation::HEIGHT: {
popup.title( _( "Enter height in centimeters. Minimum 145, maximum 200" ) )
.text( string_format( "%d", you.base_height() ) )
.only_digits( true );
const int result = popup.query_int();
if( result != 0 ) {
you.set_base_height( clamp( popup.query_int(), 145, 200 ) );
}
break;
}
} else if( ch == '\n' ) {
// nope, we ignore this newline, don't want it in char names
} else {
wrap.append( ctxt.get_raw_input().text );
you.name = wrap.str();
}
no_name_entered = false;

} else if( action == "QUIT" && query_yn( _( "Return to main menu?" ) ) ) {
return tab_direction::QUIT;
}
Expand Down