-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from Stuff-Mods/pouch
Widget improvements and track pouch items
- Loading branch information
Showing
15 changed files
with
216 additions
and
57 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
ItemBoxTracker/src/Plugin/Converter/GenericValueConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Windows.Data; | ||
using System.Windows.Markup; | ||
using HunterPie.Plugins; | ||
using static MHWItemBoxTracker.Main; | ||
|
||
namespace MHWItemBoxTracker.Converter { | ||
public abstract class GenericValueConverter<TFrom, TTo> : MarkupExtension, IValueConverter { | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { | ||
if (value == null) return null; | ||
|
||
// Plugin.Log($"typeof({typeof(TTo)}) != {targetType}"); | ||
// Plugin.Log($"!({value.GetType()}).IsAssignableFrom({typeof(TFrom)})"); | ||
// if (typeof(TTo) != targetType) return null; | ||
if (!value.GetType().IsAssignableFrom(typeof(TFrom))) return null; | ||
return Convert((TFrom)value, parameter); | ||
} | ||
|
||
public abstract TTo Convert(TFrom value, object parameter); | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { | ||
throw new NotImplementedException(); | ||
} | ||
|
||
|
||
#region MarkupExtension members | ||
|
||
public override object ProvideValue(IServiceProvider serviceProvider) { | ||
return this; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using MHWItemBoxTracker.Model; | ||
|
||
namespace MHWItemBoxTracker.Converter { | ||
public class InventoryToAmounts : GenericValueConverter<InventoryItemModel, AmountsModel> { | ||
public override AmountsModel Convert(InventoryItemModel value, object parameter) { | ||
return new() { | ||
InPouch = value.AmountInPouch, | ||
InBox = value.AmountInBox, | ||
Craftable = value.AmountCraftable, | ||
Wanted = value.Item.Amount, | ||
}; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
ItemBoxTracker/src/Plugin/Converter/InventoryToAmountsText.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using MHWItemBoxTracker.Model; | ||
|
||
namespace MHWItemBoxTracker.Converter { | ||
public class InventoryToAmountsText : GenericValueConverter<InventoryItemModel, string> { | ||
public override string Convert(InventoryItemModel value, object parameter) { | ||
var pouch = value.TrackPouch ? $"{value.AmountInPouch}" : ""; | ||
var box = value.TrackBox ? $"{value.AmountInBox}" : ""; | ||
var craftable = value.TrackCraftable ? $" (+{value.AmountCraftable})" : ""; | ||
var divider = (value.TrackPouch && value.TrackBox) ? " | " : ""; | ||
var wanted = (value.TrackPouch || value.TrackBox || value.TrackCraftable) ? $" / {value.Item.Amount}" : ""; | ||
|
||
return $"{pouch}{divider}{box}{craftable}{wanted}"; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Linq; | ||
|
||
namespace MHWItemBoxTracker.Converter { | ||
public class SumOverLast : GenericMultiValueConverter<double> { | ||
public override double Convert(object[] values) { | ||
var size = values.Length; | ||
var sum = values.Take(size - 1).Sum(x => (int)x); | ||
var last = (int)values[size - 1]; | ||
|
||
return last != 0 ? sum * 1f / last : 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
ItemBoxTracker/src/Plugin/GUI/ProgressBarDataTemplate.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<ResourceDictionary | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:data="clr-namespace:MHWItemBoxTracker.Model" | ||
xmlns:convert="clr-namespace:MHWItemBoxTracker.Converter"> | ||
<DataTemplate DataType="{x:Type data:AmountsModel}"> | ||
<Grid> | ||
<ProgressBar | ||
Minimum="0" | ||
Maximum="1" | ||
Foreground="#A18029"> | ||
<ProgressBar.Value> | ||
<MultiBinding Converter="{convert:SumOverLast}"> | ||
<Binding Path="InBox" /> | ||
<Binding Path="InPouch" /> | ||
<Binding Path="Craftable" /> | ||
<Binding Path="Wanted" /> | ||
</MultiBinding> | ||
</ProgressBar.Value> | ||
</ProgressBar> | ||
<ProgressBar | ||
Minimum="0" | ||
Maximum="1" | ||
BorderBrush="Transparent" | ||
Foreground="#2981a1"> | ||
<ProgressBar.Value> | ||
<MultiBinding Converter="{convert:SumOverLast}"> | ||
<Binding Path="InBox" /> | ||
<Binding Path="InPouch" /> | ||
<Binding Path="Wanted" /> | ||
</MultiBinding> | ||
</ProgressBar.Value> | ||
</ProgressBar> | ||
<ProgressBar | ||
BorderBrush="Transparent" | ||
Minimum="0" | ||
Maximum="1"> | ||
<ProgressBar.Value> | ||
<MultiBinding Converter="{convert:SumOverLast}"> | ||
<Binding Path="InBox" /> | ||
<Binding Path="Wanted" /> | ||
</MultiBinding> | ||
</ProgressBar.Value> | ||
</ProgressBar> | ||
</Grid> | ||
</DataTemplate> | ||
</ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using MHWItemBoxTracker.Utils; | ||
|
||
namespace MHWItemBoxTracker.Model { | ||
public class AmountsModel : NotifyPropertyChanged { | ||
private int inBox = 0; | ||
private int inPouch = 0; | ||
private int craftable = 0; | ||
private int wanted = 0; | ||
|
||
public int InBox { | ||
get => inBox; | ||
set => SetField(ref inBox, value); | ||
} | ||
public int InPouch { | ||
get => inPouch; | ||
set => SetField(ref inPouch, value); | ||
} | ||
public int Craftable { | ||
get => craftable; | ||
set => SetField(ref craftable, value); | ||
} | ||
public int Wanted { | ||
get => wanted; | ||
set => SetField(ref wanted, value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters