Skip to content

Commit

Permalink
Fixed release build crash + more
Browse files Browse the repository at this point in the history
- Hazelnut will now prompt to open project on startup if no command line args are set
- Fixed crash when editing already set script module class name
- Added UI::ScopedStyleColor utility class
  • Loading branch information
TheCherno committed Dec 5, 2022
1 parent 8b80550 commit bba1220
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 17 deletions.
5 changes: 4 additions & 1 deletion Hazel/src/Hazel/Scripting/ScriptEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,11 @@ namespace Hazel {
Scope<filewatch::FileWatch<std::string>> AppAssemblyFileWatcher;
bool AssemblyReloadPending = false;

#ifdef HZ_DEBUG
bool EnableDebugging = true;

#else
bool EnableDebugging = false;
#endif
// Runtime

Scene* SceneContext = nullptr;
Expand Down
35 changes: 35 additions & 0 deletions Hazel/src/Hazel/UI/UI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include <imgui/imgui.h>

namespace Hazel::UI {

struct ScopedStyleColor
{
ScopedStyleColor() = default;

ScopedStyleColor(ImGuiCol idx, ImVec4 color, bool predicate = true)
: m_Set(predicate)
{
if (predicate)
ImGui::PushStyleColor(idx, color);
}

ScopedStyleColor(ImGuiCol idx, ImU32 color, bool predicate = true)
: m_Set(predicate)
{
if (predicate)
ImGui::PushStyleColor(idx, color);
}

~ScopedStyleColor()
{
if (m_Set)
ImGui::PopStyleColor();
}
private:
bool m_Set = false;
};


}
39 changes: 28 additions & 11 deletions Hazelnut/src/EditorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ namespace Hazel {
else
{
// TODO(Yan): prompt the user to select a directory
NewProject();
// NewProject();

// If no project is opened, close Hazelnut
// NOTE: this is while we don't have a new project path
if (!OpenProject())
Application::Get().Close();

}

m_EditorCamera = EditorCamera(30.0f, 1.778f, 0.1f, 1000.0f);
Expand Down Expand Up @@ -187,21 +193,22 @@ namespace Hazel {
{
if (ImGui::BeginMenu("File"))
{
// Disabling fullscreen would allow the window to be moved to the front of other windows,
// which we can't undo at the moment without finer window depth/z control.
//ImGui::MenuItem("Fullscreen", NULL, &opt_fullscreen_persistant);1
if (ImGui::MenuItem("New", "Ctrl+N"))
NewScene();
if (ImGui::MenuItem("Open Project...", "Ctrl+O"))
OpenProject();

if (ImGui::MenuItem("Open...", "Ctrl+O"))
OpenScene();
ImGui::Separator();

if (ImGui::MenuItem("Save", "Ctrl+S"))
if (ImGui::MenuItem("New Scene", "Ctrl+N"))
NewScene();

if (ImGui::MenuItem("Save Scene", "Ctrl+S"))
SaveScene();

if (ImGui::MenuItem("Save As...", "Ctrl+Shift+S"))
if (ImGui::MenuItem("Save Scene As...", "Ctrl+Shift+S"))
SaveSceneAs();

ImGui::Separator();

if (ImGui::MenuItem("Exit"))
Application::Get().Close();

Expand Down Expand Up @@ -446,7 +453,7 @@ namespace Hazel {
case Key::O:
{
if (control)
OpenScene();
OpenProject();

break;
}
Expand Down Expand Up @@ -597,6 +604,16 @@ namespace Hazel {
}
}

bool EditorLayer::OpenProject()
{
std::string filepath = FileDialogs::OpenFile("Hazel Project (*.hproj)\0*.hproj\0");
if (filepath.empty())
return false;

OpenProject(filepath);
return true;
}

void EditorLayer::SaveProject()
{
// Project::SaveActive();
Expand Down
1 change: 1 addition & 0 deletions Hazelnut/src/EditorLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Hazel {
void OnOverlayRender();

void NewProject();
bool OpenProject();
void OpenProject(const std::filesystem::path& path);
void SaveProject();

Expand Down
10 changes: 5 additions & 5 deletions Hazelnut/src/Panels/SceneHierarchyPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Hazel/Scene/Components.h"

#include "Hazel/Scripting/ScriptEngine.h"
#include "Hazel/UI/UI.h"

#include <imgui/imgui.h>
#include <imgui/imgui_internal.h>
Expand Down Expand Up @@ -327,11 +328,13 @@ namespace Hazel {
static char buffer[64];
strcpy_s(buffer, sizeof(buffer), component.ClassName.c_str());

if (!scriptClassExists)
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.9f, 0.2f, 0.3f, 1.0f));
UI::ScopedStyleColor textColor(ImGuiCol_Text, ImVec4(0.9f, 0.2f, 0.3f, 1.0f), !scriptClassExists);

if (ImGui::InputText("Class", buffer, sizeof(buffer)))
{
component.ClassName = buffer;
return;
}

// Fields
bool sceneRunning = scene->IsRunning();
Expand Down Expand Up @@ -394,9 +397,6 @@ namespace Hazel {
}
}
}

if (!scriptClassExists)
ImGui::PopStyleColor();
});

DrawComponent<SpriteRendererComponent>("Sprite Renderer", entity, [](auto& component)
Expand Down

0 comments on commit bba1220

Please sign in to comment.