-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMod.cs
More file actions
126 lines (110 loc) · 5.44 KB
/
Copy pathMod.cs
File metadata and controls
126 lines (110 loc) · 5.44 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 Colossal.IO.AssetDatabase;
using Colossal.Logging;
using Colossal.UI;
using Game;
using Game.Modding;
using Game.SceneFlow;
using System;
using System.IO;
namespace ResourceLocator
{
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(); } }
/// <summary>
/// One-time mod loading.
/// </summary>
public void OnLoad(UpdateSystem updateSystem)
{
log.Info($"{nameof(Mod)}.{nameof(OnLoad)} Version {ModAssemblyInfo.Version}");
try
{
// Register and load mod settings.
ModSettings = new ModSettings(this);
ModSettings.RegisterInOptionsUI();
AssetDatabase.global.LoadSettings(ModAssemblyInfo.Name, ModSettings, new ModSettings(this));
// 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 the infoview.
RLInfoviewUtils.Initialize();
// Initialize production/surplus.
ProductionSurplus.Initialize();
// Create and activate this mod's systems.
updateSystem.UpdateAt<ResourceLocatorUISystem>(SystemUpdatePhase.UIUpdate);
updateSystem.UpdateAt<BuildingColorSystem>(SystemUpdatePhase.Rendering);
#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().Contains("companies"))
// //if (keyValue.Value.StartsWith("Cargo"))
// if (keyValue.Value.ToLower() == "raw materials" || keyValue.Value.ToLower() == "processed goods")
// {
// log.Info(keyValue.Key + "\t" + keyValue.Value);
// }
// // SelectedInfoPanel.VEHICLE_STATES[Fishing]
// }
//}
// 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 == "Tutorials.TITLE[InlandFishFarmingTutorial]")
// {
// log.Info(keyValue.Key + "\t" + localeID + "\t" + keyValue.Value);
// break;
// }
// }
//}
//localizationManager.SetActiveLocale("en-US");
// Create UI files.
// Uncomment this only when the UI files need to be created or recreated.
// Then run the mod once in the game to create the files.
// Then comment this again. The UI files are now available to use.
//CreateUIFiles.Create();
#endif
}
catch(Exception ex)
{
log.Error(ex);
}
log.Info($"{nameof(Mod)}.{nameof(OnLoad)} complete.");
}
/// <summary>
/// One-time mod disposing.
/// </summary>
public void OnDispose()
{
log.Info($"{nameof(Mod)}.{nameof(OnDispose)}");
// Unregister mod settings.
ModSettings?.UnregisterInOptionsUI();
ModSettings = null;
}
}
}