/
W3GameControl.vb
62 lines (54 loc) · 2.59 KB
/
W3GameControl.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Namespace WC3
'Verification disabled because of many warnings in generated code
<ContractVerification(False)>
Public Class W3GameControl
Private ReadOnly inQueue As CallQueue = MakeControlCallQueue(Me)
Private ReadOnly _manager As WC3.GameManager
Private ReadOnly _game As WC3.Game
Private ReadOnly _hooks As New List(Of IDisposable)
<ContractInvariantMethod()> Private Sub ObjectInvariant()
Contract.Invariant(inQueue IsNot Nothing)
Contract.Invariant(_manager IsNot Nothing)
Contract.Invariant(_game IsNot Nothing)
Contract.Invariant(_hooks IsNot Nothing)
End Sub
Private Shadows Sub OnDisposed() Handles Me.Disposed
For Each hook In _hooks
Contract.Assume(hook IsNot Nothing)
hook.Dispose()
Next hook
End Sub
Private Sub OnCommand(sender As CommandControl, argument As String) Handles comGame.IssuedCommand
Contract.Requires(argument IsNot Nothing)
Tinker.Components.UIInvokeCommand(_manager, argument)
End Sub
Public Sub New(manager As WC3.GameManager)
Contract.Assert(manager IsNot Nothing)
InitializeComponent()
Me._manager = manager
Me._game = manager.Game
logGame.SetGame(_game)
AddHandler _game.Updated, AddressOf OnGameUpdated
_hooks.Add(New DelegatedDisposable(Sub() RemoveHandler _game.Updated, AddressOf OnGameUpdated))
_game.QueueThrowUpdated()
End Sub
Private Sub txtInput_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtInput.KeyPress
If e.KeyChar <> Microsoft.VisualBasic.ChrW(Keys.Enter) Then Return
If txtInput.Text = "" Then Return
_game.QueueBroadcastMessage(txtInput.Text)
txtInput.Text = ""
e.Handled = True
End Sub
Private Async Sub OnGameUpdated(sender As WC3.Game, slots As SlotSet)
Contract.Assume(sender IsNot Nothing)
Contract.Assume(slots IsNot Nothing)
Dim descriptions = Await TaskEx.WhenAll(From slot In slots Select slot.AsyncGenerateDescription)
inQueue.QueueAction(Sub()
If IsDisposed Then Return
For Each i In descriptions.Length.Range
lstSlots.Items(i) = descriptions(i)
Next i
End Sub)
End Sub
End Class
End Namespace