Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameclient): tooltips drawn from Window/Html/Tooltip.html

Olcay Seyganf1f71388031c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b120334bf..2c10ca1c5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -503,6 +503,7 @@ found and fixed — EA's own, not port damage.**
- The bar's own buttons are drawn to match, steel caps lit gold under the pointer and pressed in when pushed. The menu is a small square with three bars in the screen's top left corner. The idle worker button is a key like the smoke signals', a hard hat on it, in a steel step against the middle panel's bottom left corner, where it no longer hides the end of the power bar, and the build buttons sit down level with it, a few pixels over the bottom of the screen. Each of the fourteen build places is its own dark cell with steel running between them, so an empty place reads as a slot waiting for a button. The power bar is sunk into the same steel plate as the build grid, the plate carried on upward as wide as it, and the money's block sits on top of that plate with no seam between them: the build grid, the power and the money read as one piece. The power bar is as long as the build grid on every side, where it used to change length from one faction to the next, and the money sits over the grid's middle. The build grid's panel no longer carries an empty strip down its left side. There is no chat button any more: Enter opens the chat as it always did. The portrait sits in the radar's lit steel too. The experience bar beside it is ten gold rungs in a sunk groove, climbing from the bottom as you earn your way to the next rank, and your rank stands in a steel tab on the portrait's top right corner, a key sunk in it like the idle worker's with one star for every rank there is, gold up to the one you hold. The portrait's grid is steel between dark cells on every side, where America's was drawn in blue lines that matched nothing else on the bar. That key is the promotions button: point at it and it comes up with a gold rim, it blinks bright in your side's own steel while you have a promotion to spend, and a click opens the promotion screen. The bar has no minimise arrow any more: it is only as big as what it holds. The radar sits sunk in a bezel of lit steel, bright along the top and shadowed down the right, and the build grid and the money wear the same steel, the figure in a dark window of its own, and the under-attack light is a long red lamp set in a steel tab on its top left corner, dark until you are hit and then blinking. No words on it, so it reads the same in any language.
- The general's powers you have bought and can fire, the column that climbed the right edge of the screen, stand over the portrait now in a tray of the bar's own steel. The first sits in the corner against the right edge of the screen, and each one you gain takes the place to the left of the last, three to a row before a new row starts above, so the tray is only ever as big as what you hold and an empty one takes no room at all. Each power sits on a dark cell three quarters the size of a build button, where the side's old tray art used to frame it. It is always out; there is no button to fold it away.
- Three buttons sit in a step of the radar's own steel, on its right: the smoke signals Alt+Z, X and C send, placed in the middle of your view for your allies to see. Each is a key sunk into the steel with a sharp white picture on it instead of a word: a crosshair to attack, a shield to defend, an eye to look. Point at one and it comes up out of its well as lit steel with a gold rim, and it sinks in darker while you hold the button down. They rise into place one after another from the bottom of the screen when the match starts. A game with nobody on your side to see the smoke, a skirmish against the computer or a replay, has no signal buttons at all.
+- Tooltips wear the bar's steel. Point at a build button and a card opens right above it rather than in a fixed box at the side: the name on a steel header in your side's colour with the price in gold at its end, every "Power Supplied: 5" or "Strong: infantry" line of the description laid out as a label and a bold figure, the build time, damage and range under a rule, and "not enough money" or what you still need in a sunk red note at the bottom. Point at something on the battlefield and a small dark box beside the pointer names it, its owner's colour in a stripe down the left edge.
- The readout in the top right corner is a box of its own and always there: the time of day, the match time and the real time beside it, the logic rate and the frame rate, the renderer and the frame number. In a network game it adds how many frames are ready out of the input delay, the room's frame rate and the traffic in and out, and under a unit limit your count against it.
## Placing buildings
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index 7703085a2..89e427d55 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -916,6 +916,24 @@ TOOLTIP:WeaponStats
"Dmg %d Range %d"
END
+// The same figures as rows of Window/Html/Tooltip.html, a label and its value each.
+
+TOOLTIP:StatTime
+"Build time"
+END
+
+TOOLTIP:StatSeconds
+"%ds"
+END
+
+TOOLTIP:StatDamage
+"Damage"
+END
+
+TOOLTIP:StatRange
+"Range"
+END
+
// Peace time - the lobby combo box, its tooltip, the corner countdown and the three things the game
// says while the clock runs. Tools/peacetime_layout.py selfcheck fails if any of these goes missing.
diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.str
index 7068d5e06..cf6c7e4c7 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -15565,6 +15565,22 @@ TOOLTIP:WeaponStats
"Hasar %d Menzil %d"
END
+TOOLTIP:StatTime
+"Üretim süresi"
+END
+
+TOOLTIP:StatSeconds
+"%d sn"
+END
+
+TOOLTIP:StatDamage
+"Hasar"
+END
+
+TOOLTIP:StatRange
+"Menzil"
+END
+
GUI:HudToggles
"Şeritler"
END
diff --git a/GeneralsMD/Code/Data/Window/Html/Tooltip.html b/GeneralsMD/Code/Data/Window/Html/Tooltip.html
new file mode 100644
index 000000000..dcce8b782
--- /dev/null
+++ b/GeneralsMD/Code/Data/Window/Html/Tooltip.html
@@ -0,0 +1,119 @@
+<!DOCTYPE html>
+<!--
+ Every tooltip in a match, in the command bar's steel. Two kinds, one box:
+
+ card a command bar button's build tooltip, over the hovered button: the name and the cost in a
+ steel header, the description with every "Label: value" line as a row, the build time,
+ damage and range, then why it cannot be bought now and what it still needs, each in a
+ sunk note
+ tip what the pointer is on, beside it: the name, then the owner and the like, with a stripe
+ down the left in the owner's colour
+
+ The one element with id "box" is measured after layout and placed by the game, so it must stay one
+ element and stay absolutely placed. Nothing inside it may be absolutely or relatively placed:
+ inside an absolute box this renderer lays such children out from the screen's corner. The
+ materials and what the renderer does not draw are in Window/Html/Spectator.html's header.
+
+ The game fills in, every frame it is up (GameClient/HtmlTemplate.h):
+ {{side}} "america", "china" or "gla", the side whose bar is on screen
+ {{kind}} "card" or "tip"
+ {{box.x}} {{box.y}} where the box goes, in the page's pixels
+ data-each="lines" the description (card) or the lines after the name (tip): {{kind}}
+ "row" with {{label}} {{value}}, "text" with {{text}}, or "gap"
+ card only:
+ {{name}} the button's name
+ {{cost}} what it costs, {{costkind}} "money" or "science" (promotion points),
+ {{cost.shown}} "hidden" when it costs nothing
+ {{time}} {{damage}} {{range}} build time with its unit, the best weapon's damage and range;
+ {{stats.shown}} and {{weapon.shown}}
+ {{warning}} why it cannot be bought right now, {{warning.shown}}
+ {{requires}} "Requires: ...", {{requires.shown}}
+ tip only:
+ {{title}} the first line, the name of what the pointer is on
+ {{accent}} its owner's colour as #rrggbb, "transparent" for none
+
+ Edit the copy under Run/Window/Html and the next match reads it.
+-->
+<html>
+<head>
+<meta charset="utf-8">
+<title>Tooltip</title>
+<style>
+ html, body { margin: 0; padding: 0; }
+ body { background-color: #3b4a36; font-size: 8px; color: #dfe5ea; }
+ .hidden { display: none; }
+
+ /* the box: the panels' dark body under a steel rim, lit along the top and left */
+ #box { position: absolute; background-color: rgba(8, 12, 16, 0.96); border: 1px solid #1a2026;
+ border-top-color: #aab4bf; border-left-color: #8a949f; }
+ .china #box { background-color: rgba(20, 8, 6, 0.96); border-top-color: #d98a72; border-left-color: #b8604b; }
+ .gla #box { background-color: rgba(18, 16, 7, 0.96); border-top-color: #cbbf82; border-left-color: #a99d62; }
+ #box.card { width: 210px; }
+
+ /* the card's header: the rail's steel, the name on it and the cost at its right hand end */
+ .head { padding: 3px 6px 3px 6px; background: linear-gradient(to bottom, #7d8691, #3f4650);
+ border-bottom: 1px solid #0c1114; }
+ .china .head { background: linear-gradient(to bottom, #9a4331, #4c1b13); }
+ .gla .head { background: linear-gradient(to bottom, #8f8249, #48401e); }
+ .name { font-size: 9px; font-weight: bold; color: #ffffff; }
+ .cost { float: right; margin-left: 6px; font-size: 9px; font-weight: bold; color: #e8d27a; }
+ .cost .star { display: inline-block; width: 8px; height: 8px; margin-right: 2px; background-image: url(Icons/RankStar.svg); }
+ .cost.money .star { display: none; }
+ .cost.science .dollar { display: none; }
+
+ /* the body: rows as label and value, prose in a softer grey, a gap where the text left a blank line */
+ .body { padding: 4px 6px 5px 6px; }
+ .line { line-height: 11px; }
+ .line.gap { height: 4px; }
+ .line.text { color: #c9d2d9; }
+ .line.text .label, .line.text .value, .line.gap .label, .line.gap .value { display: none; }
+ .label { color: #8a949f; }
+ .value { color: #f1f4f6; font-weight: bold; }
+ .china .label { color: #b48a80; }
+ .gla .label { color: #a89f78; }
+
+ /* the three figures under a rule, the numbers in the bar's gold */
+ .stats { margin: 4px 6px 0 6px; padding: 3px 0 4px 0; border-top: 1px solid #2c343c; }
+ .china .stats { border-top-color: #3e1f19; }
+ .gla .stats { border-top-color: #37321c; }
+ .stats .value { color: #e8d27a; }
+
+ /* a note sunk into the card: dark on top, lit below, the warning in the under-attack lamp's red */
+ .note { margin: 0 6px 6px 6px; padding: 3px 5px 3px 5px; line-height: 10px; background-color: #1b232b;
+ border: 1px solid #06090b; border-bottom-color: #4b535e; border-right-color: #4b535e; }
+ .china .note { background-color: #2a1512; border-bottom-color: #6a2a1e; border-right-color: #6a2a1e; }
+ .gla .note { background-color: #26220f; border-bottom-color: #625a31; border-right-color: #625a31; }
+ .note.warning { color: #ff7a60; font-weight: bold; }
+ .note.requires { color: #e8a090; }
+
+ /* the tip: the owner's colour down the left edge, the name over the lines */
+ #box.tip { border-left: 3px solid #8a949f; padding: 2px 6px 3px 5px; }
+ .tip .title { font-weight: bold; color: #ffffff; line-height: 10px; }
+ .tip .body { padding: 0; }
+ .card .tiponly, .tip .cardonly { display: none; }
+</style>
+</head>
+<body class="{{side}}">
+ <div id="box" class="{{kind}}" style="left: {{box.x}}px; top: {{box.y}}px; border-left-color: {{accent}}">
+ <div class="cardonly">
+ <div class="head">
+ <span class="cost {{costkind}} {{cost.shown}}"><span class="star"></span><span class="dollar">$</span>{{cost}}</span>
+ <span class="name">{{name}}</span>
+ </div>
+ </div>
+ <div class="tiponly title">{{title}}</div>
+ <div class="body">
+ <div class="line {{kind}}" data-each="lines"><span class="label">{{label}}: </span><span class="value">{{value}}</span>{{text}}</div>
+ </div>
+ <div class="cardonly">
+ <div class="stats {{stats.shown}}">
+ <div class="line"><span class="label">{{text:TOOLTIP:StatTime}}: </span><span class="value">{{time}}</span></div>
+ <div class="line {{weapon.shown}}"><span class="label">{{text:TOOLTIP:StatDamage}}: </span><span class="value">{{damage}}</span></div>
+ <div class="line {{weapon.shown}}"><span class="label">{{text:TOOLTIP:StatRange}}: </span><span class="value">{{range}}</span></div>
+ </div>
+ <div class="note warning {{warning.shown}}">{{warning}}</div>
+ <div class="note requires {{requires.shown}}">{{requires}}</div>
+ </div>
+ </div>
+</body>
+</html>
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
index 7d2776954..6e16d934b 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
@@ -673,6 +673,25 @@ enum ControlBarStages
MAX_CONTROL_BAR_STAGES
};
+//-------------------------------------------------------------------------------------------------
+/** What the build tooltip says, piece by piece, so Window/Html/Tooltip.html can lay each piece out
+ * on its own: ControlBarPopupDescription.wnd gets the same pieces run together into one text. */
+//-------------------------------------------------------------------------------------------------
+struct BuildTooltipCard
+{
+ UnicodeString name;
+ UnicodeString description; ///< the button's own text, its lines split by \n
+ UnicodeString warning; ///< why it cannot be bought right now, empty when it can
+ UnicodeString requires; ///< "Requires: ..." naming what is still missing
+ UnsignedInt cost; ///< 0 for nothing to pay
+ Bool costsScience; ///< the cost is promotion points rather than money
+ Bool hasStats; ///< DetailedBuildTooltips: the three figures below are there
+ Int buildSeconds;
+ Int damage; ///< the best weapon's, before any bonus; 0 for no weapon
+ Int range;
+ IRegion2D anchor; ///< the hovered window, in screen pixels
+};
+
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
class ControlBar : public SubsystemInterface
@@ -1335,7 +1354,10 @@ protected:
WindowLayout *m_buildToolTipLayout; ///< The window that will slide on/display tooltips
Bool m_showBuildToolTipLayout; ///< every frame we test to see if we aregoing to continue showing this or not.
+ BuildTooltipCard m_buildTooltipCard; ///< what the layout says, piece by piece
public:
+ /** What the build tooltip up on screen says, NULL while none is. */
+ const BuildTooltipCard *getBuildTooltipCard( void );
void showBuildTooltipLayout( GameWindow *cmdButton );
void hideBuildTooltipLayout( void );
void deleteBuildTooltipLayout( void );
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index 3bf53217e..2c7872629 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -408,6 +408,12 @@ public: // ********************************************************************
* when `act` is set the button it names is pressed. */
Bool handleControlBarPageClick( const ICoord2D *mouse, Bool act );
void drawScoreboard( void ); ///< that scoreboard, over everything
+ /** Window/Html/Tooltip.html is there to draw with, in a match. */
+ Bool isTooltipPageReady( void );
+ /** The tooltip page: the command bar's build tooltip over the hovered button while one is up,
+ * otherwise `cursorText` beside the pointer, edged in `accent` when it has one. FALSE when the
+ * page is not ready, and the caller draws the old way. */
+ Bool drawTooltipPage( const UnicodeString &cursorText, const RGBColor *accent );
virtual Bool isMessagesOn( void ) { return m_messagesOn; } ///< are the display messages on
void freeMessageResources( void ); ///< free resources for the ui messages
Color getMessageColor(Bool altColor) { return (altColor)?m_messageColor2:m_messageColor1; }
@@ -1212,6 +1218,10 @@ protected:
Bool m_controlBarPageLoaded;
Bool m_controlBarPageShown; ///< drawn this frame, so its buttons can be clicked
std::string m_controlBarPage;
+ HtmlOverlay * m_tooltipOverlay;
+ Bool m_tooltipPageLoaded;
+ std::string m_tooltipPage;
+ ICoord2D m_tooltipSize; ///< the box as last laid out, in screen pixels, to place the next one by
Bool m_signalsWereShown; ///< the smoke signal column was up last frame
UnsignedInt m_signalsRiseStartMs; ///< when it last came up, the start of its buttons' rise
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Mouse.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Mouse.h
index 1ff85c34c..2161707d6 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Mouse.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Mouse.h
@@ -283,7 +283,8 @@ public:
/** Where a tooltip box of this size goes for a pointer here: beside it, flipped to the other
* side at the right or bottom edge, and then held inside the screen. Static and free of every
- * member so the placement can be checked without a display; drawTooltip is its only caller. */
+ * member so the placement can be checked without a display; drawTooltip and the tooltip page
+ * are its callers. */
static void placeTooltip( Int mouseX, Int mouseY, Int width, Int height,
Int minX, Int minY, Int maxX, Int maxY,
Int *xOut, Int *yOut );
@@ -384,6 +385,8 @@ protected:
UnsignedInt m_stillTime;
RGBAColorInt m_tooltipTextColor;
RGBAColorInt m_tooltipBackColor;
+ Bool m_tooltipHasAccent; ///< the tooltip came with a colour, its owner's
+ RGBColor m_tooltipAccent; ///< that colour as it came, before the INI's alt colour rules
Int m_eventsThisFrame;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp
index 042110caf..999cb2ae2 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp
@@ -105,6 +105,28 @@ static GameWindow *theWindow = NULL;
static AnimateWindowManager *theAnimateWindowManager = NULL;
static GameWindow *prevWindow = NULL;
static Bool useAnimation = FALSE;
+
+static void drawNothing( GameWindow *window, WinInstanceData *instData )
+{
+}
+
+/** `window` and every child of it, down, draw nothing from now on. */
+static void silenceWindowTree( GameWindow *window )
+{
+ window->winSetDrawFunc( drawNothing );
+ for( GameWindow *child = window->winGetChild(); child; child = child->winGetNext() )
+ silenceWindowTree( child );
+}
+
+/** Every window of `layout` draws nothing from now on. The layout's own list, not the windows'
+ * sibling chain: a top level window's next is the next window on screen, and walking that silenced
+ * the command bar and everything else the moment a build tooltip came up. */
+static void silenceLayout( WindowLayout *layout )
+{
+ for( GameWindow *window = layout->getFirstWindow(); window; window = window->winGetNextInLayout() )
+ silenceWindowTree( window );
+}
+
void ControlBarPopupDescriptionUpdateFunc( WindowLayout *layout, void *param )
{
if(TheScriptEngine->isGameEnding())
@@ -237,6 +259,19 @@ void ControlBar::showBuildTooltipLayout( GameWindow *cmdButton )
}
+const BuildTooltipCard *ControlBar::getBuildTooltipCard( void )
+{
+ if( m_buildToolTipLayout == NULL || m_buildToolTipLayout->isHidden() || prevWindow == NULL )
+ return NULL;
+
+ Int width, height;
+ prevWindow->winGetScreenPosition( &m_buildTooltipCard.anchor.lo.x, &m_buildTooltipCard.anchor.lo.y );
+ prevWindow->winGetSize( &width, &height );
+ m_buildTooltipCard.anchor.hi.x = m_buildTooltipCard.anchor.lo.x + width;
+ m_buildTooltipCard.anchor.hi.y = m_buildTooltipCard.anchor.lo.y + height;
+ return &m_buildTooltipCard;
+}
+
void ControlBar::repopulateBuildTooltipLayout( void )
{
if(!prevWindow || !m_buildToolTipLayout)
@@ -259,6 +294,8 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,
const ProductionPrerequisite *prereq;
Bool fireScienceButton = false;
UnsignedInt costToBuild = 0;
+ BuildTooltipCard &card = m_buildTooltipCard;
+ card = BuildTooltipCard();
if(commandButton)
{
@@ -347,26 +384,22 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,
switch( makeType )
{
case CANMAKE_NO_MONEY:
- descrip.concat( L"\n\n" );
- descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipNotEnoughMoneyToBuild" ) );
+ card.warning = TheGameText->fetch( "TOOLTIP:TooltipNotEnoughMoneyToBuild" );
break;
case CANMAKE_QUEUE_FULL:
- descrip.concat( L"\n\n" );
- descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipCannotPurchaseBecauseQueueFull" ) );
+ card.warning = TheGameText->fetch( "TOOLTIP:TooltipCannotPurchaseBecauseQueueFull" );
break;
case CANMAKE_PARKING_PLACES_FULL:
- descrip.concat( L"\n\n" );
- descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipCannotBuildUnitBecauseParkingFull" ) );
+ card.warning = TheGameText->fetch( "TOOLTIP:TooltipCannotBuildUnitBecauseParkingFull" );
break;
case CANMAKE_MAXED_OUT_FOR_PLAYER:
- descrip.concat( L"\n\n" );
if ( thingTemplate->isKindOf( KINDOF_STRUCTURE ) )
{
- descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipCannotBuildBuildingBecauseMaximumNumber" ) );
+ card.warning = TheGameText->fetch( "TOOLTIP:TooltipCannotBuildBuildingBecauseMaximumNumber" );
}
else
{
- descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipCannotBuildUnitBecauseMaximumNumber" ) );
+ card.warning = TheGameText->fetch( "TOOLTIP:TooltipCannotBuildUnitBecauseMaximumNumber" );
}
break;
//case CANMAKE_NO_PREREQ:
@@ -385,13 +418,11 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,
ProductionUpdateInterface *pui = selectedObject->getProductionUpdateInterface();
if( pui && pui->getProductionCount() >= pui->getMaxQueueEntries() )
{
- descrip.concat( L"\n\n" );
- descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipCannotPurchaseBecauseQueueFull" ) );
+ card.warning = TheGameText->fetch( "TOOLTIP:TooltipCannotPurchaseBecauseQueueFull" );
}
else if( !TheUpgradeCenter->canAffordUpgrade( ThePlayerList->getLocalPlayer(), upgradeTemplate, FALSE ) )
{
- descrip.concat( L"\n\n" );
- descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipNotEnoughMoneyToBuild" ) );
+ card.warning = TheGameText->fetch( "TOOLTIP:TooltipNotEnoughMoneyToBuild" );
}
}
}
@@ -421,9 +452,8 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,
//
if( TheGlobalData->m_detailedBuildTooltips )
{
- UnicodeString stats;
- Int buildSecs = ControlBar_secondsFromFrames( (Real)thingTemplate->calcTimeToBuild( player ) );
- stats.format( TheGameText->fetch( "TOOLTIP:BuildTimeSeconds" ), buildSecs );
+ card.hasStats = TRUE;
+ card.buildSeconds = ControlBar_secondsFromFrames( (Real)thingTemplate->calcTimeToBuild( player ) );
// no bonuses: these are the template's own numbers, before veterancy or upgrades
WeaponBonus noBonus;
@@ -444,16 +474,8 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,
}
}
- if( bestDamage > 0.0f )
- {
- UnicodeString weap;
- // the gap is here rather than in the string: the string table collapses runs of spaces
- weap.format( TheGameText->fetch( "TOOLTIP:WeaponStats" ), REAL_TO_INT( bestDamage ), REAL_TO_INT( bestRange ) );
- stats.concat( L" " );
- stats.concat( weap );
- }
-
- descrip.concat( stats );
+ card.damage = REAL_TO_INT( bestDamage );
+ card.range = REAL_TO_INT( bestRange );
}
// ask each prerequisite to give us a list of the non satisfied prerequisites
@@ -473,14 +495,7 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,
requires.concat(requiresList);
}
if( !requires.isEmpty() )
- {
- UnicodeString requireFormat = TheGameText->fetch("CONTROLBAR:Requirements");
- requires.format(requireFormat.str(), requires.str());
- if(!descrip.isEmpty())
- descrip.concat(L"\n");
- descrip.concat(requires);
-
- }
+ card.requires.format( TheGameText->fetch( "CONTROLBAR:Requirements" ).str(), requires.str() );
}
else if( upgradeTemplate )
{
@@ -554,12 +569,7 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,
}
if( missingScience )
- {
- if( !descrip.isEmpty() )
- descrip.concat(L"\n");
- requires.format( TheGameText->fetch( "CONTROLBAR:Requirements" ).str(), TheGameText->fetch( "CONTROLBAR:GeneralsPromotion" ).str() );
- descrip.concat( requires );
- }
+ card.requires.format( TheGameText->fetch( "CONTROLBAR:Requirements" ).str(), TheGameText->fetch( "CONTROLBAR:GeneralsPromotion" ).str() );
}
}
else if( st != SCIENCE_INVALID && !fireScienceButton )
@@ -567,6 +577,7 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,
TheScienceStore->getNameAndDescription(st, name, descrip);
costToBuild = TheScienceStore->getSciencePurchaseCost( st );
+ card.costsScience = TRUE;
if( costToBuild > 0 )
{
cost.format( TheGameText->fetch("TOOLTIP:ScienceCost"), costToBuild );
@@ -591,13 +602,7 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,
requires.concat(requiresList);
}
if( !requires.isEmpty() )
- {
- UnicodeString requireFormat = TheGameText->fetch("CONTROLBAR:Requirements");
- requires.format(requireFormat.str(), requires.str());
- if(!descrip.isEmpty())
- descrip.concat(L"\n");
- descrip.concat(requires);
- }
+ card.requires.format( TheGameText->fetch( "CONTROLBAR:Requirements" ).str(), requires.str() );
}
}
@@ -641,8 +646,46 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,
DEBUG_ASSERTCRASH(FALSE, ("ControlBar::populateBuildTooltipLayout We attempted to call the popup tooltip on a game window that has yet to be hand coded in as this fuction was/is designed for only buttons but has been hacked to work with GameWindows."));
return;
}
-
+
+ }
+
+ card.name = name;
+ card.description = descrip;
+ card.cost = costToBuild;
+
+ // the layout's one text: the description, then why it cannot be bought, the figures and what it
+ // still needs
+ if( !card.warning.isEmpty() )
+ {
+ descrip.concat( L"\n\n" );
+ descrip.concat( card.warning );
+ }
+ if( card.hasStats )
+ {
+ UnicodeString stats;
+ stats.format( TheGameText->fetch( "TOOLTIP:BuildTimeSeconds" ), card.buildSeconds );
+ if( card.damage > 0 )
+ {
+ UnicodeString weapon;
+ // the gap is here rather than in the string: the string table collapses runs of spaces
+ weapon.format( TheGameText->fetch( "TOOLTIP:WeaponStats" ), card.damage, card.range );
+ stats.concat( L" " );
+ stats.concat( weapon );
+ }
+ descrip.concat( stats );
}
+ if( !card.requires.isEmpty() )
+ {
+ if( !descrip.isEmpty() )
+ descrip.concat( L"\n" );
+ descrip.concat( card.requires );
+ }
+
+ // with the tooltip page in a match the layout stays up for the show and hide logic above, and the
+ // page draws what it says
+ if( TheInGameUI->isTooltipPageReady() )
+ silenceLayout( m_buildToolTipLayout );
+
GameWindow *win = TheWindowManager->winGetWindowFromId(m_buildToolTipLayout->getFirstWindow(), TheNameKeyGenerator->nameToKey("ControlBarPopupDescription.wnd:StaticTextName"));
if(win)
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index ada4dbe59..f165bc199 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -1204,6 +1204,10 @@ InGameUI::InGameUI()
m_controlBarOverlay = NULL;
m_controlBarPageLoaded = FALSE;
m_controlBarPageShown = FALSE;
+ m_tooltipOverlay = NULL;
+ m_tooltipPageLoaded = FALSE;
+ m_tooltipSize.x = 0;
+ m_tooltipSize.y = 0;
m_signalsWereShown = FALSE;
m_signalsRiseStartMs = 0;
for( Int stripSeconds = 0; stripSeconds < STRIP_SECONDS_STRINGS; stripSeconds++ )
@@ -1327,6 +1331,8 @@ InGameUI::~InGameUI()
m_scoreboardOverlay = NULL;
delete m_controlBarOverlay;
m_controlBarOverlay = NULL;
+ delete m_tooltipOverlay;
+ m_tooltipOverlay = NULL;
}
//-------------------------------------------------------------------------------------------------
@@ -3875,6 +3881,7 @@ void InGameUI::reset( void )
m_scoreboardOpen = FALSE;
m_scoreboardPageLoaded = FALSE;
m_controlBarPageLoaded = FALSE;
+ m_tooltipPageLoaded = FALSE;
m_signalsWereShown = FALSE;
m_spectatorPageLoaded = FALSE;
m_spectatorFlipped.clear();
@@ -12183,6 +12190,201 @@ void InGameUI::notifyResolutionChange( void )
RecreateQuitMenu();
}
+static const char *const TOOLTIP_PAGE = "Window\\Html\\Tooltip.html";
+
+enum
+{
+ TOOLTIP_ANCHOR_GAP = 6, ///< page pixels between the build tooltip and the button it describes
+ TOOLTIP_LABEL_LIMIT = 28, ///< a description line "Label: value" is a row when its label is no longer
+ TOOLTIP_LAYOUT_PASSES = 2, ///< laid out again once when the box came out another size than it was placed by
+};
+
+//-------------------------------------------------------------------------------------------------
+/** A tooltip text as data-each="lines": {{kind}} "row" with {{label}} and {{value}} for a line that
+ * reads "Label: value" - the string table's "Strong: infantry", "Energy Provided: 5" - and "text"
+ * with {{text}} for any other. A run of blank lines is one entry of kind "gap", and none opens or
+ * closes the list. */
+//-------------------------------------------------------------------------------------------------
+static void putTooltipLines( const UnicodeString &text, std::vector< HtmlValues > &lines )
+{
+ const std::wstring whitespace = L" \t\r";
+ const std::wstring whole = text.str();
+ Bool gapOwed = FALSE;
+ for( size_t start = 0; start <= whole.size(); )
+ {
+ size_t end = whole.find( L'\n', start );
+ if( end == std::wstring::npos )
+ end = whole.size();
+ std::wstring line = whole.substr( start, end - start );
+ start = end + 1;
+
+ const size_t first = line.find_first_not_of( whitespace );
+ if( first == std::wstring::npos )
+ {
+ gapOwed = !lines.empty();
+ continue;
+ }
+ line = line.substr( first, line.find_last_not_of( whitespace ) - first + 1 );
+
+ if( gapOwed )
+ {
+ HtmlValues gap;
+ gap[ "kind" ] = "gap";
+ lines.push_back( gap );
+ gapOwed = FALSE;
+ }
+
+ HtmlValues entry;
+ const size_t colon = line.find( L':' );
+ const size_t valueStart = colon == std::wstring::npos ? colon : line.find_first_not_of( whitespace, colon + 1 );
+ if( colon != std::wstring::npos && colon <= TOOLTIP_LABEL_LIMIT && valueStart != std::wstring::npos )
+ {
+ entry[ "kind" ] = "row";
+ entry[ "label" ] = WideCharStringToMultiByte( line.substr( 0, colon ).c_str() );
+ entry[ "value" ] = WideCharStringToMultiByte( line.substr( valueStart ).c_str() );
+ }
+ else
+ {
+ entry[ "kind" ] = "text";
+ entry[ "text" ] = WideCharStringToMultiByte( line.c_str() );
+ }
+ lines.push_back( entry );
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+/** A button label as a name: the '&' that marks its hotkey letter taken out. */
+//-------------------------------------------------------------------------------------------------
+static std::string tooltipName( const UnicodeString &label )
+{
+ std::wstring name = label.str();
+ const size_t marker = name.find( L'&' );
+ if( marker != std::wstring::npos )
+ name.erase( marker, 1 );
+ return WideCharStringToMultiByte( name.c_str() );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The build tooltip's values: {{name}}, {{cost}} with {{costkind}} "money" or "science" and
+ * {{cost.shown}}, data-each="lines" out of the description, {{warning}} and {{requires}} each with
+ * its .shown, and the three figures {{time}} {{damage}} {{range}} with {{stats.shown}} and
+ * {{weapon.shown}}. */
+//-------------------------------------------------------------------------------------------------
+static void putBuildTooltipCard( const BuildTooltipCard &card, HtmlValues &values, HtmlLists &lists )
+{
+ values[ "kind" ] = "card";
+ values[ "name" ] = tooltipName( card.name );
+ values[ "cost" ] = std::to_string( card.cost );
+ values[ "costkind" ] = card.costsScience ? "science" : "money";
+ values[ "cost.shown" ] = card.cost > 0 ? "shown" : "hidden";
+ putTooltipLines( card.description, lists[ "lines" ] );
+ values[ "warning" ] = WideCharStringToMultiByte( card.warning.str() );
+ values[ "warning.shown" ] = card.warning.isEmpty() ? "hidden" : "shown";
+ values[ "requires" ] = WideCharStringToMultiByte( card.requires.str() );
+ values[ "requires.shown" ] = card.requires.isEmpty() ? "hidden" : "shown";
+
+ UnicodeString seconds;
+ seconds.format( TheGameText->fetch( "TOOLTIP:StatSeconds" ), card.buildSeconds );
+ values[ "time" ] = WideCharStringToMultiByte( seconds.str() );
+ values[ "damage" ] = std::to_string( card.damage );
+ values[ "range" ] = std::to_string( card.range );
+ values[ "stats.shown" ] = card.hasStats ? "shown" : "hidden";
+ values[ "weapon.shown" ] = card.hasStats && card.damage > 0 ? "shown" : "hidden";
+}
+
+//-------------------------------------------------------------------------------------------------
+Bool InGameUI::isTooltipPageReady( void )
+{
+ if( TheGameLogic == NULL || !TheGameLogic->isInGame() || TheGameLogic->isInShellGame() )
+ return FALSE;
+
+ if( !m_tooltipPageLoaded )
+ {
+ m_tooltipPageLoaded = TRUE;
+ readHtmlPage( TOOLTIP_PAGE, m_tooltipPage );
+ }
+ return !m_tooltipPage.empty();
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Both tooltips out of Window/Html/Tooltip.html, in the side's steel. The box is placed by the
+ * size it came out last time; when this one comes out another size it is placed and laid out once
+ * more, so a new tooltip is never drawn a frame in the wrong place. */
+//-------------------------------------------------------------------------------------------------
+Bool InGameUI::drawTooltipPage( const UnicodeString &cursorText, const RGBColor *accent )
+{
+ if( !isTooltipPageReady() )
+ return FALSE;
+
+ const BuildTooltipCard *card = TheControlBar->getBuildTooltipCard();
+ if( card == NULL && cursorText.isEmpty() )
+ return TRUE;
+
+ if( m_tooltipOverlay == NULL )
+ m_tooltipOverlay = new HtmlOverlay( m_superweaponNormalFont );
+
+ HtmlValues values;
+ HtmlLists lists;
+ values[ "side" ] = spectatorSide();
+ if( card )
+ {
+ putBuildTooltipCard( *card, values, lists );
+ }
+ else
+ {
+ // the first line names what is under the pointer, the rest are its owner and the like
+ std::vector< HtmlValues > &lines = lists[ "lines" ];
+ putTooltipLines( cursorText, lines );
+ values[ "kind" ] = "tip";
+ if( !lines.empty() )
+ {
+ values[ "title" ] = lines.front()[ "kind" ] == "text" ? lines.front()[ "text" ]
+ : lines.front()[ "label" ] + ": " + lines.front()[ "value" ];
+ lines.erase( lines.begin() );
+ }
+ values[ "accent" ] = accent ? cssColor( GameMakeColor( REAL_TO_INT( accent->red * 255.0f ), REAL_TO_INT( accent->green * 255.0f ),
+ REAL_TO_INT( accent->blue * 255.0f ), 255 ) )
+ : "transparent";
+ }
+
+ const Int screenWidth = TheDisplay->getWidth();
+ const Int screenHeight = TheDisplay->getHeight();
+ const ICoord2D &mouse = TheMouse->getMouseStatus()->pos;
+ const Int gap = REAL_TO_INT( TOOLTIP_ANCHOR_GAP * ControlBarUniformScale() );
+ for( Int pass = 0; pass < TOOLTIP_LAYOUT_PASSES; pass++ )
+ {
+ IRegion2D box;
+ if( card )
+ {
+ // over the button, centred on it, and under it when there is no room above
+ box.lo.x = ( card->anchor.lo.x + card->anchor.hi.x - m_tooltipSize.x ) / 2;
+ box.lo.y = card->anchor.lo.y - gap - m_tooltipSize.y;
+ if( box.lo.y < 0 )
+ box.lo.y = card->anchor.hi.y + gap;
+ box.lo.x = max( 0, min( box.lo.x, screenWidth - m_tooltipSize.x ) );
+ }
+ else
+ {
+ Mouse::placeTooltip( mouse.x, mouse.y, m_tooltipSize.x, m_tooltipSize.y, 0, 0, screenWidth, screenHeight,
+ &box.lo.x, &box.lo.y );
+ }
+ box.hi.x = box.lo.x + m_tooltipSize.x;
+ box.hi.y = box.lo.y + m_tooltipSize.y;
+ putPageRect( values, "box", box, TRUE );
+ m_tooltipOverlay->setPage( HtmlTemplate_expand( m_tooltipPage, values, lists, lookupGameText ) );
+
+ std::vector< IRegion2D > laidOut;
+ m_tooltipOverlay->rectsOf( "#box", laidOut );
+ DEBUG_ASSERTCRASH( laidOut.size() == 1, ( "%s has %d #box elements, wants one\n", TOOLTIP_PAGE, (Int)laidOut.size() ) );
+ const ICoord2D size = { laidOut.front().hi.x - laidOut.front().lo.x, laidOut.front().hi.y - laidOut.front().lo.y };
+ if( size.x == m_tooltipSize.x && size.y == m_tooltipSize.y )
+ break;
+ m_tooltipSize = size;
+ }
+ m_tooltipOverlay->draw();
+ return TRUE;
+}
+
void InGameUI::disableTooltipsUntil(UnsignedInt frameNum)
{
if (frameNum > m_tooltipsDisabledUntil)
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Input/Mouse.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Input/Mouse.cpp
index 3044b0c10..729b4cc33 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Input/Mouse.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Input/Mouse.cpp
@@ -539,6 +539,7 @@ Mouse::Mouse( void )
m_tooltipBackColor.green = 0;
m_tooltipBackColor.blue = 0;
m_tooltipBackColor.alpha = 255;
+ m_tooltipHasAccent = FALSE;
} // end Mouse
@@ -869,8 +870,10 @@ void Mouse::setCursorTooltip( UnicodeString tooltip, Int delay, const RGBColor *
m_tooltipDisplayString->setText(tooltip);
//DEBUG_LOG(("Tooltip: %ls\n", tooltip.str()));
}
+ m_tooltipHasAccent = color != NULL;
if (color)
{
+ m_tooltipAccent = *color;
if (m_useTooltipAltTextColor)
{
if (m_adjustTooltipAltColor)
@@ -1034,7 +1037,15 @@ void Mouse::drawTooltip( void )
return;
}
- if( m_displayTooltip && TheDisplay && m_tooltipDisplayString && (m_tooltipDisplayString->getTextLength() > 0) && !m_isTooltipEmpty)
+ const Bool cursorTip = m_displayTooltip && TheDisplay && m_tooltipDisplayString && (m_tooltipDisplayString->getTextLength() > 0) && !m_isTooltipEmpty;
+
+ // in a match the tooltip page draws both kinds, this one and the command bar's build tooltip;
+ // TheInGameUI is not made yet while the first screens load
+ const UnicodeString pageText = cursorTip ? m_tooltipDisplayString->getText() : UnicodeString::TheEmptyString;
+ if( TheInGameUI && TheInGameUI->drawTooltipPage( pageText, m_tooltipHasAccent ? &m_tooltipAccent : NULL ) )
+ return;
+
+ if( cursorTip )
{
Int width, xPos;
Int height, yPos;