From 454ec59951b180e0fb0a50ee2c3f5fec0f312bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Sun, 23 Jun 2024 17:15:09 +0200 Subject: [PATCH] Use icon buttons for save component and context menu, right click context menu --- .../resources/Textures/EditorIcons.dds | Bin 327808 -> 344192 bytes .../resources/Textures/EditorIcons.psd | Bin 87626 -> 89758 bytes .../src/EditWindows/ComponentEditWindow.bf | 81 ++++++++++-------- GlitchyEditor/src/EditorIcons.bf | 6 +- GlitchyEngine/src/ImGui/ImGuiExtension.bf | 6 +- .../src/Platform/DX11/ImGui/Dx11ImGui.bf | 8 +- 6 files changed, 54 insertions(+), 47 deletions(-) diff --git a/GlitchyEditor/resources/Textures/EditorIcons.dds b/GlitchyEditor/resources/Textures/EditorIcons.dds index c28f49608b2d98b571ca8b525f9f7e05b68ddc64..f6c3fb157e99965999943f5007235eaf68a203fa 100644 GIT binary patch delta 3452 zcmcInZA=tL7-nX-^%N-!NQ+VHk!S>kx)hDqg5jtbAz(SdaW8wglKC2G|{&2yL)%A$A{^U{@I<` znfH0WKXzB+q+N}v(~63gTX)38#U&~<&JJ(;EAU8-izDzN?1*#j=`wB7G4}xB%4KR3 z?gaTh8STk}dn!d~g8YE6VDTK@L&@z?uWHUM+`WkA;)Pn`Z=1b3S?3b@Rzq0NT9uU- zIN)vbmlt#-#h$l6$>E{TXc^Pi&GXv_iizLjOi}p0{c-^44(jksb9%XBf>eZ$V(zYy zoGj3o$`3D)xlRL;#{1iJ68Vm52A1U%AMWGX0nAy=Hiwlxe0)+=-3Q=OhuwJu01CiXgBUTNS1+g z%9&?usNF#MLaxmw2T-f(v8Y!gH3XO4tefyyh-CQC@B|<(761mZGQ_bC#Bah!EgxpO zwJ6=DuCDcmvAVDwU_d0N6tH1?;)nRa> zjR1lJ!PzName{w6l*Aha!Ylhh#!O6pcDMe#SCz*?-Y()B$xn$oDd1NCst4U+q$=i+ z@a-q6Q5N8W8!l`{z!q3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B>h-avKYhi&R@ zRG&yLa>Z_H*&-|^qeM_AdJm{K(Mn=u{XZQE*+(qZ)Fu+R8n6ethnqP8K@qJVKN#t9M4LhDnvm}zCbv>fT+um;W) zFYl;lO?cQN{Z({<3Wwpb`f#{68^7zrfQajp67%r7dUc05)IWa8WYaZnD>(!l-|(yV H9%ugoM1)oV diff --git a/GlitchyEditor/resources/Textures/EditorIcons.psd b/GlitchyEditor/resources/Textures/EditorIcons.psd index 5ff9b69e42d967adec0ae15cdac042d667781724..cd95b1d9fab7ce7bd45d0e637fd87fc30680fe31 100644 GIT binary patch delta 4269 zcmeHKc~q6h6~9+_0o)NGqJW?nHKG+ODw`}K$d0&c)kaHQ0T)n`ib!LV;)XcUIYeWn zS{s$9sTx}a#iUk2QDb7`8Z}yCP*8%1NFMa}&G!MC<}~N@MoAh`$pW$?B1<9@KI8}KN0yC^L>vsAcrvl-TWS5U;PB|Ac zDdbAgKuLs6IUjqA04tk;Hp<|b*Onx_V5kcW**s@x482B6u$Kt$5%4o+Cc^2PVO|A zhS7XlPs>yQYiJE{KK%i07rm=wKAof!bPR@1&}F(qVE_<8*bB7TS+VF_q2m@C>uFgg?>FUP)L7+ zF+BsHX&HdS2DW)F1C?-p6VCQh5mtW$sbyd<9i+o511oUIL{b4{P*VUd`o=i*S> zcp};&%udCNWu-aA6^Mluo%w{Addkrvlgh->Q_ejzsT>J5H)c{(%cfeqPqob>6*A3% zoyCPyov`V&-0i?_!t%7H6ifDJd*N|9&h!wETAfHgon@-RgYitnJ@gkL#luXG@yylB zz%J}BjuiXps;Dh~-J*s{MRLiTN>-J;X@ZW0<^XmS>(0#AhUM!<3^8qjP;281t=c$H6^XC`zIK;V2 zmsHe6=DDKn7r81_?^k%bu(-TcO>DbdZyYBxob5N7d4za;Wv`mbyLw-(cY2jai|g0+ z=_aLfKaLaEufMPRk{wJuUR=9z1W^op2{UD1?gDfhz_H@y&20#F#jQ&8$+vHzkNfIl zOm6W+hU4y}0e;wqgJfVJa?}3q3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IqB?=nZ;}^65?b3kl^>0Ue_E zXg`(0o}e>yp4(9qHE>6|N-gA2>;B=MdVmgN)jlewT${Sd?!fR zs>X7I%Bot$4YJhE7IpLPAQgBzP^~$=UbQ>3US-sWsFP=G%I(WHxKWij0#xmniBORZ zK~iSt_DY?dg>KDR42yLjk5Zp~H5Y-QO#v$L+#IM1sM>S!dd>NruvgB109$aO3^w{= zDQx4#5-fhgk8SGO*NY*$J<2iaoqsOJn9nz-5hxzab5vaQO31<~Y>^#9I8KfIS3dgI zSoHS{<#6@brQK5a04Jzn-xkV&ju1mG@0V9bV6P$nE|BN^IaYaocK~a$Mnd-cexE73 ztIOXzTcz}Qh=bIyAKpcO(r*!q)u%U$)zV*b@zoRu<6#4Soemjbh5X{zD0YZ+VcnZgz*aYZ0=uiFoEu+D zfs`yt@z z#2CM>& zNmd!!mq(g7Nnu|eeV?a6;?a*sYp5i@ACJ>iiI)#VMt!)v>BE7VE%EEmv++75j*0R` ze~yNXYzUR40UQYl%;bjwjM}9++l0u_CaZLQ*qB!Vx$|L;K{U;2mBEh~8@V?}NYx|! z45HP|ljUV!PKVspGD$)QX$b;jw)yc~YzYcA69DitIIx!>{(~7mc@5w>xHk5#LAPP| zA6>4J<>z6Xuj^H^Tp14DK;BgiT?=M{v3k?pL(N61ALI91gPON6x$?L{GoZVUICx8v zv!gi=8qmec;V}kaATLxlj^$?&*X2sA0i20^G=sMScrC(U&@La1;}y^V5w)s~K^O54 z#ij&KiH976}RCY21W=P>bw0Wmc6%dfSn3 zrkxi_wVg91b`sv#sWR(56^%!8iX$37B&WO>V>s6-yhZj*;Q|ScPZSOamrPvBz-^+=V!P32xqW-T+rKoj1d+n1OQYl-n~(); 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();