author | unc0rr |
Tue, 17 May 2016 23:18:08 +0300 | |
branch | qmlfrontend |
changeset 11827 | 8c71c5a1172f |
parent 11443 | 5182d44fb733 |
child 11842 | 93e6c401cc3d |
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; |
11434 | 39 |
passFlibEvent_t * flibPassFlibEvent; |
11416 | 40 |
sendChatLine_t * flibSendChatLine; |
11423 | 41 |
joinRoom_t * flibJoinRoom; |
11424 | 42 |
partRoom_t * flibPartRoom; |
10402 | 43 |
} |
10420 | 44 |
|
11424 | 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 |
||
11439 | 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"); |
11439 | 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"); |
11434 | 93 |
flibPassFlibEvent = (passFlibEvent_t*) hwlib.resolve("passFlibEvent"); |
11416 | 94 |
flibSendChatLine = (sendChatLine_t*) hwlib.resolve("sendChatLine"); |
11423 | 95 |
flibJoinRoom = (joinRoom_t*) hwlib.resolve("joinRoom"); |
11424 | 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 |
|
11434 | 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 |
{ |
11434 | 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 |
} |
11827
8c71c5a1172f
- Add state to engine callback for it to know what engine is sending
unc0rr
parents:
11443
diff
changeset
|
169 |
case MSG_PREVIEWHOGCOUNT: { |
8c71c5a1172f
- Add state to engine callback for it to know what engine is sending
unc0rr
parents:
11443
diff
changeset
|
170 |
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
|
171 |
break; |
8c71c5a1172f
- Add state to engine callback for it to know what engine is sending
unc0rr
parents:
11443
diff
changeset
|
172 |
} |
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
|
173 |
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
|
174 |
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
|
175 |
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
|
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_REMOVEPLAYINGTEAM: { |
11415 | 179 |
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
|
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_ADDTEAM: { |
11415 | 183 |
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
|
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 |
} |
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 |
case MSG_REMOVETEAM: { |
11415 | 187 |
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
|
188 |
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
|
189 |
} |
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
190 |
case MSG_TEAMCOLOR: { |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
191 |
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
|
192 |
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
|
193 |
break; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
194 |
} |
11443 | 195 |
case MSG_HEDGEHOGSNUMBER: { |
196 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
|
197 |
emit hedgehogsNumberChanged(l[0], l[1].toInt()); |
|
198 |
break; |
|
199 |
} |
|
10951
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10896
diff
changeset
|
200 |
case MSG_NETDATA: { |
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10896
diff
changeset
|
201 |
flibPassNetData(msg.constData()); |
11415 | 202 |
break; |
203 |
} |
|
11434 | 204 |
case MSG_FLIBEVENT: { |
205 |
flibPassFlibEvent(msg.constData()); |
|
206 |
break; |
|
207 |
} |
|
11415 | 208 |
case MSG_CONNECTED: { |
209 |
emit netConnected(); |
|
210 |
break; |
|
211 |
} |
|
212 |
case MSG_DISCONNECTED: { |
|
213 |
emit netDisconnected(QString::fromUtf8(msg)); |
|
214 |
break; |
|
215 |
} |
|
216 |
case MSG_ADDLOBBYCLIENT: { |
|
217 |
emit lobbyClientAdded(QString::fromUtf8(msg)); |
|
218 |
break; |
|
219 |
} |
|
220 |
case MSG_REMOVELOBBYCLIENT: { |
|
11423 | 221 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
11437 | 222 |
if(l.size() < 2) |
223 |
l.append(""); |
|
11423 | 224 |
emit lobbyClientRemoved(l[0], l[1]); |
11415 | 225 |
break; |
226 |
} |
|
227 |
case MSG_LOBBYCHATLINE: { |
|
228 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
|
229 |
emit lobbyChatLine(l[0], l[1]); |
|
230 |
break; |
|
10951
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10896
diff
changeset
|
231 |
} |
11424 | 232 |
case MSG_ADDROOMCLIENT: { |
233 |
emit roomClientAdded(QString::fromUtf8(msg)); |
|
234 |
break; |
|
235 |
} |
|
236 |
case MSG_REMOVEROOMCLIENT: { |
|
237 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
|
11435 | 238 |
if(l.size() < 2) |
239 |
l.append(""); |
|
11424 | 240 |
emit roomClientRemoved(l[0], l[1]); |
241 |
break; |
|
242 |
} |
|
243 |
case MSG_ROOMCHATLINE: { |
|
244 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
|
245 |
emit roomChatLine(l[0], l[1]); |
|
246 |
break; |
|
247 |
} |
|
11418 | 248 |
case MSG_ADDROOM: { |
249 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
|
250 |
emit roomAdded(0, l[1], l[2].toInt(), l[3].toInt(), l[4], l[5], l[6], l[7], l[8]); |
|
251 |
break; |
|
252 |
} |
|
253 |
case MSG_UPDATEROOM: { |
|
11422 | 254 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
255 |
emit roomUpdated(l[0], 0, l[2], l[3].toInt(), l[4].toInt(), l[5], l[6], l[7], l[8], l[9]); |
|
11418 | 256 |
break; |
257 |
} |
|
258 |
case MSG_REMOVEROOM: { |
|
11419 | 259 |
emit roomRemoved(QString::fromUtf8(msg)); |
11418 | 260 |
break; |
261 |
} |
|
11423 | 262 |
case MSG_ERROR: { |
263 |
emit errorMessage(QString::fromUtf8(msg)); |
|
264 |
break; |
|
265 |
} |
|
266 |
case MSG_WARNING: { |
|
267 |
emit warningMessage(QString::fromUtf8(msg)); |
|
268 |
break; |
|
269 |
} |
|
11424 | 270 |
case MSG_MOVETOLOBBY: { |
271 |
emit movedToLobby(); |
|
272 |
break; |
|
273 |
} |
|
274 |
case MSG_MOVETOROOM: { |
|
275 |
emit movedToRoom(); |
|
276 |
break; |
|
277 |
} |
|
11430 | 278 |
case MSG_NICKNAME: { |
279 |
m_myNickname = QString::fromUtf8(msg); |
|
280 |
break; |
|
281 |
} |
|
11431 | 282 |
case MSG_SEED: { |
283 |
emit seedChanged(QString::fromUtf8(msg)); |
|
284 |
break; |
|
285 |
} |
|
286 |
case MSG_THEME: { |
|
287 |
emit themeChanged(QString::fromUtf8(msg)); |
|
288 |
break; |
|
289 |
} |
|
290 |
case MSG_SCRIPT: { |
|
291 |
emit scriptChanged(QString::fromUtf8(msg)); |
|
292 |
break; |
|
293 |
} |
|
11433 | 294 |
case MSG_FEATURESIZE: { |
295 |
emit featureSizeChanged(msg.toInt()); |
|
296 |
break; |
|
297 |
} |
|
298 |
case MSG_MAPGEN: { |
|
299 |
emit mapGenChanged(msg.toInt()); |
|
300 |
break; |
|
301 |
} |
|
302 |
case MSG_MAP: { |
|
303 |
emit mapChanged(QString::fromUtf8(msg)); |
|
304 |
break; |
|
305 |
} |
|
306 |
case MSG_MAZESIZE: { |
|
307 |
emit mazeSizeChanged(msg.toInt()); |
|
308 |
break; |
|
309 |
} |
|
310 |
case MSG_TEMPLATE: { |
|
311 |
emit templateChanged(msg.toInt()); |
|
312 |
break; |
|
313 |
} |
|
11437 | 314 |
case MSG_AMMO: { |
315 |
emit ammoChanged(QString::fromUtf8(msg)); |
|
316 |
break; |
|
317 |
} |
|
11440 | 318 |
case MSG_SCHEME: { |
319 |
emit schemeChanged(QString::fromUtf8(msg)); |
|
320 |
break; |
|
321 |
} |
|
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
|
322 |
} |
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
323 |
} |
10416 | 324 |
|
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
325 |
QString HWEngine::currentSeed() |
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
326 |
{ |
10430 | 327 |
return QString::fromLatin1(flibGetSeed()); |
10416 | 328 |
} |
10434
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 |
void HWEngine::fillModels() |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
331 |
{ |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
332 |
QStringList resultModel; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
333 |
|
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
334 |
char ** themes = flibGetThemesList(); |
10616 | 335 |
for (char **i = themes; *i != NULL; i++) |
336 |
resultModel << QString::fromUtf8(*i); |
|
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
337 |
flibFreeThemesList(themes); |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
338 |
|
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
339 |
m_engine->rootContext()->setContextProperty("themesModel", QVariant::fromValue(resultModel)); |
10612 | 340 |
|
10616 | 341 |
// scripts model |
10612 | 342 |
resultModel.clear(); |
10616 | 343 |
for (char **i = flibGetScriptsList(); *i != NULL; i++) |
344 |
resultModel << QString::fromUtf8(*i); |
|
10612 | 345 |
|
346 |
m_engine->rootContext()->setContextProperty("scriptsModel", QVariant::fromValue(resultModel)); |
|
10616 | 347 |
|
348 |
// schemes model |
|
349 |
resultModel.clear(); |
|
350 |
for (char **i = flibGetSchemesList(); *i != NULL; i++) |
|
351 |
resultModel << QString::fromUtf8(*i); |
|
352 |
||
353 |
m_engine->rootContext()->setContextProperty("schemesModel", QVariant::fromValue(resultModel)); |
|
10888 | 354 |
|
355 |
// ammos model |
|
356 |
resultModel.clear(); |
|
357 |
for (char **i = flibGetAmmosList(); *i != NULL; i++) |
|
358 |
resultModel << QString::fromUtf8(*i); |
|
359 |
||
360 |
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
|
361 |
} |
10442 | 362 |
|
363 |
void HWEngine::getTeamsList() |
|
364 |
{ |
|
365 |
char ** teams = flibGetTeamsList(); |
|
366 |
for (char **i = teams; *i != NULL; i++) { |
|
367 |
QString team = QString::fromUtf8(*i); |
|
368 |
||
369 |
emit localTeamAdded(team, 0); |
|
370 |
} |
|
371 |
} |
|
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
|
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 |
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
|
374 |
{ |
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 |
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
|
376 |
} |
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 |
|
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 |
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
|
379 |
{ |
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 |
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
|
381 |
} |
10450 | 382 |
|
383 |
void HWEngine::resetGameConfig() |
|
384 |
{ |
|
385 |
flibResetGameConfig(); |
|
386 |
} |
|
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
387 |
|
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
388 |
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
|
389 |
{ |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
390 |
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
|
391 |
} |
10456 | 392 |
|
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
10888
diff
changeset
|
393 |
void HWEngine::connect(const QString &host, quint16 port) |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
10888
diff
changeset
|
394 |
{ |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
10888
diff
changeset
|
395 |
flibConnectOfficialServer(); |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
10888
diff
changeset
|
396 |
} |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
10888
diff
changeset
|
397 |
|
11416 | 398 |
void HWEngine::sendChatMessage(const QString &msg) |
399 |
{ |
|
400 |
flibSendChatLine(msg.toUtf8().constData()); |
|
401 |
} |
|
402 |
||
11423 | 403 |
void HWEngine::joinRoom(const QString &roomName) |
404 |
{ |
|
405 |
flibJoinRoom(roomName.toUtf8().constData()); |
|
406 |
} |
|
407 |
||
11424 | 408 |
void HWEngine::partRoom(const QString &message) |
409 |
{ |
|
410 |
flibPartRoom(message.toUtf8().constData()); |
|
411 |
} |
|
412 |
||
11430 | 413 |
QString HWEngine::myNickname() |
414 |
{ |
|
415 |
return m_myNickname; |
|
416 |
} |
|
417 |
||
10456 | 418 |
void HWEngine::setTheme(const QString &theme) |
419 |
{ |
|
420 |
flibSetTheme(theme.toUtf8().constData()); |
|
421 |
} |
|
10612 | 422 |
|
423 |
void HWEngine::setScript(const QString &script) |
|
424 |
{ |
|
425 |
flibSetScript(script.toUtf8().constData()); |
|
426 |
} |
|
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10616
diff
changeset
|
427 |
|
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10616
diff
changeset
|
428 |
void HWEngine::setScheme(const QString &scheme) |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10616
diff
changeset
|
429 |
{ |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10616
diff
changeset
|
430 |
flibSetScheme(scheme.toUtf8().constData()); |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10616
diff
changeset
|
431 |
} |
10888 | 432 |
|
433 |
void HWEngine::setAmmo(const QString &ammo) |
|
434 |
{ |
|
435 |
flibSetAmmo(ammo.toUtf8().constData()); |
|
436 |
} |