Skip to content

Commit

Permalink
improve Active Mobs appearance
Browse files Browse the repository at this point in the history
  • Loading branch information
SlashNephy committed Apr 14, 2024
1 parent 33b5ab2 commit b4b84d6
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 145 deletions.
94 changes: 0 additions & 94 deletions FaloopIntegration/ActiveMobUi.cs

This file was deleted.

10 changes: 5 additions & 5 deletions FaloopIntegration/Config/PluginConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ private void DrawPerRankConfigs()
{
ImGui.Indent();

if (ImGuiEx.CheckboxConfig(Localization.EnableActiveMobUi, ref FaloopIntegration.Instance.Config.EnableActiveMobUi))
{
FaloopIntegration.Instance.Ui.IsDrawing = FaloopIntegration.Instance.Config.EnableActiveMobUi;
}

ImGui.Checkbox(Localization.EnableSimpleReports, ref FaloopIntegration.Instance.Config.EnableSimpleReports);

DrawPerRankConfig(Localization.RankS, ref Config.RankS);
Expand Down Expand Up @@ -117,11 +122,6 @@ private static void DrawDebugConfig()
{
if (ImGui.CollapsingHeader("Debug"))
{
if (ImGuiEx.CheckboxConfig(Localization.EnableActiveMobUi, ref FaloopIntegration.Instance.Config.EnableActiveMobUi))
{
FaloopIntegration.Instance.Ui.IsDrawing = FaloopIntegration.Instance.Config.EnableActiveMobUi;
}

if (ImGui.Button("Emit mock payload"))
{
FaloopIntegration.Instance.EmitMockData();
Expand Down
67 changes: 26 additions & 41 deletions FaloopIntegration/FaloopIntegration.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text.Json;
using System.Threading.Tasks;
using Dalamud.Divination.Common.Api.Dalamud;
Expand All @@ -15,6 +16,8 @@
using Divination.FaloopIntegration.Config;
using Divination.FaloopIntegration.Faloop;
using Divination.FaloopIntegration.Faloop.Model;
using Divination.FaloopIntegration.Ipc;
using Divination.FaloopIntegration.Ui;
using Lumina.Excel.GeneratedSheets;
using SocketIOClient;

Expand All @@ -27,7 +30,7 @@ public sealed class FaloopIntegration : DivinationPlugin<FaloopIntegration, Plug
{
private readonly FaloopSocketIOClient socket = new();
private readonly FaloopSession session = new();
public readonly ActiveMobUi Ui = new();
public readonly ActiveMobUi Ui;

public FaloopIntegration(DalamudPluginInterface pluginInterface) : base(pluginInterface)
{
Expand All @@ -45,7 +48,11 @@ public FaloopIntegration(DalamudPluginInterface pluginInterface) : base(pluginIn
socket.OnPing += OnPing;
socket.OnPong += OnPong;

Ui.IsDrawing = Config.EnableActiveMobUi;
var ipc = new AetheryteLinkInChatIpc(pluginInterface, Divination.Chat);
Ui = new ActiveMobUi(ipc, Divination.Chat)
{
IsDrawing = Config.EnableActiveMobUi
};
Dalamud.PluginInterface.UiBuilder.Draw += Ui.Draw;

Connect();
Expand Down Expand Up @@ -104,16 +111,26 @@ private void OnMobReport(MobReportData data)
case MobReportActions.Spawn when config.EnableSpawnReport:
{
var spawn = JsonSerializer.Deserialize<MobReportData.Spawn>(data.Data) ?? throw new InvalidOperationException("invalid spawn data");
var ev = new MobSpawnEvent(mobData.BNpcId, worldId, spawn.ZoneId, data.ZoneInstance, spawn.ZonePoiIds?.FirstOrDefault(), mobData.Rank, spawn.Timestamp, spawn.Reporters?.FirstOrDefault()?.Name);
if (!FaloopEmbedData.Locations.TryGetValue(spawn.ZonePoiIds?.FirstOrDefault() ?? default, out var location))
{
DalamudLog.Log.Debug("OnMobReport: location == null");
}

var ev = new MobSpawnEvent(mobData.BNpcId, worldId, spawn.ZoneId, data.ZoneInstance, mobData.Rank, spawn.Timestamp, spawn.Reporters?.FirstOrDefault()?.Name, location);
OnMobSpawn(ev, config.Channel);
DalamudLog.Log.Verbose("OnMobReport: OnSpawnMobReport");
break;
}
case MobReportActions.SpawnLocation when config.EnableSpawnReport:
{
var spawn = JsonSerializer.Deserialize<MobReportData.SpawnLocation>(data.Data) ?? throw new InvalidOperationException("invalid spawn location data");
if (!FaloopEmbedData.Locations.TryGetValue(spawn.ZonePoiId, out var location))
{
DalamudLog.Log.Debug("OnMobReport: location == null");
}

var previous = Config.SpawnStates.FirstOrDefault(x => x.MobId == mobData.BNpcId && x.WorldId == worldId);
var ev = new MobSpawnEvent(mobData.BNpcId, worldId, spawn.ZoneId, data.ZoneInstance, spawn.ZonePoiId, mobData.Rank, previous?.SpawnedAt ?? DateTime.UtcNow, previous?.Reporter);
var ev = new MobSpawnEvent(mobData.BNpcId, worldId, spawn.ZoneId, data.ZoneInstance, mobData.Rank, previous?.SpawnedAt ?? DateTime.UtcNow, previous?.Reporter, location);
OnMobSpawn(ev, config.Channel);
break;
}
Expand All @@ -126,7 +143,7 @@ private void OnMobReport(MobReportData data)
DalamudLog.Log.Debug("OnMobReport: previous == null");
break;
}
var ev = new MobSpawnEvent(mobData.BNpcId, worldId, previous.TerritoryTypeId, data.ZoneInstance, previous.ZoneLocationId, mobData.Rank, spawn.Timestamp, previous.Reporter);
var ev = new MobSpawnEvent(mobData.BNpcId, worldId, previous.TerritoryTypeId, data.ZoneInstance, mobData.Rank, spawn.Timestamp, previous.Reporter, previous.Location);
OnMobSpawn(ev, config.Channel);
break;
}
Expand All @@ -152,6 +169,7 @@ private bool CheckSpawnNotificationCondition(PluginConfig.PerRankConfig config,
var currentDataCenter = currentWorld?.DataCenter?.Value;
if (currentWorld == default || currentDataCenter == default)
{
// TODO
DalamudLog.Log.Debug("OnMobReport: currentWorld == null || currentDataCenter == null");
return false;
}
Expand Down Expand Up @@ -197,13 +215,10 @@ private void OnMobSpawn(MobSpawnEvent ev, int channel)
payloads.Add(new TextPayload($" {ev.Mob.Singular.RawString} "));

// append MapLink only if pop location is known
if (ev.ZoneLocationId.HasValue)
if (ev.Coordinates.HasValue)
{
var mapLink = CreateMapLink(ev.TerritoryTypeId, ev.ZoneLocationId.Value, ev.ZoneInstance);
if (mapLink != default)
{
payloads.AddRange(mapLink.Payloads);
}
var mapLink = Utils.CreateMapLink(ev.TerritoryType, ev.Map, ev.Coordinates.Value, ev.ZoneInstance);
payloads.AddRange(mapLink.Payloads);
}

payloads.Add(new IconPayload(BitmapFontIcon.CrossWorld));
Expand Down Expand Up @@ -266,36 +281,6 @@ private void OnMobDeath(MobDeathEvent ev, int channel, bool skipOrphanReport)
});
}

private SeString? CreateMapLink(uint zoneId, int zonePoiId, int? instance)
{
var zone = Dalamud.DataManager.GetExcelSheet<TerritoryType>()?.GetRow(zoneId);
var map = zone?.Map.Value;
if (zone == default || map == default)
{
DalamudLog.Log.Debug("CreateMapLink: zone == null || map == null");
return default;
}

if (!FaloopEmbedData.Locations.TryGetValue(zonePoiId, out var location))
{
DalamudLog.Log.Debug("CreateMapLink: location == null");
return default;
}

var n = 41 / (map.SizeFactor / 100.0);
var loc = location.Split([','], 2)
.Select(int.Parse)
.Select(x => x / 2048.0 * n + 1)
.Select(x => Math.Round(x, 1))
.Select(x => (float)x)
.ToList();

var mapLink = SeString.CreateMapLink(zone.RowId, zone.Map.Row, loc[0], loc[1]);

var instanceIcon = Utils.GetInstanceIcon(instance);
return instanceIcon != default ? mapLink.Append(instanceIcon) : mapLink;
}

private static void OnAny(string name, SocketIOResponse response)
{
DalamudLog.Log.Debug("Event {Name} = {Message}", name, response);
Expand Down
5 changes: 5 additions & 0 deletions FaloopIntegration/FaloopIntegration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference
Include="..\AetheryteLinkInChat.IpcModel\AetheryteLinkInChat.IpcModel.csproj" />
</ItemGroup>
</Project>
47 changes: 47 additions & 0 deletions FaloopIntegration/Ipc/AetheryteLinkInChatIpc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Linq;
using System.Numerics;
using Dalamud.Divination.Common.Api.Chat;
using Dalamud.Divination.Common.Api.Dalamud;
using Dalamud.Plugin;
using Dalamud.Plugin.Ipc;
using Divination.AetheryteLinkInChat.IpcModel;

namespace Divination.FaloopIntegration.Ipc;

public class AetheryteLinkInChatIpc(DalamudPluginInterface pluginInterface, IChatClient chatClient)
{
private readonly ICallGateSubscriber<TeleportPayload, bool> subscriber = pluginInterface.GetIpcSubscriber<TeleportPayload, bool>(TeleportPayload.Name);

public bool Teleport(uint territoryTypeId, uint mapId, Vector2 coordinates, uint worldId)
{
if (!IsPluginInstalled())
{
chatClient.PrintError(Localization.AetheryteLinkInChatPluginNotInstalled);
return false;
}

var payload = new TeleportPayload()
{
TerritoryTypeId = territoryTypeId,
MapId = mapId,
Coordinates = coordinates,
WorldId = worldId,
};

try
{
return subscriber.InvokeFunc(payload);
}
catch (Exception e)
{
DalamudLog.Log.Error(e, "failed to invoke Teleport");
return false;
}
}

private bool IsPluginInstalled()
{
return pluginInterface.InstalledPlugins.Any(x => x.Name == "Divination.AetheryteLinkInChat" && x.IsLoaded);
}
}
36 changes: 33 additions & 3 deletions FaloopIntegration/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,49 @@ public static class Localization

public static readonly LocalizedString ActiveMob = new()
{
En = "Active Mobs",
Ja = "現在のモブ",
En = "Faloop: Active Mobs",
Ja = "Faloop: 現在のモブ情報",
};

public static readonly LocalizedString EnableActiveMobUi = new()
{
En = "Enable Active Mobs UI",
Ja = "現在のモブ」パネルを表示",
Ja = "現在のモブ情報」パネルを表示",
};

public static readonly LocalizedString EnableSimpleReports = new()
{
En = "Enable simplified, condensed reports in chat",
Ja = "簡素な通知メッセージを使用する",
};

public static readonly LocalizedString TableHeaderMob = new()
{
En = "Mob",
Ja = "モブ",
};

public static readonly LocalizedString TableHeaderTime = new()
{
En = "Time",
Ja = "経過時間",
};

public static readonly LocalizedString TableButtonTeleport = new()
{
En = "Teleport",
Ja = "テレポ",
};

public static readonly LocalizedString TeleportingMessage = new()
{
En = "Teleporting to \"{0}\"...",
Ja = "「{0}」にテレポしています...",
};

public static readonly LocalizedString AetheryteLinkInChatPluginNotInstalled = new()
{
En = "Divination.AetheryteLinkInChat plugin is not installed.",
Ja = "Divination.AetheryteLinkInChat プラグインがインストールされていません。",
};
}
Loading

0 comments on commit b4b84d6

Please sign in to comment.