Skip to content

Commit

Permalink
theme and accent selectable,
Browse files Browse the repository at this point in the history
background of add.win. settable,
lots of cleanup in options,
fixed handcount index out of bounds (hopefully),
fixed add.win. just being gone when minimized before app. close,
message to restart hs if log.config new/changed,
trackerwindow actually remembers pos now
  • Loading branch information
epix37 committed Jun 21, 2014
1 parent 35c9123 commit 2655e09
Show file tree
Hide file tree
Showing 12 changed files with 315 additions and 112 deletions.
8 changes: 7 additions & 1 deletion Hearthstone Deck Tracker/Config.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Xml.Serialization;
using MahApps.Metro;

namespace Hearthstone_Deck_Tracker
{
Expand Down Expand Up @@ -37,7 +38,7 @@ public class Config
public bool WindowsTopmost = false;
public bool WindowsTopmostIfHsForeground = false;
public bool WindowsOnStartup = false;
public string WindowsBackgroundHex = "";
public string WindowsBackgroundHex = "#696969";
public int UpdateDelay = 100;
public double PlayerDeckTop = 17;
public double PlayerDeckHeight = 65;
Expand Down Expand Up @@ -82,5 +83,10 @@ public class Config
public bool Debug = false;

public bool HideOpponentCardAge = false;

public string AccentName;
public string ThemeName;

public string SelectedWindowBackground = "Theme";
}
}
4 changes: 2 additions & 2 deletions Hearthstone Deck Tracker/Controls/DeckPicker.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid>
<Label Content="{Binding GetName}" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Black" FontSize="14"></Label>
<Label Content="{Binding TagList}" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="10" Margin="0,22, 0, 0"></Label>
<Label Content="{Binding GetName}" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Black" FontSize="14" Foreground="Black"></Label>
<Label Content="{Binding TagList}" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="10" Margin="0,22, 0, 0" Foreground="Black"></Label>
</Grid>
</Grid>
</DataTemplate>
Expand Down
16 changes: 16 additions & 0 deletions Hearthstone Deck Tracker/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Windows.Forms;
using MessageBox = System.Windows.MessageBox;
Expand Down Expand Up @@ -64,5 +65,20 @@ public static bool IsFullscreen(string windowName)

return bounds.Width == width && bounds.Height == height;
}

public static bool IsHex(IEnumerable<char> chars)
{
bool isHex;
foreach (var c in chars)
{
isHex = ((c >= '0' && c <= '9') ||
(c >= 'a' && c <= 'f') ||
(c >= 'A' && c <= 'F'));

if (!isHex)
return false;
}
return true;
}
}
}
160 changes: 119 additions & 41 deletions Hearthstone Deck Tracker/MainWindow.xaml

Large diffs are not rendered by default.

180 changes: 155 additions & 25 deletions Hearthstone Deck Tracker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using MahApps.Metro;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using Microsoft.Win32;
using Brush = System.Windows.Media.Brush;
using Color = System.Windows.Media.Color;
using ColorConverter = System.Windows.Media.ColorConverter;
using SystemColors = System.Windows.SystemColors;

#endregion

Expand Down Expand Up @@ -55,6 +60,7 @@ public partial class MainWindow
private bool _showIncorrectDeckMessage;
private readonly Version _newVersion;
private readonly TurnTimer _turnTimer;
private readonly bool _updatedLogConfig;


public MainWindow()
Expand All @@ -72,6 +78,7 @@ public MainWindow()
if (!File.Exists(_logConfigPath))
{
File.Copy("Files/log.config", _logConfigPath);
_updatedLogConfig = true;
}
else
{
Expand All @@ -81,7 +88,9 @@ public MainWindow()
if (file.LastWriteTime > localFile.LastWriteTime)
{
File.Copy("Files/log.config", _logConfigPath, true);
_updatedLogConfig = true;
}

}
}
catch (UnauthorizedAccessException e)
Expand Down Expand Up @@ -201,6 +210,9 @@ public MainWindow()
_xmlManager.Save("PlayerDecks.xml", _deckList);
}

ComboboxAccent.ItemsSource = ThemeManager.Accents;
ComboboxTheme.ItemsSource = ThemeManager.AppThemes;

LoadConfig();

//find hs directory
Expand Down Expand Up @@ -637,6 +649,10 @@ private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
{
ShowNewUpdateMessage();
}
if (_updatedLogConfig)
{
ShowUpdatedLogConfigMessage();
}
}

#endregion
Expand Down Expand Up @@ -688,11 +704,17 @@ private void ShowIncorrectDeckMessage()

private void LoadConfig()
{
if (_config.TrackerWindowTop != -1)
if (_config.TrackerWindowTop != -32000 && _config.TrackerWindowTop != -1)
Top = _config.TrackerWindowTop;
if (_config.TrackerWindowLeft != -1)
if (_config.TrackerWindowLeft != -32000 && _config.TrackerWindowLeft != -1)
Left = _config.TrackerWindowLeft;

var theme = ThemeManager.AppThemes.First(t => t.Name == _config.ThemeName);
var accent = ThemeManager.Accents.First(a => a.Name == _config.AccentName);
ThemeManager.ChangeAppStyle(Application.Current, accent, theme);
ComboboxTheme.SelectedItem = theme;
ComboboxAccent.SelectedItem = accent;

Height = _config.WindowHeight;
Hearthstone.HighlightCardsInHand = _config.HighlightCardsInHand;
CheckboxHideOverlayInBackground.IsChecked = _config.HideInBackground;
Expand Down Expand Up @@ -746,6 +768,13 @@ private void LoadConfig()
tags.Remove("All");
TagControlSet.LoadTags(tags);

ComboboxWindowBackground.SelectedItem = _config.SelectedWindowBackground;
TextboxCustomBackground.IsEnabled = _config.SelectedWindowBackground == "Custom";
TextboxCustomBackground.Text = string.IsNullOrEmpty(_config.WindowsBackgroundHex)
? "#696969"
: _config.WindowsBackgroundHex;
UpdateAdditionalWindowsBackground();

}

private void SortCardCollection(ItemCollection collection)
Expand Down Expand Up @@ -814,6 +843,10 @@ await this.ShowMessageAsync("New Update available!", "Download version " + strin
}

}
private async void ShowUpdatedLogConfigMessage()
{
await this.ShowMessageAsync("Restart Hearthstone", "This is either your first time starting the tracker or the log.config file has been updated. Please restart heartstone once, for the tracker to work properly.");
}

#endregion

Expand Down Expand Up @@ -1580,13 +1613,32 @@ private void CheckboxWindowsTopmost_Unchecked(object sender, RoutedEventArgs e)
private void CheckboxWindowsOpenAutomatically_Checked(object sender, RoutedEventArgs e)
{
if (!_initialized) return;
_playerWindow.Show();
_playerWindow.Activate();
_opponentWindow.Show();
_opponentWindow.Activate();
if (!_config.HideTimers)
{
_timerWindow.Show();
_timerWindow.Activate();
}

_playerWindow.SetCardCount(_hearthstone.PlayerHandCount,
30 - _hearthstone.PlayerDrawn.Sum(card => card.Count));

_opponentWindow.SetOpponentCardCount(_hearthstone.EnemyHandCount,
_hearthstone.OpponentDeckCount, _hearthstone.OpponentHasCoin);

_config.WindowsOnStartup = true;
SaveConfig(true);
}

private void CheckboxWindowsOpenAutomatically_Unchecked(object sender, RoutedEventArgs e)
{
if (!_initialized) return;
_playerWindow.Hide();
_opponentWindow.Hide();
_timerWindow.Hide();
_config.WindowsOnStartup = false;
SaveConfig(true);
}
Expand All @@ -1598,26 +1650,6 @@ private void SaveConfig(bool updateOverlay)
_overlay.Update(true);
}

private void BtnShowWindows_Click(object sender, RoutedEventArgs e)
{
//show playeroverlay and enemy overlay
_playerWindow.Show();
_playerWindow.Activate();
_opponentWindow.Show();
_opponentWindow.Activate();
if(!_config.HideTimers)
{
_timerWindow.Show();
_timerWindow.Activate();
}

_playerWindow.SetCardCount(_hearthstone.PlayerHandCount,
30 - _hearthstone.PlayerDrawn.Sum(card => card.Count));

_opponentWindow.SetOpponentCardCount(_hearthstone.EnemyHandCount,
_hearthstone.OpponentDeckCount, _hearthstone.OpponentHasCoin);
}

private void RangeSliderPlayer_UpperValueChanged(object sender, RangeParameterChangedEventArgs e)
{
if (!_initialized) return;
Expand Down Expand Up @@ -1710,16 +1742,22 @@ private void CheckboxWinTopmostHsForeground_Checked(object sender, RoutedEventAr
{
if (!_initialized) return;
_config.WindowsTopmostIfHsForeground = true;
_playerWindow.Topmost = true;
_opponentWindow.Topmost = true;
_timerWindow.Topmost = true;
_playerWindow.Topmost = false;
_opponentWindow.Topmost = false;
_timerWindow.Topmost = false;
SaveConfig(false);
}

private void CheckboxWinTopmostHsForeground_Unchecked(object sender, RoutedEventArgs e)
{
if (!_initialized) return;
_config.WindowsTopmostIfHsForeground = false;
if (_config.WindowsTopmost)
{
_playerWindow.Topmost = true;
_opponentWindow.Topmost = true;
_timerWindow.Topmost = true;
}
SaveConfig(false);
}

Expand Down Expand Up @@ -1861,11 +1899,103 @@ private void SliderTimersVerticalSpacing_ValueChanged(object sender, RoutedPrope
}
#endregion


//TODO: MOVE THESE TO RIGHT REGIONS
private void MetroWindow_LocationChanged(object sender, EventArgs e)
{
_config.TrackerWindowTop = (int)Top;
_config.TrackerWindowLeft = (int)Left;
}

private void ComboboxAccent_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!_initialized) return;
var accent = ComboboxAccent.SelectedItem as Accent;
if (accent != null)
{
ThemeManager.ChangeAppStyle(Application.Current, accent, ThemeManager.DetectAppStyle().Item1);
_config.AccentName = accent.Name;
SaveConfig(false);
}
}

private void ComboboxTheme_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!_initialized) return;
var theme = ComboboxTheme.SelectedItem as AppTheme;
if (theme != null)
{
ThemeManager.ChangeAppStyle(Application.Current, ThemeManager.DetectAppStyle().Item2, theme);
_config.ThemeName = theme.Name;
//if(ComboboxWindowBackground.SelectedItem.ToString() != "Default")
UpdateAdditionalWindowsBackground();
SaveConfig(false);
}
}

private void ComboboxWindowBackground_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!_initialized) return;
TextboxCustomBackground.IsEnabled = ComboboxWindowBackground.SelectedItem.ToString() == "Custom";
_config.SelectedWindowBackground = ComboboxWindowBackground.SelectedItem.ToString();
UpdateAdditionalWindowsBackground();
}
private void UpdateAdditionalWindowsBackground(Brush brush = null)
{
Brush background = brush;

switch (ComboboxWindowBackground.SelectedItem.ToString())
{
case "Theme":
background = Background;
break;
case "Light":
background = SystemColors.ControlLightBrush;
break;
case "Dark":
background = SystemColors.ControlDarkDarkBrush;
break;
}
if (background == null)
{
var hexBackground = BackgroundFromHex();
if (hexBackground != null)
{
_playerWindow.Background = hexBackground;
_opponentWindow.Background = hexBackground;
_timerWindow.Background = hexBackground;
}
}
else
{
_playerWindow.Background = background;
_opponentWindow.Background = background;
_timerWindow.Background = background;
}
}
private SolidColorBrush BackgroundFromHex()
{
SolidColorBrush brush = null;
var hex = TextboxCustomBackground.Text;
if (hex.StartsWith("#")) hex = hex.Remove(0, 1);
if (!string.IsNullOrEmpty(hex) && hex.Length == 6 && Helper.IsHex(hex))
{
var color = ColorTranslator.FromHtml("#" + hex);
brush = new SolidColorBrush(Color.FromRgb(color.R, color.G, color.B));
}
return brush;
}

private void TextboxCustomBackground_TextChanged(object sender, TextChangedEventArgs e)
{
if (!_initialized || ComboboxWindowBackground.SelectedItem.ToString() != "Custom") return;
var background = BackgroundFromHex();
if(background != null)
{
UpdateAdditionalWindowsBackground(background);
_config.WindowsBackgroundHex = TextboxCustomBackground.Text;
SaveConfig(false);
}
}
}
}
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/Windows/OpponentWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:local="clr-namespace:Hearthstone_Deck_Tracker"
Title="Opponent" Height="440" Width="226" MinWidth="226" MaxWidth="226" Background="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" SizeChanged="Window_SizeChanged_1" Activated="Window_Activated_1" Icon="/Hearthstone Deck Tracker;component/Images/HearthstoneDeckTracker.ico" Deactivated="MetroWindow_Deactivated" LocationChanged="MetroWindow_LocationChanged">
Title="Opponent" Height="440" Width="226" MinWidth="226" MaxWidth="226" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" SizeChanged="Window_SizeChanged_1" Activated="Window_Activated_1" Icon="/Hearthstone Deck Tracker;component/Images/HearthstoneDeckTracker.ico" Deactivated="MetroWindow_Deactivated" LocationChanged="MetroWindow_LocationChanged">
<Grid Name="WindowGrid">
<StackPanel>
<local:DeckListView x:Name="ListViewOpponent" Foreground="White" FontWeight="Bold" BorderThickness="0" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.CanContentScroll="False" FontFamily="Arial">
Expand Down
Loading

0 comments on commit 2655e09

Please sign in to comment.