-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGridSelector.java
More file actions
311 lines (303 loc) · 6.73 KB
/
GridSelector.java
File metadata and controls
311 lines (303 loc) · 6.73 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
package awpsoft.gamemodule;
public class GridSelector
{
public enum SelectorMenuStyle
{
MNSTYLE_V,
MNSTYLE_H,
MNSTYLE_VL,
MNSTYLE_HL,
MNSTYLE_GR
};
private int primaryAdd()
{
int i, s, t;
i = CurrentSelect & 0x0000FFFF;
s = CurrentSelect & 0xFFFF0000;
switch (MenuStyle)
{
case MNSTYLE_H:
case MNSTYLE_V:
case MNSTYLE_HL:
case MNSTYLE_VL:
while (i < PKinds - 1)
{
i++;
t = UnitAttribute[flatten(i, 0)];
if (0 != (t & 0xF0000000) && 0 != (t & 0x0F000000))
{
CurrentSelect = i;
return CurrentSelect;
}
}
break;
case MNSTYLE_GR:
while (i < PKinds - 1)
{
i++;
t = UnitAttribute[flatten(i, s >>> 16)];
if (0 != (t & 0xF0000000) && 0 != (t & 0x0F000000))
{
CurrentSelect = i | s;
return CurrentSelect;
}
}
break;
default:
break;
}
return CurrentSelect;
}
private int primarySub()
{
int i, s, t;
i = CurrentSelect & 0x0000FFFF;
s = CurrentSelect & 0xFFFF0000;
switch (MenuStyle)
{
case MNSTYLE_H:
case MNSTYLE_V:
case MNSTYLE_HL:
case MNSTYLE_VL:
while (i > 0)
{
i--;
t = UnitAttribute[flatten(i, 0)];
if (0 != (t & 0xF0000000) && 0 != (t & 0x0F000000))
{
CurrentSelect = i;
return CurrentSelect;
}
}
break;
case MNSTYLE_GR:
while (i > 0)
{
i--;
t = getUnitAttribute(i, s >>> 16);
if (0 != (t & 0xF0000000) && 0 != (t & 0x0F000000))
{
CurrentSelect = i | s;
return CurrentSelect;
}
}
break;
default:
break;
}
return CurrentSelect;
}
private int secondaryAdd()
{
int i, s, t;
i = CurrentSelect & 0x0000FFFF;
s = CurrentSelect & 0xFFFF0000;
s >>>= 16;
switch (MenuStyle)
{
case MNSTYLE_H:
case MNSTYLE_V:
return CurrentSelect;
case MNSTYLE_HL:
case MNSTYLE_VL:
case MNSTYLE_GR:
while (s < SKinds - 1)
{
s++;
t = UnitAttribute[flatten(i, s)];
if (0 != (t & 0xF0000000) && 0 != (t & 0x0F000000))
{
CurrentSelect = (s << 16) | i;
return CurrentSelect;
}
}
break;
default:
break;
}
return CurrentSelect;
}
private int secondarySub()
{
int i, s, t;
i = CurrentSelect & 0x0000FFFF;
s = CurrentSelect & 0xFFFF0000;
s >>>= 16;
switch (MenuStyle)
{
case MNSTYLE_H:
case MNSTYLE_V:
return CurrentSelect;
case MNSTYLE_HL:
case MNSTYLE_VL:
case MNSTYLE_GR:
while (s > 0)
{
s--;
t = UnitAttribute[flatten(i, s)];
if (0 != (t & 0xF0000000) && 0 != (t & 0x0F000000))
{
CurrentSelect = (s << 16) | i;
return CurrentSelect;
}
}
break;
default:
break;
}
return CurrentSelect;
}
protected SelectorMenuStyle MenuStyle;
protected int CurrentSelect; // Secondary:&0xFFFF0000 Primary:&0x0000FFFF
protected int PKinds, SKinds;
protected int[] UnitAttribute; // Valid:&0xFF000000 Unlock:&&0x00FF0000 Value:&0x0000FFFF
protected int flatten(int index, int secondaryIndex)
{
return (int)((long)(index & 0x0000ffff) * (long)(SKinds & 0x0000ffff)) + (secondaryIndex & 0x0000ffff);
}
public static final int Attribute_Valid = 0xF0000000;
public static final int Attribute_Unlock = 0x0F000000;
public static final int Attribute_Enable = 0xFF000000;
public GridSelector(SelectorMenuStyle style, int sorts, int secondarySorts)
{
MenuStyle = style;
PKinds = 0x0000FFFF & sorts;
SKinds = 0x0000FFFF & secondarySorts;
CurrentSelect = 0x0;
switch (style)
{
case MNSTYLE_V:
case MNSTYLE_H:
SKinds = 1;
break;
case MNSTYLE_HL:
case MNSTYLE_VL:
case MNSTYLE_GR:
break;
}
int len = PKinds * SKinds;
UnitAttribute = new int[ PKinds * SKinds];
for(int i =0; i<len; i++) UnitAttribute[i] = 0xff000000;
}
public GridSelector(SelectorMenuStyle style, int sorts)
{
MenuStyle = style;
PKinds = 0x0000ffff & sorts;
SKinds = 1;
CurrentSelect = 0x0;
switch (style)
{
case MNSTYLE_V:
case MNSTYLE_H:
SKinds = 1;
break;
case MNSTYLE_HL:
case MNSTYLE_VL:
case MNSTYLE_GR:
break;
}
int len = PKinds * SKinds;
UnitAttribute = new int[ PKinds * SKinds];
for(int i =0; i < len; i++) UnitAttribute[i] = 0xFF000000;
}
/* Valid:&0xF0000000 Unlock:&&0x0F000000 Value:&0x00FFFFFF */
public void setUnitAttribute(int attribute, int index){setUnitAttribute(attribute, index, 0);}
public void setUnitAttribute(int attribute, int index, int secondaryIndex)
{
index = Math.min(0x0000FFFF & index, PKinds - 1);
secondaryIndex = Math.min(0x0000FFFF & secondaryIndex, SKinds - 1);
UnitAttribute[flatten(index, secondaryIndex)] = attribute;
}
public void setCurrentAttribute(int attribute)
{
UnitAttribute[flatten(CurrentSelect, CurrentSelect >>> 16)] = attribute;
}
public int getUnitAttribute(int index){return getUnitAttribute(index, 0);}
public int getUnitAttribute(int index, int secondaryIndex)
{
index = Math.min(0x0000FFFF & index, PKinds - 1);
secondaryIndex = Math.min(0x0000FFFF & secondaryIndex, SKinds - 1);
return UnitAttribute[flatten(index, secondaryIndex)];
}
public int getCurrentSelectIndex(){return CurrentSelect & 0x0000FFFF;}
public int getCurrentSelectSecondaryIndex(){return CurrentSelect >>> 16;}
public void setCurrentSelectIndex(int index){setCurrentSelectIndex(index, 0);}
public void setCurrentSelectIndex(int index, int secondaryIndex)
{
index = Math.min(0x0000FFFF &index, PKinds - 1);
secondaryIndex = Math.min(0x0000FFFF &secondaryIndex, SKinds - 1);
CurrentSelect = (secondaryIndex << 16) | index;
}
public int getCurrentSelectAttribute()
{
return UnitAttribute[flatten(CurrentSelect, CurrentSelect >>> 16)];
}
public int up()
{
switch (MenuStyle)
{
case MNSTYLE_H:
return CurrentSelect;
case MNSTYLE_V:
case MNSTYLE_VL:
case MNSTYLE_GR:
return primarySub();
case MNSTYLE_HL:
return secondarySub();
default:
break;
}
return CurrentSelect;
}
public int down()
{
switch (MenuStyle)
{
case MNSTYLE_H:
return CurrentSelect;
case MNSTYLE_V:
case MNSTYLE_VL:
case MNSTYLE_GR:
return primaryAdd();
case MNSTYLE_HL:
return secondaryAdd();
default:
break;
}
return CurrentSelect;
}
public int left()
{
switch (MenuStyle)
{
case MNSTYLE_V:
return CurrentSelect;
case MNSTYLE_H:
case MNSTYLE_HL:
return primarySub();
case MNSTYLE_GR:
case MNSTYLE_VL:
return secondarySub();
default:
break;
}
return CurrentSelect;
}
public int right()
{
switch (MenuStyle)
{
case MNSTYLE_V:
return CurrentSelect;
case MNSTYLE_H:
case MNSTYLE_HL:
return primaryAdd();
case MNSTYLE_GR:
case MNSTYLE_VL:
return secondaryAdd();
default:
break;
}
return CurrentSelect;
}
}