Skip to content

Make ToolbarWindow toggleable via command #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Ktisis/Events/EventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Ktisis.Events {
public static class EventManager {
public delegate void GPoseChange(ActorGposeState state);
public delegate void GPoseChange(bool isInGPose);
public static GPoseChange? OnGPoseChange = null;

public delegate void TransformationMatrixChange(bool state);
Expand All @@ -25,9 +25,9 @@ public static class EventManager {
internal delegate void KeyReleaseEventDelegate(VirtualKey key);
internal static KeyReleaseEventDelegate? OnKeyReleased;

public static void FireOnGposeChangeEvent(ActorGposeState state) {
Logger.Debug($"FireOnGposeChangeEvent {state}");
OnGPoseChange?.Invoke(state);
public static void FireOnGposeChangeEvent(bool isInGPose) {
Logger.Debug("FireOnGposeChangeEvent {0}", isInGPose ? "ON" : "OFF");
OnGPoseChange?.Invoke(isInGPose);
}

public static unsafe void FireOnTransformationMatrixChangeEvent(bool state) {
Expand Down
2 changes: 1 addition & 1 deletion Ktisis/History/HistoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void Undo() {
_currentIdx--;
}

internal static void OnGPoseChange(ActorGposeState _state) {
internal static void OnGPoseChange(bool isInGpose) {
Logger.Verbose("Clearing previous history...");
_currentIdx = 0;
_maxIdx = 0;
Expand Down
5 changes: 4 additions & 1 deletion Ktisis/Interface/Windows/ConfigGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Dalamud.Interface.Components;
using Dalamud.Game.ClientState.Keys;

using Ktisis.Interface.Windows.Toolbar;
using Ktisis.Util;
using Ktisis.Overlay;
using Ktisis.Localization;
Expand Down Expand Up @@ -149,8 +150,10 @@ public static void DrawInterfaceTab(Configuration cfg) {
cfg.TransformTableDisplayMultiplierInputs = displayMultiplierInputs;

var showToolbar = cfg.ShowToolbar;
if (ImGui.Checkbox("Show Experimental Toolbar", ref showToolbar))
if (ImGui.Checkbox("Show Experimental Toolbar", ref showToolbar)) {
cfg.ShowToolbar = showToolbar;
ToolbarWindow.Visible = showToolbar;
}

ImGui.Spacing();
ImGui.Separator();
Expand Down
21 changes: 19 additions & 2 deletions Ktisis/Interface/Windows/Toolbar/ToolbarWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,38 @@

using Ktisis.History;
using Ktisis.Interface.Components;
using Ktisis.Events;
using Ktisis.Interface.Windows.ActorEdit;
using Ktisis.Interop.Hooks;
using Ktisis.Overlay;
using Ktisis.Util;

namespace Ktisis.Interface.Windows.Toolbar {
public static class ToolbarWindow {
private static bool Visible = true;
internal static bool Visible = false;

// Toggle visibility
public static void Toggle() => Visible = !Visible;

public static void Init() {
EventManager.OnGPoseChange += OnGPoseStateChange;
}

public static void Dispose() {
EventManager.OnGPoseChange -= OnGPoseStateChange;
}

public static void OnGPoseStateChange(bool isInGPose) {
if (isInGPose) {
if (Ktisis.Configuration.ShowToolbar)
Visible = true;
} else
Visible = false;
}

// Draw window
public static void Draw() {
if (!Visible || !Ktisis.IsInGPose || !Ktisis.Configuration.ShowToolbar)
if (!Visible)
return;

AdvancedWindow.Draw();
Expand Down
4 changes: 2 additions & 2 deletions Ktisis/Interface/Windows/Workspace/Workspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public static class Workspace {
public static void Show() => Visible = true;
public static void Toggle() => Visible = !Visible;

public static void OnEnterGposeToggle(Structs.Actor.State.ActorGposeState gposeState) {
public static void OnEnterGposeToggle(bool isInGpose) {
if (Ktisis.Configuration.OpenKtisisMethod == OpenKtisisMethod.OnEnterGpose)
Visible = gposeState == Structs.Actor.State.ActorGposeState.ON;
Visible = isInGpose;
}

public static float PanelHeight => ImGui.GetTextLineHeight() * 2 + ImGui.GetStyle().ItemSpacing.Y + ImGui.GetStyle().FramePadding.Y;
Expand Down
12 changes: 11 additions & 1 deletion Ktisis/Ktisis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Ktisis.Structs.Actor;
using Ktisis.History;
using Ktisis.Events;
using Ktisis.Interface.Windows.Toolbar;
using Ktisis.Overlay;

namespace Ktisis {
Expand Down Expand Up @@ -68,6 +69,7 @@ public Ktisis(DalamudPluginInterface pluginInterface) {

Input.Init();
ActorStateWatcher.Init();
ToolbarWindow.Init();

// Register command

Expand Down Expand Up @@ -102,7 +104,7 @@ public void Dispose() {
Interop.Hooks.PoseHooks.Dispose();

Interop.Alloc.Dispose();
ActorStateWatcher.Instance.Dispose();
ActorStateWatcher.Dispose();
EventManager.OnGPoseChange -= Workspace.OnEnterGposeToggle;

Data.Sheets.Cache.Clear();
Expand All @@ -112,6 +114,7 @@ public void Dispose() {

Input.Dispose();
HistoryManager.Dispose();
ToolbarWindow.Dispose();

foreach (var (_, texture) in References.Textures) {
texture.Dispose();
Expand All @@ -131,6 +134,13 @@ private void OnCommand(string command, string arguments) {
case "configuration":
ConfigGui.Toggle();
break;
case "toolbar":
if (IsInGPose) {
ToolbarWindow.Toggle();
} else {
/* TODO: Throw a warning up? */
}
break;
default:
Workspace.Toggle();
break;
Expand Down
6 changes: 0 additions & 6 deletions Ktisis/Structs/Actor/State/ActorGposeState.cs

This file was deleted.

38 changes: 9 additions & 29 deletions Ktisis/Structs/Actor/State/ActorStateWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,24 @@
using System;

namespace Ktisis.Structs.Actor.State {
public sealed class ActorStateWatcher : IDisposable {
public static class ActorStateWatcher {

private static ActorStateWatcher? _instance;
private static bool _wasInGPose = false;

private ActorGposeState _gposeState = ActorGposeState.OFF;

public static ActorStateWatcher Instance {
get {
if (_instance == null) {
_instance = new ActorStateWatcher();
}
return _instance;
}
}

private ActorStateWatcher() {
Services.Framework.Update += Monitor;
}

public void Dispose() {
public static void Dispose() {
Services.Framework.Update -= Monitor;
if(Ktisis.IsInGPose)
EventManager.FireOnGposeChangeEvent(ActorGposeState.OFF);
EventManager.FireOnGposeChangeEvent(false);
}

public static void Init() {
_ = Instance;
Services.Framework.Update += Monitor;
}

public void Monitor(Framework framework) {
if (_gposeState == ActorGposeState.OFF && Ktisis.IsInGPose) {
_gposeState = ActorGposeState.ON;
EventManager.FireOnGposeChangeEvent(_gposeState);
}

if (_gposeState == ActorGposeState.ON && !Ktisis.IsInGPose) {
_gposeState = ActorGposeState.OFF;
EventManager.FireOnGposeChangeEvent(_gposeState);
public static void Monitor(Framework framework) {
if (_wasInGPose != Ktisis.IsInGPose) {
_wasInGPose = Ktisis.IsInGPose;
EventManager.FireOnGposeChangeEvent(Ktisis.IsInGPose);
}
}
}
Expand Down