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