-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMod.cs
More file actions
152 lines (130 loc) · 5.59 KB
/
Mod.cs
File metadata and controls
152 lines (130 loc) · 5.59 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
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
using Colossal.IO.AssetDatabase;
using Colossal.Logging;
using Colossal.PSI.Common;
using ctrlC.Constants;
using ctrlC.Rendering;
using ctrlC.Systems.AssetManagement;
using ctrlC.Systems.UISystem;
using ctrlC.Tools;
using ctrlC.Tools.Selection;
using Game;
using Game.Input;
using Game.Modding;
using Game.SceneFlow;
using Game.UI.Menu;
using System;
using System.IO;
using System.Linq;
using Unity.Entities;
using UnityEngine;
namespace ctrlC
{
public class Mod : IMod
{
#region Logger
public static ILog log = LogManager.GetLogger($"{nameof(ctrlC)}.{nameof(Mod)}").SetShowsErrorsInUI(false);
#endregion Logger
public const string kCopyActionName = "Copy Binding";
public const string kPhotoActionName = "Take Thumbnail Photo";
public const string kMirrorActionName = "Mirror Binding";
public const string kOpenModActionName = "Open Mod Binding";
public const string MOD_NAME = nameof(ctrlC);
public static bool AutoOpenPrefabMenu;
public static ProxyAction m_CopyAction;
public static ProxyAction m_PhotoAction;
public static ProxyAction m_MirrorAction;
public static ProxyAction m_OpenModAction;
public static string[] PrefabCategories = new string[4];
internal static NotificationUISystem _NotificationUISystem;
internal static ModUISystem m_ModUISystem;
internal static Setting m_Setting;
public static void ReadCategoryNames(string cat1, string cat2, string cat3, string cat4)
{
PrefabCategories[0] = cat1;
PrefabCategories[1] = cat2;
PrefabCategories[2] = cat3;
PrefabCategories[3] = cat4;
World.DefaultGameObjectInjectionWorld.GetOrCreateSystemManaged<ModUISystem>().PrefabCategoriesString = string.Join(", ", PrefabCategories);
}
public void OnCreateWorld(UpdateSystem updateSystem)
{
updateSystem.UpdateAt<ModUISystem>(SystemUpdatePhase.UIUpdate);
updateSystem.UpdateAt<PlacementTool>(SystemUpdatePhase.ToolUpdate);
updateSystem.UpdateAt<SelectionTool>(SystemUpdatePhase.ToolUpdate);
updateSystem.UpdateAt<OverlayCircleRenderer>(SystemUpdatePhase.ToolUpdate);
updateSystem.UpdateAt<ThumbnailCameraTool>(SystemUpdatePhase.ToolUpdate);
}
public void OnDispose()
{
log.Info(nameof(OnDispose));
m_Setting?.UnregisterInOptionsUI();
m_Setting = null;
}
public void OnLoad(UpdateSystem updateSystem)
{
log.Info(nameof(OnLoad));
_NotificationUISystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystemManaged<NotificationUISystem>();
if (GameManager.instance.modManager.TryGetExecutableAsset(this, out var asset))
{
PathConstants.ModPath = asset.path.Replace("ctrlC.dll", "");
log.Info($"Environment ModPath set to: {PathConstants.ModPath}");
}
if (!Directory.Exists(PathConstants.GetCouiThumbnailPath()))
{
log.Info($"Coui path didnt exist, creating path..");
Directory.CreateDirectory(PathConstants.GetCouiThumbnailPath());
}
string currentGameVersion = Game.Version.current.shortVersion;
log.Info($"Game version is {currentGameVersion}");
m_Setting = new Setting(this);
m_Setting.RegisterInOptionsUI();
GameManager.instance.localizationManager.AddSource("en-US", new LocaleEN(m_Setting));
m_Setting.RegisterKeyBindings();
AssetDatabase.global.LoadSettings(nameof(ctrlC), m_Setting, new Setting(this));
try
{
m_ModUISystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystemManaged<ModUISystem>();
ReadCategoryNames(m_Setting.Category1Name, m_Setting.Category2Name, m_Setting.Category3Name, m_Setting.Category4Name);
SetActions();
OnCreateWorld(updateSystem);
PrefabStorageSystem.TryLoadPrefabs();
}
catch
{
log.Warn($"CtrlC is outdated! Current version of ctrlC is not compatible with game version '{currentGameVersion}'");
log.Info($"For more info, visit {PathConstants.XLink}");
HandleOutdatedMod();
}
}
private void HandleOutdatedMod()
{
_NotificationUISystem.AddOrUpdateNotification(
"ctrlCOutDated",
title: "CtrlC is outdated! ",
text: "I will work on updating ctrlC A$AP. For more info, click on me",
progressState: ProgressState.None,
progress: 0,
onClicked: OpenLink,
thumbnail: PathConstants.ModPath + "/.BuildContent/Images/C.png"
);
}
private void OpenLink()
{
Application.OpenURL(PathConstants.XLink);
}
private void SetActions()
{
m_OpenModAction = m_Setting.GetAction(kOpenModActionName);
m_CopyAction = m_Setting.GetAction(kCopyActionName);
m_PhotoAction = m_Setting.GetAction(kPhotoActionName);
m_MirrorAction = m_Setting.GetAction(kMirrorActionName);
m_OpenModAction.shouldBeEnabled = true;
m_OpenModAction.onInteraction += (_, _) => StartMod();
AutoOpenPrefabMenu = m_Setting.AutoOpenPrefabMenu;
}
private void StartMod()
{
m_ModUISystem.StartMod();
}
}
}