Selaa lähdekoodia

feat: Implement new map marker system

Closes #5
Dragon 4 vuotta sitten
vanhempi
sitoutus
08ca3eeb64
3 muutettua tiedostoa jossa 150 lisäystä ja 12 poistoa
  1. 8 2
      HuntBuddy/HuntBuddy.csproj
  2. 91 6
      HuntBuddy/Interface.cs
  3. 51 4
      HuntBuddy/Location.cs

+ 8 - 2
HuntBuddy/HuntBuddy.csproj

@@ -3,8 +3,8 @@
     <PropertyGroup>
         <TargetFramework>net5.0-windows</TargetFramework>
         <Nullable>enable</Nullable>
-        <AssemblyVersion>0.9.0.0</AssemblyVersion>
-        <FileVersion>0.9.0.0</FileVersion>
+        <AssemblyVersion>0.9.1.0</AssemblyVersion>
+        <FileVersion>0.9.1.0</FileVersion>
         <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
         <RootNamespace>HuntBuddy</RootNamespace>
         <IsPackable>false</IsPackable>
@@ -13,6 +13,12 @@
     <PropertyGroup>
         <ProduceReferenceAssembly>false</ProduceReferenceAssembly>
     </PropertyGroup>
+    <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+        <PlatformTarget>x64</PlatformTarget>
+    </PropertyGroup>
+    <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
+        <PlatformTarget>x64</PlatformTarget>
+    </PropertyGroup>
     <ItemGroup>
         <Reference Include="Dalamud">
             <HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\Dalamud.dll</HintPath>

+ 91 - 6
HuntBuddy/Interface.cs

@@ -91,12 +91,51 @@ namespace HuntBuddy
 					{
 						if (Location.Database.ContainsKey(mobHuntEntry.MobHuntId))
 						{
-							if (Interface.IconButton(FontAwesomeIcon.MapMarked, $"##{mobHuntEntry.MobHuntId}"))
+							if (Interface.IconButton(FontAwesomeIcon.MapMarkerAlt, $"pin##{mobHuntEntry.MobHuntId}"))
 							{
-								Location.OpenMapLink(
+								Location.CreateMapMarker(
 									mobHuntEntry.TerritoryType,
 									mobHuntEntry.MapId,
-									mobHuntEntry.MobHuntId);
+									mobHuntEntry.MobHuntId,
+									mobHuntEntry.Name,
+									Location.OpenType.None);
+							}
+
+							if (ImGui.IsItemHovered())
+							{
+								ImGui.BeginTooltip();
+								ImGui.Text("Place marker on the map");
+								ImGui.EndTooltip();
+							}
+
+							ImGui.SameLine();
+
+							if (Interface.IconButton(FontAwesomeIcon.Compass, $"openRadius##{mobHuntEntry.MobHuntId}"))
+							{
+								Location.CreateMapMarker(
+									mobHuntEntry.TerritoryType,
+									mobHuntEntry.MapId,
+									mobHuntEntry.MobHuntId,
+									mobHuntEntry.Name,
+									Location.OpenType.ShowOpen);
+							}
+
+							if (ImGui.IsItemHovered())
+							{
+								ImGui.BeginTooltip();
+								ImGui.Text("Show hunt location on the map");
+								ImGui.EndTooltip();
+							}
+
+							ImGui.SameLine();
+
+							if (Interface.IconButton(FontAwesomeIcon.MapMarkedAlt, $"open##{mobHuntEntry.MobHuntId}"))
+							{
+								Location.CreateMapMarker(
+									mobHuntEntry.TerritoryType,
+									mobHuntEntry.MapId,
+									mobHuntEntry.MobHuntId,
+									mobHuntEntry.Name);
 							}
 
 							if (ImGui.IsItemHovered())
@@ -207,12 +246,58 @@ namespace HuntBuddy
 
 				if (Location.Database.ContainsKey(mobHuntEntry.MobHuntId))
 				{
-					if (Interface.IconButton(FontAwesomeIcon.MapMarked, $"##{mobHuntEntry.MobHuntId}"))
+					if (Interface.IconButton(FontAwesomeIcon.MapMarkerAlt, $"pin##{mobHuntEntry.MobHuntId}"))
 					{
-						Location.OpenMapLink(
+						Location.CreateMapMarker(
 							mobHuntEntry.TerritoryType,
 							mobHuntEntry.MapId,
-							mobHuntEntry.MobHuntId);
+							mobHuntEntry.MobHuntId,
+							mobHuntEntry.Name,
+							Location.OpenType.None);
+					}
+
+					if (ImGui.IsItemHovered())
+					{
+						ImGui.BeginTooltip();
+						ImGui.Text("Place marker on the map");
+						ImGui.EndTooltip();
+					}
+
+					ImGui.SameLine();
+
+					if (Interface.IconButton(FontAwesomeIcon.Compass, $"openRadius##{mobHuntEntry.MobHuntId}"))
+					{
+						Location.CreateMapMarker(
+							mobHuntEntry.TerritoryType,
+							mobHuntEntry.MapId,
+							mobHuntEntry.MobHuntId,
+							mobHuntEntry.Name,
+							Location.OpenType.ShowOpen);
+					}
+
+					if (ImGui.IsItemHovered())
+					{
+						ImGui.BeginTooltip();
+						ImGui.Text("Show hunt location on the map");
+						ImGui.EndTooltip();
+					}
+
+					ImGui.SameLine();
+
+					if (Interface.IconButton(FontAwesomeIcon.MapMarkedAlt, $"open##{mobHuntEntry.MobHuntId}"))
+					{
+						Location.CreateMapMarker(
+							mobHuntEntry.TerritoryType,
+							mobHuntEntry.MapId,
+							mobHuntEntry.MobHuntId,
+							mobHuntEntry.Name);
+					}
+
+					if (ImGui.IsItemHovered())
+					{
+						ImGui.BeginTooltip();
+						ImGui.Text("Show hunt location on the map");
+						ImGui.EndTooltip();
 					}
 
 					ImGui.SameLine();

+ 51 - 4
HuntBuddy/Location.cs

@@ -1,8 +1,11 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using System.Linq;
 using System.Numerics;
 using Dalamud.Game.Text.SeStringHandling.Payloads;
+using FFXIVClientStructs.FFXIV.Client.UI;
 using Lumina.Excel.GeneratedSheets;
+using MapType = FFXIVClientStructs.FFXIV.Client.UI.Agent.MapType;
 
 namespace HuntBuddy
 {
@@ -451,10 +454,54 @@ namespace HuntBuddy
 			{ 10435, new PositionInfo { X = 16.3f, Y = 14.1f } }, // Other One
 		};
 
-		public static void OpenMapLink(uint territoryType, uint mapId, uint mobHuntId)
+		public enum OpenType
 		{
-			var mapLinkPayload = new MapLinkPayload(territoryType, mapId, Database[mobHuntId].X, Database[mobHuntId].Y);
-			Plugin.GameGui.OpenMapWithMapLink(mapLinkPayload);
+			None, // Just place marker
+			ShowOpen, // Show special map with radius
+			MarkerOpen // Show normal map
+		}
+
+		public static unsafe void CreateMapMarker(uint territoryType, uint mapId, uint mobHuntId, string? mobHuntName, OpenType openType = OpenType.MarkerOpen)
+		{
+			var map = FFXIVClientStructs.FFXIV.Client.UI.Agent.AgentMap.Instance();
+			
+			if (map == null)
+			{
+				return;
+			}
+			
+			var pos = MapToWorldCoordinates(Database[mobHuntId].Coordinate, mapId);
+
+			map->IsFlagMarkerSet = 0;
+			map->SetFlagMapMarker(territoryType, mapId, pos.X, pos.Y, 60004);
+
+			switch (openType)
+			{
+				case OpenType.None:
+					break;
+				case OpenType.ShowOpen:
+					map->AgentInterface.Hide();
+					map->AddGatheringTempMarker(pos.X, pos.Y, 150, 60004, 4, mobHuntName);
+					map->OpenMap(mapId, territoryType, mobHuntName, MapType.GatheringLog);
+					break;
+				case OpenType.MarkerOpen:
+					map->AgentInterface.Hide();
+					map->OpenMap(mapId, territoryType);
+					break;
+				default:
+					throw new ArgumentOutOfRangeException(nameof(openType), openType, null);
+			}
+		}
+		
+		private static (int X, int Y) MapToWorldCoordinates(Vector2 pos, uint mapId)
+		{
+			var scale = Plugin.DataManager.GetExcelSheet<Map>()?.GetRow(mapId)?.SizeFactor ?? 100;
+			var num = scale / 100f;
+			var x = (float)(((pos.X - 1.0) * num / 41.0 * 2048.0) - 1024.0) / num * 1000f;
+			var y = (float)(((pos.Y - 1.0) * num / 41.0 * 2048.0) - 1024.0) / num * 1000f;
+			x = (int)(MathF.Round(x, 3, MidpointRounding.AwayFromZero) * 1000) * 0.001f / 1000f;
+			y = (int)(MathF.Round(y, 3, MidpointRounding.AwayFromZero) * 1000) * 0.001f / 1000f;
+			return ((int)x, (int)y);
 		}
 
 		private static Vector2 ConvertPixelPositionToMapCoordinate(int x, int y, float scale)