├── .gitignore
├── AdvancedVehicleOptions
├── AdvancedVehicleOptions.cs
├── AdvancedVehicleOptions.csproj
├── AdvancedVehicleOptions.sln
├── Configuration.cs
├── DebugUtils.cs
├── GUI
│ ├── UIFastList.cs
│ ├── UIMainPanel.cs
│ ├── UIOptionPanel.cs
│ ├── UITitleBar.cs
│ ├── UIUtils.cs
│ ├── UIVehicleItem.cs
│ └── UIWarningModal.cs
├── PreviewRenderer.cs
├── Properties
│ └── AssemblyInfo.cs
├── SerializableDataExtension.cs
└── VehicleOptions.cs
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | build/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 |
25 | # Visual Studo 2015 cache/options directory
26 | .vs/
27 |
28 | # MSTest test Results
29 | [Tt]est[Rr]esult*/
30 | [Bb]uild[Ll]og.*
31 |
32 | # NUNIT
33 | *.VisualState.xml
34 | TestResult.xml
35 |
36 | # Build Results of an ATL Project
37 | [Dd]ebugPS/
38 | [Rr]eleasePS/
39 | dlldata.c
40 |
41 | *_i.c
42 | *_p.c
43 | *_i.h
44 | *.ilk
45 | *.meta
46 | *.obj
47 | *.pch
48 | *.pdb
49 | *.pgc
50 | *.pgd
51 | *.rsp
52 | *.sbr
53 | *.tlb
54 | *.tli
55 | *.tlh
56 | *.tmp
57 | *.tmp_proj
58 | *.log
59 | *.vspscc
60 | *.vssscc
61 | .builds
62 | *.pidb
63 | *.svclog
64 | *.scc
65 |
66 | # Chutzpah Test files
67 | _Chutzpah*
68 |
69 | # Visual C++ cache files
70 | ipch/
71 | *.aps
72 | *.ncb
73 | *.opensdf
74 | *.sdf
75 | *.cachefile
76 |
77 | # Visual Studio profiler
78 | *.psess
79 | *.vsp
80 | *.vspx
81 |
82 | # TFS 2012 Local Workspace
83 | $tf/
84 |
85 | # Guidance Automation Toolkit
86 | *.gpState
87 |
88 | # ReSharper is a .NET coding add-in
89 | _ReSharper*/
90 | *.[Rr]e[Ss]harper
91 | *.DotSettings.user
92 |
93 | # JustCode is a .NET coding addin-in
94 | .JustCode
95 |
96 | # TeamCity is a build add-in
97 | _TeamCity*
98 |
99 | # DotCover is a Code Coverage Tool
100 | *.dotCover
101 |
102 | # NCrunch
103 | _NCrunch_*
104 | .*crunch*.local.xml
105 |
106 | # MightyMoose
107 | *.mm.*
108 | AutoTest.Net/
109 |
110 | # Web workbench (sass)
111 | .sass-cache/
112 |
113 | # Installshield output folder
114 | [Ee]xpress/
115 |
116 | # DocProject is a documentation generator add-in
117 | DocProject/buildhelp/
118 | DocProject/Help/*.HxT
119 | DocProject/Help/*.HxC
120 | DocProject/Help/*.hhc
121 | DocProject/Help/*.hhk
122 | DocProject/Help/*.hhp
123 | DocProject/Help/Html2
124 | DocProject/Help/html
125 |
126 | # Click-Once directory
127 | publish/
128 |
129 | # Publish Web Output
130 | *.[Pp]ublish.xml
131 | *.azurePubxml
132 | # TODO: Comment the next line if you want to checkin your web deploy settings
133 | # but database connection strings (with potential passwords) will be unencrypted
134 | *.pubxml
135 | *.publishproj
136 |
137 | # NuGet Packages
138 | *.nupkg
139 | # The packages folder can be ignored because of Package Restore
140 | **/packages/*
141 | # except build/, which is used as an MSBuild target.
142 | !**/packages/build/
143 | # Uncomment if necessary however generally it will be regenerated when needed
144 | #!**/packages/repositories.config
145 |
146 | # Windows Azure Build Output
147 | csx/
148 | *.build.csdef
149 |
150 | # Windows Store app package directory
151 | AppPackages/
152 |
153 | # Others
154 | *.[Cc]ache
155 | ClientBin/
156 | [Ss]tyle[Cc]op.*
157 | ~$*
158 | *~
159 | *.dbmdl
160 | *.dbproj.schemaview
161 | *.pfx
162 | *.publishsettings
163 | node_modules/
164 | bower_components/
165 |
166 | # RIA/Silverlight projects
167 | Generated_Code/
168 |
169 | # Backup & report files from converting an old project file
170 | # to a newer Visual Studio version. Backup files are not needed,
171 | # because we have git ;-)
172 | _UpgradeReport_Files/
173 | Backup*/
174 | UpgradeLog*.XML
175 | UpgradeLog*.htm
176 |
177 | # SQL Server files
178 | *.mdf
179 | *.ldf
180 |
181 | # Business Intelligence projects
182 | *.rdl.data
183 | *.bim.layout
184 | *.bim_*.settings
185 |
186 | # Microsoft Fakes
187 | FakesAssemblies/
188 |
189 | # Node.js Tools for Visual Studio
190 | .ntvs_analysis.dat
191 |
192 | # Visual Studio 6 build log
193 | *.plg
194 |
195 | # Visual Studio 6 workspace options file
196 | *.opt
197 |
--------------------------------------------------------------------------------
/AdvancedVehicleOptions/AdvancedVehicleOptions.cs:
--------------------------------------------------------------------------------
1 | using ICities;
2 | using UnityEngine;
3 |
4 | using System;
5 | using System.Text;
6 | using System.Collections;
7 | using System.Collections.Generic;
8 | using System.IO;
9 |
10 | using ColossalFramework;
11 | using ColossalFramework.Threading;
12 | using ColossalFramework.UI;
13 |
14 | namespace AdvancedVehicleOptions
15 | {
16 | public class ModInfo : IUserMod
17 | {
18 | public ModInfo()
19 | {
20 | try
21 | {
22 | // Creating setting file
23 | GameSettings.AddSettingsFile(new SettingsFile[] { new SettingsFile() { fileName = AdvancedVehicleOptions.settingsFileName } });
24 | }
25 | catch (Exception e)
26 | {
27 | DebugUtils.Log("Couldn't load/create the setting file.");
28 | DebugUtils.LogException(e);
29 | }
30 | }
31 |
32 | public string Name
33 | {
34 | get { return "Advanced Vehicle Options " + version; }
35 | }
36 |
37 | public string Description
38 | {
39 | get { return "Customize your vehicles"; }
40 | }
41 |
42 | public void OnSettingsUI(UIHelperBase helper)
43 | {
44 | try
45 | {
46 | UICheckBox checkBox;
47 | UIHelperBase group = helper.AddGroup(Name);
48 |
49 | checkBox = (UICheckBox)group.AddCheckbox("Disable debug messages logging", DebugUtils.hideDebugMessages.value, (b) =>
50 | {
51 | DebugUtils.hideDebugMessages.value = b;
52 | });
53 | checkBox.tooltip = "If checked, debug messages won't be logged.";
54 |
55 | group.AddSpace(10);
56 |
57 | checkBox = (UICheckBox)group.AddCheckbox("Hide the user interface", AdvancedVehicleOptions.hideGUI.value, (b) =>
58 | {
59 | AdvancedVehicleOptions.hideGUI.value = b;
60 | AdvancedVehicleOptions.UpdateGUI();
61 |
62 | });
63 | checkBox.tooltip = "Hide the UI completely if you feel like you are done with it\nand want to save the little bit of memory it takes\nEverything else will still be functional";
64 |
65 | checkBox = (UICheckBox)group.AddCheckbox("Disable warning at map loading", !AdvancedVehicleOptions.onLoadCheck.value, (b) =>
66 | {
67 | AdvancedVehicleOptions.onLoadCheck.value = !b;
68 | });
69 | checkBox.tooltip = "Disable service vehicle availability check at the loading of a map";
70 |
71 | }
72 | catch (Exception e)
73 | {
74 | DebugUtils.Log("OnSettingsUI failed");
75 | DebugUtils.LogException(e);
76 | }
77 | }
78 |
79 | public const string version = "1.8.2";
80 | }
81 |
82 | public class AdvancedVehicleOptionsLoader : LoadingExtensionBase
83 | {
84 | private static AdvancedVehicleOptions instance;
85 |
86 | #region LoadingExtensionBase overrides
87 | ///
88 | /// Called when the level (game, map editor, asset editor) is loaded
89 | ///
90 | public override void OnLevelLoaded(LoadMode mode)
91 | {
92 | try
93 | {
94 | // Is it an actual game ?
95 | if (mode != LoadMode.LoadGame && mode != LoadMode.NewGame)
96 | {
97 | DefaultOptions.Clear();
98 | return;
99 | }
100 |
101 | AdvancedVehicleOptions.isGameLoaded = true;
102 |
103 | if (instance != null)
104 | {
105 | GameObject.DestroyImmediate(instance.gameObject);
106 | }
107 |
108 | instance = new GameObject("AdvancedVehicleOptions").AddComponent();
109 |
110 | try
111 | {
112 | DefaultOptions.BuildVehicleInfoDictionary();
113 | VehicleOptions.Clear();
114 | DebugUtils.Log("UIMainPanel created");
115 | }
116 | catch
117 | {
118 | DebugUtils.Log("Could not create UIMainPanel");
119 |
120 | if (instance != null)
121 | GameObject.Destroy(instance.gameObject);
122 |
123 | return;
124 | }
125 |
126 | //new EnumerableActionThread(BrokenAssetsFix);
127 | }
128 | catch (Exception e)
129 | {
130 | if (instance != null)
131 | GameObject.Destroy(instance.gameObject);
132 | DebugUtils.LogException(e);
133 | }
134 | }
135 |
136 | ///
137 | /// Called when the level is unloaded
138 | ///
139 | public override void OnLevelUnloading()
140 | {
141 | try
142 | {
143 | DebugUtils.Log("Restoring default values");
144 | DefaultOptions.RestoreAll();
145 | DefaultOptions.Clear();
146 |
147 | if (instance != null)
148 | GameObject.Destroy(instance.gameObject);
149 |
150 | AdvancedVehicleOptions.isGameLoaded = false;
151 | }
152 | catch (Exception e)
153 | {
154 | DebugUtils.LogException(e);
155 | }
156 | }
157 | #endregion
158 | }
159 |
160 | public class AdvancedVehicleOptions : MonoBehaviour
161 | {
162 | public const string settingsFileName = "AdvancedVehicleOptions";
163 |
164 | public static SavedBool hideGUI = new SavedBool("hideGUI", settingsFileName, false, true);
165 | public static SavedBool onLoadCheck = new SavedBool("onLoadCheck", settingsFileName, true, true);
166 |
167 | private static GUI.UIMainPanel m_mainPanel;
168 |
169 | private static VehicleInfo m_removeInfo;
170 | private static VehicleInfo m_removeParkedInfo;
171 |
172 | private const string m_fileName = "AdvancedVehicleOptions.xml";
173 |
174 | public static bool isGameLoaded = false;
175 | public static Configuration config = new Configuration();
176 |
177 | public void Start()
178 | {
179 | try
180 | {
181 | // Loading config
182 | AdvancedVehicleOptions.InitConfig();
183 |
184 | if (AdvancedVehicleOptions.onLoadCheck)
185 | {
186 | AdvancedVehicleOptions.CheckAllServicesValidity();
187 | }
188 |
189 | m_mainPanel = GameObject.FindObjectOfType();
190 | UpdateGUI();
191 | }
192 | catch (Exception e)
193 | {
194 | DebugUtils.Log("UI initialization failed.");
195 | DebugUtils.LogException(e);
196 |
197 | GameObject.Destroy(gameObject);
198 | }
199 | }
200 |
201 | public static void UpdateGUI()
202 | {
203 | if(!isGameLoaded) return;
204 |
205 | if(!hideGUI && m_mainPanel == null)
206 | {
207 | // Creating GUI
208 | m_mainPanel = UIView.GetAView().AddUIComponent(typeof(GUI.UIMainPanel)) as GUI.UIMainPanel;
209 | }
210 | else if (hideGUI && m_mainPanel != null)
211 | {
212 | GameObject.Destroy(m_mainPanel.gameObject);
213 | m_mainPanel = null;
214 | }
215 | }
216 |
217 | ///
218 | /// Init the configuration
219 | ///
220 | public static void InitConfig()
221 | {
222 | // Store modded values
223 | DefaultOptions.StoreAllModded();
224 |
225 | if(config.data != null)
226 | {
227 | config.DataToOptions();
228 |
229 | // Remove unneeded options
230 | List optionsList = new List();
231 |
232 | for (uint i = 0; i < config.options.Length; i++)
233 | {
234 | if (config.options[i] != null && config.options[i].prefab != null) optionsList.Add(config.options[i]);
235 | }
236 |
237 | config.options = optionsList.ToArray();
238 | }
239 | else if (File.Exists(m_fileName))
240 | {
241 | // Import config
242 | ImportConfig();
243 | return;
244 | }
245 | else
246 | {
247 | DebugUtils.Log("No configuration found. Default values will be used.");
248 | }
249 |
250 | // Checking for new vehicles
251 | CompileVehiclesList();
252 |
253 | // Checking for conflicts
254 | DefaultOptions.CheckForConflicts();
255 |
256 | // Update existing vehicles
257 | new EnumerableActionThread(VehicleOptions.UpdateCapacityUnits);
258 | new EnumerableActionThread(VehicleOptions.UpdateBackEngines);
259 |
260 | DebugUtils.Log("Configuration initialized");
261 | LogVehicleListSteamID();
262 | }
263 |
264 | ///
265 | /// Import the configuration file
266 | ///
267 | public static void ImportConfig()
268 | {
269 | if (!File.Exists(m_fileName))
270 | {
271 | DebugUtils.Log("Configuration file not found.");
272 | return;
273 | }
274 |
275 | config.Deserialize(m_fileName);
276 |
277 | if (config.options == null)
278 | {
279 | DebugUtils.Log("Configuration empty. Default values will be used.");
280 | }
281 | else
282 | {
283 | // Remove unneeded options
284 | List optionsList = new List();
285 |
286 | for (uint i = 0; i < config.options.Length; i++)
287 | {
288 | if (config.options[i] != null && config.options[i].prefab != null) optionsList.Add(config.options[i]);
289 | }
290 |
291 | config.options = optionsList.ToArray();
292 | }
293 |
294 | // Checking for new vehicles
295 | CompileVehiclesList();
296 |
297 | // Checking for conflicts
298 | DefaultOptions.CheckForConflicts();
299 |
300 | // Update existing vehicles
301 | new EnumerableActionThread(VehicleOptions.UpdateCapacityUnits);
302 | new EnumerableActionThread(VehicleOptions.UpdateBackEngines);
303 |
304 | DebugUtils.Log("Configuration imported");
305 | LogVehicleListSteamID();
306 | }
307 |
308 | ///
309 | /// Export the configuration file
310 | ///
311 | public static void ExportConfig()
312 | {
313 | config.Serialize(m_fileName);
314 | }
315 |
316 | public static void CheckAllServicesValidity()
317 | {
318 | string warning = "";
319 |
320 | for (int i = 0; i < (int)VehicleOptions.Category.Natural; i++)
321 | if (!CheckServiceValidity((VehicleOptions.Category)i)) warning += "- " + GUI.UIMainPanel.categoryList[i + 1] + "\n";
322 |
323 | if(warning != "")
324 | {
325 | GUI.UIWarningModal.instance.message = "The following services may not work correctly because no vehicles are allowed to spawn :\n\n" + warning;
326 | UIView.PushModal(GUI.UIWarningModal.instance);
327 | GUI.UIWarningModal.instance.Show(true);
328 | }
329 |
330 | }
331 |
332 | public static bool CheckServiceValidity(VehicleOptions.Category service)
333 | {
334 | if (config == null || config.options == null) return true;
335 |
336 | int count = 0;
337 |
338 | for (int i = 0; i < config.options.Length; i++)
339 | {
340 | if (config.options[i].category == service)
341 | {
342 | if(config.options[i].enabled) return true;
343 | count++;
344 | }
345 | }
346 |
347 | return count == 0;
348 | }
349 |
350 | public static void ClearVehicles(VehicleOptions options, bool parked)
351 | {
352 | if (parked)
353 | {
354 | if(options == null)
355 | {
356 | new EnumerableActionThread(ActionRemoveParkedAll);
357 | return;
358 | }
359 |
360 | m_removeParkedInfo = options.prefab;
361 | new EnumerableActionThread(ActionRemoveParked);
362 | }
363 | else
364 | {
365 | if (options == null)
366 | {
367 | new EnumerableActionThread(ActionRemoveExistingAll);
368 | return;
369 | }
370 |
371 | m_removeInfo = options.prefab;
372 | new EnumerableActionThread(ActionRemoveExisting);
373 | }
374 | }
375 |
376 | public static IEnumerator ActionRemoveExisting(ThreadBase t)
377 | {
378 | VehicleInfo info = m_removeInfo;
379 |
380 | for (ushort i = 0; i < VehicleManager.instance.m_vehicles.m_size; i++)
381 | {
382 | if (VehicleManager.instance.m_vehicles.m_buffer[i].Info != null)
383 | {
384 | if (info == VehicleManager.instance.m_vehicles.m_buffer[i].Info)
385 | VehicleManager.instance.ReleaseVehicle(i);
386 | }
387 |
388 | if (i % 256 == 255) yield return i;
389 | }
390 | }
391 |
392 | public static IEnumerator ActionRemoveParked(ThreadBase t)
393 | {
394 | VehicleInfo info = m_removeParkedInfo;
395 |
396 | for (ushort i = 0; i < VehicleManager.instance.m_parkedVehicles.m_size; i++)
397 | {
398 | if (VehicleManager.instance.m_parkedVehicles.m_buffer[i].Info != null)
399 | {
400 | if (info == VehicleManager.instance.m_parkedVehicles.m_buffer[i].Info)
401 | VehicleManager.instance.ReleaseParkedVehicle(i);
402 | }
403 |
404 | if (i % 256 == 255) yield return i;
405 | }
406 | }
407 |
408 | public static IEnumerator ActionRemoveExistingAll(ThreadBase t)
409 | {
410 | for (ushort i = 0; i < VehicleManager.instance.m_vehicles.m_size; i++)
411 | {
412 | VehicleManager.instance.ReleaseVehicle(i);
413 | if (i % 256 == 255) yield return i;
414 | }
415 | }
416 |
417 | public static IEnumerator ActionRemoveParkedAll(ThreadBase t)
418 | {
419 | for (ushort i = 0; i < VehicleManager.instance.m_parkedVehicles.m_size; i++)
420 | {
421 | VehicleManager.instance.ReleaseParkedVehicle(i);
422 | if (i % 256 == 255) yield return i;
423 | }
424 | }
425 |
426 | private static int ParseVersion(string version)
427 | {
428 | if (version.IsNullOrWhiteSpace()) return 0;
429 |
430 | int v = 0;
431 | string[] t = version.Split('.');
432 |
433 | for (int i = 0; i < t.Length; i++)
434 | {
435 | v *= 100;
436 | if (int.TryParse(t[i], out int a))
437 | v += a;
438 | }
439 |
440 | return v;
441 | }
442 |
443 | ///
444 | /// Check if there are new vehicles and add them to the options list
445 | ///
446 | private static void CompileVehiclesList()
447 | {
448 | List optionsList = new List();
449 | if (config.options != null) optionsList.AddRange(config.options);
450 |
451 | for (uint i = 0; i < PrefabCollection.PrefabCount(); i++)
452 | {
453 | VehicleInfo prefab = PrefabCollection.GetPrefab(i);
454 |
455 | if (prefab == null || ContainsPrefab(prefab)) continue;
456 |
457 | // New vehicle
458 | VehicleOptions options = new VehicleOptions();
459 | options.SetPrefab(prefab);
460 |
461 | optionsList.Add(options);
462 | }
463 |
464 | if (config.options != null)
465 | DebugUtils.Log("Found " + (optionsList.Count - config.options.Length) + " new vehicle(s)");
466 | else
467 | DebugUtils.Log("Found " + optionsList.Count + " new vehicle(s)");
468 |
469 | config.options = optionsList.ToArray();
470 |
471 | }
472 |
473 | private static bool ContainsPrefab(VehicleInfo prefab)
474 | {
475 | if (config.options == null) return false;
476 | for (int i = 0; i < config.options.Length; i++)
477 | {
478 | if (config.options[i].prefab == prefab) return true;
479 | }
480 | return false;
481 | }
482 |
483 | private static void LogVehicleListSteamID()
484 | {
485 | StringBuilder steamIDs = new StringBuilder("Vehicle Steam IDs : ");
486 |
487 | for (int i = 0; i < config.options.Length; i++)
488 | {
489 | if (config.options[i] != null && config.options[i].name.Contains("."))
490 | {
491 | steamIDs.Append(config.options[i].name.Substring(0, config.options[i].name.IndexOf(".")));
492 | steamIDs.Append(",");
493 | }
494 | }
495 | steamIDs.Length--;
496 |
497 | DebugUtils.Log(steamIDs.ToString());
498 | }
499 |
500 | private static bool IsAICustom(VehicleAI ai)
501 | {
502 | Type type = ai.GetType();
503 | return (type != typeof(AmbulanceAI) ||
504 | type != typeof(BusAI) ||
505 | type != typeof(CargoTruckAI) ||
506 | type != typeof(FireTruckAI) ||
507 | type != typeof(GarbageTruckAI) ||
508 | type != typeof(HearseAI) ||
509 | type != typeof(PassengerCarAI) ||
510 | type != typeof(PoliceCarAI));
511 | }
512 | }
513 | }
514 |
--------------------------------------------------------------------------------
/AdvancedVehicleOptions/AdvancedVehicleOptions.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {C323E306-D11E-48A7-9620-121E4ADC4765}
8 | Library
9 | Properties
10 | AdvancedVehicleOptions
11 | AdvancedVehicleOptions
12 | v3.5
13 | 512
14 |
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | none
27 | true
28 | bin\Release\
29 |
30 |
31 | prompt
32 | 4
33 | true
34 |
35 |
36 |
37 | ..\..\..\ProgramFiles\Steam\SteamApps\common\Cities_Skylines\Cities_Data\Managed\Assembly-CSharp.dll
38 |
39 |
40 | ..\..\..\ProgramFiles\Steam\SteamApps\common\Cities_Skylines\Cities_Data\Managed\ColossalManaged.dll
41 |
42 |
43 | ..\..\..\ProgramFiles\Steam\SteamApps\common\Cities_Skylines\Cities_Data\Managed\ICities.dll
44 |
45 |
46 |
47 |
48 | ..\..\..\ProgramFiles\Steam\SteamApps\common\Cities_Skylines\Cities_Data\Managed\UnityEngine.dll
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 | mkdir "%25LOCALAPPDATA%25\Colossal Order\Cities_Skylines\Addons\Mods\$(SolutionName)"
71 | del "%25LOCALAPPDATA%25\Colossal Order\Cities_Skylines\Addons\Mods\$(SolutionName)\$(TargetFileName)"
72 | xcopy /y "$(TargetPath)" "%25LOCALAPPDATA%25\Colossal Order\Cities_Skylines\Addons\Mods\$(SolutionName)"
73 |
74 |
81 |
--------------------------------------------------------------------------------
/AdvancedVehicleOptions/AdvancedVehicleOptions.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.31101.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdvancedVehicleOptions", "AdvancedVehicleOptions.csproj", "{C323E306-D11E-48A7-9620-121E4ADC4765}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {C323E306-D11E-48A7-9620-121E4ADC4765}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {C323E306-D11E-48A7-9620-121E4ADC4765}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {C323E306-D11E-48A7-9620-121E4ADC4765}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {C323E306-D11E-48A7-9620-121E4ADC4765}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/AdvancedVehicleOptions/Configuration.cs:
--------------------------------------------------------------------------------
1 | using ColossalFramework.IO;
2 |
3 | using System;
4 | using System.IO;
5 | using System.Xml;
6 | using System.Xml.Serialization;
7 | using System.ComponentModel;
8 | using System.Collections.Generic;
9 |
10 | namespace AdvancedVehicleOptions
11 | {
12 | [XmlType("ArrayOfVehicleOptions")]
13 | [Serializable]
14 | public class Configuration : IDataContainer
15 | {
16 | public class VehicleData
17 | {
18 | #region serialized
19 | [XmlAttribute("name")]
20 | public string name;
21 | [DefaultValue(true)]
22 | public bool enabled = true;
23 | [DefaultValue(false)]
24 | public bool addBackEngine = false;
25 | public float maxSpeed;
26 | public float acceleration;
27 | public float braking;
28 | [DefaultValue(true)]
29 | public bool useColorVariations = true;
30 | public HexaColor color0;
31 | public HexaColor color1;
32 | public HexaColor color2;
33 | public HexaColor color3;
34 | [DefaultValue(-1)]
35 | public int capacity = -1;
36 | #endregion
37 |
38 | public bool isCustomAsset
39 | {
40 | get
41 | {
42 | return name.Contains(".");
43 | }
44 | }
45 | }
46 |
47 | [XmlElement("VehicleOptions")]
48 | public VehicleData[] data;
49 |
50 | [XmlIgnore]
51 | public VehicleOptions[] options;
52 |
53 | private List m_defaultVehicles = new List();
54 |
55 | // Serialize to save
56 | public void Serialize(DataSerializer s)
57 | {
58 | try
59 | {
60 | int count = options.Length;
61 | s.WriteInt32(count);
62 |
63 | for (int i = 0; i < count; i++)
64 | {
65 | s.WriteUniqueString(options[i].name);
66 | s.WriteBool(options[i].enabled);
67 | s.WriteBool(options[i].addBackEngine);
68 | s.WriteFloat(options[i].maxSpeed);
69 | s.WriteFloat(options[i].acceleration);
70 | s.WriteFloat(options[i].braking);
71 | s.WriteBool(options[i].useColorVariations);
72 | s.WriteUniqueString(options[i].color0.Value);
73 | s.WriteUniqueString(options[i].color1.Value);
74 | s.WriteUniqueString(options[i].color2.Value);
75 | s.WriteUniqueString(options[i].color3.Value);
76 | s.WriteInt32(options[i].capacity);
77 | }
78 | }
79 | catch (Exception e)
80 | {
81 | DebugUtils.LogException(e);
82 | }
83 | }
84 |
85 | public void Deserialize(DataSerializer s)
86 | {
87 | try
88 | {
89 | options = null;
90 | data = null;
91 |
92 | int count = s.ReadInt32();
93 | data = new VehicleData[count];
94 |
95 | for (int i = 0; i < count; i++)
96 | {
97 | data[i] = new VehicleData();
98 | data[i].name = s.ReadUniqueString();
99 | data[i].enabled = s.ReadBool();
100 | data[i].addBackEngine = s.ReadBool();
101 | data[i].maxSpeed = s.ReadFloat();
102 | data[i].acceleration = s.ReadFloat();
103 | data[i].braking = s.ReadFloat();
104 | data[i].useColorVariations = s.ReadBool();
105 | data[i].color0 = new HexaColor(s.ReadUniqueString());
106 | data[i].color1 = new HexaColor(s.ReadUniqueString());
107 | data[i].color2 = new HexaColor(s.ReadUniqueString());
108 | data[i].color3 = new HexaColor(s.ReadUniqueString());
109 | data[i].capacity = s.ReadInt32();
110 | }
111 | }
112 | catch (Exception e)
113 | {
114 | // Couldn't Deserialize
115 | DebugUtils.Warning("Couldn't deserialize");
116 | DebugUtils.LogException(e);
117 | }
118 | }
119 |
120 | public void AfterDeserialize(DataSerializer s)
121 | {
122 | }
123 |
124 | // Serialize to file
125 | public void Serialize(string filename)
126 | {
127 | try
128 | {
129 | if (AdvancedVehicleOptions.isGameLoaded) OptionsToData();
130 |
131 | // Add back default vehicle options that might not exist on the map
132 | // I.E. Snowplow on non-snowy maps
133 | if (m_defaultVehicles.Count > 0)
134 | {
135 | List new_data = new List(data);
136 |
137 | for (int i = 0; i < m_defaultVehicles.Count; i++)
138 | {
139 | bool found = false;
140 | for (int j = 0; j < data.Length; j++)
141 | {
142 | if (m_defaultVehicles[i].name == data[j].name)
143 | {
144 | found = true;
145 | break;
146 | }
147 | }
148 | if (!found)
149 | {
150 | new_data.Add(m_defaultVehicles[i]);
151 | }
152 | }
153 |
154 | data = new_data.ToArray();
155 | }
156 |
157 | using (FileStream stream = new FileStream(filename, FileMode.OpenOrCreate))
158 | {
159 | stream.SetLength(0); // Emptying the file !!!
160 | XmlSerializer xmlSerializer = new XmlSerializer(typeof(Configuration));
161 | xmlSerializer.Serialize(stream, this);
162 | DebugUtils.Log("Configuration saved");
163 | }
164 | }
165 | catch (Exception e)
166 | {
167 | DebugUtils.Warning("Couldn't save configuration at \"" + Directory.GetCurrentDirectory() + "\"");
168 | DebugUtils.LogException(e);
169 | }
170 | }
171 |
172 | public void Deserialize(string filename)
173 | {
174 | XmlSerializer xmlSerializer = new XmlSerializer(typeof(Configuration));
175 | Configuration config = null;
176 |
177 | options = null;
178 | data = null;
179 |
180 | try
181 | {
182 | // Trying to Deserialize the configuration file
183 | using (FileStream stream = new FileStream(filename, FileMode.Open))
184 | {
185 | config = xmlSerializer.Deserialize(stream) as Configuration;
186 | }
187 | }
188 | catch (Exception e)
189 | {
190 | // Couldn't Deserialize (XML malformed?)
191 | DebugUtils.Warning("Couldn't load configuration (XML malformed?)");
192 | DebugUtils.LogException(e);
193 |
194 | config = null;
195 | }
196 |
197 | if(config != null)
198 | {
199 | data = config.data;
200 |
201 | if(data != null)
202 | {
203 | // Saves all default vehicle options that might not exist on the map
204 | // I.E. Snowplow on non-snowy maps
205 | m_defaultVehicles.Clear();
206 | for (int i = 0; i < data.Length; i++)
207 | {
208 | if (data[i] != null && !data[i].isCustomAsset)
209 | m_defaultVehicles.Add(data[i]);
210 | }
211 | }
212 |
213 |
214 | if (AdvancedVehicleOptions.isGameLoaded) DataToOptions();
215 | }
216 | }
217 |
218 | public void OptionsToData()
219 | {
220 | if (options == null) return;
221 |
222 | data = new VehicleData[options.Length];
223 |
224 | for (int i = 0; i < options.Length; i++)
225 | {
226 | data[i] = new VehicleData();
227 | data[i].name = options[i].name;
228 | data[i].enabled = options[i].enabled;
229 | data[i].addBackEngine = options[i].addBackEngine;
230 | data[i].maxSpeed = options[i].maxSpeed;
231 | data[i].acceleration = options[i].acceleration;
232 | data[i].braking = options[i].braking;
233 | data[i].useColorVariations = options[i].useColorVariations;
234 | data[i].color0 = options[i].color0;
235 | data[i].color1 = options[i].color1;
236 | data[i].color2 = options[i].color2;
237 | data[i].color3 = options[i].color3;
238 | data[i].capacity = options[i].capacity;
239 | }
240 | }
241 |
242 | public void DataToOptions()
243 | {
244 | if (data == null) return;
245 |
246 | options = new VehicleOptions[data.Length];
247 |
248 | for (int i = 0; i < data.Length; i++)
249 | {
250 | if (data[i].name == null) continue;
251 |
252 | options[i] = new VehicleOptions();
253 | options[i].name = data[i].name;
254 | options[i].enabled = data[i].enabled;
255 | options[i].addBackEngine = data[i].addBackEngine;
256 | options[i].maxSpeed = data[i].maxSpeed;
257 | options[i].acceleration = data[i].acceleration;
258 | options[i].braking = data[i].braking;
259 | options[i].useColorVariations = data[i].useColorVariations;
260 | options[i].color0 = data[i].color0;
261 | options[i].color1 = data[i].color1;
262 | options[i].color2 = data[i].color2;
263 | options[i].color3 = data[i].color3;
264 | options[i].capacity = data[i].capacity;
265 | }
266 |
267 | VehicleOptions.UpdateTransfertVehicles();
268 | }
269 | }
270 | }
271 |
--------------------------------------------------------------------------------
/AdvancedVehicleOptions/DebugUtils.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using ColossalFramework;
3 |
4 | using System;
5 |
6 | namespace AdvancedVehicleOptions
7 | {
8 | public class DebugUtils
9 | {
10 | public const string modPrefix = "[Advanced Vehicle Options "+ModInfo.version+"] ";
11 |
12 | public static SavedBool hideDebugMessages = new SavedBool("hideDebugMessages", AdvancedVehicleOptions.settingsFileName, true, true);
13 |
14 | public static void Log(string message)
15 | {
16 | if (hideDebugMessages.value) return;
17 |
18 | if (message == m_lastLog)
19 | {
20 | m_duplicates++;
21 | }
22 | else if (m_duplicates > 0)
23 | {
24 | Debug.Log(modPrefix + m_lastLog + "(x" + (m_duplicates + 1) + ")");
25 | Debug.Log(modPrefix + message);
26 | m_duplicates = 0;
27 | }
28 | else
29 | {
30 | Debug.Log(modPrefix + message);
31 | }
32 | m_lastLog = message;
33 | }
34 |
35 | public static void Warning(string message)
36 | {
37 | if (message != m_lastWarning)
38 | {
39 | Debug.LogWarning(modPrefix + "Warning: " + message);
40 | }
41 | m_lastWarning = message;
42 | }
43 |
44 | public static void LogException(Exception e)
45 | {
46 | Debug.LogError(modPrefix + "Intercepted exception (not game breaking):");
47 | Debug.LogException(e);
48 | }
49 |
50 | private static string m_lastWarning;
51 | private static string m_lastLog;
52 | private static int m_duplicates = 0;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/AdvancedVehicleOptions/GUI/UIFastList.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using ColossalFramework.UI;
3 |
4 | using System;
5 |
6 | namespace AdvancedVehicleOptions.GUI
7 | {
8 | public interface IUIFastListRow
9 | {
10 | #region Methods to implement
11 | ///
12 | /// Method invoked very often, make sure it is fast
13 | /// Avoid doing any calculations, the data should be already processed any ready to display.
14 | ///
15 | /// What needs to be displayed
16 | /// Use this to display a different look for your odd rows
17 | void Display(object data, bool isRowOdd);
18 |
19 | ///
20 | /// Change the style of the selected row here
21 | ///
22 | /// Use this to display a different look for your odd rows
23 | void Select(bool isRowOdd);
24 | ///
25 | /// Change the style of the row back from selected here
26 | ///
27 | /// Use this to display a different look for your odd rows
28 | void Deselect(bool isRowOdd);
29 | #endregion
30 |
31 | #region From UIPanel
32 | // No need to implement those, they are in UIPanel
33 | // Those are declared here so they can be used inside UIFastList
34 | float width { get; set; }
35 | bool enabled { get; set; }
36 | Vector3 relativePosition { get; set; }
37 | event MouseEventHandler eventClick;
38 | event MouseEventHandler eventMouseEnter;
39 | #endregion
40 | }
41 |
42 | ///
43 | /// This component is specifically designed the handle the display of
44 | /// very large amount of rows in a scrollable panel while minimizing
45 | /// the impact on the performances.
46 | ///
47 | /// This class will instantiate the rows for you based on the actual
48 | /// height of the UIFastList and the rowHeight value provided.
49 | ///
50 | /// The row class must inherit UIPanel and implement IUIFastListRow :
51 | /// public class MyCustomRow : UIPanel, IUIFastListRow
52 | ///
53 | /// How it works :
54 | /// This class only instantiate as many rows as visible on screen (+1
55 | /// extra to simulate in-between steps). Then the content of those is
56 | /// updated according to what needs to be displayed by calling the
57 | /// Display method declared in IUIFastListRow.
58 | ///
59 | /// Provide the list of data with rowData. This data is send back to
60 | /// your custom row when it needs to be displayed. For optimal
61 | /// performances, make sure this data is already processed and ready
62 | /// to display.
63 | ///
64 | /// Creation example :
65 | /// UIFastList myFastList = UIFastList.Create(this);
66 | /// myFastList.size = new Vector2(200f, 300f);
67 | /// myFastList.rowHeight = 40f;
68 | /// myFastList.rowData = myDataList;
69 | ///
70 | ///
71 | public class UIFastList : UIComponent
72 | {
73 | #region Private members
74 | private UIPanel m_panel;
75 | private UIScrollbar m_scrollbar;
76 | private FastList m_rows;
77 | private FastList