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