Skip to content

Commit

Permalink
ui
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Nov 2, 2022
1 parent 216e8b0 commit a267c62
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 16 deletions.
76 changes: 65 additions & 11 deletions FModel/Views/Snooper/SnimGui.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Windows;
using CUE4Parse.UE4.Objects.Core.Misc;
using FModel.Framework;
Expand All @@ -14,6 +14,7 @@ public class SnimGui
{
public readonly ImGuiController Controller;
private bool _viewportFocus;
private bool _swapAwareness;

private readonly Vector4 _accentColor = new (32, 107, 212, 1f);
private readonly Vector4 _alertColor = new (212, 146, 32, 1f);
Expand Down Expand Up @@ -144,7 +145,7 @@ private void DrawOuliner(Snooper s)
s.Renderer.Settings.SelectModel(guid);
if (ImGui.Selectable("Delete")) s.Renderer.Cache.Models.Remove(guid);
if (ImGui.Selectable("Deselect")) s.Renderer.Settings.SelectModel(Guid.Empty);
if (ImGui.Selectable("Copy Name to Clipboard")) Application.Current.Dispatcher.Invoke(() => Clipboard.SetText(model.Name));
if (ImGui.Selectable("Copy Name to Clipboard")) ImGui.SetClipboardText(model.Name);
ImGui.EndPopup();
}
ImGui.PopID();
Expand Down Expand Up @@ -192,6 +193,7 @@ private void DrawDetails(Snooper s)
ImGui.TableSetupColumn("Material");
ImGui.TableHeadersRow();

var swap = false;
for (var i = 0; i < model.Sections.Length; i++)
{
var section = model.Sections[i];
Expand All @@ -214,14 +216,53 @@ private void DrawDetails(Snooper s)
if (ImGui.BeginPopupContextItem())
{
s.Renderer.Settings.SelectSection(i);
if (ImGui.Selectable("Swap")) s.Renderer.Settings.SwapMaterial(true);
if (ImGui.Selectable("Copy Name to Clipboard")) Application.Current.Dispatcher.Invoke(() => Clipboard.SetText(material.Name));
if (ImGui.Selectable("Swap"))
{
if (_swapAwareness)
{
s.Renderer.Settings.SwapMaterial(true);
s.WindowShouldClose(true, false);
}
else swap = true;
}
if (ImGui.Selectable("Copy Name to Clipboard")) ImGui.SetClipboardText(material.Name);
ImGui.EndPopup();
}
ImGui.PopID();
}

ImGui.EndTable();

var p_open = true;
if (swap) ImGui.OpenPopup("Swap?");
ImGui.SetNextWindowPos(ImGui.GetMainViewport().GetCenter(), ImGuiCond.Appearing, new Vector2(.5f));
if (ImGui.BeginPopupModal("Swap?", ref p_open, ImGuiWindowFlags.AlwaysAutoResize))
{
ImGui.TextWrapped("You're about to swap a material.\nThe window will close for you to extract a material!\n\n");
ImGui.Separator();

ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, Vector2.Zero);
ImGui.Checkbox("Got it! Don't show me again", ref _swapAwareness);
ImGui.PopStyleVar();

var size = new Vector2(120, 0);
if (ImGui.Button("OK", size))
{
ImGui.CloseCurrentPopup();
s.Renderer.Settings.SwapMaterial(true);
s.WindowShouldClose(true, false);
}

ImGui.SetItemDefaultFocus();
ImGui.SameLine();

if (ImGui.Button("Cancel", size))
{
ImGui.CloseCurrentPopup();
}

ImGui.EndPopup();
}

ImGui.EndTabItem();
}

Expand Down Expand Up @@ -261,6 +302,7 @@ private void DrawDetails(Snooper s)
}
}
}
else NoMeshSelected();
PopStyleCompact();
ImGui.End();
}
Expand Down Expand Up @@ -333,6 +375,7 @@ private void DrawTransform(Snooper s)

model.UpdateMatrix(model.SelectedInstance);
}
else NoMeshSelected();
PopStyleCompact();
ImGui.End();
}
Expand All @@ -357,13 +400,18 @@ private void DrawUvChannels(Snooper s)
ImGui.SetNextItemOpen(true, ImGuiCond.Appearing);
if (ImGui.TreeNode("Textures"))
{
var size = new Vector2(ImGui.GetContentRegionAvail().X / 4.75f);
DrawSquareTexture(material.Diffuse[material.SelectedChannel], size); ImGui.SameLine();
DrawSquareTexture(material.Normals[material.SelectedChannel], size); ImGui.SameLine();
DrawSquareTexture(material.SpecularMasks[material.SelectedChannel], size); ImGui.SameLine();
DrawSquareTexture(material.Emissive[material.SelectedChannel], size); ImGui.SameLine();
if (material.Diffuse.Length > 0)
{
var size = new Vector2(ImGui.GetContentRegionAvail().X / 4.75f);
DrawSquareTexture(material.Diffuse[material.SelectedChannel], size); ImGui.SameLine();
DrawSquareTexture(material.Normals[material.SelectedChannel], size); ImGui.SameLine();
DrawSquareTexture(material.SpecularMasks[material.SelectedChannel], size); ImGui.SameLine();
DrawSquareTexture(material.Emissive[material.SelectedChannel], size); ImGui.SameLine();
}
else TextColored(_errorColor, "no texture in material section");
}
}
else NoMeshSelected();
PopStyleCompact();
ImGui.End();
}
Expand Down Expand Up @@ -438,6 +486,12 @@ private void PushStyleCompact()
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, style.ItemSpacing with { Y = style.ItemSpacing.Y * 0.6f });
}

private void NoMeshSelected() => TextColored(_errorColor, "no mesh selected");
private void TextColored(Vector4 color, string text)
{
ImGui.TextColored(color, text);
}

private void DrawSquareTexture(Texture texture, Vector2 size) =>
ImGui.Image(texture?.GetPointer() ?? IntPtr.Zero, size, Vector2.Zero, Vector2.One, Vector4.One, new Vector4(1, 1, 1, .5f));

Expand Down Expand Up @@ -490,7 +544,7 @@ private void Theme(ImGuiStylePtr style)
style.Colors[(int) ImGuiCol.TabHovered] = new Vector4(0.35f, 0.35f, 0.41f, 0.80f);
style.Colors[(int) ImGuiCol.TabActive] = new Vector4(0.23f, 0.24f, 0.29f, 1.00f);
style.Colors[(int) ImGuiCol.TabUnfocused] = new Vector4(0.15f, 0.15f, 0.15f, 1.00f);
style.Colors[(int) ImGuiCol.TabUnfocusedActive] = new Vector4(0.14f, 0.26f, 0.42f, 1.00f);
style.Colors[(int) ImGuiCol.TabUnfocusedActive] = new Vector4(0.15f, 0.15f, 0.15f, 1.00f);
style.Colors[(int) ImGuiCol.DockingPreview] = new Vector4(0.26f, 0.59f, 0.98f, 0.70f);
style.Colors[(int) ImGuiCol.DockingEmptyBg] = new Vector4(0.20f, 0.20f, 0.20f, 1.00f);
style.Colors[(int) ImGuiCol.PlotLines] = new Vector4(0.61f, 0.61f, 0.61f, 1.00f);
Expand Down
10 changes: 5 additions & 5 deletions FModel/Views/Snooper/Snooper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void LoadExport(CancellationToken cancellationToken, UObject export)
_previousSpeed = Camera.Speed;
}

private unsafe void WindowShouldClose(bool value, bool clear)
public unsafe void WindowShouldClose(bool value, bool clear)
{
if (clear)
{
Expand Down Expand Up @@ -175,12 +175,12 @@ protected override void OnResize(ResizeEventArgs e)
{
base.OnResize(e);

GL.Viewport(0, 0, Size.X, Size.Y);
GL.Viewport(0, 0, e.Width, e.Height);

Framebuffer = new FramebufferObject(Size);
Framebuffer = new FramebufferObject(e.Size);
Framebuffer.Setup();
Camera.AspectRatio = Size.X / (float)Size.Y;
_gui.Controller.WindowResized(ClientSize.X, ClientSize.Y);
Camera.AspectRatio = e.Width / (float) e.Height;
_gui.Controller.WindowResized(e.Width, e.Height);
}

protected override void Dispose(bool disposing)
Expand Down

0 comments on commit a267c62

Please sign in to comment.