A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
--- a/QTfrontend/hats.cpp Fri Feb 26 16:29:00 2010 +0000
+++ b/QTfrontend/hats.cpp Fri Feb 26 19:52:22 2010 +0000
@@ -20,6 +20,7 @@
#include <QPixmap>
#include <QPainter>
#include "hwconsts.h"
+#include "hwform.h"
#include "hats.h"
HatsModel::HatsModel(QObject* parent) :
@@ -51,6 +52,24 @@
hats.append(qMakePair(str, QIcon(tmppix)));
}
+ // Reserved hats
+ tmpdir.cd("Reserved");
+ hatsList = tmpdir.entryList(QStringList(playerHash+"*.png"));
+ for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it )
+ {
+ QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1");
+ QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/Reserved/" + str + ".png");
+
+ QPixmap tmppix(32, 37);
+ tmppix.fill(QColor(Qt::transparent));
+
+ QPainter painter(&tmppix);
+ painter.drawPixmap(QPoint(0, 5), hhpix);
+ painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32));
+ painter.end();
+
+ hats.append(qMakePair("Reserved "+str.remove(0,32), QIcon(tmppix)));
+ }
}
QVariant HatsModel::headerData(int section,
--- a/QTfrontend/hwform.cpp Fri Feb 26 16:29:00 2010 +0000
+++ b/QTfrontend/hwform.cpp Fri Feb 26 19:52:22 2010 +0000
@@ -34,6 +34,7 @@
#include <QScrollBar>
#include <QDataWidgetMapper>
#include <QTableView>
+#include <QCryptographicHash>
#include "hwform.h"
#include "game.h"
@@ -68,6 +69,7 @@
// I started handing this down to each place it touches, but it was getting ridiculous
// and this one flag does not warrant a static class
bool frontendEffects = true;
+QString playerHash;
HWForm::HWForm(QWidget *parent)
: QMainWindow(parent), pnetserver(0), pRegisterServer(0), editedTeam(0), hwnet(0)
@@ -77,6 +79,7 @@
#endif
gameSettings = new QSettings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat);
frontendEffects = gameSettings->value("video/frontendeffects", true).toBool();
+ playerHash = QString(QCryptographicHash::hash(gameSettings->value("net/nick","").toString().toLatin1(), QCryptographicHash::Md5).toHex());
ui.setupUi(this);
--- a/QTfrontend/hwform.h Fri Feb 26 16:29:00 2010 +0000
+++ b/QTfrontend/hwform.h Fri Feb 26 19:52:22 2010 +0000
@@ -44,6 +44,7 @@
class QSettings;
extern bool frontendEffects;
+extern QString playerHash;
class HWForm : public QMainWindow
{
--- a/QTfrontend/team.cpp Fri Feb 26 16:29:00 2010 +0000
+++ b/QTfrontend/team.cpp Fri Feb 26 19:52:22 2010 +0000
@@ -21,6 +21,7 @@
#include <QApplication>
#include <QStringList>
#include <QLineEdit>
+#include <QCryptographicHash>
#include "team.h"
#include "hwform.h"
#include "pages.h"
@@ -217,8 +218,11 @@
hwform->ui.pageEditTeam->CBTeamLvl->setCurrentIndex(difficulty);
for(int i = 0; i < 8; i++)
{
- hwform->ui.pageEditTeam->HHNameEdit[i]->setText(HHName[i]);
- hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData(HHHat[i], Qt::DisplayRole));
+ hwform->ui.pageEditTeam->HHNameEdit[i]->setText(HHName[i]);
+ if (HHHat[i].startsWith("Reserved"))
+ hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData("Reserved "+HHHat[i].remove(0,40), Qt::DisplayRole));
+ else
+ hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData(HHHat[i], Qt::DisplayRole));
}
hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(Grave));
hwform->ui.pageEditTeam->CBFlag->setCurrentIndex(hwform->ui.pageEditTeam->CBFlag->findText(Flag));
@@ -240,7 +244,10 @@
for(int i = 0; i < 8; i++)
{
HHName[i] = hwform->ui.pageEditTeam->HHNameEdit[i]->text();
- HHHat[i] = hwform->ui.pageEditTeam->HHHats[i]->currentText();
+ if (hwform->ui.pageEditTeam->HHHats[i]->currentText().startsWith("Reserved"))
+ HHHat[i] = "Reserved"+playerHash+hwform->ui.pageEditTeam->HHHats[i]->currentText().remove(0,9);
+ else
+ HHHat[i] = hwform->ui.pageEditTeam->HHHats[i]->currentText();
}
Grave = hwform->ui.pageEditTeam->CBGrave->currentText();
@@ -256,10 +263,14 @@
QStringList HWTeam::TeamGameConfig(quint32 InitHealth) const
{
QStringList sl;
- sl.push_back(QString("eaddteam %1 %2").arg(teamColor.rgb() & 0xffffff).arg(TeamName));
+ if (m_isNetTeam)
+ {
+ sl.push_back(QString("eaddteam %3 %1 %2").arg(teamColor.rgb() & 0xffffff).arg(TeamName).arg(QString(QCryptographicHash::hash(Owner.toLatin1(), QCryptographicHash::Md5).toHex())));
+ sl.push_back("erdriven");
+ }
+ else sl.push_back(QString("eaddteam %3 %1 %2").arg(teamColor.rgb() & 0xffffff).arg(TeamName).arg(playerHash));
if (m_isNetTeam)
- sl.push_back("erdriven");
sl.push_back(QString("egrave " + Grave));
sl.push_back(QString("efort " + Fort));
--- a/hedgewars/CCHandlers.inc Fri Feb 26 16:29:00 2010 +0000
+++ b/hedgewars/CCHandlers.inc Fri Feb 26 19:52:22 2010 +0000
@@ -73,12 +73,13 @@
procedure chAddTeam(var s: shortstring);
var Color: Longword;
- ts: shortstring;
+ ts, cs: shortstring;
begin
if isDeveloperMode then
begin
- SplitBySpace(s, ts);
- val(s, Color);
+ SplitBySpace(s, cs);
+ SplitBySpace(cs, ts);
+ val(cs, Color);
TryDo(Color <> 0, 'Error: black team color', true);
// color is always little endian so the mask must be constant also in big endian archs
@@ -86,6 +87,7 @@
AddTeam(Color);
CurrentTeam^.TeamName:= ts;
+ CurrentTeam^.PlayerHash:= s;
if GameType in [gmtDemo, gmtSave] then CurrentTeam^.ExtDriven:= true;
CurrentTeam^.voicepack:= AskForVoicepack('Default')
@@ -169,7 +171,9 @@
with CurrentTeam^ do
begin
if not CurrentHedgehog^.King then
- if (s = '') or (((GameFlags and gfKing) <> 0) and (s = 'crown')) then
+ if (s = '') or
+ (((GameFlags and gfKing) <> 0) and (s = 'crown')) or
+ ((Length(s) > 39) and (Copy(s,1,8) = 'Reserved') and (Copy(s,9,32) <> PlayerHash)) then
CurrentHedgehog^.Hat:= 'NoHat'
else
CurrentHedgehog^.Hat:= s
--- a/hedgewars/uStore.pas Fri Feb 26 16:29:00 2010 +0000
+++ b/hedgewars/uStore.pas Fri Feb 26 19:52:22 2010 +0000
@@ -247,7 +247,11 @@
NameTagTex:= RenderStringTex(Name, Clan^.Color, CheckCJKFont(Name,fnt16));
if Hat <> 'NoHat' then
begin
- texsurf:= LoadImage(Pathz[ptHats] + '/' + Hat, ifNone);
+ texsurf:= nil;
+ if (Length(Hat) > 39) and (Copy(Hat,1,8) = 'Reserved') and (Copy(Hat,9,32) = PlayerHash) then
+ texsurf:= LoadImage(Pathz[ptHats] + '/Reserved/' + Copy(Hat,9,Length(s)-8), ifNone)
+ else
+ texsurf:= LoadImage(Pathz[ptHats] + '/' + Hat, ifNone);
if texsurf <> nil then
begin
HatTex:= Surface2Tex(texsurf, true);
--- a/hedgewars/uTeams.pas Fri Feb 26 16:29:00 2010 +0000
+++ b/hedgewars/uTeams.pas Fri Feb 26 19:52:22 2010 +0000
@@ -79,6 +79,7 @@
HedgehogsNumber: Longword;
hasGone: boolean;
voicepack: PVoicepack;
+ PlayerHash: string; // md5 hash of player name. For temporary enabling of hats as thank you. Hashed for privacy of players
end;
TClan = record
--- a/share/hedgewars/Data/Graphics/Hats/CMakeLists.txt Fri Feb 26 16:29:00 2010 +0000
+++ b/share/hedgewars/Data/Graphics/Hats/CMakeLists.txt Fri Feb 26 19:52:22 2010 +0000
@@ -1,3 +1,5 @@
+add_subdirectory(Reserved)
+
file(GLOB HatSprites *.png)
install(FILES
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/Graphics/Hats/Reserved/CMakeLists.txt Fri Feb 26 19:52:22 2010 +0000
@@ -0,0 +1,5 @@
+file(GLOB HatSprites *.png)
+
+install(FILES
+ ${HatSprites}
+ DESTINATION ${SHAREPATH}Data/Graphics/Hats/Reserved)
Binary file share/hedgewars/Data/Graphics/Hats/Reserved/e587f6146ebfbdefdc028c591643f220test.png has changed