-
Notifications
You must be signed in to change notification settings - Fork 495
Expand file tree
/
Copy pathGui.cpp
More file actions
3064 lines (2643 loc) · 104 KB
/
Gui.cpp
File metadata and controls
3064 lines (2643 loc) · 104 KB
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
/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2012 Petr Mrázek ([email protected])
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#include "Internal.h"
#include "modules/Gui.h"
#include "MemAccess.h"
#include "VersionInfo.h"
#include "Types.h"
#include "Error.h"
#include "ModuleFactory.h"
#include "Core.h"
#include "Debug.h"
#include "PluginManager.h"
#include "MiscUtils.h"
#include "DataDefs.h"
#include "modules/Job.h"
#include "modules/Screen.h"
#include "modules/Maps.h"
#include "modules/Units.h"
#include "modules/World.h"
#include "df/adventurest.h"
#include "df/announcement_alertst.h"
#include "df/announcement_flags.h"
#include "df/announcement_infost.h"
#include "df/building_cagest.h"
#include "df/building_civzonest.h"
#include "df/building_def_workshopst.h"
#include "df/building_def_furnacest.h"
#include "df/building_furnacest.h"
#include "df/building_trapst.h"
#include "df/building_type.h"
#include "df/building_workshopst.h"
#include "df/buildreq.h"
#include "df/cri_unitst.h"
#include "df/d_init.h"
#include "df/enabler.h"
#include "df/game_mode.h"
#include "df/gamest.h"
#include "df/general_ref.h"
#include "df/global_objects.h"
#include "df/graphic.h"
#include "df/graphic_viewportst.h"
#include "df/historical_figure.h"
#include "df/init.h"
#include "df/interfacest.h"
#include "df/item_corpsepiecest.h"
#include "df/item_corpsest.h"
#include "df/job.h"
#include "df/legend_pagest.h"
#include "df/markup_text_boxst.h"
#include "df/markup_text_linkst.h"
#include "df/markup_text_wordst.h"
#include "df/occupation.h"
#include "df/plant.h"
#include "df/plotinfost.h"
#include "df/popup_message.h"
#include "df/report.h"
#include "df/report_zoom_type.h"
#include "df/route_stockpile_link.h"
#include "df/soundst.h"
#include "df/stop_depart_condition.h"
#include "df/unit.h"
#include "df/unit_inventory_item.h"
#include "df/viewscreen_choose_start_sitest.h"
#include "df/viewscreen_dungeonmodest.h"
#include "df/viewscreen_dwarfmodest.h"
#include "df/viewscreen_legendsst.h"
#include "df/viewscreen_new_arenast.h"
#include "df/viewscreen_new_regionst.h"
#include "df/viewscreen_setupdwarfgamest.h"
#include "df/viewscreen_titlest.h"
#include "df/viewscreen_worldst.h"
#include "df/world.h"
#include <string>
#include <vector>
#include <map>
using std::string;
using std::vector;
using namespace DFHack;
const size_t MAX_REPORTS_SIZE = 3000; // DF clears old reports to maintain this vector size
const int32_t RECENT_REPORT_TICKS = 500; // used by UNIT_COMBAT_REPORT_ALL_ACTIVE
const int32_t ANNOUNCE_LINE_DURATION = 100; // time to display each line in announcement bar; 2 sec at 50 GFPS
const int16_t ANNOUNCE_DISPLAY_TIME = 2000; // DF uses this value for most announcements; 40 sec at 50 GFPS
namespace DFHack
{
DBG_DECLARE(core, gui, DebugCategory::LINFO);
}
using namespace df::enums;
using df::building_civzonest;
using df::global::game;
using df::global::gamemode;
using df::global::gps;
using df::global::gview;
using df::global::init;
using df::global::plotinfo;
using df::global::selection_rect;
using df::global::ui_menu_width;
using df::global::world;
/* TODO: understand how this changes for v50
static df::layer_object_listst *getLayerList(df::viewscreen_layer *layer, int idx)
{
return virtual_cast<df::layer_object_listst>(vector_get(layer->layer_objects,idx));
}
*/
static std::string getNameChunk(const virtual_identity *id, int start, int end)
{
if (!id)
return "UNKNOWN";
const char *name = id->getName();
int len = strlen(name);
if (len > start + end)
return std::string(name+start, len-start-end);
else
return name;
}
/*
* Classifying focus context by means of a string path.
*/
typedef void (*getFocusStringsHandler)(std::string &str, std::vector<std::string> &strList, df::viewscreen *screen);
static std::map<const virtual_identity*, getFocusStringsHandler> getFocusStringsHandlers;
#define VIEWSCREEN(name) df::viewscreen_##name##st
#define DEFINE_GET_FOCUS_STRING_HANDLER(screen_type) \
static void getFocusStrings_##screen_type(const std::string &baseFocus, std::vector<std::string> &focusStrings, VIEWSCREEN(screen_type) *screen);\
DFHACK_STATIC_ADD_TO_MAP(\
&getFocusStringsHandlers, &VIEWSCREEN(screen_type)::_identity, \
(getFocusStringsHandler)getFocusStrings_##screen_type \
); \
static void getFocusStrings_##screen_type(const std::string &baseFocus, std::vector<std::string> &focusStrings, VIEWSCREEN(screen_type) *screen)
DEFINE_GET_FOCUS_STRING_HANDLER(title)
{
if (screen->managing_mods)
focusStrings.push_back(baseFocus + "/Mods");
else if (game->main_interface.settings.open)
focusStrings.push_back(baseFocus + "/Settings");
if (focusStrings.empty())
focusStrings.push_back(baseFocus + "/Default");
}
DEFINE_GET_FOCUS_STRING_HANDLER(new_region)
{
if (screen->raw_load)
focusStrings.push_back(baseFocus + "/Loading");
else if (screen->doing_mods)
focusStrings.push_back(baseFocus + "/Mods");
else if (screen->doing_simple_params)
focusStrings.push_back(baseFocus + "/Basic");
else if (screen->doing_params)
focusStrings.push_back(baseFocus + "/Advanced");
if (focusStrings.empty())
focusStrings.push_back(baseFocus);
}
DEFINE_GET_FOCUS_STRING_HANDLER(new_arena)
{
if (screen->raw_load)
focusStrings.push_back(baseFocus + "/Loading");
else if (screen->doing_mods)
focusStrings.push_back(baseFocus + "/Mods");
if (focusStrings.empty())
focusStrings.push_back(baseFocus);
}
DEFINE_GET_FOCUS_STRING_HANDLER(choose_start_site)
{
if (screen->doing_site_finder)
focusStrings.push_back(baseFocus + "/SiteFinder");
else if (screen->choosing_civilization)
focusStrings.push_back(baseFocus + "/ChooseCiv");
else if (screen->choosing_reclaim)
focusStrings.push_back(baseFocus + "/Reclaim");
if (focusStrings.empty())
focusStrings.push_back(baseFocus);
}
DEFINE_GET_FOCUS_STRING_HANDLER(setupdwarfgame)
{
if (screen->doing_custom_settings)
focusStrings.push_back(baseFocus + "/CustomSettings");
else if (game->main_interface.options.open)
focusStrings.push_back(baseFocus + "/Abort");
else if (screen->initial_selection == 1)
focusStrings.push_back(baseFocus + "/Default");
else if (game->main_interface.name_creator.open) {
switch (game->main_interface.name_creator.context) {
case df::name_creator_context_type::EMBARK_FORT_NAME:
focusStrings.push_back(baseFocus + "/FortName");
break;
case df::name_creator_context_type::EMBARK_GROUP_NAME:
focusStrings.push_back(baseFocus + "/GroupName");
break;
case df::name_creator_context_type::IMAGE_CREATOR_NAME:
focusStrings.push_back(baseFocus + "/ImageName");
break;
default:
break;
}
}
else if (game->main_interface.image_creator.open) {
focusStrings.push_back(baseFocus + "/GroupSymbol");
}
else if (screen->viewing_objections != 0)
focusStrings.push_back(baseFocus + "/Objections");
else {
switch (screen->mode) {
case 0: focusStrings.push_back(baseFocus + "/Dwarves"); break;
case 1: focusStrings.push_back(baseFocus + "/Items"); break;
case 2: focusStrings.push_back(baseFocus + "/Animals"); break;
default:
break;
}
}
if (focusStrings.empty())
focusStrings.push_back(baseFocus + "/Default");
}
DEFINE_GET_FOCUS_STRING_HANDLER(legends)
{
if (screen->init_stage != -1)
focusStrings.push_back(baseFocus + "/Loading");
else if (screen->page.size() <= 1)
focusStrings.push_back(baseFocus + "/Default");
else
focusStrings.push_back(baseFocus + '/' + screen->page[screen->active_page_index]->header);
}
DEFINE_GET_FOCUS_STRING_HANDLER(world)
{
focusStrings.push_back(baseFocus + '/' + enum_item_key(screen->view_mode));
}
static bool widget_is_visible(df::widget * w) {
return w && w->flag.bits.VISIBILITY_VISIBLE;
}
static size_t get_num_children(df::widget * w) {
if (!w)
return 0;
df::widget_container *container = virtual_cast<df::widget_container>(w);
if (!container)
return 0;
return container->children.size();
}
static df::widget * get_visible_child(df::widget *parent) {
df::widget_container *container = virtual_cast<df::widget_container>(parent);
if (!container)
return NULL;
for (auto child : container->children) {
if (widget_is_visible(child.get()))
return child.get();
}
return NULL;
}
static df::widget_container * get_visible_child_container(df::widget *parent) {
df::widget_container *container = virtual_cast<df::widget_container>(parent);
if (!container)
return NULL;
for (auto child : container->children) {
if (widget_is_visible(child.get()))
return virtual_cast<df::widget_container>(child.get());
}
return NULL;
}
static string get_building_custom_name(df::building_workshopst * bld) {
if (bld->type != df::workshop_type::Custom)
return "";
if (auto bld_def = vector_get(world->raws.buildings.workshops, bld->custom_type))
return bld_def->code + '/';
return "";
}
static string get_building_custom_name(df::building_furnacest * bld) {
if (bld->type != df::furnace_type::Custom)
return "";
if (auto bld_def = vector_get(world->raws.buildings.furnaces, bld->custom_type))
return bld_def->code + '/';
return "";
}
static string get_building_custom_name(df::building_trapst * bld) {
return "";
}
template<typename T>
static void add_profile_tab_focus_string(
vector<string> & focusStrings, const string & base, T * bld)
{
string fs = base + '/' + get_building_custom_name(bld);
switch (game->main_interface.view_sheets.active_sub_tab) {
case 0: fs += "Tasks"; break;
case 1: fs += "Workers"; break;
case 2: fs += "WorkOrders"; break;
default:
return;
}
focusStrings.push_back(fs);
}
static void add_main_interface_focus_strings(const string &baseFocus, vector<string> &focusStrings) {
std::string newFocusString;
if (game->main_interface.main_designation_selected != -1) {
newFocusString = baseFocus;
newFocusString += "/Designate/" + enum_item_key(game->main_interface.main_designation_selected);
focusStrings.push_back(newFocusString);
}
if (get_visible_child(&game->main_interface.announcements.stack)) {
focusStrings.push_back(baseFocus + "/Announcements");
}
if (game->main_interface.info.open) {
newFocusString = baseFocus;
newFocusString += "/Info";
newFocusString += '/' + enum_item_key(game->main_interface.info.current_mode);
switch(game->main_interface.info.current_mode) {
case df::enums::info_interface_mode_type::CREATURES:
{
auto tab = get_visible_child_container(Gui::getWidget(&game->main_interface.info.creatures, "Tabs"));
if (!tab) {
WARN(gui).print("Info tab widget not found\n");
} else if (tab->name == "Citizens") {
if (tab->children.size() > 1)
newFocusString += "/ActivityDetails";
else
newFocusString += "/CITIZEN";
} else if (tab->name == "Pets/Livestock") {
if (Gui::getWidget(tab, "Overall training"))
newFocusString += "/OverallTraining";
else if (Gui::getWidget(tab, "Trainer"))
newFocusString += "/AddingTrainer";
else if (Gui::getWidget(tab, "Hunting assignment"))
newFocusString += "/AssignWorkAnimal";
else
newFocusString += "/PET";
} else if (tab->name == "Other") {
newFocusString += "/OTHER";
} else if (tab->name == "Dead/Missing") {
newFocusString += "/DECEASED";
}
break;
}
case df::enums::info_interface_mode_type::BUILDINGS:
newFocusString += '/' + enum_item_key(game->main_interface.info.buildings.mode);
break;
case df::enums::info_interface_mode_type::LABOR:
{
auto tab = get_visible_child(Gui::getWidget(&game->main_interface.info.labor, "Tabs"));
if (!tab) {
WARN(gui).print("Labor tab widget not found\n");
} else if (tab->name == "Work Details") {
newFocusString += "/WORK_DETAILS";
auto rp = Gui::getWidget(virtual_cast<df::labor_work_details_interfacest>(tab), "Right panel");
if (get_num_children(rp) == 2)
newFocusString += "/Details";
else
newFocusString += "/Default";
} else if (tab->name == "Standing orders") {
newFocusString += "/STANDING_ORDERS";
auto lsoi = virtual_cast<df::labor_standing_orders_interfacest>(tab);
newFocusString += '/' + enum_item_key(lsoi->current_category);
} else if (tab->name == "Kitchen") {
newFocusString += "/KITCHEN";
auto lki = virtual_cast<df::labor_kitchen_interfacest>(tab);
newFocusString += '/' + enum_item_key(lki->current_category);
} else if (tab->name == "Stone use") {
newFocusString += "/STONE_USE";
auto lsui = virtual_cast<df::labor_stone_use_interfacest>(tab);
newFocusString += '/' + enum_item_key(lsui->current_category);
}
break;
}
case df::enums::info_interface_mode_type::ARTIFACTS:
newFocusString += '/' + enum_item_key(game->main_interface.info.artifacts.mode);
break;
case df::enums::info_interface_mode_type::JUSTICE:
{
auto tab = get_visible_child(Gui::getWidget(&game->main_interface.info.justice, "Tabs"));
if (!tab) {
WARN(gui).print("Justice tab widget not found\n");
} else if (tab->name == "Open cases") {
auto * container_tab = virtual_cast<df::widget_container>(tab);
auto * right_panel = container_tab ?
virtual_cast<df::widget_container>(Gui::getWidget(container_tab, "Right panel")) :
NULL;
bool is_valid = right_panel && right_panel->children.size() > 1;
if (is_valid && right_panel->children[1]->name == "Interrogate")
newFocusString += "/Interrogating";
else if (is_valid && right_panel->children[1]->name == "Convict")
newFocusString += "/Convicting";
else
newFocusString += "/OPEN_CASES";
} else if (tab->name == "Closed cases") {
newFocusString += "/CLOSED_CASES";
} else if (tab->name == "Cold cases") {
auto * container_tab = virtual_cast<df::widget_container>(tab);
auto * right_panel = container_tab ?
virtual_cast<df::widget_container>(Gui::getWidget(container_tab, "Right panel")) :
NULL;
bool is_valid = right_panel && right_panel->children.size() > 1;
if (is_valid && right_panel->children[1]->name == "Interrogate")
newFocusString += "/Interrogating";
else if (is_valid && right_panel->children[1]->name == "Convict")
newFocusString += "/Convicting";
else
newFocusString += "/COLD_CASES";
} else if (tab->name == "Fortress guard") {
newFocusString += "/FORTRESS_GUARD";
} else if (tab->name == "Convicts") {
newFocusString += "/CONVICTS";
} else if (tab->name == "Intelligence") {
newFocusString += "/COUNTERINTELLIGENCE";
}
break;
}
case df::enums::info_interface_mode_type::WORK_ORDERS:
if (game->main_interface.info.work_orders.conditions.open) {
newFocusString += "/Conditions";
if (game->main_interface.info.work_orders.conditions.change_type != df::work_order_condition_change_type::NONE)
newFocusString += '/' + enum_item_key(game->main_interface.info.work_orders.conditions.change_type);
else
newFocusString += "/Default";
}
else if (game->main_interface.create_work_order.open)
newFocusString += "/Create";
else
newFocusString += "/Default";
break;
case df::enums::info_interface_mode_type::ADMINISTRATORS:
if (game->main_interface.info.administrators.choosing_candidate)
newFocusString += "/Candidates";
else if (game->main_interface.info.administrators.assigning_symbol)
newFocusString += "/Symbols";
else
newFocusString += "/Default";
break;
default:
break;
}
focusStrings.push_back(newFocusString);
}
if (game->main_interface.view_sheets.open) {
newFocusString = baseFocus;
newFocusString += "/ViewSheets";
newFocusString += '/' + enum_item_key(game->main_interface.view_sheets.active_sheet);
switch (game->main_interface.view_sheets.active_sheet) {
case df::view_sheet_type::UNIT:
switch (game->main_interface.view_sheets.active_sub_tab) {
case 0: newFocusString += "/Overview"; break;
case 1: newFocusString += "/Items"; break;
case 2:
newFocusString += "/Health";
switch (game->main_interface.view_sheets.unit_health_active_tab) {
case 0: newFocusString += "/Status"; break;
case 1: newFocusString += "/Wounds"; break;
case 2: newFocusString += "/Treatment"; break;
case 3: newFocusString += "/History"; break;
case 4: newFocusString += "/Description"; break;
default: break;
}
break;
case 3:
newFocusString += "/Skills";
switch (game->main_interface.view_sheets.unit_skill_active_tab) {
case 0: newFocusString += "/Labor"; break;
case 1: newFocusString += "/Combat"; break;
case 2: newFocusString += "/Social"; break;
case 3: newFocusString += "/Other"; break;
case 4:
newFocusString += "/Knowledge";
if (game->main_interface.view_sheets.skill_description_raw_str.size())
newFocusString += "/Details";
else
newFocusString += "/Default";
break;
default: break;
}
break;
case 4: newFocusString += "/Rooms"; break;
case 5:
newFocusString += "/Labor";
switch (game->main_interface.view_sheets.unit_labor_active_tab) {
case 0: newFocusString += "/WorkDetails"; break;
case 1: newFocusString += "/Workshops"; break;
case 2: newFocusString += "/Locations"; break;
case 3: newFocusString += "/WorkAnimals"; break;
default: break;
}
break;
case 6: newFocusString += "/Relations"; break;
case 7: newFocusString += "/Groups"; break;
case 8:
newFocusString += "/Military";
switch (game->main_interface.view_sheets.unit_military_active_tab) {
case 0: newFocusString += "/Squad"; break;
case 1: newFocusString += "/Uniform"; break;
case 2: newFocusString += "/Kills"; break;
default: break;
}
break;
case 9:
newFocusString += "/Thoughts";
switch (game->main_interface.view_sheets.thoughts_active_tab) {
case 0: newFocusString += "/Recent"; break;
case 1: newFocusString += "/Memories"; break;
default: break;
}
break;
case 10:
newFocusString += "/Personality";
switch (game->main_interface.view_sheets.personality_active_tab) {
case 0: newFocusString += "/Traits"; break;
case 1: newFocusString += "/Values"; break;
case 2: newFocusString += "/Preferences"; break;
case 3: newFocusString += "/Needs"; break;
default: break;
}
break;
default:
break;
}
break;
case df::view_sheet_type::BUILDING:
if (game->main_interface.view_sheets.linking_lever)
newFocusString += "/LinkingLever";
else if (game->main_interface.stockpile_link.open && game->main_interface.stockpile_link.adding_new_link)
newFocusString += "/LinkingStockpile";
else if (auto bld = df::building::find(game->main_interface.view_sheets.viewing_bldid)) {
newFocusString += '/' + enum_item_key(bld->getType());
auto bld_type = bld->getType();
if (bld_type == df::enums::building_type::Trap) {
if (auto trap = strict_virtual_cast<df::building_trapst>(bld)) {
newFocusString += '/' + enum_item_key(trap->trap_type);
if (trap->trap_type == df::trap_type::Lever)
add_profile_tab_focus_string(focusStrings, newFocusString, trap);
}
} else if (bld_type == df::enums::building_type::Workshop) {
if (auto ws = strict_virtual_cast<df::building_workshopst>(bld)) {
newFocusString += '/' + enum_item_key(ws->type);
add_profile_tab_focus_string(focusStrings, newFocusString, ws);
}
} else if (bld_type == df::enums::building_type::Furnace) {
if (auto furn = strict_virtual_cast<df::building_furnacest>(bld)) {
newFocusString += '/' + enum_item_key(furn->type);
add_profile_tab_focus_string(focusStrings, newFocusString, furn);
}
}
if (game->main_interface.view_sheets.show_linked_buildings)
newFocusString += "/LinkedBuildings";
else
newFocusString += "/Items";
}
break;
default:
break;
}
focusStrings.push_back(newFocusString);
}
if (game->main_interface.bottom_mode_selected != -1) {
newFocusString = baseFocus;
switch(game->main_interface.bottom_mode_selected) {
case df::enums::main_bottom_mode_type::STOCKPILE:
newFocusString += "/Stockpile";
if (game->main_interface.stockpile.cur_bld) {
newFocusString += "/Some";
if (game->main_interface.stockpile_link.open)
newFocusString += "/Links";
else if (game->main_interface.stockpile_tools.open)
newFocusString += "/Containers";
else if (game->main_interface.custom_stockpile.open)
newFocusString += "/Customize";
else
newFocusString += "/Default";
}
break;
case df::enums::main_bottom_mode_type::STOCKPILE_PAINT:
newFocusString += "/Stockpile/Paint";
break;
case df::enums::main_bottom_mode_type::HAULING:
newFocusString += "/Hauling";
break;
case df::enums::main_bottom_mode_type::ZONE:
newFocusString += "/Zone";
if (game->main_interface.civzone.cur_bld) {
newFocusString += "/Some";
newFocusString += '/' + enum_item_key(game->main_interface.civzone.cur_bld->type);
}
break;
case df::enums::main_bottom_mode_type::ZONE_PAINT:
newFocusString += "/Zone/Paint/" + enum_item_key(game->main_interface.civzone.adding_new_type);
break;
case df::enums::main_bottom_mode_type::BURROW:
newFocusString += "/Burrow";
break;
case df::enums::main_bottom_mode_type::BURROW_PAINT:
newFocusString += "/Burrow/Paint";
break;
case df::enums::main_bottom_mode_type::BUILDING:
newFocusString += "/Building";
break;
case df::enums::main_bottom_mode_type::BUILDING_PLACEMENT:
newFocusString += "/Building/Placement";
break;
case df::enums::main_bottom_mode_type::BUILDING_PICK_MATERIALS:
newFocusString += "/Building/PickMaterials";
break;
default:
break;
}
focusStrings.push_back(newFocusString);
}
if (game->main_interface.trade.open) {
newFocusString = baseFocus;
newFocusString += "/Trade";
if (game->main_interface.trade.choosing_merchant)
newFocusString += "/ChoosingMerchant";
else
newFocusString += "/Default";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.job_details.open) {
newFocusString = baseFocus;
newFocusString += "/JobDetails/" + enum_item_key(game->main_interface.job_details.context);
focusStrings.push_back(newFocusString);
}
if (game->main_interface.assign_trade.open) {
newFocusString = baseFocus;
newFocusString += "/AssignTrade";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.diplomacy.open) {
newFocusString = baseFocus;
newFocusString += "/Diplomacy";
if (game->main_interface.diplomacy.taking_requests)
newFocusString += "/Requests";
else if (game->main_interface.diplomacy.selecting_land_holder_position)
newFocusString += "/ElevateLandHolder";
else
newFocusString += "/Default";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.petitions.open) {
newFocusString = baseFocus;
newFocusString += "/Petitions";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.stocks.open) {
newFocusString = baseFocus;
newFocusString += "/Stocks";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.assign_display_item.open) {
newFocusString = baseFocus;
newFocusString += "/AssignDisplayItem";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.name_creator.open) {
newFocusString = baseFocus;
newFocusString += "/NameCreator";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.image_creator.open) {
newFocusString = baseFocus;
newFocusString += "/ImageCreator";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.unit_selector.flag.bits.VISIBILITY_ACTIVE) {
newFocusString = baseFocus;
newFocusString += "/UnitSelector/";
newFocusString += enum_item_key(game->main_interface.unit_selector.context);
focusStrings.push_back(newFocusString);
}
if (game->main_interface.announcement_alert.open) {
newFocusString = baseFocus;
newFocusString += "/AnnouncementAlert";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.custom_symbol.open) {
newFocusString = baseFocus;
newFocusString += "/CustomSymbol";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.patrol_routes.open) {
newFocusString = baseFocus;
newFocusString += "/PatrolRoutes";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.squad_selector.open) {
newFocusString = baseFocus;
newFocusString += "/SquadSelector";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.burrow_selector.open) {
newFocusString = baseFocus;
newFocusString += "/BurrowSelector";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.location_selector.open) {
newFocusString = baseFocus;
newFocusString += "/LocationSelector/";
if (game->main_interface.location_selector.choosing_temple_religious_practice)
newFocusString += "Temple";
else if (game->main_interface.location_selector.choosing_craft_guild)
newFocusString += "Guildhall";
else
newFocusString += "Default";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.location_details.open) {
newFocusString = baseFocus;
newFocusString += "/LocationDetails";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.hauling_stop_conditions.open) {
newFocusString = baseFocus;
newFocusString += "/HaulingStopConditions";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.assign_vehicle.open) {
newFocusString = baseFocus;
newFocusString += "/AssignVehicle";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.create_squad.open) {
newFocusString = baseFocus;
newFocusString += "/CreateSquad";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.squads.open) {
newFocusString = baseFocus;
newFocusString += "/Squads";
if (game->main_interface.squads.editing_squad_schedule_id >= 0) {
newFocusString += "/EditingSchedule";
} else if (game->main_interface.squad_schedule.open) {
newFocusString += "/Schedule";
} else if (game->main_interface.squad_equipment.open) {
newFocusString += "/Equipment";
if (game->main_interface.squad_equipment.customizing_equipment) {
newFocusString += "/Customizing";
if (game->main_interface.squad_equipment.cs_setting_material)
newFocusString += "/Material";
else if (game->main_interface.squad_equipment.cs_setting_color_pattern)
newFocusString += "/Color";
else
newFocusString += "/Default";
}
else
newFocusString += "/Default";
} else {
newFocusString += "/Default";
}
focusStrings.push_back(newFocusString);
}
if (game->main_interface.assign_uniform.open) {
newFocusString = baseFocus;
newFocusString += "/AssignUniform";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.hotkey.open) {
newFocusString = baseFocus;
newFocusString += "/Hotkey";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.options.open) {
newFocusString = baseFocus;
newFocusString += "/Options";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.help.open) {
newFocusString = baseFocus;
newFocusString += "/Help";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.settings.open) {
newFocusString = baseFocus;
newFocusString += "/Settings";
newFocusString += '/' + enum_item_key(game->main_interface.settings.current_mode);
if (game->main_interface.settings.current_mode == df::settings_tab_type::DIFFICULTY) {
if (game->main_interface.settings.doing_custom_settings)
newFocusString += "/CustomSettings";
else
newFocusString += "/Default";
}
focusStrings.push_back(newFocusString);
}
if (game->main_interface.adventure.aim_projectile.open) {
focusStrings.push_back(baseFocus + "/AimProjectile");
}
if (game->main_interface.adventure.announcements.open) {
focusStrings.push_back(baseFocus + "/Announcements");
}
if (game->main_interface.adventure.attack.open) {
focusStrings.push_back(baseFocus + "/Attack");
}
if (game->main_interface.adventure.combat_pref.open) {
focusStrings.push_back(baseFocus + "/CombatPref");
}
if (game->main_interface.adventure.companions.open) {
focusStrings.push_back(baseFocus + "/Companions");
}
if (game->main_interface.adventure.conversation.open) {
focusStrings.push_back(baseFocus + "/Conversation");
}
if (game->main_interface.adventure.inventory.open) {
focusStrings.push_back(baseFocus + "/Inventory");
}
if (game->main_interface.adventure.jump.open) {
focusStrings.push_back(baseFocus + "/Jump");
}
if (game->main_interface.adventure.look.open) {
focusStrings.push_back(baseFocus + "/Look");
}
if (game->main_interface.adventure.movement_options.open) {
focusStrings.push_back(baseFocus + "/MovementOptions");
}
if (game->main_interface.adventure.option_list.open) {
focusStrings.push_back(baseFocus + "/OptionList");
}
if (game->main_interface.adventure.perform.open) {
focusStrings.push_back(baseFocus + "/Perform");
}
if (game->main_interface.adventure.sleep.open) {
focusStrings.push_back(baseFocus + "/Sleep");
}
}
DEFINE_GET_FOCUS_STRING_HANDLER(dwarfmode)
{
std::string newFocusString;
if (df::global::gametype && !World::isFortressMode()) {
newFocusString = baseFocus;
newFocusString += '/' + enum_item_key(*df::global::gametype);
if (*df::global::gametype == df::game_type::DWARF_ARENA) {
if (game->main_interface.bottom_mode_selected != df::main_bottom_mode_type::NONE)
newFocusString += "/Paint/" + enum_item_key(game->main_interface.bottom_mode_selected);
else if (game->main_interface.arena_unit.open)
newFocusString += "/ConfigureUnit";
else if (game->main_interface.arena_tree.open)
newFocusString += "/ConfigureTree";
else
newFocusString += "/Default";
}
focusStrings.push_back(newFocusString);
}
add_main_interface_focus_strings(baseFocus, focusStrings);
static const string squads_default = "dwarfmode/Squads/Default";
if (!focusStrings.size() || (focusStrings.size() == 1 && focusStrings[0] == squads_default)) {
focusStrings.push_back(baseFocus + "/Default");
}
}
DEFINE_GET_FOCUS_STRING_HANDLER(dungeonmode)
{
std::string newFocusString;
if (df::global::gametype && !World::isAdventureMode()) {
newFocusString = baseFocus;
newFocusString += '/' + enum_item_key(*df::global::gametype);
focusStrings.push_back(newFocusString);
}
add_main_interface_focus_strings(baseFocus, focusStrings);
if (!focusStrings.size()) {
focusStrings.push_back(baseFocus + '/' + enum_item_key(df::global::adventure->menu));
}
}
static std::unordered_map<df::viewscreen *, vector<string>> cached_focus_strings;
void Gui::clearFocusStringCache() {
cached_focus_strings.clear();
}
bool Gui::matchFocusString(std::string focus_string, df::viewscreen *top) {
if (!top)
top = getCurViewscreen(true);
if (!cached_focus_strings.contains(top))
cached_focus_strings[top] = getFocusStrings(top);
vector<string> &cached = cached_focus_strings[top];
return std::find_if(cached.begin(), cached.end(), [&focus_string](const std::string &item) {
return prefix_matches(focus_string, item);
}) != cached.end();
}
static void push_dfhack_focus_string(dfhack_viewscreen *vs, std::vector<std::string> &focusStrings)
{
auto name = vs->getFocusString();
if (name.empty())
name = "dfhack";
else if (string::npos == name.find("dfhack/"))
name = "dfhack/" + name;
focusStrings.push_back(name);
}
std::vector<std::string> Gui::getFocusStrings(df::viewscreen* top)
{
std::vector<std::string> focusStrings;
if (!top)
return focusStrings;
if (dfhack_viewscreen::is_instance(top))
{
dfhack_viewscreen *vs = static_cast<dfhack_viewscreen*>(top);
if (vs->isFocused())
{
push_dfhack_focus_string(vs, focusStrings);
return focusStrings;
}
top = Gui::getDFViewscreen(top);
if (dfhack_viewscreen::is_instance(top))
{
push_dfhack_focus_string(static_cast<dfhack_viewscreen*>(top), focusStrings);
return focusStrings;
}
}
if (const virtual_identity *id = virtual_identity::get(top))
{
std::string name = getNameChunk(id, 11, 2);
auto handler = map_find(getFocusStringsHandlers, id);
if (handler)
handler(name, focusStrings, top);
}
if (!focusStrings.size())
{
Core &core = Core::getInstance();
std::string name = core.p->readClassName(*(void**)top);
focusStrings.push_back(name.substr(11, name.size()-11-2));
}
return focusStrings;
}
// Predefined common guard functions
bool Gui::default_hotkey(df::viewscreen *top)
{
return World::isFortressMode() || World::isAdventureMode();
}
bool Gui::anywhere_hotkey(df::viewscreen *) {
return true;
}