This repository has been archived by the owner on May 11, 2019. It is now read-only.
forked from akira-ishizaki/CS-EnhancedHearseAI
/
Identity.cs
82 lines (75 loc) · 2.91 KB
/
Identity.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
using ColossalFramework;
using ICities;
using System.IO;
namespace EnhancedHearseAI
{
public class Identity : IUserMod
{
public string Name
{
get { return Settings.Instance.Tag; }
}
public string Description
{
get { return "Oversees death services to ensure that vehicles are dispatched in an efficient manner."; }
}
public const string SETTINGFILENAME = "EnhancedHearseAI.xml";
public static string configPath;
public static ModConfiguration ModConf;
public void OnSettingsUI(UIHelperBase helper)
{
this.InitConfigFile();
UIHelperBase group = helper.AddGroup(Translation.GetString("Settings"));
group.AddCheckbox(Translation.GetString("PrioritizeTargetsWithRedSigns"), ModConf.PrioritizeTargetWithRedSigns, delegate (bool isChecked)
{
Identity.ModConf.PrioritizeTargetWithRedSigns = isChecked;
ModConfiguration.Serialize(Identity.configPath, Identity.ModConf);
});
group.AddCheckbox(Translation.GetString("MinimizeHearses"), ModConf.MinimizeHearses, delegate (bool isChecked)
{
Identity.ModConf.MinimizeHearses = isChecked;
ModConfiguration.Serialize(Identity.configPath, Identity.ModConf);
});
}
private void InitConfigFile()
{
try
{
string pathName = GameSettings.FindSettingsFileByName("gameSettings").pathName;
string str = "";
if (pathName != "")
{
str = Path.GetDirectoryName(pathName) + Path.DirectorySeparatorChar;
}
Identity.configPath = str + SETTINGFILENAME;
Identity.ModConf = ModConfiguration.Deserialize(Identity.configPath);
if (Identity.ModConf == null)
{
Identity.ModConf = ModConfiguration.Deserialize(SETTINGFILENAME);
if (Identity.ModConf != null && ModConfiguration.Serialize(str + SETTINGFILENAME, Identity.ModConf))
{
try
{
File.Delete(SETTINGFILENAME);
}
catch
{
}
}
}
if (Identity.ModConf == null)
{
Identity.ModConf = new ModConfiguration();
if (!ModConfiguration.Serialize(Identity.configPath, Identity.ModConf))
{
Identity.configPath = SETTINGFILENAME;
ModConfiguration.Serialize(Identity.configPath, Identity.ModConf);
}
}
}
catch
{
}
}
}
}