Skip to content

Commit

Permalink
Default text color for popups
Browse files Browse the repository at this point in the history
  • Loading branch information
AMurkin authored and kevingranade committed Jan 31, 2019
1 parent db89b63 commit 917f536
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/advanced_inv.cpp
Expand Up @@ -2038,7 +2038,8 @@ int advanced_inventory::add_item( aim_location destarea, item &new_item, int cou
// @todo: Make it use same exact methods as regular pickup
if( ( destarea == AIM_INVENTORY || destarea == AIM_WORN || panes[dest].in_vehicle() ) &&
new_item.is_bucket_nonempty() &&
!query_yn( _( "Spill contents of %s?" ), new_item.tname().c_str() ) ) {
!query_yn( _( "Spill contents of %s?" ),
colorize( new_item.tname(), new_item.color_in_inventory() ) ) ) {
break;
} else if( destarea == AIM_INVENTORY ) {
const item &added = g->u.i_add( new_item );
Expand Down
4 changes: 3 additions & 1 deletion src/armor_layers.cpp
Expand Up @@ -698,7 +698,9 @@ void player::sort_armor()
}
} else if( action == "CHANGE_SIDE" ) {
if( leftListIndex < static_cast<int>( tmp_worn.size() ) && tmp_worn[leftListIndex]->is_sided() ) {
if( g->u.query_yn( _( "Swap side for %s?" ), tmp_worn[leftListIndex]->tname().c_str() ) ) {
if( g->u.query_yn( _( "Swap side for %s?" ),
colorize( tmp_worn[leftListIndex]->tname(),
tmp_worn[leftListIndex]->color_in_inventory() ) ) ) {
change_side( *tmp_worn[leftListIndex] );
wrefresh( w_sort_armor );
}
Expand Down
4 changes: 3 additions & 1 deletion src/bionics.cpp
Expand Up @@ -407,7 +407,9 @@ bool player::activate_bionic( int b, bool eff_only )
static const auto volume_per_water_charge = units::from_milliliter( 500 );
if( it->is_corpse() ) {
const int avail = it->get_var( "remaining_water", it->volume() / volume_per_water_charge );
if( avail > 0 && query_yn( _( "Extract water from the %s" ), it->tname().c_str() ) ) {
if( avail > 0 &&
query_yn( _( "Extract water from the %s" ),
colorize( it->tname(), it->color_in_inventory() ) ) ) {
item water( "water_clean", calendar::turn, avail );
if( g->consume_liquid( water ) ) {
extracted = true;
Expand Down
8 changes: 5 additions & 3 deletions src/consumption.cpp
Expand Up @@ -511,12 +511,14 @@ ret_val<edible_rating> player::will_eat( const item &food, bool interactive ) co
}

const bool eat_verb = food.has_flag( "USE_EAT_VERB" );
std::string food_tame = food.tname();
const nc_color food_color = food.color_in_inventory();
if( eat_verb || comest->comesttype == "FOOD" ) {
req << string_format( _( "Eat your %s anyway?" ), food.tname().c_str() );
req << string_format( _( "Eat your %s anyway?" ), colorize( food_tame, food_color ) );
} else if( !eat_verb && comest->comesttype == "DRINK" ) {
req << string_format( _( "Drink your %s anyway?" ), food.tname().c_str() );
req << string_format( _( "Drink your %s anyway?" ), colorize( food_tame, food_color ) );
} else {
req << string_format( _( "Consume your %s anyway?" ), food.tname().c_str() );
req << string_format( _( "Consume your %s anyway?" ), colorize( food_tame, food_color ) );
}

if( !query_yn( req.str() ) ) {
Expand Down
8 changes: 4 additions & 4 deletions src/crafting.cpp
Expand Up @@ -1231,13 +1231,13 @@ bool player::disassemble( item &obj, int pos, bool ground, bool interactive )
if( !r.learn_by_disassembly.empty() && !knows_recipe( &r ) && can_decomp_learn( r ) ) {
if( !query_yn(
_( "Disassembling the %s may yield:\n%s\nReally disassemble?\nYou feel you may be able to understand this object's construction.\n" ),
obj.tname().c_str(),
list.str().c_str() ) ) {
colorize( obj.tname(), obj.color_in_inventory() ),
list.str() ) ) {
return false;
}
} else if( !query_yn( _( "Disassembling the %s may yield:\n%s\nReally disassemble?" ),
obj.tname().c_str(),
list.str().c_str() ) ) {
colorize( obj.tname(), obj.color_in_inventory() ),
list.str() ) ) {
return false;
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/iuse.cpp
Expand Up @@ -1237,7 +1237,7 @@ int iuse::marloss( player *p, item *it, bool, const tripoint & )
int iuse::marloss_seed( player *p, item *it, bool, const tripoint & )
{
if( !query_yn( _( "Sure you want to eat the %s? You could plant it in a mound of dirt." ),
it->tname().c_str() ) ) {
colorize( it->tname(), it->color_in_inventory() ) ) ) {
return 0; // Save the seed for later!
}

Expand Down Expand Up @@ -3961,7 +3961,8 @@ int iuse::blood_draw( player *p, item *it, bool, const tripoint & )
bool acid_blood = false;
for( auto &map_it : g->m.i_at( p->posx(), p->posy() ) ) {
if( map_it.is_corpse() &&
query_yn( _( "Draw blood from %s?" ), map_it.tname().c_str() ) ) {
query_yn( _( "Draw blood from %s?" ),
colorize( map_it.tname(), map_it.color_in_inventory() ) ) ) {
p->add_msg_if_player( m_info, _( "You drew blood from the %s..." ), map_it.tname().c_str() );
drew_blood = true;
auto bloodtype( map_it.get_mtype()->bloodType() );
Expand Down Expand Up @@ -4789,7 +4790,8 @@ static bool heat_item( player &p )
target.apply_freezerburn();

if( target.has_flag( "EATEN_COLD" ) &&
!query_yn( _( "%s is best served cold. Heat beyond defrosting?" ), target.tname() ) ) {
!query_yn( _( "%s is best served cold. Heat beyond defrosting?" ),
colorize( target.tname(), target.color_in_inventory() ) ) ) {

// assume environment is warm; heat less to keep COLD longer
int counter_mod = 550;
Expand Down Expand Up @@ -5333,7 +5335,7 @@ int iuse::seed( player *p, item *it, bool, const tripoint & )
{
if( p->is_npc() ||
query_yn( _( "Sure you want to eat the %s? You could plant it in a mound of dirt." ),
it->tname().c_str() ) ) {
colorize( it->tname(), it->color_in_inventory() ) ) ) {
return it->type->charges_to_use(); //This eats the seed object.
}
return 0;
Expand Down
5 changes: 3 additions & 2 deletions src/output.cpp
Expand Up @@ -605,11 +605,12 @@ bool query_yn( const std::string &text )
return query_popup()
.context( "YESNO" )
.message( force_uc ?
pgettext( "query_yn", "<color_light_red>%s (Case Sensitive)</color>" ) :
pgettext( "query_yn", "<color_light_red>%s</color>" ), text )
pgettext( "query_yn", "%s (Case Sensitive)" ) :
pgettext( "query_yn", "%s" ), text )
.option( "YES", allow_key )
.option( "NO", allow_key )
.cursor( 1 )
.default_color( c_light_red )
.query()
.action == "YES";
}
Expand Down
16 changes: 10 additions & 6 deletions src/player.cpp
Expand Up @@ -7170,7 +7170,8 @@ bool player::has_mission_item(int mission_id) const
//Returns the amount of charges that were consumed by the player
int player::drink_from_hands(item& water) {
int charges_consumed = 0;
if( query_yn( _("Drink %s from your hands?"), water.type_name().c_str() ) )
if( query_yn( _( "Drink %s from your hands?" ),
colorize( water.type_name(), water.color_in_inventory() ) ) )
{
// Create a dose of water no greater than the amount of water remaining.
item water_temp( water );
Expand Down Expand Up @@ -8493,7 +8494,8 @@ bool player::takeoff( const item &it, std::list<item> *res )

if( res == nullptr ) {
if( volume_carried() + it.volume() > volume_capacity_reduced_by( it.get_storage() ) ) {
if( is_npc() || query_yn( _( "No room in inventory for your %s. Drop it?" ), it.tname().c_str() ) ) {
if( is_npc() || query_yn( _( "No room in inventory for your %s. Drop it?" ),
colorize( it.tname(), it.color_in_inventory() ) ) ) {
drop( get_item_position( &it ), pos() );
return true; // the drop activity ends up taking off the item anyway so shouldn't try to do it again here
} else {
Expand Down Expand Up @@ -9185,8 +9187,9 @@ void player::gunmod_add( item &gun, item &mod )
int qty = 0;

if( mod.is_irremovable() ) {
if( !query_yn( _( "Permanently install your %1$s in your %2$s?" ), mod.tname().c_str(),
gun.tname().c_str() ) ) {
if( !query_yn( _( "Permanently install your %1$s in your %2$s?" ),
colorize( mod.tname(), mod.color_in_inventory() ),
colorize( gun.tname(), gun.color_in_inventory() ) ) ) {
add_msg_if_player( _( "Never mind." ) );
return; // player canceled installation
}
Expand Down Expand Up @@ -9252,8 +9255,9 @@ void player::toolmod_add( item_location tool, item_location mod )
return;
}

if( !query_yn( _( "Permanently install your %1$s in your %2$s?" ), mod->tname().c_str(),
tool->tname().c_str() ) ) {
if( !query_yn( _( "Permanently install your %1$s in your %2$s?" ),
colorize( mod->tname().c_str(), mod->color_in_inventory() ),
colorize( tool->tname().c_str(), tool->color_in_inventory() ) ) ) {
add_msg_if_player( _( "Never mind." ) );
return; // player canceled installation
}
Expand Down
11 changes: 9 additions & 2 deletions src/popup.cpp
Expand Up @@ -6,7 +6,8 @@
extern bool test_mode;

query_popup::query_popup()
: cur( 0 ), anykey( false ), cancel( false ), ontop( false ), fullscr( false )
: cur( 0 ), default_text_color( c_white ), anykey( false ), cancel( false ), ontop( false ),
fullscr( false )
{
}

Expand Down Expand Up @@ -69,6 +70,12 @@ query_popup &query_popup::cursor( size_t pos )
return *this;
}

query_popup &query_popup::default_color( const nc_color &d_color )
{
default_text_color = d_color;
return *this;
}

std::vector<std::vector<std::string>> query_popup::fold_query(
const std::string &category,
const std::vector<query_option> &options,
Expand Down Expand Up @@ -206,7 +213,7 @@ void query_popup::show() const
draw_border( win );

for( size_t line = 0; line < folded_msg.size(); ++line ) {
nc_color col = c_white;
nc_color col = default_text_color;
print_colored_text( win, border_width + line, border_width, col, col,
folded_msg[line] );
}
Expand Down
8 changes: 6 additions & 2 deletions src/popup.h
Expand Up @@ -8,8 +8,7 @@

#include "cursesdef.h"
#include "input.h"

class nc_color;
#include "color.h"

/**
* UI class for displaying messages or querying player input with popups.
Expand Down Expand Up @@ -163,6 +162,10 @@ class query_popup
* Specify starting cursor position.
**/
query_popup &cursor( size_t pos );
/**
* Specify the default message color.
**/
query_popup &default_color( const nc_color &d_color );

/**
* Draw the UI. An input context should be provided using `context()`
Expand Down Expand Up @@ -194,6 +197,7 @@ class query_popup
std::string text;
std::vector<query_option> options;
size_t cur;
nc_color default_text_color;
bool anykey;
bool cancel;
bool ontop;
Expand Down

0 comments on commit 917f536

Please sign in to comment.