forked from jadaradix/dsgamemaker
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGlobalVariables.cs
More file actions
284 lines (267 loc) · 10.5 KB
/
GlobalVariables.cs
File metadata and controls
284 lines (267 loc) · 10.5 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
using System.Drawing.Drawing2D;
namespace DS_Game_Maker
{
public partial class GlobalVariables
{
private List<string> Variables = new List<string>();
private List<string> MyVariableTypes = new List<string>();
private List<string> VariableValues = new List<string>();
private string CurrentName = string.Empty;
private bool AllowClose = true;
public GlobalVariables()
{
InitializeComponent();
}
private void Globals_Load(object sender, EventArgs e)
{
SetEnablity(false);
TypeList.Items.Clear();
foreach (string X in ScriptsLib.VariableTypes)
TypeList.Items.Add(X);
foreach (string P in DSGMlib.GetXDSFilter("STRUCT "))
TypeList.Items.Add(P.Substring(7));
Variables.Clear();
MyVariableTypes.Clear();
VariableValues.Clear();
foreach (string X_ in DSGMlib.GetXDSFilter("GLOBAL "))
{
string X = X_;
X = X.Substring(7);
Variables.Add(DSGMlib.iGet(X, (byte)0, ","));
MyVariableTypes.Add(DSGMlib.iGet(X, (byte)1, ","));
VariableValues.Add(DSGMlib.iGet(X, (byte)2, ","));
}
VariablesList.Items.Clear();
if (Variables.Count > 0)
{
for (short i = 0, loopTo = (short)(Variables.Count - 1); i <= loopTo; i++)
VariablesList.Items.Add(Variables[i]);
}
NameTextBox.BackColor = Color.FromArgb(64, 64, 64);
ValueTextBox.Text = string.Empty;
if (VariablesList.Items.Count > 0)
VariablesList.SelectedIndex = 0;
AllowClose = true;
}
private void RemoveButton_Click(object sender, EventArgs e)
{
if (CurrentName.Length == 0)
return;
short DOn = 0;
for (short i = 0, loopTo = (short)(VariablesList.Items.Count - 1); i <= loopTo; i++)
{
if (Equals(VariablesList.Items[i], CurrentName))
{
DOn = i;
break;
}
}
// For Each X As String In VariablesList.Items
// If X = CurrentName Then Exit For
// DOn += 1
// Next
VariablesList.Items.RemoveAt(DOn);
Variables.RemoveAt(DOn);
MyVariableTypes.RemoveAt(DOn);
VariableValues.RemoveAt(DOn);
NameTextBox.Text = string.Empty;
ValueTextBox.Text = string.Empty;
string Message = "You have just deleted '" + CurrentName + "'." + Constants.vbCrLf + Constants.vbCrLf;
if (VariablesList.Items.Count > 0)
{
VariablesList.SelectedIndex = 0;
}
else
{
SetEnablity(false);
}
Message += "Be sure to update any logic that uses this Variable.";
DSGMlib.MsgInfo(Message);
CurrentName = string.Empty;
}
private void AddButton_Click(object sender, EventArgs e)
{
short ToUse = 1;
for (int i = 1; i <= 100; i++)
{
if (!Variables.Contains("Variable_" + i.ToString()))
{
ToUse = (short)i;
break;
}
}
Variables.Add("Variable_" + ToUse.ToString());
MyVariableTypes.Add("Integer");
VariableValues.Add("0");
VariablesList.Items.Add("Variable_" + ToUse.ToString());
VariablesList.SelectedIndex = VariablesList.Items.Count - 1;
}
private void VariablesList_SelectedIndexChanged(object sender, EventArgs e)
{
if (Variables.Count == 0)
return;
short Position = (short)VariablesList.SelectedIndex;
try
{
string X = MyVariableTypes[Position];
}
catch
{
return;
}
TypeList.Text = MyVariableTypes[Position];
ValueTextBox.Text = VariableValues[Position];
CurrentName = Variables[Position];
NameTextBox.Text = CurrentName;
SetEnablity(true);
NameTextBox.Focus();
NameTextBox.SelectionStart = NameTextBox.Text.Length;
NameTextBox.SelectionLength = 0;
}
private void TypeList_SelectedIndexChanged(object sender, EventArgs e)
{
if (Variables.Count == 0)
return;
string Returnable = "<No description>";
TypeTitleLabel.Text = TypeList.Text;
switch (TypeList.Text ?? "")
{
case "Integer":
{
Returnable = "An integer is a numerical value that does not have a decimal point.";
break;
}
case "Boolean":
{
Returnable = "A boolean holds one of two values: true or false.";
break;
}
case "Signed Byte":
{
Returnable = "A numerical value ranging from -127 to 127.";
break;
}
case "Unsigned Byte":
{
Returnable = "A numerical value ranging from 0 to 255.";
break;
}
case "Float":
{
Returnable = "A float is a numerical value which may possess a decimal point.";
break;
}
case "String":
{
Returnable = "A word or phrase; a linear sequence of symbols (characters).";
break;
}
}
TypeDescriptionLabel.Text = Returnable;
MyVariableTypes[VariablesList.SelectedIndex] = TypeList.Text;
}
public void SetEnablity(bool Enabled)
{
TypeList.Enabled = Enabled;
ValueTextBox.Enabled = Enabled;
NameTextBox.Enabled = Enabled;
TypeTitleLabel.Enabled = Enabled;
TypeDescriptionLabel.Enabled = Enabled;
}
private void NameTextBox_TextChanged(object sender, EventArgs e)
{
if (Variables.Count == 0)
return;
if (DSGMlib.ValidateSomething(NameTextBox.Text, (byte)DSGMlib.ValidateLevel.Tight))
{
NameTextBox.BackColor = Color.FromArgb(64, 64, 64);
Variables[VariablesList.SelectedIndex] = NameTextBox.Text;
VariablesList.Items[VariablesList.SelectedIndex] = NameTextBox.Text;
AllowClose = true;
}
else
{
NameTextBox.BackColor = Color.FromArgb(192, 0, 0);
AllowClose = false;
}
}
private void ValueTextBox_TextChanged(object sender, EventArgs e)
{
if (Variables.Count == 0)
return;
try
{
VariableValues[VariablesList.SelectedIndex] = ValueTextBox.Text;
}
catch
{
}
}
private void VariablesList_MeasureItem(object sender, MeasureItemEventArgs e)
{
e.ItemHeight = 20;
}
private void VariablesList_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index < 0)
return;
bool IsSelected = false;
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
IsSelected = true;
e.Graphics.FillRectangle(Brushes.White, e.Bounds);
string FinalText = Variables[e.Index];
var TF = new Font("Tahoma", 11f, FontStyle.Regular, GraphicsUnit.Pixel);
if (IsSelected)
{
var x = new LinearGradientBrush(new Rectangle(0, e.Bounds.X, e.Bounds.Width, 20), Color.FromArgb(64, 64, 64), Color.Black, LinearGradientMode.Vertical);
e.Graphics.FillRectangle(x, new Rectangle(0, e.Bounds.Y, e.Bounds.Width, 20));
e.Graphics.DrawString(FinalText, TF, Brushes.White, 20f, e.Bounds.Y + 3);
}
else
{
e.Graphics.DrawString(FinalText, TF, Brushes.Black, 20f, e.Bounds.Y + 3);
}
e.Graphics.DrawImageUnscaled(Properties.Resources.VariableIcon, new Point(4, e.Bounds.Y + 4));
}
private void TypeList_MeasureItem(object sender, MeasureItemEventArgs e)
{
e.ItemHeight = 16;
}
private void TypeList_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index < 0)
return;
bool IsSelected = false;
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
IsSelected = true;
e.Graphics.FillRectangle(Brushes.White, e.Bounds);
string FinalText = TypeList.Items[e.Index].ToString();
if (IsSelected)
{
var x = new LinearGradientBrush(new Rectangle(0, e.Bounds.X, e.Bounds.Width, e.Bounds.Height), Color.FromArgb(192, 192, 192), Color.FromArgb(80, 80, 80), LinearGradientMode.Vertical);
e.Graphics.FillRectangle(x, new Rectangle(0, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
e.Graphics.DrawString(FinalText, new Font("Tahoma", 11f, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, 3f, e.Bounds.Y + 1);
}
else
{
e.Graphics.DrawString(FinalText, new Font("Tahoma", 11f, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.Black, 3f, e.Bounds.Y + 1);
}
}
private void GlobalVariables_FormClosing(object sender, FormClosingEventArgs e)
{
if (!AllowClose)
{
e.Cancel = true;
return;
}
DSGMlib.XDSRemoveFilter("GLOBAL ");
for (short i = 0, loopTo = (short)(Variables.Count - 1); i <= loopTo; i++)
{
string NewLine = "GLOBAL " + Variables[i] + ",";
NewLine += MyVariableTypes[i] + ",";
NewLine += VariableValues[i];
DSGMlib.XDSAddLine(NewLine);
}
}
}
}