@@ -19,6 +19,11 @@ public partial class EditVars : Form
19
19
private readonly int selectedMap ;
20
20
private readonly Trigger trigger ;
21
21
22
+ //Lists to keep track of the last value in any given cell of the gridviews, so it can be reverted
23
+ private readonly List < string > savedVarNames = new List < string > ( ) ;
24
+ private readonly List < string > savedProcNames = new List < string > ( ) ;
25
+ private readonly List < string > savedLabelNames = new List < string > ( ) ;
26
+
22
27
public EditVars ( ScriptViewer parent , string viewingFile , int selectedMap , Trigger trigger )
23
28
{
24
29
InitializeComponent ( ) ;
@@ -47,15 +52,27 @@ private void PopulateLists()
47
52
48
53
for ( int i = 0 ; i < Info . NumVars ( ) ; i ++ )
49
54
{
50
- DGV_Vars . Rows . Add ( Info . GetVar ( i ) ) ;
55
+ int cellNr = DGV_Vars . Rows . Add ( Info . GetVar ( i ) ) ;
56
+ var cell = DGV_Vars . Rows [ cellNr ] . Cells [ 0 ] ;
57
+
58
+ if ( i < 24 )
59
+ {
60
+ cell . Style . BackColor = Color . LightGray ;
61
+ }
62
+
63
+ savedVarNames . Add ( Info . GetVar ( i ) ) ;
51
64
}
52
65
for ( int i = 0 ; i < Info . NumProcs ( ) ; i ++ )
53
66
{
54
67
DGV_Procs . Rows . Add ( Info . GetProc ( i ) ) ;
68
+
69
+ savedProcNames . Add ( Info . GetProc ( i ) ) ;
55
70
}
56
71
foreach ( KeyValuePair < int , string > entry in Info . Labels )
57
72
{
58
73
DGV_Labels . Rows . Add ( entry . Value ) ;
74
+
75
+ savedLabelNames . Add ( entry . Value ) ;
59
76
}
60
77
}
61
78
@@ -99,17 +116,6 @@ private void SaveScriptInfo()
99
116
ScriptViewerWnd . InsertDecompiledCode ( ) ;
100
117
}
101
118
102
- private void Btn_Apply_Click ( object sender , EventArgs e )
103
- {
104
- SaveScriptInfo ( ) ;
105
- }
106
-
107
- private void DGV_Vars_CellValueChanged ( object sender , DataGridViewCellEventArgs e )
108
- {
109
- GameScriptSaveInfo Info = ScriptSaveInfoHandler . ActiveInfo ;
110
- Info . SetVar ( e . RowIndex , DGV_Vars . Rows [ e . RowIndex ] . Cells [ 0 ] . Value . ToString ( ) ) ;
111
- }
112
-
113
119
private void Btn_Reset_Click ( object sender , EventArgs e )
114
120
{
115
121
DialogResult res = MessageBox . Show (
@@ -135,5 +141,115 @@ private void Btn_Reset_Click(object sender, EventArgs e)
135
141
PopulateLists ( ) ;
136
142
}
137
143
}
144
+
145
+ private void Btn_Apply_Click ( object sender , EventArgs e )
146
+ {
147
+ SaveScriptInfo ( ) ;
148
+ }
149
+
150
+ private void DGV_Vars_CellValueChanged ( object sender , DataGridViewCellEventArgs e )
151
+ {
152
+ if ( e . RowIndex < 0 )
153
+ {
154
+ return ;
155
+ }
156
+
157
+ DataGridViewCell cell = DGV_Vars . Rows [ e . RowIndex ] . Cells [ 0 ] ;
158
+
159
+ //Check if using reserved syntax
160
+ foreach ( string s in Syntax . SYNTAX_KEYWORDS )
161
+ {
162
+ if ( ( ( string ) cell . Value ) . IndexOf ( s ) >= 0 )
163
+ {
164
+ MessageBox . Show ( "A variable cannot contain reserved keyword " + s + "." , "Invalid name" ,
165
+ MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
166
+
167
+ cell . Value = savedVarNames [ e . RowIndex ] ;
168
+ return ;
169
+ }
170
+ }
171
+ //Check if using hashcode naming
172
+ if ( ( ( string ) cell . Value ) . IndexOf ( "HT_" ) >= 0 )
173
+ {
174
+ MessageBox . Show ( "A variable cannot contain \" HT_\" , as this marks the start of a hashcode." , "Invalid name" ,
175
+ MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
176
+
177
+ cell . Value = savedVarNames [ e . RowIndex ] ;
178
+ return ;
179
+ }
180
+
181
+ //Else overwrite our saved value
182
+ savedVarNames [ e . RowIndex ] = ( string ) cell . Value ;
183
+ }
184
+
185
+ private void DGV_Procs_CellValueChanged ( object sender , DataGridViewCellEventArgs e )
186
+ {
187
+ if ( e . RowIndex < 0 )
188
+ {
189
+ return ;
190
+ }
191
+
192
+ DataGridViewCell cell = DGV_Procs . Rows [ e . RowIndex ] . Cells [ 0 ] ;
193
+
194
+ //Check if using reserved syntax
195
+ foreach ( string s in Syntax . SYNTAX_KEYWORDS )
196
+ {
197
+ if ( ( ( string ) cell . Value ) . IndexOf ( s ) >= 0 )
198
+ {
199
+ MessageBox . Show ( "A procedure cannot contain reserved keyword " + s + "." , "Invalid name" ,
200
+ MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
201
+
202
+ cell . Value = savedProcNames [ e . RowIndex ] ;
203
+ return ;
204
+ }
205
+ }
206
+ //Check if using hashcode naming
207
+ if ( ( ( string ) cell . Value ) . IndexOf ( "HT_" ) >= 0 )
208
+ {
209
+ MessageBox . Show ( "A procedure cannot contain \" HT_\" , as this marks the start of a hashcode." , "Invalid name" ,
210
+ MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
211
+
212
+ cell . Value = savedProcNames [ e . RowIndex ] ;
213
+ return ;
214
+ }
215
+
216
+ //Else overwrite our saved value
217
+ savedProcNames [ e . RowIndex ] = ( string ) cell . Value ;
218
+ }
219
+
220
+ private void DGV_Labels_CellValueChanged ( object sender , DataGridViewCellEventArgs e )
221
+ {
222
+ if ( e . RowIndex < 0 )
223
+ {
224
+ return ;
225
+ }
226
+
227
+ DataGridViewCell cell = DGV_Labels . Rows [ e . RowIndex ] . Cells [ 0 ] ;
228
+
229
+ //Check if using reserved syntax
230
+ foreach ( string s in Syntax . SYNTAX_KEYWORDS )
231
+ {
232
+ if ( ( ( string ) cell . Value ) . IndexOf ( s ) >= 0 )
233
+ {
234
+ MessageBox . Show ( "A label cannot contain reserved keyword " + s + "." , "Invalid name" ,
235
+ MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
236
+
237
+ cell . Value = savedLabelNames [ e . RowIndex ] ;
238
+ return ;
239
+ }
240
+ }
241
+ //Check if using hashcode naming
242
+ if ( ( ( string ) cell . Value ) . IndexOf ( "HT_" ) >= 0 )
243
+ {
244
+ MessageBox . Show ( "A label cannot contain \" HT_\" , as this marks the start of a hashcode." , "Invalid name" ,
245
+ MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
246
+
247
+ cell . Value = savedLabelNames [ e . RowIndex ] ;
248
+ return ;
249
+ }
250
+
251
+ //Else overwrite our saved value
252
+ savedLabelNames [ e . RowIndex ] = ( string ) cell . Value ;
253
+ }
138
254
}
139
255
}
0 commit comments