forked from bloodypenguin/ImprovedPublicTransport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VehicleListBox.cs
285 lines (265 loc) · 10.2 KB
/
VehicleListBox.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
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
// Decompiled with JetBrains decompiler
// Type: ImprovedPublicTransport.VehicleListBox
// Assembly: ImprovedPublicTransport, Version=1.0.6177.17409, Culture=neutral, PublicKeyToken=null
// MVID: 76F370C5-F40B-41AE-AA9D-1E3F87E934D3
// Assembly location: C:\Games\Steam\steamapps\workshop\content\255710\424106600\ImprovedPublicTransport.dll
using ColossalFramework.UI;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace ImprovedPublicTransport2
{
public class VehicleListBox : UIPanel
{
protected int _itemHeight = 27;
protected float _nextKeyCombi = Time.time;
protected VehicleListBoxRow[] _items = new VehicleListBoxRow[0];
protected UIScrollablePanel _scrollablePanel;
protected UIScrollbar _scrollbar;
public UIFont Font { get; set; }
public new float height
{
get
{
return this.m_Size.y;
}
set
{
this.size = new Vector2(this.m_Size.x, value);
if ((UnityEngine.Object) this._scrollablePanel != (UnityEngine.Object) null)
this._scrollablePanel.height = value;
if (!((UnityEngine.Object) this._scrollbar != (UnityEngine.Object) null))
return;
this._scrollbar.parent.height = value;
this._scrollbar.height = value;
this._scrollbar.trackObject.height = value;
}
}
public int SelectedIndex
{
get
{
int num = -1;
for (int index = 0; index < this._items.Length; ++index)
{
if (this._items[index].IsSelected)
{
num = index;
break;
}
}
return num;
}
}
public int[] SelectedIndexes
{
get
{
List<int> intList = new List<int>();
for (int index = 0; index < this._items.Length; ++index)
{
if (this._items[index].IsSelected)
intList.Add(index);
}
return intList.ToArray();
}
}
public HashSet<ushort> SelectedVehicles
{
get
{
HashSet<ushort> ushortSet = new HashSet<ushort>();
for (int index = 0; index < this._items.Length; ++index)
{
VehicleListBoxRow vehicleListBoxRow = this._items[index];
if (vehicleListBoxRow.IsSelected)
ushortSet.Add(vehicleListBoxRow.VehicleID);
}
return ushortSet;
}
}
public HashSet<string> SelectedItems
{
get
{
HashSet<string> stringSet = new HashSet<string>();
for (int index = 0; index < this._items.Length; ++index)
{
VehicleListBoxRow vehicleListBoxRow = this._items[index];
if (vehicleListBoxRow.IsSelected)
stringSet.Add(vehicleListBoxRow.Prefab.ObjectName);
}
return stringSet;
}
set
{
if (value == null || this.SelectedItems == value)
return;
for (int index = 0; index < this._items.Length; ++index)
{
VehicleListBoxRow vehicleListBoxRow = this._items[index];
if (value.Contains(vehicleListBoxRow.Prefab.ObjectName))
vehicleListBoxRow.IsSelected = true;
}
}
}
public HashSet<string> Items
{
get
{
HashSet<string> stringSet = new HashSet<string>();
for (int index = 0; index < this._items.Length; ++index)
{
VehicleListBoxRow vehicleListBoxRow = this._items[index];
stringSet.Add(vehicleListBoxRow.Prefab.ObjectName);
}
return stringSet;
}
}
public event MouseEventHandler eventRowShiftClick;
public event PropertyChangedEventHandler<HashSet<string>> eventSelectedItemsChanged;
private bool AllSelected()
{
for (int index = 0; index < this._items.Length; ++index)
{
if (!this._items[index].IsSelected)
return false;
}
return true;
}
public void SetSelectionStateToAll(bool state, bool triggerItemsChangedEvent = false)
{
for (int index = 0; index < this._items.Length; ++index)
this._items[index].IsSelected = state;
if (!triggerItemsChangedEvent)
return;
this.OnSelectedItemsChanged();
}
public void ClearItems()
{
if (this._items.Length == 0)
return;
for (int index = 0; index < this._items.Length; ++index)
UnityEngine.Object.Destroy((UnityEngine.Object) this._items[index].gameObject);
this._items = new VehicleListBoxRow[0];
this._scrollablePanel.scrollPosition = new Vector2(0.0f, 0.0f);
}
public void AddItem(PrefabData data, ushort vehicleID = 0)
{
VehicleListBoxRow[] vehicleListBoxRowArray = new VehicleListBoxRow[this._items.Length + 1];
Array.Copy((Array) this._items, (Array) vehicleListBoxRowArray, this._items.Length);
VehicleListBoxRow vehicleListBoxRow = this._scrollablePanel.AddUIComponent<VehicleListBoxRow>();
if ((UnityEngine.Object) this.Font != (UnityEngine.Object) null)
vehicleListBoxRow.Font = this.Font;
vehicleListBoxRow.Prefab = data;
vehicleListBoxRow.VehicleID = vehicleID;
vehicleListBoxRow.eventMouseDown += new MouseEventHandler(this.OnMouseDown);
vehicleListBoxRowArray[this._items.Length] = vehicleListBoxRow;
this._items = vehicleListBoxRowArray;
}
private void OnMouseDown(UIComponent component, UIMouseEventParameter p)
{
VehicleListBoxRow vehicleListBoxRow = component as VehicleListBoxRow;
bool zoomIn = Input.GetKey(KeyCode.LeftShift) | Input.GetKey(KeyCode.RightShift);
if ((int) vehicleListBoxRow.VehicleID != 0 && p.buttons == UIMouseButton.Right)
{
InstanceID id = new InstanceID();
id.Vehicle = vehicleListBoxRow.VehicleID;
ToolsModifierControl.cameraController.SetTarget(id, ToolsModifierControl.cameraController.transform.position, zoomIn);
DefaultTool.OpenWorldInfoPanel(id, ToolsModifierControl.cameraController.transform.position);
}
else
{
if (p.buttons != UIMouseButton.Left)
return;
// ISSUE: reference to a compiler-generated field
if (this.eventRowShiftClick != null && zoomIn)
{
this.PlayClickSound(p.source);
// ISSUE: reference to a compiler-generated field
this.eventRowShiftClick(component, p);
if (vehicleListBoxRow.IsSelected)
return;
}
vehicleListBoxRow.IsSelected = !vehicleListBoxRow.IsSelected;
this.OnSelectedItemsChanged();
}
}
protected override void OnMouseHover(UIMouseEventParameter p)
{
base.OnMouseHover(p);
if (!((Input.GetKey(KeyCode.LeftControl) | Input.GetKey(KeyCode.RightControl)) & Input.GetKey(KeyCode.A)) || (double) this._nextKeyCombi >= (double) Time.time)
return;
this._nextKeyCombi = Time.time + 0.25f;
if (this.AllSelected())
this.SetSelectionStateToAll(false, true);
else
this.SetSelectionStateToAll(true, true);
}
protected internal virtual void OnSelectedItemsChanged()
{
// ISSUE: reference to a compiler-generated field
if (this.eventSelectedItemsChanged != null)
{
// ISSUE: reference to a compiler-generated field
this.eventSelectedItemsChanged((UIComponent) this, this.SelectedItems);
}
this.InvokeUpward("OnSelectedItemsChanged", (object) this.SelectedItems);
}
public static VehicleListBox Create(UIComponent parent)
{
return parent.AddUIComponent<VehicleListBox>();
}
public override void Start()
{
base.Start();
this.autoLayoutDirection = LayoutDirection.Horizontal;
this.autoLayoutStart = LayoutStart.TopLeft;
this.autoLayoutPadding = new RectOffset(0, 0, 0, 0);
this.autoLayout = true;
this._scrollablePanel = this.AddUIComponent<UIScrollablePanel>();
this._scrollablePanel.width = this.width - 10f;
this._scrollablePanel.height = this.height;
this._scrollablePanel.autoLayoutDirection = LayoutDirection.Vertical;
this._scrollablePanel.autoLayoutStart = LayoutStart.TopLeft;
this._scrollablePanel.autoLayoutPadding = new RectOffset(0, 0, 0, 0);
this._scrollablePanel.autoLayout = true;
this._scrollablePanel.clipChildren = true;
this._scrollablePanel.backgroundSprite = "UnlockingPanel";
this._scrollablePanel.color = (Color32) Color.black;
UIPanel uiPanel = this.AddUIComponent<UIPanel>();
uiPanel.width = 10f;
uiPanel.height = this.height;
uiPanel.autoLayoutDirection = LayoutDirection.Horizontal;
uiPanel.autoLayoutStart = LayoutStart.TopLeft;
uiPanel.autoLayoutPadding = new RectOffset(0, 0, 0, 0);
uiPanel.autoLayout = true;
UIScrollbar scrollbar = uiPanel.AddUIComponent<UIScrollbar>();
scrollbar.width = 10f;
scrollbar.height = scrollbar.parent.height;
scrollbar.orientation = UIOrientation.Vertical;
scrollbar.pivot = UIPivotPoint.BottomLeft;
scrollbar.AlignTo((UIComponent) uiPanel, UIAlignAnchor.TopRight);
scrollbar.minValue = 0.0f;
scrollbar.value = 0.0f;
scrollbar.incrementAmount = 27f;
this._scrollbar = scrollbar;
UISlicedSprite uiSlicedSprite1 = scrollbar.AddUIComponent<UISlicedSprite>();
uiSlicedSprite1.relativePosition = (Vector3) Vector2.zero;
uiSlicedSprite1.autoSize = true;
uiSlicedSprite1.size = uiSlicedSprite1.parent.size;
uiSlicedSprite1.fillDirection = UIFillDirection.Vertical;
uiSlicedSprite1.spriteName = "ScrollbarTrack";
scrollbar.trackObject = (UIComponent) uiSlicedSprite1;
UISlicedSprite uiSlicedSprite2 = uiSlicedSprite1.AddUIComponent<UISlicedSprite>();
uiSlicedSprite2.relativePosition = (Vector3) Vector2.zero;
uiSlicedSprite2.fillDirection = UIFillDirection.Vertical;
uiSlicedSprite2.autoSize = true;
uiSlicedSprite2.width = uiSlicedSprite2.parent.width - 4f;
uiSlicedSprite2.spriteName = "ScrollbarThumb";
scrollbar.thumbObject = (UIComponent) uiSlicedSprite2;
this._scrollablePanel.verticalScrollbar = scrollbar;
this._scrollablePanel.eventMouseWheel += (MouseEventHandler) ((component, param) => this._scrollablePanel.scrollPosition += new Vector2(0.0f, Mathf.Sign(param.wheelDelta) * -1f * scrollbar.incrementAmount));
}
}
}