Skip to content

Commit

Permalink
Merge pull request #60 from Stuff-Mods/pouch
Browse files Browse the repository at this point in the history
Widget improvements and track pouch items
  • Loading branch information
DevilPepper authored May 16, 2021
2 parents 746dede + 0852c92 commit 60bff47
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 57 deletions.
35 changes: 35 additions & 0 deletions ItemBoxTracker/src/Plugin/Converter/GenericValueConverter.cs
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
}
}
14 changes: 14 additions & 0 deletions ItemBoxTracker/src/Plugin/Converter/InventoryToAmounts.cs
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 ItemBoxTracker/src/Plugin/Converter/InventoryToAmountsText.cs
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}";
}
}
}
10 changes: 0 additions & 10 deletions ItemBoxTracker/src/Plugin/Converter/RatioToPercent.cs

This file was deleted.

13 changes: 13 additions & 0 deletions ItemBoxTracker/src/Plugin/Converter/SumOverLast.cs
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;
}
}
}
62 changes: 24 additions & 38 deletions ItemBoxTracker/src/Plugin/GUI/InventoryItemDataTemplate.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,29 @@
xmlns:data="clr-namespace:MHWItemBoxTracker.Model"
xmlns:convert="clr-namespace:MHWItemBoxTracker.Converter">
<DataTemplate DataType="{x:Type data:InventoryItemModel}">
<Grid Margin="0,2">
<!--<Image />-->

<ContentControl
Grid.Column="0"
Content="{Binding Item}" />
<TextBlock
Grid.Column="1"
FontSize="14"
HorizontalAlignment="Right"
Padding="0,0,10,0">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}/{1}">
<Binding Path="AmountInBox" />
<Binding Path="Item.Amount" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<ProgressBar
Grid.Column="2"
Minimum="0"
Maximum="100">
<ProgressBar.Value>
<MultiBinding Converter="{convert:RatioToPercent}">
<Binding Path="AmountInBox" />
<Binding Path="Item.Amount" />
</MultiBinding>
</ProgressBar.Value>
</ProgressBar>
<!--<Custom:MinimalHealthBar Style="{StaticResource OVERLAY_MONSTER_PART_BAR_STYLE}" RenderTransformOrigin="0.5,0.5" VerticalAlignment="Top" />-->

<Grid.ColumnDefinitions>
<!--<ColumnDefinition Width="50" />-->
<ColumnDefinition Width="*" />
<ColumnDefinition Width="75" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
</Grid>
<StackPanel>
<Grid Margin="0 5">
<Grid.Effect>
<DropShadowEffect
ShadowDepth="4"
Direction="315"
Color="Black" />
</Grid.Effect>
<ContentControl
Grid.Column="0"
Content="{Binding Item}" />
<TextBlock
Grid.Column="1"
Text="{Binding Path=., Converter={convert:InventoryToAmountsText}}"
Foreground="#ffbfbfbf"
HorizontalAlignment="Right"
Padding="0,0,10,0" />
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="75" />
</Grid.ColumnDefinitions>
</Grid>
<ContentControl Content="{Binding Path=., Converter={convert:InventoryToAmounts}}" />
</StackPanel>
</DataTemplate>
</ResourceDictionary>
2 changes: 1 addition & 1 deletion ItemBoxTracker/src/Plugin/GUI/ItemDataTemplate.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
Source="{Binding ItemId, Converter={StaticResource id2icon}}"
MaxHeight="30"
MaxWidth="30"
Padding="5 0" /> -->
Padding="5 0" /> -->
<TextBlock
Padding="5 0"
Text="{Binding Name}"
Expand Down
47 changes: 47 additions & 0 deletions ItemBoxTracker/src/Plugin/GUI/ProgressBarDataTemplate.xaml
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>
27 changes: 27 additions & 0 deletions ItemBoxTracker/src/Plugin/Model/AmountsModel.cs
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);
}
}
}
10 changes: 10 additions & 0 deletions ItemBoxTracker/src/Plugin/Model/InventoryItemModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class InventoryItemModel : NotifyPropertyChanged {
public bool trackInVillage = false;
public bool trackInQuest = false;
public bool trackCraftable = false;
public bool trackBox = false;
public bool trackPouch = false;

public ItemModel Item {
get => item;
Expand Down Expand Up @@ -39,6 +41,14 @@ public bool TrackCraftable {
get => trackCraftable;
set => SetField(ref trackCraftable, value);
}
public bool TrackBox {
get => trackBox;
set => SetField(ref trackBox, value);
}
public bool TrackPouch {
get => trackPouch;
set => SetField(ref trackPouch, value);
}

public override bool Equals(object obj) {
if ((obj != null) && GetType().Equals(obj.GetType())) {
Expand Down
4 changes: 2 additions & 2 deletions ItemBoxTracker/src/Plugin/Model/ItemModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
namespace MHWItemBoxTracker.Model {
public class ItemModel : NotifyPropertyChanged {
private string name;
public int itemId;
public int amount;
private int itemId;
private int amount;

public string Name {
get => name;
Expand Down
16 changes: 14 additions & 2 deletions ItemBoxTracker/src/Plugin/Service/InventoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,22 @@ public void Refresh() {
TrackInVillage = true,
TrackInQuest = true,
TrackCraftable = Settings.Always.TrackCraftable,
TrackBox = Settings.Always.TrackBox,
TrackPouch = Settings.Always.TrackPouch,
});
var village = Settings.Village.Tracking.Select(i => new InventoryItemModel() {
Item = i,
TrackInVillage = true,
TrackCraftable = Settings.Village.TrackCraftable,
TrackBox = Settings.Village.TrackBox,
TrackPouch = Settings.Village.TrackPouch,
});
var quest = Settings.Quest.Tracking.Select(i => new InventoryItemModel() {
Item = i,
TrackInQuest = true,
TrackCraftable = Settings.Quest.TrackCraftable,
TrackBox = Settings.Quest.TrackBox,
TrackPouch = Settings.Quest.TrackPouch,
});

var itemsInSettings = always.Union(village).Union(quest);
Expand All @@ -63,9 +69,15 @@ public void Refresh() {
}
var ids = Data.Items.Select(i => i.Item.ItemId).ToHashSet();
var box = Context.Player.ItemBox?.FindItemsInBox(ids) ?? new();
var pouch = Context.Player.Inventory?.FindItemsAndAmmos(ids).ToDictionary(i => i.ItemId, i => i.Amount);
foreach (var item in Data.Items) {
box.TryGetValue(item.Item.ItemId, out int amountInBox);
item.AmountInBox = amountInBox;
box.TryGetValue(item.Item.ItemId, out int AmountInBox);
pouch.TryGetValue(item.Item.ItemId, out int AmountInPouch);
// TODO: Get this
int AmountCraftable = 0;
item.AmountInBox = item.TrackBox ? AmountInBox : 0;
item.AmountInPouch = item.TrackPouch ? AmountInPouch : 0;
item.AmountCraftable = item.TrackCraftable ? AmountCraftable : 0;
}
}

Expand Down
10 changes: 9 additions & 1 deletion ItemBoxTracker/src/Plugin/Views/InventoryView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../GUI/InventoryItemDataTemplate.xaml" />
<ResourceDictionary Source="../GUI/ItemDataTemplate.xaml" />
<ResourceDictionary Source="../GUI/ProgressBarDataTemplate.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<ListBox
<Window.Background>
<SolidColorBrush
Color="#00000000"
Opacity="0" />
</Window.Background>
<ItemsControl
BorderThickness="0"
ItemsSource="{Binding Items}"
HorizontalContentAlignment="Stretch"
Background="{x:Null}"
IsEnabled="False" />
</src:Widget>
4 changes: 2 additions & 2 deletions ItemBoxTracker/src/Shareables/Views/AutoSuggestBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
IsEnabled="{Binding IsEnabled, Mode=TwoWay}"
x:Name="searchInput"
BorderThickness="0"
Foreground="#ffbfbfbf">
Foreground="White">
<TextBox.InputBindings>
<KeyBinding
Key="Enter"
Expand Down Expand Up @@ -128,8 +128,8 @@
Background="{x:Null}"
Text="{Binding NoResultsText, RelativeSource={RelativeSource AncestorType=UserControl}}"
VerticalAlignment="Center"
Padding="5 0"
Visibility="{Binding SuggestionsView.IsEmpty, Converter={convert:BooleanToVisibilityConverter}}"
Padding="5 0"
Foreground="#ffbfbfbf" />
</Grid>
</Popup>
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ A plugin for hunter pie that lets players track the items they are farming.

Reducing cognitive overhead by allowing the player to stop looking at the box after every quest to find out that they still need 5 more tickets, 1 less than the last time they checked, and stop asking "how many did I need again?"

![Bootleg](https://user-images.githubusercontent.com/5027713/103073631-f05cf680-4595-11eb-9fd8-47546db63873.png)
![Overlay](https://user-images.githubusercontent.com/5027713/118384904-3b74b600-b5d8-11eb-90d7-5b6794b67526.png)

> The numbers displayed are `pouch | box (+craftable) / wanted`
## Changelog

Expand Down

0 comments on commit 60bff47

Please sign in to comment.