-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathPlaybackControlsUI.cs
264 lines (222 loc) · 11.5 KB
/
PlaybackControlsUI.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
using System;
using System.Diagnostics;
using System.Numerics;
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Interface;
using Dalamud.Interface.Utility;
using FFXIVClientStructs.FFXIV.Client.System.Framework;
using FFXIVClientStructs.FFXIV.Component.GUI;
using Hypostasis.Game.Structures;
using ImGuiNET;
namespace ARealmRecorded;
public static unsafe class PlaybackControlsUI
{
public static readonly float[] presetSpeeds = [ 0.5f, 1, 2, 5, 10, 20 ];
private static bool loadingPlayback = false;
private static bool loadedPlayback = true;
private static bool shouldPlaybackControlHide = false;
private static bool showReplaySettings = false;
private static bool showDebug = false;
private static float lastSeek = 0;
private static bool showUnstuckButton = false;
private static readonly Stopwatch unstuckTimer = new();
public static void Draw()
{
if (DalamudApi.GameGui.GameUiHidden || DalamudApi.Condition[ConditionFlag.WatchingCutscene]) return;
if (!Common.ContentsReplayModule->InPlayback)
{
loadingPlayback = false;
loadedPlayback = false;
return;
}
if (DalamudApi.GameGui.GetAddonByName("TalkSubtitle") != nint.Zero) return; // Hide during cutscenes
if (Common.ContentsReplayModule->seek != lastSeek || Common.ContentsReplayModule->IsPaused)
{
lastSeek = Common.ContentsReplayModule->seek;
unstuckTimer.Restart();
showUnstuckButton = false;
}
else if (unstuckTimer.ElapsedMilliseconds > 3_000)
{
showUnstuckButton = true;
loadedPlayback = true;
}
if (!loadedPlayback)
{
if (Common.ContentsReplayModule->u0x708 != 0)
{
loadingPlayback = true;
}
else if (loadingPlayback && Common.ContentsReplayModule->u0x708 == 0)
{
loadedPlayback = true;
if (!ARealmRecorded.Config.EnableWaymarks)
Game.ToggleWaymarks();
}
return;
}
var addon = (AtkUnitBase*)DalamudApi.GameGui.GetAddonByName("ContentsReplayPlayer");
if (addon == null || (ARealmRecorded.Config.EnablePlaybackControlHiding && !addon->IsVisible && !showUnstuckButton))
{
shouldPlaybackControlHide = true;
return;
}
using var _ = ImGuiEx.StyleVarBlock.Begin(ImGuiStyleVar.Alpha, ARealmRecorded.Config.EnablePlaybackControlHiding && shouldPlaybackControlHide && !showUnstuckButton ? 0.001f : 1);
var addonW = addon->RootNode->GetWidth() * addon->Scale;
var addonPadding = addon->Scale * 8;
ImGuiHelpers.ForceNextWindowMainViewport();
ImGui.SetNextWindowPos(new Vector2(addon->X + addonPadding, addon->Y + addonPadding) + ImGuiHelpers.MainViewport.Pos, ImGuiCond.Always, Vector2.UnitY);
ImGui.SetNextWindowSize(new Vector2(addonW - addonPadding * 2, 0));
ImGui.Begin("Expanded Playback", ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings);
if (showReplaySettings && !Common.ContentsReplayModule->IsLoadingChapter)
{
DrawReplaySettings();
ImGui.Separator();
}
else if (showDebug)
{
DrawDebug();
ImGui.Separator();
}
//if (ImGuiEx.FontButton(FontAwesomeIcon.List.ToIconString(), UiBuilder.IconFont))
// ReplayListUI.DisplayDetachedReplayList ^= true;
//ImGuiEx.SetItemTooltip("Display replay list.");
//ImGui.SameLine();
if (ImGuiEx.FontButton(FontAwesomeIcon.Users.ToIconString(), UiBuilder.IconFont))
Framework.Instance()->GetUIModule()->EnterGPose();
ImGuiEx.SetItemTooltip("Enters group pose.");
ImGui.SameLine();
if (ImGuiEx.FontButton(FontAwesomeIcon.Video.ToIconString(), UiBuilder.IconFont))
Framework.Instance()->GetUIModule()->EnterIdleCam(0, DalamudApi.TargetManager.FocusTarget is { } focus ? focus.GameObjectId : 0xE0000000);
ImGuiEx.SetItemTooltip("Enters idle camera on the current focus target.");
ImGui.SameLine();
var v = Game.IsWaymarkVisible;
if (ImGuiEx.FontButton(v ? FontAwesomeIcon.ToggleOn.ToIconString() : FontAwesomeIcon.ToggleOff.ToIconString(), UiBuilder.IconFont))
{
Game.ToggleWaymarks();
ARealmRecorded.Config.EnableWaymarks ^= true;
ARealmRecorded.Config.Save();
}
ImGuiEx.SetItemTooltip(v ? "Hide waymarks." : "Show waymarks.");
using (ImGuiEx.FontBlock.Begin(UiBuilder.IconFont))
{
ImGui.SameLine();
if (ImGui.Button(FontAwesomeIcon.Cog.ToIconString()))
showReplaySettings ^= true;
ImGui.SameLine();
ImGui.Button(FontAwesomeIcon.Skull.ToIconString());
if (ImGui.BeginPopupContextItem(null, ImGuiPopupFlags.MouseButtonLeft))
{
if (ImGui.Selectable(FontAwesomeIcon.DoorOpen.ToIconString()))
Common.ContentsReplayModule->overallDataOffset = long.MaxValue;
ImGui.EndPopup();
}
#if DEBUG
ImGui.SameLine();
if (ImGui.Button(FontAwesomeIcon.ExclamationTriangle.ToIconString()))
showDebug ^= true;
#endif
}
if (showUnstuckButton)
{
ImGui.SameLine();
var segment = Game.GetReplayDataSegmentDetour(Common.ContentsReplayModule);
using (ImGuiEx.StyleColorBlock.Begin(ImGuiCol.Button, ImGui.GetColorU32(ImGuiCol.TabActive)))
{
if (ImGui.Button("UNSTUCK") && segment != null)
Common.ContentsReplayModule->overallDataOffset += segment->Length;
}
}
using (ImGuiEx.FontBlock.Begin(UiBuilder.IconFont))
{
var buttonSize = ImGui.CalcTextSize(FontAwesomeIcon.EyeSlash.ToIconString()) + ImGui.GetStyle().FramePadding * 2;
ImGui.SameLine(ImGui.GetContentRegionMax().X - buttonSize.X);
if (ImGui.Button(ARealmRecorded.Config.EnablePlaybackControlHiding ? FontAwesomeIcon.EyeSlash.ToIconString() : FontAwesomeIcon.Eye.ToIconString(), buttonSize))
{
ARealmRecorded.Config.EnablePlaybackControlHiding ^= true;
ARealmRecorded.Config.Save();
}
}
ImGuiEx.SetItemTooltip("Hides the menu under certain circumstances.");
const int restartDelayMS = 12_000;
var sliderWidth = ImGui.GetContentRegionAvail().X;
var seekMS = Math.Max(Common.ContentsReplayModule->seek.ToMilliseconds(), (int)Common.ContentsReplayModule->chapters[0]->ms);
var lastStartChapterMS = Common.ContentsReplayModule->chapters[Common.ContentsReplayModule->FindPreviousChapterType(2)]->ms;
var nextStartChapterMS = Common.ContentsReplayModule->chapters[Common.ContentsReplayModule->FindNextChapterType(2)]->ms;
if (lastStartChapterMS >= nextStartChapterMS)
nextStartChapterMS = Common.ContentsReplayModule->replayHeader.totalMS;
var currentTime = new TimeSpan(0, 0, 0, 0, (int)(seekMS - lastStartChapterMS));
using (ImGuiEx.ItemWidthBlock.Begin(sliderWidth))
{
using (ImGuiEx.DisabledBlock.Begin(Common.ContentsReplayModule->IsLoadingChapter))
using (ImGuiEx.StyleVarBlock.Begin(ImGuiStyleVar.GrabMinSize, 4))
ImGui.SliderInt($"##Time{lastStartChapterMS}", ref seekMS, (int)lastStartChapterMS, (int)nextStartChapterMS - restartDelayMS, currentTime.ToString("hh':'mm':'ss"), ImGuiSliderFlags.NoInput);
if (ImGui.IsItemHovered())
{
var hoveredWidth = ImGui.GetMousePos().X - ImGui.GetItemRectMin().X;
var hoveredPercent = hoveredWidth / sliderWidth;
if (hoveredPercent is >= 0.0f and <= 1.0f)
{
var hoveredTime = new TimeSpan(0, 0, 0, 0, (int)Math.Min(Math.Max((int)((nextStartChapterMS - lastStartChapterMS - restartDelayMS) * hoveredPercent), 0), nextStartChapterMS - lastStartChapterMS));
ImGui.SetTooltip(hoveredTime.ToString("hh':'mm':'ss"));
if (ImGui.IsMouseClicked(ImGuiMouseButton.Left))
ReplayManager.SeekToTime((uint)hoveredTime.TotalMilliseconds + lastStartChapterMS);
else if (ARealmRecorded.Config.EnableJumpToTime && ImGui.IsMouseClicked(ImGuiMouseButton.Right))
ReplayManager.JumpToTime((uint)hoveredTime.TotalMilliseconds + lastStartChapterMS);
}
}
var speed = Common.ContentsReplayModule->speed;
if (ImGui.SliderFloat("##Speed", ref speed, 0.05f, 10.0f, "%.2fx", ImGuiSliderFlags.AlwaysClamp))
Common.ContentsReplayModule->speed = speed;
}
for (int i = 0; i < presetSpeeds.Length; i++)
{
if (i != 0)
ImGui.SameLine();
var s = presetSpeeds[i];
if (ImGui.Button($"{s}x"))
Common.ContentsReplayModule->speed = s == Common.ContentsReplayModule->speed ? 1 : s;
}
var customSpeed = ARealmRecorded.Config.CustomSpeedPreset;
ImGui.SameLine();
ImGui.Dummy(Vector2.Zero);
ImGui.SameLine();
if (ImGui.Button($"{customSpeed}x"))
Common.ContentsReplayModule->speed = customSpeed == Common.ContentsReplayModule->speed ? 1 : customSpeed;
shouldPlaybackControlHide = !ImGui.IsWindowHovered(ImGuiHoveredFlags.ChildWindows | ImGuiHoveredFlags.RectOnly);
ImGui.End();
}
private static void DrawReplaySettings()
{
var save = false;
if (ImGui.Checkbox("Hide Own Name (Requires Replay Restart)", ref ARealmRecorded.Config.EnableHideOwnName))
{
Game.replaceLocalPlayerNamePatch.Toggle();
save = true;
}
save |= ImGui.Checkbox("Enable Quick Chapter Load", ref ARealmRecorded.Config.EnableQuickLoad);
save |= ImGui.Checkbox("Enable Right Click to Jump to Time", ref ARealmRecorded.Config.EnableJumpToTime);
if (ImGui.IsItemHovered())
ImGui.SetTooltip("Doing this WILL result in playback not appearing correctly!");
ImGui.SameLine();
using (ImGuiEx.FontBlock.Begin(UiBuilder.IconFont))
ImGui.TextColored(new Vector4(1, 1, 0, 1), FontAwesomeIcon.ExclamationTriangle.ToIconString());
save |= ImGui.SliderFloat("Loading Speed", ref ARealmRecorded.Config.MaxSeekDelta, 100, 2000, "%.f%%");
if (ImGui.IsItemHovered())
ImGui.SetTooltip("Can cause issues with some fights that contain arena changes.");
save |= ImGui.SliderFloat("Speed Preset", ref ARealmRecorded.Config.CustomSpeedPreset, 0.05f, 60, "%.2fx", ImGuiSliderFlags.AlwaysClamp);
if (save)
ARealmRecorded.Config.Save();
}
[Conditional("DEBUG")]
private static void DrawDebug()
{
var segment = Game.GetReplayDataSegmentDetour(Common.ContentsReplayModule);
if (segment == null) return;
ImGui.TextUnformatted($"Offset: {Common.ContentsReplayModule->overallDataOffset + sizeof(FFXIVReplay.Header) + sizeof(FFXIVReplay.ChapterArray):X}");
ImGui.TextUnformatted($"Opcode: {segment->opcode:X}");
ImGui.TextUnformatted($"Data Length: {segment->dataLength}");
ImGui.TextUnformatted($"Time: {segment->ms / 1000f}");
ImGui.TextUnformatted($"Object ID: {segment->objectID:X}");
}
}