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

Improvements to groups and UI #4016

Merged
merged 6 commits into from
Jul 28, 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
3 changes: 2 additions & 1 deletion src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,8 @@ void droidUpdate(DROID *psDroid)
if (psDroid->repairGroup != UBYTE_MAX &&
psDroid->order.type != DORDER_RTR &&
psDroid->order.type != DORDER_RTR_SPECIFIED &&
psDroid->order.type != DORDER_RTB)
psDroid->order.type != DORDER_RTB &&
secondaryGetState(psDroid, DSO_REPAIR_LEVEL) == DSS_REPLEV_NEVER)
Comment on lines -836 to +837
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pastdue and I are uncertain about the purpose of this change. The intent for this if statement was to prevent a retreating unit, that was disturbed from rtr/rtb, forever having a red group number until fully repaired. Unless there is some specific behavior difference we aren't noticing.

Copy link
Contributor Author

@Monsterovich Monsterovich Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KJeff01

forever having a red group number until fully repaired. Unless there is some specific behavior difference we aren't noticing.

This is only possible if there are no repair facilities or repairing units.

In the worst case, I'll just set a "do or die" flag on the units and just send them into battle, but it's too expensive to lose units. That's what alfred007 was talking about on Discord:

pic

The point is to keep as many units as possible, at the very least let them stand at the HQ with repair group set until I build repair facilities and send them to be repaired. Currently, the damaged units will just go into battle with low health which is worse.

Copy link
Contributor Author

@Monsterovich Monsterovich Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also an idea to make damaged units that stand at the HQ, automatically go to repair when at least one repair facility appears (I can do this, but it would be in a separate PR).

{
droidWasFullyRepairedBase(psDroid);
}
Expand Down
36 changes: 35 additions & 1 deletion src/hci/groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class GroupsUIController: public std::enable_shared_from_this<GroupsUIController
struct GroupDisplayInfo
{
size_t numberInGroup = 0;
size_t numberDamagedInGroup = 0;
size_t numberCommandedByGroup = 0; // the number of droids commanded by commanders in this group
uint64_t totalGroupMaxHealth = 0;
DROID_TEMPLATE displayDroidTemplate;
Expand Down Expand Up @@ -108,6 +109,7 @@ class GroupButton : public DynamicIntFancyButton
std::shared_ptr<GroupsUIController> controller;
std::shared_ptr<W_LABEL> groupNumberLabel;
std::shared_ptr<W_LABEL> groupCountLabel;
std::shared_ptr<W_LABEL> groupDamagedCountLabel;
size_t groupNumber;
uint32_t lastUpdatedGlowAlphaTime = 0;
protected:
Expand Down Expand Up @@ -135,6 +137,12 @@ class GroupButton : public DynamicIntFancyButton
groupCountLabel->setString("");
groupCountLabel->setTransparentToMouse(true);

attach(groupDamagedCountLabel = std::make_shared<W_LABEL>());
groupDamagedCountLabel->setGeometry(0, 0, 16, 16);
groupDamagedCountLabel->setFontColour(pal_RGBA(255, 0, 0, 255) /* red */);
groupDamagedCountLabel->setString("");
groupDamagedCountLabel->setTransparentToMouse(true);

buttonBackgroundEmpty = true;

const std::string groupNumberStr = std::to_string(groupNumber);
Expand Down Expand Up @@ -193,7 +201,7 @@ class GroupButton : public DynamicIntFancyButton
lastUpdatedGlowAlphaTime = realTime;
}

if (!groupInfo->numberInGroup)
if (!groupInfo->numberInGroup && !groupInfo->numberDamagedInGroup)
{
groupCountLabel->setString("");
displayBlank(xOffset, yOffset, false);
Expand All @@ -202,6 +210,26 @@ class GroupButton : public DynamicIntFancyButton
{
displayIMD(AtlasImage(), ImdObject::DroidTemplate(&(groupInfo->displayDroidTemplate)), xOffset, yOffset);
groupCountLabel->setString(WzString::fromUtf8(astringf("%u", groupInfo->numberInGroup)));
int32_t xNumberOffset = 0;
const uint32_t xFitNumberInTheBox = 16;
if (groupCountLabel->getMaxLineWidth() > xFitNumberInTheBox)
{
xNumberOffset -= groupCountLabel->getMaxLineWidth() - xFitNumberInTheBox;
}
groupCountLabel->move(
OBJ_TEXTX + 40 + xNumberOffset - groupDamagedCountLabel->getMaxLineWidth(),
groupCountLabel->y()
);
}

if (!groupInfo->numberDamagedInGroup)
{
groupDamagedCountLabel->setString("");
}
else
{
groupDamagedCountLabel->setString(WzString::fromUtf8(astringf("+%u", groupInfo->numberDamagedInGroup)));
groupDamagedCountLabel->move(groupCountLabel->x() + groupCountLabel->getMaxLineWidth(), groupCountLabel->y());
}

if (groupInfo->currAttackGlowAlpha > 0)
Expand Down Expand Up @@ -270,6 +298,7 @@ void GroupsUIController::updateData()
struct AccumulatedGroupInfo
{
size_t numberInGroup = 0;
size_t numberDamagedInGroup = 0;
size_t numberCommandedByGroup = 0; // the number of droids commanded by commanders in this group
uint64_t totalGroupMaxHealth = 0;
DROID *displayDroid = nullptr;
Expand All @@ -280,6 +309,10 @@ void GroupsUIController::updateData()
std::array<AccumulatedGroupInfo, 10> calculatedGroupInfo;
for (DROID *psDroid : apsDroidLists[selectedPlayer])
{
if (psDroid->repairGroup < calculatedGroupInfo.size()) {
calculatedGroupInfo[psDroid->repairGroup].numberDamagedInGroup++;
}

auto groupIdx = psDroid->group;
if (psDroid->group >= calculatedGroupInfo.size())
{
Expand Down Expand Up @@ -313,6 +346,7 @@ void GroupsUIController::updateData()
const auto& calculatedInfo = calculatedGroupInfo[idx];
auto& storedGroupInfo = groupInfo[idx];
storedGroupInfo.numberInGroup = calculatedInfo.numberInGroup;
storedGroupInfo.numberDamagedInGroup = calculatedInfo.numberDamagedInGroup;
storedGroupInfo.numberCommandedByGroup = calculatedInfo.numberCommandedByGroup;
storedGroupInfo.totalGroupMaxHealth = calculatedInfo.totalGroupMaxHealth;
if (calculatedInfo.numberInGroup > 0)
Expand Down
1 change: 1 addition & 0 deletions src/order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3330,6 +3330,7 @@ void secondaryCheckDamageLevel(DROID *psDroid)
if (psDroid->group != UBYTE_MAX)
{
psDroid->repairGroup = psDroid->group;
intGroupsChanged(psDroid->group);
}
psDroid->group = UBYTE_MAX;
}
Expand Down
Loading