-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMod.cs
More file actions
133 lines (115 loc) · 5.95 KB
/
Copy pathMod.cs
File metadata and controls
133 lines (115 loc) · 5.95 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
using Colossal.IO.AssetDatabase;
using Colossal.Logging;
using Colossal.UI;
using Game;
using Game.Modding;
using Game.Notifications;
using Game.SceneFlow;
using System;
using System.IO;
using Unity.Entities;
namespace VehicleUse
{
public class Mod : IMod
{
// Create a new log just for this mod.
// This mod will have its own log file in the game's Logs folder.
public static readonly ILog log = LogManager.GetLogger(ModAssemblyInfo.Name)
.SetShowsErrorsInUI(true) // Show message in UI for severity level Error and above.
.SetShowsStackTraceAboveLevels(Level.Error); // Include stack trace for severity level Error and above.
// The global settings for this mod.
public static ModSettings ModSettings { get; private set; }
// URI for UI images.
// When the URI is used to access an image, the game forces the URI portion to lower case.
// So make the URI lower case here to be compatible.
public static string ImagesURI { get { return ModAssemblyInfo.Name.ToLower(); } }
public void OnLoad(UpdateSystem updateSystem)
{
log.Info($"{nameof(Mod)}.{nameof(OnLoad)} Version {ModAssemblyInfo.Version}");
try
{
// Load mod settings but do not register settings in UI because all settings are hidden.
ModSettings = new ModSettings(this);
AssetDatabase.global.LoadSettings(ModAssemblyInfo.Name, ModSettings, new ModSettings(this));
// The two vehicle source settings cannot both be false.
if (!ModSettings.VehicleSourceCity && !ModSettings.VehicleSourceOutsideConnections)
{
ModSettings.VehicleSourceCity = true;
}
// The two vehicle status settings cannot both be false.
if (!ModSettings.VehicleStatusHas && !ModSettings.VehicleStatusEmpty)
{
ModSettings.VehicleStatusHas = true;
}
// The two vehicle display settings cannot both be false.
if (!ModSettings.VehicleDisplayColor && !ModSettings.VehicleDisplayIcon)
{
ModSettings.VehicleDisplayColor = true;
}
// Initialize translations.
Translation.Initialize();
// Add mod UI images directory to UI resource handler.
if (!GameManager.instance.modManager.TryGetExecutableAsset(this, out ExecutableAsset modExecutableAsset))
{
log.Error("Unable to get mod executable asset.");
return;
}
string assemblyPath = Path.GetDirectoryName(modExecutableAsset.path);
string imagesPath = Path.Combine(assemblyPath, "Images");
UIManager.defaultUISystem.AddHostLocation(ImagesURI, imagesPath);
// Initialize infoview infos by referencing the instance.
VUInfoviewInfos infoviewInfos = VUInfoviewInfos.Instance;
// Create the vehicle color system.
// This sytem does not need to be activated because it uses Harmony to run when ObjectColorsystem.OnUpdate() runs.
World.DefaultGameObjectInjectionWorld.GetOrCreateSystemManaged<VehicleColorSystem>();
// Create and activate this mod's systems.
updateSystem.UpdateAt<VehicleUseUISystem>(SystemUpdatePhase.UIUpdate);
updateSystem.UpdateAfter<VehicleIconSystem, MarkerCreateSystem>(SystemUpdatePhase.ModificationEnd);
#if DEBUG
// Get localized text from the game where the value is or contains specific text.
//Colossal.Localization.LocalizationManager localizationManager = GameManager.instance.localizationManager;
//foreach (System.Collections.Generic.KeyValuePair<string, string> keyValue in localizationManager.activeDictionary.entries)
//{
// // Exclude assets.
// if (!keyValue.Key.StartsWith("Assets."))
// {
// if (keyValue.Value.ToLower() == "vehicle" || keyValue.Value.ToLower() == "no vehicles")
// //if (keyValue.Key.ToLower().Contains("private_vehicle"))
// //if (keyValue.Value.ToLower().Contains("plow"))
// {
// log.Info(keyValue.Key + "\t" + keyValue.Value);
// }
// }
//}
// For a specific localization key, get the localized text for each base game locale ID.
//string[] localeIDs = new string[] { "en-US", "de-DE", "es-ES", "fr-FR", "it-IT", "ja-JP", "ko-KR", "pl-PL", "pt-BR", "ru-RU", "zh-HANS", "zh-HANT" };
//foreach (string localeID in localeIDs)
//{
// localizationManager.SetActiveLocale(localeID);
// foreach (System.Collections.Generic.KeyValuePair<string, string> keyValue in localizationManager.activeDictionary.entries)
// {
// if (keyValue.Key == "Common.VALUE_MILLION")
// {
// log.Info(keyValue.Key + "\t" + localeID + "\t" + keyValue.Value);
// break;
// }
// }
//}
//localizationManager.SetActiveLocale("en-US");
#endif
}
catch (Exception ex)
{
log.Error(ex);
}
log.Info($"{nameof(Mod)}.{nameof(OnLoad)} complete.");
}
public void OnDispose()
{
log.Info($"{nameof(Mod)}.{nameof(OnDispose)}");
// Unregister mod settings.
ModSettings?.UnregisterInOptionsUI();
ModSettings = null;
}
}
}