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

feat: Show item kill count in the examine item menu, make the menu option red #5511

Merged
merged 3 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading