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