Skip to content

Commit

Permalink
rankdetection: fix Overlay.IsRankConvered(), less flickering
Browse files Browse the repository at this point in the history
- lowered MaxRankDetectionTries
- tries count always incremented, but only checked if the overlay would flicker.
- friendslist message only shows up if max tries is not exceeded.
  • Loading branch information
Alexander Zeier committed Dec 9, 2015
1 parent 24c9b8b commit 39df2c3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
31 changes: 20 additions & 11 deletions Hearthstone Deck Tracker/GameEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,32 +279,40 @@ public async void TurnStart(ActivePlayer player, int turnNumber)

private bool _rankDetectionRunning;
private int _rankDetectionTries;
private const int MaxRankDetectionTries = 3;
private int _rankDetectionOverlayToggles;
private const int MaxRankDetectionTries = 2;

private async void DetectRanks()
{
if(_rankDetectionTries >= MaxRankDetectionTries)
{
Logger.WriteLine(string.Format("Exceeded max rank detection tries ({0}). Gamemode must be casual.", MaxRankDetectionTries),
"GameEventHandler");
}
if(_rankDetectionRunning)
return;
_rankDetectionRunning = true;
Logger.WriteLine(string.Format("Trying to detect ranks... (overlay toggles: {0})", _rankDetectionTries), "GameEventHandler");
Logger.WriteLine(string.Format("Trying to detect ranks... (tries={0}, overlaytoggles={1})", _rankDetectionTries, _rankDetectionOverlayToggles), "GameEventHandler");
var rect = Helper.GetHearthstoneRect(true);
var reEnableOverlay = false;
if(Core.Overlay.IsRankConvered())
{
//only increment rank detection tries if the users can tell it's happening (overlay flickering)
_rankDetectionTries++;
if(_rankDetectionTries >= MaxRankDetectionTries)
{
Logger.WriteLine(string.Format("Not toggling overlay, exceeded max rank detection tries ({0}).", MaxRankDetectionTries),
"GameEventHandler");
_rankDetectionRunning = false;
return;
}
_rankDetectionOverlayToggles++;
Logger.WriteLine("Toggling overlay...", "GameEventHandler");
Core.Overlay.ShowOverlay(false);
reEnableOverlay = true;
}
while(await Helper.FriendsListOpen())
Core.Overlay.ShowFriendsListWarning(true);
Core.Overlay.ShowFriendsListWarning(false);
{
//silently wait for friendslist to close
if(_rankDetectionTries >= MaxRankDetectionTries)
await Task.Delay(300);
else
Core.Overlay.ShowFriendsListWarning(true);
}
Core.Overlay.ShowFriendsListWarning(false);
var capture = Helper.CaptureHearthstone(new Point(0, 0), rect.Width / 3, rect.Height);
if(reEnableOverlay)
Core.Overlay.ShowOverlay(true);
Expand All @@ -325,6 +333,7 @@ private async void DetectRanks()
}
else
Logger.WriteLine("No ranks were detected.", "GameEventHandler");
_rankDetectionTries++;
_rankDetectionRunning = false;
}

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 @@ -1393,10 +1393,10 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName

private const double RankCoveredMaxLeft = 0.1;
private const double PlayerRankCoveredMaxHeight = 0.8;
private const double OpponentRankCoveredMaxTop = 0.8;
private const double OpponentRankCoveredMaxTop = 0.12;
public bool IsRankConvered()
{
if(Canvas.GetLeft(StackPanelPlayer) < RankCoveredMaxLeft * Height)
if(Canvas.GetLeft(StackPanelPlayer) < RankCoveredMaxLeft * Width)
{
if(Canvas.GetTop(StackPanelPlayer) + StackPanelPlayer.ActualHeight > PlayerRankCoveredMaxHeight * Height)
{
Expand All @@ -1409,7 +1409,7 @@ public bool IsRankConvered()
return true;
}
}
if(Canvas.GetLeft(StackPanelOpponent) < RankCoveredMaxLeft * Height)
if(Canvas.GetLeft(StackPanelOpponent) < RankCoveredMaxLeft * Width)
{
if(Canvas.GetTop(StackPanelOpponent) + StackPanelOpponent.ActualHeight > PlayerRankCoveredMaxHeight * Height)
{
Expand Down

0 comments on commit 39df2c3

Please sign in to comment.