diff --git a/GlitchyEditor/resources/Textures/EditorIcons.dds b/GlitchyEditor/resources/Textures/EditorIcons.dds index c28f496..f6c3fb1 100644 Binary files a/GlitchyEditor/resources/Textures/EditorIcons.dds and b/GlitchyEditor/resources/Textures/EditorIcons.dds differ diff --git a/GlitchyEditor/resources/Textures/EditorIcons.psd b/GlitchyEditor/resources/Textures/EditorIcons.psd index 5ff9b69..cd95b1d 100644 Binary files a/GlitchyEditor/resources/Textures/EditorIcons.psd and b/GlitchyEditor/resources/Textures/EditorIcons.psd differ diff --git a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf index 00b2972..b0e7aed 100644 --- a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf +++ b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf @@ -115,20 +115,28 @@ namespace GlitchyEditor.EditWindows TComponent* component = entity.GetComponent(); bool nodeOpen = ImGui.CollapsingHeader(header.CStr(), .DefaultOpen | .AllowOverlap | .Framed | .SpanFullWidth); - + ImGui.PushID(header.CStr()); defer { ImGui.PopID(); } + + if (showComponentContextMenu != null && ImGui.IsItemClicked(.Right)) + { + ImGui.OpenPopup("component_popup"); + } float positionX = ImGui.GetWindowContentRegionMax().x; - float2 buttonSize = (.)ImGui.CalcTextSize("..."); + float2 buttonSize = ImGui.GetTextLineHeight().XX; + + ImGui.PushStyleColor(.Button, .(0, 0, 0, 0)); if (showComponentContextMenu != null) { - positionX -= buttonSize.X + 2 * ImGui.GetStyle().FramePadding.x; + positionX -= buttonSize.X + ImGui.GetStyle().FramePadding.x; ImGui.SameLine(positionX); + positionX -= ImGui.GetStyle().FramePadding.x; - if (ImGui.SmallButton("...")) + if (ImGui.ImageButton("save", EditorIcons.Instance.Icon_ContextMenu, (.)buttonSize)) { ImGui.OpenPopup("component_popup"); } @@ -141,11 +149,40 @@ namespace GlitchyEditor.EditWindows } } + if (ScriptEngine.ApplicationInfo.IsInPlayMode) + { + positionX -= buttonSize.X + ImGui.GetStyle().FramePadding.x; + ImGui.SameLine(positionX); + + if (ImGui.ImageButton("save", EditorIcons.Instance.Icon_Save, (.)buttonSize)) + { + if (Entity editorEntity = Editor.Instance.EditorScene.GetEntityByID(entity.UUID)) + { + Scene.CopyComponent(entity, editorEntity); + + if (typeof(TComponent) == typeof(ScriptComponent)) + { + // TODO: Copy script data into editor + // TODO: Somehow get the scriptserializer used to serialize the editor scene + //scriptSerializer.SerializeScriptInstance(((ScriptComponent*)component).Instance); + } + } + else + { + ImGui.OpenPopup("###CopyNewEntityToEditor"); + } + } + + ImGui.AttachTooltip("Save the component to edit mode"); + } + + ImGui.PopStyleColor(); + if (ImGui.BeginPopupModal("Create new entity?###CopyNewEntityToEditor")) { //ImGui.Text("This entity only exists in play mode. Do you want to copy only this component, or all components?"); - ImGui.Text("This entity only exists in play mode. Saving will create an entity that only contains this component."); - + ImGui.Text("This entity only exists in play mode.\nSaving will create an entity that only contains this component in edit mode."); + //if (ImGui.Button("Copy only this component")) if (ImGui.Button("Ok")) { @@ -182,38 +219,6 @@ namespace GlitchyEditor.EditWindows ImGui.EndPopup(); } - if (ScriptEngine.ApplicationInfo.IsInPlayMode) - { - positionX -= buttonSize.X + 1 * ImGui.GetStyle().FramePadding.x; - ImGui.SameLine(positionX); - - float2 imageButtonSize = (.)buttonSize; - imageButtonSize.X -= ImGui.GetStyle().FramePadding.x * 2; - imageButtonSize.Y -= ImGui.GetStyle().FramePadding.y * 2; - - //if (ImGui.ImageButton("save", EditorIcons.Instance.Save, (.)imageButtonSize)) - if (ImGui.SmallButton("Save")) - { - if (Entity editorEntity = Editor.Instance.EditorScene.GetEntityByID(entity.UUID)) - { - Scene.CopyComponent(entity, editorEntity); - - if (typeof(TComponent) == typeof(ScriptComponent)) - { - // TODO: Copy script data into editor - // TODO: Somehow get the scriptserializer used to serialize the editor scene - //scriptSerializer.SerializeScriptInstance(((ScriptComponent*)component).Instance); - } - } - else - { - ImGui.OpenPopup("###CopyNewEntityToEditor"); - } - } - - ImGui.AttachTooltip("Save component to edit mode."); - } - if (nodeOpen && ImGui.BeginPropertyTable("properties", TableId)) { if (entity.TryGetComponent(let actualComponent)) diff --git a/GlitchyEditor/src/EditorIcons.bf b/GlitchyEditor/src/EditorIcons.bf index b073eb9..f2217fc 100644 --- a/GlitchyEditor/src/EditorIcons.bf +++ b/GlitchyEditor/src/EditorIcons.bf @@ -31,7 +31,8 @@ namespace GlitchyEditor public SubTexture2D File_Shader ~ _.ReleaseRef(); public SubTexture2D Entity_Visible ~ _.ReleaseRef(); public SubTexture2D Entity_Hidden ~ _.ReleaseRef(); - public SubTexture2D Save ~ _.ReleaseRef(); + public SubTexture2D Icon_Save ~ _.ReleaseRef(); + public SubTexture2D Icon_ContextMenu ~ _.ReleaseRef(); public static EditorIcons Instance => _editorIcons; @@ -68,7 +69,8 @@ namespace GlitchyEditor File_Shader = GetNextGridTexture(ref pen, iconSize); Entity_Visible = GetNextGridTexture(ref pen, iconSize); Entity_Hidden = GetNextGridTexture(ref pen, iconSize); - Save = GetNextGridTexture(ref pen, iconSize); + Icon_Save = GetNextGridTexture(ref pen, iconSize); + Icon_ContextMenu = GetNextGridTexture(ref pen, iconSize); } public ~this() diff --git a/GlitchyEngine/src/ImGui/ImGuiExtension.bf b/GlitchyEngine/src/ImGui/ImGuiExtension.bf index 3514204..b214f7e 100644 --- a/GlitchyEngine/src/ImGui/ImGuiExtension.bf +++ b/GlitchyEngine/src/ImGui/ImGuiExtension.bf @@ -113,17 +113,17 @@ namespace ImGui public static extern void Image(TextureViewBinding textureViewBinding, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 tint_col = Vec4.Ones, Vec4 border_col = Vec4.Zero); - public static bool ImageButton(char8* id, SubTexture2D subTexture, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones) + public static bool ImageButton(char8* id, SubTexture2D subTexture, Vec2 imageSize, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones) { if (uv0 != .Zero || uv1 != .Ones) Runtime.NotImplemented(); float2 v = (.)subTexture.TexCoords.XY + subTexture.TexCoords.ZW; - return ImageButton(id, subTexture.Texture.GetViewBinding(), size, (.)subTexture.TexCoords.XY, (.)v, bg_col, tint_col); + return ImageButton(id, subTexture.Texture.GetViewBinding(), imageSize, (.)subTexture.TexCoords.XY, (.)v, bg_col, tint_col); } - public static extern bool ImageButton(char8* id, TextureViewBinding textureViewBinding, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones); + public static extern bool ImageButton(char8* id, TextureViewBinding textureViewBinding, Vec2 imageSize, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones); public static bool ImageButtonEx(uint32 id, SubTexture2D subTexture, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones) { diff --git a/GlitchyEngine/src/Platform/DX11/ImGui/Dx11ImGui.bf b/GlitchyEngine/src/Platform/DX11/ImGui/Dx11ImGui.bf index ab8b462..bf1ec80 100644 --- a/GlitchyEngine/src/Platform/DX11/ImGui/Dx11ImGui.bf +++ b/GlitchyEngine/src/Platform/DX11/ImGui/Dx11ImGui.bf @@ -22,24 +22,24 @@ namespace ImGui textureViewBinding.Release(); } - public static override bool ImageButton(char8* id, TextureViewBinding textureViewBinding, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones) + public static override bool ImageButton(char8* id, TextureViewBinding textureViewBinding, Vec2 imageSize, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones) { var view = textureViewBinding._nativeShaderResourceView..AddRef(); _resourceViews.Add(view); - bool pressed = ImGui.ImageButton(id, view, size, uv0, uv1, bg_col, tint_col); + bool pressed = ImGui.ImageButton(id, view, imageSize, uv0, uv1, bg_col, tint_col); textureViewBinding.Release(); return pressed; } - public static override bool ImageButtonEx(uint32 id, TextureViewBinding textureViewBinding, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones) + public static override bool ImageButtonEx(uint32 id, TextureViewBinding textureViewBinding, Vec2 imageSize, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones) { var view = textureViewBinding._nativeShaderResourceView..AddRef(); _resourceViews.Add(view); - bool pressed = ImGui.ImageButtonEx(id, view, size, uv0, uv1, bg_col, tint_col); + bool pressed = ImGui.ImageButtonEx(id, view, imageSize, uv0, uv1, bg_col, tint_col); textureViewBinding.Release();