Only show objects with a delay
This commit is contained in:
parent
d16c8f47b2
commit
e5d7b89675
@ -8,6 +8,7 @@ using Dalamud.IoC;
|
||||
using Dalamud.Plugin;
|
||||
using ImGuiNET;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
@ -33,6 +34,11 @@ namespace SliceIsRight
|
||||
private const ushort GoldSaucerTerritoryId = 144;
|
||||
private bool IsInGoldSaucer { get; set; }
|
||||
|
||||
private readonly IDictionary<uint, DateTime> objectsAndSpawnTime = new Dictionary<uint, DateTime>();
|
||||
private readonly ISet<uint> objectsToMatch = new HashSet<uint>();
|
||||
|
||||
private const float MaxDistance = 30f;
|
||||
|
||||
public SliceIsRightPlugin()
|
||||
{
|
||||
PluginInterface!.UiBuilder.Draw += DrawUI;
|
||||
@ -64,26 +70,29 @@ namespace SliceIsRight
|
||||
if (!ClientState.IsLoggedIn || !IsInGoldSaucer || ObjectTable == null)
|
||||
return;
|
||||
|
||||
|
||||
for (int index = 0; index < ObjectTable.Length; ++ index)
|
||||
{
|
||||
GameObject? obj = ObjectTable[index];
|
||||
if (obj == null)
|
||||
if (obj == null || DistanceToPlayer(obj.Position) > MaxDistance)
|
||||
continue;
|
||||
|
||||
int model = Marshal.ReadInt32(obj.Address + 128);
|
||||
if (obj.ObjectKind == ObjectKind.EventObj && (model >= 2010777 && model <= 2010779))
|
||||
{
|
||||
//this.DebugObject(index, obj, model);
|
||||
//DebugObject(index, obj, model);
|
||||
RenderObject(index, obj, model);
|
||||
}
|
||||
else if (ClientState.LocalPlayer?.ObjectId == obj.ObjectId)
|
||||
{
|
||||
// local player
|
||||
//this.DebugObject(index, obj, model);
|
||||
//this.RenderObject(index, obj, 2010779);
|
||||
DebugObject(index, obj, model);
|
||||
//RenderObject(index, obj, 2010779);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (uint objectId in objectsToMatch)
|
||||
objectsAndSpawnTime.Remove(objectId);
|
||||
objectsToMatch.Clear();
|
||||
}
|
||||
|
||||
|
||||
@ -94,7 +103,8 @@ namespace SliceIsRight
|
||||
// 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 objectText = $"{obj.Address.ToInt64():X}:{obj.ObjectId:X}[{index}] - {obj.ObjectKind} - {model}: {obj.Name}";
|
||||
float distance = DistanceToPlayer(obj.Position);
|
||||
var objectText = $"{obj.Address.ToInt64():X}:{obj.ObjectId:X}[{index}] - {obj.ObjectKind} - {model}: {obj.Name} - {distance:F2}";
|
||||
|
||||
var screenPos = ImGui.GetMainViewport().Pos;
|
||||
var screenSize = ImGui.GetMainViewport().Size;
|
||||
@ -109,12 +119,12 @@ namespace SliceIsRight
|
||||
screenCoords.Y + windowSize.Y > screenPos.Y + screenSize.Y)
|
||||
return;
|
||||
|
||||
if (obj.YalmDistanceX > 20f)
|
||||
if (distance > MaxDistance)
|
||||
return;
|
||||
|
||||
ImGui.SetNextWindowPos(new Vector2(screenCoords.X, screenCoords.Y));
|
||||
|
||||
ImGui.SetNextWindowBgAlpha(Math.Max(1f - (obj.YalmDistanceX / 20f), 0.2f));
|
||||
ImGui.SetNextWindowBgAlpha(Math.Max(1f - (distance / MaxDistance), 0.2f));
|
||||
if (ImGui.Begin(
|
||||
$"Actor{index}##ActorWindow{index}",
|
||||
ImGuiWindowFlags.NoDecoration |
|
||||
@ -132,6 +142,20 @@ namespace SliceIsRight
|
||||
|
||||
private void RenderObject(int index, GameObject obj, int model)
|
||||
{
|
||||
objectsToMatch.Remove(obj.ObjectId);
|
||||
|
||||
if (objectsAndSpawnTime.TryGetValue(obj.ObjectId, out DateTime spawnTime))
|
||||
{
|
||||
if (spawnTime.AddSeconds(5) > DateTime.Now)
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
objectsAndSpawnTime.Add(obj.ObjectId, DateTime.Now);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ImGui.PushID("booWindow" + index);
|
||||
|
||||
ImGui.PushStyleVar((ImGuiStyleVar)1, new Vector2(0.0f, 0.0f));
|
||||
@ -230,5 +254,10 @@ namespace SliceIsRight
|
||||
nearCenter = farCenter;
|
||||
}
|
||||
}
|
||||
|
||||
private float DistanceToPlayer(Vector3 center)
|
||||
{
|
||||
return Vector3.Distance(ClientState.LocalPlayer?.Position ?? Vector3.Zero, center);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user