/
DaggerfallTravelMapWindow.cs
1867 lines (1610 loc) · 80.5 KB
/
DaggerfallTravelMapWindow.cs
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
// Project: Daggerfall Unity
// Copyright: Copyright (C) 2009-2022 Daggerfall Workshop
// Web Site: http://www.dfworkshop.net
// License: MIT License (http://www.opensource.org/licenses/mit-license.php)
// Source Code: https://github.com/Interkarma/daggerfall-unity
// Original Author: Lypyl (lypyl@dfworkshop.net), Gavin Clayton (interkarma@dfworkshop.net)
// Contributors: Hazelnut, TheLacus
//
// Notes:
//
using UnityEngine;
using System;
using System.Linq;
using System.IO;
using DaggerfallConnect;
using DaggerfallConnect.Utility;
using DaggerfallConnect.Arena2;
using DaggerfallWorkshop.Utility;
using DaggerfallWorkshop.Game.UserInterface;
using System.Collections.Generic;
using Wenzil.Console;
using Wenzil.Console.Commands;
using DaggerfallWorkshop.Game.Utility;
using DaggerfallWorkshop.Game.Serialization;
using DaggerfallWorkshop.Utility.AssetInjection;
using DaggerfallWorkshop.Game.Questing;
namespace DaggerfallWorkshop.Game.UserInterfaceWindows
{
/// <summary>
/// Implements Daggerfall's travel map.
/// </summary>
public class DaggerfallTravelMapWindow : DaggerfallPopupWindow
{
#region Fields
protected const int betonyIndex = 19;
protected const string overworldImgName = "TRAV0I00.IMG";
protected const string regionPickerImgName = "TRAV0I01.IMG";
protected const string findAtButtonImgName = "TRAV0I03.IMG";
protected const string locationFilterButtonEnabledImgName = "TRAV01I0.IMG";
protected const string locationFilterButtonDisabledImgName = "TRAV01I1.IMG";
protected const string downArrowImgName = "TRAVAI05.IMG";
protected const string upArrowImgName = "TRAVBI05.IMG";
protected const string rightArrowImgName = "TRAVCI05.IMG";
protected const string leftArrowImgName = "TRAVDI05.IMG";
protected const string regionBorderImgName = "MBRD00I0.IMG";
protected const string colorPaletteColName = "FMAP_PAL.COL";
protected const int regionPanelOffset = 12;
protected const int identifyFlashCount = 4;
protected const int identifyFlashCountSelected = 2;
protected const float identifyFlashInterval = 0.5f;
protected const int dotsOutlineThickness = 1;
protected Color32 dotOutlineColor = new Color32(0, 0, 0, 128);
protected Vector2[] outlineDisplacements =
{
new Vector2(-0.5f, -0f),
new Vector2(0f, -0.5f),
new Vector2(0f, 0.5f),
new Vector2(0.5f, 0f)
};
protected DaggerfallTravelPopUp popUp;
protected Dictionary<string, Vector2> offsetLookup = new Dictionary<string, Vector2>();
protected string[] selectedRegionMapNames;
protected Place gotoPlace; // Used by journal click-through to fast travel to a specific quest location
protected DFBitmap regionPickerBitmap;
protected DFRegion currentDFRegion;
protected int currentDFRegionIndex = -1;
protected int lastQueryLocationIndex = -1;
protected string lastQueryLocationName;
protected ContentReader.MapSummary locationSummary;
protected KeyCode toggleClosedBinding;
protected Panel borderPanel;
protected Panel regionTextureOverlayPanel;
protected Panel[] regionLocationDotsOutlinesOverlayPanel;
protected Panel regionLocationDotsOverlayPanel;
protected Panel playerRegionOverlayPanel;
protected Panel identifyOverlayPanel;
protected TextLabel regionLabel;
protected Texture2D overworldTexture;
protected Texture2D identifyTexture;
protected Texture2D locationDotsTexture;
protected Texture2D locationDotsOutlineTexture;
protected Texture2D findButtonTexture;
protected Texture2D atButtonTexture;
protected Texture2D dungeonFilterButtonEnabled;
protected Texture2D dungeonFilterButtonDisabled;
protected Texture2D templesFilterButtonEnabled;
protected Texture2D templesFilterButtonDisabled;
protected Texture2D homesFilterButtonEnabled;
protected Texture2D homesFilterButtonDisabled;
protected Texture2D townsFilterButtonEnabled;
protected Texture2D townsFilterButtonDisabled;
protected Texture2D upArrowTexture;
protected Texture2D downArrowTexture;
protected Texture2D leftArrowTexture;
protected Texture2D rightArrowTexture;
protected Texture2D borderTexture;
protected Button findButton;
protected Button atButton;
protected Button exitButton;
protected Button horizontalArrowButton = new Button();
protected Button verticalArrowButton = new Button();
protected Button dungeonsFilterButton = new Button();
protected Button templesFilterButton = new Button();
protected Button homesFilterButton = new Button();
protected Button townsFilterButton = new Button();
protected Rect playerRegionOverlayPanelRect = new Rect(0, 0, 320, 200);
protected Rect regionTextureOverlayPanelRect = new Rect(0, regionPanelOffset, 320, 160);
protected Rect dungeonsFilterButtonSrcRect = new Rect(0, 0, 99, 11);
protected Rect templesFilterButtonSrcRect = new Rect(0, 11, 99, 11);
protected Rect homesFilterButtonSrcRect = new Rect(99, 0, 80, 11);
protected Rect townsFilterButtonSrcRect = new Rect(99, 11, 80, 11);
protected Rect findButtonRect = new Rect(0, 0, 45, 11);
protected Rect atButtonRect = new Rect(0, 11, 45, 11);
protected Color32[] identifyPixelBuffer;
protected Color32[] locationDotsPixelBuffer;
protected Color32[] locationDotsOutlinePixelBuffer;
protected Color32[] locationPixelColors; // Pixel colors for different location types
protected Color identifyFlashColor;
protected int zoomfactor = 2;
protected int mouseOverRegion = -1;
protected int selectedRegion = -1;
protected int mapIndex = 0; // Current index of loaded map from selectedRegionMapNames
protected float scale = 1.0f;
protected float identifyLastChangeTime = 0;
protected float identifyChanges = 0;
protected bool identifyState = false;
protected bool identifying = false;
protected bool locationSelected = false;
protected bool findingLocation = false;
protected bool zoom = false; // Toggles zoom mode
protected bool teleportationTravel = false; // Indicates travel should be by teleportation
protected static bool revealUndiscoveredLocations; // Flag used to indicate cheat/debugging mode for revealing undiscovered locations
protected bool filterDungeons = false;
protected bool filterTemples = false;
protected bool filterHomes = false;
protected bool filterTowns = false;
protected Vector2 lastMousePos = Vector2.zero;
protected Vector2 zoomOffset = Vector2.zero;
protected Vector2 zoomPosition = Vector2.zero;
protected readonly Dictionary<string, Texture2D> regionTextures = new Dictionary<string, Texture2D>();
protected readonly Dictionary<int, Texture2D> importedOverlays = new Dictionary<int, Texture2D>();
protected readonly int maxMatchingResults = 1000;
protected string distanceRegionName = null;
protected IDistance distance;
// Populated with localized names whenever player searches or lists inside this region
// Used to complete search and list on localized names over canonical names
protected Dictionary<string, int> localizedMapNameLookup = new Dictionary<string, int>();
#endregion
#region Properties
protected string RegionImgName { get; set; }
protected bool HasMultipleMaps
{
get { return (selectedRegionMapNames.Length > 1) ? true : false; }
}
protected bool HasVerticalMaps
{
get { return (selectedRegionMapNames.Length > 2) ? true : false; }
}
protected bool RegionSelected
{
get { return selectedRegion != -1; }
}
protected bool MouseOverRegion
{
get { return mouseOverRegion != -1; }
}
protected bool MouseOverOtherRegion
{
get { return RegionSelected && (selectedRegion != mouseOverRegion); }
}
protected bool FindingLocation
{
get { return identifying && findingLocation && RegionSelected; }
}
public ContentReader.MapSummary LocationSummary { get => locationSummary; }
public void ActivateTeleportationTravel()
{
teleportationTravel = true;
}
public void GotoPlace(Place place)
{
gotoPlace = place;
}
#endregion
#region Constructors
public DaggerfallTravelMapWindow(IUserInterfaceManager uiManager)
: base(uiManager)
{
// Register console commands
try
{
TravelMapConsoleCommands.RegisterCommands();
}
catch (Exception ex)
{
Debug.LogError(string.Format("Error Registering Travelmap Console commands: {0}", ex.Message));
}
// Prevent duplicate close calls with base class's exitKey (Escape)
AllowCancel = false;
}
#endregion
#region User Interface
protected override void Setup()
{
ParentPanel.BackgroundColor = Color.black;
// Set location pixel colors and identify flash color from palette file
DFPalette colors = new DFPalette();
if (!colors.Load(Path.Combine(DaggerfallUnity.Instance.Arena2Path, colorPaletteColName)))
throw new Exception("DaggerfallTravelMap: Could not load color palette.");
locationPixelColors = new Color32[]
{
new Color32(colors.GetRed(237), colors.GetGreen(237), colors.GetBlue(237), 255), //dunglab (R215, G119, B39)
new Color32(colors.GetRed(240), colors.GetGreen(240), colors.GetBlue(240), 255), //dungkeep (R191, G87, B27)
new Color32(colors.GetRed(243), colors.GetGreen(243), colors.GetBlue(243), 255), //dungruin (R171, G51, B15)
new Color32(colors.GetRed(246), colors.GetGreen(246), colors.GetBlue(246), 255), //graveyards (R147, G15, B7)
new Color32(colors.GetRed(0), colors.GetGreen(0), colors.GetBlue(0), 255), //coven (R15, G15, B15)
new Color32(colors.GetRed(53), colors.GetGreen(53), colors.GetBlue(53), 255), //farms (R165, G100, B70)
new Color32(colors.GetRed(51), colors.GetGreen(51), colors.GetBlue(51), 255), //wealthy (R193, G133, B100)
new Color32(colors.GetRed(55), colors.GetGreen(55), colors.GetBlue(55), 255), //poor (R140, G86, B55)
new Color32(colors.GetRed(96), colors.GetGreen(96), colors.GetBlue(96), 255), //temple (R176, G205, B255)
new Color32(colors.GetRed(101), colors.GetGreen(101), colors.GetBlue(101), 255), //cult (R68, G124, B192)
new Color32(colors.GetRed(39), colors.GetGreen(39), colors.GetBlue(39), 255), //tavern (R126, G81, B89)
new Color32(colors.GetRed(33), colors.GetGreen(33), colors.GetBlue(33), 255), //city (R220, G177, B177)
new Color32(colors.GetRed(35), colors.GetGreen(35), colors.GetBlue(35), 255), //hamlet (R188, G138, B138)
new Color32(colors.GetRed(37), colors.GetGreen(37), colors.GetBlue(37), 255), //village (R155, G105, B106)
};
identifyFlashColor = new Color32(colors.GetRed(244), colors.GetGreen(244), colors.GetBlue(244), 255); // (R163, G39, B15)
// Populate the offset dict
PopulateRegionOffsetDict();
// Load picker colours
regionPickerBitmap = DaggerfallUI.GetImgBitmap(regionPickerImgName);
// Add region label
regionLabel = DaggerfallUI.AddTextLabel(DaggerfallUI.DefaultFont, new Vector2(0, 2), string.Empty, NativePanel);
regionLabel.HorizontalAlignment = HorizontalAlignment.Center;
// Handle clicks
NativePanel.OnMouseClick += ClickHandler;
// Setup buttons for first time
LoadButtonTextures();
SetupButtons();
UpdateSearchButtons();
// Region overlay panel
regionTextureOverlayPanel = DaggerfallUI.AddPanel(regionTextureOverlayPanelRect, NativePanel);
regionTextureOverlayPanel.Enabled = false;
// Location dots overlay panel
if (DaggerfallUnity.Settings.TravelMapLocationsOutline)
{
regionLocationDotsOutlinesOverlayPanel = new Panel[outlineDisplacements.Length];
for (int i = 0; i < outlineDisplacements.Length; i++)
{
Rect modifedPanelRect = regionTextureOverlayPanelRect;
modifedPanelRect.x += outlineDisplacements[i].x * dotsOutlineThickness / NativePanel.LocalScale.x;
modifedPanelRect.y += outlineDisplacements[i].y * dotsOutlineThickness / NativePanel.LocalScale.y;
regionLocationDotsOutlinesOverlayPanel[i] = DaggerfallUI.AddPanel(modifedPanelRect, NativePanel);
regionLocationDotsOutlinesOverlayPanel[i].Enabled = false;
}
}
regionLocationDotsOverlayPanel = DaggerfallUI.AddPanel(regionTextureOverlayPanelRect, NativePanel);
regionLocationDotsOverlayPanel.Enabled = false;
// Current region overlay panel
playerRegionOverlayPanel = DaggerfallUI.AddPanel(playerRegionOverlayPanelRect, NativePanel);
playerRegionOverlayPanel.Enabled = false;
// Overlay for the region panel
identifyOverlayPanel = DaggerfallUI.AddPanel(regionTextureOverlayPanelRect, NativePanel);
identifyOverlayPanel.Enabled = false;
// Borders around the region maps
borderTexture = DaggerfallUI.GetTextureFromImg(regionBorderImgName);
borderPanel = DaggerfallUI.AddPanel(new Rect(new Vector2(0, regionTextureOverlayPanelRect.position.y), regionTextureOverlayPanelRect.size), NativePanel);
borderPanel.BackgroundTexture = borderTexture;
borderPanel.Enabled = false;
// Load native overworld texture
overworldTexture = ImageReader.GetTexture(overworldImgName);
NativePanel.BackgroundTexture = overworldTexture;
// Setup pixel buffer and texture for region/location identify
identifyPixelBuffer = new Color32[(int)regionTextureOverlayPanelRect.width * (int)regionTextureOverlayPanelRect.height];
identifyTexture = new Texture2D((int)regionTextureOverlayPanelRect.width, (int)regionTextureOverlayPanelRect.height, TextureFormat.ARGB32, false);
identifyTexture.filterMode = FilterMode.Point;
// Setup pixel buffer and texture for location dots overlay
locationDotsOutlinePixelBuffer = new Color32[(int)regionTextureOverlayPanelRect.width * (int)regionTextureOverlayPanelRect.height];
locationDotsPixelBuffer = new Color32[(int)regionTextureOverlayPanelRect.width * (int)regionTextureOverlayPanelRect.height];
locationDotsOutlineTexture = new Texture2D((int)regionTextureOverlayPanelRect.width, (int)regionTextureOverlayPanelRect.height, TextureFormat.ARGB32, false);
locationDotsOutlineTexture.filterMode = FilterMode.Point;
locationDotsTexture = new Texture2D((int)regionTextureOverlayPanelRect.width, (int)regionTextureOverlayPanelRect.height, TextureFormat.ARGB32, false);
locationDotsTexture.filterMode = FilterMode.Point;
// Load map names for player region
selectedRegionMapNames = GetRegionMapNames(GetPlayerRegion());
// Identify current region
StartIdentify();
UpdateIdentifyTextureForPlayerRegion();
}
public override void OnPush()
{
base.OnPush();
toggleClosedBinding = InputManager.Instance.GetBinding(InputManager.Actions.TravelMap);
if (IsSetup)
{
StartIdentify();
UpdateIdentifyTextureForPlayerRegion();
CloseRegionPanel();
}
}
public override void OnPop()
{
base.OnPop();
teleportationTravel = false;
findingLocation = false;
gotoPlace = null;
distanceRegionName = null;
distance = null;
}
public override void Update()
{
base.Update();
// Toggle window closed with same hotkey used to open it
if (InputManager.Instance.GetKeyUp(toggleClosedBinding) || InputManager.Instance.GetBackButtonUp())
{
if (RegionSelected)
CloseRegionPanel();
else
CloseWindow();
}
// Input handling
HotkeySequence.KeyModifiers keyModifiers = HotkeySequence.GetKeyboardKeyModifiers();
Vector2 currentMousePos = new Vector2((NativePanel.ScaledMousePosition.x), (NativePanel.ScaledMousePosition.y));
if (currentMousePos != lastMousePos)
{
lastMousePos = currentMousePos;
if (RegionSelected == true)
UpdateMouseOverLocation();
else
UpdateMouseOverRegion();
}
UpdateRegionLabel();
if (RegionSelected)
{
if (InputManager.Instance.GetMouseButtonUp(1))
{
// Zoom to mouse position
zoomPosition = currentMousePos;
zoom = !zoom;
ZoomMapTextures();
}
else if ((Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) && zoom && NativePanel.MouseOverComponent)
{
// Scrolling while zoomed in
zoomPosition = currentMousePos;
ZoomMapTextures();
}
if (DaggerfallShortcut.GetBinding(DaggerfallShortcut.Buttons.TravelMapList).IsUpWith(keyModifiers))
{
if (!RegionSelected || currentDFRegion.LocationCount < 1)
return;
string[] locations = GetCurrentRegionLocalizedMapNames().OrderBy(p => p).ToArray();
ShowLocationPicker(locations, true);
}
else if (DaggerfallShortcut.GetBinding(DaggerfallShortcut.Buttons.TravelMapFind).IsUpWith(keyModifiers))
FindlocationButtonClickHandler(null, Vector2.zero);
}
else
{
if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
{
if (identifying)
OpenRegionPanel(GetPlayerRegion());
}
}
// Show/hide identify panel when identify is running
identifyOverlayPanel.Enabled = identifying && identifyState;
AnimateIdentify();
// If a goto location specified, find it and ask if player wants to travel.
if (gotoPlace != null)
{
// Get localized name for search with fallback to canonical name
string localizedGotoPlaceName = TextManager.Instance.GetLocalizedLocationName(gotoPlace.SiteDetails.mapId, gotoPlace.SiteDetails.locationName);
// Open region and search for localizedGotoPlaceName
mouseOverRegion = gotoPlace.SiteDetails.regionIndex;
OpenRegionPanel(mouseOverRegion);
UpdateRegionLabel();
HandleLocationFindEvent(null, localizedGotoPlaceName);
gotoPlace = null;
}
}
#endregion
#region Setup
// Initial button setup
void SetupButtons()
{
// Exit button
exitButton = DaggerfallUI.AddButton(new Rect(278, 175, 39, 22), NativePanel);
exitButton.OnMouseClick += ExitButtonClickHandler;
// Find button
findButton = DaggerfallUI.AddButton(new Rect(3, 175, findButtonRect.width, findButtonRect.height), NativePanel);
findButton.BackgroundTexture = findButtonTexture;
findButton.OnMouseClick += FindlocationButtonClickHandler;
findButton.Enabled = false;
// I'm At button
atButton = DaggerfallUI.AddButton(new Rect(3, 186, atButtonRect.width, atButtonRect.height), NativePanel);
atButton.BackgroundTexture = atButtonTexture;
atButton.OnMouseClick += AtButtonClickHandler;
// Dungeons filter button
dungeonsFilterButton.Position = new Vector2(50, 175);
dungeonsFilterButton.Size = new Vector2(dungeonsFilterButtonSrcRect.width, dungeonsFilterButtonSrcRect.height);
dungeonsFilterButton.Name = "dungeonsFilterButton";
dungeonsFilterButton.OnMouseClick += FilterButtonClickHandler;
NativePanel.Components.Add(dungeonsFilterButton);
// Temples filter button
templesFilterButton.Position = new Vector2(50, 186);
templesFilterButton.Size = new Vector2(templesFilterButtonSrcRect.width, templesFilterButtonSrcRect.height);
templesFilterButton.Name = "templesFilterButton";
templesFilterButton.OnMouseClick += FilterButtonClickHandler;
NativePanel.Components.Add(templesFilterButton);
// Homes filter button
homesFilterButton.Position = new Vector2(149, 175);
homesFilterButton.Size = new Vector2(homesFilterButtonSrcRect.width, homesFilterButtonSrcRect.height);
homesFilterButton.Name = "homesFilterButton";
homesFilterButton.OnMouseClick += FilterButtonClickHandler;
NativePanel.Components.Add(homesFilterButton);
// Towns filter button
townsFilterButton.Position = new Vector2(149, 186);
townsFilterButton.Size = new Vector2(townsFilterButtonSrcRect.width, townsFilterButtonSrcRect.height);
townsFilterButton.Name = "townsFilterButton";
townsFilterButton.OnMouseClick += FilterButtonClickHandler;
NativePanel.Components.Add(townsFilterButton);
// Horizontal arrow button
horizontalArrowButton.Position = new Vector2(231, 176);
horizontalArrowButton.Size = new Vector2(22, 20);
horizontalArrowButton.Enabled = false;
NativePanel.Components.Add(horizontalArrowButton);
horizontalArrowButton.Name = "horizontalArrowButton";
horizontalArrowButton.OnMouseClick += ArrowButtonClickHandler;
// Vertical arrow button
verticalArrowButton.Position = new Vector2(254, 176);
verticalArrowButton.Size = new Vector2(22, 20);
verticalArrowButton.Enabled = false;
NativePanel.Components.Add(verticalArrowButton);
verticalArrowButton.Name = "verticalArrowButton";
verticalArrowButton.OnMouseClick += ArrowButtonClickHandler;
// Store toggle closed binding for this window
toggleClosedBinding = InputManager.Instance.GetBinding(InputManager.Actions.TravelMap);
}
protected virtual void SetupArrowButtons()
{
// Vertical arrow
if (selectedRegionMapNames.Length > 2)
{
verticalArrowButton.Enabled = true;
verticalArrowButton.BackgroundTexture = (mapIndex > 1) ? upArrowTexture : downArrowTexture;
}
else
verticalArrowButton.Enabled = false;
// Horizontal arrow
if (selectedRegionMapNames.Length > 1)
{
horizontalArrowButton.Enabled = true;
horizontalArrowButton.BackgroundTexture = (mapIndex % 2 == 0) ? rightArrowTexture : leftArrowTexture;
}
else
horizontalArrowButton.Enabled = false;
}
// Loads textures for buttons
void LoadButtonTextures()
{
Texture2D baselocationFilterButtonEnabledText = ImageReader.GetTexture(locationFilterButtonEnabledImgName);
Texture2D baselocationFilterButtonDisabledText = ImageReader.GetTexture(locationFilterButtonDisabledImgName);
DFSize baseSize = new DFSize(179, 22);
// Dungeons toggle button
dungeonFilterButtonEnabled = ImageReader.GetSubTexture(baselocationFilterButtonEnabledText, dungeonsFilterButtonSrcRect, baseSize);
dungeonFilterButtonDisabled = ImageReader.GetSubTexture(baselocationFilterButtonDisabledText, dungeonsFilterButtonSrcRect, baseSize);
// Dungeons toggle button
templesFilterButtonEnabled = ImageReader.GetSubTexture(baselocationFilterButtonEnabledText, templesFilterButtonSrcRect, baseSize);
templesFilterButtonDisabled = ImageReader.GetSubTexture(baselocationFilterButtonDisabledText, templesFilterButtonSrcRect, baseSize);
// Homes toggle button
homesFilterButtonEnabled = ImageReader.GetSubTexture(baselocationFilterButtonEnabledText, homesFilterButtonSrcRect, baseSize);
homesFilterButtonDisabled = ImageReader.GetSubTexture(baselocationFilterButtonDisabledText, homesFilterButtonSrcRect, baseSize);
// Towns toggle button
townsFilterButtonEnabled = ImageReader.GetSubTexture(baselocationFilterButtonEnabledText, townsFilterButtonSrcRect, baseSize);
townsFilterButtonDisabled = ImageReader.GetSubTexture(baselocationFilterButtonDisabledText, townsFilterButtonSrcRect, baseSize);
DFSize buttonsFullSize = new DFSize(45, 22);
findButtonTexture = ImageReader.GetTexture(findAtButtonImgName);
findButtonTexture = ImageReader.GetSubTexture(findButtonTexture, findButtonRect, buttonsFullSize);
atButtonTexture = ImageReader.GetTexture(findAtButtonImgName);
atButtonTexture = ImageReader.GetSubTexture(atButtonTexture, atButtonRect, buttonsFullSize);
// Arrows
upArrowTexture = ImageReader.GetTexture(upArrowImgName);
downArrowTexture = ImageReader.GetTexture(downArrowImgName);
leftArrowTexture = ImageReader.GetTexture(leftArrowImgName);
rightArrowTexture = ImageReader.GetTexture(rightArrowImgName);
}
// Populates offset dictionary for aligning top-left of map to map pixel coordinates.
// Most maps have a 1:1 pixel ratio with map cells. A couple of maps have a larger scale.
void PopulateRegionOffsetDict()
{
offsetLookup = new Dictionary<string, Vector2>();
offsetLookup.Add("FMAPAI00.IMG", new Vector2(212, 340));
offsetLookup.Add("FMAPBI00.IMG", new Vector2(322, 340));
offsetLookup.Add("FMAPAI01.IMG", new Vector2(583, 279));
offsetLookup.Add("FMAPBI01.IMG", new Vector2(680, 279));
offsetLookup.Add("FMAPCI01.IMG", new Vector2(583, 340));
offsetLookup.Add("FMAPDI01.IMG", new Vector2(680, 340));
offsetLookup.Add("FMAP0I05.IMG", new Vector2(381, 4));
offsetLookup.Add("FMAP0I09.IMG", new Vector2(525, 114));
offsetLookup.Add("FMAP0I11.IMG", new Vector2(437, 340));
offsetLookup.Add("FMAPAI16.IMG", new Vector2(578, 0));
offsetLookup.Add("FMAPBI16.IMG", new Vector2(680, 0));
offsetLookup.Add("FMAPCI16.IMG", new Vector2(578, 52));
offsetLookup.Add("FMAPDI16.IMG", new Vector2(680, 52));
offsetLookup.Add("FMAP0I17.IMG", new Vector2(39, 106));
offsetLookup.Add("FMAP0I18.IMG", new Vector2(20, 29));
offsetLookup.Add("FMAP0I19.IMG", new Vector2(80, 123)); // Betony scale different
offsetLookup.Add("FMAP0I20.IMG", new Vector2(217, 293));
offsetLookup.Add("FMAP0I21.IMG", new Vector2(263, 79));
offsetLookup.Add("FMAP0I22.IMG", new Vector2(548, 219));
offsetLookup.Add("FMAP0I23.IMG", new Vector2(680, 146));
offsetLookup.Add("FMAP0I26.IMG", new Vector2(680, 80));
offsetLookup.Add("FMAP0I32.IMG", new Vector2(41, 0));
offsetLookup.Add("FMAP0I33.IMG", new Vector2(660, 101));
offsetLookup.Add("FMAP0I34.IMG", new Vector2(578, 40));
offsetLookup.Add("FMAP0I35.IMG", new Vector2(525, 3));
offsetLookup.Add("FMAP0I36.IMG", new Vector2(440, 40));
offsetLookup.Add("FMAP0I37.IMG", new Vector2(448, 0));
offsetLookup.Add("FMAP0I38.IMG", new Vector2(366, 0));
offsetLookup.Add("FMAP0I39.IMG", new Vector2(300, 8));
offsetLookup.Add("FMAP0I40.IMG", new Vector2(202, 0));
offsetLookup.Add("FMAP0I41.IMG", new Vector2(223, 6));
offsetLookup.Add("FMAP0I42.IMG", new Vector2(148, 76));
offsetLookup.Add("FMAP0I43.IMG", new Vector2(15, 340));
offsetLookup.Add("FMAP0I44.IMG", new Vector2(61, 340));
offsetLookup.Add("FMAP0I45.IMG", new Vector2(86, 338));
offsetLookup.Add("FMAP0I46.IMG", new Vector2(132, 340));
offsetLookup.Add("FMAP0I47.IMG", new Vector2(344, 309));
offsetLookup.Add("FMAP0I48.IMG", new Vector2(381, 251));
offsetLookup.Add("FMAP0I49.IMG", new Vector2(553, 255));
offsetLookup.Add("FMAP0I50.IMG", new Vector2(661, 217));
offsetLookup.Add("FMAP0I51.IMG", new Vector2(672, 275));
offsetLookup.Add("FMAP0I52.IMG", new Vector2(680, 256));
offsetLookup.Add("FMAP0I53.IMG", new Vector2(680, 340));
offsetLookup.Add("FMAP0I54.IMG", new Vector2(491, 340));
offsetLookup.Add("FMAP0I55.IMG", new Vector2(293, 340));
offsetLookup.Add("FMAP0I56.IMG", new Vector2(263, 340));
offsetLookup.Add("FMAP0I57.IMG", new Vector2(680, 157));
offsetLookup.Add("FMAP0I58.IMG", new Vector2(17, 53));
offsetLookup.Add("FMAP0I59.IMG", new Vector2(0, 0)); // Glenumbra Moors correct at 0,0
offsetLookup.Add("FMAP0I60.IMG", new Vector2(107, 11));
offsetLookup.Add("FMAP0I61.IMG", new Vector2(255, 275)); // Cybiades
}
#endregion
#region Map Texture Management
// Called when a region is selected
protected virtual void UpdateMapTextures()
{
// Region must be selected
if (!RegionSelected)
return;
// Cached region texture if not available
string mapName = selectedRegionMapNames[mapIndex];
if (!regionTextures.ContainsKey(mapName))
{
Texture2D regionTextureOut;
if (!TextureReplacement.TryImportImage(selectedRegionMapNames[mapIndex], false, out regionTextureOut))
regionTextureOut = ImageReader.GetTexture(mapName);
regionTextures.Add(mapName, regionTextureOut);
}
// Present region and locations
regionTextureOverlayPanel.BackgroundTexture = regionTextures[mapName];
UpdateMapLocationDotsTexture();
}
// Updates location dots
protected virtual void UpdateMapLocationDotsTexture()
{
// Get map and dimensions
string mapName = selectedRegionMapNames[mapIndex];
Vector2 origin = offsetLookup[mapName];
int originX = (int)origin.x;
int originY = (int)origin.y;
int width = (int)regionTextureOverlayPanelRect.width;
int height = (int)regionTextureOverlayPanelRect.height;
// Plot locations to color array
scale = GetRegionMapScale(selectedRegion);
Array.Clear(locationDotsPixelBuffer, 0, locationDotsPixelBuffer.Length);
Array.Clear(locationDotsOutlinePixelBuffer, 0, locationDotsOutlinePixelBuffer.Length);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int offset = (int)((((height - y - 1) * width) + x) * scale);
if (offset >= (width * height))
continue;
int sampleRegion = DaggerfallUnity.Instance.ContentReader.MapFileReader.GetPoliticIndex(originX + x, originY + y) - 128;
// Set location pixel if inside region area
if (sampleRegion == selectedRegion)
{
ContentReader.MapSummary summary;
if (DaggerfallUnity.Instance.ContentReader.HasLocation(originX + x, originY + y, out summary))
{
if (!checkLocationDiscovered(summary))
continue;
int index = GetPixelColorIndex(summary.LocationType);
if (index == -1)
continue;
else
{
if (DaggerfallUnity.Settings.TravelMapLocationsOutline)
locationDotsOutlinePixelBuffer[offset] = dotOutlineColor;
locationDotsPixelBuffer[offset] = locationPixelColors[index];
}
}
}
}
}
// Apply updated color array to texture
if (DaggerfallUnity.Settings.TravelMapLocationsOutline)
{
locationDotsOutlineTexture.SetPixels32(locationDotsOutlinePixelBuffer);
locationDotsOutlineTexture.Apply();
}
locationDotsTexture.SetPixels32(locationDotsPixelBuffer);
locationDotsTexture.Apply();
// Present texture
if (DaggerfallUnity.Settings.TravelMapLocationsOutline)
for (int i = 0; i < outlineDisplacements.Length; i++)
regionLocationDotsOutlinesOverlayPanel[i].BackgroundTexture = locationDotsOutlineTexture;
regionLocationDotsOverlayPanel.BackgroundTexture = locationDotsTexture;
}
// Zoom and pan region texture
protected virtual void ZoomMapTextures()
{
// Exit cropped rendering
if (!RegionSelected || !zoom)
{
regionTextureOverlayPanel.BackgroundTextureLayout = BackgroundLayout.StretchToFill;
if (DaggerfallUnity.Settings.TravelMapLocationsOutline)
for (int i = 0; i < outlineDisplacements.Length; i++)
regionLocationDotsOutlinesOverlayPanel[i].BackgroundTextureLayout = BackgroundLayout.StretchToFill;
regionLocationDotsOverlayPanel.BackgroundTextureLayout = BackgroundLayout.StretchToFill;
identifyOverlayPanel.BackgroundTextureLayout = BackgroundLayout.StretchToFill;
UpdateBorder();
return;
}
// Get current region texture
Texture2D regionTexture;
if (!regionTextures.TryGetValue(selectedRegionMapNames[mapIndex], out regionTexture))
return;
// Centre cropped porition over mouse using classic dimensions
int width = (int)regionTextureOverlayPanelRect.width;
int height = (int)regionTextureOverlayPanelRect.height;
int zoomWidth = width / (zoomfactor * 2);
int zoomHeight = height / (zoomfactor * 2);
int startX = (int)zoomPosition.x - zoomWidth;
int startY = (int)(height + (-zoomPosition.y - zoomHeight)) + regionPanelOffset;
// Clamp to edges
if (startX < 0)
startX = 0;
else if (startX + width / zoomfactor >= width)
startX = width - width / zoomfactor;
if (startY < 0)
startY = 0;
else if (startY + height / zoomfactor >= height)
startY = height - height / zoomfactor;
zoomOffset = new Vector2(startX, startY);
// Set cropped area in region texture - can be a replacement texture so need to determine ratio compared to classic
float ratioX = regionTexture.width / (float)width;
float ratioY = regionTexture.height / (float)height;
regionTextureOverlayPanel.BackgroundTextureLayout = BackgroundLayout.Cropped;
regionTextureOverlayPanel.BackgroundCroppedRect = new Rect(startX * ratioX, startY * ratioY, width / zoomfactor * ratioX, height / zoomfactor * ratioY);
// Set cropped area in location dots panel - always at classic dimensions
Rect locationDotsNewRect = new Rect(startX, startY, width / zoomfactor, height / zoomfactor);
if (DaggerfallUnity.Settings.TravelMapLocationsOutline)
for (int i = 0; i < outlineDisplacements.Length; i++)
{
Rect modifiedRect = locationDotsNewRect;
modifiedRect.x += outlineDisplacements[i].x * dotsOutlineThickness / NativePanel.LocalScale.x;
modifiedRect.y += outlineDisplacements[i].y * dotsOutlineThickness / NativePanel.LocalScale.y;
regionLocationDotsOutlinesOverlayPanel[i].BackgroundTextureLayout = BackgroundLayout.Cropped;
regionLocationDotsOutlinesOverlayPanel[i].BackgroundCroppedRect = modifiedRect;
}
regionLocationDotsOverlayPanel.BackgroundTextureLayout = BackgroundLayout.Cropped;
regionLocationDotsOverlayPanel.BackgroundCroppedRect = locationDotsNewRect;
// Set cropped area in identify panel - always at classic dimensions
// This ensures zoomed crosshair pans with location dots panel
identifyOverlayPanel.BackgroundTextureLayout = BackgroundLayout.Cropped;
identifyOverlayPanel.BackgroundCroppedRect = regionLocationDotsOverlayPanel.BackgroundCroppedRect;
UpdateBorder();
}
// Show/hide map borders based on state
protected virtual void UpdateBorder()
{
borderPanel.Enabled = (RegionSelected && !zoom);
}
// Set region block for identify overlay
protected virtual void UpdateIdentifyTextureForPlayerRegion()
{
// Only for overworld map
if (RegionSelected)
return;
// Player must be inside a valid region
int playerRegion = GetPlayerRegion();
if (playerRegion == -1)
return;
// Clear existing pixel buffer
Array.Clear(identifyPixelBuffer, 0, identifyPixelBuffer.Length);
// Import custom map overlays named TRAV0I00.IMG-RegionName (e.g. TRAV0I00.IMG-Ilessan Hills) if available
// Custom image must be based on 320x160 interior snip of TRAV0I00.IMG (so exclude top and bottom bars) but can be a higher resolution like 1600x800
Texture2D customRegionOverlayTexture;
if (importedOverlays.TryGetValue(playerRegion, out customRegionOverlayTexture) ||
TextureReplacement.TryImportImage(string.Format("{0}-{1}", overworldImgName, GetRegionNameForMapReplacement(playerRegion)), false, out customRegionOverlayTexture))
{
identifyOverlayPanel.BackgroundTexture = importedOverlays[playerRegion] = customRegionOverlayTexture;
return;
}
// Region shape is filled from picker bitmap, so this has to be open
if (regionPickerBitmap == null)
regionPickerBitmap = DaggerfallUI.GetImgBitmap(regionPickerImgName);
// Create a texture overlay for the region area
int width = regionPickerBitmap.Width;
int height = regionPickerBitmap.Height;
int pickerOverlayPanelHeightDifference = height - (int)regionTextureOverlayPanelRect.height - regionPanelOffset + 1;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int srcOffset = y * width + x;
int dstOffset = ((height - y - pickerOverlayPanelHeightDifference) * width) + x;
int sampleRegion = regionPickerBitmap.Data[srcOffset] - 128;
if (sampleRegion == playerRegion)
identifyPixelBuffer[dstOffset] = identifyFlashColor;
}
}
identifyTexture.SetPixels32(identifyPixelBuffer);
identifyTexture.Apply();
identifyOverlayPanel.BackgroundTexture = identifyTexture;
}
protected virtual void UpdateCrosshair()
{
if (FindingLocation)
UpdateIdentifyTextureForPosition(MapsFile.GetPixelFromPixelID(locationSummary.ID), locationSummary.RegionIndex);
else
UpdateIdentifyTextureForPosition(TravelTimeCalculator.GetPlayerTravelPosition(), selectedRegion);
}
protected virtual void UpdateIdentifyTextureForPosition(DFPosition pos, int regionIndex = -1)
{
if (regionIndex == -1)
regionIndex = GetPlayerRegion();
UpdateIdentifyTextureForPosition(pos.X, pos.Y, regionIndex);
}
// Set location crosshair for identify overlay
protected virtual void UpdateIdentifyTextureForPosition(int mapPixelX, int mapPixelY, int regionIndex)
{
// Only for regions
if (!RegionSelected)
return;
// Clear existing pixel buffer
Array.Clear(identifyPixelBuffer, 0, identifyPixelBuffer.Length);
string mapName = selectedRegionMapNames[mapIndex];
Vector2 origin = offsetLookup[mapName];
float scale = GetRegionMapScale(regionIndex);
// Manually adjust Betony vertical offset
int yAdjust = 0;
if (regionIndex == betonyIndex)
yAdjust = -477;
int scaledX = (int)((mapPixelX - origin.x) * scale);
int scaledY = (int)((mapPixelY - origin.y) * scale) + regionPanelOffset + yAdjust;
int width = (int)regionTextureOverlayPanelRect.width;
int height = (int)regionTextureOverlayPanelRect.height;
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
if (x == scaledX || y + regionPanelOffset == scaledY)
{
identifyPixelBuffer[(height - y - 1) * width + x] = identifyFlashColor;
}
}
}
identifyTexture.SetPixels32(identifyPixelBuffer);
identifyTexture.Apply();
identifyOverlayPanel.BackgroundTexture = identifyTexture;
}
#endregion
#region Event Handlers
// Handle clicks on the main panel
protected virtual void ClickHandler(BaseScreenComponent sender, Vector2 position)
{
position.y -= regionPanelOffset;
// Ensure clicks are inside region texture
if (position.x < 0 || position.x > regionTextureOverlayPanelRect.width || position.y < 0 || position.y > regionTextureOverlayPanelRect.height)
return;
if (RegionSelected == false)
{
if (MouseOverRegion)
OpenRegionPanel(mouseOverRegion);
}
else if (locationSelected)
{
if (FindingLocation)
StopIdentify(true);
else
CreatePopUpWindow();
}
else if (MouseOverOtherRegion)
{
// If clicked while mouse over other region & not a location, switch to that region
OpenRegionPanel(mouseOverRegion);
}
}
protected virtual void ExitButtonClickHandler(BaseScreenComponent sender, Vector2 position)
{
DaggerfallUI.Instance.PlayOneShot(SoundClips.ButtonClick);
CloseTravelWindows();
}
protected virtual void AtButtonClickHandler(BaseScreenComponent sender, Vector2 position)
{
// Identify region or map location
findingLocation = false;
StartIdentify();
UpdateCrosshair();
}
protected virtual void FindlocationButtonClickHandler(BaseScreenComponent sender, Vector2 position)
{
// Open find location pop-up
if (RegionSelected)
{
DaggerfallUI.Instance.PlayOneShot(SoundClips.ButtonClick);
DaggerfallInputMessageBox findPopUp = new DaggerfallInputMessageBox(uiManager, null, 31, TextManager.Instance.GetLocalizedText("findLocationPrompt"), true, this);
findPopUp.TextPanelDistanceY = 5;
findPopUp.TextBox.WidthOverride = 308;
findPopUp.TextBox.MaxCharacters = 32;
findPopUp.OnGotUserInput += HandleLocationFindEvent;
findPopUp.Show();
}
}
/// <summary>
/// Button handler for travel confirmation pop up. This is a temporary solution until implementing the final pop-up.
/// </summary>
protected virtual void ConfirmTravelPopupButtonClick(DaggerfallMessageBox sender, DaggerfallMessageBox.MessageBoxButtons messageBoxButton)
{
DaggerfallUI.Instance.PlayOneShot(SoundClips.ButtonClick);
sender.CloseWindow();
if (messageBoxButton == DaggerfallMessageBox.MessageBoxButtons.Yes)
CreatePopUpWindow();
else
StopIdentify();
}
/// <summary>
/// Handles click events for the arrow buttons in the region view
/// </summary>
protected virtual void ArrowButtonClickHandler(BaseScreenComponent sender, Vector2 position)
{
if (RegionSelected == false || !HasMultipleMaps)
return;
int newIndex = mapIndex;
if (sender.Name == "horizontalArrowButton")
{
if (newIndex % 2 == 0)
newIndex += 1; // Move right
else