-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMainWindow.cpp
More file actions
884 lines (768 loc) · 33.4 KB
/
CMainWindow.cpp
File metadata and controls
884 lines (768 loc) · 33.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
#ifdef _WIN32
#include <WinSock2.h>
#endif
// Include QT
//#include <QtWidgets>
#include <QThread>
#include <QProcess>
#include <QBoxLayout>
#include <QLayoutItem>
#include <QStringList>
#include <QFile>
#include <QTextStream>
#include <QDirModel>
#include <QMouseEvent>
#include <QString>
#include <QDebug>
#include <QFileDialog>
#include <QMessageBox>
//#include <GL/glew.h>
#include <vector>
#include <string>
#ifdef __linux__
//linux code goes here
#elif _WIN32
#include <Windows.h>
// windows code goes here
#endif
#include "LudoMuse_src/Classes/AppDelegate.h"
#include "CocosQtPort/CCQApplication.h"
#include "CocosQtPort/CCQGLView.h"
#include "CocosQtPort/CCQGLWidget.h"
// Include custom classes
#include "CMainWindow.h"
#include "ui_CMainWindow.h"
#include "CEditorKernel.h"
#include "CThreadCocos.h"
#include "CThumbnailWidget.h"
#include "CLabelInspector.h"
#include "CSpriteInspector.h"
#include "CTeamNodeInspector.h"
#include "CSoundInspector.h"
#include "CSceneInspector.h"
#include "CDashboardInspector.h"
#include "CMenuNodeInspector.h"
#include "CAddSceneWizard.h"
#include "CLoaderWidget.h"
#include "CProjectManager.h"
#include "CThumbnailsLoaderThread.h"
#include "CTimelineWidget.h"
#include "CExplorerView.h"
#include "CMacroWidget.h"
// Include cocos
#include "cocos2d.h"
// Include LudoMuse
#include "Classes/Engine/Include/CNode.h"
#include "Classes/Engine/Include/CSceneNode.h"
#include "Classes/Engine/Include/CSequenceNode.h"
#include "Classes/Engine/Include/CEntityNode.h"
#include "Classes/Engine/Include/CSpriteNode.h"
#include "Classes/Engine/Include/CMenuNode.h"
#include "Classes/Engine/Include/CCallback.h"
#include "Classes/Engine/Include/CEditorFindEntityTouchVisitor.h"
#include "Classes/Modules/Util/Include/Util.h"
CMainWindow::CMainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::CMainWindow),
m_pKernel(NULL),
m_sSaveName(""),
m_oArchiver(this)
{
ui->setupUi(this);
setWindowIcon(QIcon(CProjectManager::Instance()->QGetInstallPath().append("/resources/icon.png")));
setWindowTitle("LudoMuseEditor");
// Init with loader widget
ui->mmBotView->setVisible(false);
ui->toolBarCocos->setVisible(false);
ui->sceneInspectorContainer->setVisible(false);
ui->toolBarInspector->setVisible(false);
ui->scrollInspector->setVisible(false);
CLoaderWidget* loaderWidget = new CLoaderWidget();
ui->glViewContainer->layout()->addWidget(loaderWidget);
connect(loaderWidget, SIGNAL(closeEditor()), this, SLOT(close()));
connect(loaderWidget, SIGNAL(loadProject(const QString&)), this, SLOT(loadExistingProject(const QString&)));
// ui->sceneInspectorContainer->setStyleSheet("#sceneInspectorContainer{background-color : rgb(50, 50, 50);border-right : 1px solid white }");
// disable save button
if(m_sSaveName.isEmpty())
{
ui->save->setEnabled(false);
}
// Icon creation
ui->emulateButton->setIcon(QIcon(CProjectManager::Instance()->QGetInstallPath().append("/resources/play_arrow.png")));
ui->archiveButton->setIcon(QIcon(CProjectManager::Instance()->QGetInstallPath().append("/resources/ic_action_export.png")));
// Create Template Manager
this->m_pTemplatesManager = CTemplateManager::Instance();
// Connect Tool bar
connect(ui->prevScreenButton, SIGNAL(clicked(bool)), this, SLOT(goToPreviousScene()));
connect(ui->nextScreenButton, SIGNAL(clicked(bool)), this, SLOT(goToNextScene()));
connect(ui->dashboardButton, SIGNAL(clicked(bool)), this, SLOT(goToDashBoard()));
connect(ui->waitingScreenButton, SIGNAL(clicked(bool)), this, SLOT(goToWaitingScreen()));
connect(ui->emulateButton, SIGNAL(clicked(bool)), this, SLOT(launchEmulator()));
connect(ui->JsonGo, SIGNAL(clicked(bool)), this, SLOT(saveAs()));
connect(ui->save, SIGNAL(clicked(bool)), this, SLOT(save()));
//connect(ui->lmwTestButton, SIGNAL(clicked(bool)), this, SLOT(launchAddSceneWizard()));
//connect(ui->archiveButton, SIGNAL(clicked(bool)), this, SLOT(exportProject));
// Connect kernel signal
connect(CEditorKernel::Instance(), SIGNAL(sendMenuNodeSignal(LM::CMenuNode*)), this, SLOT(receiveMenu(LM::CMenuNode*)));
this->showMaximized();
}
CMainWindow::~CMainWindow()
{
delete ui;
}
void CMainWindow::loadExistingProject(const QString& a_sProjectFile)
{
// Update CprojetManager
CProjectManager::Instance()->SetProjectFile(a_sProjectFile);
m_sSaveName = a_sProjectFile;
ui->save->setEnabled(true);
// Clear loader widget!
QLayout* glViewContainerLayout = ui->glViewContainer->layout();
QLayoutItem *child;
while ((child = glViewContainerLayout->takeAt(0)) != 0) {
delete child->widget();
delete child;
}
ui->mmBotView->setVisible(true);
ui->scrollInspector->setVisible(true);
ui->sceneInspectorContainer->setVisible(true);
// ui->sceneInspectorContainer->setStyleSheet("#sceneInspectorContainer{background-color : rgb(50, 50, 50);border-right :none}");
ui->toolBarCocos->setVisible(true);
ui->toolBarInspector->setVisible(true);
// ui->toolBarCocos->setStyleSheet("#toolBarCocos{border-bottom: 1px solid black;border-right : 2px solid rgba(255,255,255,255);}");
ui->inspectorContainer->layout()->setAlignment(Qt::AlignTop);
QString projectPath = QFileInfo(a_sProjectFile).absolutePath();
setWindowTitle(QString("LudoMuseEditor -- ") + a_sProjectFile);
// m_pDirModel = new QFileSystemModel();
// m_pDirModel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs);
// m_pDirModel->setRootPath(projectPath);
// ui->fileBrowser->setModel(m_pDirModel);
// ui->fileBrowser->setRootIndex(m_pDirModel->index(projectPath));
// ui->fileBrowser->setColumnHidden( 1, true );
// ui->fileBrowser->setColumnHidden( 2, true );
// ui->fileBrowser->setColumnHidden( 3, true );
// m_pFileModel = new QFileSystemModel(this);
// m_pFileModel->setFilter(QDir::NoDotAndDotDot | QDir::Files);
// ui->fileListView->setModel(m_pFileModel);
// ui->fileListView->setRootIndex(m_pFileModel->setRootPath(projectPath));
// ui->fileListView->SetCurrentPath(projectPath);
ui->explorer->SetProjectPath(projectPath);
AppDelegate* app = (AppDelegate*)(cocos2d::CCQApplication::getInstance());
app->setPath(m_sSaveName.toStdString());
QFileInfo tempFile(projectPath + "/" + CProjectManager::Instance()->QGetProjectName() + ".tmp");
if (tempFile.exists())
{
int i = QMessageBox::critical(this, tr("Oups !"),
tr("Il semble que LudoMuseEditor n'a pas été correctement fermé à la dernière édition de ce scénario. Voulez vous le restaurer ?\nSi vous choisissez non, les modifications seront définitvement perdues."),
QMessageBox::No | QMessageBox::Escape, QMessageBox::Yes | QMessageBox::Default);
if (i == QMessageBox::Yes)
{
app->setPath(tempFile.absoluteFilePath().toStdString());
}
else
{
QFile removeTempFile(tempFile.absoluteFilePath());
removeTempFile.remove();
}
}
app->setParentWidget(ui->glViewContainer);
cocos2d::CCQApplication::getInstance()->run();
m_pKernel = app->getKernel();
LM::CEditorFindEntityTouchVisitor* dummyVisitor= this->m_pKernel->GetEditorVisitor();
connect(dummyVisitor, SIGNAL(labelClicked(LM::CLabelNode*)), this, SLOT(receiveLabel(LM::CLabelNode*)));
connect(dummyVisitor, SIGNAL(spriteClicked(LM::CSpriteNode*)), this, SLOT(receiveSprite(LM::CSpriteNode*)));
connect(dummyVisitor, SIGNAL(teamNodeClicked(LM::CTeamNode*)), this, SLOT(receiveTeamNode(LM::CTeamNode*)));
// connect(m_pKernel, SIGNAL(addingSceneFinished(std::string, int)), this, SLOT(addingSceneFinished(std::string, int)));
// connect(m_pKernel, SIGNAL(deletingSceneFinished()), this, SLOT(deletingSceneFinished()));
connect(m_pKernel, SIGNAL(addingSceneFinished(const QString, const QString, int)),
this, SLOT(addingSceneFinished(const QString, const QString, int)));
connect(m_pKernel, SIGNAL(addingSharedSceneFinished(QString,QString,QString)),
this, SLOT(addingSharedSceneFinished(QString,QString,QString)));
connect(m_pKernel, SIGNAL(deletingSceneFinished(const QString)),
this, SLOT(deletingSceneFinished(const QString)));
connect(m_pKernel, SIGNAL(sendScene(LM::CSceneNode*, bool)),
this, SLOT(receiveScene(LM::CSceneNode*, bool)));
connect(m_pKernel, SIGNAL(captureFinished(QString)),
this, SLOT(loadCapture(QString)));
m_pTimeline = new CTimelineWidget(ui->timelineContainer);
ui->timelineContainer->layout()->addWidget(m_pTimeline);
connect(m_pTimeline, SIGNAL(thumbnailSelected()),
this, SLOT(changeScene()));
connect(m_pTimeline, SIGNAL(saveThumbnail()),
this, SLOT(saveCapture()));
this->ProcessTree();
InspectScene(m_pKernel->m_pCurrentScene);
m_pTimeline->SetCurrentPlayer(m_pKernel->GetActivePlayer());
m_pTimeline->SelectThumbnail(QString::fromStdString(m_pKernel->m_pCurrentScene->GetSceneID()));
m_pTimeline->UpdateTimeline();
m_pTimeline->LoadPreviews();
// ui->macros->Init();
ui->macros->SetKernel(m_pKernel);
ui->macros->Init();
connect(ui->macros, SIGNAL(macroModified()), this, SLOT(reloadScene()));
connect(ui->macros, SIGNAL(deleteClicked()), this, SLOT(clearInspectorContainer()));
// CExplorerView *cev = new CExplorerView(projectPath);
}
void CMainWindow::receiveLabel(LM::CLabelNode* a_pLabel)
{
//qDebug("Reception d'un Label");
this->InspectLabel(a_pLabel);
}
void CMainWindow::receiveSprite(LM::CSpriteNode* a_pSprite)
{
this->InspectSprite(a_pSprite);
}
void CMainWindow::receiveTeamNode(LM::CTeamNode* a_pTeamNode)
{
this->InspectTeamNode(a_pTeamNode);
}
void CMainWindow::receiveMenu(LM::CMenuNode* a_pMenuNode)
{
qDebug("received CMenuNode");
this->InspectMenuNode(a_pMenuNode);
}
void CMainWindow::receiveScene(LM::CSceneNode *a_pScene, bool a_bIsNav)
{
this->clearSceneInspector();
this->InspectScene(a_pScene);
/* if(a_bIsNav)
{
qDebug("navigation transition -> changing active thumbnail");
this->activeThumbnail(QString(a_pScene->GetSceneID().c_str()), m_iActivePlayer);
}*/
}
void CMainWindow::clearInspectorContainer()
{
QLayout* inspectorContainerLayout = this->ui->inspectorContainer->layout();
QLayoutItem *child;
while ((child = inspectorContainerLayout->takeAt(0)) != 0) {
child->widget()->close();
// child->widget()->deleteLater();
// delete child;
}
this->setInspectorName("");
}
void CMainWindow::clearSceneInspector()
{
QLayout* sceneInspectorLayout = this->ui->sceneInspectorContainer->layout();
QLayoutItem *child;
while ((child = sceneInspectorLayout->takeAt(0)) != 0) {
child->widget()->close();
}
}
void CMainWindow::ShowCurrentScene()
{
clearInspectorContainer();
LM::SEvent dummyEvent(LM::SEvent::NONE, nullptr, m_pTimeline->GetCurrentSceneID().toStdString(), true, m_pTimeline->GetCurrentPlayer());
ON_CC_THREAD(LM::CKernel::GotoScreenID, this->m_pKernel, dummyEvent, nullptr);
}
void CMainWindow::changeScene()
{
// saveCapture();
ShowCurrentScene();
}
void CMainWindow::goToNextScene()
{
saveCapture();
m_pTimeline->SelectNextThumbnail();
ShowCurrentScene();
}
void CMainWindow::goToPreviousScene()
{
saveCapture();
m_pTimeline->SelectPrevThumbnail();
ShowCurrentScene();
}
void CMainWindow::goToDashBoard()
{
clearInspectorContainer();
m_pTimeline->UnselectThumbnails();
ON_CC_THREAD(LM::CKernel::GotoDashboard, this->m_pKernel);
}
void CMainWindow::goToWaitingScreen()
{
clearInspectorContainer();
m_pTimeline->UnselectThumbnails();
ON_CC_THREAD(LM::CKernel::GotoWaitingScene, this->m_pKernel);
}
void CMainWindow::addOneScene(const QString &a_sPreviousID, const QString &a_sNewID, int a_iPlayerID, CTemplate* a_pTemplate)
{
// m_iActivePlayer = a_iPlayerID;
ON_CC_THREAD(LM::CKernel::AddNewScene, m_pKernel, a_pTemplate->GetPath().toStdString(),
a_sPreviousID.toStdString(), a_sNewID.toStdString(), a_iPlayerID, 0, "");
// m_pKernel->AddNewScene( a_pTemplate->GetPath().toStdString(),
// a_sPreviousID.toStdString(), a_sNewID.toStdString(), a_iPlayerID, 0, "");
}
void CMainWindow::addTwoScene(const QString &a_sPreviousIDP1, const QString &a_sNewIDP1,
const QString &a_sPreviousIDP2, const QString &a_sNewIDP2,
CTemplate* a_pTemplate)
{
ON_CC_THREAD(LM::CKernel::AddNewScene, m_pKernel, a_pTemplate->GetPath().toStdString(),
a_sPreviousIDP1.toStdString(), a_sNewIDP1.toStdString(), PLAYER_1, 0, "");
ON_CC_THREAD(LM::CKernel::AddNewScene, m_pKernel, a_pTemplate->GetPath().toStdString(),
a_sPreviousIDP2.toStdString(), a_sNewIDP2.toStdString(), PLAYER_2, 0, "");
// m_pKernel->AddNewScene(a_pTemplate->GetPath().toStdString(),
// a_sPreviousIDP1.toStdString(), a_sNewIDP1.toStdString(), PLAYER_1, 0, "");
// m_pKernel->AddNewScene(a_pTemplate->GetPath().toStdString(),
// a_sPreviousIDP2.toStdString(), a_sNewIDP2.toStdString(), PLAYER_2, 0, "");
}
void CMainWindow::addSharedScene(const QString &a_sPreviousIDP1, const QString &a_sPreviousIDP2,
const QString &a_sNewIDP, CTemplate* a_pTemplate)
{
ON_CC_THREAD(LM::CKernel::AddNewSharedScene, m_pKernel, a_pTemplate->GetPath().toStdString(),
a_sPreviousIDP1.toStdString(), a_sPreviousIDP2.toStdString(), a_sNewIDP.toStdString(), 0, "");
}
void CMainWindow::addGameScene(const QString &a_sPreviousIDP1, const QString &a_sNewIDP1,
const QString &a_sPreviousIDP2, const QString &a_sNewIDP2,
CTemplate* a_pTemplate, int a_iTemplateNumberP1, int a_iTemplateNumberP2)
{
ON_CC_THREAD(LM::CKernel::AddSyncID, m_pKernel, a_sNewIDP1.toStdString(), a_sNewIDP2.toStdString());
ON_CC_THREAD(LM::CKernel::AddNewScene, m_pKernel, a_pTemplate->GetPath().toStdString(),
a_sPreviousIDP1.toStdString(), a_sNewIDP1.toStdString(), PLAYER_1, a_iTemplateNumberP1, a_sNewIDP2.toStdString());
ON_CC_THREAD(LM::CKernel::AddNewScene, m_pKernel, a_pTemplate->GetPath().toStdString(),
a_sPreviousIDP2.toStdString(), a_sNewIDP2.toStdString(), PLAYER_2, a_iTemplateNumberP2, a_sNewIDP1.toStdString());
// m_pKernel->AddNewScene(a_pTemplate->GetPath().toStdString(),
// a_sPreviousIDP1.toStdString(), a_sNewIDP1.toStdString(), PLAYER_1, a_iTemplateNumberP1, a_sNewIDP2.toStdString());
// m_pKernel->AddNewScene(a_pTemplate->GetPath().toStdString(),
// a_sPreviousIDP2.toStdString(), a_sNewIDP2.toStdString(), PLAYER_2, a_iTemplateNumberP2, a_sNewIDP1.toStdString());
// m_pKernel->AddSyncID(a_sNewIDP1.toStdString(), a_sNewIDP2.toStdString());
}
void CMainWindow::deleteScene(QString a_sSceneID, bool a_bIsSync)
{
clearInspectorContainer();
if(!a_bIsSync)
{
ON_CC_THREAD(LM::CKernel::DeleteScene, this->m_pKernel, a_sSceneID.toStdString());
// m_pKernel->DeleteScene(a_sSceneID.toStdString());
}
else
{
ON_CC_THREAD(LM::CKernel::DeleteSyncScenes, this->m_pKernel, a_sSceneID.toStdString());
// m_pKernel->DeleteSyncScenes(a_sSceneID.toStdString());
}
}
void CMainWindow::launchEmulator()
{
QString execPath = CProjectManager::Instance()->QGetInstallPath() + "/LudoMuse";
QString jsonPath = CProjectManager::Instance()->QGetProjectPath() + CProjectManager::Instance()->QGetProjectName() + ".tmp";
produceJson(jsonPath);
// QString cmd = execPath + " server " + CProjectManager::Instance()->QGetProjectJsonFile();
//QString cmd = execPath + " server " + jsonPath;
m_oProcessServer.setProgram(execPath);
QStringList oArgsServer;
oArgsServer << "server" << jsonPath;
m_oProcessServer.setArguments(oArgsServer);
m_oProcessClient.setProgram(execPath);
QStringList oArgsClient;
oArgsClient << "client" << jsonPath;
m_oProcessClient.setArguments(oArgsClient);
QString sLogServer = CProjectManager::Instance()->QGetAbsoluteWritablePath() + "/server.log";
QString sLogClient = CProjectManager::Instance()->QGetAbsoluteWritablePath() + "/client.log";
m_oProcessServer.setStandardOutputFile(sLogServer);
m_oProcessServer.setStandardErrorFile(sLogServer);
m_oProcessClient.setStandardOutputFile(sLogClient);
m_oProcessClient.setStandardErrorFile(sLogClient);
m_oProcessServer.start();
QThread::sleep(2);
// cmd = execPath + " client " + CProjectManager::Instance()->QGetProjectJsonFile();
// cmd = execPath + " client " + jsonPath;
m_oProcessClient.start();
}
void CMainWindow::saveAs()
{
QString filePath = QFileDialog::getSaveFileName(this, "Save File",
CProjectManager::Instance()->QGetProjectPath(),
"Scénarios Ludomuse (*.json)");
if (!filePath.isNull())
{
// Covering empty result
QFileInfo fileInfo(filePath);
if(fileInfo.fileName() == ".json" || fileInfo.fileName().startsWith("."))
{
filePath = fileInfo.absolutePath() + "/Default_save_name.json";
}
// Forcing extension
if(!filePath.endsWith(".json"))
{
filePath = filePath + ".json";
}
this->m_sSaveName = filePath;
this->ui->save->setEnabled(true);
save();
CProjectManager::Instance()->SetProjectFile(filePath);
}
}
void CMainWindow::save()
{
this->produceJson(this->m_sSaveName);
QFile tempFile(CProjectManager::Instance()->QGetProjectPath() + "/" +
CProjectManager::Instance()->QGetProjectName() + ".tmp");
if (tempFile.exists())
{
tempFile.remove();
}
}
void CMainWindow::exportProject(const QString& a_rDestination)
{
if (!a_rDestination.isEmpty())
{
std::string projectFolder = CProjectManager::Instance()->GetProjectPath();
m_oArchiver.CompressFolder(projectFolder.substr(0, projectFolder.length()-1), a_rDestination.toStdString());
}
}
void CMainWindow::produceJson(const QString& a_rFileName){
QString jsonResult;
QFile file( a_rFileName );
if ( file.open(QIODevice::ReadWrite | QFile::Truncate) )
{
QTextStream stream( &file );
stream.setCodec("UTF-8");
jsonResult = QString::fromUtf8(this->m_pKernel->ToJson().c_str());
stream << jsonResult;
stream.flush();
file.close();
}
//this->ui->jsonDisplayer->setText("Parsing finished");
}
void CMainWindow::launchAddSceneWizard()
{
CAddSceneWizard* pSceneWizard;
pSceneWizard = new CAddSceneWizard(m_pTimeline->GetCurrentScenePlayer(),
m_pKernel->GetSceneIDPlayer(PLAYER_1),
m_pKernel->GetSceneIDPlayer(PLAYER_2),
this,
m_pTimeline->GetPlayerSceneID(PLAYER_1),
m_pTimeline->GetPlayerSceneID(PLAYER_2),
m_pKernel);
connect(pSceneWizard, SIGNAL(addOneScene(QString,QString,int,CTemplate*)), this, SLOT(addOneScene(QString,QString,int,CTemplate*)));
// connect(pSceneWizard, SIGNAL(addTwoScene(QString,QString,QString,QString,CTemplate*)),
// this, SLOT(addTwoScene(QString,QString,QString,QString,CTemplate*)));
connect(pSceneWizard, SIGNAL(addSharedScene(QString, QString, QString, CTemplate*)),
this, SLOT(addSharedScene(QString,QString,QString,CTemplate*)));
connect(pSceneWizard, SIGNAL(addGameScene(QString,QString,QString,QString,CTemplate*,int,int)),
this, SLOT(addGameScene(QString,QString,QString,QString,CTemplate*,int,int)));
pSceneWizard->setModal(true);
pSceneWizard->show();
}
void CMainWindow::addingSceneFinished(const QString& a_sPrevSceneID, const QString& a_sSceneID, int a_iPlayerID)
{
saveCapture();
qDebug() << "Scene : " << a_sSceneID << " - Synced : " << m_pKernel->GetSyncedScene(a_sSceneID);
m_pTimeline->InsertScene(a_sPrevSceneID, a_sSceneID, a_iPlayerID, m_pKernel->GetSyncedScene(a_sSceneID));
m_pTimeline->UpdateTimeline();
ShowCurrentScene();
}
void CMainWindow::addingSharedSceneFinished(const QString& a_sPrevSceneID1, const QString& a_sPrevSceneID2, const QString& a_sSceneID)
{
saveCapture();
m_pTimeline->InsertSharedScene(a_sPrevSceneID1, a_sPrevSceneID2, a_sSceneID);
m_pTimeline->UpdateTimeline();
ShowCurrentScene();
}
void CMainWindow::deletingSceneFinished(const QString a_sSceneID)
{
m_pTimeline->RemoveScene(a_sSceneID);
m_pTimeline->UpdateTimeline();
ShowCurrentScene();
}
void CMainWindow::ProcessTree()
{
LM::CNode *mainNode = this->m_pKernel->GetBehaviorTree();
for(LM::CNode* currentNode : *mainNode)
{
LM::CSceneNode* currentSceneNode = (dynamic_cast<LM::CSceneNode*>(currentNode));
if(currentSceneNode)
{
QString sceneId(currentSceneNode->GetSceneID().c_str());
LM::CSceneNode* currentSceneNode = (dynamic_cast<LM::CSceneNode*>(currentNode));
if(currentSceneNode)
{
m_pTimeline->PushScene(sceneId, ScreenIDToPlayerID(sceneId), m_pKernel->GetSyncedScene(sceneId));
}
}
}
}
int CMainWindow::ScreenIDToPlayerID(const QString &a_id)
{
if (m_pKernel->PlayerHasScene(a_id.toStdString(), PLAYER_1))
{
if(m_pKernel->PlayerHasScene(a_id.toStdString(), PLAYER_2))
{
return BOTH_PLAYER;
}
return PLAYER_1;
}
return PLAYER_2;
}
void CMainWindow::InspectLabel(LM::CLabelNode* a_pLabel)
{
clearInspectorContainer();
// Clear inspector tool bar
this->setInspectorName("Éditeur de texte");
// Clear inspector layout from older inspection
QLayoutItem *child;
QLayout* inspectorContainerLayout = this->ui->inspectorContainer->layout();
// if(inspectorContainerLayout != Q_NULLPTR)
// {
// while ((child = inspectorContainerLayout->takeAt(0)) != 0) {
// delete child->widget();
// delete child;
// }
// }
CLabelInspector* inspector = new CLabelInspector(a_pLabel);
inspector->setAttribute( Qt::WA_DeleteOnClose );
inspectorContainerLayout->addWidget(inspector);
connect(inspector, SIGNAL(closeInspector()), this, SLOT(clearInspectorContainer()));
connect(inspector, SIGNAL(modifyLabel(LM::CEntityNode*)), this, SLOT(nodeModified(LM::CEntityNode*)));
}
void CMainWindow::InspectSprite(LM::CSpriteNode* a_pSprite)
{
clearInspectorContainer();
// Clear inspector tool bar
this->setInspectorName("Éditeur d'image");
// Clear inspector loayout from older inspection
QLayoutItem *child;
QLayout* inspectorContainerLayout = this->ui->inspectorContainer->layout();
// if(inspectorContainerLayout != Q_NULLPTR)
// {
// while ((child = inspectorContainerLayout->takeAt(0)) != 0) {
// delete child->widget();
// delete child;
// }
// }
CSpriteInspector* inspector = new CSpriteInspector(a_pSprite, this->ui->inspectorContainer);
CSoundInspector* soundInspector = new CSoundInspector(a_pSprite, this->ui->inspectorContainer);
inspector->setAttribute( Qt::WA_DeleteOnClose );
soundInspector->setAttribute( Qt::WA_DeleteOnClose );
soundInspector->hide();
inspectorContainerLayout->addWidget(inspector);
inspectorContainerLayout->addWidget(soundInspector);
connect(inspector, SIGNAL(callSoundInspector()), inspector, SLOT(hide()));
connect(inspector, SIGNAL(callSoundInspector()), soundInspector, SLOT(show()));
connect(soundInspector, SIGNAL(closeInspector()), inspector, SLOT(show()));
connect(soundInspector, SIGNAL(closeInspector()), soundInspector, SLOT(hide()));
connect(inspector, SIGNAL(closeInspector()), this, SLOT(clearInspectorContainer()));
connect(inspector, SIGNAL(modifySprite(LM::CEntityNode*)), this, SLOT(nodeModified(LM::CEntityNode*)));
connect(soundInspector, SIGNAL(modifySound(LM::CEntityNode*,QString,QString)), this, SLOT(nodeSoundModified(LM::CEntityNode*,QString,QString)));
connect(soundInspector, SIGNAL(removeSound(LM::CEntityNode*)), this, SLOT(nodeSoundRemoved(LM::CEntityNode*)));
}
void CMainWindow::InspectTeamNode(LM::CTeamNode* a_pTeamNode)
{
clearInspectorContainer();
// Clear inspector tool bar
this->setInspectorName("Éditeur de jeu en équipe");
// Clear inspector loayout from older inspection
QLayoutItem *child;
QLayout* inspectorContainerLayout = this->ui->inspectorContainer->layout();
// if(inspectorContainerLayout != Q_NULLPTR)
// {
// while ((child = inspectorContainerLayout->takeAt(0)) != 0) {
// delete child->widget();
// delete child;
// }
// }
CTeamNodeInspector* inspector = new CTeamNodeInspector(a_pTeamNode, this->ui->inspectorContainer);
inspector->setAttribute( Qt::WA_DeleteOnClose );
inspectorContainerLayout->addWidget(inspector);
connect(inspector, SIGNAL(closeInspector()), this, SLOT(clearInspectorContainer()));
connect(inspector, SIGNAL(modifyTeamNode(LM::CEntityNode*)), this, SLOT(nodeModified(LM::CEntityNode*)));
}
void CMainWindow::nodeModified(LM::CEntityNode* a_pNode)
{
LM::CSceneNode* pScene = a_pNode->GetParentSceneNode();
LM::CSceneNode* pSyncedScene = m_pKernel->GetSyncedScene(pScene);
if (pSyncedScene != nullptr)
{
std::string sSyncedID = a_pNode->GetHierarchyID();
if (sSyncedID != "")
{
LM::CEntityNode* pBaseNode = dynamic_cast<LM::CEntityNode*>
(pScene->FindChildByID(sSyncedID, true));
LM::CEntityNode* pSyncedNode = dynamic_cast<LM::CEntityNode*>
(pSyncedScene->FindChildByID(sSyncedID, true));
if (pSyncedNode)
{
int originalWidth = pSyncedNode->GetWidth();
int originalHeight = pSyncedNode->GetHeight();
pSyncedNode->Copy(pBaseNode);
pSyncedNode->SetWidth(originalWidth, false);
pSyncedNode->SetHeight(originalHeight, false);
}
}
}
produceJson(CProjectManager::Instance()->QGetProjectPath() + "/" +
CProjectManager::Instance()->QGetProjectName() + ".tmp");
}
void CMainWindow::nodeSoundModified(LM::CEntityNode* a_pNode, const QString& a_sEvent, const QString& a_sArgument)
{
LM::CEventCallback oCallback("PlaySound", m_pKernel, &LM::CKernel::PlaySoundCallback,
LM::SEvent(LM::SEvent::STRING, a_pNode, a_sArgument.toStdString()));
a_pNode->RemoveCallbacks("PlaySound");
a_pNode->AddListener(a_sEvent.toStdString(), oCallback);
LM::CSceneNode* pScene = a_pNode->GetParentSceneNode();
LM::CSceneNode* pSyncedScene = m_pKernel->GetSyncedScene(pScene);
if (pSyncedScene != nullptr)
{
std::string sSyncedID = a_pNode->GetID();
if (sSyncedID != "")
{
LM::CEntityNode* pSyncedNode = dynamic_cast<LM::CEntityNode*>
(pSyncedScene->FindChildByID(sSyncedID, true));
if (pSyncedNode)
{
pSyncedNode->RemoveCallbacks("PlaySound");
pSyncedNode->AddListener(a_sEvent.toStdString(), oCallback);
}
}
}
}
void CMainWindow::nodeSoundRemoved(LM::CEntityNode* a_pNode)
{
a_pNode->RemoveCallbacks("PlaySound");
LM::CSceneNode* pScene = a_pNode->GetParentSceneNode();
LM::CSceneNode* pSyncedScene = m_pKernel->GetSyncedScene(pScene);
if (pSyncedScene != nullptr)
{
std::string sSyncedID = a_pNode->GetID();
if (sSyncedID != "")
{
LM::CEntityNode* pSyncedNode = dynamic_cast<LM::CEntityNode*>
(pSyncedScene->FindChildByID(sSyncedID, true));
if (pSyncedNode)
{
pSyncedNode->RemoveCallbacks("PlaySound");
}
}
}
}
void CMainWindow::InspectScene(LM::CSceneNode* a_pScene)
{
// Clear inspector loayout from older inspection
// QLayoutItem *child;
// QLayout* inspectorContainerLayout = this->ui->sceneInspectorContainer->layout();
// if(inspectorContainerLayout != Q_NULLPTR)
// {
// while ((child = inspectorContainerLayout->takeAt(0)) != 0) {
// delete child->widget();
// delete child;
// }
// }
// Searching which player have the scene
QString sceneId(a_pScene->GetSceneID().c_str());
CSceneInspector* sceneInspector = Q_NULLPTR;
if(m_pKernel->PlayerHasScene(sceneId.toStdString(), PLAYER_1)
&& m_pKernel->PlayerHasScene(sceneId.toStdString(), PLAYER_2)) // P1 and P2
{
sceneInspector = new CSceneInspector(a_pScene, BOTH_PLAYER, ui->sceneInspectorContainer);
}
else if (m_pKernel->PlayerHasScene(sceneId.toStdString(), PLAYER_1)) // P1
{
sceneInspector = new CSceneInspector(a_pScene, PLAYER_1, ui->sceneInspectorContainer);
}
else if(m_pKernel->PlayerHasScene(sceneId.toStdString(), PLAYER_2)) // P2
{
sceneInspector = new CSceneInspector(a_pScene, PLAYER_2, ui->sceneInspectorContainer);
}
if(sceneInspector)
{
sceneInspector->setAttribute(Qt::WA_DeleteOnClose);
ui->sceneInspectorContainer->layout()->addWidget(sceneInspector);
connect(sceneInspector, SIGNAL(addScene()), this, SLOT(launchAddSceneWizard()));
connect(sceneInspector, SIGNAL(deleteScene(QString, bool)), this, SLOT(deleteScene(QString, bool)));
}
else
{
qDebug("Scene id is nowhere to be found, not in p1 neither in P2");
if (sceneId == "Dashboard")
{
CDashboardInspector* dashboardInspector = new CDashboardInspector(a_pScene, ui->sceneInspectorContainer);
dashboardInspector->setAttribute(Qt::WA_DeleteOnClose);
ui->sceneInspectorContainer->layout()->addWidget(dashboardInspector);
}
}
}
void CMainWindow::InspectMenuNode(LM::CMenuNode* a_pMenuNode)
{
clearInspectorContainer();
// Clear inspector tool bar
this->setInspectorName("Éditeur de bouton de Navigation");
// Clear inspector loayout from older inspection
QLayoutItem *child;
QLayout* inspectorContainerLayout = this->ui->inspectorContainer->layout();
// if(inspectorContainerLayout != Q_NULLPTR)
// {
// while ((child = inspectorContainerLayout->takeAt(0)) != 0) {
// delete child->widget();
// delete child;
// }
// }
CMenuNodeInspector* inspector = new CMenuNodeInspector(a_pMenuNode);
inspector->setAttribute(Qt::WA_DeleteOnClose);
inspectorContainerLayout->addWidget(inspector);
connect(inspector, SIGNAL(closeInspector()), this, SLOT(clearInspectorContainer()));
}
void CMainWindow::setInspectorName(const QString &a_rName)
{
QLayout* inspectorToolbarLayout = this->ui->toolBarInspector->layout();
QLayoutItem *child;
if(inspectorToolbarLayout != Q_NULLPTR)
{
while ((child = inspectorToolbarLayout->takeAt(0)) != 0) {
delete child->widget();
delete child;
}
}
else
{
inspectorToolbarLayout = new QHBoxLayout();
this->ui->toolBarInspector->setLayout(inspectorToolbarLayout);
}
QLabel* inspectorTitle = new QLabel(a_rName);
// inspectorTitle->setAlignment(Qt::AlignHCenter);
inspectorTitle->setAlignment(Qt::AlignCenter);
inspectorTitle->setStyleSheet("QLabel{color : white;}");
this->ui->toolBarInspector->layout()->addWidget(inspectorTitle);
}
//void CMainWindow::on_fileBrowser_clicked(const QModelIndex &index)
//{
// QString path = m_pDirModel->fileInfo(index).absoluteFilePath();
// ui->fileListView->setRootIndex(m_pFileModel->setRootPath(path));
// ui->fileListView->SetCurrentPath(path);
//}
void CMainWindow::saveCapture()
{
// ON_CC_THREAD(LM::CKernel::CaptureScreen, m_pKernel, CProjectManager::Instance()->GetProjectPath()+"thumbnails/");
ON_CC_THREAD(LM::CKernel::CaptureScreen, m_pKernel);
// m_pKernel->CaptureScreen();
}
void CMainWindow::loadCapture(QString a_sSceneID)
{
m_pTimeline->LoadPreview(a_sSceneID);
}
void CMainWindow::on_archiveButton_clicked()
{
QString dir = QFileDialog::getExistingDirectory(this, tr("Choisir l'emplacement de l'archive"), QDir::home().absolutePath(), QFileDialog::ShowDirsOnly);
exportProject(dir);
}
void CMainWindow::reloadScene()
{
m_pKernel->ReloadScreen();
}
void CMainWindow::closeEvent(QCloseEvent *a_oEvent)
{
QFile tempFile(CProjectManager::Instance()->QGetProjectPath() + "/" +
CProjectManager::Instance()->QGetProjectName() + ".tmp");
if (tempFile.exists())
{
int answer = QMessageBox::warning( this, tr("Modifications en cours"),
tr("Vous avez des modifications non sauvegardées,\nêtes vous sûr de vouloir quitter ?\n(les modifications seront perdues)"),
QMessageBox::Cancel | QMessageBox::Escape | QMessageBox::Default, QMessageBox::Yes);
if (answer == QMessageBox::Cancel)
{
a_oEvent->ignore();
return;
}
}
tempFile.remove();
a_oEvent->accept();
}