Skip to content

Commit 2c9e328

Browse files
authored
[Vanilla Enhancement] Task subtitles display in the middle of the screen (#1737)
- Now you can set `MessageApplyHoverState` to true,to make the upper left messages not disappear while mouse hovering over the top of display area. - You can also let task subtitles (created by trigger 11) to display directly in the middle area of the screen instead of the upper left corner, with a semi transparent background, by setting `MessageDisplayInCenter` to true. - When the mouse hovers over the subtitle area (simply judged as a rectangle), its opacity will increase and it will not disappear during this period. In `RA2MD.INI`: ```ini [Phobos] MessageApplyHoverState=false ; boolean MessageDisplayInCenter=false ; boolean ``` --- I'm not sure if there is a better implementation, but it's the simplest implementation that comes to my mind.
1 parent 74d3082 commit 2c9e328

File tree

10 files changed

+201
-0
lines changed

10 files changed

+201
-0
lines changed

CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ This page lists all the individual contributions to the project by their author.
500500
- Several new Infotypes, no display in specific status and a new single frame display method
501501
- Customizable spawn delay of `VoxelAnim`'s `TrailerAnim` and fix its incorrect position
502502
- Add `DebrisMinimums` to keep the count of debris within a certain range
503+
- Task subtitles display in the middle of the screen
503504
- **Ollerus**:
504505
- Build limit group enhancement
505506
- Customizable rocker amplitude

Phobos.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
<ClCompile Include="src\Misc\Hooks.INIInheritance.cpp" />
190190
<ClCompile Include="src\Misc\Hooks.SkirmishColors.cpp" />
191191
<ClCompile Include="src\Misc\Hooks.Overlay.cpp" />
192+
<ClCompile Include="src\Misc\Hooks.Message.cpp" />
192193
<ClCompile Include="src\New\Type\Affiliated\TypeConvertGroup.cpp" />
193194
<ClCompile Include="src\Ext\BuildingType\Hooks.Upgrade.cpp" />
194195
<ClCompile Include="src\Phobos.COM.cpp" />

docs/User-Interface.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,23 @@ ShowTimer=yes
368368
ShowTimer.Priority=0 ; integer
369369
```
370370

371+
### Task subtitles display in the middle of the screen
372+
373+
![Message Display In Center](_static/images/messagedisplayincenter.png)
374+
375+
- Now you can set `MessageApplyHoverState` to true,to make the upper left messages not disappear while mouse hovering over the top of display area.
376+
- You can also let task subtitles (created by trigger 11) to display directly in the middle area of the screen instead of the upper left corner, with a semi transparent background, by setting `MessageDisplayInCenter` to true.
377+
- When the mouse hovers over the subtitle area (simply judged as a rectangle), its opacity will increase and it will not disappear during this period.
378+
379+
In `RA2MD.INI`:
380+
```ini
381+
[Phobos]
382+
MessageApplyHoverState=false ; boolean
383+
MessageDisplayInCenter=false ; boolean
384+
```
385+
371386
### Type select for buildings
387+
372388
- In vanilla game, type select can almost only be used on 1x1 buildings with `UndeploysInto`. Now it's possible to use it on all buildings if `BuildingTypeSelectable` set to true.
373389

374390
In `rulesmd.ini`:

docs/Whats-New.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ New:
410410
- Several attackmove related enhancement (by TaranDahl)
411411
- Ground line for select box (by NetsuNegi)
412412
- Support for more optional weapons (by FlyStar)
413+
- Task subtitles display in the middle of the screen (by CrimRecya)
413414
414415
Vanilla fixes:
415416
- Fixed sidebar not updating queued unit numbers when adding or removing units when the production is on hold (by CrimRecya)
824 KB
Loading

src/Ext/Scenario/Body.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ void ScenarioExt::ExtData::Serialize(T& Stm)
163163
.Process(this->TransportReloaders)
164164
.Process(this->SWSidebar_Enable)
165165
.Process(this->SWSidebar_Indices)
166+
// .Process(this->NewMessageList); // Should not S/L
166167
;
167168
}
168169

src/Ext/Scenario/Body.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <ScenarioClass.h>
4+
#include <MessageListClass.h>
45

56
#include <Helpers/Macro.h>
67
#include <Utilities/Container.h>
@@ -39,6 +40,8 @@ class ScenarioExt
3940
bool SWSidebar_Enable;
4041
std::vector<int> SWSidebar_Indices;
4142

43+
std::unique_ptr<MessageListClass> NewMessageList;
44+
4245
ExtData(ScenarioClass* OwnerObject) : Extension<ScenarioClass>(OwnerObject)
4346
, ShowBriefing { false }
4447
, BriefingTheme { -1 }
@@ -48,6 +51,7 @@ class ScenarioExt
4851
, TransportReloaders {}
4952
, SWSidebar_Enable { true }
5053
, SWSidebar_Indices {}
54+
, NewMessageList {}
5155
{ }
5256

5357
void SetVariableToByID(bool bIsGlobal, int nIndex, char bState);

src/Misc/Hooks.Message.cpp

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#include <MessageListClass.h>
2+
#include <WWMouseClass.h>
3+
4+
#include <Ext/Scenario/Body.h>
5+
6+
namespace MessageTemp
7+
{
8+
bool OnOldMessages = false;
9+
bool OnNewMessages = false;
10+
bool NewMessageList = false;
11+
}
12+
13+
static inline bool MouseIsOverOldMessageLists()
14+
{
15+
const auto pMousePosition = &WWMouseClass::Instance->XY1;
16+
const auto pMessages = &MessageListClass::Instance;
17+
18+
if (TextLabelClass* pText = pMessages->MessageList)
19+
{
20+
const int textHeight = pMessages->Height;
21+
int height = pMessages->MessagePos.Y;
22+
23+
for ( ; pText; pText = static_cast<TextLabelClass*>(pText->GetNext()))
24+
height += textHeight;
25+
26+
if (pMousePosition->Y < (height + 2))
27+
return true;
28+
}
29+
30+
return false;
31+
}
32+
33+
static inline bool MouseIsOverNewMessageLists()
34+
{
35+
const auto pMousePosition = &WWMouseClass::Instance->XY1;
36+
37+
if (const auto pMessages = ScenarioExt::Global()->NewMessageList.get())
38+
{
39+
if (TextLabelClass* pText = pMessages->MessageList)
40+
{
41+
if (pMousePosition->Y >= pMessages->MessagePos.Y
42+
&& pMousePosition->X >= pMessages->MessagePos.X
43+
&& pMousePosition->X <= pMessages->MessagePos.X + pMessages->Width)
44+
{
45+
const int textHeight = pMessages->Height;
46+
int height = pMessages->MessagePos.Y;
47+
48+
for ( ; pText; pText = static_cast<TextLabelClass*>(pText->GetNext()))
49+
height += textHeight;
50+
51+
if (pMousePosition->Y < (height + 2))
52+
return true;
53+
}
54+
}
55+
}
56+
57+
return false;
58+
}
59+
60+
DEFINE_HOOK(0x69300B, ScrollClass_MouseUpdate_NewMessageListCheck, 0x6)
61+
{
62+
if (Phobos::Config::MessageApplyHoverState)
63+
MessageTemp::OnOldMessages = MouseIsOverOldMessageLists();
64+
65+
if (Phobos::Config::MessageDisplayInCenter)
66+
MessageTemp::OnNewMessages = MouseIsOverNewMessageLists();
67+
68+
return 0;
69+
}
70+
71+
DEFINE_HOOK(0x4F4583, GScreenClass_NewMessageListDraw, 0x6)
72+
{
73+
MessageTemp::NewMessageList = true;
74+
75+
if (const auto pList = ScenarioExt::Global()->NewMessageList.get())
76+
pList->Draw();
77+
78+
MessageTemp::NewMessageList = false;
79+
80+
return 0;
81+
}
82+
83+
DEFINE_HOOK(0x55DDA0, MainLoop_FrameStep_NewMessageListManage, 0x5)
84+
{
85+
enum { SkipGameCode = 0x55DDAA };
86+
87+
if (!Phobos::Config::MessageApplyHoverState || !MessageTemp::OnOldMessages)
88+
MessageListClass::Instance.Manage();
89+
90+
if (!MessageTemp::OnNewMessages)
91+
{
92+
if (const auto pList = ScenarioExt::Global()->NewMessageList.get())
93+
pList->Manage();
94+
}
95+
96+
return SkipGameCode;
97+
}
98+
99+
DEFINE_HOOK(0x6DE11D, TActionClass_Execute_AddMessageInCenter, 0x5)
100+
{
101+
enum { SkipGameCode = 0x6DE122 };
102+
103+
if (const auto pList = ScenarioExt::Global()->NewMessageList.get())
104+
R->ECX(pList);
105+
else // !Phobos::Config::MessageDisplayInCenter
106+
R->ECX(&MessageListClass::Instance);
107+
108+
return SkipGameCode;
109+
}
110+
111+
DEFINE_HOOK(0x4A8BCE, DisplayClass_Set_View_Dimensions, 0x5)
112+
{
113+
if (Phobos::Config::MessageDisplayInCenter)
114+
{
115+
const auto& pScenarioExt = ScenarioExt::Global();
116+
117+
if (!pScenarioExt->NewMessageList) // Load game
118+
pScenarioExt->NewMessageList = std::make_unique<MessageListClass>();
119+
120+
const auto& rect = DSurface::ViewBounds;
121+
const auto sideWidth = rect.Width / 6;
122+
const auto width = rect.Width - (sideWidth * 2);
123+
const auto pList = pScenarioExt->NewMessageList.get();
124+
125+
// Except for X and Y, they are all original values
126+
pList->Init((rect.X + sideWidth), (rect.Height - rect.Height / 8 - 120), 6, 98, 18, -1, -1, 0, 20, 98, width);
127+
pList->SetWidth(width);
128+
}
129+
130+
return 0;
131+
}
132+
133+
DEFINE_HOOK(0x684AD3, UnknownClass_sub_684620_InitMessageList, 0x5)
134+
{
135+
if (Phobos::Config::MessageDisplayInCenter)
136+
{
137+
const auto& pScenarioExt = ScenarioExt::Global();
138+
139+
if (!pScenarioExt->NewMessageList) // Start game
140+
pScenarioExt->NewMessageList = std::make_unique<MessageListClass>();
141+
142+
const auto& rect = DSurface::ViewBounds;
143+
const auto sideWidth = rect.Width / 6;
144+
const auto width = rect.Width - (sideWidth * 2);
145+
const auto pList = pScenarioExt->NewMessageList.get();
146+
147+
// Except for X and Y, they are all original values
148+
pList->Init((rect.X + sideWidth), (rect.Height - rect.Height / 8 - 120), 6, 98, 18, -1, -1, 0, 20, 98, width);
149+
}
150+
151+
return 0;
152+
}
153+
154+
DEFINE_HOOK(0x623A9F, DSurface_sub_623880_DrawBitFontStrings, 0x5)
155+
{
156+
if (!MessageTemp::NewMessageList)
157+
return 0;
158+
159+
enum { SkipGameCode = 0x623AAB };
160+
161+
GET(RectangleStruct* const, pRect, EAX);
162+
GET(DSurface* const, pSurface, ECX);
163+
GET(const int, height, EBP);
164+
165+
pRect->Height = height;
166+
auto black = ColorStruct { 0, 0, 0 };
167+
auto trans = (MessageTemp::OnNewMessages || ScenarioClass::Instance->UserInputLocked) ? 80 : 40;
168+
pSurface->FillRectTrans(pRect, &black, trans);
169+
170+
return SkipGameCode;
171+
}

src/Phobos.INI.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ bool Phobos::Config::ArtImageSwap = false;
5353
bool Phobos::Config::ShowPlacementPreview = false;
5454
bool Phobos::Config::EnableSelectBox = false;
5555
bool Phobos::Config::DigitalDisplay_Enable = false;
56+
bool Phobos::Config::MessageApplyHoverState = false;
57+
bool Phobos::Config::MessageDisplayInCenter = false;
5658
bool Phobos::Config::RealTimeTimers = false;
5759
bool Phobos::Config::RealTimeTimers_Adaptive = false;
5860
int Phobos::Config::CampaignDefaultGameSpeed = 2;
@@ -82,6 +84,8 @@ DEFINE_HOOK(0x5FACDF, OptionsClass_LoadSettings_LoadPhobosSettings, 0x5)
8284
Phobos::Config::ToolTipBlur = CCINIClass::INI_RA2MD.ReadBool(phobosSection, "ToolTipBlur", false);
8385
Phobos::Config::PrioritySelectionFiltering = CCINIClass::INI_RA2MD.ReadBool(phobosSection, "PrioritySelectionFiltering", true);
8486
Phobos::Config::ShowPlacementPreview = CCINIClass::INI_RA2MD.ReadBool(phobosSection, "ShowPlacementPreview", true);
87+
Phobos::Config::MessageApplyHoverState = CCINIClass::INI_RA2MD.ReadBool(phobosSection, "MessageApplyHoverState", false);
88+
Phobos::Config::MessageDisplayInCenter = CCINIClass::INI_RA2MD.ReadBool(phobosSection, "MessageDisplayInCenter", false);
8589
Phobos::Config::RealTimeTimers = CCINIClass::INI_RA2MD.ReadBool(phobosSection, "RealTimeTimers", false);
8690
Phobos::Config::RealTimeTimers_Adaptive = CCINIClass::INI_RA2MD.ReadBool(phobosSection, "RealTimeTimers.Adaptive", false);
8791
Phobos::Config::EnableSelectBox = CCINIClass::INI_RA2MD.ReadBool(phobosSection, "EnableSelectBox", false);

src/Phobos.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class Phobos
8787
static bool EnableBuildingPlacementPreview;
8888
static bool EnableSelectBox;
8989
static bool DigitalDisplay_Enable;
90+
static bool MessageApplyHoverState;
91+
static bool MessageDisplayInCenter;
9092
static bool RealTimeTimers;
9193
static bool RealTimeTimers_Adaptive;
9294
static int CampaignDefaultGameSpeed;

0 commit comments

Comments
 (0)