# HG changeset patch # User unc0rr # Date 1414182670 -14400 # Node ID 47a6231f1fc1db34b5763686823f568b7638dde6 # Parent c58db813240b5667cf9ffd8c960fbdca3877a3f8 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs) diff -r c58db813240b -r 47a6231f1fc1 hedgewars/hwLibrary.pas --- a/hedgewars/hwLibrary.pas Mon Oct 20 22:55:12 2014 +0400 +++ b/hedgewars/hwLibrary.pas Sat Oct 25 00:31:10 2014 +0400 @@ -157,6 +157,8 @@ freeThemesList, getThemeIcon, getTeamsList, + tryAddTeam, + tryRemoveTeam, LoadLocaleWrapper, HW_versionInfo, HW_versionString, diff -r c58db813240b -r 47a6231f1fc1 hedgewars/uFLGameConfig.pas --- a/hedgewars/uFLGameConfig.pas Mon Oct 20 22:55:12 2014 +0400 +++ b/hedgewars/uFLGameConfig.pas Sat Oct 25 00:31:10 2014 +0400 @@ -11,6 +11,9 @@ procedure setSeed(seed: PChar); cdecl; function getSeed: PChar; cdecl; +procedure tryAddTeam(teamName: PChar); +procedure tryRemoveTeam(teamName: PChar); + implementation uses uFLIPC, hwengine, uFLUtils, uFLTeams; @@ -153,4 +156,26 @@ registerIPCCallback(nil, @engineMessageCallback) end; + +procedure tryAddTeam(teamName: PChar); +var msg: ansistring; +begin + msg:= '0' + #10 + teamName; + + guiCallbackFunction(guiCallbackPointer, mtAddPlayingTeam, @msg[1], length(msg)); + + msg:= teamName; + + guiCallbackFunction(guiCallbackPointer, mtRemoveTeam, @msg[1], length(msg)) +end; + +procedure tryRemoveTeam(teamName: PChar); +var msg: ansistring; +begin + msg:= teamName; + + guiCallbackFunction(guiCallbackPointer, mtRemovePlayingTeam, @msg[1], length(msg)); + guiCallbackFunction(guiCallbackPointer, mtAddTeam, @msg[1], length(msg)) +end; + end. diff -r c58db813240b -r 47a6231f1fc1 hedgewars/uFLTypes.pas --- a/hedgewars/uFLTypes.pas Mon Oct 20 22:55:12 2014 +0400 +++ b/hedgewars/uFLTypes.pas Sat Oct 25 00:31:10 2014 +0400 @@ -2,7 +2,7 @@ interface type - TMessageType = (mtPreview); + TMessageType = (mtPreview, mtAddPlayingTeam, mtRemovePlayingTeam, mtAddTeam, mtRemoveTeam); TIPCMessage = record str: shortstring; diff -r c58db813240b -r 47a6231f1fc1 qmlFrontend/flib.h --- a/qmlFrontend/flib.h Mon Oct 20 22:55:12 2014 +0400 +++ b/qmlFrontend/flib.h Sat Oct 25 00:31:10 2014 +0400 @@ -9,6 +9,10 @@ enum MessageType { MSG_PREVIEW + , MSG_ADDPLAYINGTEAM + , MSG_REMOVEPLAYINGTEAM + , MSG_ADDTEAM + , MSG_REMOVETEAM }; typedef union string255_ @@ -36,6 +40,8 @@ typedef uint32_t getThemeIcon_t(char * theme, char * buffer, uint32_t size); typedef char **getTeamsList_t(); +typedef void tryAddTeam_t(const char * seed); +typedef void tryRemoveTeam_t(const char * seed); #ifdef __cplusplus } diff -r c58db813240b -r 47a6231f1fc1 qmlFrontend/hwengine.cpp --- a/qmlFrontend/hwengine.cpp Mon Oct 20 22:55:12 2014 +0400 +++ b/qmlFrontend/hwengine.cpp Sat Oct 25 00:31:10 2014 +0400 @@ -21,6 +21,8 @@ freeThemesList_t *flibFreeThemesList; getThemeIcon_t *flibGetThemeIcon; getTeamsList_t *flibGetTeamsList; + tryAddTeam_t * flibTryAddTeam; + tryRemoveTeam_t * flibTryRemoveTeam; } Q_DECLARE_METATYPE(MessageType); @@ -50,6 +52,8 @@ flibGetThemeIcon = (getThemeIcon_t*) hwlib.resolve("getThemeIcon"); flibGetTeamsList = (getTeamsList_t*) hwlib.resolve("getTeamsList"); + flibTryAddTeam = (tryAddTeam_t*) hwlib.resolve("tryAddTeam"); + flibTryRemoveTeam = (tryRemoveTeam_t*) hwlib.resolve("tryRemoveTeam"); flibInit("/usr/home/unC0Rr/Sources/Hedgewars/Hedgewars-GC/share/hedgewars/Data", "/usr/home/unC0Rr/.hedgewars"); flibRegisterGUIMessagesCallback(this, &guiMessagesCallback); @@ -95,7 +99,7 @@ void HWEngine::guiMessagesCallback(void *context, MessageType mt, const char * msg, uint32_t len) { HWEngine * obj = (HWEngine *)context; - QByteArray b = QByteArray::fromRawData(msg, len); + QByteArray b = QByteArray(msg, len); qDebug() << "FLIPC in" << b.size() << b; @@ -106,12 +110,30 @@ { switch(mt) { - case MSG_PREVIEW: + case MSG_PREVIEW: { PreviewImageProvider * preview = (PreviewImageProvider *)m_engine->imageProvider(QLatin1String("preview")); preview->setPixmap(msg); emit previewImageChanged(); break; } + case MSG_ADDPLAYINGTEAM: { + QStringList l = QString::fromUtf8(msg).split('\n'); + emit playingTeamAdded(l[1], l[0].toInt(), true); + break; + } + case MSG_REMOVEPLAYINGTEAM: { + emit playingTeamRemoved(msg); + break; + } + case MSG_ADDTEAM: { + emit localTeamAdded(msg, 0); + break; + } + case MSG_REMOVETEAM: { + emit localTeamRemoved(msg); + break; + } + } } QString HWEngine::currentSeed() @@ -143,3 +165,13 @@ emit localTeamAdded(team, 0); } } + +void HWEngine::tryAddTeam(const QString &teamName) +{ + flibTryAddTeam(teamName.toUtf8().constData()); +} + +void HWEngine::tryRemoveTeam(const QString &teamName) +{ + flibTryRemoveTeam(teamName.toUtf8().constData()); +} diff -r c58db813240b -r 47a6231f1fc1 qmlFrontend/hwengine.h --- a/qmlFrontend/hwengine.h Mon Oct 20 22:55:12 2014 +0400 +++ b/qmlFrontend/hwengine.h Sat Oct 25 00:31:10 2014 +0400 @@ -22,11 +22,18 @@ Q_INVOKABLE void runQuickGame(); Q_INVOKABLE QString currentSeed(); Q_INVOKABLE void getTeamsList(); - + + Q_INVOKABLE void tryAddTeam(const QString & teamName); + Q_INVOKABLE void tryRemoveTeam(const QString & teamName); + signals: void previewImageChanged(); void localTeamAdded(const QString & teamName, int aiLevel); - + void localTeamRemoved(const QString & teamName); + + void playingTeamAdded(const QString & teamName, int aiLevel, bool isLocal); + void playingTeamRemoved(const QString & teamName); + public slots: private: diff -r c58db813240b -r 47a6231f1fc1 qmlFrontend/qml/qmlFrontend/GameConfig.qml --- a/qmlFrontend/qml/qmlFrontend/GameConfig.qml Mon Oct 20 22:55:12 2014 +0400 +++ b/qmlFrontend/qml/qmlFrontend/GameConfig.qml Sat Oct 25 00:31:10 2014 +0400 @@ -83,7 +83,7 @@ clip: true model: ListModel { - id: localTeamsModel + id: playingTeamsModel } delegate: Rectangle { @@ -97,11 +97,68 @@ Row { Text { text: name } } + + MouseArea { + z: 1 + anchors.fill: parent + onClicked: HWEngine.tryRemoveTeam(name) + } + } + + Connections { + target: HWEngine + onPlayingTeamAdded: playingTeamsModel.append({"aiLevel": aiLevel, "name": teamName, "local": isLocal}) + onPlayingTeamRemoved: { + var i = playingTeamsModel.count - 1; + while ((i >= 0) && (playingTeamsModel.get(i).name !== teamName)) --i + + if(i >= 0) playingTeamsModel.remove(i, 1) + } + } + } + + ListView { + id: localTeamsList + x: 440 + y: 224 + width: 100 + height: 192 + highlight: Rectangle { color: "#eaea00"; radius: 4 } + focus: true + clip: true + + model: ListModel { + id: localTeamsModel + } + + delegate: Rectangle { + id: localTeamDelegate + height: 24 + width: parent.width + radius: 8 + border.width: 2 + border.color: "#eaea00" + + Row { + Text { text: name } + } + + MouseArea { + z: 1 + anchors.fill: parent + onClicked: HWEngine.tryAddTeam(name) + } } Connections { target: HWEngine onLocalTeamAdded: localTeamsModel.append({"aiLevel": aiLevel, "name": teamName}) + onLocalTeamRemoved: { + var i = localTeamsModel.count - 1; + while ((i >= 0) && (localTeamsModel.get(i).name !== teamName)) --i + + if(i >= 0) localTeamsModel.remove(i, 1) + } } }