Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonysegal committed Jul 4, 2021
1 parent 2369e95 commit 573b732
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<UserControl x:Class="Hearthstone_Deck_Tracker.Controls.Overlay.LinkOpponentDeckPanel"
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"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
xmlns:lex="http://wpflocalizeextension.codeplex.com"
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="HearthstoneDeckTracker"
lex:ResxLocalizationProvider.DefaultDictionary="Strings"
mc:Ignorable="d">
<Border Background="#23272A" BorderBrush="#141617" BorderThickness="1" CornerRadius="3" Margin="0,5,0,0" Visibility="{Binding LinkOpponentDeckVisibility, Mode=OneWay}" MaxWidth="352" MouseEnter="Border_MouseEnter" MouseLeave="Border_MouseLeave">
<Grid>
<StackPanel Margin="10">
<TextBlock Text="{lex:Loc LinkOpponentDeck_Panel_Title}" Foreground="White" FontSize="14" FontWeight="Bold"/>

<TextBlock Foreground="White" FontSize="14" TextWrapping="Wrap" Visibility="{Binding DescriptorVisibility, Mode=OneWay}" Margin="0 3 0 0" Opacity=".7">
<Run Text="{lex:Loc LinkOpponentDeck_Panel_Description}"/>
</TextBlock>

<Button Content="{lex:Loc LinkOpponentDeck_Panel_LinkDeckButton}" Margin="0 6 0 0"
Click="LinkOpponentDeck_Click" DockPanel.Dock="Right" />

<TextBlock FontSize="14" TextWrapping="Wrap" Margin="0 10 0 0" Visibility="{Binding LinkMessageVisibility}" Opacity=".7" HorizontalAlignment="Center">
<Hyperlink MouseDown="Hyperlink_MouseDown" CommandParameter="https://articles.hsreplay.net/2020/04/24/introducing-bobs-buddy/" Foreground="White">
<Run Text="Dismiss"/>
</Hyperlink>
</TextBlock>

<TextBlock Foreground="Red" FontSize="14" TextWrapping="Wrap" Visibility="{Binding ErrorMessageVisibility}" Margin="0 10 0 0" >
<Run Text="{Binding ErrorMessage, Mode=OneWay}"/>
</TextBlock>

</StackPanel>
</Grid>
</Border>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@

namespace Hearthstone_Deck_Tracker.Controls.Overlay
{
public partial class OpponentUpload : UserControl, INotifyPropertyChanged
public partial class LinkOpponentDeckPanel : UserControl, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

private OpponentUploadState _uploadState;
public OpponentUploadState UploadState
private LinkOpponentDeckState _linkOpponentDeckState;
public LinkOpponentDeckState LinkOpponentDeckState
{
get => _uploadState;
get => _linkOpponentDeckState;
set
{
_uploadState = value;
_linkOpponentDeckState = value;
OnPropertyChanged();
}
}

private Visibility _uploadVisibility = Visibility.Hidden;
public Visibility UploadVisibility
private Visibility _linkOpponentDeckVisibility = Visibility.Hidden;
public Visibility LinkOpponentDeckVisibilty
{
get => _uploadVisibility;
get => _linkOpponentDeckVisibility;
set
{
_uploadVisibility = value;
_linkOpponentDeckVisibility = value;
OnPropertyChanged();
}
}
Expand Down Expand Up @@ -61,7 +61,7 @@ public string ErrorMessage

private bool _mouseIsOver = false;

public string LinkMessage => OpponentUploadStateConverter.GetLinkMessage(_uploadState);
public string LinkMessage => LinkOpponentDeckStateConverter.GetLinkMessage(_linkOpponentDeckState);

public Visibility LinkMessageVisibility => !Config.Instance.SeenLinkOpponentDeck ? Visibility.Visible : Visibility.Collapsed;

Expand All @@ -73,7 +73,7 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

public OpponentUpload()
public LinkOpponentDeckPanel()
{
InitializeComponent();
}
Expand All @@ -90,14 +90,14 @@ private async void LinkOpponentDeck_Click(object sender, RoutedEventArgs e)
Player.KnownOpponentDeck = deck;
e.Handled = true;
Core.UpdateOpponentCards();
_uploadState = OpponentUploadState.InKnownDeckMode;
_linkOpponentDeckState = LinkOpponentDeckState.InKnownDeckMode;
}
else
_uploadState = OpponentUploadState.Error;
_linkOpponentDeckState = LinkOpponentDeckState.Error;
}
catch(Exception ex)
{
_uploadState = OpponentUploadState.Error;
_linkOpponentDeckState = LinkOpponentDeckState.Error;
_errorMessage = ex.Message;
OnPropertyChanged(ErrorMessage);
}
Expand All @@ -109,13 +109,13 @@ public void Hide(bool force = false)
{
if(force || !_mouseIsOver)
{
UploadVisibility = Visibility.Hidden;
_linkOpponentDeckVisibility = Visibility.Hidden;
}
}

public void Show()
{
UploadVisibility = Visibility.Visible;
_linkOpponentDeckVisibility = Visibility.Visible;
}

private void Border_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
Expand All @@ -141,7 +141,7 @@ private void Hyperlink_MouseDown(object sender, System.Windows.Input.MouseButton
{
Player.KnownOpponentDeck = null;
Core.UpdateOpponentCards();
_uploadState = OpponentUploadState.Initial;
_linkOpponentDeckState = LinkOpponentDeckState.Initial;
OnPropertyChanged(nameof(LinkMessage));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<UserControl x:Class="Hearthstone_Deck_Tracker.Controls.Overlay.OpponentUpload"
<UserControl x:Class="Hearthstone_Deck_Tracker.Controls.Overlay.LinkOpponentDeckPanel"
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"
Expand Down
1 change: 0 additions & 1 deletion Hearthstone Deck Tracker/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
using WPFLocalizeExtension.Engine;
using Hearthstone_Deck_Tracker.Utility.Assets;
using static Hearthstone_Deck_Tracker.Utility.RemoteConfig;
using Hearthstone_Deck_Tracker.Importing;

#endregion

Expand Down
10 changes: 5 additions & 5 deletions Hearthstone Deck Tracker/Hearthstone Deck Tracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@
<Compile Include="Controls\Overlay\BattlegroundsCardsGroup.xaml.cs">
<DependentUpon>BattlegroundsCardsGroup.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\Overlay\OpponentUpload.xaml.cs">
<DependentUpon>OpponentUpload.xaml</DependentUpon>
<Compile Include="Controls\Overlay\LinkOpponentDeckPanel.xaml.cs">
<DependentUpon>LinkOpponentDeckPanel.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\Overlay\MulliganPanel.xaml.cs">
<DependentUpon>MulliganPanel.xaml</DependentUpon>
Expand Down Expand Up @@ -355,7 +355,7 @@
<Compile Include="OpponentDeadForTracker.cs" />
<Compile Include="Utility\Assets\AssetDownloader.cs" />
<Compile Include="Utility\Assets\AssetDownloaders.cs" />
<Compile Include="Utility\OpponentUploadState.cs" />
<Compile Include="Utility\LinkOpponentDeckState.cs" />
<Compile Include="Utility\ComboBoxHelper.cs" />
<Compile Include="Utility\DataLoader.cs" />
<Compile Include="Utility\DelayedMouseOver.cs" />
Expand Down Expand Up @@ -406,7 +406,7 @@
<Compile Include="Utility\Shell32.cs" />
<Compile Include="Utility\Singleton.cs" />
<Compile Include="Utility\ScheduledTaskRunner.cs" />
<Compile Include="Utility\OpponentUploadStateConverter.cs" />
<Compile Include="Utility\LinkOpponentDeckStateConverter.cs" />
<Compile Include="Utility\Toasts\ToastControls\BattlegroundsToast.xaml.cs">
<DependentUpon>BattlegroundsToast.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -1043,7 +1043,7 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\Overlay\OpponentUpload.xaml">
<Page Include="Controls\Overlay\LinkOpponentDeckPanel.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Hearthstone_Deck_Tracker
{
public enum OpponentUploadState
public enum LinkOpponentDeckState
{
Initial,
Error,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Hearthstone_Deck_Tracker
{
internal static class OpponentUploadStateConverter
internal static class LinkOpponentDeckStateConverter
{
public static string GetLinkMessage(OpponentUploadState state)
public static string GetLinkMessage(LinkOpponentDeckState state)
{
if(!Config.Instance.SeenLinkOpponentDeck)
return "Dismiss";
switch(state)
{
case OpponentUploadState.InKnownDeckMode:
case LinkOpponentDeckState.InKnownDeckMode:
return "Clear Linked Deck";
}
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private void InitializeCollections()

_clickableElements.Add(BattlegroundsMinionsPanel.BgTierIcons);
_clickableElements.Add(HeroNotificationPanel);
_clickableElements.Add(OpponentUpload);
_clickableElements.Add(LinkOpponentDeckDisplay);
_clickableElements.Add(MulliganNotificationPanel);
_clickableElements.Add(BobsBuddyDisplay);

Expand Down
8 changes: 4 additions & 4 deletions Hearthstone Deck Tracker/Windows/OverlayWindow.Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,17 @@ private void UpdateElementPositions()
Canvas.SetTop(GridOpponentBoard, Height / 2 - GridOpponentBoard.ActualHeight - Height * 0.045);
Canvas.SetTop(GridPlayerBoard, Height / 2 - Height * 0.03);

Canvas.SetLeft(OpponentUpload, Width * Config.Instance.OpponentDeckLeft / 100);
Canvas.SetLeft(LinkOpponentDeckDisplay, Width * Config.Instance.OpponentDeckLeft / 100);

var OpponentStackVisibleHeight = CanvasOpponentCount.ActualHeight + CanvasOpponentChance.ActualHeight + ViewBoxOpponent.ActualHeight;

if(BorderStackPanelOpponentTop + OpponentStackVisibleHeight + 20 + OpponentUpload.ActualHeight < Height)
if(BorderStackPanelOpponentTop + OpponentStackVisibleHeight + 20 + LinkOpponentDeckDisplay.ActualHeight < Height)
{
Canvas.SetTop(OpponentUpload, BorderStackPanelOpponentTop + OpponentStackVisibleHeight + 20);
Canvas.SetTop(LinkOpponentDeckDisplay, BorderStackPanelOpponentTop + OpponentStackVisibleHeight + 20);
}
else
{
Canvas.SetTop(OpponentUpload, BorderStackPanelOpponentTop - OpponentUpload.ActualHeight - 20);
Canvas.SetTop(LinkOpponentDeckDisplay, BorderStackPanelOpponentTop - LinkOpponentDeckDisplay.ActualHeight - 20);
}

if (Config.Instance.ShowFlavorText)
Expand Down
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/Windows/OverlayWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<local:HearthstoneTextBlock x:Name="LblOpponentFatigue" FontSize="14" Text="" Margin="4,0,0,0" TextAlignment="Center"/>
</StackPanel>
</Border>
<overlay:OpponentUpload x:Name="OpponentUpload" Width="218"/>
<overlay:LinkOpponentDeckPanel x:Name="LinkOpponentDeckDisplay" Width="218"/>

<StackPanel Name="StackPanelSecrets" Width="auto" Height="auto" Visibility="Collapsed" />

Expand Down
6 changes: 3 additions & 3 deletions Hearthstone Deck Tracker/Windows/OverlayWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ internal void HideBgsTopBar()

internal void ShowOpponentUpload()
{
OpponentUpload.Show();
LinkOpponentDeckDisplay.Show();
}

internal void ShowBobsBuddyPanel()
Expand Down Expand Up @@ -437,12 +437,12 @@ internal void UpdateOpponentDeadForTurns(List<int> turns)

private void StackPanelOpponent_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
OpponentUpload.Show();
LinkOpponentDeckDisplay.Show();
}

private void StackPanelOpponent_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
OpponentUpload.Hide();
LinkOpponentDeckDisplay.Hide();
}
}
}

0 comments on commit 573b732

Please sign in to comment.