qmlFrontend/hwengine.cpp
author unc0rr
Sun, 17 Dec 2017 21:09:59 +0100
branchqmlfrontend
changeset 12856 95d903b976d0
parent 12855 1b2b84315d27
permissions -rw-r--r--
Start removing flib functionality
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     1
#include <QLibrary>
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     2
#include <QtQml>
10404
1baaab44a0b2 - Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents: 10402
diff changeset
     3
#include <QDebug>
10420
unc0rr
parents: 10418
diff changeset
     4
#include <QPainter>
10424
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
     5
#include <QUuid>
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     6
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     7
#include "hwengine.h"
10420
unc0rr
parents: 10418
diff changeset
     8
#include "previewimageprovider.h"
10436
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
     9
#include "themeiconprovider.h"
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    10
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    11
extern "C" {
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    12
    RunEngine_t *flibRunEngine;
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10896
diff changeset
    13
    registerUIMessagesCallback_t *flibRegisterUIMessagesCallback;
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    14
    setSeed_t *flibSetSeed;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    15
    getSeed_t *flibGetSeed;
10456
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
    16
    setTheme_t *flibSetTheme;
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
    17
    setScript_t *flibSetScript;
10819
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10616
diff changeset
    18
    setScheme_t *flibSetScheme;
10888
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
    19
    setAmmo_t *flibSetAmmo;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    20
    getPreview_t *flibGetPreview;
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    21
    runQuickGame_t *flibRunQuickGame;
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10444
diff changeset
    22
    runLocalGame_t *flibRunLocalGame;
10416
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
    23
    flibInit_t *flibInit;
10424
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    24
    flibFree_t *flibFree;
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
    25
    resetGameConfig_t * flibResetGameConfig;
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
    26
    getThemesList_t *flibGetThemesList;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
    27
    freeThemesList_t *flibFreeThemesList;
10436
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    28
    getThemeIcon_t *flibGetThemeIcon;
10517
844bd43db47a getScriptsList implementation
unc0rr
parents: 10456
diff changeset
    29
    getScriptsList_t *flibGetScriptsList;
10616
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
    30
    getSchemesList_t *flibGetSchemesList;
10888
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
    31
    getAmmosList_t *flibGetAmmosList;
10442
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
    32
    getTeamsList_t *flibGetTeamsList;
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
    33
    tryAddTeam_t * flibTryAddTeam;
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
    34
    tryRemoveTeam_t * flibTryRemoveTeam;
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
    35
    changeTeamColor_t * flibChangeTeamColor;
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents: 10888
diff changeset
    36
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents: 10888
diff changeset
    37
    connectOfficialServer_t * flibConnectOfficialServer;
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10896
diff changeset
    38
    passNetData_t * flibPassNetData;
11842
93e6c401cc3d Preparation to sending engine messages to net.
unc0rr
parents: 11827
diff changeset
    39
    passToNet_t * flibPassToNet;
11434
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
    40
    passFlibEvent_t * flibPassFlibEvent;
11416
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    41
    sendChatLine_t * flibSendChatLine;
11423
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
    42
    joinRoom_t * flibJoinRoom;
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
    43
    partRoom_t * flibPartRoom;
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    44
}
10420
unc0rr
parents: 10418
diff changeset
    45
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
    46
Q_DECLARE_METATYPE(MessageType)
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    47
10420
unc0rr
parents: 10418
diff changeset
    48
HWEngine::HWEngine(QQmlEngine *engine, QObject *parent) :
unc0rr
parents: 10418
diff changeset
    49
    QObject(parent),
unc0rr
parents: 10418
diff changeset
    50
    m_engine(engine)
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    51
{
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    52
    qRegisterMetaType<MessageType>("MessageType");
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    53
11439
dd1350a475d9 Fix build for windows + other small fixes
unC0Rr
parents: 11437
diff changeset
    54
#ifdef Q_OS_WIN    
dd1350a475d9 Fix build for windows + other small fixes
unC0Rr
parents: 11437
diff changeset
    55
    QLibrary hwlib("./libhwengine.dll");
dd1350a475d9 Fix build for windows + other small fixes
unC0Rr
parents: 11437
diff changeset
    56
#else
10404
1baaab44a0b2 - Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents: 10402
diff changeset
    57
    QLibrary hwlib("./libhwengine.so");
11439
dd1350a475d9 Fix build for windows + other small fixes
unC0Rr
parents: 11437
diff changeset
    58
#endif
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    59
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    60
    if(!hwlib.load())
10404
1baaab44a0b2 - Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents: 10402
diff changeset
    61
        qWarning() << "Engine library not found" << hwlib.errorString();
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    62
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    63
    flibRunEngine = (RunEngine_t*) hwlib.resolve("RunEngine");
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10896
diff changeset
    64
    flibRegisterUIMessagesCallback = (registerUIMessagesCallback_t*) hwlib.resolve("registerUIMessagesCallback");
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    65
    flibGetSeed = (getSeed_t*) hwlib.resolve("getSeed");
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    66
    flibGetPreview = (getPreview_t*) hwlib.resolve("getPreview");
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    67
    flibRunQuickGame = (runQuickGame_t*) hwlib.resolve("runQuickGame");
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10444
diff changeset
    68
    flibRunLocalGame = (runLocalGame_t*) hwlib.resolve("runLocalGame");
10416
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
    69
    flibInit = (flibInit_t*) hwlib.resolve("flibInit");
10424
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    70
    flibFree = (flibFree_t*) hwlib.resolve("flibFree");
10416
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
    71
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
    72
    flibSetSeed = (setSeed_t*) hwlib.resolve("setSeed");
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
    73
    flibSetTheme = (setTheme_t*) hwlib.resolve("setTheme");
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
    74
    flibSetScript = (setScript_t*) hwlib.resolve("setScript");
10819
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10616
diff changeset
    75
    flibSetScheme = (setScheme_t*) hwlib.resolve("setScheme");
10888
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
    76
    flibSetAmmo = (setAmmo_t*) hwlib.resolve("setAmmo");
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
    77
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
    78
    flibGetThemesList = (getThemesList_t*) hwlib.resolve("getThemesList");
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
    79
    flibFreeThemesList = (freeThemesList_t*) hwlib.resolve("freeThemesList");
10436
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    80
    flibGetThemeIcon = (getThemeIcon_t*) hwlib.resolve("getThemeIcon");
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
    81
10517
844bd43db47a getScriptsList implementation
unc0rr
parents: 10456
diff changeset
    82
    flibGetScriptsList = (getScriptsList_t*) hwlib.resolve("getScriptsList");
10616
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
    83
    flibGetSchemesList = (getSchemesList_t*) hwlib.resolve("getSchemesList");
10888
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
    84
    flibGetAmmosList = (getAmmosList_t*) hwlib.resolve("getAmmosList");
10517
844bd43db47a getScriptsList implementation
unc0rr
parents: 10456
diff changeset
    85
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
    86
    flibResetGameConfig = (resetGameConfig_t*) hwlib.resolve("resetGameConfig");
10442
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
    87
    flibGetTeamsList = (getTeamsList_t*) hwlib.resolve("getTeamsList");
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
    88
    flibTryAddTeam = (tryAddTeam_t*) hwlib.resolve("tryAddTeam");
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
    89
    flibTryRemoveTeam = (tryRemoveTeam_t*) hwlib.resolve("tryRemoveTeam");
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
    90
    flibChangeTeamColor = (changeTeamColor_t*) hwlib.resolve("changeTeamColor");
10442
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
    91
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents: 10888
diff changeset
    92
    flibConnectOfficialServer = (connectOfficialServer_t*) hwlib.resolve("connectOfficialServer");
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10896
diff changeset
    93
    flibPassNetData = (passNetData_t*) hwlib.resolve("passNetData");
11842
93e6c401cc3d Preparation to sending engine messages to net.
unc0rr
parents: 11827
diff changeset
    94
    flibPassToNet = (passToNet_t*) hwlib.resolve("passToNet");
11434
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
    95
    flibPassFlibEvent = (passFlibEvent_t*) hwlib.resolve("passFlibEvent");
11416
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    96
    flibSendChatLine = (sendChatLine_t*) hwlib.resolve("sendChatLine");
11423
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
    97
    flibJoinRoom = (joinRoom_t*) hwlib.resolve("joinRoom");
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
    98
    flibPartRoom = (partRoom_t*) hwlib.resolve("partRoom");
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents: 10888
diff changeset
    99
12855
1b2b84315d27 Merge default. This branch is up-to-date and code is working.
unc0rr
parents: 11842
diff changeset
   100
    flibInit("/usr/home/unC0Rr/Sources/Hedgewars/MainRepo/share/hedgewars/Data", "/usr/home/unC0Rr/.hedgewars");
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10896
diff changeset
   101
    flibRegisterUIMessagesCallback(this, &guiMessagesCallback);
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   102
10436
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
   103
    ThemeIconProvider * themeIcon = (ThemeIconProvider *)m_engine->imageProvider(QLatin1String("theme"));
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
   104
    themeIcon->setFileContentsFunction(flibGetThemeIcon);
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
   105
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   106
    fillModels();
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   107
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   108
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   109
HWEngine::~HWEngine()
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   110
{
10424
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
   111
    flibFree();
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   112
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   113
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   114
void HWEngine::getPreview()
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   115
{
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   116
    flibSetSeed(QUuid::createUuid().toString().toLatin1());
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   117
    flibGetPreview();
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   118
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   119
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   120
void HWEngine::runQuickGame()
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   121
{
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   122
    flibSetSeed(QUuid::createUuid().toString().toLatin1());
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   123
    flibRunQuickGame();
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   124
}
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   125
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10444
diff changeset
   126
void HWEngine::runLocalGame()
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10444
diff changeset
   127
{
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10444
diff changeset
   128
    flibRunLocalGame();
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10444
diff changeset
   129
}
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10444
diff changeset
   130
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10444
diff changeset
   131
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   132
static QObject *hwengine_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   133
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   134
    Q_UNUSED(scriptEngine)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   135
10420
unc0rr
parents: 10418
diff changeset
   136
    HWEngine *hwengine = new HWEngine(engine);
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   137
    return hwengine;
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   138
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   139
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   140
void HWEngine::exposeToQML()
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   141
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   142
    qDebug("HWEngine::exposeToQML");
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   143
    qmlRegisterSingletonType<HWEngine>("Hedgewars.Engine", 1, 0, "HWEngine", hwengine_singletontype_provider);
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   144
}
10416
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
   145
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
   146
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   147
void HWEngine::guiMessagesCallback(void *context, MessageType mt, const char * msg, uint32_t len)
10420
unc0rr
parents: 10418
diff changeset
   148
{
unc0rr
parents: 10418
diff changeset
   149
    HWEngine * obj = (HWEngine *)context;
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   150
    QByteArray b = QByteArray(msg, len);
10420
unc0rr
parents: 10418
diff changeset
   151
11434
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
   152
    //qDebug() << "FLIPC in" << mt << " size = " << b.size();
10420
unc0rr
parents: 10418
diff changeset
   153
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   154
    QMetaObject::invokeMethod(obj, "engineMessageHandler", Qt::QueuedConnection, Q_ARG(MessageType, mt), Q_ARG(QByteArray, b));
10416
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
   155
}
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
   156
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   157
void HWEngine::engineMessageHandler(MessageType mt, const QByteArray &msg)
10416
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
   158
{
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   159
    switch(mt)
10426
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
   160
    {
11434
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
   161
    case MSG_RENDERINGPREVIEW: {
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
   162
        emit previewIsRendering();
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
   163
        break;
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
   164
    }
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   165
    case MSG_PREVIEW: {
10426
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
   166
        PreviewImageProvider * preview = (PreviewImageProvider *)m_engine->imageProvider(QLatin1String("preview"));
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
   167
        preview->setPixmap(msg);
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
   168
        emit previewImageChanged();
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   169
        break;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
   170
    }
11827
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 11443
diff changeset
   171
    case MSG_PREVIEWHOGCOUNT: {
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 11443
diff changeset
   172
        emit previewHogCountChanged((quint8)msg.data()[0]);
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 11443
diff changeset
   173
        break;
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 11443
diff changeset
   174
    }
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   175
    case MSG_ADDPLAYINGTEAM: {
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   176
        QStringList l = QString::fromUtf8(msg).split('\n');
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   177
        emit playingTeamAdded(l[1], l[0].toInt(), true);
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   178
        break;
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   179
    }
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   180
    case MSG_REMOVEPLAYINGTEAM: {
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   181
        emit playingTeamRemoved(QString::fromUtf8(msg));
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   182
        break;
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   183
    }
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   184
    case MSG_ADDTEAM: {
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   185
        emit localTeamAdded(QString::fromUtf8(msg), 0);
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   186
        break;
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   187
    }
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   188
    case MSG_REMOVETEAM: {
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   189
        emit localTeamRemoved(QString::fromUtf8(msg));
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   190
        break;
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   191
    }
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   192
    case MSG_TEAMCOLOR: {
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   193
        QStringList l = QString::fromUtf8(msg).split('\n');
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   194
        emit teamColorChanged(l[0], QColor::fromRgba(l[1].toInt()).name());
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   195
        break;
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   196
    }
11443
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11440
diff changeset
   197
    case MSG_HEDGEHOGSNUMBER: {
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11440
diff changeset
   198
        QStringList l = QString::fromUtf8(msg).split('\n');
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11440
diff changeset
   199
        emit hedgehogsNumberChanged(l[0], l[1].toInt());
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11440
diff changeset
   200
        break;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11440
diff changeset
   201
    }
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10896
diff changeset
   202
    case MSG_NETDATA: {
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10896
diff changeset
   203
        flibPassNetData(msg.constData());
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   204
        break;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   205
    }
11842
93e6c401cc3d Preparation to sending engine messages to net.
unc0rr
parents: 11827
diff changeset
   206
    case MSG_TONET: {
93e6c401cc3d Preparation to sending engine messages to net.
unc0rr
parents: 11827
diff changeset
   207
        flibPassToNet(msg.constData(), msg.size());
93e6c401cc3d Preparation to sending engine messages to net.
unc0rr
parents: 11827
diff changeset
   208
        break;
93e6c401cc3d Preparation to sending engine messages to net.
unc0rr
parents: 11827
diff changeset
   209
    }
11434
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
   210
    case MSG_FLIBEVENT: {
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
   211
        flibPassFlibEvent(msg.constData());
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
   212
        break;
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
   213
    }
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   214
    case MSG_CONNECTED: {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   215
        emit netConnected();
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   216
        break;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   217
    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   218
    case MSG_DISCONNECTED: {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   219
        emit netDisconnected(QString::fromUtf8(msg));
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   220
        break;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   221
    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   222
    case MSG_ADDLOBBYCLIENT: {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   223
        emit lobbyClientAdded(QString::fromUtf8(msg));
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   224
        break;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   225
    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   226
    case MSG_REMOVELOBBYCLIENT: {
11423
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
   227
        QStringList l = QString::fromUtf8(msg).split('\n');
11437
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11435
diff changeset
   228
        if(l.size() < 2)
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11435
diff changeset
   229
            l.append("");
11423
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
   230
        emit lobbyClientRemoved(l[0], l[1]);
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   231
        break;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   232
    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   233
    case MSG_LOBBYCHATLINE: {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   234
        QStringList l = QString::fromUtf8(msg).split('\n');
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   235
        emit lobbyChatLine(l[0], l[1]);
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   236
        break;
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10896
diff changeset
   237
    }
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   238
    case MSG_ADDROOMCLIENT: {
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   239
        emit roomClientAdded(QString::fromUtf8(msg));
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   240
        break;
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   241
    }
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   242
    case MSG_REMOVEROOMCLIENT: {
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   243
        QStringList l = QString::fromUtf8(msg).split('\n');
11435
28fb618d99c4 Prevent crashing from empty PART reason
unc0rr
parents: 11434
diff changeset
   244
        if(l.size() < 2)
28fb618d99c4 Prevent crashing from empty PART reason
unc0rr
parents: 11434
diff changeset
   245
            l.append("");
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   246
        emit roomClientRemoved(l[0], l[1]);
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   247
        break;
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   248
    }
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   249
    case MSG_ROOMCHATLINE: {
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   250
        QStringList l = QString::fromUtf8(msg).split('\n');
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   251
        emit roomChatLine(l[0], l[1]);
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   252
        break;
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   253
    }
11418
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11416
diff changeset
   254
    case MSG_ADDROOM: {
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11416
diff changeset
   255
        QStringList l = QString::fromUtf8(msg).split('\n');
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11416
diff changeset
   256
        emit roomAdded(0, l[1], l[2].toInt(), l[3].toInt(), l[4], l[5], l[6], l[7], l[8]);
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11416
diff changeset
   257
        break;
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11416
diff changeset
   258
    }
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11416
diff changeset
   259
    case MSG_UPDATEROOM: {
11422
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
   260
        QStringList l = QString::fromUtf8(msg).split('\n');
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
   261
        emit roomUpdated(l[0], 0, l[2], l[3].toInt(), l[4].toInt(), l[5], l[6], l[7], l[8], l[9]);
11418
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11416
diff changeset
   262
        break;
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11416
diff changeset
   263
    }
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11416
diff changeset
   264
    case MSG_REMOVEROOM: {
11419
8a5cc31483c6 - Handle ROOM DEL
unc0rr
parents: 11418
diff changeset
   265
        emit roomRemoved(QString::fromUtf8(msg));
11418
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11416
diff changeset
   266
        break;
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11416
diff changeset
   267
    }
11423
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
   268
    case MSG_ERROR: {
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
   269
        emit errorMessage(QString::fromUtf8(msg));
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
   270
        break;
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
   271
    }
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
   272
    case MSG_WARNING: {
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
   273
        emit warningMessage(QString::fromUtf8(msg));
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
   274
        break;
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
   275
    }
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   276
    case MSG_MOVETOLOBBY: {
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   277
        emit movedToLobby();
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   278
        break;
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   279
    }
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   280
    case MSG_MOVETOROOM: {
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   281
        emit movedToRoom();
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   282
        break;
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   283
    }
11430
f88b3948adf3 UI knowns local player nickname
unc0rr
parents: 11424
diff changeset
   284
    case MSG_NICKNAME: {
f88b3948adf3 UI knowns local player nickname
unc0rr
parents: 11424
diff changeset
   285
        m_myNickname = QString::fromUtf8(msg);
f88b3948adf3 UI knowns local player nickname
unc0rr
parents: 11424
diff changeset
   286
        break;
f88b3948adf3 UI knowns local player nickname
unc0rr
parents: 11424
diff changeset
   287
    }
11431
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11430
diff changeset
   288
    case MSG_SEED: {
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11430
diff changeset
   289
        emit seedChanged(QString::fromUtf8(msg));
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11430
diff changeset
   290
        break;
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11430
diff changeset
   291
    }
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11430
diff changeset
   292
    case MSG_THEME: {
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11430
diff changeset
   293
        emit themeChanged(QString::fromUtf8(msg));
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11430
diff changeset
   294
        break;
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11430
diff changeset
   295
    }
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11430
diff changeset
   296
    case MSG_SCRIPT: {
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11430
diff changeset
   297
        emit scriptChanged(QString::fromUtf8(msg));
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11430
diff changeset
   298
        break;
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11430
diff changeset
   299
    }
11433
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   300
    case MSG_FEATURESIZE: {
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   301
        emit featureSizeChanged(msg.toInt());
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   302
        break;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   303
    }
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   304
    case MSG_MAPGEN: {
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   305
        emit mapGenChanged(msg.toInt());
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   306
        break;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   307
    }
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   308
    case MSG_MAP: {
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   309
        emit mapChanged(QString::fromUtf8(msg));
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   310
        break;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   311
    }
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   312
    case MSG_MAZESIZE: {
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   313
        emit mazeSizeChanged(msg.toInt());
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   314
        break;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   315
    }
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   316
    case MSG_TEMPLATE: {
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   317
        emit templateChanged(msg.toInt());
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   318
        break;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11431
diff changeset
   319
    }
11437
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11435
diff changeset
   320
    case MSG_AMMO: {
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11435
diff changeset
   321
        emit ammoChanged(QString::fromUtf8(msg));
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11435
diff changeset
   322
        break;
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11435
diff changeset
   323
    }
11440
330c14f4ba69 Accept scheme from net
unc0rr
parents: 11439
diff changeset
   324
    case MSG_SCHEME: {
330c14f4ba69 Accept scheme from net
unc0rr
parents: 11439
diff changeset
   325
        emit schemeChanged(QString::fromUtf8(msg));
330c14f4ba69 Accept scheme from net
unc0rr
parents: 11439
diff changeset
   326
        break;
330c14f4ba69 Accept scheme from net
unc0rr
parents: 11439
diff changeset
   327
    }
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   328
    }
10424
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
   329
}
10416
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
   330
10424
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
   331
QString HWEngine::currentSeed()
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
   332
{
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   333
    return QString::fromLatin1(flibGetSeed());
10416
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
   334
}
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   335
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   336
void HWEngine::fillModels()
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   337
{
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   338
    QStringList resultModel;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   339
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   340
    char ** themes = flibGetThemesList();
10616
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   341
    for (char **i = themes; *i != NULL; i++)
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   342
        resultModel << QString::fromUtf8(*i);
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   343
    flibFreeThemesList(themes);
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   344
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   345
    m_engine->rootContext()->setContextProperty("themesModel", QVariant::fromValue(resultModel));
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   346
10616
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   347
    // scripts model
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   348
    resultModel.clear();
10616
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   349
    for (char **i = flibGetScriptsList(); *i != NULL; i++)
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   350
        resultModel << QString::fromUtf8(*i);
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   351
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   352
    m_engine->rootContext()->setContextProperty("scriptsModel", QVariant::fromValue(resultModel));
10616
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   353
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   354
    // schemes model
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   355
    resultModel.clear();
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   356
    for (char **i = flibGetSchemesList(); *i != NULL; i++)
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   357
        resultModel << QString::fromUtf8(*i);
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   358
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   359
    m_engine->rootContext()->setContextProperty("schemesModel", QVariant::fromValue(resultModel));
10888
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   360
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   361
    // ammos model
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   362
    resultModel.clear();
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   363
    for (char **i = flibGetAmmosList(); *i != NULL; i++)
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   364
        resultModel << QString::fromUtf8(*i);
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   365
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   366
    m_engine->rootContext()->setContextProperty("ammosModel", QVariant::fromValue(resultModel));
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   367
}
10442
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   368
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   369
void HWEngine::getTeamsList()
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   370
{
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   371
    char ** teams = flibGetTeamsList();
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   372
    for (char **i = teams; *i != NULL; i++) {
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   373
        QString team = QString::fromUtf8(*i);
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   374
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   375
        emit localTeamAdded(team, 0);
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   376
    }
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   377
}
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   378
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   379
void HWEngine::tryAddTeam(const QString &teamName)
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   380
{
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   381
    flibTryAddTeam(teamName.toUtf8().constData());
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   382
}
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   383
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   384
void HWEngine::tryRemoveTeam(const QString &teamName)
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   385
{
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   386
    flibTryRemoveTeam(teamName.toUtf8().constData());
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   387
}
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   388
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   389
void HWEngine::resetGameConfig()
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   390
{
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   391
    flibResetGameConfig();
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   392
}
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   393
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   394
void HWEngine::changeTeamColor(const QString &teamName, int dir)
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   395
{
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   396
    flibChangeTeamColor(teamName.toUtf8().constData(), dir);
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   397
}
10456
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   398
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents: 10888
diff changeset
   399
void HWEngine::connect(const QString &host, quint16 port)
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents: 10888
diff changeset
   400
{
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents: 10888
diff changeset
   401
    flibConnectOfficialServer();
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents: 10888
diff changeset
   402
}
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents: 10888
diff changeset
   403
11416
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
   404
void HWEngine::sendChatMessage(const QString &msg)
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
   405
{
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
   406
    flibSendChatLine(msg.toUtf8().constData());
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
   407
}
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
   408
11423
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
   409
void HWEngine::joinRoom(const QString &roomName)
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
   410
{
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
   411
    flibJoinRoom(roomName.toUtf8().constData());
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
   412
}
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
   413
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   414
void HWEngine::partRoom(const QString &message)
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   415
{
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   416
    flibPartRoom(message.toUtf8().constData());
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   417
}
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   418
11430
f88b3948adf3 UI knowns local player nickname
unc0rr
parents: 11424
diff changeset
   419
QString HWEngine::myNickname()
f88b3948adf3 UI knowns local player nickname
unc0rr
parents: 11424
diff changeset
   420
{
f88b3948adf3 UI knowns local player nickname
unc0rr
parents: 11424
diff changeset
   421
    return m_myNickname;
f88b3948adf3 UI knowns local player nickname
unc0rr
parents: 11424
diff changeset
   422
}
f88b3948adf3 UI knowns local player nickname
unc0rr
parents: 11424
diff changeset
   423
10456
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   424
void HWEngine::setTheme(const QString &theme)
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   425
{
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   426
    flibSetTheme(theme.toUtf8().constData());
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   427
}
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   428
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   429
void HWEngine::setScript(const QString &script)
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   430
{
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   431
    flibSetScript(script.toUtf8().constData());
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   432
}
10819
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10616
diff changeset
   433
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10616
diff changeset
   434
void HWEngine::setScheme(const QString &scheme)
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10616
diff changeset
   435
{
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10616
diff changeset
   436
    flibSetScheme(scheme.toUtf8().constData());
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10616
diff changeset
   437
}
10888
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   438
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   439
void HWEngine::setAmmo(const QString &ammo)
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   440
{
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   441
    flibSetAmmo(ammo.toUtf8().constData());
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   442
}