author | dag10 <gottlieb.drew@gmail.com> |
Sat, 19 Jan 2013 20:01:01 -0500 | |
changeset 8408 | 286823b10f35 |
parent 8385 | 9e8924ff9813 |
child 8434 | 4821897a0f10 |
permissions | -rw-r--r-- |
1236 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
6952 | 3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
1236 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
19 |
/** |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
20 |
* @file |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
21 |
* @brief HatModel class implementation |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
22 |
*/ |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
23 |
|
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
24 |
#include "HatModel.h" |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
25 |
|
1239 | 26 |
#include <QDir> |
27 |
#include <QPixmap> |
|
1281 | 28 |
#include <QPainter> |
8374 | 29 |
#include <QList> |
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
30 |
#include "hwform.h" // player hash |
1237 | 31 |
|
6930 | 32 |
#include "DataManager.h" |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
33 |
|
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
34 |
HatModel::HatModel(QObject* parent) : |
8374 | 35 |
QStandardItemModel(parent) |
36 |
{} |
|
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
37 |
|
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
38 |
void HatModel::loadHats() |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
39 |
{ |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
40 |
// this method resets the contents of this model (important to know for views). |
8374 | 41 |
QStandardItemModel::beginResetModel(); |
42 |
QStandardItemModel::clear(); |
|
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
43 |
|
8374 | 44 |
// New hats to add to model |
45 |
QList<QStandardItem *> hats; |
|
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
46 |
|
8374 | 47 |
// we'll need the DataManager a few times, so let's get a reference to it |
6930 | 48 |
DataManager & dataMgr = DataManager::instance(); |
6196 | 49 |
|
8374 | 50 |
// Default hat icon |
8049 | 51 |
QPixmap hhpix = QPixmap("physfs://Graphics/Hedgehog/Idle.png").copy(0, 0, 32, 32); |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
52 |
|
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
53 |
// my reserved hats |
6196 | 54 |
QStringList hatsList = dataMgr.entryList( |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6196
diff
changeset
|
55 |
"Graphics/Hats/Reserved", |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6196
diff
changeset
|
56 |
QDir::Files, |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6196
diff
changeset
|
57 |
QStringList(playerHash+"*.png") |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6196
diff
changeset
|
58 |
); |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
59 |
int nReserved = hatsList.size(); |
1281 | 60 |
|
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
61 |
// regular hats |
6196 | 62 |
hatsList.append(dataMgr.entryList( |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6196
diff
changeset
|
63 |
"Graphics/Hats", |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6196
diff
changeset
|
64 |
QDir::Files, |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6196
diff
changeset
|
65 |
QStringList("*.png") |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6196
diff
changeset
|
66 |
) |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
67 |
); |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
68 |
int nHats = hatsList.size(); |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
69 |
|
8374 | 70 |
// Add each hat |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
71 |
for (int i = 0; i < nHats; i++) |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
72 |
{ |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
73 |
bool isReserved = (i < nReserved); |
1239 | 74 |
|
8374 | 75 |
if (isReserved) continue; // For some reason, reserved hats were added in 9.19-dev, so this will hide them. Uncomment to show them. |
76 |
||
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
77 |
QString str = hatsList.at(i); |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
78 |
str = str.remove(QRegExp("\\.png$")); |
8049 | 79 |
QPixmap pix( |
80 |
"physfs://Graphics/Hats/" + QString(isReserved?"Reserved/":"") + str + |
|
81 |
".png" |
|
6167 | 82 |
); |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
83 |
|
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
84 |
// rename properly |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
85 |
if (isReserved) |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
86 |
str = "Reserved "+str.remove(0,32); |
5238
46ddaf14509d
Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents:
4976
diff
changeset
|
87 |
|
46ddaf14509d
Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents:
4976
diff
changeset
|
88 |
QPixmap tmppix(32, 37); |
46ddaf14509d
Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents:
4976
diff
changeset
|
89 |
tmppix.fill(QColor(Qt::transparent)); |
46ddaf14509d
Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents:
4976
diff
changeset
|
90 |
|
46ddaf14509d
Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents:
4976
diff
changeset
|
91 |
QPainter painter(&tmppix); |
46ddaf14509d
Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents:
4976
diff
changeset
|
92 |
painter.drawPixmap(QPoint(0, 5), hhpix); |
46ddaf14509d
Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents:
4976
diff
changeset
|
93 |
painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32)); |
46ddaf14509d
Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents:
4976
diff
changeset
|
94 |
if(pix.width() > 32) |
46ddaf14509d
Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents:
4976
diff
changeset
|
95 |
painter.drawPixmap(QPoint(0, 0), pix.copy(32, 0, 32, 32)); |
46ddaf14509d
Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents:
4976
diff
changeset
|
96 |
painter.end(); |
46ddaf14509d
Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents:
4976
diff
changeset
|
97 |
|
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
98 |
if (str == "NoHat") |
8374 | 99 |
hats.prepend(new QStandardItem(QIcon(tmppix), str)); |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6061
diff
changeset
|
100 |
else |
8374 | 101 |
hats.append(new QStandardItem(QIcon(tmppix), str)); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2874
diff
changeset
|
102 |
} |
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
103 |
|
8374 | 104 |
QStandardItemModel::appendColumn(hats); |
105 |
QStandardItemModel::endResetModel(); |
|
8385
9e8924ff9813
Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents:
8374
diff
changeset
|
106 |
} |