Skip to content

Commit

Permalink
feat: anomaly card is now resizable and can be moved even when not in…
Browse files Browse the repository at this point in the history
… BG game (#5)

* feat: initiate slider

* feat: improve UI layout

* feat: bind scale slider value to anomaly card setting

* fix: mouse position when moving card

* feat: add a settings shortcut to HDT "Plugin" tab

* fix: better mouse position when moving card

* feat: remove positioning limitations

* feat: keep mouse position when moving the card

* feat: initialize dummy card overlay

* feat: display temporary card if adjusting overlay while not in BG game

* feat: update README
  • Loading branch information
Mouchoir authored Nov 19, 2023
1 parent c46fff5 commit e68142b
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 89 deletions.
8 changes: 4 additions & 4 deletions HDTAnomalyDisplay/AnomalyDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void InitializeView(int cardDbfId)
Canvas.SetLeft(CardImage, Settings.Default.AnomalyCardLeft);
CardImage.Visibility = System.Windows.Visibility.Visible;

MoveManager = new MoveCardManager(CardImage);
MoveManager = new MoveCardManager(CardImage, SettingsView.IsUnlocked);
Settings.Default.PropertyChanged += SettingsChanged;
SettingsChanged(null, null);
}
Expand Down Expand Up @@ -100,13 +100,13 @@ public void ClearCard()
{
CardImage.SetCardIdFromCard(null);
Core.OverlayCanvas.Children.Remove(CardImage);
CardImage = null;

Log.Info("Destroying the MoveManager...");
MoveManager.Dispose();
Settings.Default.PropertyChanged -= SettingsChanged;

CardImage = null;
MoveManager = null;

Settings.Default.PropertyChanged -= SettingsChanged;
}
}
}
16 changes: 13 additions & 3 deletions HDTAnomalyDisplay/AnomalyDisplayPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@ public class AnomalyDisplayPlugin : IPlugin
public string Description => "Displays the current Battlegrounds anomaly on your overlay";

public string ButtonText => "SETTINGS";
// public string ButtonText => Strings.GetLocalized("");

public string Author => "Mouchoir & Tignus";

public Version Version => new Version(1, 1, 0);
public Version Version => new Version(1, 2, 0);

public MenuItem MenuItem => null;
public MenuItem MenuItem => CreateMenu();

private MenuItem CreateMenu()
{
MenuItem settingsMenuItem = new MenuItem { Header = "Anomaly Display Settings" };

settingsMenuItem.Click += (sender, args) =>
{
SettingsView.Flyout.IsOpen = true;
};

return settingsMenuItem;
}
public AnomalyDisplay anomalyDisplay;

public void OnButtonPress() => SettingsView.Flyout.IsOpen = true;
Expand Down
54 changes: 26 additions & 28 deletions HDTAnomalyDisplay/MoveCardManager.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
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 readonly CardImage _card;
public bool IsUnlocked { get; private set; }


private double xMouseDeltaFromCard;
private double yMouseDeltaFromCard;

private bool _selected;

public MoveCardManager(CardImage cardImageToMove)
public MoveCardManager(CardImage cardImageToMove, bool isUnlocked)
{
_card = cardImageToMove;
IsUnlocked = isUnlocked;
if (IsUnlocked)
{
ToggleUILockState();
}
}

public bool ToggleUILockState()
Expand All @@ -28,10 +36,15 @@ public bool ToggleUILockState()
_mouseInput.LmbDown += MouseInputOnLmbDown;
_mouseInput.LmbUp += MouseInputOnLmbUp;
_mouseInput.MouseMoved += MouseInputOnMouseMoved;
return true;
IsUnlocked = true;
}
else
{
Dispose();
IsUnlocked = false;
}
Dispose();
return false;

return IsUnlocked;
}

public bool isUILocked()
Expand Down Expand Up @@ -69,27 +82,9 @@ private void MouseInputOnMouseMoved(object sender, EventArgs eventArgs)
}

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;
}
double mouseVerticalPositionAdjust = (yMouseDeltaFromCard * Settings.Default.AnomalyCardScale / 100);
double mouseHorizontalPositionAdjust = (xMouseDeltaFromCard * Settings.Default.AnomalyCardScale / 100);
var p = Core.OverlayCanvas.PointFromScreen(new Point(pos.X - mouseHorizontalPositionAdjust, pos.Y - mouseVerticalPositionAdjust));

Settings.Default.AnomalyCardTop = p.Y;
Settings.Default.AnomalyCardLeft = p.X;
Expand All @@ -98,6 +93,9 @@ private void MouseInputOnMouseMoved(object sender, EventArgs eventArgs)
private bool PointInsideControl(Point p, FrameworkElement control)
{
var pos = control.PointFromScreen(p);
xMouseDeltaFromCard = pos.X;
yMouseDeltaFromCard = pos.Y;

return pos.X > 0 && pos.X < control.ActualWidth && pos.Y > 0 && pos.Y < control.ActualHeight;
}
}
Expand Down
29 changes: 26 additions & 3 deletions HDTAnomalyDisplay/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,31 @@
xmlns:local="clr-namespace:HDTAnomalyDisplay"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Name="BtnUnlock" Width="150" Content="Unlock Overlay" Click="BtnUnlock_Click" />
<Button Name="BtnReset" Width="150" Content="Reset Position" Click="BtnReset_Click" />
<StackPanel Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Top" Width="290" Margin="5,5,5,5" Height="290">
<StackPanel.Resources>
<Style x:Key="SliderPanelStyle" TargetType="DockPanel">
<Setter Property="Margin" Value="0,0"/>
<Setter Property="Width" Value="300"/>
</Style>
<Style x:Key="SliderStyle" TargetType="Slider">
<Setter Property="IsSnapToTickEnabled" Value="True"/>
<Setter Property="TickFrequency" Value="1"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Width" Value="150"/>
<Setter Property="LargeChange" Value="10"/>
<Setter Property="Minimum" Value="75"/>
<Setter Property="Maximum" Value="250"/>
</Style>
</StackPanel.Resources>
<Button Name="BtnUnlock" Width="150" Margin="0,30,0,5" Content="Unlock Overlay" Click="BtnUnlock_Click" />
<Label Content="(Unlocking while not ingame will display a temporary card)" Width="290" FontSize="10" HorizontalContentAlignment="Center" />

<Button Name="BtnReset" Width="150" Margin="0,5,0,30" Content="Reset Position" Click="BtnReset_Click" />
<DockPanel Style="{StaticResource SliderPanelStyle}" Width="295">
<Label Content="Scale" Width="50" Margin="20,0,0,0" />
<Slider x:Name="SliderScale" DockPanel.Dock="Top"
Style="{StaticResource SliderStyle}"
Value="{Binding AnomalyCardScale, Source={x:Static local:Settings.Default}}"/>
</DockPanel>
</StackPanel>
</UserControl>
73 changes: 33 additions & 40 deletions HDTAnomalyDisplay/SettingsView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
using Hearthstone_Deck_Tracker.Properties;
using System.Windows;
using System.Windows;
using System.Windows.Controls;

using MahApps.Metro.Controls;
using Hearthstone_Deck_Tracker;
using System.Collections.Generic;
using System;
using System.Linq;
using Hearthstone_Deck_Tracker.Utility.Logging;
using API = Hearthstone_Deck_Tracker.API;

namespace HDTAnomalyDisplay
{
public partial class SettingsView : UserControl
{
private static Flyout _flyout;

private AnomalyDisplay AnomalyDisplay;

private readonly int NorgannonDbfId = 103078;

public static bool IsUnlocked { get; private set; }


public static Flyout Flyout
{
get
Expand Down Expand Up @@ -45,55 +53,40 @@ public SettingsView()

private void BtnUnlock_Click(object sender, RoutedEventArgs e)
{
if (AnomalyDisplay.MoveManager != null)

if (AnomalyDisplay.MoveManager == null && AnomalyDisplay == null)
{
Log.Info("No ongoing game, create a dummy Norgannon card that can be moved around to save the position.");
AnomalyDisplay = new AnomalyDisplay();
AnomalyDisplay.InitializeView(NorgannonDbfId);
API.GameEvents.OnGameStart.Add(ClearCardDisplay);
}

IsUnlocked = AnomalyDisplay.MoveManager.ToggleUILockState();
if (!IsUnlocked && AnomalyDisplay != 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";
AnomalyDisplay.ClearCard();
AnomalyDisplay = null;
}

BtnUnlock.Content = IsUnlocked ? "Lock overlay" : "Unlock overlay";
}

private void BtnReset_Click(object sender, RoutedEventArgs e)
{
Settings.Default.AnomalyCardLeft = 0;
Settings.Default.AnomalyCardTop = 630;
Settings.Default.AnomalyCardScale = 100;
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";
}*/


public void ClearCardDisplay()
{
if (AnomalyDisplay != null)
{
AnomalyDisplay.ClearCard();
AnomalyDisplay = null;
}
}
}
}
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@

# HDT Anomaly Display Plugin
# HDT Anomaly Display Plugin

Enhance your Hearthstone Battlegrounds streaming experience with the HDT Anomaly Display Plugin. This tool overlays information about "anomalies" directly onto your stream, saving you from the hassle of manual updates. It's designed to integrate smoothly with Hearthstone Deck Tracker (HDT), providing both streamers and their audience with real-time game insights.

## Features

- **Automatic Anomaly Detection**: The plugin automatically detects and displays anomalies as they appear in the game, keeping your audience in the loop without any extra effort on your part.
- **Seamless Overlay Integration**: The anomaly information is displayed directly in the Hearthstone Deck Tracker overlay, ensuring a clean and unobtrusive addition to your stream.
- **Move Card**: Reposition the anomaly tooltip on the overlay to suit your stream's design.
- **Resize Card**: Resizable tooltips to accommodate different screen sizes and resolutions.
- **Localization**: Display the anomaly card in your own language using HDT settings (Options > Tracker > General > Card language).
- **Plug-and-Play**: With its user-friendly setup, all you have to do is enable the plugin and you're good to go—no complicated configurations needed.


## Usage

To install the HDT Anomaly Display Plugin:
Expand All @@ -18,15 +21,6 @@ To install the HDT Anomaly Display Plugin:

Once installed, the plugin will automatically display anomaly tooltips within the Hearthstone Deck Tracker overlay during your game sessions.

## Roadmap

We're constantly looking to improve the plugin. Here's what's on the horizon:

- [X] **Move Card**: Add the ability to reposition the anomaly tooltip on the overlay to suit your stream's design.
- [ ] **Resize Card**: Introduce resizable tooltips to accommodate different screen sizes and resolutions.
- [X] **Localization**: Expand the plugin's language support to include multiple languages, defaulting to the language set in HDT's options.
- [ ] **Autoupdate**: Implement an auto-update mechanism to ensure the plugin is always up-to-date with the latest features and anomaly information.

## Contributions

All credit to [@Tignus](https://github.com/Tignus) for the incredible work! Want to contribute? We'd love your input:
Expand Down

0 comments on commit e68142b

Please sign in to comment.