Skip to content

Commit

Permalink
[Editor] Create a new widget to manage scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
fabsgc committed Mar 1, 2024
1 parent f9cda05 commit 58797cc
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 23 deletions.
2 changes: 2 additions & 0 deletions Source/Examples/Editor/CMakeSources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ set (TE_EDITOR_INC_WIDGET
"Widget/TeWidgetProfiler.h"
"Widget/TeWidgetSettings.h"
"Widget/TeWidgetShaders.h"
"Widget/TeWidgetScripts.h"
)

set (TE_EDITOR_SRC_WIDGET
Expand All @@ -79,6 +80,7 @@ set (TE_EDITOR_SRC_WIDGET
"Widget/TeWidgetProfiler.cpp"
"Widget/TeWidgetSettings.cpp"
"Widget/TeWidgetShaders.cpp"
"Widget/TeWidgetScripts.cpp"
)

set (TE_EDITOR_INC_MATERIALS_PREVIEW
Expand Down
12 changes: 10 additions & 2 deletions Source/Examples/Editor/TeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "Widget/TeWidgetConsole.h"
#include "Widget/TeWidgetViewport.h"
#include "Widget/TeWidgetResources.h"
#include "Widget/TeWidgetScripts.h"
#include "Widget/TeWidgetTextEditor.h"
#include "Widget/TeWidgetMaterials.h"
#include "Widget/TeWidgetShaders.h"
Expand Down Expand Up @@ -106,6 +107,9 @@ namespace te
const String Editor::MeshesExtensionsStr = ".obj,.dae,.fbx,.stl,.gltf,.glb";
const String Editor::SoundsExtensionsStr = ".ogg,.flac,.wav";

Event<void()> Editor::OnOpen;
Event<void()> Editor::OnSave;

const Vector<UINT32> Editor::ComponentsWhichNeedGuizmo = {
TID_CRenderable,
TID_CRigidBody,
Expand Down Expand Up @@ -459,7 +463,7 @@ namespace te
_widgets.emplace_back(te_unique_ptr_new<WidgetSettings>()); _settings.WSettings = _widgets.back();
_widgets.emplace_back(te_unique_ptr_new<WidgetRenderOptions>()); _settings.WRenderOptions = _widgets.back();
_widgets.emplace_back(te_unique_ptr_new<WidgetConsole>()); _settings.WConsole = _widgets.back();
_widgets.emplace_back(te_unique_ptr_new<WidgetScriptEditor>()); _settings.WScript = _widgets.back();
_widgets.emplace_back(te_unique_ptr_new<WidgetScripts>()); _settings.WScript = _widgets.back();
_widgets.emplace_back(te_unique_ptr_new<WidgetShaders>()); _settings.WShaders = _widgets.back();
_widgets.emplace_back(te_unique_ptr_new<WidgetMaterials>()); _settings.WMaterials = _widgets.back();
_widgets.emplace_back(te_unique_ptr_new<WidgetResources>()); _settings.WResources = _widgets.back();
Expand Down Expand Up @@ -636,9 +640,9 @@ namespace te
ImGui::DockBuilderDockWindow(CONSOLE_TITLE, dockBottomId);
ImGui::DockBuilderDockWindow(RESOURCES_TITLE, dockBottomId);
ImGui::DockBuilderDockWindow(VIEWPORT_TITLE, dockMainId);
ImGui::DockBuilderDockWindow(SCRIPT_TITLE, dockMainId);
ImGui::DockBuilderDockWindow(SHADERS_TITLE, dockRightBottomId);
ImGui::DockBuilderDockWindow(MATERIALS_TITLE, dockRightBottomId);
ImGui::DockBuilderDockWindow(SCRIPTS_TITLE, dockLeftBottomId);
ImGui::DockBuilderDockWindow(PROPERTIES_TITLE, dockLeftBottomId);
ImGui::DockBuilderFinish(dockMainId);
}
Expand Down Expand Up @@ -913,6 +917,8 @@ namespace te
_project = static_resource_cast<Project>(multiResourceScene->Entries[0].Res);
_project->SetPath(path);

OnOpen();

return true;
}

Expand All @@ -933,6 +939,8 @@ namespace te

_settings.State = EditorState::Saved;

OnSave();

return true;
}

Expand Down
3 changes: 3 additions & 0 deletions Source/Examples/Editor/TeEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ namespace te
static const String MeshesExtensionsStr;
static const String SoundsExtensionsStr;

static Event<void()> OnOpen;
static Event<void()> OnSave;

protected:
static const Vector<UINT32> ComponentsWhichNeedGuizmo;

Expand Down
6 changes: 4 additions & 2 deletions Source/Examples/Editor/Widget/TeWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#define RESOURCES_TITLE ICON_FA_SUITCASE " Resources"
#define TOOLBAR_TITLE "ToolBar"
#define VIEWPORT_TITLE ICON_FA_IMAGE " Viewport"
#define SCRIPT_TITLE ICON_FA_SCROLL " Script"
#define EDITOR_TITLE ICON_FA_CODE " Editor"
#define SCRIPTS_TITLE ICON_FA_SCROLL " Scripts"
#define MATERIALS_TITLE ICON_FA_PALETTE " Materials"
#define PROFILER_TITLE ICON_FA_CHART_LINE " Profiler"
#define SETTINGS_TITLE ICON_FA_COGS " Settings"
Expand All @@ -45,11 +46,12 @@ namespace te
ToolBar,
Viewport,
Resources,
Script,
Editor,
Material,
Profiler,
Settings,
Shaders,
Scripts,
None
};

Expand Down
4 changes: 2 additions & 2 deletions Source/Examples/Editor/Widget/TeWidgetMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ namespace te
widget->SetVisible(!widget->GetVisible());
}

if (ImGui::MenuItem(ICON_FA_SCROLL " " ICON_FA_GRIP_LINES_VERTICAL " Script"))
if (ImGui::MenuItem(ICON_FA_SCROLL " " ICON_FA_GRIP_LINES_VERTICAL " Scripts"))
{
Widget* widget = static_cast<Widget*>(gEditor().GetWidget(WidgetType::Script));
Widget* widget = static_cast<Widget*>(gEditor().GetWidget(WidgetType::Scripts));
if (widget)
widget->SetVisible(!widget->GetVisible());
}
Expand Down
23 changes: 23 additions & 0 deletions Source/Examples/Editor/Widget/TeWidgetScripts.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "TeWidgetScripts.h"

namespace te
{
WidgetScripts::WidgetScripts()
: Widget(WidgetType::Scripts)
{
_title = SCRIPTS_TITLE;
_flags |= ImGuiWindowFlags_HorizontalScrollbar;
}

WidgetScripts::~WidgetScripts()
{ }

void WidgetScripts::Initialize()
{ }

void WidgetScripts::Update()
{ }

void WidgetScripts::UpdateBackground()
{ }
}
19 changes: 19 additions & 0 deletions Source/Examples/Editor/Widget/TeWidgetScripts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include "TeCorePrerequisites.h"
#include "../TeEditor.h"
#include "TeWidget.h"

namespace te
{
class WidgetScripts : public Widget
{
public:
WidgetScripts();
virtual ~WidgetScripts();

virtual void Initialize() override;
virtual void Update() override;
virtual void UpdateBackground() override;
};
}
26 changes: 13 additions & 13 deletions Source/Examples/Editor/Widget/TeWidgetTextEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@

namespace te
{
WidgetScriptEditor::WidgetScriptEditor()
: Widget(WidgetType::Script)
WidgetTextEditor::WidgetTextEditor()
: Widget(WidgetType::Editor)
, _selections(gEditor().GetSelectionData())
, _editor(nullptr)
, _needsSave(false)
{
_title = SCRIPT_TITLE;
_title = EDITOR_TITLE;
}

WidgetScriptEditor::~WidgetScriptEditor()
WidgetTextEditor::~WidgetTextEditor()
{ }

void WidgetScriptEditor::Initialize()
void WidgetTextEditor::Initialize()
{
_editor = te_shared_ptr_new<ImGuiTextEditor>();
}

void WidgetScriptEditor::Update()
void WidgetTextEditor::Update()
{
const auto& scripts = gScriptManager().GetScripts();
for (const auto& script : scripts)
Expand All @@ -47,10 +47,10 @@ namespace te
}
}

void WidgetScriptEditor::UpdateBackground()
void WidgetTextEditor::UpdateBackground()
{ }

void WidgetScriptEditor::PutFocus()
void WidgetTextEditor::PutFocus()
{
Widget::PutFocus();

Expand All @@ -76,7 +76,7 @@ namespace te
}
}

void WidgetScriptEditor::Save(bool force)
void WidgetTextEditor::Save(bool force)
{
if (!_currentScriptName.empty() && (_needsSave || force))
{
Expand All @@ -93,7 +93,7 @@ namespace te
}
}

void WidgetScriptEditor::Build()
void WidgetTextEditor::Build()
{
if (!_currentScriptName.empty())
{
Expand All @@ -109,7 +109,7 @@ namespace te
}
}

void WidgetScriptEditor::UpdateEditorContent()
void WidgetTextEditor::UpdateEditorContent()
{
if (_currentScriptName != "")
{
Expand All @@ -129,14 +129,14 @@ namespace te
}
}

void WidgetScriptEditor::ShowEditor()
void WidgetTextEditor::ShowEditor()
{
ImGui::BeginChild("ScriptEditor", ImVec2(ImGui::GetContentRegionAvail().x, ImGui::GetWindowHeight() - 90.0f), false);
_editor->Render("Title", ImVec2(0.0f, ImGui::GetContentRegionMax().y)); // shrink y to bring the compile button into view
ImGui::EndChild();
}

void WidgetScriptEditor::ShowToolbar()
void WidgetTextEditor::ShowToolbar()
{
auto ShowButton = [this](const char* title, bool enabled, const std::function<void()>& action)
{
Expand Down
6 changes: 3 additions & 3 deletions Source/Examples/Editor/Widget/TeWidgetTextEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace te
class ImGuiTextEditor;


class WidgetScriptEditor : public Widget
class WidgetTextEditor : public Widget
{
public:
WidgetScriptEditor();
virtual ~WidgetScriptEditor();
WidgetTextEditor();
virtual ~WidgetTextEditor();

virtual void Initialize() override;
virtual void Update() override;
Expand Down
2 changes: 1 addition & 1 deletion Source/Examples/Editor/Widget/TeWidgetViewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace te

protected:
static const float MIN_TIME_BETWEEN_UPDATE;

protected:
HEvent _resizeEvent;
Editor::SelectionData& _selections;
Expand Down

0 comments on commit 58797cc

Please sign in to comment.