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): feed events for powers, promotions, buildings, dozers; dota chat

Olcay Seygan0d702b69cba1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9e3c08c9e..d1b02cca9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -457,7 +457,7 @@ found and fixed — EA's own, not port damage.**
- The clock and frame-rate readout is drawn on top of everything.
- The superweapon countdowns are pictures now, not a list of names: the same strip treatment, in the top right corner, under that readout. Each one wears its own seconds and a sweeping clock, the next to land sits at the right hand end, and if you are watching more than eighteen of them the rest become a count.
- Every button's corner markings - the hotkey, the price, the time, the number queued - sit flush in the corners instead of floating a few pixels inside them, and are set a size smaller than the button's own text: four labels at full size were eating the picture they were meant to annotate.
-- The messages that ran down the top left corner, out of money or a structure under attack, are lines of a feed standing on the radar now, the way Dota's kill feed stands on its minimap. Each line sits on a black band that thins out over the battlefield. A line about a player opens on his general's flag with his name in his colour; the rest open on a gold mark. Chat goes in, a player beaten or gone goes in, and so does every superweapon, for a player and a watcher alike. Six lines at most, the newest at the bottom, and the feed steps up over the production queue's row whenever that is out.
+- The messages that ran down the top left corner, out of money or a structure under attack, are lines of a feed standing on the radar now, the way Dota's kill feed stands on its minimap. Each line sits on a black band that thins out over the battlefield. A line about a player opens on his general's flag with his name in his colour; the rest open on a gold mark. A smoke signal or a beacon goes in, and so does a player beaten or gone, for a player and a watcher alike. Six lines at most, ten seconds each, the newest at the bottom, and the feed steps up over the production queue's row whenever that is out.
- A superweapon's wait is written in plain seconds - 200, not 3:20 - so it compares with every other countdown on the screen at a glance. Once it is charged the number goes away entirely and the picture itself breathes in your colour, which is the one thing you want to catch out of the corner of your eye.
- The countdown inside a strip picture moved down into its bottom left corner and carries the unit with it - 45s, 200s - on a translucent plate. In the middle of the picture it sat on the one thing the picture is there to show, and the plate it lost when it was in the middle earns its place down in the corner, where a pale cameo was swallowing the digits and their shadow together. This applies to the superweapon countdowns in the top right as well.
- Every picture in the row stands in a tray - the same tray your general's powers stand in down in the corner, your own side's copy of it, so the American, Chinese and GLA strips each carry their own metal. The tray is turned back to front, because that bar grows out of the right hand corner and the strip grows out of the left, so its heavy rail leads the row instead of standing between every pair of pictures. It is never stretched to fit, and side by side the trays close up behind each other by exactly what that bar closes its own up by, so a row of them reads as one run of metal rather than a line of loose boxes. Stacked they stand clear of each other instead: a picture in a column carries its whole tray, with none of the one above it cutting across its top edge. The strip is flush against the left edge, and a black rectangle laid over the battlefield is gone.
@@ -500,6 +500,8 @@ found and fixed — EA's own, not port damage.**
- The drop-downs on the right open over the board instead of pushing it down the screen.
- The superweapon countdowns and the promotions each general has bought moved into a panel on the left, one row per player with his general at the head of it, where they used to be two strips down the right-hand edge.
- A superweapon coming ready or being fired is a line of that feed: whose it is, its picture and its name, then "ready to fire" in green or "launched" in red. Only a watcher used to be told, and only when one came ready.
+- The feed also says when a general's power is used, when a promotion is bought, and when a superweapon, a Strategy Center, a Propaganda Center or a Palace goes up and when it is finished, each with its picture. A player is told that about himself and his allies, a watcher about everybody; a finished superweapon is told to everybody, as the announcer already did. A Spectre Gunship called from three command centers on the same frame is one line, not three. A player whose last dozer dies, or last worker for the GLA, gets a line too, since he can build nothing more until he makes another.
+- Chat sits a little under the middle of the screen, the way Dota writes it: each line opens on the speaker's general's flag and his name in his colour, and is up for ten seconds. Enter opens a dark typing bar under the lines, saying whom it goes to, with the last eight lines kept up while you type.
- Both are an ordinary web page with a stylesheet, in the game's Window folder. Change the colours, the sizes or the order there and the next match you watch draws it that way, and the page opens in a browser too.
- A minimised command bar stays minimised. Changing seats, or clicking another player's unit while watching, put the whole bar back up over the battlefield you had just cleared. A new match still opens with the bar up.
- The command bar's frame is drawn new, in the same steel as the boards. Each panel holds one thing and is exactly its size, the radar, the command grid, the portrait with the experience bar, and wears a steel border outside it. Grey for America, red for China, sand for GLA. It slides and minimises with the bar, and like the boards it is a page in the Window folder; take the page away and the old painted bar comes back.
@@ -604,7 +606,7 @@ found and fixed — EA's own, not port damage.**
- Healing a unit counted as attacking it, so guards chased the wrong target.
- A supply centre could stop accepting trucks permanently.
- Selling a building mid-research gave no refund and left the upgrade in limbo.
-- A line of the event feed holds for eight seconds and then goes.
+- A line of the event feed holds for ten seconds and then goes.
- Closing a dialog while another one sits on top of it no longer leaves the game holding a pointer to the window it just freed. Every click, every keypress and the tab order all read that list, so what it caused was a crash with no pattern to it.
- A dialog asked to open twice closes once. It went on the list of windows that take every click a second time, closing took one copy off, and the other kept eating input for a window nobody could see.
- Ordering a group to use a special power that can kill the units casting it, the GLA rebel ambush over water being the one that does it every time, no longer walks a list of units that the ambush is deleting underneath.
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index 504490381..ccf444eec 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -1213,6 +1213,34 @@ GUI:HudSuperweaponLaunched
"launched"
END
+// after a general's power's name in the event feed, the moment it is used
+GUI:HudPowerUsed
+"used"
+END
+
+// after a promotion's name in the event feed, the moment it is bought
+GUI:HudPromotionBought
+"unlocked"
+END
+
+// after a superweapon's or an advanced tech building's name in the event feed
+GUI:HudStructureStarted
+"construction started"
+END
+
+GUI:HudStructureBuilt
+"built"
+END
+
+// a line of the event feed when a player's last dozer or worker is gone; %s is his name
+GUI:HudNoDozerLeft
+"%s has no dozer left"
+END
+
+GUI:HudNoWorkerLeft
+"%s has no worker left"
+END
+
// the command bar's own buttons, written on them now that the bar is drawn from a page
GUI:BarIdleWorker
"Worker"
diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.str
index f6a77ff3c..42f849abb 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -15729,6 +15729,30 @@ GUI:HudSuperweaponLaunched
"ateşlendi"
END
+GUI:HudPowerUsed
+"kullanıldı"
+END
+
+GUI:HudPromotionBought
+"açıldı"
+END
+
+GUI:HudStructureStarted
+"inşaatı başladı"
+END
+
+GUI:HudStructureBuilt
+"tamamlandı"
+END
+
+GUI:HudNoDozerLeft
+"%s için hiç dozer kalmadı"
+END
+
+GUI:HudNoWorkerLeft
+"%s için hiç işçi kalmadı"
+END
+
GUI:BarIdleWorker
"İşçi"
END
diff --git a/GeneralsMD/Code/Data/Window/Html/Chat.html b/GeneralsMD/Code/Data/Window/Html/Chat.html
new file mode 100644
index 000000000..398f8935b
--- /dev/null
+++ b/GeneralsMD/Code/Data/Window/Html/Chat.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<!--
+ The chat, a little under the middle of the screen, the way Dota writes it: each line opens on the
+ speaker's general's flag and his name in his colour. With the chat shut the lines of the last ten
+ seconds are up; Enter opens the typing bar under them and every line held, eight at most, stays
+ up until it shuts. The chat's own windows sit under the bar and take the keys; this page draws
+ everything. Same materials as Window/Html/Spectator.html, whose header says what the renderer
+ draws.
+
+ The game fills in, every frame the chat is up (InGameUI::drawChat):
+ {{left}} the chat's left edge, the chat 360 wide and centred
+ {{bar}} the typing bar's top edge; the lines stand on it
+ {{open}} "open" while the chat is open
+ {{typed}} what has been typed so far, {{caret}} "lit" for half of every second
+ {{audience}} whom it goes to: everyone, allies or observers, in the player's language
+ data-each="chat" one entry a line, the oldest first: {{image}} the speaker's general,
+ {{color}} {{name}} and {{text}} what he said
+ All in the page's pixels, a pixel of an 800x600 screen.
+-->
+<html>
+<head>
+<meta charset="utf-8">
+<title>Chat</title>
+<style>
+ html, body { margin: 0; padding: 0; }
+ body { background-color: #3b4a36; color: #eef2f5; font-size: 9px; }
+
+ #chat { position: absolute; top: 0; width: 360px; }
+ #lines { position: absolute; left: 0; bottom: 2px; width: 360px; }
+ .line { height: 15px; line-height: 15px; margin-top: 1px; padding-left: 2px; white-space: nowrap;
+ background: linear-gradient(to right, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.3) 70%, rgba(0, 0, 0, 0)); }
+ .flag { width: 20px; height: 12px; margin-right: 4px; vertical-align: middle; }
+ .who { font-weight: bold; }
+
+ #bar { display: none; position: absolute; width: 356px; height: 12px; line-height: 12px; padding: 0 2px;
+ background-color: rgba(0, 0, 0, 0.88); border: 1px solid #3a414a; border-top-color: #000000; }
+ .open #bar { display: block; }
+ .audience { color: #8a949f; margin-right: 5px; }
+ .caret { display: none; color: #f2cf4a; }
+ .caret.lit { display: inline; }
+</style>
+</head>
+<body>
+<div class="{{open}}">
+ <div id="chat" style="left: {{left}}px; height: {{bar}}px">
+ <div id="lines">
+ <div class="line" data-each="chat"><img class="flag" src="{{image}}"><span class="who" style="color: {{color}}">{{name}}:</span> {{text}}</div>
+ </div>
+ </div>
+ <div id="bar" style="left: {{left}}px; top: {{bar}}px"><span class="audience">{{audience}}</span>{{typed}}<span class="caret {{caret}}">|</span></div>
+</div>
+</body>
+</html>
diff --git a/GeneralsMD/Code/Data/Window/Html/Feed.html b/GeneralsMD/Code/Data/Window/Html/Feed.html
index c4cbc1e75..bc7c756cb 100644
--- a/GeneralsMD/Code/Data/Window/Html/Feed.html
+++ b/GeneralsMD/Code/Data/Window/Html/Feed.html
@@ -1,10 +1,12 @@
<!DOCTYPE html>
<!--
- The event feed, for a player and a watcher alike: every message the game writes, a superweapon
- coming ready or being fired, a player beaten or gone, a line of chat. It stands on the radar's
- under-attack tab in the screen's bottom left corner, the newest line at the bottom, the way Dota's
- kill feed stands on its minimap. A line is up for eight seconds, six at most, and the oldest goes
- first. Same materials as Window/Html/Spectator.html, whose header says what the renderer draws.
+ The event feed, for a player and a watcher alike: every message the game writes, a smoke signal
+ or a beacon, a superweapon coming ready or being fired, a general's power used, a promotion bought,
+ a superweapon or advanced tech building started or finished, a player beaten, gone or left with no
+ dozer. Chat has its own page, Window/Html/Chat.html. The feed stands on the radar's under-attack
+ tab in the screen's bottom left corner, the newest line at the bottom, the way Dota's kill feed
+ stands on its minimap. A line is up for ten seconds, six at most, and the oldest goes first. Same
+ materials as Window/Html/Spectator.html, whose header says what the renderer draws.
The game fills in, every frame a line is up (InGameUI::drawFeed):
{{floor}} where the feed stands: the top of the radar's tab, or of the production
@@ -14,9 +16,10 @@
"player" a message about one player: {{portrait}} his general's flag,
{{color}} his colour, and the text as {{before}} {{name}}
{{after}}, his name cut out of it wherever it says it
- "weapon" a superweapon: {{portrait}} {{color}} {{name}} of its owner,
- {{image}} its cameo, {{what}} the building's name and
- {{tagtext}} what happened, {{tag}} "ready" or "launched"
+ "act" something a player did: {{portrait}} {{color}} {{name}},
+ {{image}} its cameo, {{what}} its name and {{tagtext}} what
+ happened, {{tag}} one of "ready" "launched" "used" "unlocked"
+ "started" "built"
All in the page's pixels, a pixel of an 800x600 screen.
-->
<html>
@@ -43,12 +46,15 @@
.cameo { width: 18px; height: 13px; margin: 0 4px; vertical-align: middle; }
.what { color: #e8d27a; }
.tag { margin-left: 4px; font-weight: bold; }
- .tag.ready { color: #b8f08a; }
+ .tag.ready, .tag.built { color: #b8f08a; }
.tag.launched { color: #ff6a55; }
+ .tag.used { color: #f2cf4a; }
+ .tag.unlocked { color: #7fc8ff; }
+ .tag.started { color: #c9d2d9; }
.knote .flag, .knote .cameo, .knote .what, .knote .tag { display: none; }
.kplayer .chip, .kplayer .cameo, .kplayer .what, .kplayer .tag { display: none; }
- .kweapon .chip { display: none; }
+ .kact .chip { display: none; }
</style>
</head>
<body>
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GUICallbacks.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GUICallbacks.h
index 20442aacc..c4cf09d54 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GUICallbacks.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GUICallbacks.h
@@ -342,6 +342,7 @@ extern void ShowInGameChat( Bool immediate = TRUE );
void ResetInGameChat( void );
void SetInGameChatType( InGameChatType chatType );
Bool IsInGameChatActive();
+Bool GetInGameChatEntry( UnicodeString &typed, UnicodeString &audience, Int x, Int y, Int width, Int height );
// Diplomacy Controls --------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index f420ad63a..4cc6ad66e 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -74,6 +74,7 @@ enum LegalBuildCode;
enum KindOfType;
enum ShadowType;
enum CanAttackResult;
+enum ScienceType;
// ------------------------------------------------------------------------------------------------
enum RadiusCursorType
@@ -399,8 +400,12 @@ public: // ********************************************************************
virtual void message( UnicodeString format, ... ); ///< display a message to the user
virtual void message( AsciiString stringManagerLabel, ... );///< display a message to the user
void playerMessage( Player *player, const UnicodeString &text ); ///< a message about that player, his flag at its head
- /** The feed's line for a superweapon that came ready, or was fired when `launched`. */
- void feedSuperweapon( const Object *weapon, const AsciiString &powerName, const SpecialPowerTemplate *power, Bool launched );
+ void chatMessage( Player *player, const UnicodeString &text ); ///< a line of chat, under the middle of the screen
+ /** The feed's lines for what a player did: a special power fired, a superweapon or advanced tech
+ * building started or `finished`, a promotion bought. Each decides who is told. */
+ void feedSpecialPower( const Object *source, const AsciiString &powerName, const SpecialPowerTemplate *power );
+ void feedStructure( Object *structure, Bool finished );
+ void feedScience( Player *player, ScienceType science );
virtual void toggleMessages( void ) { m_messagesOn = 1 - m_messagesOn; } ///< toggle messages on/off
void openScoreboard( void ) { m_scoreboardOpen = TRUE; } ///< the Tab scoreboard, up while Tab is held
void closeScoreboard( void ) { m_scoreboardOpen = FALSE; }
@@ -1271,7 +1276,17 @@ protected:
};
std::vector< FeedLine > m_feedLines;
void addFeedLine( HtmlValues line );
+ void feedAct( Player *player, const Image *cameo, const std::string &what, const char *tag, const char *label );
+ void watchDozers( void );
void drawFeed( void );
+ UnsignedInt m_dozerCheckFrame; ///< the logic frame watchDozers last looked on
+ Bool m_hadDozer[ MAX_PLAYER_COUNT ]; ///< that player had a dozer or worker then
+ // the chat under the middle of the screen, Window/Html/Chat.html, the same lines kept a while
+ std::vector< FeedLine > m_chatLines;
+ void drawChat( void );
+ HtmlOverlay * m_chatOverlay;
+ Bool m_chatPageLoaded;
+ std::string m_chatPage;
HtmlOverlay * m_feedOverlay;
Bool m_feedPageLoaded;
std::string m_feedPage;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
index 030bcfe02..d8dd06ca7 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
@@ -76,6 +76,7 @@
#include "GameClient/Eva.h"
#include "GameClient/GameClient.h"
#include "GameClient/GameText.h"
+#include "GameClient/InGameUI.h"
#include "GameLogic/AI.h"
#include "GameLogic/AIPathfind.h"
@@ -1734,7 +1735,7 @@ void Player::preTeamDestroy( const Team *team )
//-------------------------------------------------------------------------------------------------
void Player::onStructureCreated( Object *builder, Object *structure )
{
-
+ TheInGameUI->feedStructure( structure, FALSE );
} // end onStructureCreated
//-------------------------------------------------------------------------------------------------
@@ -1766,7 +1767,8 @@ void Player::onStructureConstructionComplete( Object *builder, Object *structure
// the GUI needs to re-evaluate the information being displayed to the user now
if( TheControlBar )
TheControlBar->markUIDirty();
-
+ TheInGameUI->feedStructure( structure, TRUE );
+
// This object may require us to play some EVA sounds.
Player *localPlayer = ThePlayerList->getLocalPlayer();
@@ -2732,7 +2734,8 @@ Bool Player::attemptToPurchaseScience(ScienceType science)
addScience(science);
getAcademyStats()->recordGeneralsPointsSpent( cost );
-
+ TheInGameUI->feedScience( this, science );
+
if( ThePlayerList->getLocalPlayer() == this )
{
TheControlBar->markUIDirty();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/InGameChat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/InGameChat.cpp
index c71f8c0f9..de2acb63d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/InGameChat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/InGameChat.cpp
@@ -52,6 +52,14 @@ static GameWindow *chatTypeStaticText = NULL;
static UnicodeString s_savedChat;
static InGameChatType inGameChatType;
+// ------------------------------------------------------------------------------------------------
+/** Window/Html/Chat.html draws the chat: the typed line with the lines over it. The layout's
+ * windows keep the keys and draw nothing. */
+// ------------------------------------------------------------------------------------------------
+static void drawChatNothing( GameWindow *window, WinInstanceData *instData )
+{
+}
+
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void ShowInGameChat( Bool immediate )
@@ -84,6 +92,10 @@ void ShowInGameChat( Bool immediate )
static NameKeyType chatTypeStaticTextID = TheNameKeyGenerator->nameToKey( "InGameChat.wnd:StaticTextChatType" );
chatTypeStaticText = TheWindowManager->winGetWindowFromId( NULL, chatTypeStaticTextID );
+
+ chatWindow->winSetDrawFunc( drawChatNothing );
+ for( GameWindow *child = chatWindow->winGetChild(); child; child = child->winGetNext() )
+ child->winSetDrawFunc( drawChatNothing );
}
TheWindowManager->winSetFocus( chatTextEntry );
SetInGameChatType( INGAME_CHAT_EVERYONE );
@@ -142,6 +154,28 @@ void SetInGameChatType( InGameChatType chatType )
}
}
+// ------------------------------------------------------------------------------------------------
+/** While the chat is open: the line being typed and whom it goes to, and the chat's windows moved
+ * over the page's typing bar, `x` `y` `width` `height` on screen, so the invisible layout takes no
+ * clicks anywhere else. FALSE while it is shut. */
+// ------------------------------------------------------------------------------------------------
+Bool GetInGameChatEntry( UnicodeString &typed, UnicodeString &audience, Int x, Int y, Int width, Int height )
+{
+ if( !IsInGameChatActive() )
+ return FALSE;
+
+ typed = GadgetTextEntryGetText( chatTextEntry );
+ audience = GadgetStaticTextGetText( chatTypeStaticText );
+ chatWindow->winSetPosition( x, y );
+ chatWindow->winSetSize( width, height );
+ for( GameWindow *child = chatWindow->winGetChild(); child; child = child->winGetNext() )
+ {
+ child->winSetPosition( 0, 0 );
+ child->winSetSize( child == chatTextEntry ? width : 0, child == chatTextEntry ? height : 0 );
+ }
+ return TRUE;
+}
+
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
Bool IsInGameChatActive() {
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index d48323bc8..0c1674e03 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -204,7 +204,7 @@ static void formatStripSeconds( UnicodeString *text, Int seconds )
* be asked. A power with no button anywhere (a scripted one, a mod's) draws as an empty box
* with its countdown in it, which is still the timer it was asked for. */
//-------------------------------------------------------------------------------------------------
-static const Image *superweaponCameo( const SpecialPowerTemplate *powerTemplate )
+static const CommandButton *powerButton( const SpecialPowerTemplate *powerTemplate )
{
if( powerTemplate == NULL || TheControlBar == NULL )
return NULL;
@@ -213,12 +213,30 @@ static const Image *superweaponCameo( const SpecialPowerTemplate *powerTemplate
button = button->getNext() )
{
if( button->getSpecialPowerTemplate() == powerTemplate && button->getButtonImage() )
- return button->getButtonImage();
+ return button;
}
return NULL;
}
+static const Image *superweaponCameo( const SpecialPowerTemplate *powerTemplate )
+{
+ const CommandButton *button = powerButton( powerTemplate );
+ return button ? button->getButtonImage() : NULL;
+}
+
+/** The promotion screen's button that buys a science, the picture a bought promotion goes by. */
+static const CommandButton *scienceButton( ScienceType science )
+{
+ for( const CommandButton *button = TheControlBar->getCommandButtons(); button; button = button->getNext() )
+ {
+ const ScienceVec &sciences = button->getScienceVec();
+ if( button->getButtonImage() && std::find( sciences.begin(), sciences.end(), science ) != sciences.end() )
+ return button;
+ }
+ return NULL;
+}
+
//-------------------------------------------------------------------------------------------------
/** Pointer to show while a structure rides the cursor. Mouse::BUILD_PLACEMENT and
* INVALID_BUILD_PLACEMENT are two names in CursorININames[] that no shipped Mouse.ini ever
@@ -1148,6 +1166,11 @@ InGameUI::InGameUI()
m_feedPageLoaded = FALSE;
m_feedFloor = 0;
m_queueTrayTop = 0;
+ m_dozerCheckFrame = 0;
+ for( Int index = 0; index < MAX_PLAYER_COUNT; index++ )
+ m_hadDozer[ index ] = FALSE;
+ m_chatOverlay = NULL;
+ m_chatPageLoaded = FALSE;
m_replayWindow = NULL;
m_messagesOn = TRUE;
@@ -1328,6 +1351,8 @@ InGameUI::~InGameUI()
m_spectatorOverlay = NULL;
delete m_feedOverlay;
m_feedOverlay = NULL;
+ delete m_chatOverlay;
+ m_chatOverlay = NULL;
delete m_scoreboardOverlay;
m_scoreboardOverlay = NULL;
delete m_controlBarOverlay;
@@ -1806,7 +1831,7 @@ enum
PLAYER_NAME_CHARS = 11, ///< a name longer than this is cut, there is no clipping to hide it
SECONDS_IN_MINUTE = 60,
SECONDS_PER_HOUR = 60 * 60,
- FEED_LINE_FRAMES = LOGICFRAMES_PER_SECOND * 8, ///< how long a line of the event feed stays up
+ FEED_LINE_FRAMES = LOGICFRAMES_PER_SECOND * 10, ///< how long a line of the event feed stays up
FEED_LINES_KEPT = 6, ///< the most of those on screen at once; the oldest goes first
COMMAND_SLOTS_PER_COLUMN = 2, ///< the command bar numbers its slots down each column, top then bottom
PERCENT = 100
@@ -3383,6 +3408,8 @@ void InGameUI::update( void )
// the messages are lines of the event feed now, which drops them at drawing by their frame
UnsignedInt currLogicFrame = TheGameLogic->getFrame();
+ if( TheGameLogic->isInGame() && !TheGameLogic->isInShellGame() )
+ watchDozers();
UnsignedByte r, g, b, a;
Int amount;
@@ -3719,6 +3746,11 @@ void InGameUI::reset( void )
m_spectatorTotals.clear();
m_spectatorSuperweapons.clear();
m_feedPageLoaded = FALSE;
+ m_chatPageLoaded = FALSE;
+ m_chatLines.clear();
+ m_dozerCheckFrame = 0;
+ for( Int index = 0; index < MAX_PLAYER_COUNT; index++ )
+ m_hadDozer[ index ] = FALSE;
m_inputEnabled = true;
// reset the command bar
TheControlBar->reset();
@@ -3914,39 +3946,152 @@ void InGameUI::playerMessage( Player *player, const UnicodeString &text )
}
//-------------------------------------------------------------------------------------------------
-/** A superweapon that came ready or was fired: whose, its picture, its name. Only the ones with a
- * countdown on everybody's screen, so a general's power fired from a command button is not one. */
+/** Is the local screen told what `player` did where nobody else is? A watcher is told everything,
+ * a player what he or a mutual ally did: an enemy's promotion or his power going up is not his to
+ * know. */
//-------------------------------------------------------------------------------------------------
-void InGameUI::feedSuperweapon( const Object *weapon, const AsciiString &powerName, const SpecialPowerTemplate *power,
- Bool launched )
+static Bool feedShows( const Player *player )
{
- Player *owner = weapon->getControllingPlayer();
- const SuperweaponInfo *info = findSWInfo( owner->getPlayerIndex(), powerName, weapon->getID(), power );
- if( info == NULL || info->m_hiddenByScript || info->m_hiddenByScience )
- return;
+ const Player *local = ThePlayerList->getLocalPlayer();
+ if( !local->isPlayerActive() || player == local )
+ return TRUE;
+ return player->getRelationship( local->getDefaultTeam() ) == ALLIES &&
+ local->getRelationship( player->getDefaultTeam() ) == ALLIES;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** A command button's name, its hotkey marker taken out: "&A-10 Strike" is "A-10 Strike". */
+//-------------------------------------------------------------------------------------------------
+static std::string buttonName( const CommandButton *button )
+{
+ std::string name = WideCharStringToMultiByte( TheGameText->fetch( button->getTextLabel() ).str() );
+ name.erase( std::remove( name.begin(), name.end(), '&' ), name.end() );
+ return name;
+}
- HtmlValues line = spectatorHead( owner );
- line[ "kind" ] = "weapon";
+//-------------------------------------------------------------------------------------------------
+/** A line about something one player did: his flag and his name, the `cameo` it is pictured by,
+ * `what` it is called and the string table's `label` for what happened, coloured by `tag`. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::feedAct( Player *player, const Image *cameo, const std::string &what, const char *tag, const char *label )
+{
+ HtmlValues line = spectatorHead( player );
+ line[ "kind" ] = "act";
line[ "portrait" ] = line[ "image" ];
- const Image *cameo = superweaponCameo( power );
line[ "image" ] = cameo ? cameo->getName().str() : "";
- line[ "what" ] = WideCharStringToMultiByte( weapon->getTemplate()->getDisplayName().str() );
- line[ "tag" ] = launched ? "launched" : "ready";
- line[ "tagtext" ] = WideCharStringToMultiByte( TheGameText->fetch( launched ? "GUI:HudSuperweaponLaunched" : "GUI:HudSuperweaponReady" ).str() );
+ line[ "what" ] = what;
+ line[ "tag" ] = tag;
+ line[ "tagtext" ] = WideCharStringToMultiByte( TheGameText->fetch( label ).str() );
addFeedLine( line );
}
+//-------------------------------------------------------------------------------------------------
+/** A special power fired. A superweapon with a countdown on everybody's screen is told to everybody,
+ * the way EVA tells them; a general's power, one a promotion bought, only where feedShows says. A
+ * unit's own ability is neither and writes nothing. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::feedSpecialPower( const Object *source, const AsciiString &powerName, const SpecialPowerTemplate *power )
+{
+ Player *owner = source->getControllingPlayer();
+ const CommandButton *button = powerButton( power );
+ const Image *cameo = button ? button->getButtonImage() : NULL;
+ const SuperweaponInfo *info = findSWInfo( owner->getPlayerIndex(), powerName, source->getID(), power );
+ if( info != NULL )
+ {
+ if( !info->m_hiddenByScript && !info->m_hiddenByScience )
+ feedAct( owner, cameo, WideCharStringToMultiByte( source->getTemplate()->getDisplayName().str() ),
+ "launched", "GUI:HudSuperweaponLaunched" );
+ return;
+ }
+ if( power->getRequiredScience() == SCIENCE_INVALID || button == NULL || !feedShows( owner ) )
+ return;
+ feedAct( owner, cameo, buttonName( button ), "used", "GUI:HudPowerUsed" );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** A superweapon or an advanced tech building going up, or finished. A finished superweapon is told
+ * to everybody, the way EVA tells them; the rest only where feedShows says. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::feedStructure( Object *structure, Bool finished )
+{
+ const Bool superweapon = structure->isKindOf( KINDOF_FS_SUPERWEAPON );
+ if( !superweapon && !structure->isKindOf( KINDOF_FS_ADVANCED_TECH ) )
+ return;
+
+ Player *owner = structure->getControllingPlayer();
+ if( !( finished && superweapon ) && !feedShows( owner ) )
+ return;
+ feedAct( owner, structure->getTemplate()->getButtonImage(),
+ WideCharStringToMultiByte( structure->getTemplate()->getDisplayName().str() ),
+ finished ? "built" : "started", finished ? "GUI:HudStructureBuilt" : "GUI:HudStructureStarted" );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** A promotion bought: the power or the unit it opens, by the promotion screen's own button. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::feedScience( Player *player, ScienceType science )
+{
+ if( !feedShows( player ) )
+ return;
+
+ UnicodeString name, description;
+ TheScienceStore->getNameAndDescription( science, name, description );
+ const CommandButton *button = scienceButton( science );
+ feedAct( player, button ? button->getButtonImage() : NULL, WideCharStringToMultiByte( name.str() ),
+ "unlocked", "GUI:HudPromotionBought" );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Once a second: a player whose last dozer, or last worker for the GLA, has just gone gets a line,
+ * since without one he can build nothing more. Only where feedShows says, and not for a player
+ * already beaten, whose last dozer went with everything else. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::watchDozers( void )
+{
+ const UnsignedInt frame = TheGameLogic->getFrame();
+ if( frame < m_dozerCheckFrame + LOGICFRAMES_PER_SECOND && frame >= m_dozerCheckFrame )
+ return;
+ m_dozerCheckFrame = frame;
+
+ KindOfMaskType dozers;
+ dozers.set( KINDOF_DOZER );
+ for( Int index = 0; index < ThePlayerList->getPlayerCount() && index < MAX_PLAYER_COUNT; index++ )
+ {
+ Player *player = ThePlayerList->getNthPlayer( index );
+ const Bool has = player->isPlayableSide() && player->countObjects( dozers, KINDOFMASK_NONE ) > 0;
+ const Bool lost = m_hadDozer[ index ] && !has;
+ m_hadDozer[ index ] = has;
+ if( !lost || TheVictoryConditions->hasSinglePlayerBeenDefeated( player ) || !feedShows( player ) )
+ continue;
+
+ const Bool workers = player->getPlayerTemplate()->getSide().startsWith( "GLA" );
+ UnicodeString text;
+ text.format( TheGameText->fetch( workers ? "GUI:HudNoWorkerLeft" : "GUI:HudNoDozerLeft" ), player->getPlayerDisplayName().str() );
+ playerMessage( player, text );
+ }
+}
+
//-------------------------------------------------------------------------------------------------
/** One more line at the bottom of the feed, up for FEED_LINE_FRAMES; past FEED_LINES_KEPT the oldest
* goes. Every line is logged too, so a run can be read for what the feed said. */
//-------------------------------------------------------------------------------------------------
void InGameUI::addFeedLine( HtmlValues line )
{
- DEBUG_LOG(( "FEED frame %u %s: %s%s%s %s %s\n", TheGameLogic->getFrame(), line[ "kind" ].c_str(), line[ "before" ].c_str(),
- line[ "name" ].c_str(), line[ "after" ].c_str(), line[ "what" ].c_str(), line[ "tagtext" ].c_str() ));
+ // written out first: reading the names fills in the ones a kind leaves out, so every line held
+ // has all of them and two of the same compare equal
+ const std::string logged = line[ "kind" ] + ": " + line[ "before" ] + line[ "name" ] + line[ "after" ] + " " +
+ line[ "what" ] + " " + line[ "tagtext" ];
+
+ // one power fired from several of its owner's buildings on the same frame is one line, not three
+ const UnsignedInt until = TheGameLogic->getFrame() + FEED_LINE_FRAMES;
+ for( size_t each = 0; each < m_feedLines.size(); each++ )
+ if( m_feedLines[ each ].until == until && m_feedLines[ each ].values == line )
+ return;
+
+ DEBUG_LOG(( "FEED frame %u %s\n", TheGameLogic->getFrame(), logged.c_str() ));
FeedLine added;
added.values = line;
- added.until = TheGameLogic->getFrame() + FEED_LINE_FRAMES;
+ added.until = until;
m_feedLines.push_back( added );
if( m_feedLines.size() > FEED_LINES_KEPT )
m_feedLines.erase( m_feedLines.begin() );
@@ -4017,6 +4162,82 @@ void InGameUI::drawFeed( void )
m_feedOverlay->draw();
}
+static const char *const CHAT_PAGE = "Window\\Html\\Chat.html";
+
+enum
+{
+ CHAT_LINE_FRAMES = LOGICFRAMES_PER_SECOND * 10, ///< how long a chat line stays up with the chat shut
+ CHAT_LINES_KEPT = 8, ///< the most lines held, all of them shown while the chat is open
+ CHAT_WIDTH = 360, ///< the chat's width, 800x600
+ CHAT_BAR_HEIGHT = 14, ///< the typing bar's height, 800x600
+ CHAT_BAR_PERCENT = 58, ///< how far down the screen the typing bar's top stands
+ CHAT_CARET_FRAMES = LOGICFRAMES_PER_SECOND / 2 ///< the caret's blink, on and off
+};
+
+//-------------------------------------------------------------------------------------------------
+/** A line of chat from `player`: his flag, his name in his colour, what he said. It goes into the
+ * chat under the middle of the screen, Dota's way, not into the feed. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::chatMessage( Player *player, const UnicodeString &text )
+{
+ FeedLine line;
+ line.values = spectatorHead( player );
+ line.values[ "text" ] = WideCharStringToMultiByte( text.str() );
+ line.until = TheGameLogic->getFrame() + CHAT_LINE_FRAMES;
+ DEBUG_LOG(( "CHAT frame %u %s: %s\n", TheGameLogic->getFrame(), line.values[ "name" ].c_str(), line.values[ "text" ].c_str() ));
+ m_chatLines.push_back( line );
+ if( m_chatLines.size() > CHAT_LINES_KEPT )
+ m_chatLines.erase( m_chatLines.begin() );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The chat, Window/Html/Chat.html, a little under the middle of the screen: the lines of the last
+ * ten seconds, and with Enter pressed the typing bar under every line held, the chat's own windows
+ * moved under it so they take the keys and the clicks there and draw nothing. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::drawChat( void )
+{
+ if( !TheGameLogic->isInGame() || TheGameLogic->isInShellGame() )
+ return;
+
+ const Real scale = ControlBarUniformScale();
+ const Int pageWidth = REAL_TO_INT_FLOOR( TheDisplay->getWidth() / scale );
+ const Int left = ( pageWidth - CHAT_WIDTH ) / 2;
+ const Int bar = REAL_TO_INT_FLOOR( TheDisplay->getHeight() / scale ) * CHAT_BAR_PERCENT / 100;
+
+ UnicodeString typed, audience;
+ const Bool open = GetInGameChatEntry( typed, audience, REAL_TO_INT_FLOOR( left * scale ), REAL_TO_INT_FLOOR( bar * scale ),
+ REAL_TO_INT_CEIL( CHAT_WIDTH * scale ), REAL_TO_INT_CEIL( CHAT_BAR_HEIGHT * scale ) );
+ const UnsignedInt frame = TheGameLogic->getFrame();
+ HtmlLists lists;
+ std::vector< HtmlValues > &lines = lists[ "chat" ];
+ for( size_t line = 0; line < m_chatLines.size(); line++ )
+ if( open || ( frame < m_chatLines[ line ].until && frame + CHAT_LINE_FRAMES >= m_chatLines[ line ].until ) )
+ lines.push_back( m_chatLines[ line ].values );
+ if( !open && lines.empty() )
+ return;
+
+ if( !m_chatPageLoaded )
+ {
+ m_chatPageLoaded = TRUE;
+ readHtmlPage( CHAT_PAGE, m_chatPage );
+ }
+ if( m_chatPage.empty() )
+ return;
+ if( m_chatOverlay == NULL )
+ m_chatOverlay = new HtmlOverlay( m_superweaponNormalFont );
+
+ HtmlValues values;
+ values[ "left" ] = std::to_string( left );
+ values[ "bar" ] = std::to_string( bar );
+ values[ "open" ] = open ? "open" : "";
+ values[ "typed" ] = WideCharStringToMultiByte( typed.str() );
+ values[ "caret" ] = frame / CHAT_CARET_FRAMES % 2 == 0 ? "lit" : "";
+ values[ "audience" ] = WideCharStringToMultiByte( audience.str() );
+ m_chatOverlay->setPage( HtmlTemplate_expand( m_chatPage, values, lists, lookupGameText ) );
+ m_chatOverlay->draw();
+}
+
//-------------------------------------------------------------------------------------------------
/** An area selection is occurring, start graphical "hint". */
//-------------------------------------------------------------------------------------------------
@@ -7076,6 +7297,7 @@ void InGameUI::postDraw( void )
drawPlacementReach(); // after the shade, so the outline stays bright over it
drawSpectatorPage();
drawFeed();
+ drawChat();
if( m_militarySubtitle )
{
@@ -7161,7 +7383,9 @@ void InGameUI::postDraw( void )
{
if ( TheGameLogic->getFrame() > 0 )
{
- feedSuperweapon( owningObject, mapIt->first, info->getSpecialPowerTemplate(), FALSE );
+ feedAct( owningObject->getControllingPlayer(), superweaponCameo( info->getSpecialPowerTemplate() ),
+ WideCharStringToMultiByte( owningObject->getTemplate()->getDisplayName().str() ),
+ "ready", "GUI:HudSuperweaponReady" );
SpecialPowerType type = module->getSpecialPowerTemplate()->getSpecialPowerType();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp
index c103b0257..93ff74d34 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp
@@ -678,8 +678,8 @@ void SpecialPowerModule::aboutToDoSpecialPower( const Coord3D *location )
// the same place so the two can never end up describing different events.
// It stamps a frame on the client side and returns; nothing here changes.
chromaSuperweaponLaunched( type );
- // and the event feed, which writes a line only for a superweapon with a public countdown
- TheInGameUI->feedSuperweapon( getObject(), getPowerName(), getSpecialPowerModuleData()->m_specialPowerTemplate, TRUE );
+ // and the event feed, which writes a line for a superweapon and a general's power, not a unit's
+ TheInGameUI->feedSpecialPower( getObject(), getPowerName(), getSpecialPowerModuleData()->m_specialPowerTemplate );
}
// get module data
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
index 8c274eac3..a9e134572 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
@@ -2048,7 +2048,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
// tell the user
UnicodeString s;
s.format(TheGameText->fetch("GUI:BeaconPlaced"), thisPlayer->getPlayerDisplayName().str());
- TheInGameUI->message( s );
+ TheInGameUI->playerMessage( thisPlayer, s );
// play a sound
static AudioEventRTS aSound("BeaconPlaced");
@@ -2157,7 +2157,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
UnicodeString announcement;
announcement.format( TheGameText->fetch( look.announcementLabel ), thisPlayer->getPlayerDisplayName().str() );
- TheInGameUI->message( announcement );
+ TheInGameUI->playerMessage( thisPlayer, announcement );
static AudioEventRTS signalSound( "BeaconPlaced" );
signalSound.setPlayerIndex( thisPlayer->getPlayerIndex() );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp
index 498a8fae4..05be96b6a 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp
@@ -713,7 +713,7 @@ void ConnectionManager::processChat(NetChatCommandMsg *msg)
if ( ((1<<m_localSlot) & msg->getPlayerMask() ) && canSeeChat )
{
- TheInGameUI->playerMessage(player, unitext);
+ TheInGameUI->chatMessage(player, msg->getText());
// feedback for received chat messages in-game
AudioEventRTS audioEvent("GUICommunicatorIncoming");