Skip to content

Commit

Permalink
TeamStrategyView: Add background color support
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Oct 20, 2023
1 parent 2c9a5ff commit b84f7c9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/hci/teamstrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ class TeamStrategyView: public W_FORM
void setUpdatingPlayers(bool enabled);
bool getUpdatingPlayer() { return updatingPlayers; }
std::shared_ptr<WzTeamStrategyColumnImagesManager> getSharedColumnImagesManager() const { return columnImagesManager; }
void setBackgroundColor(PIELIGHT color);

public:
virtual void display(int xOffset, int yOffset) override;
Expand All @@ -338,6 +339,7 @@ class TeamStrategyView: public W_FORM
std::shared_ptr<W_LABEL> noTeammatesLabel;
size_t playerNameColIdx = 0;
bool updatingPlayers = false;
PIELIGHT backgroundColor = pal_RGBA(0,0,0,0);
};

WzTeamStrategyColumnImagesManager::~WzTeamStrategyColumnImagesManager()
Expand Down Expand Up @@ -800,7 +802,12 @@ TeamStrategyView::~TeamStrategyView()

void TeamStrategyView::display(int xOffset, int yOffset)
{
// currently, do nothing
int x0 = x() + xOffset;
int y0 = y() + yOffset;
if (backgroundColor.rgba != 0)
{
pie_UniTransBoxFill(x0, y0, x0 + width(), y0 + height(), backgroundColor);
}
}

void TeamStrategyView::geometryChanged()
Expand Down Expand Up @@ -1079,6 +1086,11 @@ void TeamStrategyView::setUpdatingPlayers(bool enabled)
}
}

void TeamStrategyView::setBackgroundColor(PIELIGHT color)
{
backgroundColor = color;
}

std::pair<std::vector<size_t>, size_t> TeamStrategyView::getMaxTableColumnDataWidths()
{
size_t totalNeededColumnWidth = 0;
Expand Down Expand Up @@ -1118,8 +1130,7 @@ int32_t TeamStrategyView::idealHeight()
// Returns true if there are *any* teams with more than one human player
bool gameHasTeamStrategyView(bool allowAIs)
{
std::unordered_set<int32_t> teamsWitHumanPlayers;
std::vector<uint32_t> playersOnSameTeamAsSelectedPlayer;
std::unordered_set<int32_t> teamsWitIncludedPlayers;
for (int32_t player = 0; player < std::min<int32_t>(game.maxPlayers, MAX_PLAYERS); ++player)
{
// Check type of player
Expand All @@ -1129,7 +1140,7 @@ bool gameHasTeamStrategyView(bool allowAIs)
)
{
auto teamNumber = checkedGetPlayerTeam(player);
auto result = teamsWitHumanPlayers.insert(teamNumber);
auto result = teamsWitIncludedPlayers.insert(teamNumber);
if (!result.second)
{
// more than one included player on a team
Expand Down Expand Up @@ -1157,6 +1168,18 @@ bool transformTeamStrategyViewMode(const std::shared_ptr<WIDGET>& view, bool upd
return true;
}

bool teamStrategyViewSetBackgroundColor(const std::shared_ptr<WIDGET>& view, PIELIGHT color)
{
auto pTeamStrategyView = std::dynamic_pointer_cast<TeamStrategyView>(view);
if (!pTeamStrategyView)
{
return false;
}

pTeamStrategyView->setBackgroundColor(color);
return true;
}

void aiInformTeamOfStrategy(uint32_t aiPlayerIdx, const std::unordered_map<WEAPON_SUBCLASS, WzStrategyPlanningState>& weaponStrategy, const std::unordered_map<WzStrategyPlanningUnitTypes, WzStrategyPlanningState>& unitTypesStrategy)
{
ASSERT_OR_RETURN(, aiPlayerIdx < MAX_PLAYERS, "Invalid aiPlayerIdx: %" PRIu32, aiPlayerIdx);
Expand Down
1 change: 1 addition & 0 deletions src/hci/teamstrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ constexpr size_t WzStrategyPlanningUnitTypes_NUM_TYPES = 3;
bool gameHasTeamStrategyView(bool allowAIs = false);
std::shared_ptr<WIDGET> createTeamStrategyView(bool allowAIs = false);
bool transformTeamStrategyViewMode(const std::shared_ptr<WIDGET>& teamStrategyView, bool updatingPlayers);
bool teamStrategyViewSetBackgroundColor(const std::shared_ptr<WIDGET>& view, PIELIGHT color);

bool recvStrategyPlanUpdate(NETQUEUE queue);

Expand Down

0 comments on commit b84f7c9

Please sign in to comment.