author | unc0rr |
Sun, 17 Dec 2017 21:09:59 +0100 | |
branch | qmlfrontend |
changeset 12856 | 95d903b976d0 |
parent 12855 | 1b2b84315d27 |
permissions | -rw-r--r-- |
10402 | 1 |
#include <QLibrary> |
2 |
#include <QtQml> |
|
10404
1baaab44a0b2
- Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents:
10402
diff
changeset
|
3 |
#include <QDebug> |
10420 | 4 |
#include <QPainter> |
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
5 |
#include <QUuid> |
10402 | 6 |
|
7 |
#include "hwengine.h" |
|
10420 | 8 |
#include "previewimageprovider.h" |
10436 | 9 |
#include "themeiconprovider.h" |
10402 | 10 |
|
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 | 14 |
setSeed_t *flibSetSeed; |
15 |
getSeed_t *flibGetSeed; |
|
10456 | 16 |
setTheme_t *flibSetTheme; |
10612 | 17 |
setScript_t *flibSetScript; |
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10616
diff
changeset
|
18 |
setScheme_t *flibSetScheme; |
10888 | 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 | 21 |
runQuickGame_t *flibRunQuickGame; |
10448 | 22 |
runLocalGame_t *flibRunLocalGame; |
10416 | 23 |
flibInit_t *flibInit; |
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
24 |
flibFree_t *flibFree; |
10450 | 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 | 28 |
getThemeIcon_t *flibGetThemeIcon; |
10517 | 29 |
getScriptsList_t *flibGetScriptsList; |
10616 | 30 |
getSchemesList_t *flibGetSchemesList; |
10888 | 31 |
getAmmosList_t *flibGetAmmosList; |
10442 | 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 | 39 |
passToNet_t * flibPassToNet; |
11434 | 40 |
passFlibEvent_t * flibPassFlibEvent; |
11416 | 41 |
sendChatLine_t * flibSendChatLine; |
11423 | 42 |
joinRoom_t * flibJoinRoom; |
11424 | 43 |
partRoom_t * flibPartRoom; |
10402 | 44 |
} |
10420 | 45 |
|
11424 | 46 |
Q_DECLARE_METATYPE(MessageType) |
10430 | 47 |
|
10420 | 48 |
HWEngine::HWEngine(QQmlEngine *engine, QObject *parent) : |
49 |
QObject(parent), |
|
50 |
m_engine(engine) |
|
10402 | 51 |
{ |
10430 | 52 |
qRegisterMetaType<MessageType>("MessageType"); |
53 |
||
11439 | 54 |
#ifdef Q_OS_WIN |
55 |
QLibrary hwlib("./libhwengine.dll"); |
|
56 |
#else |
|
10404
1baaab44a0b2
- Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents:
10402
diff
changeset
|
57 |
QLibrary hwlib("./libhwengine.so"); |
11439 | 58 |
#endif |
10402 | 59 |
|
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 | 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 | 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 | 67 |
flibRunQuickGame = (runQuickGame_t*) hwlib.resolve("runQuickGame"); |
10448 | 68 |
flibRunLocalGame = (runLocalGame_t*) hwlib.resolve("runLocalGame"); |
10416 | 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 | 71 |
|
10612 | 72 |
flibSetSeed = (setSeed_t*) hwlib.resolve("setSeed"); |
73 |
flibSetTheme = (setTheme_t*) hwlib.resolve("setTheme"); |
|
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 | 76 |
flibSetAmmo = (setAmmo_t*) hwlib.resolve("setAmmo"); |
10612 | 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 | 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 | 82 |
flibGetScriptsList = (getScriptsList_t*) hwlib.resolve("getScriptsList"); |
10616 | 83 |
flibGetSchemesList = (getSchemesList_t*) hwlib.resolve("getSchemesList"); |
10888 | 84 |
flibGetAmmosList = (getAmmosList_t*) hwlib.resolve("getAmmosList"); |
10517 | 85 |
|
10450 | 86 |
flibResetGameConfig = (resetGameConfig_t*) hwlib.resolve("resetGameConfig"); |
10442 | 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 | 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 | 94 |
flibPassToNet = (passToNet_t*) hwlib.resolve("passToNet"); |
11434 | 95 |
flibPassFlibEvent = (passFlibEvent_t*) hwlib.resolve("passFlibEvent"); |
11416 | 96 |
flibSendChatLine = (sendChatLine_t*) hwlib.resolve("sendChatLine"); |
11423 | 97 |
flibJoinRoom = (joinRoom_t*) hwlib.resolve("joinRoom"); |
11424 | 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 | 103 |
ThemeIconProvider * themeIcon = (ThemeIconProvider *)m_engine->imageProvider(QLatin1String("theme")); |
104 |
themeIcon->setFileContentsFunction(flibGetThemeIcon); |
|
105 |
||
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
106 |
fillModels(); |
10402 | 107 |
} |
108 |
||
109 |
HWEngine::~HWEngine() |
|
110 |
{ |
|
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
111 |
flibFree(); |
10402 | 112 |
} |
113 |
||
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
114 |
void HWEngine::getPreview() |
10402 | 115 |
{ |
10430 | 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 | 118 |
} |
119 |
||
10432 | 120 |
void HWEngine::runQuickGame() |
121 |
{ |
|
122 |
flibSetSeed(QUuid::createUuid().toString().toLatin1()); |
|
123 |
flibRunQuickGame(); |
|
124 |
} |
|
125 |
||
10448 | 126 |
void HWEngine::runLocalGame() |
127 |
{ |
|
128 |
flibRunLocalGame(); |
|
129 |
} |
|
130 |
||
131 |
||
10402 | 132 |
static QObject *hwengine_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine) |
133 |
{ |
|
134 |
Q_UNUSED(scriptEngine) |
|
135 |
||
10420 | 136 |
HWEngine *hwengine = new HWEngine(engine); |
10402 | 137 |
return hwengine; |
138 |
} |
|
139 |
||
140 |
void HWEngine::exposeToQML() |
|
141 |
{ |
|
142 |
qDebug("HWEngine::exposeToQML"); |
|
143 |
qmlRegisterSingletonType<HWEngine>("Hedgewars.Engine", 1, 0, "HWEngine", hwengine_singletontype_provider); |
|
144 |
} |
|
10416 | 145 |
|
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 | 148 |
{ |
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 | 151 |
|
11434 | 152 |
//qDebug() << "FLIPC in" << mt << " size = " << b.size(); |
10420 | 153 |
|
10430 | 154 |
QMetaObject::invokeMethod(obj, "engineMessageHandler", Qt::QueuedConnection, Q_ARG(MessageType, mt), Q_ARG(QByteArray, b)); |
10416 | 155 |
} |
156 |
||
10430 | 157 |
void HWEngine::engineMessageHandler(MessageType mt, const QByteArray &msg) |
10416 | 158 |
{ |
10430 | 159 |
switch(mt) |
10426 | 160 |
{ |
11434 | 161 |
case MSG_RENDERINGPREVIEW: { |
162 |
emit previewIsRendering(); |
|
163 |
break; |
|
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 | 166 |
PreviewImageProvider * preview = (PreviewImageProvider *)m_engine->imageProvider(QLatin1String("preview")); |
167 |
preview->setPixmap(msg); |
|
168 |
emit previewImageChanged(); |
|
10430 | 169 |
break; |
10426 | 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 | 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 | 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 | 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 | 197 |
case MSG_HEDGEHOGSNUMBER: { |
198 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
|
199 |
emit hedgehogsNumberChanged(l[0], l[1].toInt()); |
|
200 |
break; |
|
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 | 204 |
break; |
205 |
} |
|
11842 | 206 |
case MSG_TONET: { |
207 |
flibPassToNet(msg.constData(), msg.size()); |
|
208 |
break; |
|
209 |
} |
|
11434 | 210 |
case MSG_FLIBEVENT: { |
211 |
flibPassFlibEvent(msg.constData()); |
|
212 |
break; |
|
213 |
} |
|
11415 | 214 |
case MSG_CONNECTED: { |
215 |
emit netConnected(); |
|
216 |
break; |
|
217 |
} |
|
218 |
case MSG_DISCONNECTED: { |
|
219 |
emit netDisconnected(QString::fromUtf8(msg)); |
|
220 |
break; |
|
221 |
} |
|
222 |
case MSG_ADDLOBBYCLIENT: { |
|
223 |
emit lobbyClientAdded(QString::fromUtf8(msg)); |
|
224 |
break; |
|
225 |
} |
|
226 |
case MSG_REMOVELOBBYCLIENT: { |
|
11423 | 227 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
11437 | 228 |
if(l.size() < 2) |
229 |
l.append(""); |
|
11423 | 230 |
emit lobbyClientRemoved(l[0], l[1]); |
11415 | 231 |
break; |
232 |
} |
|
233 |
case MSG_LOBBYCHATLINE: { |
|
234 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
|
235 |
emit lobbyChatLine(l[0], l[1]); |
|
236 |
break; |
|
10951
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10896
diff
changeset
|
237 |
} |
11424 | 238 |
case MSG_ADDROOMCLIENT: { |
239 |
emit roomClientAdded(QString::fromUtf8(msg)); |
|
240 |
break; |
|
241 |
} |
|
242 |
case MSG_REMOVEROOMCLIENT: { |
|
243 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
|
11435 | 244 |
if(l.size() < 2) |
245 |
l.append(""); |
|
11424 | 246 |
emit roomClientRemoved(l[0], l[1]); |
247 |
break; |
|
248 |
} |
|
249 |
case MSG_ROOMCHATLINE: { |
|
250 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
|
251 |
emit roomChatLine(l[0], l[1]); |
|
252 |
break; |
|
253 |
} |
|
11418 | 254 |
case MSG_ADDROOM: { |
255 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
|
256 |
emit roomAdded(0, l[1], l[2].toInt(), l[3].toInt(), l[4], l[5], l[6], l[7], l[8]); |
|
257 |
break; |
|
258 |
} |
|
259 |
case MSG_UPDATEROOM: { |
|
11422 | 260 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
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 | 262 |
break; |
263 |
} |
|
264 |
case MSG_REMOVEROOM: { |
|
11419 | 265 |
emit roomRemoved(QString::fromUtf8(msg)); |
11418 | 266 |
break; |
267 |
} |
|
11423 | 268 |
case MSG_ERROR: { |
269 |
emit errorMessage(QString::fromUtf8(msg)); |
|
270 |
break; |
|
271 |
} |
|
272 |
case MSG_WARNING: { |
|
273 |
emit warningMessage(QString::fromUtf8(msg)); |
|
274 |
break; |
|
275 |
} |
|
11424 | 276 |
case MSG_MOVETOLOBBY: { |
277 |
emit movedToLobby(); |
|
278 |
break; |
|
279 |
} |
|
280 |
case MSG_MOVETOROOM: { |
|
281 |
emit movedToRoom(); |
|
282 |
break; |
|
283 |
} |
|
11430 | 284 |
case MSG_NICKNAME: { |
285 |
m_myNickname = QString::fromUtf8(msg); |
|
286 |
break; |
|
287 |
} |
|
11431 | 288 |
case MSG_SEED: { |
289 |
emit seedChanged(QString::fromUtf8(msg)); |
|
290 |
break; |
|
291 |
} |
|
292 |
case MSG_THEME: { |
|
293 |
emit themeChanged(QString::fromUtf8(msg)); |
|
294 |
break; |
|
295 |
} |
|
296 |
case MSG_SCRIPT: { |
|
297 |
emit scriptChanged(QString::fromUtf8(msg)); |
|
298 |
break; |
|
299 |
} |
|
11433 | 300 |
case MSG_FEATURESIZE: { |
301 |
emit featureSizeChanged(msg.toInt()); |
|
302 |
break; |
|
303 |
} |
|
304 |
case MSG_MAPGEN: { |
|
305 |
emit mapGenChanged(msg.toInt()); |
|
306 |
break; |
|
307 |
} |
|
308 |
case MSG_MAP: { |
|
309 |
emit mapChanged(QString::fromUtf8(msg)); |
|
310 |
break; |
|
311 |
} |
|
312 |
case MSG_MAZESIZE: { |
|
313 |
emit mazeSizeChanged(msg.toInt()); |
|
314 |
break; |
|
315 |
} |
|
316 |
case MSG_TEMPLATE: { |
|
317 |
emit templateChanged(msg.toInt()); |
|
318 |
break; |
|
319 |
} |
|
11437 | 320 |
case MSG_AMMO: { |
321 |
emit ammoChanged(QString::fromUtf8(msg)); |
|
322 |
break; |
|
323 |
} |
|
11440 | 324 |
case MSG_SCHEME: { |
325 |
emit schemeChanged(QString::fromUtf8(msg)); |
|
326 |
break; |
|
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 | 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 | 333 |
return QString::fromLatin1(flibGetSeed()); |
10416 | 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 | 341 |
for (char **i = themes; *i != NULL; i++) |
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 | 346 |
|
10616 | 347 |
// scripts model |
10612 | 348 |
resultModel.clear(); |
10616 | 349 |
for (char **i = flibGetScriptsList(); *i != NULL; i++) |
350 |
resultModel << QString::fromUtf8(*i); |
|
10612 | 351 |
|
352 |
m_engine->rootContext()->setContextProperty("scriptsModel", QVariant::fromValue(resultModel)); |
|
10616 | 353 |
|
354 |
// schemes model |
|
355 |
resultModel.clear(); |
|
356 |
for (char **i = flibGetSchemesList(); *i != NULL; i++) |
|
357 |
resultModel << QString::fromUtf8(*i); |
|
358 |
||
359 |
m_engine->rootContext()->setContextProperty("schemesModel", QVariant::fromValue(resultModel)); |
|
10888 | 360 |
|
361 |
// ammos model |
|
362 |
resultModel.clear(); |
|
363 |
for (char **i = flibGetAmmosList(); *i != NULL; i++) |
|
364 |
resultModel << QString::fromUtf8(*i); |
|
365 |
||
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 | 368 |
|
369 |
void HWEngine::getTeamsList() |
|
370 |
{ |
|
371 |
char ** teams = flibGetTeamsList(); |
|
372 |
for (char **i = teams; *i != NULL; i++) { |
|
373 |
QString team = QString::fromUtf8(*i); |
|
374 |
||
375 |
emit localTeamAdded(team, 0); |
|
376 |
} |
|
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 | 388 |
|
389 |
void HWEngine::resetGameConfig() |
|
390 |
{ |
|
391 |
flibResetGameConfig(); |
|
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 | 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 | 404 |
void HWEngine::sendChatMessage(const QString &msg) |
405 |
{ |
|
406 |
flibSendChatLine(msg.toUtf8().constData()); |
|
407 |
} |
|
408 |
||
11423 | 409 |
void HWEngine::joinRoom(const QString &roomName) |
410 |
{ |
|
411 |
flibJoinRoom(roomName.toUtf8().constData()); |
|
412 |
} |
|
413 |
||
11424 | 414 |
void HWEngine::partRoom(const QString &message) |
415 |
{ |
|
416 |
flibPartRoom(message.toUtf8().constData()); |
|
417 |
} |
|
418 |
||
11430 | 419 |
QString HWEngine::myNickname() |
420 |
{ |
|
421 |
return m_myNickname; |
|
422 |
} |
|
423 |
||
10456 | 424 |
void HWEngine::setTheme(const QString &theme) |
425 |
{ |
|
426 |
flibSetTheme(theme.toUtf8().constData()); |
|
427 |
} |
|
10612 | 428 |
|
429 |
void HWEngine::setScript(const QString &script) |
|
430 |
{ |
|
431 |
flibSetScript(script.toUtf8().constData()); |
|
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 | 438 |
|
439 |
void HWEngine::setAmmo(const QString &ammo) |
|
440 |
{ |
|
441 |
flibSetAmmo(ammo.toUtf8().constData()); |
|
442 |
} |