qmlFrontend/hwengine.cpp
author unc0rr
Thu, 19 Nov 2015 23:04:53 +0300
branchqmlfrontend
changeset 11420 05cf35103206
parent 10951 89a7f617e091
child 11421 78d6b99ddcb0
permissions -rw-r--r--
Lobby page with chat widget(readonly)
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;
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    39
}
10420
unc0rr
parents: 10418
diff changeset
    40
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    41
Q_DECLARE_METATYPE(MessageType);
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    42
10420
unc0rr
parents: 10418
diff changeset
    43
HWEngine::HWEngine(QQmlEngine *engine, QObject *parent) :
unc0rr
parents: 10418
diff changeset
    44
    QObject(parent),
unc0rr
parents: 10418
diff changeset
    45
    m_engine(engine)
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    46
{
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    47
    qRegisterMetaType<MessageType>("MessageType");
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    48
10404
1baaab44a0b2 - Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents: 10402
diff changeset
    49
    QLibrary hwlib("./libhwengine.so");
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    50
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    51
    if(!hwlib.load())
10404
1baaab44a0b2 - Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents: 10402
diff changeset
    52
        qWarning() << "Engine library not found" << hwlib.errorString();
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    53
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    54
    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
    55
    flibRegisterUIMessagesCallback = (registerUIMessagesCallback_t*) hwlib.resolve("registerUIMessagesCallback");
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    56
    flibGetSeed = (getSeed_t*) hwlib.resolve("getSeed");
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    57
    flibGetPreview = (getPreview_t*) hwlib.resolve("getPreview");
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    58
    flibRunQuickGame = (runQuickGame_t*) hwlib.resolve("runQuickGame");
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10444
diff changeset
    59
    flibRunLocalGame = (runLocalGame_t*) hwlib.resolve("runLocalGame");
10416
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
    60
    flibInit = (flibInit_t*) hwlib.resolve("flibInit");
10424
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    61
    flibFree = (flibFree_t*) hwlib.resolve("flibFree");
10416
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
    62
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
    63
    flibSetSeed = (setSeed_t*) hwlib.resolve("setSeed");
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
    64
    flibSetTheme = (setTheme_t*) hwlib.resolve("setTheme");
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
    65
    flibSetScript = (setScript_t*) hwlib.resolve("setScript");
10819
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10616
diff changeset
    66
    flibSetScheme = (setScheme_t*) hwlib.resolve("setScheme");
10888
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
    67
    flibSetAmmo = (setAmmo_t*) hwlib.resolve("setAmmo");
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
    68
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
    69
    flibGetThemesList = (getThemesList_t*) hwlib.resolve("getThemesList");
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
    70
    flibFreeThemesList = (freeThemesList_t*) hwlib.resolve("freeThemesList");
10436
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    71
    flibGetThemeIcon = (getThemeIcon_t*) hwlib.resolve("getThemeIcon");
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
    72
10517
844bd43db47a getScriptsList implementation
unc0rr
parents: 10456
diff changeset
    73
    flibGetScriptsList = (getScriptsList_t*) hwlib.resolve("getScriptsList");
10616
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
    74
    flibGetSchemesList = (getSchemesList_t*) hwlib.resolve("getSchemesList");
10888
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
    75
    flibGetAmmosList = (getAmmosList_t*) hwlib.resolve("getAmmosList");
10517
844bd43db47a getScriptsList implementation
unc0rr
parents: 10456
diff changeset
    76
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
    77
    flibResetGameConfig = (resetGameConfig_t*) hwlib.resolve("resetGameConfig");
10442
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
    78
    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
    79
    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
    80
    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
    81
    flibChangeTeamColor = (changeTeamColor_t*) hwlib.resolve("changeTeamColor");
10442
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
    82
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents: 10888
diff changeset
    83
    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
    84
    flibPassNetData = (passNetData_t*) hwlib.resolve("passNetData");
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents: 10888
diff changeset
    85
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
    86
    flibInit("/usr/home/unC0Rr/Sources/Hedgewars/Hedgewars-GC/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
    87
    flibRegisterUIMessagesCallback(this, &guiMessagesCallback);
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
    88
10436
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    89
    ThemeIconProvider * themeIcon = (ThemeIconProvider *)m_engine->imageProvider(QLatin1String("theme"));
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    90
    themeIcon->setFileContentsFunction(flibGetThemeIcon);
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    91
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
    92
    fillModels();
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    93
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    94
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    95
HWEngine::~HWEngine()
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    96
{
10424
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    97
    flibFree();
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    98
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    99
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   100
void HWEngine::getPreview()
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   101
{
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   102
    flibSetSeed(QUuid::createUuid().toString().toLatin1());
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   103
    flibGetPreview();
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   104
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   105
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   106
void HWEngine::runQuickGame()
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   107
{
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   108
    flibSetSeed(QUuid::createUuid().toString().toLatin1());
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   109
    flibRunQuickGame();
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   110
}
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   111
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10444
diff changeset
   112
void HWEngine::runLocalGame()
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10444
diff changeset
   113
{
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10444
diff changeset
   114
    flibRunLocalGame();
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10444
diff changeset
   115
}
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10444
diff changeset
   116
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10444
diff changeset
   117
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   118
static QObject *hwengine_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   119
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   120
    Q_UNUSED(scriptEngine)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   121
10420
unc0rr
parents: 10418
diff changeset
   122
    HWEngine *hwengine = new HWEngine(engine);
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   123
    return hwengine;
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   124
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   125
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   126
void HWEngine::exposeToQML()
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   127
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   128
    qDebug("HWEngine::exposeToQML");
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   129
    qmlRegisterSingletonType<HWEngine>("Hedgewars.Engine", 1, 0, "HWEngine", hwengine_singletontype_provider);
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
   130
}
10416
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
   131
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
   132
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   133
void HWEngine::guiMessagesCallback(void *context, MessageType mt, const char * msg, uint32_t len)
10420
unc0rr
parents: 10418
diff changeset
   134
{
unc0rr
parents: 10418
diff changeset
   135
    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
   136
    QByteArray b = QByteArray(msg, len);
10420
unc0rr
parents: 10418
diff changeset
   137
11420
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   138
    //qDebug() << "FLIPC in" << b.size() << b;
10420
unc0rr
parents: 10418
diff changeset
   139
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   140
    QMetaObject::invokeMethod(obj, "engineMessageHandler", Qt::QueuedConnection, Q_ARG(MessageType, mt), Q_ARG(QByteArray, b));
10416
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
   141
}
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
   142
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   143
void HWEngine::engineMessageHandler(MessageType mt, const QByteArray &msg)
10416
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
   144
{
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   145
    switch(mt)
10426
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
   146
    {
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
   147
    case MSG_PREVIEW: {
10426
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
   148
        PreviewImageProvider * preview = (PreviewImageProvider *)m_engine->imageProvider(QLatin1String("preview"));
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
   149
        preview->setPixmap(msg);
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
   150
        emit previewImageChanged();
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   151
        break;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
   152
    }
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
   153
    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
   154
        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
   155
        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
   156
        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
   157
    }
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   158
    case MSG_REMOVEPLAYINGTEAM: {
11420
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   159
        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
   160
        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
   161
    }
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   162
    case MSG_ADDTEAM: {
11420
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   163
        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
   164
        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
   165
    }
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   166
    case MSG_REMOVETEAM: {
11420
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   167
        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
   168
        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
   169
    }
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   170
    case MSG_TEAMCOLOR: {
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   171
        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
   172
        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
   173
        break;
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   174
    }
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10896
diff changeset
   175
    case MSG_NETDATA: {
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10896
diff changeset
   176
        flibPassNetData(msg.constData());
11420
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   177
        break;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   178
    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   179
    case MSG_CONNECTED: {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   180
        emit netConnected();
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   181
        break;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   182
    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   183
    case MSG_DISCONNECTED: {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   184
        emit netDisconnected(QString::fromUtf8(msg));
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   185
        break;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   186
    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   187
    case MSG_ADDLOBBYCLIENT: {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   188
        emit lobbyClientAdded(QString::fromUtf8(msg));
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   189
        break;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   190
    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   191
    case MSG_REMOVELOBBYCLIENT: {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   192
        emit lobbyClientRemoved(QString::fromUtf8(msg));
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   193
        break;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   194
    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   195
    case MSG_LOBBYCHATLINE: {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   196
        QStringList l = QString::fromUtf8(msg).split('\n');
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   197
        emit lobbyChatLine(l[0], l[1]);
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 10951
diff changeset
   198
        break;
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10896
diff changeset
   199
    }
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
   200
    }
10424
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
   201
}
10416
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
   202
10424
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
   203
QString HWEngine::currentSeed()
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
   204
{
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   205
    return QString::fromLatin1(flibGetSeed());
10416
1c301054694d - Remove --port command
unc0rr
parents: 10404
diff changeset
   206
}
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   207
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   208
void HWEngine::fillModels()
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   209
{
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   210
    QStringList resultModel;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   211
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   212
    char ** themes = flibGetThemesList();
10616
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   213
    for (char **i = themes; *i != NULL; i++)
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   214
        resultModel << QString::fromUtf8(*i);
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   215
    flibFreeThemesList(themes);
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   216
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents: 10432
diff changeset
   217
    m_engine->rootContext()->setContextProperty("themesModel", QVariant::fromValue(resultModel));
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   218
10616
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   219
    // scripts model
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   220
    resultModel.clear();
10616
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   221
    for (char **i = flibGetScriptsList(); *i != NULL; i++)
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   222
        resultModel << QString::fromUtf8(*i);
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   223
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   224
    m_engine->rootContext()->setContextProperty("scriptsModel", QVariant::fromValue(resultModel));
10616
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   225
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   226
    // schemes model
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   227
    resultModel.clear();
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   228
    for (char **i = flibGetSchemesList(); *i != NULL; i++)
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   229
        resultModel << QString::fromUtf8(*i);
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   230
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10612
diff changeset
   231
    m_engine->rootContext()->setContextProperty("schemesModel", QVariant::fromValue(resultModel));
10888
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   232
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   233
    // ammos model
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   234
    resultModel.clear();
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   235
    for (char **i = flibGetAmmosList(); *i != NULL; i++)
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   236
        resultModel << QString::fromUtf8(*i);
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   237
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   238
    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
   239
}
10442
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   240
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   241
void HWEngine::getTeamsList()
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   242
{
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   243
    char ** teams = flibGetTeamsList();
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   244
    for (char **i = teams; *i != NULL; i++) {
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   245
        QString team = QString::fromUtf8(*i);
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   246
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   247
        emit localTeamAdded(team, 0);
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   248
    }
c58db813240b Load and show local teams list
unc0rr
parents: 10436
diff changeset
   249
}
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
   250
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   251
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
   252
{
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   253
    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
   254
}
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   255
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   256
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
   257
{
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10442
diff changeset
   258
    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
   259
}
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   260
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   261
void HWEngine::resetGameConfig()
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   262
{
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   263
    flibResetGameConfig();
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   264
}
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   265
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   266
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
   267
{
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   268
    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
   269
}
10456
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   270
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents: 10888
diff changeset
   271
void HWEngine::connect(const QString &host, quint16 port)
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents: 10888
diff changeset
   272
{
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents: 10888
diff changeset
   273
    flibConnectOfficialServer();
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents: 10888
diff changeset
   274
}
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents: 10888
diff changeset
   275
10456
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   276
void HWEngine::setTheme(const QString &theme)
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   277
{
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   278
    flibSetTheme(theme.toUtf8().constData());
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   279
}
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   280
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   281
void HWEngine::setScript(const QString &script)
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   282
{
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   283
    flibSetScript(script.toUtf8().constData());
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10517
diff changeset
   284
}
10819
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10616
diff changeset
   285
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10616
diff changeset
   286
void HWEngine::setScheme(const QString &scheme)
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10616
diff changeset
   287
{
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10616
diff changeset
   288
    flibSetScheme(scheme.toUtf8().constData());
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10616
diff changeset
   289
}
10888
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   290
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   291
void HWEngine::setAmmo(const QString &ammo)
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   292
{
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   293
    flibSetAmmo(ammo.toUtf8().constData());
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   294
}