-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWMEventViewModel.vb
198 lines (169 loc) · 6.91 KB
/
WMEventViewModel.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
Imports System.ComponentModel
Imports PGSwiss.Data
Public Class WMEventViewModel
Inherits BaseViewModel
Implements INotifyPropertyChanged
Public Overrides Sub Load(FileName As String)
_WMEvent = New doWMEvent(FileName)
OnPropertyChanged("Title")
End Sub
Private Shared _SingletonInstance As WMEventViewModel
Public Shared Function GetSingleton() As WMEventViewModel
If _SingletonInstance Is Nothing Then
_SingletonInstance = New WMEventViewModel
End If
Return _SingletonInstance
End Function
Private _CurrentProgress As Integer
Public Property CurrentProgress As Integer
Get
Return _CurrentProgress
End Get
Set(value As Integer)
_CurrentProgress = value
OnPropertyChanged("CurrentProgress")
End Set
End Property
Private Sub New()
Factions.load()
Metas.load()
AllPlayers.load()
Formats.load()
Sizes.load()
End Sub
Private WithEvents _WMEvent As doWMEvent
Public Property WMEvent As doWMEvent
Get
Return _WMEvent
End Get
Set(value As doWMEvent)
_WMEvent = value
End Set
End Property
Public Property Factions As New doFactionCollection
Public Property AllPlayers As New doPlayerCollection
Public Property Metas As New doMetaCollection
Public Property Formats As New doEventFormatCollection
Public Property Sizes As New doRoundSizeCollection
Private _CurrentRound As doRound
Public Property CurrentRound As doRound
Get
Return _CurrentRound
End Get
Set(value As doRound)
_CurrentRound = value
OnPropertyChanged("CurrentRound")
End Set
End Property
Private _LastRoundRetrieved As Integer
Private _LastGamesCountRetrived As Integer
Private _cachedRoundPlayers As List(Of doPlayer)
Public ReadOnly Property CurrentRoundPlayers As List(Of doPlayer)
Get
If _LastRoundRetrieved <> _CurrentRound.RoundNumber OrElse _LastGamesCountRetrived <> (From p In _CurrentRound.Games Where p.Reported = True).Count Then
_cachedRoundPlayers = _CurrentRound.GetPlayers(_WMEvent)
_LastRoundRetrieved = _CurrentRound.RoundNumber
_LastGamesCountRetrived = (From p In _CurrentRound.Games Where p.Reported = True).Count
End If
Return _cachedRoundPlayers
End Get
End Property
Public Function PlayerOpponents(Player As doPlayer) As List(Of doPlayer)
Dim oReturn As New List(Of doPlayer)
For Each Round In WMEvent.Rounds
Dim game = (From p In Round.Games Where p.Player1.Name = Player.Name Or p.Player2.Name = Player.Name).FirstOrDefault
If Not game Is Nothing Then
If game.Player1.Name = Player.Name Then
If Not game.Player2 Is Nothing Then oReturn.Add(game.Player2)
Else
If Not game.Player1 Is Nothing Then oReturn.Add(game.Player1)
End If
End If
Next
Return oReturn
End Function
Public Function PlayerTables(Player As doPlayer) As List(Of Integer)
Dim ilReturn As New List(Of Integer)
For Each Round In WMEvent.Rounds
Dim game = (From p In Round.Games Where p.Player1.Name = Player.Name Or p.Player2.Name = Player.Name).FirstOrDefault
If Not game Is Nothing Then
ilReturn.Add(game.TableNumber)
End If
Next
Return ilReturn
End Function
Private _CurrentGame As doGame
Public Property CurrentGame As doGame
Get
Return _CurrentGame
End Get
Set(value As doGame)
_CurrentGame = value
OnPropertyChanged("CurrentGame")
End Set
End Property
Public ReadOnly Property Title As String
Get
Dim sReturn As String = "PG Swiss"
If _WMEvent IsNot Nothing Then sReturn = _WMEvent.Name
Return sReturn
End Get
End Property
Public Overrides Sub Save()
'intentionally not checking for null to force an error message if the save doesn't work
Me.WMEvent.PGSwissVersion = My.Application.Info.Version.ToString
Me.WMEvent.Save()
For Each p As doPlayer In WMEvent.Players
Dim q = From i In AllPlayers Where i.Name = p.Name
If q.Count = 0 Then AllPlayers.Add(p)
Next
Factions.Save()
Metas.Save()
AllPlayers.Save()
Formats.Save()
Sizes.Save()
End Sub
Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
' Create the OnPropertyChanged method to raise the event
Protected Sub OnPropertyChanged(ByVal name As String)
If name <> "IsDirty" AndAlso name <> "PreviousButtonVisibility" AndAlso name <> "NextButtonVisibility" Then
PGSwiss.Data.DirtyMonitor.IsDirty = True
End If
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name))
End Sub
Private Sub _WMEvent_PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Handles _WMEvent.PropertyChanged
If e.PropertyName = "Name" Then
OnPropertyChanged("Title")
End If
End Sub
Private WithEvents _DirtyMonitor As PGSwiss.Data.DirtyMonitor = PGSwiss.Data.DirtyMonitor.GetSingleton
Public Sub IsDirtyChange() Handles _DirtyMonitor.PropertyChanged
NotifyButtonVisibilityChange()
End Sub
Public Sub NotifyButtonVisibilityChange()
OnPropertyChanged("PreviousButtonVisibility")
OnPropertyChanged("NextButtonVisibility")
OnPropertyChanged("IsDirty")
End Sub
Public ReadOnly Property PreviousButtonVisibility As Visibility
Get
Dim vReturn As Visibility = Visibility.Collapsed
If BaseController.CurrentController.PreviousEnabled Then vReturn = Visibility.Visible
Return vReturn
End Get
End Property
Public ReadOnly Property NextButtonVisibility As Visibility
Get
Dim vReturn As Visibility = Visibility.Collapsed
If BaseController.CurrentController.NextEnabled Then vReturn = Visibility.Visible
Return vReturn
End Get
End Property
Public ReadOnly Property IsDirty As System.Windows.Media.Brush
Get
Dim bReturn As New SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0))
If PGSwiss.Data.DirtyMonitor.IsDirty Then bReturn = New SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 0, 220, 255))
Return bReturn
End Get
End Property
End Class