-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCityVitalsWatchLoader.cs
86 lines (72 loc) · 3.01 KB
/
CityVitalsWatchLoader.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
namespace CityVitalsWatch {
using ColossalFramework.UI;
using ICities;
using UnityEngine;
/// <summary>
/// Creates the City Vitals Watch panel when a game is loaded or started.
/// </summary>
public class CityVitalsWatchLoader : ILoadingExtension {
private static CityVitalsWatchPanel Panel = null;
/// <summary>
/// Loads the mod's settings and creates the City Vitals Watch panel.
/// </summary>
public static void CreatePanel() {
CityVitalsWatch.Settings = CityVitalsWatchSerializer.LoadSettings();
UIView uiViewParent = null;
foreach (var uiView in GameObject.FindObjectsOfType<UIView>()) {
if (uiView.name == "UIView") {
uiViewParent = uiView;
break;
}
}
if (uiViewParent != null) {
GameObject obj = new GameObject("CityVitalsWatchPanel");
obj.transform.parent = uiViewParent.cachedTransform;
Panel = obj.AddComponent<CityVitalsWatchPanel>();
}
}
/// <summary>
/// Saves the mod controls' positions to settings and destroys the City Vitals Watch panel.
/// </summary>
public static void DestroyPanel() {
var resolutionData = CityVitalsWatch.Settings.GetResolutionData(Screen.currentResolution.width, Screen.currentResolution.height);
resolutionData.PanelPositionX = Panel.relativePosition.x;
resolutionData.PanelPositionY = Panel.relativePosition.y;
resolutionData.ToggleButtonPositionX = Panel.ToggleButton.absolutePosition.x;
resolutionData.ToggleButtonPositionY = Panel.ToggleButton.absolutePosition.y;
CityVitalsWatchSerializer.SaveSettings(CityVitalsWatch.Settings);
Panel.gameObject.SetActive(false);
GameObject.Destroy(Panel.gameObject);
Panel = null;
}
/// <summary>
/// Called when the mod is created; does nothing.
/// </summary>
/// <param name="loading">Ignored parameter.</param>
public void OnCreated(ILoading loading) {
}
/// <summary>
/// Called when a level is loaded.
/// </summary>
/// <param name="mode">The type of loading operation being performed.</param>
public void OnLevelLoaded(LoadMode mode) {
// If a game is being loaded or started, load the settings and then create an object and attach the panel component
if (mode == LoadMode.LoadGame || mode == LoadMode.NewGame) {
CreatePanel();
}
}
/// <summary>
/// Called when a level is unloaded.
/// </summary>
public void OnLevelUnloading() {
if (Panel != null) {
DestroyPanel();
}
}
/// <summary>
/// Called when the mod is released; does nothing.
/// </summary>
public void OnReleased() {
}
}
}