Use icon buttons for save component and context menu, right click context menu

This commit is contained in:
Simon Lübeß
2024-06-23 17:15:21 +02:00
parent 1b130a4bce
commit 454ec59951
6 changed files with 54 additions and 47 deletions
Binary file not shown.
Binary file not shown.
@@ -119,16 +119,24 @@ namespace GlitchyEditor.EditWindows
ImGui.PushID(header.CStr()); ImGui.PushID(header.CStr());
defer { ImGui.PopID(); } defer { ImGui.PopID(); }
if (showComponentContextMenu != null && ImGui.IsItemClicked(.Right))
{
ImGui.OpenPopup("component_popup");
}
float positionX = ImGui.GetWindowContentRegionMax().x; float positionX = ImGui.GetWindowContentRegionMax().x;
float2 buttonSize = (.)ImGui.CalcTextSize("..."); float2 buttonSize = ImGui.GetTextLineHeight().XX;
ImGui.PushStyleColor(.Button, .(0, 0, 0, 0));
if (showComponentContextMenu != null) if (showComponentContextMenu != null)
{ {
positionX -= buttonSize.X + 2 * ImGui.GetStyle().FramePadding.x; positionX -= buttonSize.X + ImGui.GetStyle().FramePadding.x;
ImGui.SameLine(positionX); ImGui.SameLine(positionX);
positionX -= ImGui.GetStyle().FramePadding.x;
if (ImGui.SmallButton("...")) if (ImGui.ImageButton("save", EditorIcons.Instance.Icon_ContextMenu, (.)buttonSize))
{ {
ImGui.OpenPopup("component_popup"); ImGui.OpenPopup("component_popup");
} }
@@ -141,10 +149,39 @@ 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<TComponent>(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")) 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. 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("Copy only this component"))
if (ImGui.Button("Ok")) if (ImGui.Button("Ok"))
@@ -182,38 +219,6 @@ namespace GlitchyEditor.EditWindows
ImGui.EndPopup(); 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<TComponent>(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 (nodeOpen && ImGui.BeginPropertyTable("properties", TableId))
{ {
if (entity.TryGetComponent<TComponent>(let actualComponent)) if (entity.TryGetComponent<TComponent>(let actualComponent))
+4 -2
View File
@@ -31,7 +31,8 @@ namespace GlitchyEditor
public SubTexture2D File_Shader ~ _.ReleaseRef(); public SubTexture2D File_Shader ~ _.ReleaseRef();
public SubTexture2D Entity_Visible ~ _.ReleaseRef(); public SubTexture2D Entity_Visible ~ _.ReleaseRef();
public SubTexture2D Entity_Hidden ~ _.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; public static EditorIcons Instance => _editorIcons;
@@ -68,7 +69,8 @@ namespace GlitchyEditor
File_Shader = GetNextGridTexture(ref pen, iconSize); File_Shader = GetNextGridTexture(ref pen, iconSize);
Entity_Visible = GetNextGridTexture(ref pen, iconSize); Entity_Visible = GetNextGridTexture(ref pen, iconSize);
Entity_Hidden = 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() public ~this()
+3 -3
View File
@@ -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 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) if (uv0 != .Zero || uv1 != .Ones)
Runtime.NotImplemented(); Runtime.NotImplemented();
float2 v = (.)subTexture.TexCoords.XY + subTexture.TexCoords.ZW; 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) 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)
{ {
@@ -22,24 +22,24 @@ namespace ImGui
textureViewBinding.Release(); 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(); var view = textureViewBinding._nativeShaderResourceView..AddRef();
_resourceViews.Add(view); _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(); textureViewBinding.Release();
return pressed; 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(); var view = textureViewBinding._nativeShaderResourceView..AddRef();
_resourceViews.Add(view); _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(); textureViewBinding.Release();