-
Notifications
You must be signed in to change notification settings - Fork 1
/
clientcardmodel.cpp
executable file
·376 lines (348 loc) · 10.3 KB
/
clientcardmodel.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#include "clientcardmodel.h"
#include "datamanager.h"
#include "card.h"
#include "game.h"
#include <QThread>
#include <QDebug>
#include <QtAlgorithms>
namespace glaze {
ClientCardModel::ClientCardModel(QObject *parent)
: QAbstractListModel(parent)
{
qRegisterMetaType<myIter>("myIter");
}
int ClientCardModel::rowCount(const QModelIndex &parent) const {
Q_UNUSED(parent);
return m_list.count();
}
QVariant ClientCardModel::data(const QModelIndex &index, int role) const {
if (index.row() < 0 || index.row() >= m_list.count())
return QVariant();
const ClientCard *clientCard = m_list[index.row()];
CardData cd;
ClientCardModel* lst = 0;
const wchar_t* showingtext;
if(!clientCard)
return 0;
if(!dataManager.GetData(clientCard->code, &cd))
memset(&cd, 0, sizeof(CardData));
QString formatBuffer;
switch(clientCard->location) {
case LOCATION_DECK:
lst = &mainGame->dField.deck[clientCard->controler];
break;
case LOCATION_HAND:
lst = &mainGame->dField.hand[clientCard->controler];
break;
case LOCATION_MZONE:
lst = &mainGame->dField.mzone[clientCard->controler];
break;
case LOCATION_SZONE:
lst = &mainGame->dField.szone[clientCard->controler];
break;
case LOCATION_GRAVE:
lst = &mainGame->dField.grave[clientCard->controler];
break;
case LOCATION_REMOVED:
lst = &mainGame->dField.remove[clientCard->controler];
break;
case LOCATION_EXTRA:
lst = &mainGame->dField.extra[clientCard->controler];
break;
}
switch (role) {
case CodeRole:
return clientCard->code;
break;
case AliasRole:
return cd.alias;
break;
case BaseTypeRole:
return cd.type;
break;
case BaseLevelRole:
return cd.level;
break;
case BaseRankRole:
return clientCard->rank; //might need an update
break;
case BaseAttributeRole:
return cd.attribute;
break;
case BaseRaceRole:
return cd.race;
break;
case BaseAttackRole:
return cd.attack;
break;
case BaseDefenceRole:
return cd.defence;
break;
case BaseLscaleRole:
return cd.lscale;
break;
case BaseRscaleRole:
return cd.rscale;
break;
case NameRole:
if(cd.alias != 0 && (cd.alias - clientCard->code < 10 || clientCard->code - cd.alias < 10))
formatBuffer = QString::fromWCharArray(dataManager.GetName(cd.alias));
else
formatBuffer = QString::fromWCharArray(dataManager.GetName(clientCard->code));
return formatBuffer;
break;
case FormatTypeRole:
formatBuffer = QString::fromWCharArray(dataManager.FormatType(cd.type));
formatBuffer = "[" + formatBuffer + "]";
return formatBuffer;
break;
case TextRole:
showingtext = dataManager.GetText(clientCard->code);
return QString::fromWCharArray(showingtext);
break;
case TypeRole:
return clientCard->type;
break;
case LevelRole:
return clientCard->level;
break;
case RankRole:
return clientCard->rank;
break;
case AttributeRole:
return clientCard->attribute;
break;
case RaceRole:
return clientCard->race;
break;
case AttackRole:
return clientCard->attack;
break;
case DefenceRole:
return clientCard->defence;
break;
case LscaleRole:
return clientCard->lscale;
break;
case RscaleRole:
return clientCard->rscale;
break;
case ControlerRole:
return clientCard->controler;
break;
case LocationRole:
return clientCard->location;
break;
case PositionRole:
return clientCard->position;
break;
case IsDisabledRole:
return clientCard->is_disabled;
break;
case CmdFlagRole:
return clientCard->cmdFlag;
break;
case OverlayedSizeRole:
return clientCard->overlayed.size();
break;
case EquipTargetController:
return clientCard->equipTarget->controler;
break;
case EquipTargetLocation:
return clientCard->equipTarget->location;
break;
case EquipTargetSequence:
return clientCard->equipTarget->sequence;
break;
case IsSelectableRole:
return clientCard->is_selectable;
break;
case IsSelectedRole:
return clientCard->is_selected;
break;
case SelectSeqRole:
return clientCard->select_seq;
break;
case OpParamRole:
return clientCard->opParam;
break;
case cardRole:
return clientCard;
break;
default:
break;
}
return QVariant();
}
Qt::ItemFlags ClientCardModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::ItemIsEnabled;
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
}
bool ClientCardModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.isValid()) {
ClientCard *clientCard = m_list[index.row()];
if(!clientCard)
return 0;
switch (role) {
case IsSelectableRole:
clientCard->is_selectable = value.toBool();
// qDebug()<<"ClientCard->is_selectable set to = "<<value.toBool();
emit dataChangedSignal(index.row(), QVector<int>(1,role));
break;
case IsSelectedRole:
clientCard->is_selected = value.toBool();
// qDebug()<<"ClientCard->is_selected set to = "<<value.toBool();
emit dataChangedSignal(index.row(), QVector<int>(1,role));
break;
case OpParamRole:
clientCard->opParam = value.toUInt();
// qDebug()<<"ClientCard->opParam set to = "<<value.toUInt();
emit dataChangedSignal(index.row(), QVector<int>(1,role));
break;
default:
break;
}
return true;
}
return false;
}
void ClientCardModel::dataChangedSignal() {
QModelIndex top = createIndex(0, 0);
QModelIndex bottom = createIndex(m_list.count() - 1, 0);
emit dataChanged(top, bottom);
}
void ClientCardModel::dataChangedSignal(int sequence, const QVector<int> &roles) {
QModelIndex index = createIndex(sequence, 0);
emit dataChanged(index, index, roles);
}
QHash<int, QByteArray> ClientCardModel::roleNames() const{
QHash<int, QByteArray> roles;
roles[CodeRole] = "code";
roles[AliasRole] = "alias";
roles[BaseTypeRole] = "baseType";
roles[BaseLevelRole] = "baseLevel";
roles[BaseRankRole] = "baseRank";
roles[BaseAttributeRole] = "baseAttribute";
roles[BaseRaceRole] = "baseRace";
roles[BaseAttackRole] = "baseAttack";
roles[BaseDefenceRole] = "baseDefence";
roles[BaseLscaleRole] = "baseLscale";
roles[BaseRscaleRole] = "baseRscale";
roles[NameRole] = "name";
roles[FormatTypeRole] = "formatType";
roles[TextRole] = "showingText";
roles[TypeRole] = "type";
roles[LevelRole] = "level";
roles[RankRole] = "rank";
roles[AttributeRole] = "attribute";
roles[RaceRole] = "race";
roles[AttackRole] = "attack";
roles[DefenceRole] = "defence";
roles[LscaleRole] = "lscale";
roles[RscaleRole] = "rscale";
roles[ControlerRole] = "controler";
roles[LocationRole] = "location";
roles[PositionRole] = "position";
roles[IsDisabledRole] = "isDisabled";
roles[CmdFlagRole] = "cmdFlag";
roles[OverlayedSizeRole] = "overlayedSize";
roles[EquipTargetController] = "equipTargetController";
roles[EquipTargetLocation] = "equipTargetLocation";
roles[EquipTargetSequence] = "equipTargetSequence";
roles[IsSelectableRole] = "isSelectable";
roles[IsSelectedRole] = "isSelected";
roles[SelectSeqRole] = "selectSeq";
roles[OpParamRole] = "opParam";
roles[cardRole] = "card";
return roles;
}
QList<ClientCard*>::iterator ClientCardModel::begin() {
if(m_list.size() >= 1)
return m_list.begin();
return 0;
}
QList<ClientCard*>::iterator ClientCardModel::end() {
if(m_list.size() >= 1)
return m_list.end();
return 0;
}
QList<ClientCard*>::const_iterator ClientCardModel::find(ClientCard *value) {
return qFind(m_list,value);
}
void ClientCardModel::clear() {
beginResetModel();
m_list.clear();
endResetModel();
}
void ClientCardModel::push_back(ClientCard *card) {
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_list << card;
endInsertRows();
// emit pushBackFinished();
}
int ClientCardModel::size() const {
return m_list.size();
}
QVariant ClientCardModel::getData(int index, int role) {
if (index < 0 || index >= m_list.count())
return QVariant();
const ClientCard *clientCard = m_list[index];
if(!clientCard)
return 0;
switch (role) {
case CodeRole:
return clientCard->code;
break;
case IsSelectableRole:
return clientCard->is_selectable;
break;
case IsSelectedRole:
return clientCard->is_selected;
break;
case SelectSeqRole:
return clientCard->select_seq;
break;
case OpParamRole:
return clientCard->opParam;
break;
default:
break;
}
}
QList<ClientCard*>::iterator ClientCardModel::erase(const myIter iter) {
beginRemoveRows(QModelIndex(), iter - m_list.begin(), iter - m_list.begin());
auto rtn = m_list.erase(iter);
endRemoveRows();
return rtn;
}
QList<ClientCard*>::iterator ClientCardModel::erase(const myIter begin,const myIter end) {
beginRemoveRows(QModelIndex(), begin - m_list.begin(), end - m_list.begin());
auto rtn = m_list.erase(begin, end);
endRemoveRows();
return rtn;
}
ClientCard* &ClientCardModel::last() {
return m_list.last();
}
void ClientCardModel::swap(ClientCardModel &other) {
beginResetModel();
other.beginResetModel();
m_list.swap(other.m_list);
endResetModel();
other.endResetModel();
}
ClientCard* &ClientCardModel::operator [](int i) {
return m_list[i];
}
ClientCard* ClientCardModel::at(int i) {
return m_list[i];
}
void ClientCardModel::copy(const ClientCardModel &model) {
beginResetModel();
m_list = model.m_list;
endResetModel();
}
}