-
-
Notifications
You must be signed in to change notification settings - Fork 550
/
Copy pathwzscriptdebug.cpp
2834 lines (2586 loc) · 108 KB
/
wzscriptdebug.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This file is part of Warzone 2100.
Copyright (C) 2020-2021 Warzone 2100 Project
Warzone 2100 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Warzone 2100 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file wzscriptdebug.cpp
*
* New scripting system - debug GUI
*/
#include "wzscriptdebug.h"
#if (defined(WZ_OS_WIN) && defined(WZ_CC_MINGW))
# if (defined(vsprintf) && !defined(_GL_STDIO_H) && defined(_LIBINTL_H))
// On mingw / MXE builds, libintl's define of vsprintf breaks string_cast.hpp
// So undef it here and restore it later (HACK)
# define _wz_restore_libintl_vsprintf
# undef vsprintf
# endif
#endif
#ifndef GLM_ENABLE_EXPERIMENTAL
#define GLM_ENABLE_EXPERIMENTAL
#endif
#include <glm/gtx/string_cast.hpp>
#include <glm/gtx/rotate_vector.hpp>
#if defined(_wz_restore_libintl_vsprintf)
# undef _wz_restore_libintl_vsprintf
# undef vsprintf
# define vsprintf libintl_vsprintf
#endif
#include "lib/framework/frame.h"
#include "lib/framework/wzapp.h"
#include "lib/framework/wzconfig.h"
#include "lib/netplay/netplay.h"
#include "lib/widget/button.h"
#include "lib/widget/dropdown.h"
#include "lib/widget/editbox.h"
#include "lib/widget/multibutform.h"
#include "lib/widget/scrollablelist.h"
#include "lib/widget/table.h"
#include "lib/widget/jsontable.h"
#include "lib/ivis_opengl/pieblitfunc.h"
#include "intdisplay.h"
#include "action.h"
#include "difficulty.h"
#include "multiplay.h"
#include "objects.h"
#include "power.h"
#include "hci.h"
#include "display.h"
#include "keybind.h"
#include "loop.h"
#include "mission.h"
#include "message.h"
#include "transporter.h"
#include "template.h"
#include "multiint.h"
#include "challenge.h"
#include "multistat.h"
#include "lighting.h"
#include "texture.h"
#include "warzoneconfig.h"
#include "wzapi.h"
#include "qtscript.h"
#include <vector>
#include <numeric>
#include <algorithm>
#include <limits>
#include <tuple>
static std::shared_ptr<W_SCREEN> debugScreen = nullptr;
static std::shared_ptr<WZScriptDebugger> globalDialog = nullptr;
static jsDebugShutdownHandlerFunction globalDialogShutdownHandler;
#define SCRIPTDEBUG_WINDOW_HEIGHT_MAX 700
#define SCRIPTDEBUG_BUTTON_HEIGHT 24
#define SCRIPTDEBUG_ROW_HEIGHT 24
#define ACTION_BUTTON_ROW_SPACING 10
#define ACTION_BUTTON_SPACING 10
#define TITLE_TOP_PADDING 5
#define TITLE_HEIGHT 24
#define TITLE_BOTTOM (TITLE_TOP_PADDING + TITLE_HEIGHT)
#define TAB_BUTTONS_HEIGHT 24
#define TAB_BUTTONS_PADDING 10
const PIELIGHT WZCOL_DEBUG_FILL_COLOR = pal_RGBA(25, 0, 110, 220);
const PIELIGHT WZCOL_DEBUG_FILL_COLOR_DARK = pal_RGBA(10, 0, 70, 250);
const PIELIGHT WZCOL_DEBUG_BORDER_LIGHT = pal_RGBA(255, 255, 255, 80);
const PIELIGHT WZCOL_DEBUG_INDETERMINATE_PROGRESS_COLOR = pal_RGBA(240, 240, 255, 180);
// MARK: - Filling various models
static const std::vector<WzString> view_type = { "RES", "RPL", "PROX", "RPLX", "BEACON" };
struct RowDataModel
{
public:
RowDataModel(size_t numberOfColumns)
: m_currentMaxColumnWidths(numberOfColumns, 0)
{ }
std::shared_ptr<TableRow> newRow(const std::vector<WzString>& columnTexts, int rowHeight = 0, bool skipCalculatingColumnWidth = false)
{
std::vector<std::shared_ptr<WIDGET>> columnWidgets;
for (size_t i = 0; i < columnTexts.size(); i++)
{
columnWidgets.push_back(newColumnLabel(i, columnTexts[i], skipCalculatingColumnWidth));
}
m_rows.push_back(TableRow::make(columnWidgets, rowHeight));
return m_rows.back();
}
const std::vector<std::shared_ptr<TableRow>>& rows() const { return m_rows; }
const std::vector<size_t> currentMaxColumnWidths() const { return m_currentMaxColumnWidths; }
private:
std::shared_ptr<W_LABEL> newColumnLabel(size_t colIdx, const WzString& text, bool skipCalculatingColumnWidth = false)
{
auto newLabel = std::make_shared<W_LABEL>();
newLabel->setFont(font_regular, WZCOL_FORM_LIGHT);
newLabel->setString(text);
newLabel->setCanTruncate(true);
newLabel->setTransparentToClicks(true);
if (!skipCalculatingColumnWidth)
{
m_currentMaxColumnWidths[colIdx] = std::max(m_currentMaxColumnWidths[colIdx], static_cast<size_t>(std::max<int>(newLabel->getMaxLineWidth(), 0)));
}
return newLabel;
}
private:
std::vector<std::shared_ptr<TableRow>> m_rows;
std::vector<size_t> m_currentMaxColumnWidths;
};
static RowDataModel fillViewdataModel()
{
RowDataModel result(3);
// Name, Type, Source
std::vector<WzString> keys = getViewDataKeys();
for (const WzString& key : keys)
{
VIEWDATA *ptr = getViewData(key);
ASSERT(ptr->type < view_type.size(), "Bad viewdata type");
result.newRow({key, view_type.at(ptr->type), ptr->fileName}, SCRIPTDEBUG_ROW_HEIGHT, true);
}
return result;
}
static RowDataModel fillMessageModel()
{
const std::vector<WzString> msg_type = { "RESEARCH", "CAMPAIGN", "MISSION", "PROXIMITY" };
const std::vector<WzString> msg_data_type = { "DEFAULT", "BEACON" };
const std::vector<WzString> obj_type = { "DROID", "STRUCTURE", "FEATURE", "PROJECTILE", "TARGET" };
RowDataModel result(6);
for (int i = 0; i < MAX_PLAYERS; i++)
{
for (const MESSAGE *psCurr : apsMessages[i])
{
ASSERT(psCurr->type < msg_type.size(), "Bad message type");
ASSERT(psCurr->dataType < msg_data_type.size(), "Bad viewdata type");
std::vector<WzString> columnTexts;
columnTexts.push_back(WzString::number(psCurr->id));
columnTexts.push_back(msg_type.at(psCurr->type));
columnTexts.push_back(msg_data_type.at(psCurr->dataType));
columnTexts.push_back(WzString::number(psCurr->player));
ASSERT(!psCurr->pViewData || !psCurr->psObj, "Both viewdata and object in message should be impossible!");
if (psCurr->pViewData)
{
ASSERT(psCurr->pViewData->type < view_type.size(), "Bad viewdata type");
columnTexts.push_back(psCurr->pViewData->name);
columnTexts.push_back(view_type.at(psCurr->pViewData->type));
}
else if (psCurr->psObj)
{
columnTexts.push_back((objInfo(psCurr->psObj)));
columnTexts.push_back(obj_type.at(psCurr->psObj->type));
}
else
{
columnTexts.push_back("");
columnTexts.push_back("");
}
result.newRow(columnTexts, SCRIPTDEBUG_ROW_HEIGHT);
}
}
return result;
}
static RowDataModel fillTriggersModel(const std::vector<scripting_engine::timerNodeSnapshot>& trigger_snapshot, wzapi::scripting_instance *context)
{
RowDataModel result(7);
for (const auto &node : trigger_snapshot)
{
if (node.instance != context)
{
continue;
}
std::vector<WzString> columnTexts;
columnTexts.push_back(WzString::number(node.timerID));
columnTexts.push_back(WzString::fromUtf8(node.timerName));
if (node.baseobj >= 0)
{
columnTexts.push_back(WzString::number(node.baseobj));
}
else
{
columnTexts.push_back("-");
}
columnTexts.push_back(WzString::number(node.frameTime));
columnTexts.push_back(WzString::number(node.ms));
if (node.type == TIMER_ONESHOT_READY)
{
columnTexts.push_back("Oneshot");
}
else if (node.type == TIMER_ONESHOT_DONE)
{
columnTexts.push_back("Done");
}
else
{
columnTexts.push_back("Repeat");
}
columnTexts.push_back(WzString::number(node.calls));
result.newRow(columnTexts, SCRIPTDEBUG_ROW_HEIGHT);
}
return result;
}
static nlohmann::ordered_json fillMainModel()
{
const std::vector<std::string> lev_type = {
"LDS_COMPLETE", "LDS_CAMPAIGN", "LDS_CAMSTART", "LDS_CAMCHANGE",
"LDS_EXPAND", "LDS_BETWEEN", "LDS_MKEEP", "LDS_MCLEAR",
"LDS_EXPAND_LIMBO", "LDS_MKEEP_LIMBO", "LDS_NONE",
"LDS_MULTI_TYPE_START", "CAMPAIGN", "", "SKIRMISH", "", "", "",
"MULTI_SKIRMISH2", "MULTI_SKIRMISH3", "MULTI_SKIRMISH4" };
const std::vector<std::string> difficulty_type = { "SUPEREASY", "EASY", "NORMAL", "HARD", "INSANE" };
nlohmann::ordered_json result = nlohmann::ordered_json::object();
int8_t gameType = static_cast<int8_t>(game.type);
int8_t missionType = static_cast<int8_t>(mission.type);
ASSERT(gameType < lev_type.size() && gameType != 13 && gameType != 15 && gameType != 16 && gameType != 17, "Bad LEVEL_TYPE for game.type");
result["game.type"] = lev_type.at(gameType);
result["game.scavengers"] = game.scavengers;
result["game.map"] = game.map;
result["game.maxPlayers"] = game.maxPlayers;
result["transporterGetLaunchTime"] = transporterGetLaunchTime();
result["missionIsOffworld"] = missionIsOffworld();
result["missionCanReEnforce"] = missionCanReEnforce();
result["missionForReInforcements"] = missionForReInforcements();
ASSERT(missionType < lev_type.size() && missionType != 13 && missionType != 15 && missionType != 16 && missionType != 17, "Bad LEVEL_TYPE for mission.type");
result["mission.type"] = lev_type.at(missionType);
result["getDroidsToSafetyFlag"] = getDroidsToSafetyFlag();
result["scavengerSlot"] = scavengerSlot();
result["scavengerPlayer"] = scavengerPlayer();
result["bMultiPlayer"] = bMultiPlayer;
result["challenge"] = challengeActive;
ASSERT(getDifficultyLevel() < difficulty_type.size(), "Bad DIFFICULTY_LEVEL");
result["difficultyLevel"] = difficulty_type.at(getDifficultyLevel());
result["loopPieCount"] = loopPieCount;
result["loopPolyCount"] = loopPolyCount;
result["allowDesign"] = allowDesign;
result["includeRedundantDesigns"] = includeRedundantDesigns;
int features;
int droids;
int structures;
objCount(&droids, &structures, &features);
result["No. droids"] = droids;
result["No. structures"] = structures;
result["No. features"] = features;
return result;
}
static nlohmann::ordered_json fillPlayerModel(int i)
{
nlohmann::ordered_json result = nlohmann::ordered_json::object();
result["playerStats score"] = getMultiPlayRecentScore(i);
result["playerStats kills"] = getMultiPlayUnitsKilled(i);
result["NetPlay.players.name"] = NetPlay.players[i].name;
result["NetPlay.players.position"] = NetPlay.players[i].position;
result["NetPlay.players.colour"] = NetPlay.players[i].colour;
result["NetPlay.players.allocated"] = NetPlay.players[i].allocated;
result["NetPlay.players.team"] = NetPlay.players[i].team;
result["NetPlay.players.ai"] = NetPlay.players[i].ai;
result["NetPlay.players.difficulty"] = static_cast<int8_t>(NetPlay.players[i].difficulty);
result["NetPlay.players.autoGame"] = NetPlay.players[i].autoGame;
result["NetPlay.players.IPtextAddress"] = NetPlay.players[i].IPtextAddress;
result["NetPlay.players.isSpectator"] = NetPlay.players[i].isSpectator;
result["Current power"] = getPower(i);
result["Extracted power"] = getExtractedPower(i);
result["Wasted power"] = getWastedPower(i);
return result;
}
// MARK: - componentToString
static const char *getObjType(const BASE_OBJECT *psObj)
{
switch (psObj->type)
{
case OBJ_DROID: return "Droid";
case OBJ_STRUCTURE: return "Structure";
case OBJ_FEATURE: return "Feature";
case OBJ_PROJECTILE: return "Projectile";
default: break;
}
return "Unknown";
}
template<typename T>
static std::string arrayToString(const T *array, int length)
{
WzString result;
for (int i = 0; i < length; i++)
{
if (!result.isEmpty())
{
result.append(", ");
}
result.append(WzString::number(array[i]));
}
return result.toStdString();
}
// Using ^ to denote stats that are in templates, and as such do not change.
// Using : to denote stats that come from structure specializations.
nlohmann::ordered_json componentToString(const COMPONENT_STATS *psStats, int player)
{
nlohmann::ordered_json key = nlohmann::ordered_json::object();
key["Name"] = getStatsName(psStats);
key["NameLocalized"] = getLocalizedStatsName(psStats);
key["^Id"] = psStats->id.toUtf8();
key["^Power"] = psStats->buildPower;
key["^Build Points"] = psStats->buildPoints;
key["^Weight"] = psStats->weight;
key["^Hit points"] = psStats->getUpgrade(player).hitpoints;
key["^Hit points +% of total"] = psStats->getUpgrade(player).hitpointPct;
key["^Designable"] = psStats->designable;
switch (psStats->compType)
{
case COMP_BODY:
{
const BODY_STATS *psBody = (const BODY_STATS *)psStats;
key["^Size"] = psBody->size;
key["^Max weapons"] = psBody->weaponSlots;
key["^Body class"] = psBody->bodyClass.toUtf8();
break;
}
case COMP_PROPULSION:
{
const PROPULSION_STATS *psProp = (const PROPULSION_STATS *)psStats;
key["^Hit points +% of body"] = psProp->upgrade[player].hitpointPctOfBody;
key["^Max speed"] = psProp->maxSpeed;
key["^Propulsion type"] = psProp->propulsionType;
key["^Turn speed"] = psProp->turnSpeed;
key["^Spin speed"] = psProp->spinSpeed;
key["^Spin angle"] = psProp->spinAngle;
key["^Skid decelaration"] = psProp->skidDeceleration;
key["^Deceleration"] = psProp->deceleration;
key["^Acceleration"] = psProp->acceleration;
break;
}
case COMP_BRAIN:
{
const BRAIN_STATS *psBrain = (const BRAIN_STATS *)psStats;
std::string ranks;
for (const std::string &s : psBrain->rankNames)
{
if (!ranks.empty())
{
ranks += ", ";
}
ranks += s;
}
std::string thresholds;
for (int t : psBrain->upgrade[player].rankThresholds)
{
if (!thresholds.empty())
{
thresholds += ", ";
}
thresholds += WzString::number(t).toUtf8();
}
key["^Base command limit"] = psBrain->upgrade[player].maxDroids;
key["^Extra command limit by level"] = psBrain->upgrade[player].maxDroidsMult;
key["^Rank names"] = ranks;
key["^Rank thresholds"] = thresholds;
break;
}
case COMP_REPAIRUNIT:
{
const REPAIR_STATS *psRepair = (const REPAIR_STATS *)psStats;
key["^Repair time"] = psRepair->time;
key["^Base repair points"] = psRepair->upgrade[player].repairPoints;
break;
}
case COMP_ECM:
{
const ECM_STATS *psECM = (const ECM_STATS *)psStats;
key["^Base range"] = psECM->upgrade[player].range;
break;
}
case COMP_SENSOR:
{
const SENSOR_STATS *psSensor = (const SENSOR_STATS *)psStats;
key["^Sensor type"] = psSensor->type;
key["^Base range"] = psSensor->upgrade[player].range;
break;
}
case COMP_CONSTRUCT:
{
const CONSTRUCT_STATS *psCon = (const CONSTRUCT_STATS *)psStats;
key["^Base construct points"] = psCon->upgrade[player].constructPoints;
break;
}
case COMP_WEAPON:
{
const WEAPON_STATS *psWeap = (const WEAPON_STATS *)psStats;
key["Max range"] = psWeap->upgrade[player].maxRange;
key["Min range"] = psWeap->upgrade[player].minRange;
key["EMP Radius"] = psWeap->upgrade[player].empRadius;
key["Radius"] = psWeap->upgrade[player].radius;
key["Number of Rounds"] = psWeap->upgrade[player].numRounds;
key["Damage"] = psWeap->upgrade[player].damage;
key["Minimum damage"] = psWeap->upgrade[player].minimumDamage;
key["Periodical damage"] = psWeap->upgrade[player].periodicalDamage;
key["Periodical damage radius"] = psWeap->upgrade[player].periodicalDamageRadius;
key["Periodical damage time"] = psWeap->upgrade[player].periodicalDamageTime;
key["Radius damage"] = psWeap->upgrade[player].radiusDamage;
key["Reload time"] = psWeap->upgrade[player].reloadTime;
key["Hit chance"] = psWeap->upgrade[player].hitChance;
key["Short hit chance"] = psWeap->upgrade[player].shortHitChance;
key["Short range"] = psWeap->upgrade[player].shortRange;
break;
}
case COMP_NUMCOMPONENTS:
ASSERT_OR_RETURN(key, "%s", "Invalid component: COMP_NUMCOMPONENTS!");
break;
// no "default" case because modern compiler plus "-Werror"
// will raise error if a switch is forgotten
}
return key;
}
// MARK: - NoBackgroundTabWidget
class NoBackgroundTabWidget : public MultichoiceWidget
{
public:
NoBackgroundTabWidget(int value = -1) : MultichoiceWidget(value) { }
virtual void display(int xOffset, int yOffset) override { }
};
// MARK: - Debug buttons
struct TabButtonDisplayCache
{
WzText text;
};
static void TabButtonDisplayFunc(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset)
{
// Any widget using TabButtonDisplayFunc must have its pUserData initialized to a (TabButtonDisplayCache*)
assert(psWidget->pUserData != nullptr);
TabButtonDisplayCache& cache = *static_cast<TabButtonDisplayCache*>(psWidget->pUserData);
W_BUTTON *psButton = dynamic_cast<W_BUTTON*>(psWidget);
ASSERT_OR_RETURN(, psButton, "psWidget is null");
int x0 = psButton->x() + xOffset;
int y0 = psButton->y() + yOffset;
int x1 = x0 + psButton->width();
int y1 = y0 + psButton->height();
bool haveText = !psButton->pText.isEmpty();
bool isDown = (psButton->getState() & (WBUT_DOWN | WBUT_LOCK | WBUT_CLICKLOCK)) != 0;
bool isDisabled = (psButton->getState() & WBUT_DISABLE) != 0;
bool isHighlight = !isDisabled && ((psButton->getState() & WBUT_HIGHLIGHT) != 0);
// Display the button.
auto light_border = WZCOL_DEBUG_BORDER_LIGHT;
auto fill_color = isDown || isDisabled ? WZCOL_DEBUG_FILL_COLOR_DARK : WZCOL_DEBUG_FILL_COLOR;
iV_ShadowBox(x0, y0, x1, y1, 0, isDown ? pal_RGBA(0,0,0,0) : light_border, isDisabled ? light_border : WZCOL_FORM_DARK, fill_color);
if (isHighlight)
{
iV_Box(x0 + 2, y0 + 2, x1 - 2, y1 - 2, WZCOL_FORM_HILITE);
}
if (haveText)
{
cache.text.setText(psButton->pText, psButton->FontID);
int fw = cache.text.width();
int fx = x0 + (psButton->width() - fw) / 2;
int fy = y0 + (psButton->height() - cache.text.lineSize()) / 2 - cache.text.aboveBase();
PIELIGHT textColor = WZCOL_FORM_TEXT;
if (isDisabled)
{
textColor.byte.a = (textColor.byte.a / 2);
}
cache.text.render(fx, fy, textColor);
}
}
static std::shared_ptr<W_BUTTON> makeDebugButton(const char* text)
{
auto button = std::make_shared<W_BUTTON>();
button->setString(text);
button->FontID = font_regular;
button->displayFunction = TabButtonDisplayFunc;
button->pUserData = new TabButtonDisplayCache();
button->setOnDelete([](WIDGET *psWidget) {
assert(psWidget->pUserData != nullptr);
delete static_cast<TabButtonDisplayCache *>(psWidget->pUserData);
psWidget->pUserData = nullptr;
});
int minButtonWidthForText = iV_GetTextWidth(text, button->FontID);
button->setGeometry(0, 0, minButtonWidthForText + TAB_BUTTONS_PADDING, TAB_BUTTONS_HEIGHT);
return button;
}
// MARK: - WzMainPanel
class WzMainPanel : public W_FORM
{
public:
WzMainPanel(bool readOnly)
: W_FORM()
, readOnly(readOnly)
{}
~WzMainPanel() {}
public:
virtual void display(int xOffset, int yOffset) override
{
// no background
}
virtual void geometryChanged() override
{
playersDropdown->callCalcLayout();
powerUpdateButton->callCalcLayout();
powerEditField->callCalcLayout();
aiAttachButton->callCalcLayout();
aiPlayerDropdown->callCalcLayout();
aiDifficultyDropdown->callCalcLayout();
aiDropdown->callCalcLayout();
table->callCalcLayout();
}
public:
static std::shared_ptr<WzMainPanel> make(bool readOnly)
{
auto panel = std::make_shared<WzMainPanel>(readOnly);
std::shared_ptr<W_BUTTON> previousRowButton;
previousRowButton = panel->createButton(0, "Add droids", [](){ intOpenDebugMenu(OBJ_DROID); }, nullptr, true);
previousRowButton = panel->createButton(0, "Add structures", [](){ intOpenDebugMenu(OBJ_STRUCTURE); }, previousRowButton, true);
previousRowButton = panel->createButton(0, "Add features", [](){ intOpenDebugMenu(OBJ_FEATURE); }, previousRowButton, true);
previousRowButton = panel->createButton(1, "Research all", kf_FinishAllResearch, nullptr, true);
previousRowButton = panel->createButton(1, "Show sensors", kf_ToggleSensorDisplay, previousRowButton, false);
previousRowButton = panel->createButton(1, "Shadows", [](){ setDrawShadows(!getDrawShadows()); }, previousRowButton, false);
previousRowButton = panel->createButton(1, "Fog", kf_ToggleFog, previousRowButton, false);
previousRowButton = panel->createButton(2, "Show gateways", kf_ToggleShowGateways, nullptr, false);
previousRowButton = panel->createButton(2, "Reveal all", kf_ToggleGodMode, previousRowButton, true);
previousRowButton = panel->createButton(2, "Weather", kf_ToggleWeather, previousRowButton, false);
previousRowButton = panel->createButton(2, "Reveal mode", kf_ToggleVisibility, previousRowButton, true);
int bottomOfButtonRows = previousRowButton->y() + previousRowButton->height() + ACTION_BUTTON_ROW_SPACING;
// selected player
auto selectedPlayerLabel = std::make_shared<W_LABEL>();
panel->attach(selectedPlayerLabel);
selectedPlayerLabel->setFont(font_regular, WZCOL_FORM_TEXT);
selectedPlayerLabel->setString("Selected Player:");
selectedPlayerLabel->setGeometry(0, bottomOfButtonRows, selectedPlayerLabel->getMaxLineWidth(), std::max<int>(iV_GetTextLineSize(font_regular), TAB_BUTTONS_HEIGHT));
// Add player chooser drop-down
panel->playersDropdown = std::make_shared<DropdownWidget>();
panel->attach(panel->playersDropdown);
panel->playersDropdown->setListHeight(TAB_BUTTONS_HEIGHT * 5);
int maxButtonTextWidth = 0;
for (int i = 0; i < MAX_PLAYERS; i++)
{
WzString buttonLabel = WzString::number(i);
auto button = makeDebugButton(buttonLabel.toUtf8().c_str());
button->UserData = static_cast<UDWORD>(i);
int minButtonTextWidth = button->width();
maxButtonTextWidth = std::max<int>(minButtonTextWidth, maxButtonTextWidth);
panel->playersDropdown->addItem(button);
}
if (selectedPlayer < MAX_PLAYERS)
{
panel->playersDropdown->setSelectedIndex(selectedPlayer);
}
panel->playersDropdown->setOnChange([](DropdownWidget& dropdown) {
auto psParent = std::dynamic_pointer_cast<WzMainPanel>(dropdown.parent());
ASSERT_OR_RETURN(, psParent != nullptr, "No parent");
if (auto selectedIndex = dropdown.getSelectedIndex())
{
psParent->playerButtonClicked(static_cast<int>(selectedIndex.value()));
}
});
int contextDropdownX0 = selectedPlayerLabel->x() + selectedPlayerLabel->width() + ACTION_BUTTON_SPACING;
panel->playersDropdown->setCalcLayout([contextDropdownX0, bottomOfButtonRows](WIDGET *psWidget) {
auto psParent = psWidget->parent();
ASSERT_OR_RETURN(, psParent != nullptr, "No parent");
psWidget->setGeometry(contextDropdownX0, bottomOfButtonRows, psParent->width() - contextDropdownX0 - ACTION_BUTTON_SPACING, TAB_BUTTONS_HEIGHT);
});
int bottomOfSelectedPlayerRow = panel->playersDropdown->y() + panel->playersDropdown->height() + ACTION_BUTTON_ROW_SPACING;
// Power input field
// "Power:" label
panel->powerLabel = std::make_shared<W_LABEL>();
panel->attach(panel->powerLabel);
panel->powerLabel->setFont(font_regular, WZCOL_FORM_TEXT);
panel->powerLabel->setString("Power:");
panel->powerLabel->setGeometry(0, bottomOfSelectedPlayerRow, panel->powerLabel->getMaxLineWidth(), std::max<int>(iV_GetTextLineSize(font_regular), TAB_BUTTONS_HEIGHT));
// Add "Set Power"
panel->powerUpdateButton = makeDebugButton("Set Power");
panel->powerUpdateButton->setGeometry(panel->powerUpdateButton->x(), panel->powerUpdateButton->y(), panel->powerUpdateButton->width(), panel->powerUpdateButton->height());
panel->powerUpdateButton->setTip("Set Selected Player Power");
panel->attach(panel->powerUpdateButton);
panel->powerUpdateButton->addOnClickHandler([](W_BUTTON& button) {
auto psParent = std::dynamic_pointer_cast<WzMainPanel>(button.parent());
ASSERT_OR_RETURN(, psParent != nullptr, "No parent");
// get the value of the field, and attempt to convert to an int32_t
auto powerString = psParent->powerEditField->getString();
int powerValue = 0;
try {
powerValue = std::stoi(powerString.toStdString());
}
catch (const std::exception&) {
debug(LOG_ERROR, "Invalid power value (not convertible to an integer - use numbers only): %s", powerString.toUtf8().c_str());
return;
}
auto selectedPlayerCopy = selectedPlayer;
widgScheduleTask([selectedPlayerCopy, powerValue](){
setPower(selectedPlayerCopy, powerValue);
});
});
panel->powerUpdateButton->setCalcLayout(LAMBDA_CALCLAYOUT_SIMPLE({
auto psParent = std::dynamic_pointer_cast<WzMainPanel>(psWidget->parent());
ASSERT_OR_RETURN(, psParent != nullptr, "No parent");
int x0 = psParent->width() - psWidget->width();
int bottomOfSelectedPlayerRow = psParent->playersDropdown->y() + psParent->playersDropdown->height() + ACTION_BUTTON_ROW_SPACING;
psWidget->setGeometry(x0, bottomOfSelectedPlayerRow, psWidget->width(), psWidget->height());
}));
if (readOnly)
{
panel->powerUpdateButton->setState(WBUT_DISABLE);
}
// Power input edit box
panel->powerEditField = std::make_shared<W_EDITBOX>();
panel->attach(panel->powerEditField);
panel->powerEditField->setGeometry(panel->powerEditField->x(), panel->powerEditField->y(), panel->powerEditField->width(), TAB_BUTTONS_HEIGHT);
panel->powerEditField->setCalcLayout(LAMBDA_CALCLAYOUT_SIMPLE({
auto psParent = std::dynamic_pointer_cast<WzMainPanel>(psWidget->parent());
ASSERT_OR_RETURN(, psParent != nullptr, "No parent");
int x0 = psParent->powerLabel->x() + psParent->powerLabel->width() + ACTION_BUTTON_SPACING;
int bottomOfSelectedPlayerRow = psParent->playersDropdown->y() + psParent->playersDropdown->height() + ACTION_BUTTON_ROW_SPACING;
int y0 = bottomOfSelectedPlayerRow + TAB_BUTTONS_HEIGHT - psWidget->height();
int width = psParent->powerUpdateButton->x() - ACTION_BUTTON_SPACING - x0;
psWidget->setGeometry(x0, y0, width, psWidget->height());
}));
WzString currPower = "0";
if (selectedPlayer < MAX_PLAYERS)
{
currPower = WzString::number(getPower(selectedPlayer));
}
panel->powerEditField->setString(currPower);
panel->powerEditField->setMaxStringSize(9); // shorten maximum length
panel->powerEditField->setBoxColours(WZCOL_DEBUG_FILL_COLOR_DARK, WZCOL_DEBUG_BORDER_LIGHT, WZCOL_DEBUG_FILL_COLOR);
if (readOnly)
{
panel->powerEditField->setState(WEDBS_DISABLE);
}
int bottomOfPowerRow = panel->powerEditField->y() + panel->powerEditField->height() + ACTION_BUTTON_ROW_SPACING;
// Attach script to player
panel->attachAItoPlayerLabel = std::make_shared<W_LABEL>();
panel->attach(panel->attachAItoPlayerLabel);
panel->attachAItoPlayerLabel->setFont(font_regular, WZCOL_FORM_TEXT);
panel->attachAItoPlayerLabel->setString("Attach AI to player:");
panel->attachAItoPlayerLabel->setGeometry(0, bottomOfPowerRow, panel->attachAItoPlayerLabel->getMaxLineWidth(), std::max<int>(iV_GetTextLineSize(font_regular), TAB_BUTTONS_HEIGHT));
// "Attach" button (right-aligned in form)
panel->aiAttachButton = makeDebugButton("Attach");
panel->attach(panel->aiAttachButton);
panel->aiAttachButton->setCalcLayout(LAMBDA_CALCLAYOUT_SIMPLE({
auto psParent = std::dynamic_pointer_cast<WzMainPanel>(psWidget->parent());
ASSERT_OR_RETURN(, psParent != nullptr, "No parent");
int x0 = psParent->width() - psWidget->width();
int bottomOfPowerRow = psParent->powerEditField->y() + psParent->powerEditField->height() + ACTION_BUTTON_ROW_SPACING;
psWidget->setGeometry(x0, bottomOfPowerRow, psWidget->width(), psWidget->height());
}));
panel->aiAttachButton->addOnClickHandler([](W_BUTTON& button){
auto psParent = std::dynamic_pointer_cast<WzMainPanel>(button.parent());
ASSERT_OR_RETURN(, psParent != nullptr, "No parent");
auto selectedAiButton = psParent->aiDropdown->getSelectedItem();
ASSERT_OR_RETURN(, selectedAiButton != nullptr, "No selected AI?");
auto selectedAiDifficultyButton = psParent->aiDifficultyDropdown->getSelectedItem();
ASSERT_OR_RETURN(, selectedAiDifficultyButton != nullptr, "No selected AI difficulty?");
const AIDifficulty difficulty = static_cast<AIDifficulty>(selectedAiDifficultyButton->UserData);
auto selectedAiPlayerButton = psParent->aiPlayerDropdown->getSelectedItem();
ASSERT_OR_RETURN(, selectedAiPlayerButton != nullptr, "No selected AI player?");
const WzString script = selectedAiButton->getString();
const int player = static_cast<int>(selectedAiPlayerButton->UserData);
jsAutogameSpecific(WzString::fromUtf8("multiplay/skirmish/") + script, player, difficulty);
debug(LOG_INFO, "Script attached - close and reopen debug window to see its context");
});
if (readOnly)
{
panel->aiAttachButton->setState(WBUT_DISABLE);
}
// AI players drop-down
panel->aiPlayerDropdown = std::make_shared<DropdownWidget>();
panel->attach(panel->aiPlayerDropdown);
panel->aiPlayerDropdown->setListHeight(TAB_BUTTONS_HEIGHT * static_cast<uint32_t>(std::min<uint8_t>(game.maxPlayers, 5)));
maxButtonTextWidth = 0;
for (int i = 0; i < game.maxPlayers; i++)
{
WzString buttonLabel = WzString::number(i);
auto button = makeDebugButton(buttonLabel.toUtf8().c_str());
button->UserData = static_cast<UDWORD>(i);
maxButtonTextWidth = std::max<int>(button->width(), maxButtonTextWidth);
panel->aiPlayerDropdown->addItem(button);
}
panel->aiPlayerDropdown->setSelectedIndex(0);
panel->aiPlayerDropdown->setCalcLayout([maxButtonTextWidth](WIDGET *psWidget) {
auto pAiPlayerDropdown = static_cast<DropdownWidget *>(psWidget);
auto psParent = std::dynamic_pointer_cast<WzMainPanel>(psWidget->parent());
ASSERT_OR_RETURN(, psParent != nullptr, "No parent");
int width = maxButtonTextWidth + pAiPlayerDropdown->getScrollbarWidth();
int x0 = psParent->aiAttachButton->x() - ACTION_BUTTON_SPACING - width;
int bottomOfPowerRow = psParent->powerEditField->y() + psParent->powerEditField->height() + ACTION_BUTTON_ROW_SPACING;
pAiPlayerDropdown->setGeometry(x0, bottomOfPowerRow, width, TAB_BUTTONS_HEIGHT);
});
// AI Difficulty dropdown
// Easy through INSANE
std::vector<std::pair<AIDifficulty, std::string>> difficulties{
std::pair<AIDifficulty, std::string>{AIDifficulty::DEFAULT, "DEFAULT"},
std::pair<AIDifficulty, std::string>{AIDifficulty::EASY, "EASY"},
std::pair<AIDifficulty, std::string>{AIDifficulty::MEDIUM, "MEDIUM"},
std::pair<AIDifficulty, std::string>{AIDifficulty::HARD, "HARD"},
std::pair<AIDifficulty, std::string>{AIDifficulty::INSANE, "INSANE"}
};
panel->aiDifficultyDropdown = std::make_shared<DropdownWidget>();
panel->attach(panel->aiDifficultyDropdown);
panel->aiDifficultyDropdown->setListHeight(TAB_BUTTONS_HEIGHT * difficulties.size());
maxButtonTextWidth = 0;
for (const auto& difficulty : difficulties)
{
WzString buttonLabel = WzString::fromUtf8(difficulty.second);
auto button = makeDebugButton(buttonLabel.toUtf8().c_str());
button->UserData = static_cast<UDWORD>(difficulty.first);
maxButtonTextWidth = std::max<int>(button->width(), maxButtonTextWidth);
panel->aiDifficultyDropdown->addItem(button);
}
panel->aiDifficultyDropdown->setSelectedIndex(0);
panel->aiDifficultyDropdown->setCalcLayout([maxButtonTextWidth](WIDGET *psWidget) {
auto pAiDifficultyDropdown = static_cast<DropdownWidget *>(psWidget);
auto psParent = std::dynamic_pointer_cast<WzMainPanel>(psWidget->parent());
ASSERT_OR_RETURN(, psParent != nullptr, "No parent");
int width = maxButtonTextWidth + pAiDifficultyDropdown->getScrollbarWidth();
int x0 = psParent->aiPlayerDropdown->x() - ACTION_BUTTON_SPACING - width;
int bottomOfPowerRow =
psParent->powerEditField->y() + psParent->powerEditField->height() + ACTION_BUTTON_ROW_SPACING;
pAiDifficultyDropdown->setGeometry(x0, bottomOfPowerRow, width, TAB_BUTTONS_HEIGHT);
});
// AI names dropdown
const std::vector<WzString> AIs = getAINames();
panel->aiDropdown = std::make_shared<DropdownWidget>();
panel->attach(panel->aiDropdown);
panel->aiDropdown->setListHeight(TAB_BUTTONS_HEIGHT * 5);
maxButtonTextWidth = 0;
for (const WzString &name : AIs)
{
auto button = makeDebugButton(name.toUtf8().c_str());
maxButtonTextWidth = std::max<int>(button->width(), maxButtonTextWidth);
panel->aiDropdown->addItem(button);
}
panel->aiDropdown->setSelectedIndex(0);
panel->aiDropdown->setCalcLayout([](WIDGET *psWidget) {
auto pAiDropdown = static_cast<DropdownWidget *>(psWidget);
auto psParent = std::dynamic_pointer_cast<WzMainPanel>(psWidget->parent());
ASSERT_OR_RETURN(, psParent != nullptr, "No parent");
int x0 = psParent->attachAItoPlayerLabel->x() + psParent->attachAItoPlayerLabel->width() +
ACTION_BUTTON_SPACING;
int bottomOfPowerRow =
psParent->powerEditField->y() + psParent->powerEditField->height() + ACTION_BUTTON_ROW_SPACING;
int fillWidth = psParent->aiDifficultyDropdown->x() - ACTION_BUTTON_SPACING - x0;
pAiDropdown->setGeometry(x0, bottomOfPowerRow, fillWidth, TAB_BUTTONS_HEIGHT);
});
// JSONTable for main game state / info / model
panel->table = JSONTableWidget::make("Game Details:");
panel->attach(panel->table);
panel->table->setCalcLayout(LAMBDA_CALCLAYOUT_SIMPLE({
auto psParent = std::dynamic_pointer_cast<WzMainPanel>(psWidget->parent());
ASSERT_OR_RETURN(, psParent != nullptr, "No parent");
int y0 = psParent->aiDropdown->y() + psParent->aiDropdown->height() + ACTION_BUTTON_ROW_SPACING;
psWidget->setGeometry(0, y0, psParent->width(), psParent->height() - y0);
}));
panel->table->updateData(fillMainModel());
panel->table->setUpdateButtonFunc([](JSONTableWidget& tableWidget){
auto psParent = std::dynamic_pointer_cast<WzMainPanel>(tableWidget.parent());
if (psParent == nullptr)
{
return;
}
psParent->table->updateData(fillMainModel(), true);
}, 3 * GAME_TICKS_PER_SEC);
return panel;
}
private:
std::shared_ptr<W_BUTTON> createButton(int row, const std::string &text, const std::function<void ()>& onClickFunc, const std::shared_ptr<W_BUTTON>& previousButton = nullptr, bool requiresWriteAccess = true)
{
auto button = makeDebugButton(text.c_str());
button->setGeometry(button->x(), button->y(), button->width() + 10, button->height());
attach(button);
button->addOnClickHandler([onClickFunc](W_BUTTON& button) {
widgScheduleTask([onClickFunc](){
onClickFunc();
});
});
if (requiresWriteAccess && readOnly)
{
button->setState(WBUT_DISABLE);
}
int previousButtonRight = (previousButton) ? previousButton->x() + previousButton->width() : 0;
button->move((previousButtonRight > 0) ? previousButtonRight + ACTION_BUTTON_SPACING : 0, (row * (button->height() + ACTION_BUTTON_ROW_SPACING)));
return button;
}
void playerButtonClicked(int value)
{
if (readOnly)
{
debug(LOG_ERROR, "Unable to change selectedPlayer - readOnly mode");
if (selectedPlayer < MAX_PLAYERS)
{
playersDropdown->setSelectedIndex(selectedPlayer);
}
return;
}
ASSERT_OR_RETURN(, selectedPlayer < MAX_PLAYERS, "Invalid selectedPlayer: %" PRIu32 "", selectedPlayer);
// Do not change realSelectedPlayer here, so game doesn't pause.
const int oldSelectedPlayer = selectedPlayer;
selectedPlayer = value;
NetPlay.players[selectedPlayer].allocated = !NetPlay.players[selectedPlayer].allocated;
NetPlay.players[oldSelectedPlayer].allocated = !NetPlay.players[oldSelectedPlayer].allocated;
}
public:
std::shared_ptr<DropdownWidget> playersDropdown;
std::shared_ptr<W_LABEL> powerLabel;
std::shared_ptr<W_EDITBOX> powerEditField;
std::shared_ptr<W_BUTTON> powerUpdateButton;
std::shared_ptr<W_LABEL> attachAItoPlayerLabel;
std::shared_ptr<DropdownWidget> aiDropdown;
std::shared_ptr<DropdownWidget> aiDifficultyDropdown;
std::shared_ptr<DropdownWidget> aiPlayerDropdown;
std::shared_ptr<W_BUTTON> aiAttachButton;
std::shared_ptr<JSONTableWidget> table;
bool readOnly = false;
};
// MARK: - WzGraphicsPanel
class WzGraphicsPanel : public W_FORM
{
public:
WzGraphicsPanel(): W_FORM() {}
~WzGraphicsPanel() {}
public:
virtual void display(int xOffset, int yOffset) override { }
virtual void geometryChanged() override {}
public:
static std::shared_ptr<WzGraphicsPanel> make()
{
auto panel = std::make_shared<WzGraphicsPanel>();
auto prevButton = panel->createButton(0, "Reload terrain & water textures", [](){
loadTerrainTextures(currentMapTileset);
debug(LOG_INFO, "Done");
});
prevButton = panel->createButton(0, "Reload decals", [](){
reloadTileTextures();
debug(LOG_INFO, "Done");
}, prevButton);
prevButton = panel->createButton(0, "Reload model textures", [](){
debug(LOG_INFO, "Reloading all model textures");
modelReloadAllModelTextures();
debug(LOG_INFO, "Done");
}, prevButton);
prevButton = panel->createButton(1, "Recompile All Shaders", [](){
debug(LOG_INFO, "Recompiling all shader pipelines");
gfx_api::context::get().debugRecompileAllPipelines();
debug(LOG_INFO, "Done");
});
prevButton =panel->createButton(1, "Recompile terrainCombined", [](){
debug(LOG_INFO, "Recompiling terrainCombined");
switch (getTerrainShaderQuality())
{
case TerrainShaderQuality::CLASSIC:
gfx_api::TerrainCombined_Classic::get().recompile();
break;
case TerrainShaderQuality::MEDIUM:
gfx_api::TerrainCombined_Medium::get().recompile();
break;
case TerrainShaderQuality::NORMAL_MAPPING:
gfx_api::TerrainCombined_High::get().recompile();
break;
case TerrainShaderQuality::UNINITIALIZED_PICK_DEFAULT:
break;
}
debug(LOG_INFO, "Done");
}, prevButton);
prevButton = panel->createButton(1, "Recompile water", [](){
debug(LOG_INFO, "Recompiling water");
switch (getTerrainShaderQuality())
{
case TerrainShaderQuality::CLASSIC:
gfx_api::WaterClassicPSO::get().recompile();
break;
case TerrainShaderQuality::MEDIUM:
gfx_api::WaterPSO::get().recompile();
break;
case TerrainShaderQuality::NORMAL_MAPPING:
gfx_api::WaterHighPSO::get().recompile();
break;
case TerrainShaderQuality::UNINITIALIZED_PICK_DEFAULT:
break;
}
debug(LOG_INFO, "Done");
}, prevButton);
prevButton = panel->createButton(2, "Rotate sun", [](){
auto newSun = glm::rotate(getTheSun(), glm::pi<float>()/10.f, glm::vec3(0,1,0));
setTheSun(newSun);
debug(LOG_INFO, "Sun at %f,%f,%f", newSun.x, newSun.y, newSun.z);
});
auto dropdownWidget = panel->makeTerrainQualityDropdown(3);
#if defined(DEBUG)
// Ideally, the fallback terrain renderer will be removed soon - so don't even offer this toggle outside of debug builds
auto pWeakTerrainQualityDropdown = std::weak_ptr<DropdownWidget>(dropdownWidget);
prevButton = panel->createButton(3, "Toggle Old / New Shaders", [pWeakTerrainQualityDropdown](){
if (debugToggleTerrainShaderType())
{
auto updateMsg = std::string("Switched terrain shader type to: ") + ((getTerrainShaderType() == TerrainShaderType::SINGLE_PASS) ? "New Shader (Single-Pass)" : "Old (Fallback) Shader");
addConsoleMessage(updateMsg.c_str(), LEFT_JUSTIFY, SYSTEM_MESSAGE);
if (auto pStrongDropdown = pWeakTerrainQualityDropdown.lock())
{
pStrongDropdown->setSelectedIndex(static_cast<size_t>(getTerrainShaderQuality()));
}
}
}, dropdownWidget);
#else