forked from pcfantasy/RealConstruction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RealConstruction.cs
135 lines (120 loc) · 4.31 KB
/
RealConstruction.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
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
using ColossalFramework;
using ColossalFramework.Globalization;
using ColossalFramework.Plugins;
using ColossalFramework.UI;
using ICities;
using RealConstruction.Util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
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 = 0;
public string Name
{
get { return "Real Construction"; }
}
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();
}
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 == "2")
{
operationConsumption = 2;
}
else if (strLine == "1")
{
operationConsumption = 1;
}
else
{
operationConsumption = 0;
}
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]);
}
}
}