started adding navigation

This commit is contained in:
Boki 2026-02-13 10:43:35 -05:00
parent 32781b1462
commit 468e0a7246
20 changed files with 844 additions and 31 deletions

View file

@ -5,6 +5,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Poe2Trade.Bot;
using Poe2Trade.Core;
using Poe2Trade.Navigation;
using Serilog;
namespace Poe2Trade.Ui.ViewModels;
@ -42,6 +43,9 @@ public partial class MainWindowViewModel : ObservableObject
private bool _isStarted;
[ObservableProperty] private Bitmap? _inventoryImage;
[ObservableProperty] private Bitmap? _minimapImage;
[ObservableProperty] private string _navigationStateText = "";
private long _lastMinimapUpdate;
[ObservableProperty] private string _newUrl = "";
[ObservableProperty] private string _newLinkName = "";
@ -49,13 +53,16 @@ public partial class MainWindowViewModel : ObservableObject
[ObservableProperty] private int _tradesCompleted;
[ObservableProperty] private int _tradesFailed;
[ObservableProperty] private int _activeLinksCount;
[ObservableProperty] private BotMode _botMode;
public static LinkMode[] LinkModes { get; } = [LinkMode.Live, LinkMode.Scrap];
public static BotMode[] BotModes { get; } = [BotMode.Trading, BotMode.Mapping];
public MainWindowViewModel(BotOrchestrator bot)
{
_bot = bot;
_isPaused = bot.IsPaused;
_botMode = bot.Mode;
for (var i = 0; i < 60; i++)
InventoryCells.Add(new CellState());
@ -66,12 +73,14 @@ public partial class MainWindowViewModel : ObservableObject
{
State = bot.State;
IsPaused = bot.IsPaused;
BotMode = bot.Mode;
var status = bot.GetStatus();
TradesCompleted = status.TradesCompleted;
TradesFailed = status.TradesFailed;
ActiveLinksCount = status.Links.Count(l => l.Active);
OnPropertyChanged(nameof(Links));
UpdateInventoryGrid();
UpdateMinimapImage();
});
};
@ -99,6 +108,12 @@ public partial class MainWindowViewModel : ObservableObject
// Sub-ViewModels for tabs
public DebugViewModel? DebugVm { get; set; }
public SettingsViewModel? SettingsVm { get; set; }
public MappingViewModel? MappingVm { get; set; }
partial void OnBotModeChanged(BotMode value)
{
_bot.Mode = value;
}
[RelayCommand(CanExecute = nameof(CanStart))]
private async Task Start()
@ -198,4 +213,39 @@ public partial class MainWindowViewModel : ObservableObject
OnPropertyChanged(nameof(InventoryFreeCells));
}
private void UpdateMinimapImage()
{
var nav = _bot.Navigation;
var navState = nav.State;
NavigationStateText = navState == NavigationState.Idle ? "" : navState.ToString();
if (navState == NavigationState.Idle)
{
if (MinimapImage != null)
{
var old = MinimapImage;
MinimapImage = null;
old.Dispose();
}
return;
}
// Throttle: update at most once per second
var now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
if (now - _lastMinimapUpdate < 1000) return;
_lastMinimapUpdate = now;
try
{
var bytes = nav.GetViewportSnapshot();
var old = MinimapImage;
MinimapImage = new Bitmap(new MemoryStream(bytes));
old?.Dispose();
}
catch (Exception ex)
{
Log.Debug(ex, "Failed to update minimap image");
}
}
}

View file

@ -0,0 +1,25 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Poe2Trade.Bot;
using Poe2Trade.Core;
namespace Poe2Trade.Ui.ViewModels;
public partial class MappingViewModel : ObservableObject
{
private readonly BotOrchestrator _bot;
[ObservableProperty] private MapType _selectedMapType;
public static MapType[] MapTypes { get; } = [MapType.TrialOfChaos, MapType.Temple, MapType.Endgame];
public MappingViewModel(BotOrchestrator bot)
{
_bot = bot;
_selectedMapType = bot.Config.MapType;
}
partial void OnSelectedMapTypeChanged(MapType value)
{
_bot.Store.UpdateSettings(s => s.MapType = value);
}
}