Rise
The Vieneo Province
Loading...
Searching...
No Matches
WaypointDialog.cpp
Go to the documentation of this file.
1#include "WaypointDialog.h"
2
3#include <clocale>
4
5#include "../MathUtilities.h"
7#include "InformationDialog.h"
8
10{
11 logger->AddToCallStack("WaypointDialog::ctor");
12 active = false;
14 defaultwidth = 767;
15 defaultheight = 85;
16 tabs = 1;
17 tabusedefaultlang[0] = 0;
18 tabstr[0][0] = 0;
19
20 actions = 11;
32 actionenabled[0] = false;
33 actionenabled[1] = true;
34 actionenabled[2] = true;
35 actionenabled[3] = false;
36 actionenabled[4] = true;
37 actionenabled[5] = true;
38 actionenabled[6] = true;
39 actionenabled[7] = true;
40 actionenabled[8] = true;
41 actionenabled[9] = true;
42 actionenabled[10] = true;
43
44 showfields = true;
45 fields = 5;
46 fieldtype[0] = FIELD_ICON; // icon
47 fieldwidth[0] = 25; // pixels
48 // fieldcontent[0]=1; // unused
49 fieldtype[1] = FIELD_VARTEXT; // variable width text
50 fieldwidth[1] = gui->FONT_WIDTH * 63; // 64 UTF-16 code units including the terminator
52 sortfield = 1; // description
53 sortdirection = 1; // ascending?
54 fieldtype[2] = FIELD_VARTEXT; // variable width text
55 fieldwidth[2] = gui->FONT_WIDTH * 18; // n 00.000 w 000.000
57 fieldsortable[2] = false;
58 fieldtype[3] = FIELD_VARTEXT; // variable width text
59 fieldwidth[3] = gui->FONT_WIDTH * 10; // 999.999 km
61 fieldtype[4] = FIELD_ICON; // icon
62 fieldwidth[4] = 25; // pixels
63
64 usesHUD = true;
65 HUD.Init(&gui->g_DialogResourceManager, true, L"Textures\\GUI\\dxutcontrols.png");
67 HUD.AddEditBox(IDC_FIELDEDIT, L"", 1, 1, 1, 1, false);
69 HUD.AddEditBox(IDC_TABEDIT, L"", 1, 1, 1, 1, false);
72
73 icon = 7;
75
76 //linedsp is calculated from height
77 //linetot is equal to waypoints->WPtargetS
78
79 ptrBus = gui->game->bus.get();
82 linetop = 0;
83 lineact = 0;
84}
85
86void CALLBACK WaypointDialog::DialogCallback(UINT nEvent, int nControlID, RiseControl* pControl, void* pUserContext)
87{
88 WaypointDialog* wpd = static_cast<WaypointDialog*>(pUserContext);
89 logger->AddToCallStack("WaypointDialog::DialogCallback");
90
91 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
92 switch (nControlID)
93 {
94 case IDC_FIELDEDIT: // when I submit the waypoint
95 {
96 if (nEvent == EVENT_EDITBOX_STRING)
97 {
98 long field = wpd->editfield;
99 if (wpd->linecursel < 0 || wpd->linecursel >= static_cast<int>(wpd->filteredWaypoints.size()))
100 {
101 char msg[199];
102 sprintf_s(msg, sizeof msg, "Editing waypoint that doesn't exist in collection: %i (%zu) %i", wpd->linecursel, wpd->filteredWaypoints.size(), field);
105 logger->Log("IDC_FIELDEDIT was visible!", Logger::Level::Debug);
106 else
107 logger->Log("IDC_FIELDEDIT was NOT visible!", Logger::Level::Debug);
108 wpd->linecursel = 0;
109 field = 0;
110 }
111
112 if (field == 1) // description
113 {
114 WaypointProtocol::SetText(wpd->filteredWaypoints.at(wpd->linecursel), dynamic_cast<RiseEditBox*>(pControl)->GetText());
116 if (wpd->linecursel == 0 && wpd->activetab == 0) // temporary
117 {
118 wpd->ptrWaypoints->Upload(wpd->filteredWaypoints.at(0));
119 wpd->ptrWaypoints->Delete(0);
120 }
121 else
122 {
123 wpd->ptrWaypoints->Upload(wpd->filteredWaypoints.at(wpd->linecursel));
124 }
125 }
126 else if (field == 2) // latlng
127 {
128 char ns[3], ew[4];
129 float nsdeg, ewdeg;
130 char input[99];
131 sprintf_s(input, 99, "%S", dynamic_cast<RiseEditBox*>(pControl)->GetText());
132 int count = sscanf_s(input, "%[NnSs ]%f%[EeWw ]%f", ns, 3, &nsdeg, ew, 4, &ewdeg);
133 if (count == 4)
134 {
135 float lattemp = RiseMath::ToRadian(nsdeg);
136 float lngtemp = RiseMath::ToRadian(ewdeg);
137 bool letfailed = true;
138 if (ns[0] == 'N' || ns[0] == 'n')
139 {
140 nsdeg = -nsdeg;
141 letfailed = false;
142 }
143 else if (ns[0] == 'S' || ns[0] == 's')
144 {
145 lattemp = -lattemp;
146 letfailed = false;
147 }
148
149 if (ew[0] == ' ')
150 ew[0] = ew[1];
151 if (ew[0] == 'E' || ew[0] == 'e')
152 {
153 letfailed = false;
154 }
155 else if (ew[0] == 'W' || ew[0] == 'w')
156 {
157 lngtemp = -lngtemp;
158 ewdeg = -ewdeg;
159 letfailed = false;
160 }
161 if (fabsf(nsdeg) > 90.0f || fabsf(ewdeg) > 180.0f)
162 letfailed = true;
163
164 if (!letfailed)
165 {
166 RiseMath::Vector3 result;
167 result.y = cosf(-lngtemp) * cosf(lattemp);
168 result.x = sinf(-lngtemp) * cosf(lattemp);
169 result.z = sinf(lattemp);
170 RiseMath::Vec3Normalize(&result, &result);
171 RiseMath::Vec3Scale(&result, &result, -radiusC);
172
173 wpd->filteredWaypoints.at(wpd->linecursel).location = result;
174 wpd->filteredWaypoints.at(wpd->linecursel).latlng.x = nsdeg;
175 wpd->filteredWaypoints.at(wpd->linecursel).latlng.y = ewdeg;
176 wpd->filteredWaypoints.at(wpd->linecursel).source = 5; // keyed lat long
177 wpd->filteredWaypoints.at(wpd->linecursel).protectionLevel = 5; // private
178
179 // @todo aren't we supposed to upload this to the server!? can we edit stuff other than waypoint 0?
181 }
182 }
183 else
184 {
185 int tcpu, tcpv;
186 int index = 0;
187 if (strlen(input) > 3 && (input[2] == 'n' || input[2] == 'N')) index = 3;
188 if (strlen(input) > 4 && input[3] == ' ') index = 4;
189 count = sscanf_s(&input[index], "%4d%4d", &tcpu, &tcpv);
190 if (count == 2)
191 {
192 RiseMath::Vector3 planar = wpd->ptrViewscreen->CalculatePlanar(tcpu - 3038, tcpv - 2038);
193 const RiseMath::Vector2 latLng = CalculateLatLng(planar);
194 RiseMath::Vec3Scale(&planar, &planar, radiusC);
195
196 wpd->filteredWaypoints.at(wpd->linecursel).location = planar;
197 wpd->filteredWaypoints.at(wpd->linecursel).latlng.x = latLng.x;
198 wpd->filteredWaypoints.at(wpd->linecursel).latlng.y = latLng.y;
199 wpd->filteredWaypoints.at(wpd->linecursel).source = 6; // keyed APN
200
201 // @todo aren't we supposed to upload this to the server!? can we edit stuff other than waypoint 0?
203 }
204 }
205 }
206
207 wpd->ClearEdit();
209 wpd->UpdateMenu(-1);
210 }
211 else if (nEvent == EVENT_EDITBOX_CANCEL)
212 {
213 wpd->ClearEdit();
214 }
215 }
216 break;
217 case IDC_TABEDIT:
218 {
219 if ((((RiseEditBox*)pControl)->GetTextLength()) >= (MAX_TAB_CHARS - 4 - 1))
220 {
221 WCHAR str[MAX_TAB_CHARS - 4];
222 swprintf_s(str, MAX_TAB_CHARS - 4, L"%.*s", MAX_TAB_CHARS - 4 - 1, ((RiseEditBox*)pControl)->GetText());
223 ((RiseEditBox*)pControl)->SetText(str, false);
224 }
225 if (nEvent == EVENT_EDITBOX_STRING)
226 {
227 wcscpy_s(wpd->tabstr[wpd->edittab], MAX_TAB_CHARS - 4, ((RiseEditBox*)pControl)->GetText());
228 _wcsupr_s(wpd->tabstr[wpd->edittab], MAX_TAB_CHARS - 4);
229
230 wpd->ClearEdit();
231 wpd->UpdateMenu(-1); // content changed
232 }
233 }
234 break;
235 }
236}
237
239{
240 logger->AddToCallStack("WaypointDialog::UpdateMenu");
241
242 if (!active)
243 return;
244
245 // Server replies arrive after the drop. Rebuild the cached group once they do,
246 // retaining the selected waypoint and leaving in-progress edits/drags alone.
248 {
249 const int selectedId = linecursel >= 0 && linecursel < static_cast<long>(filteredWaypoints.size())
250 ? filteredWaypoints.at(linecursel).id : -1;
251 const int activeId = ptrBus->WPtargetC >= 0 && ptrBus->WPtargetC < static_cast<int>(ptrBus->waypoint.size())
252 ? ptrBus->waypoint.at(ptrBus->WPtargetC).id : -1;
253
255 linecursel = lineact = -1;
256 for (size_t i = 0; i < filteredWaypoints.size(); ++i)
257 {
258 if (filteredWaypoints.at(i).id == selectedId)
259 linecursel = static_cast<long>(i);
260 if (filteredWaypoints.at(i).id == activeId)
261 lineact = static_cast<long>(i);
262 }
263 waypointsDirty = false;
264 }
265
266 const long oldlinecursel = linecursel;
267 Sort();
268 if (oldlinecursel != linecursel &&
270 linetop = linecursel - linedsp; // center it
271
272 linetot = filteredWaypoints.size();
273
274 // 17-4<(18-1) = 13<17 (17-(18-1)=0
275 if ((linetot - linetop) < linedsp) // 8-3 is 5 OK, 8-4 is 4 NO, needs to be 5
276 linetop = linetot - static_cast<int>(linedsp);
277 if (linetop < 0)
278 linetop = 0;
279
280 if (editline != -1 && (editline >= (linedsp + linetop) || editline < linetop))
281 ClearEdit();
282
283 if (linecursel > -1) // has one selected
284 {
285 if (lineact == linecursel)
286 {
287 actiontoggle[0] = true; // depressed activate button
288 actionenabled[0] = false; // disabled activate button
289 }
290 else
291 {
292 actiontoggle[0] = false;
293 actionenabled[0] = true; // enable activate button
294 }
295
297 if (playerships[0].reference == REF_ONGROUND && linecursel == 0 && activetab == 0)
298 actionenabled[1] = true; // mark
299 else
300 actionenabled[1] = false;
301
302 // delete
303 actionenabled[2] = linecursel > 0 || activetab != 0; // not the temporary waypoint
304
305 if (linecursel == 0 && activetab == 0) // temporary waypoint
306 {
307 for (auto i = 5; i < 11; i++)
308 {
309 actiontoggle[i] = false;
310 actionenabled[i] = false;
311 }
312 }
313 else // all other waypoints
314 {
315 for (auto i = 5; i < 11; i++)
316 {
317 const unsigned char actionLevel = i - 5; // 0-5
318 const unsigned char waypointLevel = filteredWaypoints.at(linecursel).protectionLevel;
319 const unsigned char type = filteredWaypoints.at(linecursel).type;
320 actiontoggle[i] = (actionLevel == waypointLevel);
321
322 // only allow one down from current but any above but not current ... don't let them share airborne fixes or FAF or MM or TDZ since they buy those
323 actionenabled[i] = (actionLevel >= waypointLevel - 1) && actionLevel != waypointLevel && type == 0;
324 }
325
326 if (filteredWaypoints.at(linecursel).uniqueid == 451) // Deois Zana Zoom (Taxi Fares)
327 {
330 else if (lineact == linecursel)
331 {
333 {
336 }
337 }
338 }
339 else if (filteredWaypoints.at(linecursel).uniqueid == 716) // Deois Airport Taxi Stand
341 }
342 }
343 else
344 {
345 actionenabled[0] = false; // activate
346 actiontoggle[0] = false;
347 actionenabled[1] = false; // mark
348 actionenabled[2] = false; // delete
349
350 for (int i = 5; i < 11; i++)
351 {
352 actiontoggle[i] = false;
353 actionenabled[i] = false;
354 }
355 }
356
358
359 if (tabs < MAX_TAB)
360 actionenabled[4] = true; // add folder
361 else
362 actionenabled[4] = false;
363
364 for (long t = 0; t < linedsp; t++)
365 {
366 if ((linetop + t) >= linetot)
367 {
368 fieldline[t][0][0] = 0;
369 wcscpy_s(fieldline[t][1], HELP_SIZE, L"");
370 wcscpy_s(fieldline[t][2], HELP_SIZE, L"");
371 wcscpy_s(fieldline[t][3], HELP_SIZE, L"");
372 wcscpy_s(fieldline[t][4], HELP_SIZE, L"");
373 }
374 else
375 {
376 if ((linetop + t) < 0 || (linetop + t) >= static_cast<long>(filteredWaypoints.size()))
377 throw std::exception("Trying to update menu with a waypoint that doesn't exist in collection!");
378 if ((linetop + t) == 0 && activetab == 0) // temporary waypoint
379 {
380 if (filteredWaypoints.at(linetop + t).location.x != 0.0f)
381 swprintf_s(fieldline[t][1], HELP_SIZE, L"Unsaved waypoint, click here to rename and save!");
382 else
383 swprintf_s(fieldline[t][1], HELP_SIZE, L"Unused slot for temporary waypoints...");
384 }
385 else
386 {
387 wcscpy_s(fieldline[t][1], HELP_SIZE, filteredWaypoints.at(linetop + t).text);
388 //fieldline[t][1][34] = 0; // truncate
389 }
390
391 switch (filteredWaypoints.at(linetop + t).type)
392 {
393 case 1: // IAF
394 fieldline[t][0][0] = 13;
395 break;
396 case 2: // TDZ
397 fieldline[t][0][0] = 20;
398 break;
399 case 3: // Fix
400 fieldline[t][0][0] = 15;
401 break;
402 case 4: // Marker Beacon
403 fieldline[t][0][0] = 14; // looks like an orbital icon but at least it is differentiating ... should be middle marker
404 break;
405 default: // standard waypoint
406 fieldline[t][0][0] = 0;
407 break;
408 }
409
410
411 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
412 switch (filteredWaypoints.at(linetop + t).source)
413 {
414 case 0:
415 fieldline[t][4][0] = 12; break; // unknown
416 case 1:
417 fieldline[t][4][0] = 1; break; // marked
418 case 2: // legacy
419 case 5: // keyed lat/long
420 case 6: // keyed APN
421 fieldline[t][4][0] = 2; break;
422 case 3: // shared
423 case 8: // received
424 fieldline[t][4][0] = 19; break;
425 case 4:
426 fieldline[t][4][0] = 11; break; // purchased
427 default:
428 fieldline[t][4][0] = 0; break;
429 }
430
431 if (filteredWaypoints.at(linetop + t).location.x != 0.0f)
432 {
433 RiseMath::Vector3 result = filteredWaypoints.at(linetop + t).location;
434 const float f_temp = GetArcDist(playerships[0].position, result, true);
435 result = -result;
436
437 WCHAR northsouth, eastwest;
438 if (filteredWaypoints.at(linetop + t).latlng.x < 0.0f)
439 northsouth = gui->strings[L_LIST_NORTH].c_str()[0];
440 else
441 northsouth = gui->strings[L_LIST_SOUTH].c_str()[0];
442 if (filteredWaypoints.at(linetop + t).latlng.y < 0.0f)
443 eastwest = gui->strings[L_LIST_WEST].c_str()[0];
444 else
445 eastwest = gui->strings[L_LIST_EAST].c_str()[0];
446
447 swprintf_s(fieldline[t][2], HELP_SIZE, L"%c %06.3f %c %07.3f", northsouth, fabsf(filteredWaypoints.at(linetop + t).latlng.x), eastwest, fabsf(filteredWaypoints.at(linetop + t).latlng.y));
448 if (f_temp > 10000.0f)
449 swprintf_s(fieldline[t][3], HELP_SIZE, L"%.3f k%s", f_temp * 0.001f, gui->strings[L_LIST_KM].c_str());
450 else
451 swprintf_s(fieldline[t][3], HELP_SIZE, L"%.3f %s", f_temp, gui->strings[L_LIST_KM].c_str());
452 }
453 else
454 {
455 wcscpy_s(fieldline[t][2], HELP_SIZE, gui->strings[L_LIST_UNUSED].c_str());
456 wcscpy_s(fieldline[t][3], HELP_SIZE, gui->strings[L_LIST_UNUSED].c_str());
457 }
458 }
459 }
460
463}
464
465void WaypointDialog::TabClick(short clicked_tab)
466{
467 logger->AddToCallStack("WaypointDialog::TabClick");
468
469 if (clicked_tab != activetab) // if tab wasn't the active one, make it active
470 {
471 activetab = clicked_tab;
472 ClearEdit();
473 ActiveTab();
474 }
475 else // otherwise it was already the active tab, edit it
476 {
477 if (edittab == -1 && editline == -1)
478 {
479 edittab = clicked_tab;
480 HUD.GetEditBox(IDC_TABEDIT)->SetLocation((int)(tabx[clicked_tab] - windowlocation.x) - 8, -46);
481 HUD.GetEditBox(IDC_TABEDIT)->SetSize((int)tabwidth[clicked_tab] + 20, 32);
482 HUD.GetEditBox(IDC_TABEDIT)->SetText(tabstr[clicked_tab], false);
484 HUD.GetEditBox(IDC_TABEDIT)->HandleMouse(WM_LBUTTONDOWN, gui->ptClick, 0, 0);
485 gui->Editing = true;
486 }
487 }
488
489 logger->AddToCallStack("WaypointDialog::TabClick END");
490}
491
493{
494 if (field == 2 && linecursel != 0) return false; // only edit field 2 (location) on top line... how do we configure THAT?!
495 if (field == 1 && filteredWaypoints.at(linecursel).location.x == 0.0f) return false; // don't let them edit non-existent waypoints
496 if (field == 1 && filteredWaypoints.at(linecursel).type != 0) return false; // don't let them edit TDZ, FAF, FIX, MM
497 return true;
498}
499
501{
502 logger->AddToCallStack("WaypointDialog::ActiveTab");
503
504 HUD.SetFont(0, L"DejaVu Sans Mono", static_cast<long>(12.0f * gui->game->displayscale), FW_NORMAL);
505
508
509 logger->AddToCallStack("WaypointDialog::ActiveTab END");
510}
511
516
517short WaypointDialog::TabForGroup(unsigned char group) const
518{
519 return folderOrder.Tab(group);
520}
521
523{
524 // Use the master collection, including replies not yet shown in the cached list.
526}
527
529{
530 logger->AddToCallStack("WaypointDialog::ActionIconClick L_ACTION_ACTIVATE");
531
532 if (linecursel < 0 || linecursel >= static_cast<int>(filteredWaypoints.size()))
533 {
534 char msg[99];
535 sprintf_s(msg, sizeof msg, "Found the problem going to set WPtargetC (%i) and lineact (%i) to linecursel (%i) actionenabled %i",
540 return;
541 }
542
543 // A later record for an old server selection must not replace this user choice.
545
546 if (ptrBus->WPtargetC >= 0 && ptrBus->WPtargetC < static_cast<long>(ptrBus->waypoint.size()))
548
550
551 const auto filtered_waypoint = filteredWaypoints.at(lineact);
552 const auto master_index = ptrWaypoints->Find(filtered_waypoint.id);
553 ptrBus->WPtargetC = master_index;
554
555 if (ptrBus->WPtargetC < 0 || ptrBus->WPtargetC >= static_cast<long>(ptrBus->waypoint.size()))
556 {
557 char msg[99];
558 sprintf_s(msg, sizeof msg, "Found the problem WPtargetC %i because of lineact and linecursel!", ptrBus->WPtargetC);
561 ptrBus->WPtargetC = 0;
562 }
563
564 auto outpacket = WaypointProtocol::Select(filtered_waypoint.id,
566 gui->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
567
568 UpdateMenu(-1);
569
572
574}
575
577{
578 logger->AddToCallStack("WaypointDialog::ActionIconClick");
579
580 if (!actionenabled[icon_id])
581 return;
582
583 if (action[icon_id] == (L_ACTION_MARK - L_ACTION_MARK))
584 {
585 logger->AddToCallStack("WaypointDialog::ActionIconClick L_ACTION_MARK");
586
587 if (linecursel < 0 || linecursel >= static_cast<int>(filteredWaypoints.size()))
588 throw std::exception("Trying to ActionIconClick a waypoint that doesn't exist in collection!");
589
590 filteredWaypoints.at(linecursel).heading = -1; // directionless
594 filteredWaypoints.at(linecursel).type = 0; // waypoint
596 filteredWaypoints.at(linecursel).source = 1; // marked
598 filteredWaypoints.at(linecursel).protectionLevel = 5; // private
599
600 // @todo aren't we supposed to upload this to the server!? can we edit stuff other than waypoint 0?
602
603 UpdateMenu(-1);
604 }
605 else if (action[icon_id] == (L_ACTION_ACTIVATE - L_ACTION_MARK))
606 {
608 }
609 else if (action[icon_id] == (L_ACTION_DELETE - L_ACTION_MARK))
610 {
611 logger->AddToCallStack("WaypointDialog::ActionIconClick L_ACTION_DELETE");
612
613 const auto filtered_waypoint = filteredWaypoints.at(linecursel);
615 const auto masterIndex = ptrWaypoints->Find(filtered_waypoint.id);
616 ptrWaypoints->Delete(masterIndex);
617 if (linecursel >= static_cast<int>(filteredWaypoints.size()))
618 linecursel--;
619
620 UpdateMenu(-1);
621 }
622 else if (action[icon_id] == (L_ACTION_WP_PUBLIC - L_ACTION_MARK))
623 {
624 logger->AddToCallStack("WaypointDialog::ActionIconClick L_ACTION_WP_PUBLIC");
625
626 filteredWaypoints.at(linecursel).protectionLevel = 0;
628
629 SClientPacket outpacket;
630 outpacket.type = 37; // Waypoint management
631 outpacket.f_x = 3.0f; // protection
632 outpacket.f_y = static_cast<float>(filteredWaypoints.at(linecursel).id);
633 outpacket.f_z = 0.0f; // public
634 outpacket.f_w = 0.0f;
635 gui->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
636 UpdateMenu(-1);
637 }
638 else if (action[icon_id] == (L_ACTION_WP_NOENEMIES - L_ACTION_MARK))
639 {
640 logger->AddToCallStack("WaypointDialog::ActionIconClick L_ACTION_WP_NOENEMIES");
641
642 filteredWaypoints.at(linecursel).protectionLevel = 1;
644
645 SClientPacket outpacket;
646 outpacket.type = 37; // Waypoint management
647 outpacket.f_x = 3.0f; // protection
648 outpacket.f_y = static_cast<float>(filteredWaypoints.at(linecursel).id);
649 outpacket.f_z = 1.0f; // no enemies
650 outpacket.f_w = 0.0f;
651 gui->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
652 UpdateMenu(-1);
653 }
654 else if (action[icon_id] == (L_ACTION_WP_ALLIES - L_ACTION_MARK))
655 {
656 logger->AddToCallStack("WaypointDialog::ActionIconClick L_ACTION_WP_ALLIES");
657
658 filteredWaypoints.at(linecursel).protectionLevel = 2;
660
661 SClientPacket outpacket;
662 outpacket.type = 37; // Waypoint management
663 outpacket.f_x = 3.0f; // protection
664 outpacket.f_y = static_cast<float>(filteredWaypoints.at(linecursel).id);
665 outpacket.f_z = 2.0f; // allies
666 outpacket.f_w = 0.0f;
667 gui->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
668 UpdateMenu(-1);
669 }
670 else if (action[icon_id] == (L_ACTION_WP_ALLIANCE - L_ACTION_MARK))
671 {
672 logger->AddToCallStack("WaypointDialog::ActionIconClick L_ACTION_WP_ALLIANCE");
673
674 filteredWaypoints.at(linecursel).protectionLevel = 3;
676
677 SClientPacket outpacket;
678 outpacket.type = 37; // Waypoint management
679 outpacket.f_x = 3.0f; // protection
680 outpacket.f_y = static_cast<float>(filteredWaypoints.at(linecursel).id);
681 outpacket.f_z = 3.0f; // alliance
682 outpacket.f_w = 0.0f;
683 gui->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
684 UpdateMenu(-1);
685 }
686 else if (action[icon_id] == (L_ACTION_WP_PARTNERS - L_ACTION_MARK))
687 {
688 logger->AddToCallStack("WaypointDialog::ActionIconClick L_ACTION_WP_PARTNERS");
689
690 filteredWaypoints.at(linecursel).protectionLevel = 4;
692
693 SClientPacket outpacket;
694 outpacket.type = 37; // Waypoint management
695 outpacket.f_x = 3.0f; // protection
696 outpacket.f_y = static_cast<float>(filteredWaypoints.at(linecursel).id);
697 outpacket.f_z = 4.0f; // partners
698 outpacket.f_w = 0.0f;
699 gui->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
700 UpdateMenu(-1);
701 }
702 else if (action[icon_id] == (L_ACTION_WP_PRIVATE - L_ACTION_MARK))
703 {
704 logger->AddToCallStack("WaypointDialog::ActionIconClick L_ACTION_WP_PRIVATE");
705
706 filteredWaypoints.at(linecursel).protectionLevel = 5;
708
709 SClientPacket outpacket;
710 outpacket.type = 37; // Waypoint management
711 outpacket.f_x = 3.0f; // protection
712 outpacket.f_y = static_cast<float>(filteredWaypoints.at(linecursel).id);
713 outpacket.f_z = 5.0f; // private
714 outpacket.f_w = 0.0f;
715 gui->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
716 UpdateMenu(-1);
717 }
718 else if (action[icon_id] == (L_ACTION_REMOVE_FOLDER - L_ACTION_MARK))
719 {
720 // Recheck at click time in case a waypoint arrived after the last refresh.
721 if (!CanRemoveFolder())
722 {
723 UpdateMenu(-1);
724 return;
725 }
726 ClearEdit();
728 DialogBase::ActionIconClick(icon_id); // shifts labels and refreshes the active tab
729 }
730 else if (action[icon_id] == (L_ACTION_ADD_FOLDER - L_ACTION_MARK) && tabs < MAX_TAB) // add folder
731 {
732 tabusedefaultlang[tabs] = 0; // user config
733 tabstr[tabs][0] = 0; // unnamed
734 tabs++;
735 UpdateMenu(-1);
737 }
738
739 logger->AddToCallStack("WaypointDialog::ActionIconClick DONE");
740}
741
747
749{
750 logger->AddToCallStack("WaypointDialog::ClearEdit");
751
752 if (edittab != -1)
753 {
754 edittab = -1;
756 gui->Editing = false;
757 }
758 if (editline != -1)
759 {
761 editline = editfield = -1;
762 gui->Editing = false;
763 }
764}
765
767{
768 if (filteredWaypoints.size() < 2)
769 return;
770
771 logger->AddToCallStack("WaypointDialog::Sort");
772
773 bool swapflag;
774 do
775 {
776 swapflag = false;
777 for (unsigned s = activetab == 0 ? 1 : 0; s < (filteredWaypoints.size() - 1); s++)
778 {
779 bool flip = false;
780 if (sortfield == 1) // description
781 {
782 if (sortdirection == 1)
783 {
784 if (_wcsicmp(filteredWaypoints.at(s).text, filteredWaypoints.at(s + 1).text) > 0)
785 flip = true;
786 }
787 else
788 {
789 if (_wcsicmp(filteredWaypoints.at(s).text, filteredWaypoints.at(s + 1).text) < 0)
790 flip = true;
791 }
792 }
793 else if (sortfield == 3) // distance
794 {
795 RiseMath::Vector3 result = playerships[0].position - filteredWaypoints.at(s).location;
796 float thisdist = RiseMath::Vec3Length(&result);
797 result = playerships[0].position - filteredWaypoints.at(s + 1).location;
798 float nextdist = RiseMath::Vec3Length(&result);
799
800 if (sortdirection == 1)
801 {
802 if (thisdist > nextdist)
803 flip = true;
804 }
805 else
806 {
807 if (thisdist < nextdist)
808 flip = true;
809 }
810 }
811 if (flip)
812 {
813 const Swaypoint tempwaypoint = filteredWaypoints.at(s);
814 filteredWaypoints.at(s) = filteredWaypoints.at(s + 1);
815 filteredWaypoints.at(s + 1) = tempwaypoint;
816 if (linecursel == s)
817 linecursel = s + 1;
818 else if (linecursel == (s + 1))
819 linecursel = s;
820 if (lineact == s)
821 lineact = s + 1;
822 else if (lineact == (s + 1))
823 lineact = s;
824 swapflag = true;
825 }
826 }
827 } while (swapflag);
828}
829
831{
832 char msg[199];
833 sprintf_s(msg, sizeof msg, "WaypointDialog::DragDropItem(%i): %i", destTab, gui->dragt);
835
836 if (gui->dragt == D_COMMUNICATIONS) // from communications
837 {
839 {
840 sprintf_s(msg, sizeof msg, "Ha! This is where we were crapping out on dragline: %i", gui->dragline);
842 return;
843 }
844
845 const wchar_t* c_str = gui->chatchannel[dialogs[D_COMMUNICATIONS]->activetab].chatline.at(gui->dragline).c_str();
846 // tokenized waypoint reception
847 if (wcsncmp(c_str, L"TC_WAYPOINT,", 12) != 0) return;
848
849 // deserialize
850 WCHAR waypointName[64] = {};
851 int uniqueId;
852 float locationx, locationy, locationz;
853 setlocale(LC_ALL, "English_United States.1252");
854 const int fieldsRead = swscanf_s(c_str, L"TC_WAYPOINT,%d,%f,%f,%f,%63[^\n]", &uniqueId, &locationx, &locationy, &locationz, waypointName, static_cast<unsigned>(_countof(waypointName)));
855 gui->SetLocale();
856 if (fieldsRead != 5) return;
857 Swaypoint tempwaypoint = {};
858 tempwaypoint.uniqueid = uniqueId;
859 tempwaypoint.location = RiseMath::Vector3(locationx, locationy, locationz);
860 WaypointProtocol::SetText(tempwaypoint, waypointName);
861 tempwaypoint.source = 8; // received
862 tempwaypoint.reference = -2; // all ground based
863 tempwaypoint.group = static_cast<unsigned char>(folderOrder.Group(destTab));
864 tempwaypoint.protectionLevel = 5; // private
865 tempwaypoint.type = 0; // user waypoint
866 tempwaypoint.id = 0; // add
867 tempwaypoint.heading = -1;
868 tempwaypoint.latlng = RiseMath::Vector2(0, 0); // computed
869 tempwaypoint.elevationKm = 0.0f; // computed
870 tempwaypoint.length = 0; // unused
871 RiseMath::QuaternionIdentity(&tempwaypoint.orientation); // zero
872 tempwaypoint.pairedWithColonyId = 0; // none
873 tempwaypoint.velocity = centerC; // zero
874
875 // The server assigns the saved ID; AddOrUpdate invalidates the tab on reply.
876 this->ptrWaypoints->Upload(tempwaypoint);
877 }
878 else if (gui->dragt == D_WAYPOINTMANAGER) // move one folder to another
879 {
880 auto filtered_waypoint = filteredWaypoints.at(linecursel);
882 filtered_waypoint.group = static_cast<unsigned char>(folderOrder.Group(destTab));
883 ptrWaypoints->Upload(filtered_waypoint);
884 ptrWaypoints->UpdateMaster(filtered_waypoint);
885 linecursel = -1;
886 UpdateMenu(-1);
887 }
888}
889
891{
892 logger->AddToCallStack("WaypointDialog::Update");
893
894 if (gui->g_bLeftClick && editline != -1)
895 {
897 ClearEdit();
898 }
899}
@ TaxiService45
Definition ActiveHelp.h:398
@ TaxiService47
Definition ActiveHelp.h:400
@ TaxiService63
Definition ActiveHelp.h:416
@ TaxiService56
Definition ActiveHelp.h:409
@ TaxiService46
Definition ActiveHelp.h:399
#define EVENT_EDITBOX_STRING
Definition Controls.h:27
#define EVENT_EDITBOX_CANCEL
Definition Controls.h:31
@ D_WAYPOINTMANAGER
Definition DialogBase.h:6
@ D_COMMUNICATIONS
Definition DialogBase.h:12
RiseMath::Vector2 CalculateLatLng(RiseMath::Vector3 position)
float GetArcDist(RiseMath::Vector3 from, RiseMath::Vector3 to, bool includeAltDiff)
@ EVENT_SELECT_TARGET
Definition Networking.h:59
#define MAX_TAB
#define MAX_TAB_CHARS
const RiseMath::Vector3 centerC
@ REF_ONGROUND
Definition ServerTypes.h:43
@ SOUND_CYCLETARGET
Definition Sound.h:173
void ClearTurnByTurn()
Definition Bus.h:517
bool streetViewConfigured
Definition Bus.h:510
RiseMath::Vector3 lastWaypointLocation
Definition Bus.h:501
std::vector< Swaypoint > waypoint
Definition Bus.h:500
int WPtargetC
Definition Bus.h:499
std::vector< std::wstring > chatline
Definition chat.h:53
static HMI * gui
Definition DialogBase.h:42
short fieldcontent[MAX_FIELDS]
Definition DialogBase.h:50
bool actiontoggle[MAX_ACTION]
Definition DialogBase.h:79
short linedsp
Definition DialogBase.h:74
short icon
Definition DialogBase.h:55
short sortfield
Definition DialogBase.h:66
bool active
Definition DialogBase.h:73
short activetab
Definition DialogBase.h:64
short text
Definition DialogBase.h:71
bool showfields
Definition DialogBase.h:47
static Logger * logger
Definition DialogBase.h:43
short tabs
Definition DialogBase.h:64
short fieldtype[MAX_FIELDS]
Definition DialogBase.h:49
short tabx[MAX_TAB]
Definition DialogBase.h:91
short defaultwidth
Definition DialogBase.h:53
short dialogid
Definition DialogBase.h:102
static DialogBase * dialogs[D_ENUMERATION]
Definition DialogBase.h:41
char sortdirection
Definition DialogBase.h:67
static void UpdateScrollBar(short t)
long editfield
Definition DialogBase.h:81
WCHAR fieldline[MAX_LINES][MAX_FIELDS][HELP_SIZE]
Definition DialogBase.h:96
WCHAR tabstr[MAX_TAB][MAX_TAB_CHARS]
Definition DialogBase.h:65
bool actionenabled[MAX_ACTION]
Definition DialogBase.h:79
virtual void ActionIconClick(long icon_id)
short tabusedefaultlang[MAX_TAB]
Definition DialogBase.h:52
RiseMath::Vector3 windowdefaultlocation
Definition DialogBase.h:54
RiseMath::Vector3 windowlocation
Definition DialogBase.h:61
long edittab
Definition DialogBase.h:81
long editline
Definition DialogBase.h:81
RiseDialog HUD
Definition DialogBase.h:100
static short CheckWidth(short dialogid)
bool usesHUD
Definition DialogBase.h:58
short action[MAX_ACTION]
Definition DialogBase.h:51
short actions
Definition DialogBase.h:51
bool fieldsortable[MAX_FIELDS]
Definition DialogBase.h:98
short fieldwidth[MAX_FIELDS]
Definition DialogBase.h:48
short fields
Definition DialogBase.h:46
DialogBase(short id)
int linecursel
Definition DialogBase.h:75
virtual void ActiveTab()
short tabwidth[MAX_TAB]
Definition DialogBase.h:91
short defaultheight
Definition DialogBase.h:53
std::unique_ptr< Bus > bus
Definition GameClass.h:108
std::unique_ptr< Networking > networking
Definition GameClass.h:103
std::unique_ptr< Viewscreen > viewscreen
Definition GameClass.h:107
float displayscale
Definition GameClass.h:130
void SetLocale() const
Definition gui.cpp:1817
GameClass * game
Definition gui.h:1213
short dragt
Definition gui.h:1041
std::wstring strings[L_ENUMERATION]
Definition gui.h:1076
InformationDialog * informationDialog
Definition gui.h:1120
bool Editing
Definition gui.h:1109
long dragline
Definition gui.h:1042
POINT ptClick
Definition gui.h:1049
RiseDialogResourceManager g_DialogResourceManager
Definition gui.h:1079
Networking * networking
Definition gui.h:1211
CHATCHANNEL chatchannel[MAX_TAB]
Definition gui.h:1096
short FONT_WIDTH
Definition gui.h:1038
bool g_bLeftClick
Definition gui.h:1039
Sound * sound
Definition gui.h:1212
bool DismissHelp(int helpId, int nControlID=GUI_UNDERSTOOD)
bool PopUpHelp(short helpId, bool allowDismiss=true, bool isLearnMore=false)
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
@ Error
Definition Logger.h:28
void SendToServer(void *pData, DWORD dwSize, bool bGuaranteed, PacketOrdering order=ORDERING_NONE) const
void SendEvent(EventType eventType, float extent=0.0f) const
void SetLocation(int x, int y)
Definition Controls.h:606
bool m_bHasFocus
Definition Controls.h:645
virtual bool GetVisible()
Definition Controls.h:587
void SetSize(int width, int height)
Definition Controls.h:610
virtual void SetVisible(bool bVisible)
Definition Controls.h:583
RiseEditBox * GetEditBox(int ID)
Definition Controls.h:196
void Init(RiseDialogResourceManager *pManager, bool bRegisterDialog=true)
Definition Controls.cpp:176
void EnableKeyboardInput(bool bEnable)
Definition Controls.h:320
HRESULT AddEditBox(int ID, LPCWSTR strText, int x, int y, int width, int height, bool bIsDefault=false, bool bIsPassword=false, RiseEditBox **ppCreated=NULL)
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
virtual bool HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
LPCWSTR GetText()
Definition Controls.h:1269
void SetText(LPCWSTR wszText, bool bSelected=false)
float Play(SOUNDS soundEnum, float volume=1.0f)
Definition Sound.cpp:802
std::unique_ptr< waypoints > ptrWaypoints
Definition Viewscreen.h:437
RiseMath::Vector3 CalculatePlanar(short u, short v)
std::vector< Swaypoint > filteredWaypoints
bool canEditField(int field) override
void ActionIconClick(long icon_id) override
void DoubleClickLine() override
WaypointProtocol::FolderOrder folderOrder
void TabClick(short clicked_tab)
Viewscreen * ptrViewscreen
WaypointDialog(short id)
waypoints * ptrWaypoints
void Update() override
void UpdateMenu(short tab) override
void ClearEdit() override
static void CALLBACK DialogCallback(UINT nEvent, int nControlID, RiseControl *pControl, void *pUserContext)
short TabForGroup(unsigned char group) const
void DragDropItem(short destTab) override
bool CanRemoveFolder() const
bool Remove(short tab, short count, const std::vector< Swaypoint > &waypoints)
short Tab(unsigned char group) const
bool CanRemove(short tab, short count, const std::vector< Swaypoint > &waypoints) const
void CancelPendingSelection()
Definition waypoints.cpp:57
void Upload(Swaypoint swaypoint) const
short Find(int id) const
std::vector< Swaypoint > GetGroup(short group) const
void Delete(int index)
Definition waypoints.cpp:94
void UpdateMaster(Swaypoint waypoint) const
Definition waypoints.cpp:23
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
#define radiusC
Definition globals.h:87
@ L_FIELD_DESCRIPTION
Definition gui.h:86
@ L_DIALOG_WAYPOINTMANAGER
Definition gui.h:71
@ L_LIST_UNUSED
Definition gui.h:99
@ L_FIELD_DISTANCE
Definition gui.h:88
@ L_ACTION_WP_PUBLIC
Definition gui.h:131
@ L_ACTION_WP_ALLIANCE
Definition gui.h:134
@ L_ACTION_ACTIVATE
Definition gui.h:109
@ L_FIELD_LOCATION
Definition gui.h:87
@ L_ACTION_WP_ALLIES
Definition gui.h:133
@ L_LIST_KM
Definition gui.h:104
@ L_ACTION_WP_NOENEMIES
Definition gui.h:132
@ L_ACTION_ADD_FOLDER
Definition gui.h:111
@ L_LIST_WEST
Definition gui.h:103
@ L_ACTION_MARK
Definition gui.h:107
@ L_LIST_SOUTH
Definition gui.h:101
@ L_ACTION_WP_PRIVATE
Definition gui.h:136
@ L_LIST_NORTH
Definition gui.h:100
@ L_ACTION_WP_PARTNERS
Definition gui.h:135
@ L_ACTION_REMOVE_FOLDER
Definition gui.h:110
@ L_LIST_EAST
Definition gui.h:102
@ L_ACTION_DELETE
Definition gui.h:108
@ IDC_TABEDIT
Definition gui.h:973
@ IDC_FIELDEDIT
Definition gui.h:972
#define HELP_SIZE
Definition gui.h:21
@ FIELD_VARTEXT
Definition gui.h:43
@ FIELD_ICON
Definition gui.h:42
auto ToRadian(T value)
Definition ClientMath.h:13
float Vec3Length(const Vector3 *a)
Definition ClientMath.h:95
Quaternion * QuaternionIdentity(Quaternion *out)
Definition ClientMath.h:164
Vector3 * Vec3Normalize(Vector3 *out, const Vector3 *a)
Definition ClientMath.h:103
Vector3 * Vec3Scale(Vector3 *out, const Vector3 *a, float scale)
Definition ClientMath.h:98
void SetText(Swaypoint &waypoint, const WCHAR *text)
SClientPacket Select(int waypointId, bool streetViewConfigured)
unsigned char type
float elevationKm
short heading
unsigned char type
RiseMath::Vector3 velocity
RiseMath::Quaternion orientation
float length
RiseMath::Vector2 latlng
unsigned char group
char reference
unsigned char source
RiseMath::Vector3 location
unsigned char protectionLevel
long pairedWithColonyId
RiseMath::Quaternion orientation
Definition globals.h:521
RiseMath::Vector3 position
Definition globals.h:511
RiseMath::Vector3 velocity
Definition globals.h:500