Skip to content

Commit

Permalink
Added popup notifications to overlay
Browse files Browse the repository at this point in the history
* Removed old status text display and replaced it with a non-persistent
notification
* Fixed bugs
  • Loading branch information
topher-au committed Aug 27, 2015
1 parent 88b36da commit 106636c
Show file tree
Hide file tree
Showing 13 changed files with 331 additions and 155 deletions.
10 changes: 6 additions & 4 deletions HDT-Voice/HDT-Voice.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
<Import Include="System.Threading.Tasks" />
</ItemGroup>
<ItemGroup>
<Compile Include="HDTGrammarEngine.vb" />
<Compile Include="HDTMouse.vb" />
<Compile Include="HDTVoice\HDTGrammarEngine.vb" />
<Compile Include="HDTVoice\HDTMouse.vb" />
<Compile Include="HDTPlugin\configMain.xaml.vb">
<DependentUpon>configMain.xaml</DependentUpon>
</Compile>
Expand All @@ -95,7 +95,8 @@
</Compile>
<Compile Include="HDTPlugin\Github.vb" />
<Compile Include="HDTPlugin\HDTVoicePlugin.vb" />
<Compile Include="HDTVoice.vb" />
<Compile Include="HDTVoice\HDTPopup.vb" />
<Compile Include="HDTVoice\HDTVoice.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
Expand All @@ -122,6 +123,7 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="Resources\app.config" />
<None Include="My Project\Application.myapp">
<Generator>MyApplicationCodeGenerator</Generator>
<LastGenOutput>Application.Designer.vb</LastGenOutput>
Expand All @@ -143,7 +145,7 @@
</Page>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="Resources\packages.config" />
<None Include="Resources\recognizedsound.wav" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
Expand Down
2 changes: 1 addition & 1 deletion HDT-Voice/HDTPlugin/HDTVoicePlugin.vb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Imports MahApps.Metro.Controls
Public Class HDTVoicePlugin
Implements IPlugin

Public Shared PluginVersion As New Version(0, 7, 3)
Public Shared PluginVersion As New Version(0, 7, 4)

Private createdSettings As Boolean = False
Private configRecog As configRecog
Expand Down
8 changes: 8 additions & 0 deletions HDT-Voice/HDTPlugin/configMain.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
<ListBoxItem Content="Bottom Right"/>
</ComboBox>
</DockPanel>
<DockPanel Margin="10">
<Label Content="Notification size" />
<ComboBox Name="comboNotificationSize" Width="120" HorizontalAlignment="Right">
<ListBoxItem Content="Small"/>
<ListBoxItem Content="Medium"/>
<ListBoxItem Content="Large"/>
</ComboBox>
</DockPanel>
<DockPanel Margin="10">
<CheckBox Name="checkSmoothMouse" Content="Enable smooth mouse movement" />
</DockPanel>
Expand Down
7 changes: 7 additions & 0 deletions HDT-Voice/HDTPlugin/configMain.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Public Class configMain
comboNotificationPos.SelectedIndex = My.Settings.intNotificationPos
AddHandler comboNotificationPos.SelectionChanged, AddressOf SaveSettings

comboNotificationSize.SelectedIndex = My.Settings.intNotificationSize
AddHandler comboNotificationSize.SelectionChanged, AddressOf SaveSettings

checkSmoothMouse.IsChecked = My.Settings.boolSmoothCursor
AddHandler checkSmoothMouse.Click, AddressOf SaveSettings

Expand All @@ -36,9 +39,13 @@ Public Class configMain
My.Settings.boolListenAtStartup = checkAutoStart.IsChecked
My.Settings.boolShowNotification = checkShowNotification.IsChecked
My.Settings.intNotificationPos = comboNotificationPos.SelectedIndex
My.Settings.intNotificationSize = comboNotificationSize.SelectedIndex
My.Settings.boolSmoothCursor = checkSmoothMouse.IsChecked
My.Settings.boolDebugLog = checkDebugLog.IsChecked
My.Settings.Save()

comboNotificationSize.IsEnabled = checkShowNotification.IsChecked
comboNotificationPos.IsEnabled = checkShowNotification.IsChecked
End Sub
Public Sub ClickUpdateButton()
Process.Start("https://www.github.com/topher-au/HDT-Voice/releases/latest")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ Public Class GrammarEngine
Public ReadOnly Property MenuGrammar As Grammar
Get
Dim menuChoices As New Choices
Dim menuBuilder As New GrammarBuilder

menuChoices.Add(New SemanticResultKey("menu", "play"))
menuChoices.Add(New SemanticResultKey("menu", "casual mode"))
Expand Down Expand Up @@ -267,9 +266,8 @@ Public Class GrammarEngine
Next
deckGrammar.Append(deckChoices)
menuChoices.Add(deckGrammar)
menuBuilder.Append(menuChoices)

Return New Grammar(menuBuilder)
Return New Grammar(menuChoices)
End Get
End Property
Public ReadOnly Property MulliganGrammar As Grammar
Expand Down
File renamed without changes.
125 changes: 125 additions & 0 deletions HDT-Voice/HDTVoice/HDTPopup.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
Imports System.Threading.Thread
Imports System.Windows.Controls
Imports System.Windows.Forms

Imports Hearthstone_Deck_Tracker
Imports Hearthstone_Deck_Tracker.API
Public Class HDTPopup
Private popupText As String
Private popupDuration As Integer
Private hdtCanvas As Canvas
Private boolFadeComplete As Boolean = False
Public Sub New(Text As String, Duration As Integer)
popupText = Text
popupDuration = Duration

hdtCanvas = Core.OverlayCanvas
' Invoke popup from main canvas
hdtCanvas.Dispatcher.Invoke(AddressOf InvokePopup)
End Sub
Private Sub InvokePopup()
'Spawn backgroundworker to avoid blocking HDT thread

hdtCanvas.Dispatcher.Invoke(Sub()
Dim fadeWorker As New System.ComponentModel.BackgroundWorker
AddHandler fadeWorker.DoWork, AddressOf DoPopup
fadeWorker.RunWorkerAsync()
End Sub)
End Sub
Private Function CreatePopupCanvas(Text As String) As Canvas
Dim canvasPopup As New Canvas
canvasPopup.Tag = "HDTVoicePopup"

'Create text and add to popup
Dim htbPopupText As New HearthstoneTextBlock
Select Case My.Settings.intNotificationSize
Case 0
htbPopupText.FontSize = 12
Case 1
htbPopupText.FontSize = 16
Case 2
htbPopupText.FontSize = 22
End Select
hdtCanvas.Children.Add(canvasPopup)
htbPopupText.Text = Text
Canvas.SetZIndex(htbPopupText, 1)
Canvas.SetLeft(htbPopupText, 10)
Canvas.SetTop(htbPopupText, 8)
htbPopupText.UpdateLayout()
canvasPopup.Children.Add(htbPopupText)
canvasPopup.UpdateLayout()


'Create background, size to text and add to popup
Dim rectPopupBG As New System.Windows.Shapes.Rectangle
rectPopupBG.RadiusX = 3
rectPopupBG.RadiusY = 10
rectPopupBG.Fill = New System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(110, 0, 0, 0))
rectPopupBG.Height = htbPopupText.RenderSize.Height + 16
rectPopupBG.Width = htbPopupText.RenderSize.Width + 20
canvasPopup.Children.Add(rectPopupBG)
canvasPopup.UpdateLayout()

Select Case My.Settings.intNotificationPos
Case 0 ' Top Left
Canvas.SetTop(canvasPopup, 16)
Canvas.SetLeft(canvasPopup, 16)
Case 1 ' Bottom Left
Canvas.SetTop(canvasPopup, hdtCanvas.ActualHeight * 0.93 - rectPopupBG.Height / 2)
Canvas.SetLeft(canvasPopup, 8)
Case 2 ' Top Right
Canvas.SetTop(canvasPopup, 16)
Canvas.SetLeft(canvasPopup, hdtCanvas.ActualWidth - rectPopupBG.ActualWidth - 16)
Case 3 ' Bottom Right
Canvas.SetTop(canvasPopup, hdtCanvas.ActualHeight * 0.93 - rectPopupBG.Height / 2)
Canvas.SetLeft(canvasPopup, hdtCanvas.ActualWidth - rectPopupBG.ActualWidth - 16)
End Select

Return canvasPopup
End Function
Private Sub FadeIn(Popup As Canvas)
hdtCanvas.Children.Add(Popup)
For i = 0 To 1 Step 0.1
Popup.Opacity = i
Application.DoEvents()
Sleep(10)
Next
End Sub
Private Sub FadeOut(Popup As Canvas)
For i = 1 To 0 Step -0.05
Popup.Opacity = i
Application.DoEvents()
Sleep(15)
Next
hdtCanvas.Children.Remove(Popup)
End Sub
Private Sub DoPopup()

Dim popupCanvas As Canvas = hdtCanvas.Dispatcher.Invoke(Function()
Return CreatePopupCanvas(popupText)
End Function)

hdtCanvas.Dispatcher.Invoke(Sub()
RemoveAllPopups()
FadeIn(popupCanvas)
End Sub)
Sleep(popupDuration)
hdtCanvas.Dispatcher.Invoke(Sub()
FadeOut(popupCanvas)
End Sub)
End Sub

Private Sub RemoveAllPopups()
Do
For Each child In hdtCanvas.Children
If TypeOf child Is Canvas Then
If child.Tag = "HDTVoicePopup" Then
hdtCanvas.Children.Remove(child)
Continue Do
End If
End If
Next
Exit Do
Loop
End Sub
End Class
Loading

0 comments on commit 106636c

Please sign in to comment.