forked from Th3ClosetG33k/OGame-Planet-Builder-V2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.cs
166 lines (154 loc) · 5.24 KB
/
GUI.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
namespace OGPB
{
public class GUI
{
private delegate void callback();
private delegate void callbackSingle(Object param1);
private delegate void callbackDouble(Object param1, Object param2);
public Form formMain;
public TextBox txtUsername;
public TextBox txtPassword;
public Button btnLogin;
public Button btnBotStatus;
public TextBox txtLog;
public ToolStripStatusLabel lblStatus;
public TabControl tabMaster;
public ListBox lstToBuild;
public ListBox lstToBuildTrue;
public Translate translate;
public void FocusUsername()
{
if (formMain.InvokeRequired)
{
callback inv = new callback(this.FocusUsername);
formMain.Invoke(inv, new object[] { });
}
else
{
txtUsername.Focus();
}
}
public void FocusPassword()
{
if (formMain.InvokeRequired)
{
callback inv = new callback(this.FocusPassword);
formMain.Invoke(inv, new object[] { });
}
else
{
txtPassword.Focus();
}
}
public void EnableDisableLogin(Object enabled)
{
if (formMain.InvokeRequired)
{
callbackSingle inv = new callbackSingle(this.EnableDisableLogin);
formMain.Invoke(inv, new object[] { enabled });
}
else
{
txtUsername.Enabled = (bool)enabled;
txtPassword.Enabled = (bool)enabled;
btnLogin.Enabled = (bool)enabled;
}
}
public void EnableDisableBotStatus(Object enabled)
{
if (formMain.InvokeRequired)
{
callbackSingle inv = new callbackSingle(this.EnableDisableBotStatus);
formMain.Invoke(inv, new object[] { enabled });
}
else
{
btnBotStatus.Enabled = (bool)enabled;
}
}
public void ChangeStatus(Object newStatus)
{
if (formMain.InvokeRequired)
{
callbackSingle inv = new callbackSingle(this.ChangeStatus);
formMain.Invoke(inv, new object[] { newStatus });
}
else
{
lblStatus.Text = (string)newStatus;
AddToLog("Status Changed: " + newStatus);
}
}
public void AddToLog(Object toAdd)
{
if (formMain.InvokeRequired)
{
callbackSingle inv = new callbackSingle(this.AddToLog);
formMain.Invoke(inv, new object[] { toAdd });
}
else
{
txtLog.Text += (string)toAdd + "\r\n";
}
}
public void AddPlanetTab(object planetID, object planetName)
{
if (formMain.InvokeRequired)
{
callbackDouble inv = new callbackDouble(this.AddPlanetTab);
formMain.Invoke(inv, new object[] { planetID, planetName });
}
else
{
tabMaster.TabPages.Add("tab" + planetID.ToString(), (string)planetName);
}
}
public void GoToHomePlanet()
{
if (formMain.InvokeRequired)
{
callback inv = new callback(this.GoToHomePlanet);
formMain.Invoke(inv, new object[] { });
}
else
{
tabMaster.SelectedIndex = 2;
}
}
public void UpdateBuildList(object basePlanetInfo)
{
Planet currentPlanet = (Planet)((Planet)basePlanetInfo).Clone();
if (formMain.InvokeRequired)
{
callbackSingle inv = new callbackSingle(this.UpdateBuildList);
formMain.Invoke(inv, new object[] { basePlanetInfo });
}
else
{
string toTranslate;
Type type = Type.GetType("OGPB.Planet");
FieldInfo field;
lstToBuild.Items.Clear();
for (int i = 0; i < currentPlanet.buildList.Length; i++)
{
toTranslate = currentPlanet.buildList[i].ToString();
if (toTranslate.Contains("#") == true)
{
lstToBuild.Items.Insert(i, toTranslate.Substring(toTranslate.IndexOf("#") + 1) + " " + translate.GetString(toTranslate.Substring(0, toTranslate.IndexOf("#"))));
}
else
{
field = type.GetField(toTranslate.Substring(0, 1).ToLower() + toTranslate.Substring(1));
field.SetValue(currentPlanet, (Convert.ToInt32(field.GetValue(currentPlanet)) + 1));
lstToBuild.Items.Insert(i, translate.GetString(toTranslate) + " " + field.GetValue(currentPlanet));
}
}
}
}
}
}