-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSwitchableTankManagerUI.cs
78 lines (68 loc) · 2.29 KB
/
SwitchableTankManagerUI.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
using System;
using AT_Utils.UI;
using CC.UI;
using UnityEngine;
using UnityEngine.EventSystems;
namespace AT_Utils
{
public static class CC_UI
{
public static readonly UIBundle AssetBundle = UIBundle.Create("000_AT_Utils/cc_ui.bundle");
}
public class SwitchableTankManagerUI : UIWindowBase<TankManagerUI>
{
private readonly SwitchableTankManager manager;
public SwitchableTankManagerUI(SwitchableTankManager manager) : base(CC_UI.AssetBundle)
{
this.manager = manager ?? throw new ArgumentNullException(nameof(manager));
}
protected override void init_controller()
{
base.init_controller();
Controller.closeButton.onClick.AddListener(Close);
Controller.colorSettingsButton.onClick.AddListener(toggleColors);
Controller.onPointerEnterEvent.AddListener(highlightPart);
Controller.onPointerExitEvent.AddListener(highlightPartDefault);
Controller.SetTankManager(manager);
if(manager != null)
pos = manager.uiPos;
}
private void highlightPart(PointerEventData _)
{
var part = manager?.part;
if(part != null)
part.HighlightAlways(Colors.Active.color);
}
private void highlightPartDefault(PointerEventData _)
{
var part = manager?.part;
if(part != null)
part.SetHighlightDefault();
}
public override void SyncState()
{
base.SyncState();
if(manager != null)
manager.uiPos = pos;
}
protected override void onClose()
{
base.onClose();
highlightPartDefault(null);
}
public void Toggle(MonoBehaviour monoBehaviour) => Toggle(monoBehaviour, !manager.EnablePartControls);
public void OnLateUpdate()
{
if(!IsShown)
return;
if(manager.EnablePartControls)
{
Close();
return;
}
if(FlightGlobals.ready && manager.part != null)
Controller.gameObject.SetActive(manager.part.vessel == FlightGlobals.ActiveVessel);
Controller.UpdateDisplay();
}
}
}