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