76 |
76 |
77 if (isReserved) continue; // For some reason, reserved hats were added in 9.19-dev, so this will hide them. Uncomment to show them. |
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 |
78 |
79 QString str = hatsList.at(i); |
79 QString str = hatsList.at(i); |
80 str = str.remove(QRegExp("\\.png$")); |
80 str = str.remove(QRegExp("\\.png$")); |
81 QPixmap pix( |
81 QPixmap hatpix( |
82 "physfs://Graphics/Hats/" + QString(isReserved?"Reserved/":"") + str + |
82 "physfs://Graphics/Hats/" + QString(isReserved?"Reserved/":"") + str + |
83 ".png" |
83 ".png" |
84 ); |
84 ); |
85 |
85 |
86 // rename properly |
86 // rename properly |
87 if (isReserved) |
87 if (isReserved) |
88 str = "Reserved "+str.remove(0,32); |
88 str = "Reserved "+str.remove(0,32); |
89 |
89 |
90 QPixmap tmppix(32, 37); |
90 // Color for team hats. We use the default color of the first team. |
91 tmppix.fill(QColor(Qt::transparent)); |
91 QColor overlay_color = QColor(colors[0]); |
92 |
92 |
93 QPainter painter(&tmppix); |
93 QPixmap ppix(32, 37); |
|
94 ppix.fill(QColor(Qt::transparent)); |
|
95 QPainter painter(&ppix); |
|
96 |
|
97 QPixmap opix(32, 37); |
|
98 opix.fill(QColor(Qt::transparent)); |
|
99 QPainter overlay_painter(&opix); |
|
100 |
|
101 // The hat is drawn in reverse: First the color overlay, then the hat, then the hedgehog. |
|
102 |
|
103 // draw hat's color layer, if present |
|
104 int overlay_offset = -1; |
|
105 if((hatpix.height() == 32) && (hatpix.width() == 64)) { |
|
106 overlay_offset = 32; |
|
107 } else if(hatpix.width() > 64) { |
|
108 overlay_offset = 64; |
|
109 } |
|
110 if(overlay_offset > -1) { |
|
111 // colorized layer |
|
112 overlay_painter.drawPixmap(QPoint(0, 0), hatpix.copy(overlay_offset, 0, 32, 32)); |
|
113 overlay_painter.setCompositionMode(QPainter::CompositionMode_Multiply); |
|
114 overlay_painter.fillRect(0, 0, 32, 32, overlay_color); |
|
115 |
|
116 // uncolorized layer and combine |
|
117 painter.drawPixmap(QPoint(0, 0), hatpix.copy(overlay_offset, 0, 32, 32)); |
|
118 painter.setCompositionMode(QPainter::CompositionMode_SourceAtop); |
|
119 painter.drawPixmap(QPoint(0, 0), opix.copy(0, 0, 32, 32)); |
|
120 } |
|
121 |
|
122 // draw hat below the color layer |
|
123 painter.setCompositionMode(QPainter::CompositionMode_DestinationOver); |
|
124 painter.drawPixmap(QPoint(0, 0), hatpix.copy(0, 0, 32, 32)); |
|
125 |
|
126 // draw hedgehog below the hat |
94 painter.drawPixmap(QPoint(0, 5), hhpix); |
127 painter.drawPixmap(QPoint(0, 5), hhpix); |
95 painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32)); |
128 |
96 if(pix.width() > 32) |
|
97 painter.drawPixmap(QPoint(0, 0), pix.copy(32, 0, 32, 32)); |
|
98 painter.end(); |
129 painter.end(); |
99 |
130 |
100 if (str == "NoHat") |
131 if (str == "NoHat") |
101 hats.prepend(new QStandardItem(QIcon(tmppix), str)); |
132 hats.prepend(new QStandardItem(QIcon(ppix), str)); |
102 else |
133 else |
103 hats.append(new QStandardItem(QIcon(tmppix), str)); |
134 hats.append(new QStandardItem(QIcon(ppix), str)); |
104 } |
135 } |
105 |
136 |
106 QStandardItemModel::appendColumn(hats); |
137 QStandardItemModel::appendColumn(hats); |
107 QStandardItemModel::endResetModel(); |
138 QStandardItemModel::endResetModel(); |
108 } |
139 } |