|
16 | 16 |
|
17 | 17 | using System; |
18 | 18 | using System.Collections.Generic; |
| 19 | +using System.Linq; |
19 | 20 | using Unity.VisualScripting; |
20 | 21 |
|
21 | 22 | namespace VisualPinball.Unity.VisualScripting.Editor |
22 | 23 | { |
23 | 24 | [Widget(typeof(LampEventUnit))] |
24 | | - public sealed class LampEventUnitWidget : UnitWidget<LampEventUnit> |
| 25 | + public sealed class LampEventUnitWidget : GleUnitWidget<LampEventUnit> |
25 | 26 | { |
26 | 27 | public LampEventUnitWidget(FlowCanvas canvas, LampEventUnit unit) : base(canvas, unit) |
27 | 28 | { |
28 | | - lampIdInspectorConstructor = (metadata) => new VariableNameInspector(metadata, GetNameSuggestions); |
| 29 | + _lampIdInspectorConstructor = meta => new VariableNameInspector(meta, GetNameSuggestions); |
29 | 30 | } |
30 | 31 |
|
31 | 32 | protected override NodeColorMix baseColor => NodeColorMix.TealReadable; |
32 | 33 |
|
33 | | - private VariableNameInspector lampIdInspector; |
34 | | - private Func<Metadata, VariableNameInspector> lampIdInspectorConstructor; |
| 34 | + private VariableNameInspector _lampIdInspector; |
| 35 | + private readonly Func<Metadata, VariableNameInspector> _lampIdInspectorConstructor; |
35 | 36 |
|
36 | | - public override Inspector GetPortInspector(IUnitPort port, Metadata metadata) |
| 37 | + public override Inspector GetPortInspector(IUnitPort port, Metadata meta) |
37 | 38 | { |
38 | | - if (port == unit.id) { |
39 | | - InspectorProvider.instance.Renew(ref lampIdInspector, metadata, lampIdInspectorConstructor); |
| 39 | + if (port == unit.Id) { |
| 40 | + InspectorProvider.instance.Renew(ref _lampIdInspector, meta, _lampIdInspectorConstructor); |
40 | 41 |
|
41 | | - return lampIdInspector; |
| 42 | + return _lampIdInspector; |
42 | 43 | } |
43 | 44 |
|
44 | | - return base.GetPortInspector(port, metadata); |
| 45 | + return base.GetPortInspector(port, meta); |
45 | 46 | } |
46 | 47 |
|
47 | 48 | private IEnumerable<string> GetNameSuggestions() |
48 | 49 | { |
49 | | - var list = new List<string>(); |
50 | | - |
51 | | - var tableComponent = TableSelector.Instance.SelectedTable; |
52 | | - |
53 | | - if (tableComponent != null) { |
54 | | - var gle = tableComponent.gameObject.GetComponent<IGamelogicEngine>(); |
55 | | - |
56 | | - if (gle != null) { |
57 | | - foreach (var lamp in gle.AvailableLamps) { |
58 | | - list.Add(lamp.Id); |
59 | | - } |
60 | | - } |
| 50 | + if (!GameObjectAvailable) { |
| 51 | + return new List<string>(); |
61 | 52 | } |
62 | 53 |
|
63 | | - return list; |
| 54 | + var gle = Gle; |
| 55 | + return gle == null ? new List<string>() : gle.AvailableLamps.Select(lamp => lamp.Id).ToList(); |
64 | 56 | } |
65 | 57 | } |
66 | 58 | } |
0 commit comments