author | Wuzzy <Wuzzy2@mail.ru> |
Fri, 05 Jun 2020 00:37:33 +0200 | |
changeset 15591 | 130b5052335c |
parent 12926 | 502d18361c7e |
permissions | -rw-r--r-- |
1236 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
9998
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1236 | 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 |
{ |
9738 | 40 |
qDebug("HatModel::loadHats()"); |
41 |
||
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
42 |
// this method resets the contents of this model (important to know for views). |
8374 | 43 |
QStandardItemModel::beginResetModel(); |
44 |
QStandardItemModel::clear(); |
|
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
45 |
|
8374 | 46 |
// New hats to add to model |
47 |
QList<QStandardItem *> hats; |
|
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
48 |
|
8374 | 49 |
// we'll need the DataManager a few times, so let's get a reference to it |
6930 | 50 |
DataManager & dataMgr = DataManager::instance(); |
6196 | 51 |
|
8374 | 52 |
// Default hat icon |
8049 | 53 |
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
|
54 |
|
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
|
55 |
// my reserved hats |
6196 | 56 |
QStringList hatsList = dataMgr.entryList( |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6196
diff
changeset
|
57 |
"Graphics/Hats/Reserved", |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6196
diff
changeset
|
58 |
QDir::Files, |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6196
diff
changeset
|
59 |
QStringList(playerHash+"*.png") |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6196
diff
changeset
|
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 |
int nReserved = hatsList.size(); |
1281 | 62 |
|
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
|
63 |
// regular hats |
6196 | 64 |
hatsList.append(dataMgr.entryList( |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6196
diff
changeset
|
65 |
"Graphics/Hats", |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6196
diff
changeset
|
66 |
QDir::Files, |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6196
diff
changeset
|
67 |
QStringList("*.png") |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6196
diff
changeset
|
68 |
) |
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
|
69 |
); |
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
|
70 |
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
|
71 |
|
8374 | 72 |
// 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
|
73 |
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
|
74 |
{ |
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
|
75 |
bool isReserved = (i < nReserved); |
1239 | 76 |
|
8374 | 77 |
if (isReserved) continue; // For some reason, reserved hats were added in 9.19-dev, so this will hide them. Uncomment to show them. |
78 |
||
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
|
79 |
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
|
80 |
str = str.remove(QRegExp("\\.png$")); |
12926
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
81 |
QPixmap hatpix( |
8049 | 82 |
"physfs://Graphics/Hats/" + QString(isReserved?"Reserved/":"") + str + |
8434 | 83 |
".png" |
6167 | 84 |
); |
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
|
85 |
|
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 |
// 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
|
87 |
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
|
88 |
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
|
89 |
|
12926
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
90 |
// Color for team hats. We use the default color of the first team. |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
91 |
QColor overlay_color = QColor(colors[0]); |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
92 |
|
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
93 |
QPixmap ppix(32, 37); |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
94 |
ppix.fill(QColor(Qt::transparent)); |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
95 |
QPainter painter(&ppix); |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
96 |
|
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
97 |
QPixmap opix(32, 37); |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
98 |
opix.fill(QColor(Qt::transparent)); |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
99 |
QPainter overlay_painter(&opix); |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
100 |
|
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
101 |
// The hat is drawn in reverse: First the color overlay, then the hat, then the hedgehog. |
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
|
102 |
|
12926
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
103 |
// draw hat's color layer, if present |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
104 |
int overlay_offset = -1; |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
105 |
if((hatpix.height() == 32) && (hatpix.width() == 64)) { |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
106 |
overlay_offset = 32; |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
107 |
} else if(hatpix.width() > 64) { |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
108 |
overlay_offset = 64; |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
109 |
} |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
110 |
if(overlay_offset > -1) { |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
111 |
// colorized layer |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
112 |
overlay_painter.drawPixmap(QPoint(0, 0), hatpix.copy(overlay_offset, 0, 32, 32)); |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
113 |
overlay_painter.setCompositionMode(QPainter::CompositionMode_Multiply); |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
114 |
overlay_painter.fillRect(0, 0, 32, 32, overlay_color); |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
115 |
|
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
116 |
// uncolorized layer and combine |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
117 |
painter.drawPixmap(QPoint(0, 0), hatpix.copy(overlay_offset, 0, 32, 32)); |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
118 |
painter.setCompositionMode(QPainter::CompositionMode_SourceAtop); |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
119 |
painter.drawPixmap(QPoint(0, 0), opix.copy(0, 0, 32, 32)); |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
120 |
} |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
121 |
|
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
122 |
// draw hat below the color layer |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
123 |
painter.setCompositionMode(QPainter::CompositionMode_DestinationOver); |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
124 |
painter.drawPixmap(QPoint(0, 0), hatpix.copy(0, 0, 32, 32)); |
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
125 |
|
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
126 |
// draw hedgehog below the hat |
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
|
127 |
painter.drawPixmap(QPoint(0, 5), hhpix); |
12926
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
128 |
|
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
|
129 |
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
|
130 |
|
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
|
131 |
if (str == "NoHat") |
12926
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
132 |
hats.prepend(new QStandardItem(QIcon(ppix), 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
|
133 |
else |
12926
502d18361c7e
Fix broken preview of team hats in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
134 |
hats.append(new QStandardItem(QIcon(ppix), str)); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2874
diff
changeset
|
135 |
} |
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
136 |
|
8374 | 137 |
QStandardItemModel::appendColumn(hats); |
138 |
QStandardItemModel::endResetModel(); |
|
8385
9e8924ff9813
Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents:
8374
diff
changeset
|
139 |
} |