|
1 | 1 | using UnityEngine; |
| 2 | +using System.Collections.Generic; |
2 | 3 | using KSP.UI.Screens; |
3 | 4 |
|
| 5 | + |
4 | 6 | #if !DUMMY |
5 | 7 | namespace ClickThroughFix |
6 | 8 | { |
| 9 | + internal class PartEAPS |
| 10 | + { |
| 11 | + |
| 12 | + internal uint persistentId; |
| 13 | + internal Part p; |
| 14 | + internal EditorActionPartSelector eaps; |
| 15 | + |
| 16 | + internal PartEAPS(Part p) |
| 17 | + { |
| 18 | + this.persistentId = p.persistentId; |
| 19 | + this.p = p; |
| 20 | + this.eaps = p.GetComponent<EditorActionPartSelector>(); |
| 21 | + } |
| 22 | + } |
| 23 | + |
7 | 24 | [KSPAddon(KSPAddon.Startup.SpaceCentre, true)] |
8 | 25 | class CBTMonitor : MonoBehaviour |
9 | 26 | { |
| 27 | + static internal Dictionary<uint, PartEAPS> partEAPSDict; |
| 28 | + |
10 | 29 | void Start() |
11 | 30 | { |
12 | 31 | DontDestroyOnLoad(this); |
13 | | - GameEvents.onGameSceneLoadRequested.Add(onGameSceneLoadRequested); |
| 32 | + GameEvents.onGameSceneLoadRequested.Add(onGameSceneLoadRequested); |
| 33 | + GameEvents.onEditorShipModified.Add(_onEditorShipModified); |
| 34 | + GameEvents.onLevelWasLoadedGUIReady.Add(onLevelWasLoadedGUIReady); |
| 35 | + |
14 | 36 | ClickThruBlocker.CTBWin.activeBlockerCnt = 0; |
| 37 | + partEAPSDict = new Dictionary<uint, PartEAPS>(); |
15 | 38 | } |
16 | 39 |
|
17 | 40 | void onGameSceneLoadRequested(GameScenes gs) |
18 | 41 | { |
19 | 42 | ClickThruBlocker.CTBWin.activeBlockerCnt = 0; |
| 43 | + partEAPSDict.Clear(); |
| 44 | + } |
| 45 | + |
| 46 | + void ScanParts(List<Part> parts) |
| 47 | + { |
| 48 | + for (int i = parts.Count - 1; i >= 0; i--) |
| 49 | + { |
| 50 | + if (!partEAPSDict.ContainsKey(parts[i].persistentId)) |
| 51 | + { |
| 52 | + partEAPSDict.Add(parts[i].persistentId, new PartEAPS(parts[i])); |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + void _onEditorShipModified(ShipConstruct sc) |
| 57 | + { |
| 58 | + if (sc != null && sc.parts != null) |
| 59 | + { |
| 60 | + ScanParts(sc.parts); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + void onLevelWasLoadedGUIReady(GameScenes gs) |
| 65 | + { |
| 66 | + if (HighLogic.LoadedSceneIsEditor) |
| 67 | + { |
| 68 | + if (EditorLogic.fetch != null && EditorLogic.fetch.ship != null && EditorLogic.fetch.ship.Parts != null) |
| 69 | + ScanParts(EditorLogic.fetch.ship.Parts); |
| 70 | + } |
20 | 71 | } |
21 | 72 |
|
22 | 73 | // this whole mess below is to work around a stock bug. |
23 | | - // The bug is that the editor ignores the lock when the Action Group pane is show. |
| 74 | + // The bug is that the editor ignores the lock when the Action Group pane is shown. |
24 | 75 | // So we have to each time, clear all locks and then reset those which were active when |
25 | 76 | // the mouse moved over a protected window |
26 | 77 | void Update() |
27 | 78 | { |
28 | | - if (HighLogic.LoadedSceneIsEditor && ClearInputLocks.focusFollowsclick) // || |
29 | | - //(!HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick && !HighLogic.LoadedSceneIsEditor)) |
| 79 | + if (HighLogic.LoadedSceneIsEditor && ClearInputLocks.focusFollowsclick) |
30 | 80 | return; |
31 | | - |
| 81 | + if (ClickThruBlocker.CTBWin.activeBlockerCnt > 0) |
32 | 82 | { |
33 | | - if (ClickThruBlocker.CTBWin.activeBlockerCnt > 0) |
34 | | - { |
35 | | - //Log.Info("Setting Mouse.HoveredPart to null & deselecting all parts"); |
36 | | - Mouse.HoveredPart = null; |
| 83 | + //Log.Info("Setting Mouse.HoveredPart to null & deselecting all parts"); |
| 84 | + Mouse.HoveredPart = null; |
37 | 85 |
|
38 | | - if (EditorLogic.fetch == null) |
39 | | - { |
40 | | - return; |
41 | | - } |
| 86 | + if (EditorLogic.fetch == null) |
| 87 | + { |
| 88 | + return; |
| 89 | + } |
| 90 | + for (int i = EditorLogic.fetch.ship.Parts.Count - 1; i >= 0; i--) |
| 91 | + { |
| 92 | + EditorActionPartSelector selector = partEAPSDict[EditorLogic.fetch.ship.Parts[i].persistentId].eaps; // EditorLogic.fetch.ship.Parts[i].GetComponent<EditorActionPartSelector>(); |
| 93 | + if (selector != null) |
| 94 | + selector.Deselect(); |
| 95 | + } |
42 | 96 |
|
43 | | - for (int i = EditorLogic.fetch.ship.Parts.Count - 1; i >= 0; i--) |
44 | | - //for (int i = 0; i < EditorLogic.fetch.ship.Parts.Count; i++) |
| 97 | + if (EditorActionGroups.Instance != null) |
| 98 | + { |
| 99 | + if (EditorActionGroups.Instance.HasSelectedParts()) |
| 100 | + EditorActionGroups.Instance.ClearSelection(true); |
| 101 | + for (int i = ClickThruBlocker.CTBWin.selectedParts.Count - 1; i >= 0; i--) |
| 102 | + //for (int i = 0; i < ClickThruBlocker.CTBWin.selectedParts.Count; i++) |
45 | 103 | { |
46 | | - EditorActionPartSelector selector = EditorLogic.fetch.ship.Parts[i].GetComponent<EditorActionPartSelector>(); |
| 104 | + EditorActionPartSelector selector = partEAPSDict[ClickThruBlocker.CTBWin.selectedParts[i].persistentId].eaps; // ClickThruBlocker.CTBWin.selectedParts[i].GetComponent<EditorActionPartSelector>(); |
47 | 105 | if (selector != null) |
48 | | - selector.Deselect(); |
49 | | - } |
50 | | - |
51 | | - if (EditorActionGroups.Instance != null) |
52 | | - { |
53 | | - EditorActionGroups.Instance.ClearSelection(true); |
54 | | - for (int i = ClickThruBlocker.CTBWin.selectedParts.Count - 1; i >= 0; i--) |
55 | | - //for (int i = 0; i < ClickThruBlocker.CTBWin.selectedParts.Count; i++) |
56 | | - { |
57 | | - EditorActionPartSelector selector = ClickThruBlocker.CTBWin.selectedParts[i].GetComponent<EditorActionPartSelector>(); |
58 | | - if (selector != null) |
59 | | - EditorActionGroups.Instance.AddToSelection(selector); |
60 | | - } |
| 106 | + EditorActionGroups.Instance.AddToSelection(selector); |
61 | 107 | } |
62 | 108 | } |
63 | | - |
64 | 109 | } |
| 110 | + |
65 | 111 | } |
66 | 112 |
|
67 | 113 | //static internal long timeTics = 0; |
|
0 commit comments