|
1 | | -// Visual Pinball Engine |
2 | | -// Copyright (C) 2022 freezy and VPE Team |
3 | | -// |
4 | | -// This program is free software: you can redistribute it and/or modify |
5 | | -// it under the terms of the GNU General Public License as published by |
6 | | -// the Free Software Foundation, either version 3 of the License, or |
7 | | -// (at your option) any later version. |
8 | | -// |
9 | | -// This program is distributed in the hope that it will be useful, |
10 | | -// but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | | -// GNU General Public License for more details. |
13 | | -// |
14 | | -// You should have received a copy of the GNU General Public License |
15 | | -// along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | | - |
17 | | -// ReSharper disable UnusedType.Global |
18 | | - |
19 | | -using System; |
20 | | -using System.Collections.Generic; |
21 | | -using System.Linq; |
22 | | -using Unity.VisualScripting; |
23 | | - |
24 | | -namespace VisualPinball.Unity.VisualScripting.Editor |
25 | | -{ |
26 | | - [Widget(typeof(LampEventUnit))] |
27 | | - public sealed class LampEventUnitWidget : GleUnitWidget<LampEventUnit> |
28 | | - { |
29 | | - private readonly List<Func<Metadata, VariableNameInspector>> _lampIdInspectorConstructorList; |
30 | | - |
31 | | - public LampEventUnitWidget(FlowCanvas canvas, LampEventUnit unit) : base(canvas, unit) |
32 | | - { |
33 | | - _lampIdInspectorConstructorList = new List<Func<Metadata, VariableNameInspector>>(); |
34 | | - } |
35 | | - |
36 | | - public override Inspector GetPortInspector(IUnitPort port, Metadata meta) |
37 | | - { |
38 | | - if (_lampIdInspectorConstructorList.Count() < unit.inputCount) |
39 | | - { |
40 | | - for (var index = 0; index < unit.inputCount - _lampIdInspectorConstructorList.Count(); index++) |
41 | | - { |
42 | | - _lampIdInspectorConstructorList.Add(meta => new VariableNameInspector(meta, GetNameSuggestions)); |
43 | | - } |
44 | | - } |
45 | | - |
46 | | - for (var index = 0; index < unit.inputCount; index++) |
47 | | - { |
48 | | - if (unit.multiInputs[index] == port) |
49 | | - { |
50 | | - VariableNameInspector lampIdInspector = new VariableNameInspector(meta, GetNameSuggestions); |
51 | | - InspectorProvider.instance.Renew(ref lampIdInspector, meta, _lampIdInspectorConstructorList[index]); |
52 | | - |
53 | | - return lampIdInspector; |
54 | | - } |
55 | | - } |
56 | | - |
57 | | - return base.GetPortInspector(port, meta); |
58 | | - } |
59 | | - |
60 | | - private IEnumerable<string> GetNameSuggestions() |
61 | | - { |
62 | | - return !GleAvailable |
63 | | - ? new List<string>() |
64 | | - : Gle.RequestedLamps.Select(lamp => lamp.Id).ToList(); |
65 | | - } |
66 | | - } |
67 | | -} |
| 1 | +// Visual Pinball Engine |
| 2 | +// Copyright (C) 2022 freezy and VPE Team |
| 3 | +// |
| 4 | +// This program is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// This program is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +// ReSharper disable UnusedType.Global |
| 18 | + |
| 19 | +using System.Collections.Generic; |
| 20 | +using System.Linq; |
| 21 | +using Unity.VisualScripting; |
| 22 | + |
| 23 | +namespace VisualPinball.Unity.VisualScripting.Editor |
| 24 | +{ |
| 25 | + [Widget(typeof(LampEventUnit))] |
| 26 | + public sealed class LampEventUnitWidget : GleMultiUnitWidget<LampEventUnit> |
| 27 | + { |
| 28 | + public LampEventUnitWidget(FlowCanvas canvas, LampEventUnit unit) : base(canvas, unit) |
| 29 | + { |
| 30 | + } |
| 31 | + |
| 32 | + protected override IEnumerable<string> IdSuggestions(IGamelogicEngine gle) => gle.RequestedLamps.Select(lamp => lamp.Id); |
| 33 | + } |
| 34 | +} |
0 commit comments