-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGridSelector.cpp
287 lines (273 loc) · 5.91 KB
/
GridSelector.cpp
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
#include "GridSelector.h"
#include <new>
namespace AwpSoftGameModule
{
unsigned int GridSelector::primaryAdd()
{
unsigned 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((unsigned short)i, 0)];
if ((t & 0xF0000000) && (t & 0x0F000000))
{
CurrentSelect = i;
return CurrentSelect;
}
}
break;
case MNSTYLE_GR:
while (i < PKinds - 1)
{
i++;
t = UnitAttribute[flatten((unsigned short)i, s >> 16)];
if ((t & 0xF0000000) && (t & 0x0F000000))
{
CurrentSelect = i | s;
return CurrentSelect;
}
}
break;
default:
break;
}
return CurrentSelect;
}
unsigned int GridSelector::primarySub()
{
unsigned 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[(unsigned short)flatten((unsigned short)i, 0)];
if ((t & 0xF0000000) && (t & 0x0F000000))
{
CurrentSelect = i;
return CurrentSelect;
}
}
break;
case MNSTYLE_GR:
while (i > 0)
{
i--;
t = getUnitAttribute((unsigned short)i, s >> 16);
if ((t & 0xF0000000) && (t & 0x0F000000))
{
CurrentSelect = i | s;
return CurrentSelect;
}
}
break;
default:
break;
}
return CurrentSelect;
}
unsigned int GridSelector::secondaryAdd()
{
unsigned 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((unsigned short)i, (unsigned short)s)];
if ((t & 0xF0000000) && (t & 0x0F000000))
{
CurrentSelect = (s << 16) | i;
return CurrentSelect;
}
}
break;
default:
break;
}
return CurrentSelect;
}
unsigned int GridSelector::secondarySub()
{
unsigned 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((unsigned short)i, (unsigned short)s)];
if ((t & 0xF0000000) && (t & 0x0F000000))
{
CurrentSelect = (s << 16) | i;
return CurrentSelect;
}
}
break;
default:
break;
}
return CurrentSelect;
}
unsigned int GridSelector::flatten(unsigned short index, unsigned short secondaryIndex)
{
return index * SKinds + secondaryIndex;
}
GridSelector::GridSelector(SelectorMenuStyle style, unsigned short kinds, unsigned short secondaryKinds)
{
MenuStyle = style;
PKinds = kinds;
SKinds = secondaryKinds;
CurrentSelect = 0x0;
switch (style)
{
case MNSTYLE_V:
case MNSTYLE_H:
SKinds = 1;
break;
case MNSTYLE_HL:
case MNSTYLE_VL:
case MNSTYLE_GR:
break;
}
UnitAttribute = std::move(std::vector<unsigned int>(SKinds * PKinds , 0xFF000000));
}
GridSelector::~GridSelector()
{
}
void GridSelector::setUnitAttribute(unsigned int attribute, unsigned short index, unsigned short secondaryIndex)
{
index = (unsigned short)min((unsigned int)index, PKinds - 1);
secondaryIndex = (unsigned short)min((unsigned int)secondaryIndex, SKinds - 1);
UnitAttribute[flatten(index, secondaryIndex)] = attribute;
}
void GridSelector::setCurrentAttribute(unsigned int attribute)
{
unsigned int temp = CurrentSelect;
UnitAttribute[flatten(temp & 0x0000FFFF, (temp >> 16) & 0x0000FFFF)] = attribute;
}
unsigned int GridSelector::getUnitAttribute(unsigned short index, unsigned short secondaryIndex)
{
index = (unsigned short)min((unsigned int)index, PKinds - 1);
secondaryIndex = (unsigned short)min((unsigned int)secondaryIndex, SKinds - 1);
return UnitAttribute[flatten(index, secondaryIndex)];
}
unsigned short GridSelector::getCurrentSelectIndex()
{
return (unsigned short)(CurrentSelect & 0x0000FFFF);
}
unsigned short GridSelector::getCurrentSelectSecondaryIndex()
{
return (unsigned short)((CurrentSelect & 0xFFFF0000) >> 16);
}
void GridSelector::setCurrentSelectIndex(unsigned short index, unsigned short secondaryIndex)
{
index = (unsigned short)min((unsigned int)index, PKinds - 1);
secondaryIndex = (unsigned short)min((unsigned int)secondaryIndex, SKinds - 1);
CurrentSelect = (secondaryIndex << 16) | index;
}
unsigned int GridSelector::getCurrentSelectAttribute()
{
unsigned int temp = CurrentSelect;
return UnitAttribute[flatten(temp & 0x0000FFFF, (temp >> 16) & 0x0000FFFF)];
}
unsigned int GridSelector::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;
}
unsigned int GridSelector::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;
}
unsigned int GridSelector::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;
}
unsigned int GridSelector::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;
}
};