Skip to content

Commit

Permalink
feat: Show item kill count in the examine item menu, make the menu op…
Browse files Browse the repository at this point in the history
…tion red (#5511)

* color kills button

* print item kill count in examine item menu

* add switch case to acknowledge existence of new enum value
  • Loading branch information
Soadreqm authored Oct 5, 2024
1 parent b49bc82 commit 0d3b37f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
29 changes: 25 additions & 4 deletions src/examine_item_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@ bool run(
std::vector<action_entry> actions;
uilist action_list;

const auto add_entry = [&]( const char *act, hint_rating hint, std::function<bool()> &&on_select ) {
/**
Add a menu entry
@param act the action name, corresponding to an action in data/raw/keybindings.json
@param hint determines what color the text will be
@param on_select lambda function for what the menu entry actually does
@param number will be printed after the menu entry in parentheses, optional
INT_MIN is treated as a null value
*/
const auto add_entry = [&]( const char *act, hint_rating hint, std::function<bool()> &&on_select,
int number = INT_MIN ) {
action_entry ae;
ae.action = act;
ae.on_select = std::move( on_select );
Expand All @@ -97,7 +106,12 @@ bool run(
std::string bound_key = ctxt.key_bound_to( act );
int bound_key_i = bound_key.size() == 1 ? bound_key[0] : '?';
std::string act_name = ctxt.get_action_name( act );
action_list.addentry( actions.size(), true, bound_key_i, act_name );
if( number == INT_MIN ) {
action_list.addentry( actions.size(), true, bound_key_i, act_name );
} else {
action_list.addentry( actions.size(), true, bound_key_i,
act_name + " (" + std::to_string( number ) + ")" );
}

auto &list_entry = action_list.entries.back();
switch( hint ) {
Expand All @@ -110,6 +124,9 @@ bool run(
case hint_rating::good:
list_entry.text_color = c_light_green;
break;
case hint_rating::blood:
list_entry.text_color = c_red;
break;
}
};

Expand Down Expand Up @@ -191,10 +208,10 @@ bool run(
} );

if( itm.kill_count() > 0 ) {
add_entry( "SHOW_KILL_LIST", hint_rating::good, [&]() {
add_entry( "SHOW_KILL_LIST", hint_rating::blood, [&]() {
itm.show_kill_list();
return true;
} );
}, itm.kill_count() );
}

if( !itm.is_favorite ) {
Expand Down Expand Up @@ -399,6 +416,10 @@ hint_rating rate_action_reload( const avatar &you, const item &it )
case hint_rating::good:
return hint_rating::good;

case hint_rating::blood:
// This doesn't happen, but if it did, just pass the color hint along
return hint_rating::blood;

case hint_rating::cant:
continue;

Expand Down
4 changes: 3 additions & 1 deletion src/examine_item_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ enum class hint_rating : int {
/** Item should display as red (action impossible at the moment) */
iffy,
/** Item should display as green (action possible at the moment) */
good
good,
/** Item should display as bright red (kill list) */
blood
};

hint_rating rate_action_use( const avatar &you, const item &it );
Expand Down

0 comments on commit 0d3b37f

Please sign in to comment.