forked from pcfantasy/RealConstruction
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRealConstruction.cs
More file actions
146 lines (128 loc) · 4.68 KB
/
RealConstruction.cs
File metadata and controls
146 lines (128 loc) · 4.68 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
using CitiesHarmony.API;
using ICities;
using RealConstruction.Util;
using System;
using System.IO;
using System.Reflection;
namespace RealConstruction
{
public class RealConstruction : IUserMod
{
public static bool IsEnabled = false;
public static bool debugMode = false;
public static bool fixUnRouteTransfer = false;
public static int operationConsumption = 2;
#if DEBUG
private static string config => " [DEBUG]";
#else
private static string config => "";
#endif
public static string ModName => $"Real Construction{config}";
public string Name
{
get {
// Get the currently executing assembly (.exe assembly)
var assembly = Assembly.GetExecutingAssembly();
var name = assembly.GetName();
// Retrieve and display the version
var version = $" {name.Version}";
return ModName + version;
}
}
public string Description
{
get { return "Private building construction will start only after getting enough resource."; }
}
public void OnEnabled()
{
IsEnabled = true;
FileStream fs = File.Create("RealConstruction.txt");
fs.Close();
HarmonyHelper.EnsureHarmonyInstalled();
}
public void OnDisabled()
{
IsEnabled = false;
}
public static void SaveSetting()
{
//save langugae
FileStream fs = File.Create("RealConstruction_setting.txt");
StreamWriter streamWriter = new StreamWriter(fs);
streamWriter.WriteLine(debugMode);
streamWriter.WriteLine(fixUnRouteTransfer);
streamWriter.WriteLine(operationConsumption);
streamWriter.Flush();
fs.Close();
}
public static void LoadSetting()
{
if (File.Exists("RealConstruction_setting.txt"))
{
FileStream fs = new FileStream("RealConstruction_setting.txt", FileMode.Open);
StreamReader sr = new StreamReader(fs);
string strLine = sr.ReadLine();
if (strLine == "True")
{
debugMode = true;
}
else
{
debugMode = false;
}
strLine = sr.ReadLine();
if (strLine == "True")
{
fixUnRouteTransfer = true;
}
else
{
fixUnRouteTransfer = false;
}
strLine = sr.ReadLine();
if (strLine == "0")
{
operationConsumption = 0;
}
else if (strLine == "1")
{
operationConsumption = 1;
}
else
{
operationConsumption = 2;
}
sr.Close();
fs.Close();
}
}
public void OnSettingsUI(UIHelperBase helper)
{
LoadSetting();
UIHelperBase group = helper.AddGroup(Localization.Get("DEBUG_MODE"));
group.AddCheckbox(Localization.Get("SHOW_LACK_OF_RESOURCE"), debugMode, (index) => debugModeEnable(index));
UIHelperBase group1 = helper.AddGroup(Localization.Get("FIX_UNROUTED_TRANSFER_MATCH_DESCRIPTION"));
group1.AddCheckbox(Localization.Get("FIX_UNROUTED_TRANSFER_MATCH_ENALBE"), fixUnRouteTransfer, (index) => fixUnRouteTransferEnable(index));
UIHelperBase group2 = helper.AddGroup(Localization.Get("OPERATION_RESOURCE_CONSUMPTION"));
group2.AddDropdown(Localization.Get("OPERATION_RESOURCE_CONSUMPTION"), new string[] { Localization.Get("NORMAL"), Localization.Get("HALF"), Localization.Get("NONE") }, operationConsumption, (index) => GetOperationConsumption(index));
SaveSetting();
}
public void debugModeEnable(bool index)
{
debugMode = index;
SaveSetting();
}
public void fixUnRouteTransferEnable(bool index)
{
fixUnRouteTransfer = index;
SaveSetting();
}
public void GetOperationConsumption(int index)
{
operationConsumption = index;
SaveSetting();
//MethodInfo method = typeof(OptionsMainPanel).GetMethod("OnLocaleChanged", BindingFlags.Instance | BindingFlags.NonPublic);
//method.Invoke(UIView.library.Get<OptionsMainPanel>("OptionsPanel"), new object[0]);
}
}
}