forked from mmp/vice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstars.go
4382 lines (3859 loc) · 121 KB
/
stars.go
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
// stars.go
// Copyright(c) 2022 Matt Pharr, licensed under the GNU Public License, Version 3.
// SPDX: GPL-3.0-only
// Main missing features:
// Altitude alerts
// CDRA (can build off of CRDAConfig, however)
// Quicklook
package main
import (
"errors"
"fmt"
"math"
"sort"
"strconv"
"strings"
"time"
"unicode"
"unsafe"
"github.com/davecgh/go-spew/spew"
"github.com/mmp/imgui-go/v4"
)
var (
STARSBackgroundColor = RGB{0, 0, 0}
STARSListColor = RGB{.1, .9, .1}
STARSTextAlertColor = RGB{1, .1, .1}
STARSTrackBlockColor = RGB{0.1, 0.4, 1}
STARSTrackHistoryColor = RGB{.2, 0, 1}
STARSJRingConeColor = RGB{.5, .5, 1}
STARSTrackedAircraftColor = RGB{1, 1, 1}
STARSUntrackedAircraftColor = RGB{.1, .9, .1}
STARSPointedOutAircraftColor = RGB{.9, .9, .1}
STARSSelectedAircraftColor = RGB{.1, .9, .9}
ErrSTARSIllegalParam = errors.New("ILL PARAM")
ErrSTARSIllegalTrack = errors.New("ILL TRK")
ErrSTARSCommandFormat = errors.New("FORMAT")
)
const NumSTARSPreferenceSets = 32
const NumSTARSMaps = 28
type STARSPane struct {
currentPreferenceSet STARSPreferenceSet
SelectedPreferenceSet int
PreferenceSets []STARSPreferenceSet
Facility STARSFacility
weatherRadar WeatherRadar
systemFont [6]*Font
eventsId EventSubscriberId
// All of the aircraft in the world, each with additional information
// carried along in an STARSAircraftState.
aircraft map[*Aircraft]*STARSAircraftState
// map from legit to their ghost, if present
ghostAircraft map[*Aircraft]*Aircraft
aircraftToIndex map[*Aircraft]int // for use in lists
indexToAircraft map[int]*Aircraft // map is sort of wasteful since it's dense, but...
AutoTrackDepartures map[string]interface{}
pointedOutAircraft *TransientMap[*Aircraft, string]
queryUnassociated *TransientMap[*Aircraft, interface{}]
rangeBearingLines []STARSRangeBearingLine
minSepAircraft [2]*Aircraft
// Various UI state
scopeClickHandler func(pw [2]float32, transforms ScopeTransformations) STARSCommandStatus
activeDCBMenu int
commandMode CommandMode
multiFuncPrefix string
previewAreaOutput string
previewAreaInput string
havePlayedSPCAlertSound map[*Aircraft]interface{}
lastCASoundTime time.Time
drawApproachAirspace bool
drawDepartureAirspace bool
}
type STARSRangeBearingLine struct {
p [2]struct {
// If ac is non-nil, use its position, otherwise we have a fixed position.
loc Point2LL
ac *Aircraft
}
}
type CommandMode int
const (
CommandModeNone = iota
CommandModeInitiateControl
CommandModeTerminateControl
CommandModeHandOff
CommandModeVP
CommandModeMultiFunc
CommandModeFlightData
CommandModeCollisionAlert
CommandModeMin
CommandModeSavePrefAs
CommandModeMaps
CommandModeLDR
CommandModeRangeRings
CommandModeRange
CommandModeSiteMenu
)
const (
DCBMenuMain = iota
DCBMenuAux
DCBMenuMaps
DCBMenuBrite
DCBMenuCharSize
DCBMenuPref
DCBMenuSite
DCBMenuSSAFilter
DCBMenuGITextFilter
)
type STARSAircraftState struct {
isGhost bool
suppressGhost bool // for ghost only
forceGhost bool // for non-ghost only
datablockType DatablockType
datablockErrText string
datablockText [2][]string
datablockDrawOffset [2]float32
// Only drawn if non-zero
jRingRadius float32
coneLength float32
displayTPASize bool // flip this so that zero-init works here? (What is the default?)
leaderLineDirection *CardinalOrdinalDirection // nil -> unset
displayPilotAltitude bool
pilotAltitude int
displayReportedBeacon bool // note: only for unassociated
displayPTL bool
disableCAWarnings bool
disableMSAW bool
inhibitMSAWAlert bool // only applies if in an alert. clear when alert is over?
spcOverride string
outboundHandoffAccepted bool
outboundHandoffFlashEnd time.Time
}
///////////////////////////////////////////////////////////////////////////
// STARSFacility and related
type STARSFacility struct {
CA struct {
LateralMinimum float32
VerticalMinimum int32
Floor int32
}
CRDAConfig CRDAConfig
// TODO: transition alt -> show pressure altitude above
// TODO: RNAV patterns
// TODO: automatic scratchpad stuff
}
type STARSMap struct {
Label string `json:"label"`
Group int `json:"group"` // 0 -> A, 1 -> B
Name string `json:"name"`
cb CommandBuffer
}
func MakeDefaultFacility() STARSFacility {
var f STARSFacility
f.CA.LateralMinimum = 3
f.CA.VerticalMinimum = 1000
f.CA.Floor = 500
f.CRDAConfig = NewCRDAConfig()
return f
}
///////////////////////////////////////////////////////////////////////////
// STARSPreferenceSet
type STARSPreferenceSet struct {
Name string
DisplayDCB bool
Center Point2LL
Range float32
currentCenter Point2LL
offCenter bool
RangeRingsCenter Point2LL
RangeRingRadius int
// TODO? cursor speed
// Note: not saved across sessions
currentATIS string
giText [9]string
RadarTrackHistory int
WeatherIntensity [6]bool
// If empty, then then MULTI mode. The custom JSON name is so we don't
// get errors parsing old configs, which stored this as an array...
RadarSiteSelected string `json:"RadarSiteSelectedName"`
LeaderLineDirection CardinalOrdinalDirection
LeaderLineLength int // 0-7
ListSelectedMaps bool // TODO: show this list, e.g.:
// CURRENT MAPS
// > 2 EAST PHILADELPHIA MAP EAST
// > ...
AltitudeFilters struct {
Unassociated [2]int // low, high
Associated [2]int
}
DisableCRDA bool
DisplayLDBBeaconCodes bool // TODO: default?
SelectedBeaconCodes []string
// TODO: review--should some of the below not be in prefs but be in STARSPane?
DisplayUncorrelatedTargets bool
DisableCAWarnings bool
DisableMSAW bool
OverflightFullDatablocks bool
AutomaticFDBOffset bool
DisplayTPASize bool
VideoMapVisible map[string]interface{}
PTLLength float32
PTLOwn, PTLAll bool
TopDownMode bool
GroundRangeMode bool
Bookmarks [10]struct {
Center Point2LL
Range float32
TopDownMode bool
}
Brightness struct {
VideoGroupA STARSBrightness
VideoGroupB STARSBrightness
FullDatablocks STARSBrightness
Lists STARSBrightness
Positions STARSBrightness
LimitedDatablocks STARSBrightness
OtherTracks STARSBrightness
Lines STARSBrightness
RangeRings STARSBrightness
Compass STARSBrightness
BeaconSymbols STARSBrightness
PrimarySymbols STARSBrightness
History STARSBrightness
}
CharSize struct {
Datablocks int
Lists int
Tools int
PositionSymbols int
}
PreviewAreaPosition [2]float32
SSAList struct {
Position [2]float32
Visible bool
Filter struct {
All bool
Time bool
Altimeter bool
Status bool
Radar bool
Codes bool
SpecialPurposeCodes bool
Range bool
PredictedTrackLines bool
AltitudeFilters bool
AirportWeather bool
QuickLookPositions bool
DisabledTerminal bool
ActiveCRDAPairs bool
Text struct {
Main bool
GI [9]bool
}
}
}
VFRList struct {
Position [2]float32
Visible bool
Lines int
}
TABList struct {
Position [2]float32
Visible bool
Lines int
}
AlertList struct {
Position [2]float32
Visible bool
Lines int
}
CoastList struct {
Position [2]float32
Visible bool
Lines int
}
SignOnList struct {
Position [2]float32
Visible bool
}
VideoMapsList struct {
Position [2]float32
Visible bool
}
CRDAStatusList struct {
Position [2]float32
Visible bool
}
TowerLists [3]struct {
Position [2]float32
Visible bool
Lines int
}
}
func MakePreferenceSet(name string, facility STARSFacility) STARSPreferenceSet {
var ps STARSPreferenceSet
ps.Name = name
ps.DisplayDCB = true
ps.Center = scenarioGroup.Center
ps.Range = 40
ps.currentCenter = ps.Center
ps.RangeRingsCenter = ps.Center
ps.RangeRingRadius = 5
ps.RadarTrackHistory = 5
ps.VideoMapVisible = make(map[string]interface{})
if len(scenarioGroup.STARSMaps) > 0 {
ps.VideoMapVisible[scenarioGroup.STARSMaps[0].Name] = nil
}
ps.LeaderLineDirection = North
ps.LeaderLineLength = 1
ps.AltitudeFilters.Unassociated = [2]int{100, 60000}
ps.AltitudeFilters.Associated = [2]int{100, 60000}
ps.DisplayUncorrelatedTargets = true
ps.DisplayTPASize = true
ps.PTLLength = 1
ps.Brightness.VideoGroupA = 50
ps.Brightness.VideoGroupB = 40
ps.Brightness.FullDatablocks = 80
ps.Brightness.Lists = 80
ps.Brightness.Positions = 80
ps.Brightness.LimitedDatablocks = 80
ps.Brightness.OtherTracks = 80
ps.Brightness.Lines = 40
ps.Brightness.RangeRings = 10
ps.Brightness.Compass = 30
ps.Brightness.BeaconSymbols = 55
ps.Brightness.PrimarySymbols = 80
ps.Brightness.History = 60
ps.CharSize.Datablocks = 1
ps.CharSize.Lists = 1
ps.CharSize.Tools = 1
ps.CharSize.PositionSymbols = 0
ps.PreviewAreaPosition = [2]float32{.05, .8}
ps.SSAList.Position = [2]float32{.05, .95}
ps.SSAList.Visible = true
ps.SSAList.Filter.All = true
ps.TABList.Position = [2]float32{.05, .7}
ps.TABList.Lines = 5
ps.TABList.Visible = true
ps.VFRList.Position = [2]float32{.05, .2}
ps.VFRList.Lines = 5
ps.VFRList.Visible = true
ps.AlertList.Position = [2]float32{.85, .25}
ps.AlertList.Lines = 5
ps.AlertList.Visible = true
ps.CoastList.Position = [2]float32{.85, .65}
ps.CoastList.Lines = 5
ps.CoastList.Visible = false
ps.SignOnList.Position = [2]float32{.85, .95}
ps.SignOnList.Visible = true
ps.VideoMapsList.Position = [2]float32{.85, .5}
ps.VideoMapsList.Visible = false
ps.CRDAStatusList.Position = [2]float32{.05, .7}
ps.TowerLists[0].Position = [2]float32{.05, .5}
ps.TowerLists[0].Lines = 5
ps.TowerLists[0].Visible = true
ps.TowerLists[1].Position = [2]float32{.05, .8}
ps.TowerLists[1].Lines = 5
ps.TowerLists[2].Position = [2]float32{.05, .9}
ps.TowerLists[2].Lines = 5
return ps
}
func (ps *STARSPreferenceSet) Duplicate() STARSPreferenceSet {
dupe := *ps
dupe.SelectedBeaconCodes = DuplicateSlice(ps.SelectedBeaconCodes)
dupe.VideoMapVisible = DuplicateMap(ps.VideoMapVisible)
return dupe
}
func (ps *STARSPreferenceSet) Activate() {
ps.currentCenter = ps.Center
if ps.VideoMapVisible == nil {
ps.VideoMapVisible = make(map[string]interface{})
if len(scenarioGroup.STARSMaps) > 0 {
ps.VideoMapVisible[scenarioGroup.STARSMaps[0].Name] = nil
}
}
}
///////////////////////////////////////////////////////////////////////////
// Utility types and methods
type DatablockType int
const (
PartialDatablock = iota
LimitedDatablock
FullDatablock
)
func flightPlanSTARS(ac *Aircraft) (string, error) {
fp := ac.FlightPlan
if fp == nil {
return "", ErrSTARSIllegalTrack // ??
}
// AAL1416 B738/L squawk controller id
// (start of route) (alt 100s)
result := ac.Callsign + " " + fp.AircraftType + " " + ac.AssignedSquawk.String() + " "
if ctrl := sim.GetController(ac.TrackingController); ctrl != nil {
result += ctrl.SectorId
}
result += "\n"
// Display the first two items in the route
routeFields := strings.Fields(fp.Route)
if len(routeFields) > 2 {
routeFields = routeFields[:2]
}
result += strings.Join(routeFields, " ") + " "
result += fmt.Sprintf("%d", fp.Altitude/100)
return result, nil
}
func squawkingSPC(squawk Squawk) bool {
return squawk == Squawk(0o7500) || squawk == Squawk(0o7600) ||
squawk == Squawk(0o7700) || squawk == Squawk(0o7777)
}
type STARSCommandStatus struct {
clear bool
output string
err error
}
type STARSBrightness int
func (b STARSBrightness) RGB() RGB {
v := float32(b) / 100
return RGB{v, v, v}
}
func (b STARSBrightness) ScaleRGB(r RGB) RGB {
return r.Scale(float32(b) / 100)
}
///////////////////////////////////////////////////////////////////////////
// STARSPane proper
// Takes aircraft position in window coordinates
func NewSTARSPane() *STARSPane {
return &STARSPane{
Facility: MakeDefaultFacility(),
SelectedPreferenceSet: -1,
}
}
func (sp *STARSPane) Name() string { return "STARS" }
func (sp *STARSPane) Activate() {
if sp.SelectedPreferenceSet != -1 && sp.SelectedPreferenceSet < len(sp.PreferenceSets) {
sp.currentPreferenceSet = sp.PreferenceSets[sp.SelectedPreferenceSet]
} else {
sp.currentPreferenceSet = MakePreferenceSet("", sp.Facility)
}
sp.currentPreferenceSet.Activate()
if sp.havePlayedSPCAlertSound == nil {
sp.havePlayedSPCAlertSound = make(map[*Aircraft]interface{})
}
if sp.pointedOutAircraft == nil {
sp.pointedOutAircraft = NewTransientMap[*Aircraft, string]()
}
if sp.queryUnassociated == nil {
sp.queryUnassociated = NewTransientMap[*Aircraft, interface{}]()
}
sp.initializeSystemFonts()
sp.aircraftToIndex = make(map[*Aircraft]int)
sp.indexToAircraft = make(map[int]*Aircraft)
if sp.AutoTrackDepartures == nil {
sp.AutoTrackDepartures = make(map[string]interface{})
}
sp.eventsId = eventStream.Subscribe()
ps := sp.currentPreferenceSet
if Find(ps.WeatherIntensity[:], true) != -1 {
sp.weatherRadar.Activate(sp.currentPreferenceSet.Center)
}
// start tracking all of the active aircraft
sp.initializeAircraft()
}
func (sp *STARSPane) Deactivate() {
// Drop all of them
sp.aircraft = nil
sp.ghostAircraft = nil
eventStream.Unsubscribe(sp.eventsId)
sp.eventsId = InvalidEventSubscriberId
sp.weatherRadar.Deactivate()
}
func (sp *STARSPane) ResetScenarioGroup() {
ps := &sp.currentPreferenceSet
ps.Center = scenarioGroup.Center
ps.currentCenter = ps.Center
ps.RangeRingsCenter = ps.Center
ps.VideoMapVisible = make(map[string]interface{})
if len(scenarioGroup.STARSMaps) > 0 {
ps.VideoMapVisible[scenarioGroup.STARSMaps[0].Name] = nil
}
}
func (sp *STARSPane) ResetScenario(s *Scenario) {
// Make the scenario's default video map be visible
ps := &sp.currentPreferenceSet
ps.VideoMapVisible = make(map[string]interface{})
ps.VideoMapVisible[s.DefaultMap] = nil
}
func (sp *STARSPane) DrawUI() {
sp.AutoTrackDepartures, _ = drawAirportSelector(sp.AutoTrackDepartures, "Auto track departure airports")
/*
if newFont, changed := DrawFontPicker(&sp.LabelFontIdentifier, "Label font"); changed {
sp.labelFont = newFont
}
*/
if imgui.CollapsingHeader("Collision alerts") {
imgui.SliderFloatV("Lateral minimum (nm)", &sp.Facility.CA.LateralMinimum, 0, 10, "%.1f", 0)
imgui.InputIntV("Vertical minimum (feet)", &sp.Facility.CA.VerticalMinimum, 100, 100, 0)
imgui.InputIntV("Altitude floor (feet)", &sp.Facility.CA.Floor, 100, 100, 0)
}
/*
if imgui.CollapsingHeader("CRDA") {
sp.Facility.CRDAConfig.DrawUI()
}
*/
}
func (sp *STARSPane) CanTakeKeyboardFocus() bool { return true }
func (sp *STARSPane) processEvents(es *EventStream) {
ps := sp.currentPreferenceSet
for _, event := range es.Get(sp.eventsId) {
switch v := event.(type) {
case *AddedAircraftEvent:
sa := &STARSAircraftState{}
if v.ac.TrackingController == sim.Callsign() {
sa.datablockType = FullDatablock
}
sp.aircraft[v.ac] = sa
if fp := v.ac.FlightPlan; fp != nil {
if v.ac.TrackingController == "" {
if _, ok := sp.AutoTrackDepartures[fp.DepartureAirport]; ok {
sim.InitiateTrack(v.ac.Callsign) // ignore error...
sp.aircraft[v.ac].datablockType = FullDatablock
}
}
}
if !ps.DisableCRDA {
if ghost := sp.Facility.CRDAConfig.GetGhost(v.ac); ghost != nil {
sp.ghostAircraft[v.ac] = ghost
sp.aircraft[ghost] = &STARSAircraftState{
// TODO: other defaults?
isGhost: true,
displayTPASize: ps.DisplayTPASize,
}
}
}
if squawkingSPC(v.ac.Squawk) {
if _, ok := sp.havePlayedSPCAlertSound[v.ac]; !ok {
sp.havePlayedSPCAlertSound[v.ac] = nil
//globalConfig.AudioSettings.HandleEvent(AudioEventAlert)
}
}
case *RemovedAircraftEvent:
if ghost, ok := sp.ghostAircraft[v.ac]; ok {
delete(sp.aircraft, ghost)
}
delete(sp.aircraft, v.ac)
delete(sp.ghostAircraft, v.ac)
case *ModifiedAircraftEvent:
if squawkingSPC(v.ac.Squawk) {
if _, ok := sp.havePlayedSPCAlertSound[v.ac]; !ok {
sp.havePlayedSPCAlertSound[v.ac] = nil
//globalConfig.AudioSettings.HandleEvent(AudioEventAlert)
}
}
if !ps.DisableCRDA {
// always start out by removing the old ghost
if oldGhost, ok := sp.ghostAircraft[v.ac]; ok {
delete(sp.aircraft, oldGhost)
delete(sp.ghostAircraft, v.ac)
}
}
if _, ok := sp.aircraft[v.ac]; !ok {
sp.aircraft[v.ac] = &STARSAircraftState{}
}
// new ghost
if !ps.DisableCRDA {
if ghost := sp.Facility.CRDAConfig.GetGhost(v.ac); ghost != nil {
sp.ghostAircraft[v.ac] = ghost
sp.aircraft[ghost] = &STARSAircraftState{isGhost: true}
}
}
case *PointOutEvent:
sp.pointedOutAircraft.Add(v.ac, v.controller, 10*time.Second)
case *AcceptedHandoffEvent:
// Note that we only want to do that if we were the handing-off
// from controller, but that info isn't available to us
// currently. For the purposes of SimServer, that's fine...
if v.controller != sim.Callsign() {
state := sp.aircraft[v.ac]
state.outboundHandoffAccepted = true
state.outboundHandoffFlashEnd = time.Now().Add(10 * time.Second)
}
}
}
}
func (sp *STARSPane) Draw(ctx *PaneContext, cb *CommandBuffer) {
sp.processEvents(ctx.events)
cb.ClearRGB(RGB{}) // clear to black, regardless of the color scheme
if ctx.mouse != nil && ctx.mouse.Clicked[MouseButtonPrimary] {
wmTakeKeyboardFocus(sp, false)
}
sp.processKeyboardInput(ctx)
transforms := GetScopeTransformations(ctx, sp.currentPreferenceSet.currentCenter,
float32(sp.currentPreferenceSet.Range), 0)
ps := sp.currentPreferenceSet
drawBounds := Extent2D{
p0: [2]float32{0, 0},
p1: [2]float32{ctx.paneExtent.Width(), ctx.paneExtent.Height()}}
if ps.DisplayDCB {
sp.DrawDCB(ctx, transforms)
drawBounds.p1[1] -= STARSButtonHeight
// scissor so we can't draw in the DCB area
paneRemaining := ctx.paneExtent
paneRemaining.p1[1] -= STARSButtonHeight
fbPaneExtent := paneRemaining.Scale(dpiScale(platform))
cb.Scissor(int(fbPaneExtent.p0[0]), int(fbPaneExtent.p0[1]),
int(fbPaneExtent.Width()+.5), int(fbPaneExtent.Height()+.5))
}
weatherIntensity := float32(0)
for i, set := range ps.WeatherIntensity {
if set {
weatherIntensity = float32(i) / float32(len(ps.WeatherIntensity)-1)
}
}
if weatherIntensity != 0 {
sp.weatherRadar.Draw(weatherIntensity, transforms, cb)
}
color := ps.Brightness.RangeRings.RGB()
cb.LineWidth(1)
DrawRangeRings(ps.RangeRingsCenter, float32(ps.RangeRingRadius), color, transforms, cb)
transforms.LoadWindowViewingMatrices(cb)
// Maps
cb.PointSize(5)
cb.LineWidth(1)
for _, vmap := range scenarioGroup.STARSMaps {
if _, ok := ps.VideoMapVisible[vmap.Name]; !ok {
continue
}
color := ps.Brightness.VideoGroupA.RGB()
if vmap.Group == 1 {
color = ps.Brightness.VideoGroupB.RGB()
}
cb.SetRGB(color)
transforms.LoadLatLongViewingMatrices(cb)
cb.Call(vmap.cb)
}
transforms.LoadWindowViewingMatrices(cb)
if ps.Brightness.Compass > 0 {
cb.LineWidth(1)
cbright := ps.Brightness.Compass.RGB()
font := sp.systemFont[ps.CharSize.Tools]
DrawCompass(ps.currentCenter, ctx, 0, font, cbright, drawBounds, transforms, cb)
}
// Per-aircraft stuff: tracks, datablocks, vector lines, range rings, ...
// Sort the aircraft so that they are always drawn in the same order
// (go's map iterator randomization otherwise randomizes the order,
// which can cause shimmering when datablocks overlap (especially if
// one is selected). We'll go with alphabetical by callsign, with the
// selected aircraft, if any, always drawn last.
aircraft := sp.visibleAircraft()
sort.Slice(aircraft, func(i, j int) bool {
return aircraft[i].Callsign < aircraft[j].Callsign
})
sp.drawSystemLists(aircraft, ctx, transforms, cb)
sp.Facility.CRDAConfig.DrawRegions(ctx, transforms, cb)
// Tools before datablocks
sp.drawPTLs(aircraft, ctx, transforms, cb)
sp.drawRingsAndCones(aircraft, ctx, transforms, cb)
sp.drawRBLs(ctx, transforms, cb)
sp.drawMinSep(ctx, transforms, cb)
sp.drawCARings(ctx, transforms, cb)
sp.drawAirspace(ctx, transforms, cb)
DrawHighlighted(ctx, transforms, cb)
sp.drawTracks(aircraft, ctx, transforms, cb)
sp.updateDatablockTextAndPosition(aircraft)
sp.drawDatablocks(aircraft, ctx, transforms, cb)
sp.consumeMouseEvents(ctx, transforms)
}
func (sp *STARSPane) processKeyboardInput(ctx *PaneContext) {
if !ctx.haveFocus || ctx.keyboard == nil {
return
}
input := strings.ToUpper(ctx.keyboard.Input)
if sp.commandMode == CommandModeMultiFunc && sp.multiFuncPrefix == "" && len(input) > 0 {
sp.multiFuncPrefix = string(input[0])
input = input[1:]
}
sp.previewAreaInput += input
ps := &sp.currentPreferenceSet
//lg.Printf("input \"%s\" ctl %v alt %v", input, ctx.keyboard.IsPressed(KeyControl), ctx.keyboard.IsPressed(KeyAlt))
if ctx.keyboard.IsPressed(KeyControl) && len(input) == 1 && unicode.IsDigit(rune(input[0])) {
idx := byte(input[0]) - '0'
// This test should be redundant given the IsDigit check, but just to be safe...
if int(idx) < len(ps.Bookmarks) {
if ctx.keyboard.IsPressed(KeyAlt) {
// Record bookmark
ps.Bookmarks[idx].Center = ps.currentCenter
ps.Bookmarks[idx].Range = ps.Range
ps.Bookmarks[idx].TopDownMode = ps.TopDownMode
} else {
// Recall bookmark
ps.Center = ps.Bookmarks[idx].Center
ps.currentCenter = ps.Bookmarks[idx].Center
ps.Range = ps.Bookmarks[idx].Range
ps.TopDownMode = ps.Bookmarks[idx].TopDownMode
}
}
}
for key := range ctx.keyboard.Pressed {
switch key {
case KeyBackspace:
if len(sp.previewAreaInput) > 0 {
sp.previewAreaInput = sp.previewAreaInput[:len(sp.previewAreaInput)-1]
} else {
sp.multiFuncPrefix = ""
}
case KeyEnd:
sp.resetInputState()
sp.commandMode = CommandModeMin
case KeyEnter:
status := sp.executeSTARSCommand(sp.previewAreaInput)
if status.err != nil {
// TODO: rewrite errors returned by the ATCServer to e.g.,
// ILL TRK, etc.
sp.previewAreaOutput = status.err.Error()
} else {
if status.clear {
sp.resetInputState()
}
sp.previewAreaOutput = status.output
}
case KeyEscape:
sp.resetInputState()
sp.activeDCBMenu = DCBMenuMain
// Also disable any mouse capture from spinners, just in case
// the user is mashing escape to get out of one.
sp.disableMenuSpinner()
case KeyF1:
if ctx.keyboard.IsPressed(KeyControl) {
// Recenter
ps.Center = scenarioGroup.Center
ps.currentCenter = ps.Center
}
case KeyF2:
if ctx.keyboard.IsPressed(KeyControl) && ps.DisplayDCB {
sp.disableMenuSpinner()
sp.activeDCBMenu = DCBMenuMaps
} else {
sp.resetInputState()
sp.commandMode = CommandModeMaps
}
case KeyF3:
sp.resetInputState()
sp.commandMode = CommandModeInitiateControl
case KeyF4:
if ctx.keyboard.IsPressed(KeyControl) && ps.DisplayDCB {
sp.disableMenuSpinner()
sp.activeDCBMenu = DCBMenuBrite
} else {
sp.resetInputState()
sp.commandMode = CommandModeTerminateControl
}
case KeyF5:
if ctx.keyboard.IsPressed(KeyControl) && ps.DisplayDCB {
sp.activeDCBMenu = DCBMenuMain
sp.activateMenuSpinner(unsafe.Pointer(&ps.LeaderLineLength))
} else {
sp.resetInputState()
sp.commandMode = CommandModeHandOff
}
case KeyF6:
if ctx.keyboard.IsPressed(KeyControl) && ps.DisplayDCB {
sp.disableMenuSpinner()
sp.activeDCBMenu = DCBMenuCharSize
} else {
sp.resetInputState()
sp.commandMode = CommandModeVP
}
case KeyF7:
if ctx.keyboard.IsPressed(KeyControl) && ps.DisplayDCB {
sp.disableMenuSpinner()
if sp.activeDCBMenu == DCBMenuMain {
sp.activeDCBMenu = DCBMenuAux
} else {
sp.activeDCBMenu = DCBMenuMain
}
} else {
sp.resetInputState()
sp.commandMode = CommandModeMultiFunc
}
case KeyF8:
if ctx.keyboard.IsPressed(KeyControl) {
sp.disableMenuSpinner()
ps.DisplayDCB = !ps.DisplayDCB
}
case KeyF9:
if ctx.keyboard.IsPressed(KeyControl) && ps.DisplayDCB {
sp.disableMenuSpinner()
sp.activateMenuSpinner(unsafe.Pointer(&ps.RangeRingRadius))
} else {
sp.resetInputState()
sp.commandMode = CommandModeFlightData
}
case KeyF10:
if ctx.keyboard.IsPressed(KeyControl) && ps.DisplayDCB {
sp.disableMenuSpinner()
sp.activateMenuSpinner(unsafe.Pointer(&ps.Range))
}
case KeyF11:
if ctx.keyboard.IsPressed(KeyControl) && ps.DisplayDCB {
sp.disableMenuSpinner()
sp.activeDCBMenu = DCBMenuSite
} else {
sp.resetInputState()
sp.commandMode = CommandModeCollisionAlert
}
}
}
}
func (sp *STARSPane) disableMenuSpinner() {
activeSpinner = nil
platform.EndCaptureMouse()
}