Skip to content

Commit

Permalink
Groups UI: Update with commander group changes
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Aug 29, 2023
1 parent 601c1d8 commit 39d873d
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/cmddroid.cpp
Expand Up @@ -36,6 +36,7 @@
#include "console.h"
#include "objmem.h"
#include "droid.h"
#include "hci.h"

/**This represents the current selected player, which is the client's player.*/
extern UDWORD selectedPlayer;
Expand Down Expand Up @@ -88,6 +89,8 @@ bool cmdDroidAddDroid(DROID *psCommander, DROID *psDroid)
ASSERT_OR_RETURN(false, psCommander != nullptr, "psCommander is null?");
ASSERT_OR_RETURN(false, psDroid != nullptr, "psDroid is null?");

auto initialDroidGroup = psDroid->group;

if (psCommander->psGroup == nullptr)
{
psGroup = grpCreate();
Expand Down Expand Up @@ -120,6 +123,11 @@ bool cmdDroidAddDroid(DROID *psCommander, DROID *psDroid)
}
}

if (initialDroidGroup != psDroid->group)
{
intGroupsChanged();
}

return addedToGroup;
}

Expand Down
11 changes: 9 additions & 2 deletions src/droid.cpp
Expand Up @@ -288,9 +288,16 @@ int32_t droidDamage(DROID *psDroid, unsigned damage, WEAPON_CLASS weaponClass, W

relativeDamage = objDamage(psDroid, damage, psDroid->originalBody, weaponClass, weaponSubClass, isDamagePerSecond, minDamage, empRadiusHit);

if (relativeDamage != 0 && psDroid->player == selectedPlayer && psDroid->group != UBYTE_MAX && psDroid->timeLastHit == gameTime)
if (relativeDamage != 0 && psDroid->player == selectedPlayer && psDroid->timeLastHit == gameTime)
{
intGroupDamaged(psDroid->group, (relativeDamage > 0) ? static_cast<uint64_t>(relativeDamage) : 0, (relativeDamage < 0)); // update UI information
if (psDroid->group != UBYTE_MAX)
{
intGroupDamaged(psDroid->group, (relativeDamage > 0) ? static_cast<uint64_t>(relativeDamage) : 0, (relativeDamage < 0)); // update UI information
}
else if (psDroid->psGroup && psDroid->psGroup->psCommander)
{
intCommanderGroupDamaged(psDroid->psGroup->psCommander, (relativeDamage > 0) ? static_cast<uint64_t>(relativeDamage) : 0, (relativeDamage < 0)); // update UI information
}
}

if (relativeDamage > 0)
Expand Down
11 changes: 11 additions & 0 deletions src/group.cpp
Expand Up @@ -31,6 +31,7 @@
#include "group.h"
#include "droid.h"
#include "order.h"
#include "hci.h"
#include <map>

// Group system variables: grpGlobalManager enables to remove all the groups to Shutdown the system
Expand Down Expand Up @@ -150,6 +151,11 @@ void DROID_GROUP::add(DROID *psDroid)
syncDebug("Droid %d joining command group %d", psDroid->id, psCommander != nullptr ? psCommander->id : 0);
}
}

if (type == GT_COMMAND && psCommander)
{
intCommanderGroupChanged(psCommander);
}
}

// remove a droid from a group
Expand Down Expand Up @@ -222,6 +228,11 @@ void DROID_GROUP::remove(DROID *psDroid)
grpGlobalManager.erase(id);
delete this;
}

if (type == GT_COMMAND && psCommander)
{
intCommanderGroupChanged(psCommander);
}
}

// count the members of a group
Expand Down
13 changes: 13 additions & 0 deletions src/hci.cpp
Expand Up @@ -2044,6 +2044,19 @@ void intGroupDamaged(UBYTE group, uint64_t additionalDamage, bool unitKilled)
}
}

void intCommanderGroupChanged(const DROID *psCommander)
{
intGroupsChanged(); // just trigger full group change event
}

void intCommanderGroupDamaged(const DROID *psCommander, uint64_t additionalDamage, bool unitKilled)
{
if (groupsUI)
{
groupsUI->addCommanderGroupDamageForCurrentTick(psCommander, additionalDamage, unitKilled);
}
}

bool intShowGroupSelectionMenu()
{
bool isSpectator = (bMultiPlayer && selectedPlayer < NetPlay.players.size() && NetPlay.players[selectedPlayer].isSpectator);
Expand Down
4 changes: 4 additions & 0 deletions src/hci.h
Expand Up @@ -312,6 +312,10 @@ void intAlliedResearchChanged();
void intGroupsChanged(optional<UBYTE> selectedGroup = nullopt);
void intGroupDamaged(UBYTE group, uint64_t additionalDamage, bool unitKilled);

/* Tell the interface that commander groups have changed */
void intCommanderGroupChanged(const DROID *psCommander);
void intCommanderGroupDamaged(const DROID *psCommander, uint64_t additionalDamage, bool unitKilled);

/* Sync the interface to an object */
void intObjectSelected(BASE_OBJECT *psObj);

Expand Down
14 changes: 14 additions & 0 deletions src/hci/groups.cpp
Expand Up @@ -77,6 +77,15 @@ class GroupsUIController: public std::enable_shared_from_this<GroupsUIController
}
}

void addCommanderGroupDamageForCurrentTick(const DROID *psCommander, uint64_t additionalDamage, bool unitKilled)
{
if (psCommander->group >= groupInfo.size())
{
return;
}
addGroupDamageForCurrentTick(psCommander->group, additionalDamage, unitKilled);
}

void selectGroup(size_t groupNumber)
{
// select the group
Expand Down Expand Up @@ -315,6 +324,11 @@ void GroupsForum::addGroupDamageForCurrentTick(size_t group, uint64_t additional
groupsUIController->addGroupDamageForCurrentTick(group, additionalDamage, unitKilled);
}

void GroupsForum::addCommanderGroupDamageForCurrentTick(const DROID *psCommander, uint64_t additionalDamage, bool unitKilled)
{
groupsUIController->addCommanderGroupDamageForCurrentTick(psCommander, additionalDamage, unitKilled);
}

void GroupsForum::addTabList()
{
attach(groupsList = IntListTabWidget::make(TabAlignment::RightAligned));
Expand Down
1 change: 1 addition & 0 deletions src/hci/groups.h
Expand Up @@ -54,6 +54,7 @@ class GroupsForum: public IntFormAnimated
void updateData();
void updateSelectedGroup(size_t group);
void addGroupDamageForCurrentTick(size_t group, uint64_t additionalDamage, bool unitKilled);
void addCommanderGroupDamageForCurrentTick(const DROID *psCommander, uint64_t additionalDamage, bool unitKilled);
private:
std::shared_ptr<GroupButton> makeGroupButton(size_t groupNumber);
void addTabList();
Expand Down

0 comments on commit 39d873d

Please sign in to comment.