author | unc0rr |
Thu, 17 Dec 2015 00:51:20 +0300 | |
branch | qmlfrontend |
changeset 11464 | 30397f91571c |
parent 11448 | 5182d44fb733 |
child 11832 | 8c71c5a1172f |
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; |
11439 | 39 |
passFlibEvent_t * flibPassFlibEvent; |
11421 | 40 |
sendChatLine_t * flibSendChatLine; |
11428 | 41 |
joinRoom_t * flibJoinRoom; |
11429 | 42 |
partRoom_t * flibPartRoom; |
10402 | 43 |
} |
10420 | 44 |
|
11429 | 45 |
Q_DECLARE_METATYPE(MessageType) |
10430 | 46 |
|
10420 | 47 |
HWEngine::HWEngine(QQmlEngine *engine, QObject *parent) : |
48 |
QObject(parent), |
|
49 |
m_engine(engine) |
|
10402 | 50 |
{ |
10430 | 51 |
qRegisterMetaType<MessageType>("MessageType"); |
52 |
||
11444 | 53 |
#ifdef Q_OS_WIN |
54 |
QLibrary hwlib("./libhwengine.dll"); |
|
55 |
#else |
|
10404
1baaab44a0b2
- Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents:
10402
diff
changeset
|
56 |
QLibrary hwlib("./libhwengine.so"); |
11444 | 57 |
#endif |
10402 | 58 |
|
59 |
if(!hwlib.load()) |
|
10404
1baaab44a0b2
- Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents:
10402
diff
changeset
|
60 |
qWarning() << "Engine library not found" << hwlib.errorString(); |
10402 | 61 |
|
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
62 |
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
|
63 |
flibRegisterUIMessagesCallback = (registerUIMessagesCallback_t*) hwlib.resolve("registerUIMessagesCallback"); |
10430 | 64 |
flibGetSeed = (getSeed_t*) hwlib.resolve("getSeed"); |
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
65 |
flibGetPreview = (getPreview_t*) hwlib.resolve("getPreview"); |
10432 | 66 |
flibRunQuickGame = (runQuickGame_t*) hwlib.resolve("runQuickGame"); |
10448 | 67 |
flibRunLocalGame = (runLocalGame_t*) hwlib.resolve("runLocalGame"); |
10416 | 68 |
flibInit = (flibInit_t*) hwlib.resolve("flibInit"); |
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
69 |
flibFree = (flibFree_t*) hwlib.resolve("flibFree"); |
10416 | 70 |
|
10612 | 71 |
flibSetSeed = (setSeed_t*) hwlib.resolve("setSeed"); |
72 |
flibSetTheme = (setTheme_t*) hwlib.resolve("setTheme"); |
|
73 |
flibSetScript = (setScript_t*) hwlib.resolve("setScript"); |
|
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10616
diff
changeset
|
74 |
flibSetScheme = (setScheme_t*) hwlib.resolve("setScheme"); |
10888 | 75 |
flibSetAmmo = (setAmmo_t*) hwlib.resolve("setAmmo"); |
10612 | 76 |
|
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
77 |
flibGetThemesList = (getThemesList_t*) hwlib.resolve("getThemesList"); |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
78 |
flibFreeThemesList = (freeThemesList_t*) hwlib.resolve("freeThemesList"); |
10436 | 79 |
flibGetThemeIcon = (getThemeIcon_t*) hwlib.resolve("getThemeIcon"); |
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
80 |
|
10517 | 81 |
flibGetScriptsList = (getScriptsList_t*) hwlib.resolve("getScriptsList"); |
10616 | 82 |
flibGetSchemesList = (getSchemesList_t*) hwlib.resolve("getSchemesList"); |
10888 | 83 |
flibGetAmmosList = (getAmmosList_t*) hwlib.resolve("getAmmosList"); |
10517 | 84 |
|
10450 | 85 |
flibResetGameConfig = (resetGameConfig_t*) hwlib.resolve("resetGameConfig"); |
10442 | 86 |
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
|
87 |
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
|
88 |
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
|
89 |
flibChangeTeamColor = (changeTeamColor_t*) hwlib.resolve("changeTeamColor"); |
10442 | 90 |
|
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
10888
diff
changeset
|
91 |
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
|
92 |
flibPassNetData = (passNetData_t*) hwlib.resolve("passNetData"); |
11439 | 93 |
flibPassFlibEvent = (passFlibEvent_t*) hwlib.resolve("passFlibEvent"); |
11421 | 94 |
flibSendChatLine = (sendChatLine_t*) hwlib.resolve("sendChatLine"); |
11428 | 95 |
flibJoinRoom = (joinRoom_t*) hwlib.resolve("joinRoom"); |
11429 | 96 |
flibPartRoom = (partRoom_t*) hwlib.resolve("partRoom"); |
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
10888
diff
changeset
|
97 |
|
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
98 |
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
|
99 |
flibRegisterUIMessagesCallback(this, &guiMessagesCallback); |
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
100 |
|
10436 | 101 |
ThemeIconProvider * themeIcon = (ThemeIconProvider *)m_engine->imageProvider(QLatin1String("theme")); |
102 |
themeIcon->setFileContentsFunction(flibGetThemeIcon); |
|
103 |
||
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
104 |
fillModels(); |
10402 | 105 |
} |
106 |
||
107 |
HWEngine::~HWEngine() |
|
108 |
{ |
|
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
109 |
flibFree(); |
10402 | 110 |
} |
111 |
||
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
112 |
void HWEngine::getPreview() |
10402 | 113 |
{ |
10430 | 114 |
flibSetSeed(QUuid::createUuid().toString().toLatin1()); |
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
115 |
flibGetPreview(); |
10402 | 116 |
} |
117 |
||
10432 | 118 |
void HWEngine::runQuickGame() |
119 |
{ |
|
120 |
flibSetSeed(QUuid::createUuid().toString().toLatin1()); |
|
121 |
flibRunQuickGame(); |
|
122 |
} |
|
123 |
||
10448 | 124 |
void HWEngine::runLocalGame() |
125 |
{ |
|
126 |
flibRunLocalGame(); |
|
127 |
} |
|
128 |
||
129 |
||
10402 | 130 |
static QObject *hwengine_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine) |
131 |
{ |
|
132 |
Q_UNUSED(scriptEngine) |
|
133 |
||
10420 | 134 |
HWEngine *hwengine = new HWEngine(engine); |
10402 | 135 |
return hwengine; |
136 |
} |
|
137 |
||
138 |
void HWEngine::exposeToQML() |
|
139 |
{ |
|
140 |
qDebug("HWEngine::exposeToQML"); |
|
141 |
qmlRegisterSingletonType<HWEngine>("Hedgewars.Engine", 1, 0, "HWEngine", hwengine_singletontype_provider); |
|
142 |
} |
|
10416 | 143 |
|
144 |
||
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
145 |
void HWEngine::guiMessagesCallback(void *context, MessageType mt, const char * msg, uint32_t len) |
10420 | 146 |
{ |
147 |
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
|
148 |
QByteArray b = QByteArray(msg, len); |
10420 | 149 |
|
11439 | 150 |
//qDebug() << "FLIPC in" << mt << " size = " << b.size(); |
10420 | 151 |
|
10430 | 152 |
QMetaObject::invokeMethod(obj, "engineMessageHandler", Qt::QueuedConnection, Q_ARG(MessageType, mt), Q_ARG(QByteArray, b)); |
10416 | 153 |
} |
154 |
||
10430 | 155 |
void HWEngine::engineMessageHandler(MessageType mt, const QByteArray &msg) |
10416 | 156 |
{ |
10430 | 157 |
switch(mt) |
10426 | 158 |
{ |
11439 | 159 |
case MSG_RENDERINGPREVIEW: { |
160 |
emit previewIsRendering(); |
|
161 |
break; |
|
162 |
} |
|
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
|
163 |
case MSG_PREVIEW: { |
10426 | 164 |
PreviewImageProvider * preview = (PreviewImageProvider *)m_engine->imageProvider(QLatin1String("preview")); |
165 |
preview->setPixmap(msg); |
|
166 |
emit previewImageChanged(); |
|
10430 | 167 |
break; |
10426 | 168 |
} |
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
|
169 |
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
|
170 |
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
|
171 |
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
|
172 |
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
|
173 |
} |
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10442
diff
changeset
|
174 |
case MSG_REMOVEPLAYINGTEAM: { |
11420 | 175 |
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
|
176 |
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
|
177 |
} |
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 |
case MSG_ADDTEAM: { |
11420 | 179 |
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
|
180 |
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
|
181 |
} |
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 |
case MSG_REMOVETEAM: { |
11420 | 183 |
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
|
184 |
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
|
185 |
} |
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
186 |
case MSG_TEAMCOLOR: { |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
187 |
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
|
188 |
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
|
189 |
break; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
190 |
} |
11448 | 191 |
case MSG_HEDGEHOGSNUMBER: { |
192 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
|
193 |
emit hedgehogsNumberChanged(l[0], l[1].toInt()); |
|
194 |
break; |
|
195 |
} |
|
10951
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10896
diff
changeset
|
196 |
case MSG_NETDATA: { |
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10896
diff
changeset
|
197 |
flibPassNetData(msg.constData()); |
11420 | 198 |
break; |
199 |
} |
|
11439 | 200 |
case MSG_FLIBEVENT: { |
201 |
flibPassFlibEvent(msg.constData()); |
|
202 |
break; |
|
203 |
} |
|
11420 | 204 |
case MSG_CONNECTED: { |
205 |
emit netConnected(); |
|
206 |
break; |
|
207 |
} |
|
208 |
case MSG_DISCONNECTED: { |
|
209 |
emit netDisconnected(QString::fromUtf8(msg)); |
|
210 |
break; |
|
211 |
} |
|
212 |
case MSG_ADDLOBBYCLIENT: { |
|
213 |
emit lobbyClientAdded(QString::fromUtf8(msg)); |
|
214 |
break; |
|
215 |
} |
|
216 |
case MSG_REMOVELOBBYCLIENT: { |
|
11428 | 217 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
11442 | 218 |
if(l.size() < 2) |
219 |
l.append(""); |
|
11428 | 220 |
emit lobbyClientRemoved(l[0], l[1]); |
11420 | 221 |
break; |
222 |
} |
|
223 |
case MSG_LOBBYCHATLINE: { |
|
224 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
|
225 |
emit lobbyChatLine(l[0], l[1]); |
|
226 |
break; |
|
10951
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10896
diff
changeset
|
227 |
} |
11429 | 228 |
case MSG_ADDROOMCLIENT: { |
229 |
emit roomClientAdded(QString::fromUtf8(msg)); |
|
230 |
break; |
|
231 |
} |
|
232 |
case MSG_REMOVEROOMCLIENT: { |
|
233 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
|
11440 | 234 |
if(l.size() < 2) |
235 |
l.append(""); |
|
11429 | 236 |
emit roomClientRemoved(l[0], l[1]); |
237 |
break; |
|
238 |
} |
|
239 |
case MSG_ROOMCHATLINE: { |
|
240 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
|
241 |
emit roomChatLine(l[0], l[1]); |
|
242 |
break; |
|
243 |
} |
|
11423 | 244 |
case MSG_ADDROOM: { |
245 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
|
246 |
emit roomAdded(0, l[1], l[2].toInt(), l[3].toInt(), l[4], l[5], l[6], l[7], l[8]); |
|
247 |
break; |
|
248 |
} |
|
249 |
case MSG_UPDATEROOM: { |
|
11427 | 250 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
251 |
emit roomUpdated(l[0], 0, l[2], l[3].toInt(), l[4].toInt(), l[5], l[6], l[7], l[8], l[9]); |
|
11423 | 252 |
break; |
253 |
} |
|
254 |
case MSG_REMOVEROOM: { |
|
11424 | 255 |
emit roomRemoved(QString::fromUtf8(msg)); |
11423 | 256 |
break; |
257 |
} |
|
11428 | 258 |
case MSG_ERROR: { |
259 |
emit errorMessage(QString::fromUtf8(msg)); |
|
260 |
break; |
|
261 |
} |
|
262 |
case MSG_WARNING: { |
|
263 |
emit warningMessage(QString::fromUtf8(msg)); |
|
264 |
break; |
|
265 |
} |
|
11429 | 266 |
case MSG_MOVETOLOBBY: { |
267 |
emit movedToLobby(); |
|
268 |
break; |
|
269 |
} |
|
270 |
case MSG_MOVETOROOM: { |
|
271 |
emit movedToRoom(); |
|
272 |
break; |
|
273 |
} |
|
11435 | 274 |
case MSG_NICKNAME: { |
275 |
m_myNickname = QString::fromUtf8(msg); |
|
276 |
break; |
|
277 |
} |
|
11436 | 278 |
case MSG_SEED: { |
279 |
emit seedChanged(QString::fromUtf8(msg)); |
|
280 |
break; |
|
281 |
} |
|
282 |
case MSG_THEME: { |
|
283 |
emit themeChanged(QString::fromUtf8(msg)); |
|
284 |
break; |
|
285 |
} |
|
286 |
case MSG_SCRIPT: { |
|
287 |
emit scriptChanged(QString::fromUtf8(msg)); |
|
288 |
break; |
|
289 |
} |
|
11438 | 290 |
case MSG_FEATURESIZE: { |
291 |
emit featureSizeChanged(msg.toInt()); |
|
292 |
break; |
|
293 |
} |
|
294 |
case MSG_MAPGEN: { |
|
295 |
emit mapGenChanged(msg.toInt()); |
|
296 |
break; |
|
297 |
} |
|
298 |
case MSG_MAP: { |
|
299 |
emit mapChanged(QString::fromUtf8(msg)); |
|
300 |
break; |
|
301 |
} |
|
302 |
case MSG_MAZESIZE: { |
|
303 |
emit mazeSizeChanged(msg.toInt()); |
|
304 |
break; |
|
305 |
} |
|
306 |
case MSG_TEMPLATE: { |
|
307 |
emit templateChanged(msg.toInt()); |
|
308 |
break; |
|
309 |
} |
|
11442 | 310 |
case MSG_AMMO: { |
311 |
emit ammoChanged(QString::fromUtf8(msg)); |
|
312 |
break; |
|
313 |
} |
|
11445 | 314 |
case MSG_SCHEME: { |
315 |
emit schemeChanged(QString::fromUtf8(msg)); |
|
316 |
break; |
|
317 |
} |
|
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
|
318 |
} |
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
319 |
} |
10416 | 320 |
|
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
321 |
QString HWEngine::currentSeed() |
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
322 |
{ |
10430 | 323 |
return QString::fromLatin1(flibGetSeed()); |
10416 | 324 |
} |
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
325 |
|
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
326 |
void HWEngine::fillModels() |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
327 |
{ |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
328 |
QStringList resultModel; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
329 |
|
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
330 |
char ** themes = flibGetThemesList(); |
10616 | 331 |
for (char **i = themes; *i != NULL; i++) |
332 |
resultModel << QString::fromUtf8(*i); |
|
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
333 |
flibFreeThemesList(themes); |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
334 |
|
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
335 |
m_engine->rootContext()->setContextProperty("themesModel", QVariant::fromValue(resultModel)); |
10612 | 336 |
|
10616 | 337 |
// scripts model |
10612 | 338 |
resultModel.clear(); |
10616 | 339 |
for (char **i = flibGetScriptsList(); *i != NULL; i++) |
340 |
resultModel << QString::fromUtf8(*i); |
|
10612 | 341 |
|
342 |
m_engine->rootContext()->setContextProperty("scriptsModel", QVariant::fromValue(resultModel)); |
|
10616 | 343 |
|
344 |
// schemes model |
|
345 |
resultModel.clear(); |
|
346 |
for (char **i = flibGetSchemesList(); *i != NULL; i++) |
|
347 |
resultModel << QString::fromUtf8(*i); |
|
348 |
||
349 |
m_engine->rootContext()->setContextProperty("schemesModel", QVariant::fromValue(resultModel)); |
|
10888 | 350 |
|
351 |
// ammos model |
|
352 |
resultModel.clear(); |
|
353 |
for (char **i = flibGetAmmosList(); *i != NULL; i++) |
|
354 |
resultModel << QString::fromUtf8(*i); |
|
355 |
||
356 |
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
|
357 |
} |
10442 | 358 |
|
359 |
void HWEngine::getTeamsList() |
|
360 |
{ |
|
361 |
char ** teams = flibGetTeamsList(); |
|
362 |
for (char **i = teams; *i != NULL; i++) { |
|
363 |
QString team = QString::fromUtf8(*i); |
|
364 |
||
365 |
emit localTeamAdded(team, 0); |
|
366 |
} |
|
367 |
} |
|
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
|
368 |
|
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10442
diff
changeset
|
369 |
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
|
370 |
{ |
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10442
diff
changeset
|
371 |
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
|
372 |
} |
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10442
diff
changeset
|
373 |
|
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10442
diff
changeset
|
374 |
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
|
375 |
{ |
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10442
diff
changeset
|
376 |
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
|
377 |
} |
10450 | 378 |
|
379 |
void HWEngine::resetGameConfig() |
|
380 |
{ |
|
381 |
flibResetGameConfig(); |
|
382 |
} |
|
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
383 |
|
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
384 |
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
|
385 |
{ |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
386 |
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
|
387 |
} |
10456 | 388 |
|
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
10888
diff
changeset
|
389 |
void HWEngine::connect(const QString &host, quint16 port) |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
10888
diff
changeset
|
390 |
{ |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
10888
diff
changeset
|
391 |
flibConnectOfficialServer(); |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
10888
diff
changeset
|
392 |
} |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
10888
diff
changeset
|
393 |
|
11421 | 394 |
void HWEngine::sendChatMessage(const QString &msg) |
395 |
{ |
|
396 |
flibSendChatLine(msg.toUtf8().constData()); |
|
397 |
} |
|
398 |
||
11428 | 399 |
void HWEngine::joinRoom(const QString &roomName) |
400 |
{ |
|
401 |
flibJoinRoom(roomName.toUtf8().constData()); |
|
402 |
} |
|
403 |
||
11429 | 404 |
void HWEngine::partRoom(const QString &message) |
405 |
{ |
|
406 |
flibPartRoom(message.toUtf8().constData()); |
|
407 |
} |
|
408 |
||
11435 | 409 |
QString HWEngine::myNickname() |
410 |
{ |
|
411 |
return m_myNickname; |
|
412 |
} |
|
413 |
||
10456 | 414 |
void HWEngine::setTheme(const QString &theme) |
415 |
{ |
|
416 |
flibSetTheme(theme.toUtf8().constData()); |
|
417 |
} |
|
10612 | 418 |
|
419 |
void HWEngine::setScript(const QString &script) |
|
420 |
{ |
|
421 |
flibSetScript(script.toUtf8().constData()); |
|
422 |
} |
|
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10616
diff
changeset
|
423 |
|
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10616
diff
changeset
|
424 |
void HWEngine::setScheme(const QString &scheme) |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10616
diff
changeset
|
425 |
{ |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10616
diff
changeset
|
426 |
flibSetScheme(scheme.toUtf8().constData()); |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10616
diff
changeset
|
427 |
} |
10888 | 428 |
|
429 |
void HWEngine::setAmmo(const QString &ammo) |
|
430 |
{ |
|
431 |
flibSetAmmo(ammo.toUtf8().constData()); |
|
432 |
} |