Frontend:
* Added support for extended Xfire status display (Win32; requires Xfire SDK; CMAKE variable to add/ignore missing)
--- a/QTfrontend/CMakeLists.txt Wed Feb 17 17:38:32 2010 +0000
+++ b/QTfrontend/CMakeLists.txt Wed Feb 17 19:50:22 2010 +0000
@@ -89,6 +89,11 @@
bgwidget.cpp
)
+#xfire integration
+if(WIN32)
+ set(hwfr_src ${hwfr_src} xfire.cpp xfiregameclient.cpp)
+endif(WIN32)
+
if(MINGW)
# resource compilation for mingw
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/hedgewars_rc.o
--- a/QTfrontend/hwform.cpp Wed Feb 17 17:38:32 2010 +0000
+++ b/QTfrontend/hwform.cpp Wed Feb 17 19:50:22 2010 +0000
@@ -54,6 +54,7 @@
#include "input_ip.h"
#include "ammoSchemeModel.h"
#include "bgwidget.h"
+#include "xfire.h"
#ifdef __APPLE__
#include "CocoaInitializer.h"
@@ -71,6 +72,7 @@
HWForm::HWForm(QWidget *parent)
: QMainWindow(parent), pnetserver(0), pRegisterServer(0), editedTeam(0), hwnet(0)
{
+ xfire_init();
gameSettings = new QSettings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat);
frontendEffects = gameSettings->value("video/frontendeffects", true).toBool();
@@ -205,6 +207,53 @@
GoBack();
}
+void HWForm::updateXfire(void)
+{
+// xfire_setvalue(XFIRE_ROOM, "None");
+// xfire_setvalue(XFIRE_GAMEMODE, "Multiplayer");
+// xfire_setvalue(XFIRE_NICKNAME, ui.pageOptions->editNetNick->text().toAscii());
+// if(!host.compare("netserver.hedgewars.org"))
+// xfire_setvalue(XFIRE_SERVER, "Official server");
+// else
+// xfire_setvalue(XFIRE_SERVER, "Custom or local LAN server");
+ if(hwnet)
+ {
+ xfire_setvalue(XFIRE_SERVER, !hwnet->getHost().compare("netserver.hedgewars.org:46631") ? "Official server" : hwnet->getHost().toAscii());
+ switch(hwnet->getClientState())
+ {
+ case 1: // Connecting
+ xfire_setvalue(XFIRE_STATUS, "Connecting");
+ xfire_setvalue(XFIRE_NICKNAME, "-");
+ xfire_setvalue(XFIRE_ROOM, "-");
+ case 2: // In lobby
+ xfire_setvalue(XFIRE_STATUS, "Online");
+ xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
+ xfire_setvalue(XFIRE_ROOM, "In game lobby");
+ break;
+ case 3: // In room
+ xfire_setvalue(XFIRE_STATUS, "Online");
+ xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
+ xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (waiting for players)").toAscii());
+ break;
+ case 5: // In game
+ xfire_setvalue(XFIRE_STATUS, "Online");
+ xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
+ xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (playing or spectating)").toAscii());
+ break;
+ default:
+ break;
+ }
+ }
+ else
+ {
+ xfire_setvalue(XFIRE_STATUS, "Offline");
+ xfire_setvalue(XFIRE_NICKNAME, "-");
+ xfire_setvalue(XFIRE_ROOM, "-");
+ xfire_setvalue(XFIRE_SERVER, "-");
+ }
+ xfire_update();
+}
+
void HWForm::onFrontendFullscreen(bool value)
{
if (value)
@@ -359,6 +408,7 @@
void HWForm::OnPageShown(quint8 id, quint8 lastid)
{
+ updateXfire();
if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETGAME) {
QStringList tmNames = config->GetTeamsList();
TeamSelWidget* curTeamSelWidget;
@@ -891,6 +941,7 @@
void HWForm::closeEvent(QCloseEvent *event)
{
+ xfire_free();
config->SaveOptions();
event->accept();
}
--- a/QTfrontend/hwform.h Wed Feb 17 17:38:32 2010 +0000
+++ b/QTfrontend/hwform.h Wed Feb 17 19:50:22 2010 +0000
@@ -55,6 +55,7 @@
SDLInteraction sdli;
GameUIConfig * config;
QSettings * gameSettings; // Same file GameUIConfig points to but without the baggage. Needs sync() calls if you want to get GameUIConfig changes though
+ void updateXfire();
private slots:
void GoToMain();
--- a/QTfrontend/newnetclient.cpp Wed Feb 17 17:38:32 2010 +0000
+++ b/QTfrontend/newnetclient.cpp Wed Feb 17 19:50:22 2010 +0000
@@ -67,6 +67,7 @@
void HWNewNet::Connect(const QString & hostName, quint16 port, const QString & nick)
{
mynick = nick.isEmpty() ? QLineEdit::tr("unnamed") : nick;
+ myhost = hostName + QString(":%1").arg(port);
NetSocket.connectToHost(hostName, port);
}
@@ -87,6 +88,8 @@
return;
}
+ myroom = room;
+
RawSendNet(QString("CREATE_ROOM%1%2").arg(delimeter).arg(room));
isChief = true;
}
@@ -99,6 +102,8 @@
return;
}
+ myroom = room;
+
RawSendNet(QString("JOIN_ROOM%1%2").arg(delimeter).arg(room));
isChief = false;
}
@@ -621,6 +626,26 @@
RawSendNet(QString("LIST"));
}
+int HWNewNet::getClientState()
+{
+ return netClientState;
+}
+
+QString HWNewNet::getNick()
+{
+ return mynick;
+}
+
+QString HWNewNet::getRoom()
+{
+ return myroom;
+}
+
+QString HWNewNet::getHost()
+{
+ return myhost;
+}
+
bool HWNewNet::isRoomChief()
{
return isChief;
--- a/QTfrontend/newnetclient.h Wed Feb 17 17:38:32 2010 +0000
+++ b/QTfrontend/newnetclient.h Wed Feb 17 19:50:22 2010 +0000
@@ -44,7 +44,11 @@
void Disconnect();
bool isRoomChief();
bool isInRoom();
-
+ int getClientState();
+ QString getNick();
+ QString getRoom();
+ QString getHost();
+
private:
GameUIConfig* config;
GameCFGWidget* m_pGameCFGWidget;
@@ -52,6 +56,8 @@
bool isChief;
QString mynick;
+ QString myroom;
+ QString myhost;
QTcpSocket NetSocket;
QString seed;
bool m_game_connected;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/xfire.cpp Wed Feb 17 19:50:22 2010 +0000
@@ -0,0 +1,82 @@
+/*
+ * Hedgewars Xfire integration
+ * Copyright (c) 2010 Mario Liebisch <mario.liebisch AT googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include <string>
+#include <stdio.h>
+
+#include "xfire.h"
+#include "xfiregameclient.h"
+
+// use_xfire: stores if xfire is loaded and functions should do something at all
+bool use_xfire = false;
+char *keys[XFIRE_KEY_COUNT];
+char *values[XFIRE_KEY_COUNT];
+
+// xfire_init(): used to initialize all variables and set their default values
+void xfire_init(void)
+{
+ if(use_xfire)
+ return;
+ use_xfire = XfireIsLoaded() == 1;
+
+ if(!use_xfire)
+ return;
+
+ for(int i = 0; i < XFIRE_KEY_COUNT; i++)
+ {
+ keys[i] = new char[256];
+ values[i] = new char[256];
+ strcpy(keys[i], "");
+ strcpy(values[i], "");
+ }
+
+ strcpy(keys[XFIRE_NICKNAME], "Nickname");
+ strcpy(keys[XFIRE_ROOM], "Room");
+ strcpy(keys[XFIRE_SERVER], "Server");
+ strcpy(keys[XFIRE_STATUS], "Status");
+ xfire_update();
+}
+
+// xfire_free(): used to free up ressources used etc.
+void xfire_free(void)
+{
+ if(!use_xfire)
+ return;
+
+ for(int i = 0; i < XFIRE_KEY_COUNT; i++)
+ {
+ delete [] keys[i];
+ delete [] values[i];
+ }
+}
+
+// xfire_setvalue(): set a specific value
+void xfire_setvalue(const XFIRE_KEYS status, const char *value)
+{
+ if(!use_xfire || strlen(value) > 255)
+ return;
+ strcpy(values[status], value);
+}
+
+// xfire_update(): submits current values to the xfire app
+void xfire_update(void)
+{
+ if(!use_xfire)
+ return;
+ XfireSetCustomGameDataA(XFIRE_KEY_COUNT, (const char**)keys, (const char**)values);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/xfire.h Wed Feb 17 19:50:22 2010 +0000
@@ -0,0 +1,48 @@
+/*
+ * Hedgewars Xfire integration
+ * Copyright (c) 2010 Mario Liebisch <mario.liebisch AT googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifndef XFIRE_H
+#define XFIRE_H
+
+#ifdef _WIN32
+// TODO: Move to CMAKE
+#define USE_XFIRE
+#endif
+
+enum XFIRE_KEYS
+{
+ XFIRE_STATUS = 0,
+ XFIRE_NICKNAME,
+ XFIRE_SERVER,
+ XFIRE_ROOM,
+ XFIRE_KEY_COUNT,
+};
+
+#ifdef USE_XFIRE
+void xfire_init(void);
+void xfire_free(void);
+void xfire_setvalue(const XFIRE_KEYS status, const char *value);
+void xfire_update(void);
+#else
+#define xfire_init() /*xfire_init()*/
+#define xfire_free() /*xfire_free()*/
+#define xfire_setvalue(a, b) /*xfire_setvalue(a, b)*/
+#define xfire_update() /*xfire_update()*/
+#endif
+
+#endif // XFIRE_H
--- a/project_files/hedgewars.pro Wed Feb 17 17:38:32 2010 +0000
+++ b/project_files/hedgewars.pro Wed Feb 17 19:50:22 2010 +0000
@@ -32,7 +32,7 @@
../QTfrontend/team.h ../QTfrontend/teamselect.h \
../QTfrontend/teamselhelper.h ../QTfrontend/togglebutton.h \
../QTfrontend/ui_hwform.h ../QTfrontend/vertScrollArea.h \
- ../QTfrontend/weaponItem.h
+ ../QTfrontend/weaponItem.h ../QTFrontend/xfire.h
SOURCES += ../QTfrontend/SDLs.cpp ../QTfrontend/SquareLabel.cpp \
../QTfrontend/about.cpp ../QTfrontend/ammoSchemeModel.cpp \
@@ -55,6 +55,7 @@
../QTfrontend/teamselect.cpp ../QTfrontend/teamselhelper.cpp \
../QTfrontend/togglebutton.cpp ../QTfrontend/ui_hwform.cpp \
../QTfrontend/vertScrollArea.cpp ../QTfrontend/weaponItem.cpp \
+ ../QTfrontend/xfire.cpp
TRANSLATIONS += ../share/hedgewars/Data/Locale/hedgewars_bg.ts
TRANSLATIONS += ../share/hedgewars/Data/Locale/hedgewars_de.ts