Skip to content

Commit

Permalink
Merge pull request #226 from olanti-p/ui-changes-4
Browse files Browse the repository at this point in the history
Misc UI changes/fixes from DDA 4
  • Loading branch information
Coolthulhu authored Nov 23, 2020
2 parents ffbd9d8 + 70316b3 commit bbd2a5d
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 72 deletions.
8 changes: 4 additions & 4 deletions src/crafting_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ const recipe *select_crafting_recipe( int &batch_size )
if( highlight ) {
cursor_pos = print_from;
}
mvwprintz( w_data, print_from, col, utf8_truncate( tmp_name, 28 ) );
mvwprintz( w_data, print_from, col, trim_by_length( tmp_name, 27 ) );
}
} else if( line >= recmax - dataHalfLines ) {
for( int i = recmax - dataLines; i < recmax; ++i ) {
Expand All @@ -392,7 +392,7 @@ const recipe *select_crafting_recipe( int &batch_size )
cursor_pos = print_from;
}
mvwprintz( w_data, print_from, col,
utf8_truncate( tmp_name, 28 ) );
trim_by_length( tmp_name, 27 ) );
}
} else {
for( int i = line - dataHalfLines; i < line - dataHalfLines + dataLines; ++i ) {
Expand All @@ -408,7 +408,7 @@ const recipe *select_crafting_recipe( int &batch_size )
cursor_pos = print_from;
}
mvwprintz( w_data, print_from, col,
utf8_truncate( tmp_name, 28 ) );
trim_by_length( tmp_name, 27 ) );
}
}
} else {
Expand All @@ -423,7 +423,7 @@ const recipe *select_crafting_recipe( int &batch_size )
if( highlight ) {
cursor_pos = print_from;
}
mvwprintz( w_data, print_from, col, utf8_truncate( tmp_name, 28 ) );
mvwprintz( w_data, print_from, col, trim_by_length( tmp_name, 27 ) );
}
}

Expand Down
58 changes: 46 additions & 12 deletions src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,11 @@ void character_edit_menu()
}

enum {
D_NAME, D_SKILLS, D_STATS, D_ITEMS, D_DELETE_ITEMS, D_ITEM_WORN,
D_DESC, D_SKILLS, D_STATS, D_ITEMS, D_DELETE_ITEMS, D_ITEM_WORN,
D_HP, D_STAMINA, D_MORALE, D_PAIN, D_NEEDS, D_HEALTHY, D_STATUS, D_MISSION_ADD, D_MISSION_EDIT,
D_TELE, D_MUTATE, D_CLASS, D_ATTITUDE, D_OPINION, D_ASTHMA
};
nmenu.addentry( D_NAME, true, 'N', "%s", _( "Edit [N]ame" ) );
nmenu.addentry( D_DESC, true, 'D', "%s", _( "Edit [D]escription - Name, Age, Height" ) );
nmenu.addentry( D_SKILLS, true, 's', "%s", _( "Edit [s]kills" ) );
nmenu.addentry( D_STATS, true, 't', "%s", _( "Edit s[t]ats" ) );
nmenu.addentry( D_ITEMS, true, 'i', "%s", _( "Grant [i]tems" ) );
Expand Down Expand Up @@ -743,16 +743,50 @@ void character_edit_menu()
}
}
break;
case D_NAME: {
std::string filterstring = p.name;
string_input_popup popup;
popup
.title( _( "Rename:" ) )
.width( 85 )
.description( string_format( _( "NPC:\n%s\n" ), p.name ) )
.edit( filterstring );
if( popup.confirmed() ) {
p.name = filterstring;
case D_DESC: {
uilist smenu;
smenu.text = _( "Select a value and press enter to change it." );
smenu.addentry( 0, true, 'n', "%s: %s", _( "Current name" ), p.get_name() );
smenu.addentry( 1, true, 'a', "%s: %d", _( "Current age" ), p.base_age() );
smenu.addentry( 2, true, 'h', "%s: %d", _( "Current height in cm" ), p.base_height() );
smenu.query();
switch( smenu.ret ) {
case 0: {
std::string buf = p.name;
string_input_popup popup;
popup
.title( _( "Rename:" ) )
.width( 85 )
.edit( buf );
if( popup.confirmed() ) {
p.name = buf;
}
}
break;
case 1: {
string_input_popup popup;
popup
.title( _( "Enter age in years. Minimum 16, maximum 55" ) )
.text( string_format( "%d", p.base_age() ) )
.only_digits( true );
const int result = popup.query_int();
if( result != 0 ) {
p.set_base_age( clamp( result, 16, 55 ) );
}
}
break;
case 2: {
string_input_popup popup;
popup
.title( _( "Enter height in centimeters. Minimum 145, maximum 200" ) )
.text( string_format( "%d", p.base_height() ) )
.only_digits( true );
const int result = popup.query_int();
if( result != 0 ) {
p.set_base_height( clamp( result, 145, 200 ) );
}
}
break;
}
}
break;
Expand Down
25 changes: 0 additions & 25 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,31 +586,6 @@ static void close()
}
}

static void handbrake()
{
const optional_vpart_position vp = g->m.veh_at( g->u.pos() );
if( !vp ) {
return;
}
vehicle *const veh = &vp->vehicle();
add_msg( _( "You pull a handbrake." ) );
veh->cruise_velocity = 0;
if( veh->last_turn != 0 && rng( 15, 60 ) * 100 < std::abs( veh->velocity ) ) {
veh->skidding = true;
add_msg( m_warning, _( "You lose control of %s." ), veh->name );
veh->turn( veh->last_turn > 0 ? 60 : -60 );
} else {
int braking_power = std::abs( veh->velocity ) / 2 + 10 * 100;
if( std::abs( veh->velocity ) < braking_power ) {
veh->stop();
} else {
int sgn = veh->velocity > 0 ? 1 : -1;
veh->velocity = sgn * ( std::abs( veh->velocity ) - braking_power );
}
}
g->u.moves = 0;
}

// Establish or release a grab on a vehicle
static void grab()
{
Expand Down
4 changes: 4 additions & 0 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ int iuse_transform::use( player &p, item &it, bool t, const tripoint &pos ) cons
ret_val<bool> iuse_transform::can_use( const Character &p, const item &, bool,
const tripoint & ) const
{
if( qualities_needed.empty() ) {
return ret_val<bool>::make_success();
}

std::map<quality_id, int> unmet_reqs;
inventory inv;
inv.form_from_map( p.pos(), 1, &p, true, true );
Expand Down
37 changes: 30 additions & 7 deletions src/martialarts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <unordered_map>
#include <utility>

#include "avatar.h"
#include "character.h"
#include "character_martial_arts.h"
#include "color.h"
Expand Down Expand Up @@ -510,7 +511,12 @@ std::string ma_requirements::get_description( bool buff ) const

dump += enumerate_as_string( min_skill.begin(),
min_skill.end(), []( const std::pair<skill_id, int> &pr ) {
return string_format( "%s: <stat>%d</stat>", pr.first->name(), pr.second );
int player_skill = g->u.get_skill_level( skill_id( pr.first ) );
if( g->u.has_active_bionic( bio_cqb ) ) {
player_skill = BIO_CQB_LEVEL;
}
return string_format( "%s: <stat>%d</stat>/<stat>%d</stat>", pr.first->name(), player_skill,
pr.second );
}, enumeration_conjunction::none ) + "\n";
}

Expand Down Expand Up @@ -1411,22 +1417,26 @@ bool ma_style_callback::key( const input_context &ctxt, const input_event &event

if( ma.arm_block_with_bio_armor_arms || ma.arm_block != 99 ||
ma.leg_block_with_bio_armor_legs || ma.leg_block != 99 ) {
int unarmed_skill = g->u.get_skill_level( skill_unarmed );
if( g->u.has_active_bionic( bio_cqb ) ) {
unarmed_skill = BIO_CQB_LEVEL;
}
if( ma.arm_block_with_bio_armor_arms ) {
buffer += _( "You can <info>arm block</info> by installing the <info>Arms Alloy Plating CBM</info>" );
buffer += "\n";
} else if( ma.arm_block != 99 ) {
buffer += string_format(
_( "You can <info>arm block</info> at <info>unarmed combat:</info> <stat>%s</stat>" ),
ma.arm_block ) + "\n";
_( "You can <info>arm block</info> at <info>unarmed combat:</info> <stat>%s</stat>/<stat>%s</stat>" ),
unarmed_skill, ma.arm_block ) + "\n";
}

if( ma.leg_block_with_bio_armor_legs ) {
buffer += _( "You can <info>leg block</info> by installing the <info>Legs Alloy Plating CBM</info>" );
buffer += "\n";
} else if( ma.leg_block != 99 ) {
buffer += string_format(
_( "You can <info>leg block</info> at <info>unarmed combat:</info> <stat>%s</stat>" ),
ma.leg_block );
_( "You can <info>leg block</info> at <info>unarmed combat:</info> <stat>%s</stat>/<stat>%s</stat>" ),
unarmed_skill, ma.leg_block );
buffer += "\n";
}
buffer += "--\n";
Expand Down Expand Up @@ -1464,7 +1474,14 @@ bool ma_style_callback::key( const input_context &ctxt, const input_event &event
if( !ma.weapons.empty() ) {
std::vector<std::string> weapons;
std::transform( ma.weapons.begin(), ma.weapons.end(),
std::back_inserter( weapons ), []( const std::string & wid )-> std::string { return item::nname( wid ); } );
std::back_inserter( weapons ), []( const itype_id & wid )-> std::string {
if( item::nname( wid ) == g->u.weapon.display_name() )
{
return colorize( item::nname( wid ) + _( " (wielded)" ), c_light_cyan );
} else
{
return item::nname( wid );
} } );
// Sorting alphabetically makes it easier to find a specific weapon
std::sort( weapons.begin(), weapons.end(), localized_compare );
// This removes duplicate names (e.g. a real weapon and a replica sharing the same name) from the weapon list.
Expand Down Expand Up @@ -1509,6 +1526,8 @@ bool ma_style_callback::key( const input_context &ctxt, const input_event &event
input_context ict;
ict.register_action( "UP" );
ict.register_action( "DOWN" );
ict.register_action( "PAGE_UP" );
ict.register_action( "PAGE_DOWN" );
ict.register_action( "QUIT" );
ict.register_action( "HELP_KEYBINDINGS" );

Expand All @@ -1530,7 +1549,7 @@ bool ma_style_callback::key( const input_context &ctxt, const input_event &event
}

ui_manager::redraw();

const int scroll_lines = catacurses::getmaxy( w ) - 4;
std::string action = ict.handle_input();

if( action == "QUIT" ) {
Expand All @@ -1539,6 +1558,10 @@ bool ma_style_callback::key( const input_context &ctxt, const input_event &event
selected++;
} else if( action == "UP" ) {
selected--;
} else if( action == "PAGE_DOWN" ) {
selected += scroll_lines;
} else if( action == "PAGE_UP" ) {
selected -= scroll_lines;
}
} while( true );
}
Expand Down
57 changes: 39 additions & 18 deletions src/overmap_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,40 +1199,61 @@ static bool search( const ui_adaptor &om_ui, tripoint &curs, const tripoint &ori
catacurses::window w_search;

ui_adaptor ui;
int search_width = OVERMAP_LEGEND_WIDTH - 1;
ui.on_screen_resize( [&]( ui_adaptor & ui ) {
w_search = catacurses::newwin( 13, 27, point( TERMX - 27, 3 ) );
w_search = catacurses::newwin( 13, search_width, point( TERMX - search_width, 3 ) );

ui.position_from_window( w_search );
} );
ui.mark_resize();

input_context ctxt( "OVERMAP_SEARCH" );
ctxt.register_leftright();
ctxt.register_action( "NEXT_TAB", to_translation( "Next target" ) );
ctxt.register_action( "PREV_TAB", to_translation( "Previous target" ) );
ctxt.register_action( "QUIT" );
ctxt.register_action( "NEXT_TAB", to_translation( "Next result" ) );
ctxt.register_action( "PREV_TAB", to_translation( "Previous result" ) );
ctxt.register_action( "CONFIRM" );
ctxt.register_action( "QUIT" );
ctxt.register_action( "HELP_KEYBINDINGS" );
ctxt.register_action( "ANY_INPUT" );

ui.on_redraw( [&]( const ui_adaptor & ) {
//Draw search box

int a = utf8_width( _( "Search:" ) );
int b = utf8_width( _( "Result:" ) );
int c = utf8_width( _( "Results:" ) );
int d = utf8_width( _( "Direction:" ) );
int align_width = 0;
int align_w_value[4] = { a, b, c, d};
for( int n : align_w_value ) {
if( n > align_width ) {
align_width = n + 2;
}
}

// NOLINTNEXTLINE(cata-use-named-point-constants)
mvwprintz( w_search, point( 1, 1 ), c_light_blue, _( "Search:" ) );
mvwprintz( w_search, point( 10, 1 ), c_light_red, "%s", right_justify( term, 12 ) );
mvwprintz( w_search, point( align_width, 1 ), c_light_red, "%s", term );

mvwprintz( w_search, point( 1, 2 ), c_light_blue, _( "Result(s):" ) );
mvwprintz( w_search, point( 16, 2 ), c_light_red, "%*d/%d", 3, i + 1, locations.size() );
mvwprintz( w_search, point( 1, 2 ), c_light_blue,
locations.size() == 1 ? _( "Result:" ) : _( "Results:" ) );
mvwprintz( w_search, point( align_width, 2 ), c_light_red, "%d/%d ", i + 1,
locations.size() );

mvwprintz( w_search, point( 1, 3 ), c_light_blue, _( "Direction:" ) );
mvwprintz( w_search, point( 14, 3 ), c_white, "%*d %s",
5, static_cast<int>( trig_dist( orig, tripoint( locations[i], orig.z ) ) ),
direction_name_short( direction_from( orig, tripoint( locations[i], orig.z ) ) )
);

mvwprintz( w_search, point( 1, 6 ), c_white, _( "'<-' '->' Cycle targets." ) );
mvwprintz( w_search, point( 1, 10 ), c_white, _( "Enter/Spacebar to select." ) );
mvwprintz( w_search, point( 1, 11 ), c_white, _( "q or ESC to return." ) );
mvwprintz( w_search, point( align_width, 3 ), c_light_red, "%d %s",
static_cast<int>( trig_dist( orig, tripoint( locations[i], orig.z ) ) ),
direction_name_short( direction_from( orig, tripoint( locations[i], orig.z ) ) ) );

if( locations.size() > 1 ) {
fold_and_print( w_search, point( 1, 6 ), search_width, c_white,
_( "Press [<color_yellow>%s</color>] or [<color_yellow>%s</color>] "
"to cycle through search results." ),
ctxt.get_desc( "NEXT_TAB" ), ctxt.get_desc( "PREV_TAB" ) );
}
fold_and_print( w_search, point( 1, 10 ), search_width, c_white,
_( "Press [<color_yellow>%s</color>] to confirm." ), ctxt.get_desc( "CONFIRM" ) );
fold_and_print( w_search, point( 1, 11 ), search_width, c_white,
_( "Press [<color_yellow>%s</color>] to quit." ), ctxt.get_desc( "QUIT" ) );
draw_border( w_search );
wrefresh( w_search );
} );
Expand All @@ -1247,9 +1268,9 @@ static bool search( const ui_adaptor &om_ui, tripoint &curs, const tripoint &ori
if( uistate.overmap_blinking ) {
uistate.overmap_show_overlays = !uistate.overmap_show_overlays;
}
if( action == "NEXT_TAB" || action == "RIGHT" ) {
if( action == "NEXT_TAB" ) {
i = ( i + 1 ) % locations.size();
} else if( action == "PREV_TAB" || action == "LEFT" ) {
} else if( action == "PREV_TAB" ) {
i = ( i + locations.size() - 1 ) % locations.size();
} else if( action == "QUIT" ) {
curs = prev_curs;
Expand Down
3 changes: 2 additions & 1 deletion src/start_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ tripoint start_location::find_player_initial_location() const
}
}
// Should never happen, if it does we messed up.
popup( _( "Unable to generate a valid starting location, please report this failure." ) );
popup( _( "Unable to generate a valid starting location %s [%s] in a radius of %d overmaps, please report this failure." ),
name(), id.str(), radius );
return overmap::invalid_tripoint;
}

Expand Down
4 changes: 2 additions & 2 deletions src/veh_interact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ void veh_interact::do_repair()

if( reason == INVALID_TARGET ) {
vehicle_part *most_repairable = get_most_repariable_part();
if( most_repairable ) {
if( most_repairable && most_repairable->damage_percent() ) {
move_cursor( ( most_repairable->mount + dd ).rotate( 3 ) );
return;
}
Expand Down Expand Up @@ -2378,7 +2378,7 @@ void veh_interact::display_stats() const
vehicle_part *most_repairable = get_most_repariable_part();

// Write the most damaged part
if( mostDamagedPart ) {
if( mostDamagedPart && mostDamagedPart->damage_percent() ) {
const std::string damaged_header = mostDamagedPart == most_repairable ?
_( "Most damaged:" ) :
_( "Most damaged (can't repair):" );
Expand Down
2 changes: 2 additions & 0 deletions src/vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ enum ter_bitflags : int;
template<typename feature_type>
class vehicle_part_with_feature_range;

void handbrake();

namespace catacurses
{
class window;
Expand Down
Loading

0 comments on commit bbd2a5d

Please sign in to comment.