Skip to content

Commit

Permalink
UI improvements, project generator fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Klemmbaustein committed Aug 3, 2024
1 parent 7637ea1 commit 913b440
Show file tree
Hide file tree
Showing 23 changed files with 98 additions and 46 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,4 +382,4 @@
### Fixes
- Fixed some issues with point lights.
- Fixed issues with shadows.
- Fixed an issue with the default movement.
- Fixed an issue with the default movement.
2 changes: 2 additions & 0 deletions EngineSource/Engine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<ClCompile Include="UI\Default\ScrollObject.cpp" />
<ClCompile Include="UI\Default\TextRenderer.cpp" />
<ClCompile Include="UI\EditorUI\SerializePanel.cpp" />
<ClCompile Include="UI\EditorUI\Tabs\CSharpErrorList.cpp" />
<ClCompile Include="UI\UICanvas.cpp" />
<ClCompile Include="UI\EditorUI\ContextMenu.cpp" />
<ClCompile Include="UI\EditorUI\EditorPanel.cpp" />
Expand Down Expand Up @@ -252,6 +253,7 @@
<ClInclude Include="UI\Default\TextRenderer.h" />
<ClInclude Include="UI\Default\TextSegment.h" />
<ClInclude Include="UI\EditorUI\SerializePanel.h" />
<ClInclude Include="UI\EditorUI\Tabs\CSharpErrorList.h" />
<ClInclude Include="UI\UICanvas.h" />
<ClInclude Include="UI\EditorUI\ContextMenu.h" />
<ClInclude Include="UI\EditorUI\EditorPanel.h" />
Expand Down
2 changes: 2 additions & 0 deletions EngineSource/Engine/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ namespace Application
std::string StartupSceneOverride;
bool ShowStartupInfo = true;

int Initialize(int argc, char** argv);

bool ShouldClose = false;

void Quit()
Expand Down
2 changes: 0 additions & 2 deletions EngineSource/Engine/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ namespace Application

extern bool ShowStartupInfo;

int Initialize(int argc, char** argv);

/**
* @brief
* DeInitializes the engine, quits the application.
Expand Down
1 change: 1 addition & 0 deletions EngineSource/Engine/EngineError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void Error::PrintStackTrace()
auto trace = std::stacktrace::current();
if (trace.empty())
{
Log::Print("[Error]: No stack trace available. Missing debug symbols?", Log::LogColor::Red);
return;
}
Log::Print("[Error]: ---------------------------------[Stack trace]---------------------------------", Log::LogColor::Red);
Expand Down
2 changes: 1 addition & 1 deletion EngineSource/Engine/LaunchArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace LaunchArgs

std::map<std::string, void(*)(std::vector<std::string>)> Commands =
{
std::pair("neverHideConsole", &NeverHideConsole),
std::pair("neverhideconsole", &NeverHideConsole),
std::pair("scene", &LoadScene),
std::pair("novsync", &NoVSync),
std::pair("wireframe", &Wireframe),
Expand Down
2 changes: 1 addition & 1 deletion EngineSource/Engine/Subsystem/CSharpInterop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ CSharpInterop::CSharpInterop()

#if ENGINE_NO_SOURCE && !SERVER
Window::SetWindowTitle(CSharpInterop::StaticCall<const char*>(
CSharpInterop::CSharpSystem->LoadCSharpFunction("GetNameInternally", "Engine", "StringDelegate")
CSharpInterop::CSharpSystem->LoadCSharpFunction("GetNameInternally", "Engine.Core.Engine", "StringDelegate")
));
#endif
}
Expand Down
13 changes: 6 additions & 7 deletions EngineSource/UI/EditorUI/ContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,10 @@ void ContextMenu::OnResized()
}

BackgroundBox->AddChild((new UIText(0.55f, EditorUI::UIColors[2], "Object: " + SelectedObject->Name, EditorUI::Text))
->SetWrapEnabled(true, Scale.X * 2.0f - 0.1f, UIBox::SizeMode::ScreenRelative)
->SetWrapEnabled(true, Scale.X - 0.1f, UIBox::SizeMode::ScreenRelative)
->SetPadding(0.01f, 0, 0.01f, 0.01f));
BackgroundBox->AddChild((new UIText(0.45f, EditorUI::UIColors[2], "Class: " + SelectedObject->GetObjectDescription().Name, EditorUI::Text))
->SetWrapEnabled(true, Scale.X * 2.0f - 0.1f, UIBox::SizeMode::ScreenRelative)
->SetWrapEnabled(true, Scale.X - 0.1f, UIBox::SizeMode::ScreenRelative)
->SetPadding(0.005f, 0, 0.01f, 0.01f));
BackgroundBox->AddChild((new UIBackground(UIBox::Orientation::Horizontal,
0,
Expand Down Expand Up @@ -605,15 +605,14 @@ void ContextMenu::OnResized()
{
BackgroundBox->AddChild((new UIText(0.55f, EditorUI::UIColors[2], "Scene: "
+ FileUtil::GetFileNameWithoutExtensionFromPath(Scene::CurrentScene), EditorUI::Text))
->SetWrapEnabled(true, Scale.X * 2.0f - 0.1f, UIBox::SizeMode::ScreenRelative)
->SetWrapEnabled(true, Scale.X - 0.1f, UIBox::SizeMode::ScreenRelative)
->SetPadding(0.01f, 0, 0.01f, 0.01f));
BackgroundBox->AddChild((new UIText(0.45f, EditorUI::UIColors[2], "Path: " + Scene::CurrentScene + ".jscn", EditorUI::Text))
->SetWrapEnabled(true, Scale.X * 2.0f - 0.1f, UIBox::SizeMode::ScreenRelative)
->SetPadding(0.005f, 0, 0.01f, 0.01f));
BackgroundBox->AddChild((new UIBackground(UIBox::Orientation::Horizontal,
0,
EditorUI::UIColors[2],
Vector2(Scale.X - 0.005f, 2.0f / Graphics::WindowResolution.Y)))
Vector2(1)))
->SetSizeMode(UIBox::SizeMode::PixelRelative)
->SetTryFill(true)
->SetPadding(0, 0.005f, 0.0025f, 0));


Expand Down
9 changes: 6 additions & 3 deletions EngineSource/UI/EditorUI/EditorPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void EditorPanel::HandlePanelDrag(int Index)

void EditorPanel::OnButtonClicked(int Index)
{
if (Tabs[Index] != UI::HoveredBox)
if (Tabs[Index] != UI::HoveredBox && Children.size())
{
delete Children[Index];
return;
Expand Down Expand Up @@ -422,8 +422,11 @@ void EditorPanel::AddTab(EditorPanel* NewTab, ChildrenType Align, size_t TabPosi
NewPanel->AddTab(this);
}
Parent->ActiveTab = std::min(TabPosition, Parent->Children.size() - 1);
NewTab->Size = NewPanel->Scale.Y / 2;
Size = NewPanel->Size / 2;

float NewSize = Align == ChildrenType::Horizontal ? PanelMainBackground->GetUsedSize().X : PanelMainBackground->GetUsedSize().Y;

NewTab->Size = NewSize / 2;
Size = NewTab->Size;
GetAbsoluteParent()->ReSort();
GetAbsoluteParent()->OnPanelResized();
}
Expand Down
32 changes: 22 additions & 10 deletions EngineSource/UI/EditorUI/EditorUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace Editor
bool Async = false;
};

static void ReadProcessPipe(FILE* p, ProcessInfo* Info)
static int ReadProcessPipe(FILE* p, ProcessInfo* Info)
{
std::string CurrentMessage;
while (!feof(p))
Expand All @@ -118,9 +118,14 @@ namespace Editor
CurrentMessage.append({ NewChar });
}
}
fclose(p);

#if _WIN32
int ret = _pclose(p);
#else
int ret = pclose(p);
#endif
Info->Active = false;

return ret;
}
}

Expand Down Expand Up @@ -242,13 +247,17 @@ void EditorUI::LaunchInEditor()
|| std::filesystem::last_write_time("CSharp/Build/CSharpAssembly.dll") < FileUtil::GetLastWriteTimeOfFolder("Scripts", { "obj" }))
&& CSharpInterop::GetUseCSharp())
{
RebuildAssembly();
if (!RebuildAssembly())
{
Log::Print("Failed to build C# assembly.", Log::LogColor::Red);
return;
}
}
#endif
}
catch (std::exception& e)
{
Log::Print("Exception thrown when trying to check for rebuild. " + std::string(e.what()));
Log::Print("Exception thrown when trying to check for rebuild. " + std::string(e.what()), Log::LogColor::Red);
return;
}

Expand All @@ -267,6 +276,8 @@ void EditorUI::LaunchInEditor()
StrUtil::ReplaceChar(ExecutablePath, '\\', "/");
#endif

// -nostartupinfo: Do not show any version information on startup, this just clutters the editor log.
// -nocolor: Do not print any color. The editor log ignores it anyways, and on Linux this just puts color codes everywhere.
std::string CommandLine = ExecutablePath + " -nostartupinfo -nocolor -editorPath " + Application::GetEditorPath() + " " + Args;

if (LaunchWithServer)
Expand Down Expand Up @@ -335,12 +346,13 @@ void EditorUI::SetSaveSceneOnLaunch(bool NewValue)
}

#ifdef ENGINE_CSHARP
void EditorUI::RebuildAssembly()
bool EditorUI::RebuildAssembly()
{
Editor::ReloadingCSharp = true;
PipeProcessToLog("cd Scripts && dotnet build", "[C#]: [Build]: ");
bool Success = PipeProcessToLog("cd Scripts && dotnet build", "[C#]: [Build]: ") == 0;
Editor::ReloadingCSharp = false;
Editor::CanHotreload = true;
Editor::CanHotreload = Success;
return Success;
}
#endif

Expand Down Expand Up @@ -483,7 +495,7 @@ void EditorUI::LoadPanelLayout(EditorPanel* From)
RootPanel = From;
}

void EditorUI::PipeProcessToLog(std::string Command, std::string Prefix)
int EditorUI::PipeProcessToLog(std::string Command, std::string Prefix)
{
using namespace Editor;

Expand All @@ -500,7 +512,7 @@ void EditorUI::PipeProcessToLog(std::string Command, std::string Prefix)
proc.Command = Command;
proc.Pipe = process;

ReadProcessPipe(process, &proc);
return ReadProcessPipe(process, &proc);
}

void EditorUI::CreateFile(std::string Path, std::string Name, std::string Ext)
Expand Down
4 changes: 2 additions & 2 deletions EngineSource/UI/EditorUI/EditorUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class EditorUI : public EditorSubsystem
* @brief
* Rebuilds the project's CSharpAssembly and reloads it.
*/
static void RebuildAssembly();
static bool RebuildAssembly();
#endif

/**
Expand Down Expand Up @@ -126,7 +126,7 @@ class EditorUI : public EditorSubsystem
* @param Prefix
* Log prefix added to the output of the command.
*/
static void PipeProcessToLog(std::string Command, std::string Prefix = "");
static int PipeProcessToLog(std::string Command, std::string Prefix = "");

/**
* @brief
Expand Down
6 changes: 3 additions & 3 deletions EngineSource/UI/EditorUI/ItemBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void ItemBrowser::GenerateTopBox()
->SetSizeMode(UIBox::SizeMode::AspectRelative));

TopBox->AddChild((new UIText(0.45f, EditorUI::UIColors[2], Path, EditorUI::Text))
->SetWrapEnabled(true, Scale.X * 1.2f, UIBox::SizeMode::ScreenRelative)
->SetWrapEnabled(true, Scale.X - 0.1f / Graphics::AspectRatio, UIBox::SizeMode::ScreenRelative)
->SetPadding(0.005f));
}

Expand Down Expand Up @@ -265,7 +265,7 @@ void ItemBrowser::GenerateAssetList()
->SetSizeMode(UIBox::SizeMode::AspectRelative)
->SetPaddingSizeMode(UIBox::SizeMode::AspectRelative))
->AddChild((new UIText(0.38f, EditorUI::UIColors[2], Item.Name, EditorUI::Text))
->SetWrapEnabled(true, 0.23f, UIBox::SizeMode::AspectRelative)
->SetWrapEnabled(true, 0.12f, UIBox::SizeMode::AspectRelative)
->SetPadding(0, 0, 0.005f, 0.005f)
->SetPaddingSizeMode(UIBox::SizeMode::AspectRelative)));
Index++;
Expand All @@ -274,7 +274,7 @@ void ItemBrowser::GenerateAssetList()
if (LoadedItems.empty())
{
HorizontalBoxes[0]->AddChild((new UIText(0.45f, EditorUI::UIColors[2], EmptyText, EditorUI::Text))
->SetWrapEnabled(true, Scale.X * 2.0f - 0.1f, UIBox::SizeMode::ScreenRelative)
->SetWrapEnabled(true, Scale.X - 0.1f, UIBox::SizeMode::ScreenRelative)
->SetPadding(0.01f));
}
}
Expand Down
6 changes: 4 additions & 2 deletions EngineSource/UI/EditorUI/LogUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

static float LogTextSize = 0.38f;
static std::vector<UIBox*> LogElements;
LogUI* LogUI::Current = nullptr;

void LogUI::UpdateLogBoxSize()
{
Expand Down Expand Up @@ -52,6 +53,7 @@ LogUI::LogUI(EditorPanel* Parent) : EditorPanel(Parent, "Console", "log")
CommandsBackground
->SetOpacity(0.95f)
->AddChild(CommandHighlightScrollBox);
Current = this;

UpdateLogBoxSize();
}
Expand All @@ -63,7 +65,7 @@ void LogUI::OnResized()
{
for (UIText* i : LogTexts)
{
i->SetWrapEnabled(true, 1.75f * LogScrollBox->GetUsedSize().X, UIBox::SizeMode::ScreenRelative);
i->SetWrapEnabled(true, LogScrollBox->GetUsedSize().X - 0.05f, UIBox::SizeMode::ScreenRelative);
}
ResetScroll();
}
Expand Down Expand Up @@ -166,7 +168,7 @@ void LogUI::Tick()
LogTexts.push_back((new UIText(LogTextSize, LogMessages.at(PrevLogLength).Color, Text, EditorUI::MonoText)));

LogScrollBox->AddChild(LogTexts.at(LogTexts.size() - 1)
->SetWrapEnabled(true, 1.75f * LogScrollBox->GetUsedSize().X, UIBox::SizeMode::ScreenRelative)
->SetWrapEnabled(true, LogScrollBox->GetUsedSize().X, UIBox::SizeMode::ScreenRelative)
->SetPadding(-0.001f, PrevLogLength == LogMessages.size() - 1 ? 0.015f : -0.001f, 0.001f, 0.001f));
PrevAmount = LogMessages.at(LogMessages.size() - 1).Amount;
}
Expand Down
3 changes: 3 additions & 0 deletions EngineSource/UI/EditorUI/LogUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class LogUI : public EditorPanel
void UpdateLogBoxSize();
void UpdateAutoComplete();
public:

static LogUI* Current;

LogUI(EditorPanel* Parent);
void OnResized() override;

Expand Down
2 changes: 1 addition & 1 deletion EngineSource/UI/EditorUI/Popups/ClassCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void ClassCreator::Create(std::string Name, std::string Namespace, ClassType New
case ClassCreator::ClassType::CPlusPlus:
std::filesystem::copy(Application::GetEditorPath() + "/EditorContent/CodeTemplates/Class.h", "Code/Objects/Class.h");
std::filesystem::copy(Application::GetEditorPath() + "/EditorContent/CodeTemplates/Class.cpp", "Code/Objects/Class.cpp");
system("\"..\\..\\Tools\\bin\\Bui.ldToolexe\" in=../../EngineSource/Objects in=Code/Objects out=GeneratedIncludes");
system("\"..\\..\\Tools\\bin\\BuildToolexe\" in=../../EngineSource/Objects in=Code/Objects out=GeneratedIncludes");
system(("cd ../.. && ProjectGenerator.exe -projectName " + Build::GetProjectBuildName() + " -onlyBuildFiles").c_str());
break;
#endif
Expand Down
4 changes: 2 additions & 2 deletions EngineSource/UI/EditorUI/Popups/DialogBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ DialogBox::DialogBox(std::string Title, Vector2 Position, std::string Message, s
: EditorPopup(Position, 0.3f, Title)
{
PopupBackground->AddChild((new UIText(0.45f, EditorUI::UIColors[2], Message, EditorUI::Text))
->SetWrapEnabled(true, (PopupBackground->GetMinSize().X - 0.04f) * 1.8f, UIBox::SizeMode::ScreenRelative)
->SetPadding(0.02f));
->SetWrapEnabled(true, (PopupBackground->GetMinSize().X - 0.1f), UIBox::SizeMode::ScreenRelative)
->SetPadding(0.01f));
SetOptions(Answers);
}

Expand Down
7 changes: 6 additions & 1 deletion EngineSource/UI/EditorUI/StatusBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <UI/EditorUI/Popups/DialogBox.h>
#include <UI/EditorUI/Popups/ClassCreator.h>
#include <UI/EditorUI/Popups/BakeMenu.h>
#include <UI/EditorUI/Tabs/CSharpErrorList.h>
#include <UI/EditorUI/LogUI.h>
#include <thread>
#include "Viewport.h"
#include <Engine/Subsystem/BackgroundTask.h>
Expand Down Expand Up @@ -104,7 +106,10 @@ static std::vector<MenuBarItem> MenuBarItems =
MenuBarItem("C#",
{
MenuBarEntry("Open Solution", []() { OS::OpenFile(Build::GetProjectBuildName() + ".sln"); }),
MenuBarEntry("Rebuild C# Assembly", []() { new BackgroundTask(EditorUI::RebuildAssembly); }, true),
MenuBarEntry("Rebuild C# Assembly", []() { new BackgroundTask(EditorUI::RebuildAssembly); }),
#if 0
MenuBarEntry("Error List", []() { LogUI::Current->AddTab(new CSharpErrorList()); }, true),
#endif
MenuBarEntry("New Class", []() { new ClassCreator(); }),
}),
#endif
Expand Down
14 changes: 14 additions & 0 deletions EngineSource/UI/EditorUI/Tabs/CSharpErrorList.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#if EDITOR && ENGINE_CSHARP
#include "CSharpErrorList.h"

CSharpErrorList::CSharpErrorList()
: EditorPanel(0, 0, "C# Error List", "csharp_errors")
{
CanBeClosed = true;
}

void CSharpErrorList::Tick()
{
}

#endif
13 changes: 13 additions & 0 deletions EngineSource/UI/EditorUI/Tabs/CSharpErrorList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#if EDITOR && ENGINE_CSHARP
#pragma once
#include "../EditorPanel.h"

class CSharpErrorList : public EditorPanel
{
public:
CSharpErrorList();

void Tick() override;
};

#endif
4 changes: 2 additions & 2 deletions EngineSource/UI/EditorUI/Tabs/MaterialTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ void MaterialTab::GenerateUI()
->SetMinSize(Vector2(DescriptionSize, 0.1f))
->SetPadding(0.005f)
->AddChild((new UIText(0.5f, EditorUI::UIColors[2], i.UniformName, EditorUI::MonoText))
->SetWrapEnabled(true, DescriptionSize * 1.6f, UIBox::SizeMode::ScreenRelative)
->SetWrapEnabled(true, DescriptionSize, UIBox::SizeMode::ScreenRelative)
->SetPadding(0.005f))
->AddChild((new UIText(0.4f, Vector3::Lerp(EditorUI::UIColors[2], 0.5f, 0.25f), Description, EditorUI::Text))
->SetWrapEnabled(true, DescriptionSize * 1.6f, UIBox::SizeMode::ScreenRelative)
->SetWrapEnabled(true, DescriptionSize, UIBox::SizeMode::ScreenRelative)
->SetPadding(0.005f)));

ParamBox->AddChild((new UIBackground(UIBox::Orientation::Horizontal, 0, EditorUI::UIColors[0] * 0.75f, Vector2(2.0f / Graphics::WindowResolution.X, 0)))
Expand Down
2 changes: 1 addition & 1 deletion EngineSource/UI/UIText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ float UIText::GetRenderedSize() const

float UIText::GetWrapDistance() const
{
float Distance = WrapDistance;
float Distance = WrapDistance * 2;
if (WrapSizeMode == SizeMode::AspectRelative)
{
Distance /= Graphics::AspectRatio;
Expand Down
Loading

0 comments on commit 913b440

Please sign in to comment.