forked from Slazanger/SMT
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Universe3dControl.xaml.cs
687 lines (531 loc) · 20.8 KB
/
Universe3dControl.xaml.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
using HelixToolkit.Wpf.SharpDX;
using SharpDX;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Media3D;
namespace SMT
{
/// <summary>
/// Interaction logic for Universe3DControl.xaml
/// </summary>
public partial class Universe3DControl : UserControl, INotifyPropertyChanged
{
private double m_ESIOverlayScale = 1.0f;
private bool m_ShowNPCKills = false;
private bool m_ShowPodKills = false;
private bool m_ShowShipKills = false;
private bool m_ShowShipJumps = false;
private bool m_ShowJumpBridges = true;
public MapConfig MapConf { get; set; }
public List<EVEData.Navigation.RoutePoint> ActiveRoute { get; set; }
public bool FollowCharacter
{
get
{
return FollowCharacterChk.IsChecked.Value;
}
set
{
FollowCharacterChk.IsChecked = value;
}
}
public Universe3DControl()
{
InitializeComponent();
DataContext = this;
}
private struct GateHelper
{
public EVEData.System from { get; set; }
public EVEData.System to { get; set; }
public bool RegionalGate { get; set; }
}
public bool ShowJumpBridges
{
get
{
return m_ShowJumpBridges;
}
set
{
m_ShowJumpBridges = value;
OnPropertyChanged("ShowJumpBridges");
}
}
public double ESIOverlayScale
{
get
{
return m_ESIOverlayScale;
}
set
{
m_ESIOverlayScale = value;
OnPropertyChanged("ESIOverlayScale");
}
}
public bool ShowNPCKills
{
get
{
return m_ShowNPCKills;
}
set
{
m_ShowNPCKills = value;
if (m_ShowNPCKills)
{
ShowPodKills = false;
ShowShipKills = false;
ShowShipJumps = false;
}
OnPropertyChanged("ShowNPCKills");
}
}
public bool ShowPodKills
{
get
{
return m_ShowPodKills;
}
set
{
m_ShowPodKills = value;
if (m_ShowPodKills)
{
ShowNPCKills = false;
ShowShipKills = false;
ShowShipJumps = false;
}
OnPropertyChanged("ShowPodKills");
}
}
public bool ShowShipKills
{
get
{
return m_ShowShipKills;
}
set
{
m_ShowShipKills = value;
if (m_ShowShipKills)
{
ShowNPCKills = false;
ShowPodKills = false;
ShowShipJumps = false;
}
OnPropertyChanged("ShowShipKills");
}
}
public bool ShowShipJumps
{
get
{
return m_ShowShipJumps;
}
set
{
m_ShowShipJumps = value;
if (m_ShowShipJumps)
{
ShowNPCKills = false;
ShowPodKills = false;
ShowShipKills = false;
}
OnPropertyChanged("ShowShipJumps");
}
}
public EVEData.LocalCharacter ActiveCharacter { get; set; }
public void UpdateActiveCharacter(EVEData.LocalCharacter lc)
{
ActiveCharacter = lc;
if (FollowCharacterChk.IsChecked.HasValue && (bool)FollowCharacterChk.IsChecked)
{
CentreMapOnActiveCharacter();
}
}
public static readonly RoutedEvent RequestRegionSystemSelectEvent = EventManager.RegisterRoutedEvent("RequestRegionSystem", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Universe3DControl));
public event RoutedEventHandler RequestRegionSystem
{
add { AddHandler(RequestRegionSystemSelectEvent, value); }
remove { RemoveHandler(RequestRegionSystemSelectEvent, value); }
}
private List<GateHelper> universeSysLinksCache;
private List<KeyValuePair<string, double>> activeJumpSpheres;
private double universeWidth;
private double universeDepth;
private double universeHeight;
private double universeXMin;
private double universeXMax;
private double universeScale;
private double universeZMin;
private double universeZMax;
private double universeYMin;
private double universeYMax;
private EVEData.EveManager EM;
// Timer to Re-draw the map
private System.Windows.Threading.DispatcherTimer uiRefreshTimer;
private int uiRefreshTimer_interval = 0;
public void Init()
{
EM = EVEData.EveManager.Instance;
universeSysLinksCache = new List<GateHelper>();
activeJumpSpheres = new List<KeyValuePair<string, double>>();
universeXMin = 0;
universeXMax = 0;
universeZMin = 0;
universeZMax = 0;
universeYMin = 0;
universeYMax = 0;
uiRefreshTimer = new System.Windows.Threading.DispatcherTimer();
uiRefreshTimer.Tick += UiRefreshTimer_Tick;
uiRefreshTimer.Interval = new TimeSpan(0, 0, 5);
uiRefreshTimer.Start();
PropertyChanged += Universe3DControl_PropertyChanged;
DataContext = this;
foreach (EVEData.System sys in EM.Systems)
{
foreach (string jumpTo in sys.Jumps)
{
EVEData.System to = EM.GetEveSystem(jumpTo);
bool NeedsAdd = true;
foreach (GateHelper gh in universeSysLinksCache)
{
if (((gh.from == sys) || (gh.to == sys)) && ((gh.from == to) || (gh.to == to)))
{
NeedsAdd = false;
break;
}
}
if (NeedsAdd)
{
GateHelper g = new GateHelper();
g.from = sys;
g.to = to;
g.RegionalGate = sys.Region != to.Region;
universeSysLinksCache.Add(g);
}
}
if (sys.ActualX < universeXMin)
{
universeXMin = sys.ActualX;
}
if (sys.ActualX > universeXMax)
{
universeXMax = sys.ActualX;
}
if (sys.ActualZ < universeZMin)
{
universeZMin = sys.ActualZ;
}
if (sys.ActualZ > universeZMax)
{
universeZMax = sys.ActualZ;
}
if (sys.ActualY < universeYMin)
{
universeYMin = sys.ActualY;
}
if (sys.ActualY > universeYMax)
{
universeYMax = sys.ActualY;
}
}
universeWidth = universeXMax - universeXMin;
universeDepth = universeZMax - universeZMin;
universeHeight = universeYMax - universeYMin;
List<EVEData.System> globalSystemList = new List<EVEData.System>(EM.Systems);
globalSystemList.Sort((a, b) => string.Compare(a.Name, b.Name));
GlobalSystemDropDownAC.ItemsSource = globalSystemList;
UniverseMain3DViewPort.EffectsManager = new DefaultEffectsManager();
HelixToolkit.Wpf.SharpDX.PerspectiveCamera pc = new HelixToolkit.Wpf.SharpDX.PerspectiveCamera();
pc.NearPlaneDistance = 0.1;
pc.FarPlaneDistance = 100000;
pc.Position = new Point3D(4000, 4000, 10000);
pc.UpDirection = new Vector3D(0,0,1);
pc.LookDirection = new Vector3D(-1,0, 0);
pc.LookAt(new Point3D(4000, 4000, 4000), 1);
UniverseMain3DViewPort.Camera = pc;
ReDrawMap(true);
}
private void SetJumpRange_Click(object sender, RoutedEventArgs e)
{
}
private void UiRefreshTimer_Tick(object sender, EventArgs e)
{
uiRefreshTimer_interval++;
bool FullRedraw = false;
bool FastUpdate = true;
bool DataRedraw = false;
if (uiRefreshTimer_interval == 4)
{
uiRefreshTimer_interval = 0;
DataRedraw = false;
}
if (FollowCharacterChk.IsChecked.HasValue && (bool)FollowCharacterChk.IsChecked)
{
CentreMapOnActiveCharacter();
}
// ReDrawMap(FullRedraw, DataRedraw, FastUpdate);
}
private void VHSystems_MouseClicked(object sender, RoutedEventArgs e)
{
EVEData.System sys = (EVEData.System)e.OriginalSource;
ContextMenu cm = this.FindResource("SysRightClickContextMenu") as ContextMenu;
cm.DataContext = sys;
cm.IsOpen = true;
MenuItem setDesto = cm.Items[2] as MenuItem;
MenuItem addWaypoint = cm.Items[3] as MenuItem;
if (ActiveCharacter != null && ActiveCharacter.ESILinked)
{
setDesto.IsEnabled = true;
addWaypoint.IsEnabled = true;
}
// update SOV
MenuItem SovHeader = cm.Items[6] as MenuItem;
SovHeader.Items.Clear();
SovHeader.IsEnabled = false;
if (sys.SOVAllianceIHUB != 0)
{
MenuItem mi = new MenuItem();
mi.Header = "IHUB: " + EM.GetAllianceTicker(sys.SOVAllianceIHUB);
mi.DataContext = sys.SOVAllianceIHUB;
mi.Click += VHSystems_SOV_Clicked;
SovHeader.IsEnabled = true;
SovHeader.Items.Add(mi);
}
if (sys.SOVAllianceTCU != 0)
{
MenuItem mi = new MenuItem();
mi.DataContext = sys.SOVAllianceTCU;
mi.Header = "TCU : " + EM.GetAllianceTicker(sys.SOVAllianceTCU);
mi.Click += VHSystems_SOV_Clicked;
SovHeader.IsEnabled = true;
SovHeader.Items.Add(mi);
}
// update stats
MenuItem StatsHeader = cm.Items[7] as MenuItem;
StatsHeader.Items.Clear();
StatsHeader.IsEnabled = false;
if (sys.HasNPCStation)
{
MenuItem mi = new MenuItem();
mi.Header = "NPC Station(s)";
StatsHeader.IsEnabled = true;
StatsHeader.Items.Add(mi);
}
if (sys.HasIceBelt)
{
MenuItem mi = new MenuItem();
mi.Header = "Ice Belts";
StatsHeader.IsEnabled = true;
StatsHeader.Items.Add(mi);
}
if (sys.HasJoveObservatory)
{
MenuItem mi = new MenuItem();
mi.Header = "Jove Observatory";
StatsHeader.IsEnabled = true;
StatsHeader.Items.Add(mi);
}
if (sys.JumpsLastHour > 0)
{
MenuItem mi = new MenuItem();
mi.Header = "Jumps : " + sys.JumpsLastHour;
StatsHeader.IsEnabled = true;
StatsHeader.Items.Add(mi);
}
if (sys.ShipKillsLastHour > 0)
{
MenuItem mi = new MenuItem();
mi.Header = "Ship Kills : " + sys.ShipKillsLastHour;
StatsHeader.IsEnabled = true;
StatsHeader.Items.Add(mi);
}
if (sys.PodKillsLastHour > 0)
{
MenuItem mi = new MenuItem();
mi.Header = "Pod Kills : " + sys.PodKillsLastHour;
StatsHeader.IsEnabled = true;
StatsHeader.Items.Add(mi);
}
if (sys.NPCKillsLastHour > 0)
{
MenuItem mi = new MenuItem();
mi.Header = "NPC Kills : " + sys.NPCKillsLastHour + " (Delta: " + sys.NPCKillsDeltaLastHour + ")";
StatsHeader.IsEnabled = true;
StatsHeader.Items.Add(mi);
}
if (sys.RadiusAU > 0)
{
MenuItem mi = new MenuItem();
mi.Header = "Radius : " + sys.RadiusAU.ToString("#.##") + " (AU)";
StatsHeader.IsEnabled = true;
StatsHeader.Items.Add(mi);
}
}
private void VHSystems_SOV_Clicked(object sender, RoutedEventArgs e)
{
MenuItem mi = sender as MenuItem;
long ID = (long)mi.DataContext;
if (ID != 0)
{
string uRL = string.Format("https://evewho.com/alliance/{0}", ID);
System.Diagnostics.Process.Start(uRL);
}
}
private void Universe3DControl_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
// ReDrawMap(false, true, true);
}
/// <summary>
/// Redraw the map
/// </summary>
/// <param name="FullRedraw">Clear all the static items or not</param>
public void ReDrawMap(bool FullRedraw = false, bool DataRedraw = false, bool FastUpdate = false)
{
double Size = 8000;
double XScale = Size / universeWidth;
double ZScale = Size / universeDepth;
universeScale = Math.Min(XScale, ZScale);
var mb = new MeshBuilder();
var mbRegion = new MeshBuilder();
foreach (GateHelper gh in universeSysLinksCache)
{
double X1 = (gh.from.ActualX - universeXMin) * universeScale;
double Y1 = (gh.from.ActualZ - universeZMin) * universeScale;
double Z1 = (gh.from.ActualY - universeYMin) * universeScale;
double X2 = (gh.to.ActualX - universeXMin) * universeScale;
double Y2 = (gh.to.ActualZ - universeZMin) * universeScale;
double Z2 = (gh.to.ActualY - universeYMin) * universeScale;
if(gh.RegionalGate)
{
mbRegion.AddCylinder(new Vector3((float)X1, (float)Y1, (float)Z1), new Vector3((float)X2, (float)Y2, (float)Z2), 1, 4);
}
else
{
mb.AddCylinder(new Vector3((float)X1, (float)Y1, (float)Z1), new Vector3((float)X2, (float)Y2, (float)Z2), 1, 4);
}
}
PhongMaterial em = PhongMaterials.Gray;
PhongMaterial emrg = PhongMaterials.Red;
MeshGeometryModel3D geomModelGates = new MeshGeometryModel3D { Geometry = mb.ToMeshGeometry3D(), Material = em };
UniverseMain3DViewPort.Items.Add(geomModelGates);
MeshGeometryModel3D geomModelRegionalGates = new MeshGeometryModel3D { Geometry = mbRegion.ToMesh(), Material = emrg };
UniverseMain3DViewPort.Items.Add(geomModelRegionalGates);
var mbSystems = new MeshBuilder();
foreach (EVEData.System sys in EM.Systems)
{
double X1 = (sys.ActualX - universeXMin) * universeScale;
double Y1 = (sys.ActualZ - universeZMin) * universeScale;
double Z1 = (sys.ActualY - universeYMin) * universeScale;
Vector3 sysCentre = new Vector3((float)X1, (float)Y1, (float)Z1);
mbSystems.AddBox(sysCentre, 10, 10, 10);
// BillboardTextVisual3D sysTextBB = new BillboardTextVisual3D();
//
// sysTextBB.Position = sysCentre;
// sysTextBB.Text = " " + sys.Name;
// UniverseMain3DViewPort.Children.Add(sysTextBB);
}
PhongMaterial emsys = PhongMaterials.White;
MeshGeometryModel3D geomModelSystems = new MeshGeometryModel3D { Geometry = mbSystems.ToMesh(), Material = emsys};
UniverseMain3DViewPort.Items.Add(geomModelSystems);
// UniverseMain3DViewPort.Camera.Position = new Point3D(4000, 4000, 1000);
// UniverseMain3DViewPort.Camera.LookAt(new Point3D(0, 0, 0), 1);
// UniverseMain3DViewPort.Camera.ZoomExtents();
}
public void ShowSystem(string SystemName)
{
EVEData.System sd = EM.GetEveSystem(SystemName);
if (sd != null)
{
// actual
double X1 = (sd.ActualX - universeXMin) * universeScale;
double Y1 = (universeDepth - (sd.ActualZ - universeZMin)) * universeScale;
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
private void GlobalSystemDropDownAC_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
EVEData.System sd = GlobalSystemDropDownAC.SelectedItem as EVEData.System;
if (sd != null)
{
FollowCharacterChk.IsChecked = false;
ShowSystem(sd.Name);
}
}
/// <summary>
/// Dotlan Clicked
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SysContexMenuItemDotlan_Click(object sender, RoutedEventArgs e)
{
EVEData.System eveSys = ((System.Windows.FrameworkElement)((System.Windows.FrameworkElement)sender).Parent).DataContext as EVEData.System;
EVEData.MapRegion rd = EM.GetRegion(eveSys.Region);
string uRL = string.Format("http://evemaps.dotlan.net/map/{0}/{1}", rd.DotLanRef, eveSys.Name);
System.Diagnostics.Process.Start(uRL);
}
/// <summary>
/// ZKillboard Clicked
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SysContexMenuItemZKB_Click(object sender, RoutedEventArgs e)
{
EVEData.System eveSys = ((System.Windows.FrameworkElement)((System.Windows.FrameworkElement)sender).Parent).DataContext as EVEData.System;
EVEData.MapRegion rd = EM.GetRegion(eveSys.Region);
string uRL = string.Format("https://zkillboard.com/system/{0}", eveSys.ID);
System.Diagnostics.Process.Start(uRL);
}
private void SysContexMenuShowInRegion_Click(object sender, RoutedEventArgs e)
{
EVEData.System s = ((System.Windows.Controls.MenuItem)e.OriginalSource).DataContext as EVEData.System;
RoutedEventArgs newEventArgs = new RoutedEventArgs(RequestRegionSystemSelectEvent, s.Name);
RaiseEvent(newEventArgs);
}
private void FollowCharacterChk_Checked(object sender, RoutedEventArgs e)
{
CentreMapOnActiveCharacter();
}
private void CentreMapOnActiveCharacter()
{
}
private void RecentreBtn_Click(object sender, RoutedEventArgs e)
{
CentreMapOnActiveCharacter();
}
private void SysContexMenuItemSetDestination_Click(object sender, RoutedEventArgs e)
{
EVEData.System eveSys = ((System.Windows.FrameworkElement)((System.Windows.FrameworkElement)sender).Parent).DataContext as EVEData.System;
if (ActiveCharacter != null)
{
ActiveCharacter.AddDestination(eveSys.ID, true);
}
}
private void SysContexMenuItemAddWaypoint_Click(object sender, RoutedEventArgs e)
{
EVEData.System eveSys = ((System.Windows.FrameworkElement)((System.Windows.FrameworkElement)sender).Parent).DataContext as EVEData.System;
if (ActiveCharacter != null)
{
ActiveCharacter.AddDestination(eveSys.ID, false);
}
}
}
}