From eba3b43e78219a974d8b30ee3611d6aebb0eca15 Mon Sep 17 00:00:00 2001 From: SupaStuff Date: Tue, 29 Jun 2021 00:23:58 -0400 Subject: [PATCH 1/2] fix(widget): add design mode details and use static resources provided by HunterPie --- ItemBoxTracker/src/Plugin/Main.cs | 2 +- .../src/Plugin/Service/EventService.cs | 4 +- .../src/Plugin/Views/InventoryView.xaml | 23 ++------- .../src/Plugin/Views/InventoryView.xaml.cs | 46 ++--------------- .../src/Plugin/Views/InventoryWidget.xaml | 31 ++++++++++++ .../src/Plugin/Views/InventoryWidget.xaml.cs | 49 +++++++++++++++++++ 6 files changed, 92 insertions(+), 63 deletions(-) create mode 100644 ItemBoxTracker/src/Plugin/Views/InventoryWidget.xaml create mode 100644 ItemBoxTracker/src/Plugin/Views/InventoryWidget.xaml.cs diff --git a/ItemBoxTracker/src/Plugin/Main.cs b/ItemBoxTracker/src/Plugin/Main.cs index a937c24..4f01ce2 100644 --- a/ItemBoxTracker/src/Plugin/Main.cs +++ b/ItemBoxTracker/src/Plugin/Main.cs @@ -17,7 +17,7 @@ public class Main : IPlugin, ISettingsOwner { private EventService Events; private HunterPieService HP; private InventoryService Inventory; - private InventoryView GUI; + private InventoryWidget GUI; private SettingsView settings; private SettingsView Settings { diff --git a/ItemBoxTracker/src/Plugin/Service/EventService.cs b/ItemBoxTracker/src/Plugin/Service/EventService.cs index c45c6cc..b8fee8c 100644 --- a/ItemBoxTracker/src/Plugin/Service/EventService.cs +++ b/ItemBoxTracker/src/Plugin/Service/EventService.cs @@ -6,10 +6,10 @@ namespace MHWItemBoxTracker.Service { public class EventService { private Game Context; - InventoryView GUI; + InventoryWidget GUI; InventoryService Inventory; SettingsView Settings; - public EventService(Game Context, InventoryView GUI, InventoryService Inventory, SettingsView Settings) { + public EventService(Game Context, InventoryWidget GUI, InventoryService Inventory, SettingsView Settings) { this.Context = Context; this.GUI = GUI; this.Inventory = Inventory; diff --git a/ItemBoxTracker/src/Plugin/Views/InventoryView.xaml b/ItemBoxTracker/src/Plugin/Views/InventoryView.xaml index 07b729f..84ebf4b 100644 --- a/ItemBoxTracker/src/Plugin/Views/InventoryView.xaml +++ b/ItemBoxTracker/src/Plugin/Views/InventoryView.xaml @@ -1,37 +1,24 @@ - - + Width="350"> + - - - - + - + diff --git a/ItemBoxTracker/src/Plugin/Views/InventoryView.xaml.cs b/ItemBoxTracker/src/Plugin/Views/InventoryView.xaml.cs index 9d667e6..ce847b1 100644 --- a/ItemBoxTracker/src/Plugin/Views/InventoryView.xaml.cs +++ b/ItemBoxTracker/src/Plugin/Views/InventoryView.xaml.cs @@ -1,48 +1,10 @@ -using System.Threading.Tasks; -using HunterPie.Core.Settings; -using HunterPie.GUI; -using HunterPie.Plugins; -using MHWItemBoxTracker.Model; -using MHWItemBoxTracker.ViewModel; -using static MHWItemBoxTracker.Main; +using System.Windows.Controls; namespace MHWItemBoxTracker.Views { - public partial class InventoryView : Widget { - private static readonly string settingsJson = "widget.settings.json"; - private ItemBoxWidgetSettings widgetSettings { get; set; } - public override IWidgetSettings Settings => widgetSettings; - private InventoryViewModel VM; - public bool ShouldShow { - set { - WidgetHasContent = value; - ChangeVisibility(); - } - } - - public InventoryView(InventoryModel Inventory) : base() { + // TODO: Delete this somehow + public partial class InventoryView : UserControl { + public InventoryView() : base() { InitializeComponent(); - VM = new(Inventory); - DataContext = VM; - } - - public async Task Initialize() { - widgetSettings = await Plugin.LoadJson(settingsJson); - ApplySettings(); - } - - public void Unload() { - ShouldShow = false; - } - - public override void EnterWidgetDesignMode() { - base.EnterWidgetDesignMode(); - RemoveWindowTransparencyFlag(); - } - - public async override void LeaveWidgetDesignMode() { - base.LeaveWidgetDesignMode(); - ApplyWindowTransparencyFlag(); - await Plugin.SaveJson(settingsJson, widgetSettings); } } } diff --git a/ItemBoxTracker/src/Plugin/Views/InventoryWidget.xaml b/ItemBoxTracker/src/Plugin/Views/InventoryWidget.xaml new file mode 100644 index 0000000..6a7b079 --- /dev/null +++ b/ItemBoxTracker/src/Plugin/Views/InventoryWidget.xaml @@ -0,0 +1,31 @@ + + + + + + diff --git a/ItemBoxTracker/src/Plugin/Views/InventoryWidget.xaml.cs b/ItemBoxTracker/src/Plugin/Views/InventoryWidget.xaml.cs new file mode 100644 index 0000000..ed19b9a --- /dev/null +++ b/ItemBoxTracker/src/Plugin/Views/InventoryWidget.xaml.cs @@ -0,0 +1,49 @@ +using System.Threading.Tasks; +using HunterPie.Core.Settings; +using HunterPie.GUI; +using HunterPie.Plugins; +using MHWItemBoxTracker.Model; +using MHWItemBoxTracker.ViewModel; +using static MHWItemBoxTracker.Main; + +namespace MHWItemBoxTracker.Views { + public partial class InventoryWidget : Widget { + private static readonly string settingsJson = "widget.settings.json"; + private ItemBoxWidgetSettings widgetSettings { get; set; } + public override IWidgetSettings Settings => widgetSettings; + public InventoryViewModel VM { get; } + public bool ShouldShow { + set { + WidgetHasContent = value; + ChangeVisibility(); + } + } + + public InventoryWidget(InventoryModel Inventory) : base() { + InitializeComponent(); + SetWindowFlags(); + VM = new(Inventory); + DataContext = this; + } + + public async Task Initialize() { + widgetSettings = await Plugin.LoadJson(settingsJson); + ApplySettings(); + } + + public void Unload() { + ShouldShow = false; + } + + public override void EnterWidgetDesignMode() { + base.EnterWidgetDesignMode(); + RemoveWindowTransparencyFlag(); + } + + public async override void LeaveWidgetDesignMode() { + ApplyWindowTransparencyFlag(); + base.LeaveWidgetDesignMode(); + await Plugin.SaveJson(settingsJson, widgetSettings); + } + } +} From 3c1985fe6607dec54672ff13be939f2946177fed Mon Sep 17 00:00:00 2001 From: SupaStuff Date: Tue, 29 Jun 2021 01:49:40 -0400 Subject: [PATCH 2/2] fix(widget): override ScaleWidget() to allow resizing --- ItemBoxTracker/src/Plugin/Views/InventoryWidget.xaml | 8 +++++--- ItemBoxTracker/src/Plugin/Views/InventoryWidget.xaml.cs | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ItemBoxTracker/src/Plugin/Views/InventoryWidget.xaml b/ItemBoxTracker/src/Plugin/Views/InventoryWidget.xaml index 6a7b079..7c08f3b 100644 --- a/ItemBoxTracker/src/Plugin/Views/InventoryWidget.xaml +++ b/ItemBoxTracker/src/Plugin/Views/InventoryWidget.xaml @@ -9,17 +9,19 @@ xmlns:convert="clr-namespace:HunterPie.UI.Infrastructure.Converters;assembly=HunterPie.UI" xmlns:local="clr-namespace:MHWItemBoxTracker.Views" mc:Ignorable="d" - ResizeMode="NoResize" + ResizeMode="CanResize" WindowStyle="None" AllowsTransparency="True" ShowInTaskbar="False" Topmost="True" - SizeToContent="Height" + SizeToContent="WidthAndHeight" Width="350" Style="{StaticResource OVERLAY_WIDGET_STYLE}" WidgetActive="True"> - +