feat: add draw distance to actor view

This commit is contained in:
goat 2020-04-29 18:56:21 +02:00
parent a58de19abc
commit 0800cc4e91
3 changed files with 21 additions and 4 deletions

View file

@ -49,5 +49,15 @@ namespace Dalamud.Game.ClientState.Actors.Types {
/// possible values.
/// </summary>
public ObjectKind ObjectKind => this.actorStruct.ObjectKind;
/// <summary>
/// The X distance from the local player in yalms.
/// </summary>
public byte YalmDistanceX => this.actorStruct.YalmDistanceFromPlayerX;
/// <summary>
/// The Y distance from the local player in yalms.
/// </summary>
public byte YalmDistanceY => this.actorStruct.YalmDistanceFromPlayerY;
}
}

View file

@ -20,9 +20,9 @@ namespace Dalamud.Game.ClientState.Structs
[FieldOffset(140)] public ObjectKind ObjectKind;
[FieldOffset(141)] public byte SubKind;
[FieldOffset(142)] public bool IsFriendly;
[FieldOffset(144)] public byte YalmDistanceFromPlayer1; // Demo says one of these is x distance
[FieldOffset(144)] public byte YalmDistanceFromPlayerX; // Demo says one of these is x distance
[FieldOffset(145)] public byte PlayerTargetStatus; // This is some kind of enum
[FieldOffset(146)] public byte YalmDistanceFromPlayer2; // and the other is z distance
[FieldOffset(146)] public byte YalmDistanceFromPlayerY; // and the other is z distance
[FieldOffset(160)] public Position3 Position;
[FieldOffset(0x17F8)] public int TargetActorId;
// This field can't be correctly aligned, so we have to cut it manually.

View file

@ -1,3 +1,4 @@
using System;
using System.Linq;
using System.Numerics;
using Dalamud.Game.Chat;
@ -18,6 +19,7 @@ namespace Dalamud.Interface
private int currentKind;
private bool drawActors = false;
private float maxActorDrawDistance = 20;
public DalamudDataWindow(Dalamud dalamud) {
this.dalamud = dalamud;
@ -87,6 +89,7 @@ namespace Dalamud.Interface
stateString += $"TerritoryType: {this.dalamud.ClientState.TerritoryType}\n\n";
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++) {
var actor = this.dalamud.ClientState.Actors[i];
@ -95,7 +98,7 @@ namespace Dalamud.Interface
continue;
stateString +=
$"{actor.Address.ToInt64():X}:{actor.ActorId:X}[{i}] - {actor.ObjectKind} - {actor.Name} - {actor.Position.X} {actor.Position.Y} {actor.Position.Z}\n";
$"{actor.Address.ToInt64():X}:{actor.ActorId:X}[{i}] - {actor.ObjectKind} - {actor.Name} - X{actor.Position.X} Y{actor.Position.Y} Z{actor.Position.Z} D{actor.YalmDistanceX}\n";
if (actor is Npc npc)
stateString += $" DataId: {npc.DataId} NameId:{npc.NameId}\n";
@ -111,7 +114,11 @@ namespace Dalamud.Interface
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));
ImGui.SetNextWindowBgAlpha(0.35f);
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 |