-
Notifications
You must be signed in to change notification settings - Fork 9
/
TempOffsetOverlay.cs
186 lines (147 loc) · 8.97 KB
/
TempOffsetOverlay.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
using System;
using System.Numerics;
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Interface.Windowing;
using FFXIVClientStructs.FFXIV.Client.Game.Character;
using ImGuiNET;
using ImGuizmoNET;
namespace SimpleHeels;
public sealed unsafe class TempOffsetOverlay : Window {
private Plugin plugin;
private PluginConfig config;
public TempOffsetOverlay(string name, Plugin plugin, PluginConfig config) : base(name) {
this.plugin = plugin;
this.config = config;
SizeCondition = ImGuiCond.FirstUseEver;
Size = new Vector2(180, 100);
SizeConstraints = new WindowSizeConstraints() {
MinimumSize = new Vector2(100, 100),
MaximumSize = new Vector2(float.MaxValue, 100)
};
RespectCloseHotkey = false;
IsOpen = true;
PreDraw();
}
public override void OnClose() {
IsOpen = true;
config.TempOffsetWindowOpen = false;
}
public override void OnOpen() {
config.TempOffsetWindowOpen = true;
}
public override void PreDraw() {
ShowCloseButton = !config.TempOffsetWindowLock;
Flags = ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse | ImGuiWindowFlags.NoDocking | ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoTitleBar;
if (config.TempOffsetWindowLock) {
Flags |= ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize;
if (config.TempOffsetWindowTransparent) Flags |= ImGuiWindowFlags.NoBackground;
}
}
public bool TryGetActiveCharacter(out Character* character) {
character = (Character*)(PluginService.ClientState.LocalPlayer?.Address ?? nint.Zero);
if (character == null) return false;
if (character->GameObject.ObjectIndex >= Constants.ObjectLimit) return false;
if (!character->GameObject.IsCharacter()) return false;
return true;
}
public override bool DrawConditions() {
if (!config.TempOffsetWindowOpen) return false;
if (PluginService.ClientState.IsGPosing) return false;
if (PluginService.Condition.Any(ConditionFlag.WatchingCutscene, ConditionFlag.WatchingCutscene78, ConditionFlag.InCombat, ConditionFlag.InFlight)) return false;
return TryGetActiveCharacter(out _);
}
public override void Draw() {
if (!TryGetActiveCharacter(out var obj)) return;
var activeEmote = EmoteIdentifier.Get(obj);
var tempOffset = Plugin.TempOffsets[obj->GameObject.ObjectIndex];
var showingActive = tempOffset == null;
var edited = false;
if (tempOffset == null) {
tempOffset = new TempOffset();
if (plugin.TryGetCharacterConfig(obj, out var characterConfig))
if (characterConfig.TryGetFirstMatch(obj, out var offsetProvider))
(tempOffset.X, tempOffset.Y, tempOffset.Z, tempOffset.R, tempOffset.Pitch, tempOffset.Roll) = offsetProvider;
}
if (Plugin.Config.TempOffsetShowGizmo) {
edited = UIGizmoOverlay.Draw(tempOffset, obj, activeEmote != null, activeEmote != null);
}
ImGui.PushItemWidth(ImGui.GetContentRegionAvail().X);
edited |= ImGuiExt.FloatEditor("##height", ref tempOffset.Y, 0.0001f, forcePlusMinus: config.TempOffsetWindowPlusMinus);
if (config.TempOffsetWindowTooltips && ImGui.IsItemHovered()) ImGui.SetTooltip("Height");
using (ImRaii.Disabled(activeEmote == null)) {
edited |= ImGuiExt.FloatEditor("##forward", ref tempOffset.Z, 0.0001f, forcePlusMinus: config.TempOffsetWindowPlusMinus);
if (config.TempOffsetWindowTooltips && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) ImGui.SetTooltip("Forward / Backward");
edited |= ImGuiExt.FloatEditor("##side", ref tempOffset.X, -0.0001f, forcePlusMinus: config.TempOffsetWindowPlusMinus);
if (config.TempOffsetWindowTooltips && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) ImGui.SetTooltip("Left / Right");
var rot = tempOffset.R * 180f / MathF.PI;
if (ImGuiExt.FloatEditor("##rotation", ref rot, format: "%.0f", customPlusMinus: 1, forcePlusMinus: config.TempOffsetWindowPlusMinus)) {
edited = true;
if (rot < 0) rot += 360;
if (rot >= 360) rot -= 360;
tempOffset.R = rot * MathF.PI / 180f;
}
if (config.TempOffsetWindowTooltips && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) ImGui.SetTooltip("Rotation");
if (config.TempOffsetPitchRoll) {
var pitch = tempOffset.Pitch * 180f / MathF.PI;
if (ImGuiExt.FloatEditor("##pitch", ref pitch, format: "%.0f", customPlusMinus: 1, forcePlusMinus: config.TempOffsetWindowPlusMinus)) {
edited = true;
if (pitch < 0) pitch += 360;
if (pitch >= 360) pitch -= 360;
tempOffset.Pitch = pitch * MathF.PI / 180f;
}
if (config.TempOffsetWindowTooltips && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) ImGui.SetTooltip("Pitch");
var roll = tempOffset.Roll * 180f / MathF.PI;
if (ImGuiExt.FloatEditor("##roll", ref roll, format: "%.0f", customPlusMinus: 1, forcePlusMinus: config.TempOffsetWindowPlusMinus)) {
edited = true;
if (roll < 0) roll += 360;
if (roll >= 360) roll -= 360;
tempOffset.Roll = roll * MathF.PI / 180f;
}
if (config.TempOffsetWindowTooltips && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) ImGui.SetTooltip("Roll");
}
}
if (showingActive && activeEmote != null && Plugin.PreviousTempOffsets.TryGetValue(activeEmote, out var prevValue)) {
if (ImGui.Button(ImGui.GetContentRegionAvail().X < 105 * ImGuiHelpers.GlobalScale ? "Reapply" : "Reapply Offset", new Vector2(ImGui.CalcItemWidth(), ImGui.GetTextLineHeightWithSpacing()))) {
Plugin.TempOffsets[obj->GameObject.ObjectIndex] = prevValue;
Plugin.TempOffsetEmote[obj->GameObject.ObjectIndex] = activeEmote;
ApiProvider.ForceUpdateLocal();
}
} else {
using (ImRaii.Disabled(showingActive)) {
if (ImGui.Button(ImGui.GetContentRegionAvail().X < 105 * ImGuiHelpers.GlobalScale ? "Reset" : "Reset Offset", new Vector2(ImGui.CalcItemWidth(), ImGui.GetTextLineHeightWithSpacing()))) {
Plugin.TempOffsets[obj->GameObject.ObjectIndex] = null;
Plugin.TempOffsetEmote[obj->GameObject.ObjectIndex] = null;
ApiProvider.ForceUpdateLocal();
}
}
}
ImGui.PopItemWidth();
if (edited) {
Plugin.TempOffsets[obj->GameObject.ObjectIndex] = tempOffset;
Plugin.TempOffsetEmote[obj->GameObject.ObjectIndex] = activeEmote;
}
// Auto Resize Height Only
if (Size != null && ImGui.GetContentRegionAvail().Y != 0) {
Size = Size.Value with { Y = Size.Value.Y - (ImGui.GetContentRegionAvail().Y * 1 / ImGuiHelpers.GlobalScale) };
SizeConstraints = new WindowSizeConstraints {
MinimumSize = Size.Value with { X = 100 },
MaximumSize = Size.Value with { X = float.MaxValue },
};
}
if (ImGui.IsWindowHovered(ImGuiHoveredFlags.AllowWhenOverlapped | ImGuiHoveredFlags.AllowWhenBlockedByPopup | ImGuiHoveredFlags.AllowWhenBlockedByActiveItem)) {
var dl = ImGui.GetBackgroundDrawList();
if (!config.TempOffsetWindowTransparent) {
dl.AddRectFilled(ImGui.GetWindowPos() - new Vector2(0, ImGui.GetTextLineHeightWithSpacing() + ImGui.GetStyle().ItemSpacing.Y), ImGui.GetWindowPos() + new Vector2(ImGui.GetWindowWidth(), 0), ImGui.GetColorU32(ImGuiCol.TitleBgActive), ImGui.GetStyle().WindowRounding, ImDrawFlags.RoundCornersTop);
}
if (ImGui.GetStyle().WindowBorderSize > 0) {
dl.AddRect(ImGui.GetWindowPos() - new Vector2(0, ImGui.GetTextLineHeightWithSpacing() + ImGui.GetStyle().ItemSpacing.Y), ImGui.GetWindowPos() + new Vector2(ImGui.GetWindowWidth(), ImGui.GetWindowHeight()), ImGui.GetColorU32(ImGuiCol.Border), ImGui.GetStyle().WindowRounding, ImDrawFlags.RoundCornersTop, ImGui.GetStyle().WindowBorderSize);
if (config.TempOffsetWindowTransparent) {
dl.AddLine(ImGui.GetWindowPos(), ImGui.GetWindowPos() + ImGui.GetWindowSize() with { Y = 0 }, ImGui.GetColorU32(ImGuiCol.Border), ImGui.GetStyle().WindowBorderSize);
}
}
dl.AddText(ImGui.GetWindowPos() - new Vector2(-ImGui.GetStyle().WindowPadding.X, ImGui.GetTextLineHeightWithSpacing()), ImGui.GetColorU32(ImGuiCol.Text), "Simple Heels");
}
}
}