Add display::viewing_team_is_playing

Common enough check that this is useful in pursuit of removing direct index usage.
This commit is contained in:
Charles Dang 2024-08-31 21:32:35 -04:00
parent 500e937ac9
commit fbc7a27cdd
7 changed files with 13 additions and 12 deletions

View file

@ -358,7 +358,7 @@ namespace { // Private helpers for move_unit()
: spectator_(move_spectator)
, skip_sighting_(skip_sightings)
, skip_ally_sighting_(skip_ally_sightings)
, playing_team_is_viewing_(display::get_singleton()->playing_team_index() == display::get_singleton()->viewing_team_index() || display::get_singleton()->show_everything())
, playing_team_is_viewing_(display::get_singleton()->viewing_team_is_playing() || display::get_singleton()->show_everything())
, route_(route)
, begin_(route.begin())
, full_end_(route.end())

View file

@ -124,6 +124,11 @@ public:
const team& playing_team() const;
const team& viewing_team() const;
bool viewing_team_is_playing() const
{
return viewing_team_index() == playing_team_index();
}
/**
* Sets the team controlled by the player using the computer.
* Data from this team will be displayed in the game status.

View file

@ -72,8 +72,6 @@ const game_state & play_controller::hotkey_handler::gamestate() const {
bool play_controller::hotkey_handler::browse() const { return play_controller_.is_browsing(); }
bool play_controller::hotkey_handler::linger() const { return play_controller_.is_linger_mode(); }
bool play_controller::hotkey_handler::viewing_team_is_playing() const { return gui()->viewing_team_index() == gui()->playing_team_index(); }
void play_controller::hotkey_handler::objectives(){
menu_handler_.objectives();
}

View file

@ -70,8 +70,6 @@ protected:
bool browse() const;
bool linger() const;
bool viewing_team_is_playing() const;
public:
hotkey_handler(play_controller &, saved_game &);
~hotkey_handler();

View file

@ -238,12 +238,12 @@ bool playsingle_controller::hotkey_handler::can_execute_command(const hotkey::ui
case hotkey::HOTKEY_DELAY_SHROUD:
return !linger()
&& (gui()->viewing_team().uses_fog() || gui()->viewing_team().uses_shroud())
&& viewing_team_is_playing()
&& gui()->viewing_team_is_playing()
&& gui()->viewing_team().is_local_human()
&& !events::commands_disabled;
case hotkey::HOTKEY_UPDATE_SHROUD:
return !linger()
&& viewing_team_is_playing()
&& gui()->viewing_team_is_playing()
&& gui()->viewing_team().is_local_human()
&& !events::commands_disabled
&& gui()->viewing_team().auto_shroud_updates() == false;

View file

@ -1238,7 +1238,7 @@ void play_controller::check_next_scenario_is_known() {
bool play_controller::can_use_synced_wml_menu() const
{
const team& viewing_team = gui_->viewing_team();
return gui_->viewing_team_index() == gui_->playing_team_index() && !events::commands_disabled && viewing_team.is_local_human()
return gui_->viewing_team_is_playing() && !events::commands_disabled && viewing_team.is_local_human()
&& !is_browsing();
}

View file

@ -148,7 +148,7 @@ static unit_const_ptr get_selected_unit_ptr(const reports::context& rc)
static config gray_inactive(const reports::context& rc, const std::string &str, const std::string& tooltip = "")
{
if ( rc.screen().viewing_team().side() == rc.screen().playing_team().side() )
if ( rc.screen().viewing_team_is_playing() )
return text_report(str, tooltip);
return text_report(span_color(font::GRAY_COLOR) + str + naps, tooltip);
@ -1453,7 +1453,7 @@ REPORT_GENERATOR(gold, rc)
if (rc.wb())
fake_gold -= rc.wb()->get_spent_gold_for(viewing_team.side());
char const *end = naps;
if (viewing_team.side() != rc.screen().playing_team().side()) {
if (!rc.screen().viewing_team_is_playing()) {
str << span_color(font::GRAY_COLOR);
}
else if (fake_gold < 0) {
@ -1511,7 +1511,7 @@ REPORT_GENERATOR(income, rc)
const team& viewing_team = rc.screen().viewing_team();
team_data td(rc.dc(), viewing_team);
char const *end = naps;
if (viewing_team.side() != rc.screen().playing_team().side()) {
if (!rc.screen().viewing_team_is_playing()) {
if (td.net_income < 0) {
td.net_income = - td.net_income;
str << span_color(font::GRAY_COLOR);
@ -1773,7 +1773,7 @@ REPORT_GENERATOR(report_countdown, rc)
std::ostringstream str;
sec = viewing_team.countdown_time() / 1000;
char const *end = naps;
if (viewing_team.side() != rc.screen().playing_team().side())
if (!rc.screen().viewing_team_is_playing())
str << span_color(font::GRAY_COLOR);
else if (sec < 60)
str << "<span foreground=\"#c80000\">";