Rise
The Vieneo Province
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");
12  HUD.EnableKeyboardInput(true);
13  HUD.SetCallback(&InformationDialog::DialogCallback, this);
14 
15  normalinterlace = false;
16  tabs = 0;
17  icon = 13;
19  allowresize = false;
20  allowmove = true;
21  allowclose = false;
22  allowscroll = false;
23 
24  width = defaultwidth = 256;
25  height = defaultheight = 192;
26  windowlocation = windowdefaultlocation = D3DXVECTOR3(designedWidthC * 0.5f - 128.0f, designedHeightC * 0.5f - 96.0f, 0.0f);
27 }
28 
30 {
31  if (!activehelp) return;
32 
33  activeHelpText[0] = 0;
34 
36 }
37 
38 bool InformationDialog::PopUpHelp(short helpId, bool allowDismiss, bool isLearnMore)
39 {
40  if (gui->game->vphelp[helpId] && helpId != ActiveHelp::FuelReminder)
41  return false;
42 
44  {
45  activehelp = static_cast<unsigned char>(helpId);
46  canDismiss = allowDismiss;
47  learnMore = isLearnMore;
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].simulator)
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 
84 bool 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;
109  case ActiveHelp::Garage:
111  {
114  }
116  break;
124  break;
125  }
126 
127  if (helpId != ActiveHelp::FuelReminder)
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 
166  timeSinceLastDismiss = 0.0f;
167 
168  return true;
169 }
170 
172 {
173  activehelpqueue.clear();
174  activehelp = 0;
175  active = false;
176  timeSinceLastDismiss = 0.0f;
177 }
178 
179 void 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 
191 {
192  wcscpy_s(activeHelpText, 512, str);
193  UpdateMenu(-1);
194 }
195 
197 {
198  HUD.SetFont(0, L"DejaVu Sans Mono", static_cast<LONG>(14.0f * gui->game->displayscale), FW_NORMAL);
199  //HUD.SetFont(1, L"Verdana", static_cast<LONG>(16.0f * gui->game->displayscaley), FW_NORMAL);
200 
201  HUD.RemoveControl(GUI_REMINDME);
202  HUD.RemoveControl(GUI_UNDERSTOOD);
203 
204  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), 0, true);
205  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), 0, true);
206 
207  UpdateMenu(-1);
208 }
209 
211 {
212  logger->AddToCallStack("InformmationDialog::UpdateMenu");
213 
214  if (!HUD.GetButton(GUI_REMINDME))
215  return;
216 
218  {
219  HUD.GetButton(GUI_REMINDME)->SetText(gui->strings[L_BUTTON_CANCEL].c_str());
220  HUD.GetButton(GUI_UNDERSTOOD)->SetText(gui->strings[L_DIALOG_EXIT].c_str());
221  }
222  else if (learnMore)
223  {
224  HUD.GetButton(GUI_REMINDME)->SetText(gui->strings[L_BUTTON_REMINDME].c_str());
225  HUD.GetButton(GUI_UNDERSTOOD)->SetText(gui->strings[L_BUTTON_LEARNMORE].c_str());
226  }
227  else
228  {
229  HUD.GetButton(GUI_REMINDME)->SetText(gui->strings[L_BUTTON_REMINDME].c_str());
230  HUD.GetButton(GUI_UNDERSTOOD)->SetText(gui->strings[L_BUTTON_UNDERSTOOD].c_str());
231  }
232  if (canDismiss)
233  {
234  HUD.GetButton(GUI_REMINDME)->SetVisible(true);
235  HUD.GetButton(GUI_UNDERSTOOD)->SetVisible(true);
236  }
237  else
238  {
239  HUD.GetButton(GUI_REMINDME)->SetVisible(false);
240  HUD.GetButton(GUI_UNDERSTOOD)->SetVisible(false);
241  }
242 
243  HRESULT hr;
244 
245  logger->AddToCallStack("UpdateMenu Custom Wrapping");
246 
248  size_t startOfLine = 0;
249  size_t lastGoodSpaceIndex = 0;
250  size_t len = wcslen(activeHelpText);
251  for (size_t i = 0; i < (len - startOfLine); i++)
252  {
253  size_t i1 = (len - startOfLine - 1);
254  try
255  {
256  // taking substring from startOfLine for X characters
257  WCHAR tempStr[512];
258  wcscpy_s(tempStr, 512, &activeHelpText[startOfLine]);
259  // truncate
260  tempStr[i + 1] = 0;
261  // render and calculate
262  RECT rect = RECT();
263  try
264  {
265  V(gui->g_pChatFont->DrawTextW(gui->g_pTextSprite, tempStr, -1, &rect, DT_CALCRECT, 0xFFFFFFFF));
266  }
267  catch (...)
268  {
269  // apparently we get an exception trying to calculate "\n "?
270  }
271  // evaluate
272  if (rect.right < (width - 30) && i != i1)
273  {
274  if (tempStr[i] == L' ' || tempStr[i] == L'!' || tempStr[i] == L'。' || tempStr[i] == L',')
275  lastGoodSpaceIndex = i;
276  }
277  else
278  {
279  // back up to lastGoodSpaceIndex and push
280  if (lastGoodSpaceIndex != 0 && i != i1)
281  {
282  if (tempStr[lastGoodSpaceIndex] == L' ')
283  tempStr[lastGoodSpaceIndex] = 0;
284  else
285  tempStr[lastGoodSpaceIndex + 1] = 0;
286  }
287  wcscat_s(activeHelpTextFormatted, 512, tempStr);
288  if (i == i1)
289  break;
290  wcscat_s(activeHelpTextFormatted, 512, L" \n ");
291  if (lastGoodSpaceIndex != 0)
292  startOfLine += lastGoodSpaceIndex + 1;
293  else
294  startOfLine += wcslen(tempStr) + 1;
295  i = 0;
296  lastGoodSpaceIndex = 0;
297  }
298  }
299  catch (...)
300  {
301  char msg[999];
302  sprintf_s(msg, 999, "Exception startOfLine %i lastGoodSpaceIndex %i len %i i %i i1 %i lang %i help %i", startOfLine, lastGoodSpaceIndex, len, i, i1, gui->game->config.language, activehelp);
303  logger->Log(msg, Logger::Debug);
304  }
305  }
306 
307  logger->AddToCallStack("InformmationDialog::UpdateMenu DONE");
308 }
309 
311 {
312  return activehelp == helpId;
313 }
314 
315 void CALLBACK InformationDialog::DialogCallback(UINT, int nControlID, CDXUTControl*, void* pUserContext)
316 {
317  InformationDialog* informationDialog = static_cast<InformationDialog*>(pUserContext);
318  logger->AddToCallStack("InformationDialog::DialogCallback");
319 
320  informationDialog->DismissHelp(informationDialog->activehelp, nControlID);
321 }
322 
323 void InformationDialog::Draw(D3DXVECTOR3* tracked)
324 {
325  logger->AddToCallStack("InformmationDialog::Draw");
326 
327  if (!activeHelpTextFormatted[0])
328  return;
329 
330  RECT rect;
331  rect.top = static_cast<LONG>(tracked->y) + 15;
332  rect.left = static_cast<LONG>(tracked->x) + 15;
333  rect.right = rect.left + width - 30;
334  rect.bottom = rect.top + height - 30;
335  gui->g_pChatFont->DrawTextW(gui->g_pTextSprite, activeHelpTextFormatted, -1, &rect, DT_CENTER, 0xFFFFFFFF);
336 }
static void CALLBACK DialogCallback(UINT nEvent, int nControlID, CDXUTControl *pControl, void *pUserContext)
bool DismissHelp(int helpId, int nControlID=GUI_UNDERSTOOD)
#define designedHeightC
Definition: GameClass.h:23
void SetHelpText(WCHAR *str)
Networking * networking
Definition: gui.h:855
Config config
Definition: GameClass.h:102
unsigned char language
Definition: config.h:12
void SendToServer(void *pData, DWORD dwSize, bool bGuaranteed, PacketOrdering order=ORDERING_NONE) const
Definition: Networking.cpp:59
#define designedWidthC
Definition: GameClass.h:22
GameClass * game
Definition: gui.h:857
void UpdateMenu(short tab) override
D3DXVECTOR3 windowlocation
Definition: DialogBase.h:59
s_network_objects playerships[MAX_SCAN]
Definition: globals.cpp:174
short tabs
Definition: DialogBase.h:62
bool usesHUD
Definition: DialogBase.h:56
static void BringToFront(short t)
short defaultwidth
Definition: DialogBase.h:51
CDXUTDialogResourceManager g_DialogResourceManager
Definition: gui.h:752
void PopUpDialog()
WCHAR activeHelpTextFormatted[512]
#define dismissAfterC
bool vphelp[vphelpC]
Definition: GameClass.h:103
WCHAR activeHelpText[512]
short text
Definition: DialogBase.h:69
static DialogBase * dialogs[D_ENUMERATION]
Definition: DialogBase.h:39
bool IsAdmin
Definition: gui.h:777
WCHAR msgbartext[HELP_SIZE]
Definition: DialogBase.h:82
void ActiveTab() override
Networking * networking
Definition: GameClass.h:107
bool PopUpHelp(short helpId, bool allowDismiss=true, bool isLearnMore=false)
char msgbarcolor
Definition: DialogBase.h:81
static Logger * logger
Definition: DialogBase.h:41
bool allowclose
Definition: DialogBase.h:45
short defaultheight
Definition: DialogBase.h:51
short width
Definition: DialogBase.h:60
std::vector< HelpContainer > activehelpqueue
bool FlightFreeze
Definition: Bus.h:374
bool allowscroll
Definition: DialogBase.h:45
void FrameMove(float fElapsedTime)
bool active
Definition: DialogBase.h:71
void Log(const char *msg, Level level=Info, int errorCode=0)
Definition: Logger.cpp:11
CDXUTDialog HUD
Definition: DialogBase.h:98
short icon
Definition: DialogBase.h:53
static HMI * gui
Definition: DialogBase.h:40
bool allowresize
Definition: DialogBase.h:45
void Draw(D3DXVECTOR3 *tracked)
ActiveHelp
Definition: ActiveHelp.h:3
ID3DXSprite * g_pTextSprite
Definition: gui.h:726
short height
Definition: DialogBase.h:60
ID3DXFont * g_pChatFont
Definition: gui.h:728
#define HELP_SIZE
Definition: gui.h:17
float displayscale
Definition: GameClass.h:128
D3DXVECTOR3 windowdefaultlocation
Definition: DialogBase.h:52
bool normalinterlace
Definition: DialogBase.h:54
bool allowmove
Definition: DialogBase.h:45
std::wstring strings[L_ENUMERATION]
Definition: gui.h:749
void AddToCallStack(const char *msg)
Definition: Logger.cpp:86
Bus * bus
Definition: GameClass.h:112
void RequestVerbiage(int helpId) const
Definition: Networking.cpp:168
bool IsActive(ActiveHelp helpId) const