From 700f0a86b991fc3cfea18318b3ab1307bda57e86 Mon Sep 17 00:00:00 2001 From: occluder <69414142+occluder@users.noreply.github.com> Date: Tue, 17 Feb 2026 14:08:52 +0300 Subject: [PATCH 1/6] Add running total of platinum and ducats to 'Auto Add' window --- WFInfo/AutoAddViewModel.cs | 76 +++++++++++++++++++++++++++++++++++--- WFInfo/AutoCount.xaml | 18 +++++++-- 2 files changed, 84 insertions(+), 10 deletions(-) diff --git a/WFInfo/AutoAddViewModel.cs b/WFInfo/AutoAddViewModel.cs index 6fc2a29f..253c6106 100644 --- a/WFInfo/AutoAddViewModel.cs +++ b/WFInfo/AutoAddViewModel.cs @@ -2,14 +2,18 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Globalization; namespace WFInfo { public class AutoAddViewModel : INPC { private ObservableCollection _itemList; + private double _totalPlatinum; + private int _totalDucats; + private const NumberStyles styles = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowExponent; - public ObservableCollection ItemList + public ObservableCollection ItemList { get => _itemList; private set @@ -18,6 +22,26 @@ private set RaisePropertyChanged(); } } + + public double TotalPlatinum + { + get => _totalPlatinum; + private set + { + _totalPlatinum = value; + RaisePropertyChanged(); + } + } + public int TotalDucats + { + get => _totalDucats; + private set + { + _totalDucats = value; + RaisePropertyChanged(); + } + } + public AutoAddViewModel() { _itemList = new ObservableCollection(); @@ -26,13 +50,46 @@ public AutoAddViewModel() public void addItem(AutoAddSingleItem item) { _itemList.Add(item); - RaisePropertyChanged(); + UpdateTotalsForOptionChange(null, item.ActiveOption); } public void removeItem(AutoAddSingleItem item) { + UpdateTotalsForOptionChange(item.ActiveOption, null); _itemList.Remove(item); - RaisePropertyChanged(); + } + + public void UpdateTotalsForOptionChange(string previousOption, string newOption) + { + if (!string.IsNullOrEmpty(previousOption)) + { + JObject previousJob = (JObject)Main.dataBase.marketData.GetValue(previousOption); + string previousPlat = previousJob["plat"].ToObject(); + string previousDucats = previousJob["ducats"].ToObject(); + if (double.TryParse(previousPlat, styles, CultureInfo.InvariantCulture, out double previousPlatValue)) + { + TotalPlatinum -= previousPlatValue; + } + if (int.TryParse(previousDucats, styles, CultureInfo.InvariantCulture, out int previousDucatValue)) + { + TotalDucats -= previousDucatValue; + } + } + + if (!string.IsNullOrEmpty(newOption)) + { + JObject newJob = (JObject)Main.dataBase.marketData.GetValue(newOption); + string newPlat = newJob["plat"].ToObject(); + string newDucats = newJob["ducats"].ToObject(); + if (double.TryParse(newPlat, styles, CultureInfo.InvariantCulture, out double newPlatValue)) + { + TotalPlatinum += newPlatValue; + } + if (int.TryParse(newDucats, styles, CultureInfo.InvariantCulture, out int newDucatValue)) + { + TotalDucats += newDucatValue; + } + } } } @@ -58,8 +115,14 @@ public string ActiveOption get => _activeOption; set { - _activeOption = value; - RaisePropertyChanged(); + // FIXME: breakpoint here doesn't always get hit (active option doesn't get changed). why? + if (_activeOption != value) + { + string previousOption = _activeOption; + _activeOption = value; + RaisePropertyChanged(); + _parent?.UpdateTotalsForOptionChange(previousOption, _activeOption); + } } } @@ -75,7 +138,8 @@ public AutoAddSingleItem(List options, int activeIndex, AutoAddViewModel if (activeIndex >= 0 && options != null) { ActiveOption = options[activeIndex]; - } else + } + else { ActiveOption = ""; } diff --git a/WFInfo/AutoCount.xaml b/WFInfo/AutoCount.xaml index 9bc512ce..1ccb3ec6 100644 --- a/WFInfo/AutoCount.xaml +++ b/WFInfo/AutoCount.xaml @@ -195,16 +195,26 @@ - - + + + -