Skip to content

Commit

Permalink
Merge pull request #71 from Stuff-Mods/resize
Browse files Browse the repository at this point in the history
Allow widget to be resized
  • Loading branch information
DevilPepper authored Jun 29, 2021
2 parents 448f437 + 3c1985f commit b80e525
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 63 deletions.
2 changes: 1 addition & 1 deletion ItemBoxTracker/src/Plugin/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions ItemBoxTracker/src/Plugin/Service/EventService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 5 additions & 18 deletions ItemBoxTracker/src/Plugin/Views/InventoryView.xaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
<src:Widget
<UserControl
x:Class="MHWItemBoxTracker.Views.InventoryView"
xmlns:src="clr-namespace:HunterPie.GUI;assembly=HunterPie.UI"
xmlns:Custom="clr-namespace:HunterPie.GUIControls.Custom_Controls;assembly=HunterPie.UI"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
ResizeMode="NoResize"
WindowStyle="None"
AllowsTransparency="True"
ShowInTaskbar="False"
Topmost="True"
SizeToContent="Height"
Width="350"
WidgetActive="True">
<Window.Resources>
Width="350">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Resource/InventoryItemDataTemplate.xaml" />
<ResourceDictionary Source="../Resource/ItemDataTemplate.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Window.Background>
<SolidColorBrush
Color="#00000000"
Opacity="0" />
</Window.Background>
</UserControl.Resources>
<ItemsControl
BorderThickness="0"
ItemsSource="{Binding Items}"
HorizontalContentAlignment="Stretch"
Background="{x:Null}"
IsEnabled="False" />
</src:Widget>
</UserControl>
46 changes: 4 additions & 42 deletions ItemBoxTracker/src/Plugin/Views/InventoryView.xaml.cs
Original file line number Diff line number Diff line change
@@ -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<ItemBoxWidgetSettings>(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);
}
}
}
33 changes: 33 additions & 0 deletions ItemBoxTracker/src/Plugin/Views/InventoryWidget.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<src:Widget
x:Class="MHWItemBoxTracker.Views.InventoryWidget"
xmlns:src="clr-namespace:HunterPie.GUI;assembly=HunterPie.UI"
xmlns:Custom="clr-namespace:HunterPie.GUIControls.Custom_Controls;assembly=HunterPie.UI"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:convert="clr-namespace:HunterPie.UI.Infrastructure.Converters;assembly=HunterPie.UI"
xmlns:local="clr-namespace:MHWItemBoxTracker.Views"
mc:Ignorable="d"
ResizeMode="CanResize"
WindowStyle="None"
AllowsTransparency="True"
ShowInTaskbar="False"
Topmost="True"
SizeToContent="WidthAndHeight"
Width="350"
Style="{StaticResource OVERLAY_WIDGET_STYLE}"
WidgetActive="True">
<Grid>
<local:InventoryView
x:Name="contents"
DataContext="{Binding VM}" />
<TextBlock
Text="{Binding DesignModeDetails}"
Visibility="{Binding DesignModeDetailsVisibility}"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Width="230"
Style="{StaticResource OVERLAY_DESIGN_MODE_DEBUG}" />
</Grid>
</src:Widget>
54 changes: 54 additions & 0 deletions ItemBoxTracker/src/Plugin/Views/InventoryWidget.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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<ItemBoxWidgetSettings>(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);
}

public override void ScaleWidget(double newScaleX, double newScaleY) {
base.ScaleWidget(newScaleX, newScaleY);
contents.LayoutTransform = LayoutTransform;
}
}
}

0 comments on commit b80e525

Please sign in to comment.