1 // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
4 #include "MainWindow.h"
9 #include <qpushbutton.h>
11 #include <CrySchematyc2/IFramework.h>
12 #include <CrySchematyc2/Script/IScriptRegistry.h>
14 #include "GenericWidget.h"
15 #include "LegacyOpenDlg.h"
16 #include "LegacyOpenDlgModel.h"
18 //////////////////////////////////////////////////////////////////////////
20 namespace SchematycEd
{
22 REGISTER_VIEWPANE_FACTORY(CMainWindow
, "Schematyc Editor (Reworked)", "Tools", false)
24 CMainWindow::CMainWindow()
25 : CAssetEditor(QStringList
{ "SchematycEntity", "SchematycLibrary" })
26 , m_pLegacyOpenDlg(nullptr)
27 , m_pAddComponentButton(nullptr)
29 EnableDockingSystem();
35 CMainWindow::~CMainWindow()
37 FinishLegacyOpenDlg();
38 FinishGenericWidgets();
41 void CMainWindow::CreateDefaultLayout(CDockableContainer
* pSender
)
45 //auto pComponentsWidget = pSender->SpawnWidget("Generic0");
46 //auto pVariablesWidget = pSender->SpawnWidget("Generic1", QToolWindowAreaReference::VSplitRight);
48 //auto pGraphsWidget = pSender->SpawnWidget("Generic2", pComponentsWidget, QToolWindowAreaReference::HSplitBottom);
49 //auto pSignalsAndTypesWidget = pSender->SpawnWidget("Generic3", pGraphsWidget, QToolWindowAreaReference::HSplitBottom);
52 void CMainWindow::OnOpenLegacy()
54 m_pLegacyOpenDlg
->exec();
57 void CMainWindow::OnOpenLegacyClass(CAbstractDictionaryEntry
& classEntry
)
59 CLegacyOpenDlgEntry
& legacyEntry
= static_cast<CLegacyOpenDlgEntry
&>(classEntry
);
61 Schematyc2::IScriptFile
* pScriptFile
= gEnv
->pSchematyc2
->GetScriptRegistry().GetFile(legacyEntry
.GetFullName().toLatin1().data());
64 Schematyc2::IScriptClass
* pScriptClass
= pScriptFile
->GetClass(legacyEntry
.GetTypeGUID());
65 for (auto pWidget
: m_genericWidgets
)
67 pWidget
->setWindowTitle(pScriptClass
->GetName());
68 pWidget
->LoadClass(pScriptFile
->GetGUID(), pScriptClass
->GetGUID());
72 m_pLegacyOpenDlg
->done(0);
75 void CMainWindow::InitLegacyOpenDlg()
77 QAction
* const pAction
= GetMenu(MenuItems::FileMenu
)->CreateAction(tr("Open Legacy"), 0, 0);
78 connect(pAction
, &QAction::triggered
, this, &CMainWindow::OnOpenLegacy
);
80 m_pLegacyOpenDlg
= new CLegacyOpenDlg();
81 connect(m_pLegacyOpenDlg
->GetDialogDictWidget(), &CDictionaryWidget::OnEntryDoubleClicked
, this, &CMainWindow::OnOpenLegacyClass
);
84 void CMainWindow::FinishLegacyOpenDlg()
86 m_pLegacyOpenDlg
->deleteLater();
89 void CMainWindow::InitGenericWidgets()
91 //RegisterDockableWidget("Generic0", std::bind(&CMainWindow::CreateWidgetTemplateFunc, this, "<Empty>"), true, false);
92 //RegisterDockableWidget("Generic1", std::bind(&CMainWindow::CreateWidgetTemplateFunc, this, "<Empty>"), true, false);
93 //RegisterDockableWidget("Generic2", std::bind(&CMainWindow::CreateWidgetTemplateFunc, this, "<Empty>"), true, false);
94 //RegisterDockableWidget("Generic3", std::bind(&CMainWindow::CreateWidgetTemplateFunc, this, "<Empty>"), true, false);
97 void CMainWindow::FinishGenericWidgets()
99 for (auto pWidget
: m_genericWidgets
)
101 pWidget
->deleteLater();
103 m_genericWidgets
.clear();
107 QWidget
* CMainWindow::CreateWidgetTemplateFunc(const char* name
)
109 m_genericWidgets
.push_back(CGenericWidget::Create());
110 m_genericWidgets
.back()->setWindowTitle(name
);
112 return m_genericWidgets
.back();
115 } //namespace SchematycEd