author | unC0Rr |
Wed, 02 Dec 2015 13:39:16 +0300 | |
branch | qmlfrontend |
changeset 11439 | dd1350a475d9 |
parent 11437 | 6e641b5453f9 |
child 11440 | 330c14f4ba69 |
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 |
} |
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: { |
11415 | 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: { |
11415 | 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: { |
11415 | 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()); |
11415 | 193 |
break; |
194 |
} |
|
11434 | 195 |
case MSG_FLIBEVENT: { |
196 |
flibPassFlibEvent(msg.constData()); |
|
197 |
break; |
|
198 |
} |
|
11415 | 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: { |
|
11423 | 212 |
QStringList l = QString::fromUtf8(msg).split('\n'); |
11437 | 213 |
if(l.size() < 2) |
214 |
l.append(""); |
|
11423 | 215 |
emit lobbyClientRemoved(l[0], l[1]); |
11415 | 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 |
} |
11424 | 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'); |
|
11435 | 229 |
if(l.size() < 2) |
230 |
l.append(""); |
|
11424 | 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 |
} |
|
11418 | 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: { |
|
11422 | 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]); |
|
11418 | 247 |
break; |
248 |
} |
|
249 |
case MSG_REMOVEROOM: { |
|
11419 | 250 |
emit roomRemoved(QString::fromUtf8(msg)); |
11418 | 251 |
break; |
252 |
} |
|
11423 | 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 |
} |
|
11424 | 261 |
case MSG_MOVETOLOBBY: { |
262 |
emit movedToLobby(); |
|
263 |
break; |
|
264 |
} |
|
265 |
case MSG_MOVETOROOM: { |
|
266 |
emit movedToRoom(); |
|
267 |
break; |
|
268 |
} |
|
11430 | 269 |
case MSG_NICKNAME: { |
270 |
m_myNickname = QString::fromUtf8(msg); |
|
271 |
break; |
|
272 |
} |
|
11431 | 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 |
} |
|
11433 | 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 |
} |
|
11437 | 305 |
case MSG_AMMO: { |
306 |
emit ammoChanged(QString::fromUtf8(msg)); |
|
307 |
break; |
|
308 |
} |
|
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
|
309 |
} |
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
310 |
} |
10416 | 311 |
|
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
312 |
QString HWEngine::currentSeed() |
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
313 |
{ |
10430 | 314 |
return QString::fromLatin1(flibGetSeed()); |
10416 | 315 |
} |
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
316 |
|
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
317 |
void HWEngine::fillModels() |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
318 |
{ |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
319 |
QStringList resultModel; |
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 |
char ** themes = flibGetThemesList(); |
10616 | 322 |
for (char **i = themes; *i != NULL; i++) |
323 |
resultModel << QString::fromUtf8(*i); |
|
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
324 |
flibFreeThemesList(themes); |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
325 |
|
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
10432
diff
changeset
|
326 |
m_engine->rootContext()->setContextProperty("themesModel", QVariant::fromValue(resultModel)); |
10612 | 327 |
|
10616 | 328 |
// scripts model |
10612 | 329 |
resultModel.clear(); |
10616 | 330 |
for (char **i = flibGetScriptsList(); *i != NULL; i++) |
331 |
resultModel << QString::fromUtf8(*i); |
|
10612 | 332 |
|
333 |
m_engine->rootContext()->setContextProperty("scriptsModel", QVariant::fromValue(resultModel)); |
|
10616 | 334 |
|
335 |
// schemes model |
|
336 |
resultModel.clear(); |
|
337 |
for (char **i = flibGetSchemesList(); *i != NULL; i++) |
|
338 |
resultModel << QString::fromUtf8(*i); |
|
339 |
||
340 |
m_engine->rootContext()->setContextProperty("schemesModel", QVariant::fromValue(resultModel)); |
|
10888 | 341 |
|
342 |
// ammos model |
|
343 |
resultModel.clear(); |
|
344 |
for (char **i = flibGetAmmosList(); *i != NULL; i++) |
|
345 |
resultModel << QString::fromUtf8(*i); |
|
346 |
||
347 |
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
|
348 |
} |
10442 | 349 |
|
350 |
void HWEngine::getTeamsList() |
|
351 |
{ |
|
352 |
char ** teams = flibGetTeamsList(); |
|
353 |
for (char **i = teams; *i != NULL; i++) { |
|
354 |
QString team = QString::fromUtf8(*i); |
|
355 |
||
356 |
emit localTeamAdded(team, 0); |
|
357 |
} |
|
358 |
} |
|
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
|
359 |
|
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10442
diff
changeset
|
360 |
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
|
361 |
{ |
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10442
diff
changeset
|
362 |
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
|
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 |
|
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 |
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
|
366 |
{ |
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 |
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
|
368 |
} |
10450 | 369 |
|
370 |
void HWEngine::resetGameConfig() |
|
371 |
{ |
|
372 |
flibResetGameConfig(); |
|
373 |
} |
|
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
374 |
|
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
375 |
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
|
376 |
{ |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
377 |
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
|
378 |
} |
10456 | 379 |
|
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
10888
diff
changeset
|
380 |
void HWEngine::connect(const QString &host, quint16 port) |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
10888
diff
changeset
|
381 |
{ |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
10888
diff
changeset
|
382 |
flibConnectOfficialServer(); |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
10888
diff
changeset
|
383 |
} |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
10888
diff
changeset
|
384 |
|
11416 | 385 |
void HWEngine::sendChatMessage(const QString &msg) |
386 |
{ |
|
387 |
flibSendChatLine(msg.toUtf8().constData()); |
|
388 |
} |
|
389 |
||
11423 | 390 |
void HWEngine::joinRoom(const QString &roomName) |
391 |
{ |
|
392 |
flibJoinRoom(roomName.toUtf8().constData()); |
|
393 |
} |
|
394 |
||
11424 | 395 |
void HWEngine::partRoom(const QString &message) |
396 |
{ |
|
397 |
flibPartRoom(message.toUtf8().constData()); |
|
398 |
} |
|
399 |
||
11430 | 400 |
QString HWEngine::myNickname() |
401 |
{ |
|
402 |
return m_myNickname; |
|
403 |
} |
|
404 |
||
10456 | 405 |
void HWEngine::setTheme(const QString &theme) |
406 |
{ |
|
407 |
flibSetTheme(theme.toUtf8().constData()); |
|
408 |
} |
|
10612 | 409 |
|
410 |
void HWEngine::setScript(const QString &script) |
|
411 |
{ |
|
412 |
flibSetScript(script.toUtf8().constData()); |
|
413 |
} |
|
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10616
diff
changeset
|
414 |
|
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10616
diff
changeset
|
415 |
void HWEngine::setScheme(const QString &scheme) |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10616
diff
changeset
|
416 |
{ |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10616
diff
changeset
|
417 |
flibSetScheme(scheme.toUtf8().constData()); |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10616
diff
changeset
|
418 |
} |
10888 | 419 |
|
420 |
void HWEngine::setAmmo(const QString &ammo) |
|
421 |
{ |
|
422 |
flibSetAmmo(ammo.toUtf8().constData()); |
|
423 |
} |