Rise
The Vieneo Province
Loading...
Searching...
No Matches
InformationDialog.cpp
Go to the documentation of this file.
1#include "InformationDialog.h"
2
3#include "../GameClass.h"
4
5#define dismissAfterC 2.5f
6
8{
9 logger->AddToCallStack("InformationDialog::ctor");
10 usesHUD = true;
11 HUD.Init(&gui->g_DialogResourceManager, true, L"Textures\\GUI\\dxutcontrols.png");
13
14 normalinterlace = false;
15 tabs = 0;
16 icon = 13;
18 allowresize = false;
19 allowmove = true;
20 allowclose = false;
21 allowscroll = false;
22
23 width = defaultwidth = 256;
24 height = defaultheight = 192;
26}
27
36
37bool InformationDialog::PopUpHelp(short helpId, bool allowDismiss, bool isLearnMore)
38{
39 if (gui->game->vphelp[helpId] && helpId != ActiveHelp::FuelReminder && helpId != ActiveHelp::EnteringHangar)
40 return false;
41
43 {
44 activehelp = static_cast<unsigned char>(helpId);
45 canDismiss = allowDismiss;
46 learnMore = isLearnMore;
47 if (helpId != ActiveHelp::EnteringHangar)
49
50 if (gui->IsAdmin)
51 {
52 swprintf_s(msgbartext, HELP_SIZE, L"Verbiage Item %i", helpId);
53 msgbarcolor = 0; // normal
54 }
55
56 active = true;
57 UpdateMenu(-1);
59 if (playerships[0].isSimulator)
60 gui->game->bus->FlightFreeze = true;
61 }
62 else
63 {
64 if (activehelp && activehelp == static_cast<unsigned char>(helpId))
65 return true;
66
67 // queue it up if it isn't already queued
68 for (size_t i = 0; i < activehelpqueue.size(); i++)
69 {
70 if (activehelpqueue.at(i).helpId == helpId)
71 return true;
72 }
73
74 HelpContainer helpContainer;
75 helpContainer.helpId = helpId;
76 helpContainer.canDismiss = allowDismiss;
77 helpContainer.learnMore = isLearnMore;
78 activehelpqueue.emplace_back(helpContainer);
79 }
80
81 return true;
82}
83
84bool InformationDialog::DismissHelp(int helpId, int nControlID)
85{
86 if (helpId != activehelp)
87 {
88 // added this 3/17/2021 because he has the Manifest up on the MFD but TaxiService55 was queued but not quite active yet
89 for (size_t i = 0; i < activehelpqueue.size(); i++)
90 {
91 if (activehelpqueue.at(i).helpId == helpId)
92 {
93 activehelpqueue.erase(activehelpqueue.begin() + i);
94 return true;
95 }
96 }
97 return false;
98 }
99
100 if (nControlID == GUI_UNDERSTOOD)
101 {
102 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
103 switch (helpId)
104 {
106 logger->Log("Confirmed exit through Fuel Reminder in Information Dialog");
107 PostQuitMessage(0);
108 break;
111 {
114 }
116 break;
124 break;
125 }
126
127 if (helpId != ActiveHelp::FuelReminder && helpId != ActiveHelp::EnteringHangar)
128 {
129 if (!gui->game->vphelp[activehelp]) // not seen
130 {
131 gui->game->vphelp[activehelp] = true;
132 SClientPacket outpacket = SClientPacket();
133 // 41=HelpVerbiageControl, x=helpId, y=(0=remindme,1=understood,2=reset,3=disable,4=import), z=, w=
134 outpacket.type = 41;
135 outpacket.f_x = static_cast<float>(activehelp);
136 outpacket.f_y = 1.0f;
137 outpacket.f_z = 0.0f;
138 outpacket.f_w = 0.0f;
139 gui->game->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
140 }
141 }
142 }
143 else if (nControlID == GUI_REMINDME)
144 {
145 SClientPacket outpacket = SClientPacket();
146 // 41=HelpVerbiageControl, x=helpId, y=(0=remindme,1=understood,2=reset,3=disable,4=import), z=, w=
147 outpacket.type = 41;
148 outpacket.f_x = static_cast<float>(activehelp);
149 outpacket.f_y = 0.0f;
150 outpacket.f_z = 0.0f;
151 outpacket.f_w = 0.0f;
152 gui->game->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
153 }
154
156 {
160 }
161
162 activehelp = 0;
163
164 active = false;
165
167
168 return true;
169}
170
172{
173 activehelpqueue.clear();
174 activehelp = 0;
175 active = false;
177}
178
179void InformationDialog::FrameMove(float fElapsedTime)
180{
181 if (!activehelp)
182 timeSinceLastDismiss += fElapsedTime;
184 {
185 PopUpHelp(activehelpqueue.at(0).helpId, activehelpqueue.at(0).canDismiss, activehelpqueue.at(0).learnMore);
186 activehelpqueue.erase(activehelpqueue.begin());
187 }
188}
189
190void InformationDialog::SetHelpText(WCHAR* str, int id)
191{
192 wcscpy_s(activeHelpText, 512, str);
194 PopUpHelp(id, false, false);
195 UpdateMenu(-1);
196}
197
199{
200 HUD.SetFont(0, L"DejaVu Sans Mono", static_cast<LONG>(14.0f * gui->game->displayscale), FW_NORMAL);
201
202 //DialogBase::ActiveTab();
203
206
207 HUD.AddButton(GUI_REMINDME, L"", static_cast<int>(19.0f * gui->game->displayscale), static_cast<int>(148.0f * gui->game->displayscale), static_cast<int>((144.0f - 38.0f) * gui->game->displayscale), static_cast<int>((62.0f - 39.0f) * gui->game->displayscale));
208 HUD.AddButton(GUI_UNDERSTOOD, L"", static_cast<int>(132.0f * gui->game->displayscale), static_cast<int>(148.0f * gui->game->displayscale), static_cast<int>((144.0f - 38.0f) * gui->game->displayscale), static_cast<int>((62.0f - 39.0f) * gui->game->displayscale));
209
210 UpdateMenu(-1);
211}
212
214{
215 logger->AddToCallStack("InformationDialog::UpdateMenu");
216
218 return;
219
221 {
224 }
225 else if (learnMore)
226 {
229 }
230 else
231 {
234 }
235 if (canDismiss)
236 {
239 }
240 else
241 {
244 }
245
246 HRESULT hr;
247
248 logger->AddToCallStack("UpdateMenu Custom Wrapping");
249
251 size_t startOfLine = 0;
252 size_t lastGoodSpaceIndex = 0;
253 size_t len = wcslen(activeHelpText);
254 for (size_t i = 0; i < (len - startOfLine); i++)
255 {
256 size_t i1 = (len - startOfLine - 1);
257 try
258 {
259 // taking substring from startOfLine for X characters
260 WCHAR tempStr[512];
261 wcscpy_s(tempStr, 512, &activeHelpText[startOfLine]);
262 // truncate
263 tempStr[i + 1] = 0;
264 // render and calculate
265 RECT rect = RECT();
266 try
267 {
268 V(gui->g_pChatFont->DrawTextW(gui->g_pTextSprite, tempStr, -1, &rect, DT_CALCRECT, 0xFFFFFFFF));
269 }
270 catch (...)
271 {
272 // apparently we get an exception trying to calculate "\n "?
273 }
274 // evaluate
275 if (rect.right < (width - 30) && i != i1)
276 {
277 // @ref https://chatgpt.com/g/g-p-68331f298f88819189596309160f7056-rise-the-vieneo-province/c/69712c98-b0a4-8327-a6dc-50afda9e2128
278 if (tempStr[i] == L' ' ||
279 tempStr[i] == L'\uFF01' || // !
280 tempStr[i] == L'\u3002' || // 。
281 tempStr[i] == L'\uFF0C') // ,
282 {
283 lastGoodSpaceIndex = i;
284 }
285 }
286 else
287 {
288 // back up to lastGoodSpaceIndex and push
289 if (lastGoodSpaceIndex != 0 && i != i1)
290 {
291 if (tempStr[lastGoodSpaceIndex] == L' ')
292 tempStr[lastGoodSpaceIndex] = 0;
293 else
294 tempStr[lastGoodSpaceIndex + 1] = 0;
295 }
296 wcscat_s(activeHelpTextFormatted, 512, tempStr);
297 if (i == i1)
298 break;
299 wcscat_s(activeHelpTextFormatted, 512, L" \n ");
300 if (lastGoodSpaceIndex != 0)
301 startOfLine += lastGoodSpaceIndex + 1;
302 else
303 startOfLine += wcslen(tempStr) + 1;
304 i = 0;
305 lastGoodSpaceIndex = 0;
306 }
307 }
308 catch (...)
309 {
310 char msg[999];
311 sprintf_s(msg, sizeof msg, "Exception startOfLine %zu lastGoodSpaceIndex %zu len %zu i %zu i1 %zu lang %i help %i", startOfLine, lastGoodSpaceIndex, len, i, i1, gui->game->config.language, activehelp);
312 logger->Log(msg, Logger::Debug);
313 }
314 }
315
316 logger->AddToCallStack("InformationDialog::UpdateMenu DONE");
317}
318
320{
321 return activehelp == helpId;
322}
323
324void CALLBACK InformationDialog::DialogCallback(UINT, int nControlID, RiseControl*, void* pUserContext)
325{
326 InformationDialog* informationDialog = static_cast<InformationDialog*>(pUserContext);
327 logger->AddToCallStack("InformationDialog::DialogCallback");
328
329 informationDialog->DismissHelp(informationDialog->activehelp, nControlID);
330}
331
333{
334 logger->AddToCallStack("InformationDialog::Draw");
335
337 return;
338
339 RECT rect;
340 rect.top = static_cast<LONG>(tracked->y) + 15;
341 rect.left = static_cast<LONG>(tracked->x) + 15;
342 rect.right = rect.left + width - 30;
343 rect.bottom = rect.top + height - 30;
344 gui->g_pChatFont->DrawTextW(gui->g_pTextSprite, activeHelpTextFormatted, -1, &rect, DT_CENTER, 0xFFFFFFFF);
345}
ActiveHelp
Definition ActiveHelp.h:4
@ ScannerPage
Definition ActiveHelp.h:431
@ TaxiService43
Definition ActiveHelp.h:396
@ ContactList2
Definition ActiveHelp.h:428
@ WaypointManager
Definition ActiveHelp.h:397
@ ContactList1
Definition ActiveHelp.h:427
@ Garage
Definition ActiveHelp.h:363
@ VehicleProximity
Definition ActiveHelp.h:395
@ Intermedia2
Definition ActiveHelp.h:415
@ TaxiService63
Definition ActiveHelp.h:416
@ Intermedia1
Definition ActiveHelp.h:356
@ EnteringHangar
Definition ActiveHelp.h:443
@ LockPickSet
Definition ActiveHelp.h:432
@ HowToScan
Definition ActiveHelp.h:430
@ FuelReminder
Definition ActiveHelp.h:362
@ VehicleTransfer
Definition ActiveHelp.h:429
#define V(expression)
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
@ D_INFORMATION
Definition DialogBase.h:10
@ D_WAYPOINTMANAGER
Definition DialogBase.h:6
@ D_INTERMEDIA
Definition DialogBase.h:9
#define designedHeightC
Definition GameClass.h:24
#define designedWidthC
Definition GameClass.h:23
#define dismissAfterC
bool FlightFreeze
Definition Bus.h:474
unsigned char language
Definition config.h:16
static HMI * gui
Definition DialogBase.h:42
short icon
Definition DialogBase.h:55
bool active
Definition DialogBase.h:73
bool allowmove
Definition DialogBase.h:47
short text
Definition DialogBase.h:71
static Logger * logger
Definition DialogBase.h:43
short tabs
Definition DialogBase.h:64
static void BringToFront(short t)
short defaultwidth
Definition DialogBase.h:53
static DialogBase * dialogs[D_ENUMERATION]
Definition DialogBase.h:41
short height
Definition DialogBase.h:62
bool allowclose
Definition DialogBase.h:47
WCHAR msgbartext[HELP_SIZE]
Definition DialogBase.h:84
short width
Definition DialogBase.h:62
RiseMath::Vector3 windowdefaultlocation
Definition DialogBase.h:54
RiseMath::Vector3 windowlocation
Definition DialogBase.h:61
void PopUpDialog()
RiseDialog HUD
Definition DialogBase.h:100
bool usesHUD
Definition DialogBase.h:58
bool allowresize
Definition DialogBase.h:47
bool normalinterlace
Definition DialogBase.h:56
bool allowscroll
Definition DialogBase.h:47
DialogBase(short id)
char msgbarcolor
Definition DialogBase.h:83
short defaultheight
Definition DialogBase.h:53
std::unique_ptr< Bus > bus
Definition GameClass.h:108
Config config
Definition GameClass.h:100
std::unique_ptr< Networking > networking
Definition GameClass.h:103
bool vphelp[vphelpC]
Definition GameClass.h:101
float displayscale
Definition GameClass.h:130
GameClass * game
Definition gui.h:1213
Rendering::RenderFont * g_pChatFont
Definition gui.h:1053
std::wstring strings[L_ENUMERATION]
Definition gui.h:1076
RiseDialogResourceManager g_DialogResourceManager
Definition gui.h:1079
Networking * networking
Definition gui.h:1211
bool IsAdmin
Definition gui.h:1108
Rendering::RenderSprite * g_pTextSprite
Definition gui.h:1051
WCHAR activeHelpTextFormatted[512]
bool DismissHelp(int helpId, int nControlID=GUI_UNDERSTOOD)
void FrameMove(float fElapsedTime)
void SetHelpText(WCHAR *str, int id)
bool IsActive(ActiveHelp helpId) const
void UpdateMenu(short tab) override
void ActiveTab() override
void Draw(RiseMath::Vector3 *tracked)
bool PopUpHelp(short helpId, bool allowDismiss=true, bool isLearnMore=false)
static void CALLBACK DialogCallback(UINT nEvent, int nControlID, RiseControl *pControl, void *pUserContext)
std::vector< HelpContainer > activehelpqueue
void Log(const char *msg, Level level=Info, int errorCode=0)
Definition Logger.cpp:283
void AddToCallStack(const char *msg)
Definition Logger.cpp:355
@ Debug
Definition Logger.h:27
void SendToServer(void *pData, DWORD dwSize, bool bGuaranteed, PacketOrdering order=ORDERING_NONE) const
void RequestVerbiage(int helpId) const
INT DrawTextW(RenderSprite *sprite, const wchar_t *text, INT count, RECT *rectangle, DWORD flags, PackedColor color)
virtual void SetVisible(bool bVisible)
Definition Controls.h:583
void RemoveControl(int ID)
Definition Controls.cpp:226
void Init(RiseDialogResourceManager *pManager, bool bRegisterDialog=true)
Definition Controls.cpp:176
RiseButton * GetButton(int ID)
Definition Controls.h:176
HRESULT SetFont(UINT index, LPCWSTR strFaceName, LONG height, LONG weight)
Definition Controls.cpp:709
void SetCallback(UICallback pCallback, void *pUserContext=NULL)
Definition Controls.cpp:212
HRESULT AddButton(int ID, LPCWSTR strText, int x, int y, int width, int height, UINT nHotkey=0, bool bIsDefault=false, RiseButton **ppCreated=NULL)
HRESULT SetText(LPCWSTR strText)
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
@ L_BUTTON_LEARNMORE
Definition gui.h:165
@ L_DIALOG_EXIT
Definition gui.h:80
@ L_DIALOG_INFORMATION
Definition gui.h:82
@ L_BUTTON_CANCEL
Definition gui.h:164
@ L_BUTTON_REMINDME
Definition gui.h:163
@ L_BUTTON_UNDERSTOOD
Definition gui.h:162
@ GUI_UNDERSTOOD
Definition gui.h:983
@ GUI_REMINDME
Definition gui.h:984
#define HELP_SIZE
Definition gui.h:21
unsigned char type