-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathVMCController.cs
More file actions
126 lines (109 loc) · 4.91 KB
/
VMCController.cs
File metadata and controls
126 lines (109 loc) · 4.91 KB
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
using ColossalFramework;
using ColossalFramework.UI;
using Klyte.Commons.Interfaces;
using Klyte.Commons.Utils;
using Klyte.VehiclesMasterControl.Extensors.VehicleExt;
using Klyte.VehiclesMasterControl.UI;
using Klyte.VehiclesMasterControl.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace Klyte.VehiclesMasterControl
{
public class VMCController : BaseController<VehiclesMasterControlMod, VMCController>
{
public static readonly string FOLDER_NAME = "VehiclesMasterControl";
public static readonly string FOLDER_PATH = FileUtils.BASE_FOLDER_PATH + FOLDER_NAME;
protected override void StartActions()
{
KlyteMonoUtils.CreateUIElement(out UIPanel buildingInfoParent, FindObjectOfType<UIView>().transform, "VMCBuildingInfoPanel", new Vector4(0, 0, 0, 1));
buildingInfoParent.gameObject.AddComponent<VMCBuildingInfoPanel>();
initNearLinesOnWorldInfoPanel();
m_districtCooldown = 10;
}
public void OpenVMCPanel() => VehiclesMasterControlMod.Instance.OpenPanelAtModTab();
public event Action eventOnDistrictChanged;
private static int m_districtCooldown;
public static void OnDistrictChanged() => m_districtCooldown = 10;
public void Update()
{
if (m_districtCooldown > 0)
{
m_districtCooldown--;
if (m_districtCooldown == 0)
{
eventOnDistrictChanged?.Invoke();
}
}
}
private void initNearLinesOnWorldInfoPanel()
{
BuildingWorldInfoPanel[] panelList = GameObject.Find("UIView").GetComponentsInChildren<BuildingWorldInfoPanel>();
LogUtils.DoLog("WIP LIST: [{0}]", string.Join(", ", panelList.Select(x => x.name).ToArray()));
foreach (BuildingWorldInfoPanel wip in panelList)
{
LogUtils.DoLog("LOADING WIP HOOK FOR: {0}", wip.name);
UIPanel parent = wip.gameObject.GetComponent<UIPanel>();
if (parent == null)
{
return;
}
parent.eventVisibilityChanged += (component, value) =>
{
updateBuildingEditShortcutButton(parent);
};
parent.eventPositionChanged += (component, value) =>
{
updateBuildingEditShortcutButton(parent);
};
}
}
private void updateBuildingEditShortcutButton(UIPanel parent)
{
if (parent != null)
{
UIButton buildingEditShortcut = parent.Find<UIButton>("VMCBuildingShortcut");
if (!buildingEditShortcut)
{
buildingEditShortcut = initBuildingEditOnWorldInfoPanel(parent);
}
FieldInfo prop = typeof(WorldInfoPanel).GetField("m_InstanceID", System.Reflection.BindingFlags.NonPublic
| System.Reflection.BindingFlags.Instance);
ushort buildingId = ((InstanceID)(prop.GetValue(parent.gameObject.GetComponent<WorldInfoPanel>()))).Building;
IEnumerable<ServiceSystemDefinition> ssds = ServiceSystemDefinition.from(Singleton<BuildingManager>.instance.m_buildings.m_buffer[buildingId].Info);
byte count = 0;
foreach (ServiceSystemDefinition ssd in ssds)
{
int maxCount = VMCBuildingUtils.GetMaxVehiclesBuilding(ref BuildingManager.instance.m_buildings.m_buffer[buildingId], ssd.vehicleType, ssd.level);
if (maxCount > 0)
{
count++;
break;
}
}
buildingEditShortcut.isVisible = count > 0;
}
}
private UIButton initBuildingEditOnWorldInfoPanel(UIPanel parent)
{
UIButton saida = parent.AddUIComponent<UIButton>();
saida.relativePosition = new Vector3(-40, parent.height - 50);
saida.width = 30;
saida.height = 30;
saida.name = "VMCBuildingShortcut";
saida.color = new Color32(170, 170, 170, 255);
saida.hoveredColor = Color.white;
saida.tooltipLocaleID = "K45_VMC_GOTO_BUILDING_CONFIG_EDIT";
KlyteMonoUtils.InitButtonSameSprite(saida, "VehiclesMasterControlIcon");
saida.eventClick += (x, y) =>
{
FieldInfo prop = typeof(WorldInfoPanel).GetField("m_InstanceID", BindingFlags.NonPublic | BindingFlags.Instance);
ushort buildingId = ((InstanceID)(prop.GetValue(parent.gameObject.GetComponent<WorldInfoPanel>()))).Building;
VMCBuildingInfoPanel.instance.openInfo(buildingId);
};
return saida;
}
}
}