Skip to content

Commit

Permalink
Replace kills screen with new scores screen
Browse files Browse the repository at this point in the history
Re-purpose the kills screen keybinding ')' to open a new UI that can
display kills as before, but can also display the new scores info.
  • Loading branch information
jbytheway committed Sep 19, 2019
1 parent b76c4bb commit 0550fb9
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 41 deletions.
4 changes: 2 additions & 2 deletions data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -1855,9 +1855,9 @@
},
{
"type": "keybinding",
"name": "View Kills",
"name": "View Scores",
"category": "DEFAULTMODE",
"id": "kills",
"id": "scores",
"bindings": [ { "input_method": "keyboard", "key": ")" } ]
},
{
Expand Down
8 changes: 4 additions & 4 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ std::string action_ident( action_id act )
return "missions";
case ACTION_FACTIONS:
return "factions";
case ACTION_KILLS:
return "kills";
case ACTION_SCORES:
return "scores";
case ACTION_MORALE:
return "morale";
case ACTION_MESSAGES:
Expand Down Expand Up @@ -401,7 +401,7 @@ bool can_action_change_worldstate( const action_id act )
case ACTION_MAP:
case ACTION_SKY:
case ACTION_MISSIONS:
case ACTION_KILLS:
case ACTION_SCORES:
case ACTION_FACTIONS:
case ACTION_MORALE:
case ACTION_MESSAGES:
Expand Down Expand Up @@ -866,7 +866,7 @@ action_id handle_action_menu()
} else if( category == _( "Info" ) ) {
REGISTER_ACTION( ACTION_PL_INFO );
REGISTER_ACTION( ACTION_MISSIONS );
REGISTER_ACTION( ACTION_KILLS );
REGISTER_ACTION( ACTION_SCORES );
REGISTER_ACTION( ACTION_FACTIONS );
REGISTER_ACTION( ACTION_MORALE );
REGISTER_ACTION( ACTION_MESSAGES );
Expand Down
4 changes: 2 additions & 2 deletions src/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ enum action_id : int {
ACTION_SKY,
/** Display missions screen */
ACTION_MISSIONS,
/** Display kills list screen */
ACTION_KILLS,
/** Display scores screen */
ACTION_SCORES,
/** Display factions screen */
ACTION_FACTIONS,
/** Display morale effects screen */
Expand Down
5 changes: 3 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
#include "safemode_ui.h"
#include "scenario.h"
#include "scent_map.h"
#include "scores_ui.h"
#include "sdltiles.h"
#include "sounds.h"
#include "start_location.h"
Expand Down Expand Up @@ -2351,7 +2352,7 @@ input_context get_default_mode_input_context()
ctxt.register_action( "sky" );
ctxt.register_action( "missions" );
ctxt.register_action( "factions" );
ctxt.register_action( "kills" );
ctxt.register_action( "scores" );
ctxt.register_action( "morale" );
ctxt.register_action( "messages" );
ctxt.register_action( "help" );
Expand Down Expand Up @@ -2561,7 +2562,7 @@ void game::death_screen()
{
gamemode->game_over();
Messages::display_messages();
get_kill_tracker().disp_kills();
show_scores_ui( stats(), get_kill_tracker() );
disp_NPC_epilogues();
follower_ids.clear();
disp_faction_ends();
Expand Down
5 changes: 3 additions & 2 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "popup.h"
#include "ranged.h"
#include "safemode_ui.h"
#include "scores_ui.h"
#include "sounds.h"
#include "veh_type.h"
#include "vehicle.h"
Expand Down Expand Up @@ -2174,8 +2175,8 @@ bool game::handle_action()
list_missions();
break;

case ACTION_KILLS:
get_kill_tracker().disp_kills();
case ACTION_SCORES:
show_scores_ui( stats(), get_kill_tracker() );
break;

case ACTION_FACTIONS:
Expand Down
47 changes: 19 additions & 28 deletions src/kill_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,47 +57,37 @@ int kill_tracker::kill_xp() const
return ret;
}

void kill_tracker::disp_kills() const
std::string kill_tracker::get_kills_text() const
{
catacurses::window w = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH,
point( std::max( 0, ( TERMX - FULL_SCREEN_WIDTH ) / 2 ), std::max( 0,
( TERMY - FULL_SCREEN_HEIGHT ) / 2 ) ) );

std::vector<std::string> data;
int totalkills = 0;
const int colum_width = ( getmaxx( w ) - 2 ) / 3; // minus border

std::map<std::tuple<std::string, std::string, std::string>, int> kill_counts;
std::map<std::tuple<std::string, std::string, nc_color>, int> kill_counts;

// map <name, sym, color> to kill count
for( auto &elem : kills ) {
for( const std::pair<mtype_id, int> &elem : kills ) {
const mtype &m = elem.first.obj();
auto key = std::make_tuple( m.nname(), m.sym, string_from_color( m.color ) );
auto key = std::make_tuple( m.nname(), m.sym, m.color );
kill_counts[key] += elem.second;
totalkills += elem.second;
}

for( const auto &entry : kill_counts ) {
const int num_kills = entry.second;
const std::string &mname = std::get<0>( entry.first );
const std::string &symbol = std::get<1>( entry.first );
const nc_color color = std::get<2>( entry.first );
std::ostringstream buffer;
buffer << "<color_" << std::get<2>( entry.first ) << ">";
buffer << std::get<1>( entry.first ) << "</color>" << " ";
buffer << "<color_light_gray>" << std::get<0>( entry.first ) << "</color>";
const int w = colum_width - utf8_width( std::get<0>( entry.first ) );
buffer.width( w - 3 ); // gap between cols, monster sym, space
buffer.fill( ' ' );
buffer << entry.second;
buffer.width( 0 );
buffer << string_format( "%4d ", num_kills );
buffer << colorize( symbol, color ) << " ";
buffer << colorize( mname, c_light_gray );
data.push_back( buffer.str() );
}
for( const auto &npc_name : npc_kills ) {
totalkills += 1;
std::ostringstream buffer;
buffer << "<color_magenta>@ " << npc_name << "</color>";
const int w = colum_width - utf8_width( npc_name );
buffer.width( w - 3 ); // gap between cols, monster sym, space
buffer.fill( ' ' );
buffer << "1";
buffer.width( 0 );
buffer << string_format( "%4d ", 1 );
buffer << colorize( "@ " + npc_name, c_magenta );
data.push_back( buffer.str() );
}
std::ostringstream buffer;
Expand All @@ -106,14 +96,15 @@ void kill_tracker::disp_kills() const
} else {
buffer << string_format( _( "KILL COUNT: %d" ), totalkills );
if( get_option<bool>( "STATS_THROUGH_KILLS" ) ) {
buffer << " ";
buffer << string_format( _( "Experience: %d (%d points available)" ), kill_xp(),
buffer << string_format( _( "\nExperience: %d (%d points available)" ), kill_xp(),
g->u.free_upgrade_points() );
}
buffer << '\n';
}
display_table( w, buffer.str(), 3, data );

g->refresh_all();
for( const std::string &line : data ) {
buffer << '\n' << line;
}
return buffer.str();
}

void kill_tracker::clear()
Expand Down
2 changes: 1 addition & 1 deletion src/kill_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class kill_tracker : public event_subscriber
// returns player's "kill xp" for monsters via STK
int kill_xp() const;

void disp_kills() const;
std::string get_kills_text() const;

void clear();

Expand Down
100 changes: 100 additions & 0 deletions src/scores_ui.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#include "scores_ui.h"

#include "cursesdef.h"
#include "kill_tracker.h"
#include "input.h"
#include "output.h"
#include "event_statistics.h"
#include "stats_tracker.h"

static std::string get_scores_text( stats_tracker &stats )
{
std::ostringstream os;
std::vector<const score *> valid_scores = stats.valid_scores();
for( const score *scr : valid_scores ) {
os << scr->description( stats ) << '\n';
}
if( valid_scores.empty() ) {
os << _( "This game has no valid scores.\n" );
}
os << _( "\nNote that only scores that existed when you started this game and still exist now "
"will appear here." );
return os.str();
}

void show_scores_ui( stats_tracker &stats, const kill_tracker &kills )
{
catacurses::window w = new_centered_win( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH );

enum class tab_mode {
scores,
kills,
num_tabs,
first_tab = scores,
};

tab_mode tab = static_cast<tab_mode>( 0 );
input_context ctxt( "SCORES" );
ctxt.register_cardinal();
ctxt.register_action( "QUIT" );
ctxt.register_action( "HELP_KEYBINDINGS" );

catacurses::window w_view = catacurses::newwin( getmaxy( w ) - 4, getmaxx( w ) - 1,
point( getbegx( w ), getbegy( w ) + 3 ) );
scrolling_text_view view( w_view );
bool new_tab = true;

while( true ) {
werase( w );

const std::vector<std::pair<tab_mode, std::string>> tabs = {
{ tab_mode::scores, _( "SCORES" ) },
{ tab_mode::kills, _( "KILLS" ) },
};
draw_tabs( w, tabs, tab );
draw_border_below_tabs( w );

if( new_tab ) {
switch( tab ) {
case tab_mode::scores:
view.set_text( get_scores_text( stats ) );
break;
case tab_mode::kills:
view.set_text( kills.get_kills_text() );
break;
case tab_mode::num_tabs:
assert( false );
break;
}
}

wrefresh( w );

view.draw( c_white );


const std::string action = ctxt.handle_input();
new_tab = false;
if( action == "RIGHT" ) {
tab = static_cast<tab_mode>( static_cast<int>( tab ) + 1 );
if( tab >= tab_mode::num_tabs ) {
tab = tab_mode::first_tab;
}
new_tab = true;
} else if( action == "LEFT" ) {
tab = static_cast<tab_mode>( static_cast<int>( tab ) - 1 );
if( tab < tab_mode::first_tab ) {
tab = static_cast<tab_mode>( static_cast<int>( tab_mode::num_tabs ) - 1 );
}
new_tab = true;
} else if( action == "DOWN" ) {
view.scroll_down();
} else if( action == "UP" ) {
view.scroll_up();
} else if( action == "CONFIRM" ) {
break;
} else if( action == "QUIT" ) {
break;
}
}
}
9 changes: 9 additions & 0 deletions src/scores_ui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef CATA_SCORES_UI_HPP
#define CATA_SCORES_UI_HPP

class kill_tracker;
class stats_tracker;

void show_scores_ui( stats_tracker &, const kill_tracker & );

#endif // CATA_SCORES_UI_HPP

0 comments on commit 0550fb9

Please sign in to comment.