added nav 3.0.0.6

This commit is contained in:
erik 2025-05-29 17:58:56 +02:00
parent 1ddfc9fbdf
commit c05d6c9d1b
6 changed files with 1825 additions and 262 deletions

View file

@ -0,0 +1,261 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using Decal.Adapter;
using Microsoft.Win32;
namespace MosswartMassacre
{
public class NavVisualization : IDisposable
{
private bool disposed = false;
private NavRoute currentRoute = null;
private string vtankProfilesDirectory = "";
private List<string> availableNavFiles = new List<string>();
// Default comparison route color (red)
private readonly Color comparisonRouteColor = Color.FromArgb(255, 255, 100, 100);
public bool IsEnabled { get; private set; } = false;
public bool HasRouteLoaded => currentRoute != null && currentRoute.WaypointCount > 0;
public string CurrentRouteFile => currentRoute?.FileName ?? "None";
public List<string> AvailableNavFiles => availableNavFiles.ToList();
public event EventHandler RouteChanged;
public NavVisualization()
{
InitializeVTankDirectory();
RefreshNavFileList();
}
private void InitializeVTankDirectory()
{
try
{
// First, check if user has configured a custom path
if (!string.IsNullOrEmpty(PluginSettings.Instance?.VTankProfilesPath))
{
vtankProfilesDirectory = PluginSettings.Instance.VTankProfilesPath;
PluginCore.WriteToChat($"[NavViz] Using configured VTank profiles path: {vtankProfilesDirectory}");
return;
}
// Try to get VTank directory from Windows Registry (same method as UtilityBelt)
var defaultPath = @"C:\Games\VirindiPlugins\VirindiTank\";
try
{
var regKey = Registry.LocalMachine.OpenSubKey("Software\\Decal\\Plugins\\{642F1F48-16BE-48BF-B1D4-286652C4533E}");
if (regKey != null)
{
var profilePath = regKey.GetValue("ProfilePath")?.ToString();
if (!string.IsNullOrEmpty(profilePath))
{
vtankProfilesDirectory = profilePath;
PluginCore.WriteToChat($"[NavViz] Found VTank profiles from registry: {vtankProfilesDirectory}");
return;
}
}
}
catch (Exception regEx)
{
PluginCore.WriteToChat($"[NavViz] Registry lookup failed: {regEx.Message}");
}
// Fall back to default path
vtankProfilesDirectory = defaultPath;
PluginCore.WriteToChat($"[NavViz] Using default VTank path: {vtankProfilesDirectory}");
PluginCore.WriteToChat($"[NavViz] If this is wrong, configure the correct path in Settings tab.");
}
catch (Exception ex)
{
PluginCore.WriteToChat($"[NavViz] Error finding VTank directory: {ex.Message}");
vtankProfilesDirectory = "";
}
}
public void RefreshNavFileList()
{
// Re-initialize directory in case settings changed
InitializeVTankDirectory();
availableNavFiles.Clear();
PluginCore.WriteToChat($"[NavViz] Refreshing nav files from: {vtankProfilesDirectory}");
if (string.IsNullOrEmpty(vtankProfilesDirectory))
{
PluginCore.WriteToChat("[NavViz] No VTank directory set");
return;
}
if (!Directory.Exists(vtankProfilesDirectory))
{
PluginCore.WriteToChat($"[NavViz] Directory does not exist: {vtankProfilesDirectory}");
return;
}
try
{
// Get ALL files first for debugging
var allFiles = Directory.GetFiles(vtankProfilesDirectory);
PluginCore.WriteToChat($"[NavViz] Directory contents ({allFiles.Length} files):");
foreach (var file in allFiles.Take(10)) // Show first 10 files
{
PluginCore.WriteToChat($" - {Path.GetFileName(file)}");
}
// Filter for .nav files ONLY and exclude follow files
var navFiles = allFiles
.Where(file => {
var ext = Path.GetExtension(file);
var isNav = ext.Equals(".nav", StringComparison.OrdinalIgnoreCase);
PluginCore.WriteToChat($"[NavViz] File: {Path.GetFileName(file)} - Extension: '{ext}' - IsNav: {isNav}");
return isNav;
})
.Select(file => {
var name = Path.GetFileNameWithoutExtension(file);
PluginCore.WriteToChat($"[NavViz] Nav file name: {name}");
return name;
})
.Where(name => !string.IsNullOrEmpty(name) &&
!name.StartsWith("follow", StringComparison.OrdinalIgnoreCase) &&
!name.StartsWith("--", StringComparison.OrdinalIgnoreCase))
.OrderBy(name => name)
.ToList();
availableNavFiles.AddRange(navFiles);
PluginCore.WriteToChat($"[NavViz] Found {navFiles.Count} .nav files: {string.Join(", ", navFiles)}");
}
catch (Exception ex)
{
PluginCore.WriteToChat($"[NavViz] Error refreshing nav files: {ex.Message}");
}
}
public bool LoadRoute(string navFileName)
{
try
{
// Clear current route
if (currentRoute != null)
{
currentRoute.Dispose();
currentRoute = null;
}
if (string.IsNullOrEmpty(navFileName) || navFileName == "None")
{
PluginCore.WriteToChat("[NavViz] Route cleared");
RouteChanged?.Invoke(this, EventArgs.Empty);
return true;
}
string fullPath = Path.Combine(vtankProfilesDirectory, navFileName + ".nav");
if (!File.Exists(fullPath))
{
PluginCore.WriteToChat($"[NavViz] Nav file not found: {navFileName}");
return false;
}
currentRoute = new NavRoute(fullPath, comparisonRouteColor);
if (!currentRoute.LoadFromFile())
{
currentRoute.Dispose();
currentRoute = null;
return false;
}
// Show route if visualization is enabled
PluginCore.WriteToChat($"[NavViz] LoadRoute: IsEnabled = {IsEnabled}");
if (IsEnabled)
{
PluginCore.WriteToChat($"[NavViz] Calling Show() for route {navFileName}");
currentRoute.Show();
}
else
{
PluginCore.WriteToChat($"[NavViz] Visualization disabled, not showing route");
}
RouteChanged?.Invoke(this, EventArgs.Empty);
return true;
}
catch (Exception ex)
{
PluginCore.WriteToChat($"[NavViz] Error loading route {navFileName}: {ex.Message}");
return false;
}
}
public void SetEnabled(bool enabled)
{
PluginCore.WriteToChat($"[NavViz] SetEnabled called: current={IsEnabled}, new={enabled}");
if (IsEnabled == enabled)
{
PluginCore.WriteToChat($"[NavViz] SetEnabled: no change needed");
return;
}
IsEnabled = enabled;
if (currentRoute != null)
{
PluginCore.WriteToChat($"[NavViz] SetEnabled: currentRoute exists, {(enabled ? "showing" : "hiding")}");
if (enabled)
{
currentRoute.Show();
}
else
{
currentRoute.Hide();
}
}
else
{
PluginCore.WriteToChat($"[NavViz] SetEnabled: no currentRoute to {(enabled ? "show" : "hide")}");
}
PluginCore.WriteToChat($"[NavViz] Navigation visualization {(enabled ? "enabled" : "disabled")}");
}
public void ToggleEnabled()
{
SetEnabled(!IsEnabled);
}
public string GetStatus()
{
if (currentRoute == null)
return "No route loaded";
string status = $"{currentRoute.FileName} ({currentRoute.WaypointCount} points)";
if (IsEnabled && currentRoute.IsVisible)
status += " - Visible";
else if (IsEnabled)
status += " - Hidden";
else
status += " - Disabled";
return status;
}
public void Dispose()
{
if (!disposed)
{
if (currentRoute != null)
{
currentRoute.Dispose();
currentRoute = null;
}
disposed = true;
}
}
}
}