diff --git a/HDTAnomalyDisplay.sln b/HDTAnomalyDisplay.sln
index 17ac24f..a220cff 100644
--- a/HDTAnomalyDisplay.sln
+++ b/HDTAnomalyDisplay.sln
@@ -8,13 +8,19 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
+ Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
+ Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9151F41C-A5D4-406A-A35E-5FC828019E88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9151F41C-A5D4-406A-A35E-5FC828019E88}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9151F41C-A5D4-406A-A35E-5FC828019E88}.Debug|x86.ActiveCfg = Debug|x86
+ {9151F41C-A5D4-406A-A35E-5FC828019E88}.Debug|x86.Build.0 = Debug|x86
{9151F41C-A5D4-406A-A35E-5FC828019E88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9151F41C-A5D4-406A-A35E-5FC828019E88}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9151F41C-A5D4-406A-A35E-5FC828019E88}.Release|x86.ActiveCfg = Release|x86
+ {9151F41C-A5D4-406A-A35E-5FC828019E88}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/HDTAnomalyDisplay/AnomalyDisplay.cs b/HDTAnomalyDisplay/AnomalyDisplay.cs
index ce1359c..1411295 100644
--- a/HDTAnomalyDisplay/AnomalyDisplay.cs
+++ b/HDTAnomalyDisplay/AnomalyDisplay.cs
@@ -8,12 +8,15 @@
using Hearthstone_Deck_Tracker.API;
using System.Windows.Controls;
using Hearthstone_Deck_Tracker.Controls;
+using System.Windows.Media;
+using ControlzEx.Standard;
namespace HDTAnomalyDisplay
{
public class AnomalyDisplay
{
- public CardImage cardImage;
+ public CardImage CardImage;
+ public static MoveCardManager MoveManager;
public AnomalyDisplay()
{
@@ -43,17 +46,30 @@ public async Task AwaitGameEntity()
public void InitializeView(int cardDbfId)
{
- if (cardImage == null)
+ // Do not recreate card if it already exists via a double call to HandleGameStart() (cf OnLoad)
+ if (CardImage == null)
{
- cardImage = new CardImage();
+ CardImage = new CardImage();
- Core.OverlayCanvas.Children.Add(cardImage);
- Canvas.SetBottom(cardImage, 50);
- Canvas.SetLeft(cardImage, 0);
- cardImage.Visibility = System.Windows.Visibility.Visible;
+ Core.OverlayCanvas.Children.Add(CardImage);
+ Canvas.SetTop(CardImage, Settings.Default.AnomalyCardTop);
+ Canvas.SetLeft(CardImage, Settings.Default.AnomalyCardLeft);
+ CardImage.Visibility = System.Windows.Visibility.Visible;
+
+ MoveManager = new MoveCardManager(CardImage);
+ Settings.Default.PropertyChanged += SettingsChanged;
+ SettingsChanged(null, null);
}
- cardImage.SetCardIdFromCard(Database.GetCardFromDbfId(cardDbfId, false));
+ CardImage.SetCardIdFromCard(Database.GetCardFromDbfId(cardDbfId, false));
+ }
+
+ // On scaling change update the card
+ private void SettingsChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
+ {
+ CardImage.RenderTransform = new ScaleTransform(Settings.Default.AnomalyCardScale / 100, Settings.Default.AnomalyCardScale / 100);
+ Canvas.SetTop(CardImage, Settings.Default.AnomalyCardTop);
+ Canvas.SetLeft(CardImage, Settings.Default.AnomalyCardLeft);
}
public async void HandleGameStart()
@@ -82,9 +98,15 @@ public async void HandleGameStart()
public void ClearCard()
{
- cardImage.SetCardIdFromCard(null);
- Core.OverlayCanvas.Children.Remove(cardImage);
- cardImage = null;
+ CardImage.SetCardIdFromCard(null);
+ Core.OverlayCanvas.Children.Remove(CardImage);
+
+ MoveManager.Dispose();
+ Settings.Default.PropertyChanged -= SettingsChanged;
+
+ CardImage = null;
+ MoveManager = null;
+
}
}
}
diff --git a/HDTAnomalyDisplay/AnomalyDisplayPlugin.cs b/HDTAnomalyDisplay/AnomalyDisplayPlugin.cs
index 2e667a8..c96518c 100644
--- a/HDTAnomalyDisplay/AnomalyDisplayPlugin.cs
+++ b/HDTAnomalyDisplay/AnomalyDisplayPlugin.cs
@@ -11,20 +11,18 @@ public class AnomalyDisplayPlugin : IPlugin
public string Description => "Displays the current Battlegrounds anomaly on your overlay";
- public string ButtonText => "NO SETTINGS";
+ public string ButtonText => "SETTINGS";
// public string ButtonText => Strings.GetLocalized("");
public string Author => "Mouchoir & Tignus";
- public Version Version => new Version(1, 0);
+ public Version Version => new Version(1, 1, 0);
public MenuItem MenuItem => null;
public AnomalyDisplay anomalyDisplay;
- public void OnButtonPress()
- {
- }
+ public void OnButtonPress() => SettingsView.Flyout.IsOpen = true;
public void OnLoad()
{
@@ -32,12 +30,13 @@ public void OnLoad()
GameEvents.OnGameStart.Add(anomalyDisplay.HandleGameStart);
GameEvents.OnGameEnd.Add(anomalyDisplay.ClearCard);
- // Processing GameStart logic in case plugin was loaded after starting a game
+ // Processing GameStart logic in case plugin was loaded/unloaded after starting a game without restarting HDT
anomalyDisplay.HandleGameStart();
}
public void OnUnload()
{
+ Settings.Default.Save();
anomalyDisplay.ClearCard();
anomalyDisplay = null;
}
diff --git a/HDTAnomalyDisplay/HDTAnomalyDisplay.csproj b/HDTAnomalyDisplay/HDTAnomalyDisplay.csproj
index 9d35eed..914a8d3 100644
--- a/HDTAnomalyDisplay/HDTAnomalyDisplay.csproj
+++ b/HDTAnomalyDisplay/HDTAnomalyDisplay.csproj
@@ -30,6 +30,23 @@
prompt
4
+
+ true
+ bin\x86\Debug\
+ DEBUG;TRACE
+ full
+ x86
+ 7.3
+ prompt
+
+
+ bin\x86\Release\
+ TRACE
+ true
+ x86
+ 7.3
+ prompt
+
references\HearthDb.dll
@@ -41,6 +58,7 @@
+
@@ -53,7 +71,34 @@
+
+
+
+ True
+ True
+ Settings.settings
+
+
+ SettingsView.xaml
+
+
+
+
+ MSBuild:Compile
+
+
+
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+
+
+ 1.6.5
+
diff --git a/HDTAnomalyDisplay/MoveCardManager.cs b/HDTAnomalyDisplay/MoveCardManager.cs
new file mode 100644
index 0000000..b8bf95d
--- /dev/null
+++ b/HDTAnomalyDisplay/MoveCardManager.cs
@@ -0,0 +1,104 @@
+using Hearthstone_Deck_Tracker;
+using Core = Hearthstone_Deck_Tracker.API.Core;
+using System;
+using System.Windows.Controls;
+using System.Windows;
+using Hearthstone_Deck_Tracker.Controls;
+using Hearthstone_Deck_Tracker.Utility;
+
+namespace HDTAnomalyDisplay
+{
+ public class MoveCardManager
+ {
+ private User32.MouseInput _mouseInput;
+ private CardImage _card;
+
+ private bool _selected;
+
+ public MoveCardManager(CardImage cardImageToMove)
+ {
+ _card = cardImageToMove;
+ }
+
+ public bool ToggleUILockState()
+ {
+ if (Hearthstone_Deck_Tracker.Core.Game.IsRunning && _mouseInput == null)
+ {
+ _mouseInput = new User32.MouseInput();
+ _mouseInput.LmbDown += MouseInputOnLmbDown;
+ _mouseInput.LmbUp += MouseInputOnLmbUp;
+ _mouseInput.MouseMoved += MouseInputOnMouseMoved;
+ return true;
+ }
+ Dispose();
+ return false;
+ }
+
+ public bool isUILocked()
+ {
+ return _mouseInput == null;
+ }
+
+ public void Dispose()
+ {
+ _mouseInput?.Dispose();
+ _mouseInput = null;
+ _selected = false;
+ }
+
+ private void MouseInputOnLmbDown(object sender, EventArgs eventArgs)
+ {
+ var pos = User32.GetMousePos();
+ var _mousePos = new Point(pos.X, pos.Y);
+ if (PointInsideControl(_mousePos, _card))
+ {
+ _selected = true;
+ }
+ }
+
+ private void MouseInputOnLmbUp(object sender, EventArgs eventArgs)
+ {
+ _selected = false;
+ }
+
+ private void MouseInputOnMouseMoved(object sender, EventArgs eventArgs)
+ {
+ if (!_selected)
+ {
+ return;
+ }
+
+ var pos = User32.GetMousePos();
+ var p = Core.OverlayCanvas.PointFromScreen(new Point(pos.X, pos.Y));
+
+ // TODO check max height and width, does not work yet
+ if (p.Y < 0)
+ {
+ p.Y = 0;
+ }
+ else if (p.Y > Core.OverlayCanvas.Height)
+ {
+
+ p.Y = Core.OverlayCanvas.Height;
+ }
+
+ if (p.X < 0)
+ {
+ p.X = 0;
+ }
+ else if (p.X > Core.OverlayCanvas.Width)
+ {
+ p.X = Core.OverlayCanvas.Width;
+ }
+
+ Settings.Default.AnomalyCardTop = p.Y;
+ Settings.Default.AnomalyCardLeft = p.X;
+ }
+
+ private bool PointInsideControl(Point p, FrameworkElement control)
+ {
+ var pos = control.PointFromScreen(p);
+ return pos.X > 0 && pos.X < control.ActualWidth && pos.Y > 0 && pos.Y < control.ActualHeight;
+ }
+ }
+}
diff --git a/HDTAnomalyDisplay/Settings.Designer.cs b/HDTAnomalyDisplay/Settings.Designer.cs
new file mode 100644
index 0000000..d8375c4
--- /dev/null
+++ b/HDTAnomalyDisplay/Settings.Designer.cs
@@ -0,0 +1,62 @@
+//------------------------------------------------------------------------------
+//
+// Ce code a été généré par un outil.
+// Version du runtime :4.0.30319.42000
+//
+// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si
+// le code est régénéré.
+//
+//------------------------------------------------------------------------------
+
+namespace HDTAnomalyDisplay {
+
+
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.8.0.0")]
+ public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+
+ private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+ public static Settings Default {
+ get {
+ return defaultInstance;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("630")]
+ public double AnomalyCardTop {
+ get {
+ return ((double)(this["AnomalyCardTop"]));
+ }
+ set {
+ this["AnomalyCardTop"] = value;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("0")]
+ public double AnomalyCardLeft {
+ get {
+ return ((double)(this["AnomalyCardLeft"]));
+ }
+ set {
+ this["AnomalyCardLeft"] = value;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("100")]
+ public double AnomalyCardScale {
+ get {
+ return ((double)(this["AnomalyCardScale"]));
+ }
+ set {
+ this["AnomalyCardScale"] = value;
+ }
+ }
+ }
+}
diff --git a/HDTAnomalyDisplay/Settings.cs b/HDTAnomalyDisplay/Settings.cs
new file mode 100644
index 0000000..c76bafb
--- /dev/null
+++ b/HDTAnomalyDisplay/Settings.cs
@@ -0,0 +1,76 @@
+using Hearthstone_Deck_Tracker;
+using Hearthstone_Deck_Tracker.Utility.Logging;
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.IO;
+using System.Linq;
+
+namespace HDTAnomalyDisplay
+{
+ public class Setting
+ {
+ public Setting() { }
+ public Setting(string name, string value)
+ {
+ Name = name;
+ Value = value;
+ }
+ public string Name { get; set; }
+ public string Value { get; set; }
+ }
+
+ public sealed partial class Settings
+ {
+ private const string Filename = "HDTAnomalyDisplaySettings.xml";
+ internal static string DataDir => Config.Instance.DataDir;
+ private static string SettingsPath => Path.Combine(DataDir, Filename);
+
+ public Settings()
+ {
+ var provider = Providers;
+
+ SettingsLoaded += SettingsLoadedEventHandler;
+ SettingsSaving += SettingsSavingEventHandler;
+ }
+
+ private void SettingsLoadedEventHandler(object sender, System.Configuration.SettingsLoadedEventArgs e)
+ {
+ try
+ {
+ if (File.Exists(SettingsPath))
+ {
+ var actual = XmlManager>.Load(SettingsPath);
+
+ foreach (var setting in actual)
+ {
+ this[setting.Name] = Convert.ChangeType(setting.Value, this.Properties[setting.Name].PropertyType);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ Log.Error(ex);
+ }
+ }
+
+ private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e)
+ {
+ try
+ {
+ var saveFormat = PropertyValues.Cast()
+ .Where(p => p.SerializedValue.ToString() != p.Property.DefaultValue.ToString())
+ .Select(p => new Setting(p.Name, p.SerializedValue.ToString()))
+ .ToList();
+
+ XmlManager>.Save(SettingsPath, saveFormat);
+
+ e.Cancel = true;
+ }
+ catch (Exception ex)
+ {
+ Log.Error(ex);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/HDTAnomalyDisplay/Settings.settings b/HDTAnomalyDisplay/Settings.settings
new file mode 100644
index 0000000..bb2d017
--- /dev/null
+++ b/HDTAnomalyDisplay/Settings.settings
@@ -0,0 +1,15 @@
+
+
+
+
+
+ 630
+
+
+ 0
+
+
+ 100
+
+
+
\ No newline at end of file
diff --git a/HDTAnomalyDisplay/SettingsView.xaml b/HDTAnomalyDisplay/SettingsView.xaml
new file mode 100644
index 0000000..15c6c46
--- /dev/null
+++ b/HDTAnomalyDisplay/SettingsView.xaml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
diff --git a/HDTAnomalyDisplay/SettingsView.xaml.cs b/HDTAnomalyDisplay/SettingsView.xaml.cs
new file mode 100644
index 0000000..b629584
--- /dev/null
+++ b/HDTAnomalyDisplay/SettingsView.xaml.cs
@@ -0,0 +1,99 @@
+using Hearthstone_Deck_Tracker.Properties;
+using System.Windows;
+using System.Windows.Controls;
+
+using MahApps.Metro.Controls;
+using Hearthstone_Deck_Tracker;
+using System.Collections.Generic;
+using System;
+using System.Linq;
+
+namespace HDTAnomalyDisplay
+{
+ public partial class SettingsView : UserControl
+ {
+ private static Flyout _flyout;
+
+ public static Flyout Flyout
+ {
+ get
+ {
+ if (_flyout == null)
+ {
+ _flyout = CreateSettingsFlyout();
+ }
+ return _flyout;
+ }
+ }
+
+ private static Flyout CreateSettingsFlyout()
+ {
+ var settings = new Flyout();
+ settings.Position = Position.Left;
+ Panel.SetZIndex(settings, 100);
+ settings.Header = "Settings";
+ settings.Content = new SettingsView();
+ Core.MainWindow.Flyouts.Items.Add(settings);
+ return settings;
+ }
+
+ public SettingsView()
+ {
+ InitializeComponent();
+ }
+ public IEnumerable OrientationTypes => Enum.GetValues(typeof(Orientation)).Cast();
+
+ private void BtnUnlock_Click(object sender, RoutedEventArgs e)
+ {
+ if (AnomalyDisplay.MoveManager != null)
+ {
+ // if MoveManager is null we should create a dummy Norgannon card that can be moved around to save the position
+ BtnUnlock.Content = AnomalyDisplay.MoveManager.ToggleUILockState() ? "Lock overlay" : "Unlock overlay";
+ }
+
+ }
+
+ private void BtnReset_Click(object sender, RoutedEventArgs e)
+ {
+ Settings.Default.AnomalyCardLeft = 0;
+ Settings.Default.AnomalyCardTop = 630;
+ Settings.Default.Save();
+ }
+ /* private void BtnUnlock_Click(object sender, RoutedEventArgs e)
+ {
+ IsOverlayLocked = !IsOverlayLocked;
+ UpdateLockStateUI();
+ ToggleOverlayDraggable(IsOverlayLocked);
+ }
+
+ private void BtnReset_Click(object sender, RoutedEventArgs e)
+ {
+ ResetOverlayPosition();
+ }
+
+ private void LoadSettings()
+ {
+ var position = new Point(Settings.Default.AnomalyCardLeft, Settings.Default.AnomalyCardTop);
+ var scale = Settings.Default.AnomalyCardScale;
+ ApplyOverlaySettings(position, scale);
+ }
+
+ private void ResetOverlayPosition()
+ {
+ var defaultPosition = GetDefaultOverlayPosition();
+ ApplyOverlayPosition(defaultPosition);
+ }
+
+ private Point GetDefaultOverlayPosition()
+ {
+ return new Point(0, 50);
+ }
+
+ private void UpdateLockStateUI()
+ {
+ BtnUnlock.Content = IsOverlayLocked ? "Unlock Overlay" : "Lock Overlay";
+ }*/
+
+
+ }
+}
diff --git a/HDTAnomalyDisplay/app.config b/HDTAnomalyDisplay/app.config
new file mode 100644
index 0000000..a38055c
--- /dev/null
+++ b/HDTAnomalyDisplay/app.config
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+ 630
+
+
+ 0
+
+
+ 100
+
+
+
+
\ No newline at end of file