Skip to content

Commit

Permalink
zzre: Allow multiple game windows and the ImGui demo window
Browse files Browse the repository at this point in the history
  • Loading branch information
Helco committed Feb 4, 2024
1 parent 7c44f8c commit 1079e07
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions zzre.core/imgui/WindowContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public class WindowContainer : BaseDisposable, IReadOnlyCollection<BaseWindow>
public int Count => windows.Count;
public ImGuiRenderer ImGuiRenderer { get; }
public MenuBar MenuBar { get; } = new();
public ref bool ShowImGuiDemoWindow => ref showImGuiDemoWindow;

private bool isInUpdateEnumeration = false;
private bool showImGuiDemoWindow = false;
private readonly OnceAction onceBeforeUpdate = new();
private readonly OnceAction onceAfterUpdate = new();
private BaseWindow? nextFocusedWindow = null;
Expand Down Expand Up @@ -136,6 +139,9 @@ public void Update(GameTime time, InputSnapshot input)
foreach (var window in this.OfType<Window>().Where(w => !w.IsOpen).ToArray())
window.Dispose();
isInUpdateEnumeration = false;

if (showImGuiDemoWindow)
ShowDemoWindow(ref showImGuiDemoWindow);
onceAfterUpdate.Invoke();
}

Expand Down
3 changes: 3 additions & 0 deletions zzre/Program.InDev.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ private static void HandleInDev(InvocationContext ctx)
windowContainer.MenuBar.AddButton("Tools/World Viewer", () => new WorldViewer(diContainer));
windowContainer.MenuBar.AddButton("Tools/Scene Viewer", () => new SceneEditor(diContainer));

windowContainer.MenuBar.AddButton("Launch Game", () => InDevLaunchGame(diContainer, ctx));
windowContainer.MenuBar.AddButton("ImGui Demo", () => windowContainer.ShowImGuiDemoWindow = true);

openDocumentSet.AddEditorType<ModelViewer>("dff");
openDocumentSet.AddEditorType<WorldViewer>("bsp");
openDocumentSet.AddEditorType<SceneEditor>("scn");
Expand Down
4 changes: 3 additions & 1 deletion zzre/tools/ZanzarahWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public event Action<Vector2> OnMouseMove

public ZanzarahWindow(ITagContainer diContainer, Savegame? savegame = null)
{
GlobalWindowIndex++;
this.diContainer = diContainer;
Window = diContainer.GetTag<WindowContainer>().NewWindow("Zanzarah");
Window.AddTag(this);
Expand Down Expand Up @@ -156,9 +157,10 @@ private void HandleMouseDrag(MouseButton button, Vector2 delta)
private void HandleMouseUp(MouseButton button, Vector2 _) => buttonsDown.Remove(button);
public bool IsMouseDown(MouseButton button) => buttonsDown.Contains(button);

private static int GlobalWindowIndex = 0; // to allow for multiple ZanzarahWindows without ImGui being mad
private void HandleResize()
{
Window.Title = $"Zanzarah {fbArea.Framebuffer.Width}x{fbArea.Framebuffer.Height}###Zanzarah";
Window.Title = $"Zanzarah {fbArea.Framebuffer.Width}x{fbArea.Framebuffer.Height}###Zanzarah{GlobalWindowIndex}";
}

private void HandleOpenScene()
Expand Down

0 comments on commit 1079e07

Please sign in to comment.