This commit is contained in:
goat 2021-04-01 22:57:33 +02:00
commit 5baf0b6d8b
7 changed files with 73 additions and 37 deletions

View file

@ -146,6 +146,7 @@ namespace Dalamud.Interface
// AT
case 2:
this.DrawActorTable();
break;
// Font
@ -289,20 +290,15 @@ namespace Dalamud.Interface
return isOpen;
}
private void DrawActorTable()
{
private void DrawActorTable() {
var stateString = string.Empty;
// LocalPlayer is null in a number of situations (at least with the current visible-actors list)
// which would crash here.
if (this.dalamud.ClientState.Actors.Length == 0)
{
ImGui.TextUnformatted("Data not ready.");
}
else if (this.dalamud.ClientState.LocalPlayer == null)
{
ImGui.TextUnformatted("LocalPlayer null.");
}
else
{
stateString +=
@ -324,40 +320,53 @@ namespace Dalamud.Interface
ImGui.Checkbox("Draw actors on screen", ref this.drawActors);
ImGui.SliderFloat("Draw Distance", ref this.maxActorDrawDistance, 2f, 40f);
for (var i = 0; i < this.dalamud.ClientState.Actors.Length; i++)
{
for (var i = 0; i < this.dalamud.ClientState.Actors.Length; i++) {
var actor = this.dalamud.ClientState.Actors[i];
if (actor == null)
continue;
this.PrintActor(actor, i.ToString());
PrintActor(actor, i.ToString());
if (this.drawActors &&
this.dalamud.Framework.Gui.WorldToScreen(actor.Position, out var screenCoords))
{
ImGui.PushID("ActorWindow" + i);
ImGui.SetNextWindowPos(new Vector2(screenCoords.X, screenCoords.Y));
this.dalamud.Framework.Gui.WorldToScreen(actor.Position, out var screenCoords)) {
// So, while WorldToScreen will return false if the point is off of game client screen, to
// to avoid performance issues, we have to manually determine if creating a window would
// produce a new viewport, and skip rendering it if so
var actorText =
$"{actor.Address.ToInt64():X}:{actor.ActorId:X}[{i}] - {actor.ObjectKind} - {actor.Name}";
var screenPos = ImGui.GetMainViewport().Pos;
var screenSize = ImGui.GetMainViewport().Size;
var windowSize = ImGui.CalcTextSize(actorText);
// Add some extra safety padding
windowSize.X += ImGui.GetStyle().WindowPadding.X + 10;
windowSize.Y += ImGui.GetStyle().WindowPadding.Y + 10;
if (screenCoords.X + windowSize.X > screenPos.X + screenSize.X ||
screenCoords.Y + windowSize.Y > screenPos.Y + screenSize.Y)
continue;
if (actor.YalmDistanceX > this.maxActorDrawDistance)
continue;
ImGui.SetNextWindowBgAlpha(
Math.Max(1f - (actor.YalmDistanceX / this.maxActorDrawDistance), 0.2f));
if (ImGui.Begin(
"Actor" + i,
ImGuiWindowFlags.NoDecoration |
ImGuiWindowFlags.AlwaysAutoResize |
ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoMove |
ImGuiWindowFlags.NoMouseInputs |
ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoNav))
{
ImGui.Text(
$"{actor.Address.ToInt64():X}:{actor.ActorId:X}[{i}] - {actor.ObjectKind} - {actor.Name}");
ImGui.End();
}
ImGui.SetNextWindowPos(new Vector2(screenCoords.X, screenCoords.Y));
ImGui.PopID();
ImGui.SetNextWindowBgAlpha(Math.Max(1f - actor.YalmDistanceX / this.maxActorDrawDistance,
0.2f));
if (ImGui.Begin($"Actor{i}##ActorWindow{i}",
ImGuiWindowFlags.NoDecoration |
ImGuiWindowFlags.AlwaysAutoResize |
ImGuiWindowFlags.NoSavedSettings |
ImGuiWindowFlags.NoMove |
ImGuiWindowFlags.NoMouseInputs |
ImGuiWindowFlags.NoDocking |
ImGuiWindowFlags.NoFocusOnAppearing |
ImGuiWindowFlags.NoNav))
ImGui.Text(actorText);
ImGui.End();
}
}
}

View file

@ -84,7 +84,8 @@ namespace Dalamud.Interface
ImGui.PushStyleColor(ImGuiCol.BorderShadow, new Vector4(0, 0, 0, 1));
ImGui.PushStyleColor(ImGuiCol.WindowBg, new Vector4(0, 0, 0, 1));
ImGui.SetNextWindowPos(new Vector2(0, 0), ImGuiCond.Always);
var mainViewportPos = ImGui.GetMainViewport().Pos;
ImGui.SetNextWindowPos(new Vector2(mainViewportPos.X, mainViewportPos.Y), ImGuiCond.Always);
ImGui.SetNextWindowBgAlpha(1);
if (ImGui.Begin("DevMenu Opener", ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoSavedSettings))

View file

@ -165,7 +165,7 @@ namespace Dalamud.Interface
// So... not great, but much better than constantly crashing on unload
this.Disable();
System.Threading.Thread.Sleep(500);
this.scene?.Dispose();
this.presentHook.Dispose();
this.resizeBuffersHook.Dispose();
@ -228,6 +228,7 @@ namespace Dalamud.Interface
private IntPtr PresentDetour(IntPtr swapChain, uint syncInterval, uint presentFlags)
{
if (this.scene == null) {
this.scene = new RawDX11Scene(swapChain);
this.scene.ImGuiIniPath = Path.Combine(Path.GetDirectoryName(this.dalamud.StartInfo.ConfigurationPath), "dalamudUI.ini");
@ -357,7 +358,12 @@ namespace Dalamud.Interface
private IntPtr ResizeBuffersDetour(IntPtr swapChain, uint bufferCount, uint width, uint height, uint newFormat, uint swapChainFlags)
{
Log.Verbose($"Calling resizebuffers {bufferCount} {width} {height} {newFormat} {swapChainFlags}");
Log.Verbose($"Calling resizebuffers swap@{swapChain.ToInt64():X}{bufferCount} {width} {height} {newFormat} {swapChainFlags}");
// We have to ensure we're working with the main swapchain,
// as viewports might be resizing as well
if (swapChain != this.scene.SwapChain.NativePointer)
return resizeBuffersHook.Original(swapChain, bufferCount, width, height, newFormat, swapChainFlags);
this.scene?.OnPreResize();