Skip to content

Commit

Permalink
Material picker (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij authored Jul 30, 2022
1 parent 1a9bec3 commit 6376373
Show file tree
Hide file tree
Showing 11 changed files with 351 additions and 36 deletions.
1 change: 1 addition & 0 deletions Editor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set (SOURCE_FILES
LayerWindow.cpp
LightWindow.cpp
MaterialWindow.cpp
MaterialPickerWindow.cpp
MeshWindow.cpp
ModelImporter_GLTF.cpp
ModelImporter_OBJ.cpp
Expand Down
78 changes: 55 additions & 23 deletions Editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void Editor::Initialize()
wi::resourcemanager::SetMode(wi::resourcemanager::Mode::ALLOW_RETAIN_FILEDATA);

infoDisplay.active = true;
infoDisplay.watermark = true;
infoDisplay.watermark = false; // can be toggled instead on gui
//infoDisplay.fpsinfo = true;
//infoDisplay.resolution = true;
//infoDisplay.logical_size = true;
Expand Down Expand Up @@ -244,23 +244,26 @@ void EditorComponent::ResizeLayout()

float hei = 25;

saveButton.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 3, 0));
saveButton.SetPos(XMFLOAT2(screenW - 40 - 44 - 44 - 104 * 3, 0));
saveButton.SetSize(XMFLOAT2(100, hei));

openButton.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 2, 0));
openButton.SetPos(XMFLOAT2(screenW - 40 - 44 - 44 - 104 * 2, 0));
openButton.SetSize(XMFLOAT2(100, hei));

closeButton.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 1, 0));
closeButton.SetPos(XMFLOAT2(screenW - 40 - 44 - 44 - 104 * 1, 0));
closeButton.SetSize(XMFLOAT2(100, hei));

aboutButton.SetPos(XMFLOAT2(screenW - 50 - 55, 0));
aboutButton.SetSize(XMFLOAT2(50, hei));
logButton.SetPos(XMFLOAT2(screenW - 40 - 44 - 44, 0));
logButton.SetSize(XMFLOAT2(40, hei));

aboutButton.SetPos(XMFLOAT2(screenW - 40 - 44, 0));
aboutButton.SetSize(XMFLOAT2(40, hei));

aboutLabel.SetSize(XMFLOAT2(screenW / 2.0f, screenH / 1.5f));
aboutLabel.SetPos(XMFLOAT2(screenW / 2.0f - aboutLabel.scale.x / 2.0f, screenH / 2.0f - aboutLabel.scale.y / 2.0f));

exitButton.SetPos(XMFLOAT2(screenW - 50, 0));
exitButton.SetSize(XMFLOAT2(50, hei));
exitButton.SetPos(XMFLOAT2(screenW - 40, 0));
exitButton.SetSize(XMFLOAT2(40, hei));
}
void EditorComponent::Load()
{
Expand All @@ -272,6 +275,7 @@ void EditorComponent::Load()

saveButton.Create(ICON_SAVE " Save");
saveButton.font.params.shadowColor = wi::Color::Transparent();
saveButton.SetShadowRadius(2);
saveButton.SetTooltip("Save the current scene to a new file (Ctrl + Shift + S)");
saveButton.SetColor(wi::Color(50, 180, 100, 180), wi::gui::WIDGETSTATE::IDLE);
saveButton.SetColor(wi::Color(50, 220, 140, 255), wi::gui::WIDGETSTATE::FOCUS);
Expand All @@ -282,6 +286,7 @@ void EditorComponent::Load()


openButton.Create(ICON_OPEN " Open");
openButton.SetShadowRadius(2);
openButton.font.params.shadowColor = wi::Color::Transparent();
openButton.SetTooltip("Open a scene, import a model or execute a Lua script...");
openButton.SetColor(wi::Color(50, 100, 255, 180), wi::gui::WIDGETSTATE::IDLE);
Expand Down Expand Up @@ -373,6 +378,7 @@ void EditorComponent::Load()


closeButton.Create(ICON_CLOSE " Close");
closeButton.SetShadowRadius(2);
closeButton.font.params.shadowColor = wi::Color::Transparent();
closeButton.SetTooltip("Close the current scene.\nThis will clear everything from the currently selected scene, and delete the scene.\nThis operation cannot be undone!");
closeButton.SetColor(wi::Color(255, 130, 100, 180), wi::gui::WIDGETSTATE::IDLE);
Expand Down Expand Up @@ -419,7 +425,20 @@ void EditorComponent::Load()
GetGUI().AddWidget(&closeButton);


logButton.Create(ICON_BACKLOG);
logButton.SetShadowRadius(2);
logButton.font.params.shadowColor = wi::Color::Transparent();
logButton.SetTooltip("Open the backlog");
logButton.SetColor(wi::Color(50, 160, 200, 180), wi::gui::WIDGETSTATE::IDLE);
logButton.SetColor(wi::Color(120, 200, 200, 255), wi::gui::WIDGETSTATE::FOCUS);
logButton.OnClick([&](wi::gui::EventArgs args) {
wi::backlog::Toggle();
});
GetGUI().AddWidget(&logButton);


aboutButton.Create(ICON_HELP);
aboutButton.SetShadowRadius(2);
aboutButton.font.params.shadowColor = wi::Color::Transparent();
aboutButton.SetTooltip("About...");
aboutButton.SetColor(wi::Color(50, 160, 200, 180), wi::gui::WIDGETSTATE::IDLE);
Expand Down Expand Up @@ -486,6 +505,7 @@ void EditorComponent::Load()
}

exitButton.Create(ICON_EXIT);
exitButton.SetShadowRadius(2);
exitButton.font.params.shadowColor = wi::Color::Transparent();
exitButton.SetTooltip("Exit");
exitButton.SetColor(wi::Color(160, 50, 50, 180), wi::gui::WIDGETSTATE::IDLE);
Expand All @@ -503,7 +523,7 @@ void EditorComponent::Load()

optionsWnd.Create("Options", wi::gui::Window::WindowControls::RESIZE_TOPRIGHT);
optionsWnd.SetPos(XMFLOAT2(100, 120));
optionsWnd.SetSize(XMFLOAT2(340, 400));
optionsWnd.SetSize(XMFLOAT2(340, 500));
optionsWnd.SetShadowRadius(2);
GetGUI().AddWidget(&optionsWnd);

Expand Down Expand Up @@ -578,28 +598,27 @@ void EditorComponent::Load()
}
GetGUI().SetVisible(false);
wi::profiler::SetEnabled(false);
main->infoDisplay.active = false;
});
optionsWnd.AddWidget(&cinemaModeCheckBox);

infoDisplayCheckBox.Create("Info Display: ");
infoDisplayCheckBox.SetTooltip("Toggle the information display (the text in top left corner).");
infoDisplayCheckBox.OnClick([&](wi::gui::EventArgs args) {
main->infoDisplay.active = args.bValue;
versionCheckBox.Create("Version: ");
versionCheckBox.SetTooltip("Toggle the engine version display text in top left corner.");
versionCheckBox.OnClick([&](wi::gui::EventArgs args) {
main->infoDisplay.watermark = args.bValue;
});
optionsWnd.AddWidget(&infoDisplayCheckBox);
infoDisplayCheckBox.SetCheck(main->infoDisplay.active);
optionsWnd.AddWidget(&versionCheckBox);
versionCheckBox.SetCheck(main->infoDisplay.watermark);

fpsCheckBox.Create("FPS: ");
fpsCheckBox.SetTooltip("Toggle the FPS display.");
fpsCheckBox.SetTooltip("Toggle the FPS display text in top left corner.");
fpsCheckBox.OnClick([&](wi::gui::EventArgs args) {
main->infoDisplay.fpsinfo = args.bValue;
});
optionsWnd.AddWidget(&fpsCheckBox);
fpsCheckBox.SetCheck(main->infoDisplay.fpsinfo);

otherinfoCheckBox.Create("Advanced: ");
otherinfoCheckBox.SetTooltip("Toggle advanced data in the info display.");
otherinfoCheckBox.SetTooltip("Toggle advanced data in the info display text in top left corner.");
otherinfoCheckBox.OnClick([&](wi::gui::EventArgs args) {
main->infoDisplay.heap_allocation_counter = args.bValue;
main->infoDisplay.vram_usage = args.bValue;
Expand All @@ -615,6 +634,9 @@ void EditorComponent::Load()


newCombo.Create("New: ");
newCombo.selected_font.anim.typewriter.looped = true;
newCombo.selected_font.anim.typewriter.time = 2;
newCombo.selected_font.anim.typewriter.character_start = 1;
newCombo.AddItem("...", ~0ull);
newCombo.AddItem("Transform", 0);
newCombo.AddItem("Material", 1);
Expand Down Expand Up @@ -849,6 +871,9 @@ void EditorComponent::Load()
GetGUI().AddWidget(&componentWindow);

newComponentCombo.Create("Add: ");
newComponentCombo.selected_font.anim.typewriter.looped = true;
newComponentCombo.selected_font.anim.typewriter.time = 2;
newComponentCombo.selected_font.anim.typewriter.character_start = 1;
newComponentCombo.SetTooltip("Add a component to the first selected entity.");
newComponentCombo.AddItem("...", ~0ull);
newComponentCombo.AddItem("Name", 0);
Expand Down Expand Up @@ -1076,6 +1101,8 @@ void EditorComponent::Load()
paintToolWnd.SetCollapsed(true);
optionsWnd.AddWidget(&paintToolWnd);

materialPickerWnd.Create(this);
optionsWnd.AddWidget(&materialPickerWnd);


sceneComboBox.Create("Scene: ");
Expand Down Expand Up @@ -1264,7 +1291,7 @@ void EditorComponent::Load()
wi::gui::Theme theme;
theme.image.background = true;
theme.image.blendFlag = wi::enums::BLENDMODE_OPAQUE;
theme.font.color = wi::Color(160, 240, 250, 255);
theme.font.color = wi::Color(130, 210, 220, 255);
theme.shadow_color = wi::Color(80, 140, 180, 100);

switch ((Theme)args.userdata)
Expand Down Expand Up @@ -1401,7 +1428,6 @@ void EditorComponent::Update(float dt)
renderPath->GetGUI().SetVisible(true);
}
GetGUI().SetVisible(true);
main->infoDisplay.active = infoDisplayCheckBox.GetCheck();
wi::profiler::SetEnabled(profilerEnabledCheckBox.GetCheck());

cinemaModeCheckBox.SetCheck(false);
Expand Down Expand Up @@ -2087,7 +2113,6 @@ void EditorComponent::Update(float dt)
hairWnd.SetEntity(INVALID_ENTITY);
meshWnd.SetEntity(INVALID_ENTITY, -1);
materialWnd.SetEntity(INVALID_ENTITY);
lightWnd.SetEntity(INVALID_ENTITY);
soundWnd.SetEntity(INVALID_ENTITY);
decalWnd.SetEntity(INVALID_ENTITY);
envProbeWnd.SetEntity(INVALID_ENTITY);
Expand Down Expand Up @@ -2242,6 +2267,7 @@ void EditorComponent::Update(float dt)
RenderPath2D::Update(dt);
RefreshComponentWindow();
RefreshOptionsWindow();
materialPickerWnd.Update();

translator.Update(camera, *this);

Expand Down Expand Up @@ -2860,10 +2886,10 @@ void EditorComponent::RefreshOptionsWindow()
pos.y += translatorCheckBox.GetSize().y;
pos.y += padding;

infoDisplayCheckBox.SetPos(XMFLOAT2(pos.x + x_off, pos.y));
versionCheckBox.SetPos(XMFLOAT2(pos.x + x_off, pos.y));
fpsCheckBox.SetPos(XMFLOAT2(pos.x + x_off + 80, pos.y));
otherinfoCheckBox.SetPos(XMFLOAT2(pos.x + x_off + 60 * 3, pos.y));
pos.y += infoDisplayCheckBox.GetSize().y;
pos.y += versionCheckBox.GetSize().y;
pos.y += padding;

cinemaModeCheckBox.SetPos(XMFLOAT2(pos.x + x_off, pos.y));
Expand Down Expand Up @@ -2923,6 +2949,11 @@ void EditorComponent::RefreshOptionsWindow()
pos.y += cameraWnd.GetSize().y;
pos.y += padding;

materialPickerWnd.SetPos(pos);
materialPickerWnd.SetSize(XMFLOAT2(width, materialPickerWnd.GetScale().y));
pos.y += materialPickerWnd.GetSize().y;
pos.y += padding;

paintToolWnd.SetPos(pos);
paintToolWnd.SetSize(XMFLOAT2(width, paintToolWnd.GetScale().y));
pos.y += paintToolWnd.GetSize().y;
Expand Down Expand Up @@ -3086,6 +3117,7 @@ void EditorComponent::PushToEntityTree(wi::ecs::Entity entity, int level)
void EditorComponent::RefreshEntityTree()
{
const Scene& scene = GetCurrentScene();
materialPickerWnd.RecreateButtons();

for (int i = 0; i < entityTree.GetItemCount(); ++i)
{
Expand Down
5 changes: 4 additions & 1 deletion Editor/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "wiScene_BindLua.h"

#include "MaterialWindow.h"
#include "MaterialPickerWindow.h"
#include "PostprocessWindow.h"
#include "WeatherWindow.h"
#include "ObjectWindow.h"
Expand Down Expand Up @@ -43,6 +44,7 @@ class EditorComponent : public wi::RenderPath2D
{
public:
MaterialWindow materialWnd;
MaterialPickerWindow materialPickerWnd;
PostprocessWindow postprocessWnd;
WeatherWindow weatherWnd;
ObjectWindow objectWnd;
Expand Down Expand Up @@ -70,6 +72,7 @@ class EditorComponent : public wi::RenderPath2D
wi::gui::Button saveButton;
wi::gui::Button openButton;
wi::gui::Button closeButton;
wi::gui::Button logButton;
wi::gui::Button aboutButton;
wi::gui::Button exitButton;
wi::gui::Label aboutLabel;
Expand All @@ -82,7 +85,7 @@ class EditorComponent : public wi::RenderPath2D
wi::gui::CheckBox profilerEnabledCheckBox;
wi::gui::CheckBox physicsEnabledCheckBox;
wi::gui::CheckBox cinemaModeCheckBox;
wi::gui::CheckBox infoDisplayCheckBox;
wi::gui::CheckBox versionCheckBox;
wi::gui::CheckBox fpsCheckBox;
wi::gui::CheckBox otherinfoCheckBox;
wi::gui::ComboBox themeCombo;
Expand Down
2 changes: 2 additions & 0 deletions Editor/Editor_SOURCE.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<ClCompile Include="$(MSBuildThisFileDirectory)IKWindow.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)LayerWindow.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)LightWindow.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)MaterialPickerWindow.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)MaterialWindow.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)meshoptimizer\allocator.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
Expand Down Expand Up @@ -137,6 +138,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)json.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)LayerWindow.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)LightWindow.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)MaterialPickerWindow.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)MaterialWindow.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)meshoptimizer\meshoptimizer.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)MeshWindow.h" />
Expand Down
2 changes: 2 additions & 0 deletions Editor/Editor_SOURCE.vcxitems.filters
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<Filter>meshoptimizer</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)TerrainGenerator.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)MaterialPickerWindow.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)AnimationWindow.h" />
Expand Down Expand Up @@ -112,6 +113,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)FontAwesomeV6.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)IconsFontAwesome6.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)IconDefinitions.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)MaterialPickerWindow.h" />
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)startup.lua" />
Expand Down
1 change: 1 addition & 0 deletions Editor/IconDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
#define ICON_SAVE ICON_FA_FLOPPY_DISK
#define ICON_OPEN ICON_FA_FOLDER_OPEN
#define ICON_CLOSE ICON_FA_TRASH
#define ICON_BACKLOG ICON_FA_BOOK
#define ICON_HELP ICON_FA_CIRCLE_QUESTION
#define ICON_EXIT ICON_FA_CIRCLE_XMARK
Loading

0 comments on commit 6376373

Please sign in to comment.