-
Notifications
You must be signed in to change notification settings - Fork 118
Feat/observer summary UI #1770
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
base: main
Are you sure you want to change the base?
Feat/observer summary UI #1770
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,6 +99,187 @@ static GameWindow *staticTextNumberOfUnitsLost = NULL; | |
| static GameWindow *staticTextPlayerName = NULL; | ||
|
|
||
| static NameKeyType s_replayObserverNameKey = NAMEKEY_INVALID; | ||
| static Int s_playerNameOriginalWidth = 0; | ||
| static Int s_playerNameOriginalHeight = 0; | ||
| static Bool s_playerNameSizeCaptured = FALSE; | ||
|
|
||
| static void ensurePlayerNameLabelHeight(Bool needsTwoLines) | ||
| { | ||
| if (!staticTextPlayerName) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (!s_playerNameSizeCaptured) | ||
| { | ||
| staticTextPlayerName->winGetSize(&s_playerNameOriginalWidth, &s_playerNameOriginalHeight); | ||
| s_playerNameSizeCaptured = TRUE; | ||
| } | ||
|
|
||
| if (s_playerNameOriginalHeight <= 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| Int currentWidth = 0; | ||
| Int currentHeight = 0; | ||
| staticTextPlayerName->winGetSize(¤tWidth, ¤tHeight); | ||
|
|
||
| const Int targetHeight = needsTwoLines ? s_playerNameOriginalHeight * 2 : s_playerNameOriginalHeight; | ||
| if (currentHeight != targetHeight) | ||
| { | ||
| staticTextPlayerName->winSetSize(currentWidth, targetHeight); | ||
| } | ||
| } | ||
|
|
||
| static AsciiString formatCompactCash(UnsignedInt cash) | ||
| { | ||
| AsciiString cashText; | ||
|
|
||
| if (cash >= 1000000) | ||
| { | ||
| if ((cash % 1000000) == 0) | ||
| { | ||
| cashText.format("$%uM", cash / 1000000); | ||
| } | ||
| else | ||
| { | ||
| const float millions = static_cast<float>(cash) / 1000000.0f; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cast not needed |
||
| cashText.format("$%.1fM", millions); | ||
| } | ||
| } | ||
| else if (cash >= 1000) | ||
| { | ||
| if ((cash % 1000) == 0) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unneccesary, displaying 1.0k is perfectly fine |
||
| { | ||
| cashText.format("$%uK", cash / 1000); | ||
| } | ||
| else | ||
| { | ||
| const float thousands = static_cast<float>(cash) / 1000.0f; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cast not needed |
||
| cashText.format("$%.1fK", thousands); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| cashText.format("$%u", cash); | ||
| } | ||
|
|
||
| return cashText; | ||
| } | ||
|
|
||
| // TheSuperHackers @feature GitHubCopilot 01/11/2025 Surface cash/rank/xp summary for observer overlays. | ||
| static UnicodeString formatObserverPlayerSummary(const Player *player) | ||
| { | ||
| UnicodeString summary; | ||
|
|
||
| if (!player) | ||
| { | ||
| return summary; | ||
| } | ||
|
|
||
| UnsignedInt cash = 0; | ||
| if (player->getMoney()) | ||
| { | ||
| cash = player->getMoney()->countMoney(); | ||
| } | ||
|
|
||
| const Int rankLevel = player->getRankLevel(); | ||
| const Int totalSkillPoints = player->getSkillPoints(); | ||
| const Int levelFloor = player->getSkillPointsLevelDown(); | ||
| const Int levelCeiling = player->getSkillPointsLevelUp(); | ||
|
|
||
| Int xpProgress = totalSkillPoints - levelFloor; | ||
| if (xpProgress < 0) | ||
| { | ||
| xpProgress = 0; | ||
| } | ||
|
|
||
| Int xpSpan = levelCeiling - levelFloor; | ||
| if (xpSpan < 0) | ||
| { | ||
| xpSpan = 0; | ||
| } | ||
|
|
||
| Int xpPercent = 100; | ||
| if (xpSpan > 0) | ||
| { | ||
| xpPercent = (xpProgress * 100) / xpSpan; | ||
| if (xpPercent > 100) | ||
| { | ||
| xpPercent = 100; | ||
| } | ||
| } | ||
|
|
||
| AsciiString asciiSummary = formatCompactCash(cash); | ||
|
|
||
| AsciiString rankToken; | ||
| rankToken.format(" R%d", rankLevel); | ||
| asciiSummary.concat(rankToken); | ||
|
|
||
| AsciiString xpToken; | ||
| if (xpSpan > 0) | ||
| { | ||
| xpToken.format(" XP %d%%", xpPercent); | ||
| } | ||
| else | ||
| { | ||
| xpToken.format(" XP %d", totalSkillPoints); | ||
| } | ||
| asciiSummary.concat(xpToken); | ||
|
|
||
| summary.translate(asciiSummary); | ||
| return summary; | ||
| } | ||
|
|
||
| static void appendSummaryToSecondLine(UnicodeString &text, const UnicodeString &summary) | ||
| { | ||
| if (summary.isEmpty()) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| UnicodeString firstLine; | ||
| UnicodeString secondLine; | ||
| Bool onSecondLine = FALSE; | ||
|
|
||
| const Int length = text.getLength(); | ||
| for (Int index = 0; index < length; ++index) | ||
| { | ||
| const WideChar ch = text.getCharAt(index); | ||
| if (!onSecondLine) | ||
| { | ||
| firstLine.concat(ch); | ||
| if (ch == L'\n') | ||
| { | ||
| onSecondLine = TRUE; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| secondLine.concat(ch); | ||
| } | ||
| } | ||
|
|
||
| if (onSecondLine) | ||
| { | ||
| if (!secondLine.isEmpty()) | ||
| { | ||
| secondLine.concat(L" "); | ||
| } | ||
| secondLine.concat(summary); | ||
| text = firstLine; | ||
| text.concat(secondLine); | ||
| } | ||
| else | ||
| { | ||
| if (!text.isEmpty()) | ||
| { | ||
| text.concat(L"\n"); | ||
| } | ||
| text.concat(summary); | ||
| } | ||
| } | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
| // PUBLIC FUNCTIONS /////////////////////////////////////////////////////////// | ||
|
|
@@ -126,6 +307,11 @@ void ControlBar::initObserverControls( void ) | |
| staticTextNumberOfUnitsKilled = TheWindowManager->winGetWindowFromId(NULL, TheNameKeyGenerator->nameToKey("ControlBar.wnd:StaticTextNumberOfUnitsKilled")); | ||
| staticTextNumberOfUnitsLost = TheWindowManager->winGetWindowFromId(NULL, TheNameKeyGenerator->nameToKey("ControlBar.wnd:StaticTextNumberOfUnitsLost")); | ||
| staticTextPlayerName = TheWindowManager->winGetWindowFromId(NULL, TheNameKeyGenerator->nameToKey("ControlBar.wnd:StaticTextPlayerName")); | ||
| if (staticTextPlayerName) | ||
| { | ||
| staticTextPlayerName->winGetSize(&s_playerNameOriginalWidth, &s_playerNameOriginalHeight); | ||
| s_playerNameSizeCaptured = TRUE; | ||
| } | ||
| winFlag = TheWindowManager->winGetWindowFromId(NULL, TheNameKeyGenerator->nameToKey("ControlBar.wnd:WinFlag")); | ||
| winGeneralPortrait = TheWindowManager->winGetWindowFromId(NULL, TheNameKeyGenerator->nameToKey("ControlBar.wnd:WinGeneralPortrait")); | ||
| buttonIdleWorker = TheWindowManager->winGetWindowFromId(NULL, TheNameKeyGenerator->nameToKey("ControlBar.wnd:ButtonIdleWorker")); | ||
|
|
@@ -270,7 +456,14 @@ void ControlBar::populateObserverList( void ) | |
| //GadgetButtonSetHiliteImage( buttonPlayer[currentButton], p->getPlayerTemplate()->getHiliteImage() ); | ||
| //GadgetButtonSetHiliteSelectedImage( buttonPlayer[currentButton], p->getPlayerTemplate()->getPushedImage() ); | ||
| //GadgetButtonSetDisabledImage( buttonPlayer[currentButton], p->getPlayerTemplate()->getDisabledImage() ); | ||
| buttonPlayer[currentButton]->winSetTooltip(p->getPlayerDisplayName()); | ||
| const UnicodeString summary = formatObserverPlayerSummary(p); | ||
| UnicodeString tooltip = p->getPlayerDisplayName(); | ||
| if (!summary.isEmpty()) | ||
| { | ||
| tooltip.concat(L"\n"); | ||
| tooltip.concat(summary); | ||
| } | ||
| buttonPlayer[currentButton]->winSetTooltip(tooltip); | ||
| buttonPlayer[currentButton]->winHide(FALSE); | ||
| buttonPlayer[currentButton]->winSetStatus( WIN_STATUS_USE_OVERLAY_STATES ); | ||
|
|
||
|
|
@@ -283,10 +476,10 @@ void ControlBar::populateObserverList( void ) | |
| teamStr.format("Team:%d", slot->getTeamNumber() + 1); | ||
| if (slot->isAI() && slot->getTeamNumber() == -1) | ||
| teamStr = "Team:AI"; | ||
|
|
||
| UnicodeString text; | ||
| text.format(TheGameText->fetch("CONTROLBAR:ObsPlayerLabel"), p->getPlayerDisplayName().str(), | ||
| TheGameText->fetch(teamStr).str()); | ||
| appendSummaryToSecondLine(text, summary); | ||
|
|
||
| GadgetStaticTextSetText(staticTextPlayer[currentButton], text ); | ||
|
|
||
|
|
@@ -312,15 +505,24 @@ void ControlBar::populateObserverList( void ) | |
| //GadgetButtonSetHiliteImage( buttonPlayer[currentButton], p->getPlayerTemplate()->getHiliteImage() ); | ||
| //GadgetButtonSetHiliteSelectedImage( buttonPlayer[currentButton], p->getPlayerTemplate()->getPushedImage() ); | ||
| //GadgetButtonSetDisabledImage( buttonPlayer[currentButton], p->getPlayerTemplate()->getDisabledImage() ); | ||
| buttonPlayer[currentButton]->winSetTooltip(p->getPlayerDisplayName()); | ||
| const UnicodeString summary = formatObserverPlayerSummary(p); | ||
| UnicodeString tooltip = p->getPlayerDisplayName(); | ||
| if (!summary.isEmpty()) | ||
| { | ||
| tooltip.concat(L"\n"); | ||
| tooltip.concat(summary); | ||
| } | ||
| buttonPlayer[currentButton]->winSetTooltip(tooltip); | ||
| buttonPlayer[currentButton]->winHide(FALSE); | ||
| buttonPlayer[currentButton]->winSetStatus( WIN_STATUS_USE_OVERLAY_STATES ); | ||
|
|
||
| Color playerColor = p->getPlayerColor(); | ||
| Color backColor = GameMakeColor(0, 0, 0, 255); | ||
| staticTextPlayer[currentButton]->winSetEnabledTextColors( playerColor, backColor ); | ||
| staticTextPlayer[currentButton]->winHide(FALSE); | ||
| GadgetStaticTextSetText(staticTextPlayer[currentButton], p->getPlayerDisplayName()); | ||
| UnicodeString text = p->getPlayerDisplayName(); | ||
| appendSummaryToSecondLine(text, summary); | ||
| GadgetStaticTextSetText(staticTextPlayer[currentButton], text); | ||
|
|
||
| ++currentButton; | ||
| break; | ||
|
|
@@ -376,10 +578,30 @@ void ControlBar::populateObserverInfoWindow ( void ) | |
| GadgetStaticTextSetText(staticTextNumberOfUnitsKilled, uString); | ||
| uString.format(L"%d",m_observerLookAtPlayer->getScoreKeeper()->getTotalUnitsLost()); | ||
| GadgetStaticTextSetText(staticTextNumberOfUnitsLost, uString); | ||
| GadgetStaticTextSetText(staticTextPlayerName, m_observerLookAtPlayer->getPlayerDisplayName()); | ||
| UnicodeString playerName = m_observerLookAtPlayer->getPlayerDisplayName(); | ||
| GadgetStaticTextSetText(staticTextPlayerName, playerName); | ||
| ensurePlayerNameLabelHeight(FALSE); | ||
| Color color = m_observerLookAtPlayer->getPlayerColor(); | ||
| staticTextPlayerName->winSetEnabledTextColors(color, GameMakeColor(0,0,0,255)); | ||
| winFlag->winSetEnabledImage(0, m_observerLookAtPlayer->getPlayerTemplate()->getFlagWaterMarkImage()); | ||
| winGeneralPortrait->winHide(FALSE); | ||
| buttonIdleWorker->winHide(FALSE); | ||
| } | ||
|
|
||
| void ControlBar::refreshObserverUI() | ||
| { | ||
| if (!m_isObserverCommandBar) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (ObserverPlayerInfoWindow && !ObserverPlayerInfoWindow->winIsHidden()) | ||
| { | ||
| populateObserverInfoWindow(); | ||
| } | ||
|
|
||
| if (ObserverPlayerListWindow && !ObserverPlayerListWindow->winIsHidden()) | ||
| { | ||
| populateObserverList(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary