From b774f08097e034c03d069f87ba81a328ed85e9e4 Mon Sep 17 00:00:00 2001 From: parax0 Date: Wed, 16 Mar 2016 21:31:27 -0600 Subject: [PATCH] Implemented spawn layer on the create tab --- src/Editor/WorldEditor/WCreateTab.cpp | 33 +++++++++++++++++++++++---- src/Editor/WorldEditor/WCreateTab.h | 6 +++++ src/Editor/WorldEditor/WCreateTab.ui | 4 ++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/Editor/WorldEditor/WCreateTab.cpp b/src/Editor/WorldEditor/WCreateTab.cpp index fe950800..a3b4714c 100644 --- a/src/Editor/WorldEditor/WCreateTab.cpp +++ b/src/Editor/WorldEditor/WCreateTab.cpp @@ -4,11 +4,14 @@ #include "CWorldEditor.h" #include "Editor/Undo/UndoCommands.h" -WCreateTab::WCreateTab(QWidget *parent) : - QWidget(parent), - ui(new Ui::WCreateTab) +WCreateTab::WCreateTab(QWidget *parent) + : QWidget(parent) + , ui(new Ui::WCreateTab) + , mpSpawnLayer(nullptr) { ui->setupUi(this); + + connect(ui->SpawnLayerComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(OnSpawnLayerChanged(int))); } WCreateTab::~WCreateTab() @@ -39,7 +42,7 @@ bool WCreateTab::eventFilter(QObject *pObj, QEvent *pEvent) if (pMimeData) { CVector3f SpawnPoint = mpEditor->Viewport()->HoverPoint(); - CCreateInstanceCommand *pCmd = new CCreateInstanceCommand(mpEditor, pMimeData->Template(), mpEditor->ActiveArea()->GetScriptLayer(0), SpawnPoint); + CCreateInstanceCommand *pCmd = new CCreateInstanceCommand(mpEditor, pMimeData->Template(), mpSpawnLayer, SpawnPoint); mpEditor->UndoStack()->push(pCmd); return true; } @@ -53,9 +56,31 @@ void WCreateTab::SetEditor(CWorldEditor *pEditor) { mpEditor = pEditor; pEditor->Viewport()->installEventFilter(this); + connect(mpEditor, SIGNAL(LayersModified()), this, SLOT(OnLayersChanged())); } void WCreateTab::SetMaster(CMasterTemplate *pMaster) { ui->TemplateView->SetMaster(pMaster); } + +// ************ PUBLIC SLOTS ************ +void WCreateTab::OnLayersChanged() +{ + CGameArea *pArea = mpEditor->ActiveArea(); + + ui->SpawnLayerComboBox->blockSignals(true); + ui->SpawnLayerComboBox->clear(); + + for (u32 iLyr = 0; iLyr < pArea->GetScriptLayerCount(); iLyr++) + ui->SpawnLayerComboBox->addItem(TO_QSTRING(pArea->GetScriptLayer(iLyr)->Name())); + + ui->SpawnLayerComboBox->blockSignals(false); + ui->SpawnLayerComboBox->setCurrentIndex(0); +} + +void WCreateTab::OnSpawnLayerChanged(int LayerIndex) +{ + CGameArea *pArea = mpEditor->ActiveArea(); + mpSpawnLayer = pArea->GetScriptLayer(LayerIndex); +} diff --git a/src/Editor/WorldEditor/WCreateTab.h b/src/Editor/WorldEditor/WCreateTab.h index cff70a2c..25a73f5b 100644 --- a/src/Editor/WorldEditor/WCreateTab.h +++ b/src/Editor/WorldEditor/WCreateTab.h @@ -13,6 +13,7 @@ class WCreateTab : public QWidget { Q_OBJECT CWorldEditor *mpEditor; + CScriptLayer *mpSpawnLayer; public: explicit WCreateTab(QWidget *parent = 0); @@ -20,6 +21,11 @@ public: bool eventFilter(QObject *, QEvent *); void SetEditor(CWorldEditor *pEditor); void SetMaster(CMasterTemplate *pMaster); + +public slots: + void OnLayersChanged(); + void OnSpawnLayerChanged(int LayerIndex); + private: Ui::WCreateTab *ui; }; diff --git a/src/Editor/WorldEditor/WCreateTab.ui b/src/Editor/WorldEditor/WCreateTab.ui index 1113891d..154fa562 100644 --- a/src/Editor/WorldEditor/WCreateTab.ui +++ b/src/Editor/WorldEditor/WCreateTab.ui @@ -35,14 +35,14 @@ - + Spawn Layer: - + 1