-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.go
336 lines (306 loc) · 11.8 KB
/
ui.go
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
package main
import (
"fmt"
"log"
"net/url"
"strconv"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/aquilax/truncate"
)
func GameType(a fyne.App) *fyne.Window {
label := widget.NewLabel("Select Match Type")
label.TextStyle.Bold = true
label.Alignment = fyne.TextAlignCenter
win := a.NewWindow("KQB Scoreboard App")
IGLButton := widget.NewButton("BGL Match", func() {
log.Println("Selected BGL KQB Scoreboard")
content := BGLMatchSelection(win)
win.Resize(fyne.NewSize(660, 500))
win.SetContent(content)
})
CustomButton := widget.NewButton("Custom Match", func() {
log.Println("Selected Custom Match Type")
content := CustomTeamSelection(win)
win.Resize(fyne.NewSize(660, 500))
win.SetContent(content)
})
cont := container.NewVBox(label, IGLButton, CustomButton)
win.SetContent(cont)
win.Resize(fyne.NewSize(660, 500))
win.CenterOnScreen()
win.Show()
go CheckForUpdates(win)
return &win
}
func CustomTeamSelection(w fyne.Window) *fyne.Container {
label := widget.NewLabel("Enter Team Info")
label.Alignment = fyne.TextAlignCenter
label.TextStyle.Bold = true
blueInput := widget.NewEntry()
blueInput.SetPlaceHolder("Blue Team")
goldInput := widget.NewEntry()
goldInput.SetPlaceHolder("Gold Team")
// win := a.NewWindow("Enter Team Info")
options := make([]string, 10)
for i := 0; i < 10; i++ {
options[i] = strconv.Itoa(i)
}
var (
blueWinsInt int
goldWinsInt int
blueLossInt int
goldLossInt int
)
blueWins := widget.NewSelect(options, func(value string) {
log.Println("Select set to", value)
blueWinsInt, _ = strconv.Atoi(value)
})
blueLoss := widget.NewSelect(options, func(value string) {
log.Println("Select set to", value)
blueLossInt, _ = strconv.Atoi(value)
})
blueStandingsLabel := widget.NewLabel("Blue Wins-Losses")
goldWins := widget.NewSelect(options, func(value string) {
log.Println("Select set to", value)
goldWinsInt, _ = strconv.Atoi(value)
})
goldLoss := widget.NewSelect(options, func(value string) {
log.Println("Select set to", value)
goldLossInt, _ = strconv.Atoi(value)
})
goldStandingsLabel := widget.NewLabel("Blue Wins-Losses")
blueWLContainer := container.NewHBox(blueStandingsLabel, blueWins, blueLoss)
goldWLContainer := container.NewHBox(goldStandingsLabel, goldWins, goldLoss)
themeSelectLabel := widget.NewLabel("Select Theme")
themeSelect := widget.NewSelect(themes, func(theme string) {
selectedTheme = theme
})
themeSelect.SetSelected("default")
themeSelectContainer := container.NewHBox(themeSelectLabel, themeSelect)
saveButton := widget.NewButton("Start Scoreboard", func() {
log.Println("Scoreboard Starting")
blueTeam := Team{blueInput.Text, "avatar.png", 1, 1, Stats{0, 0, blueWinsInt, blueLossInt}}
goldTeam := Team{goldInput.Text, "avatar.png", 1, 1, Stats{0, 0, goldWinsInt, goldLossInt}}
s = Scoreboard{&blueTeam, &goldTeam, 0, 0, 0, 0, []ScoreboardSet{}}
StartScoreboard(w)
UpdateStaticRoute()
})
saveButton.Importance = widget.HighImportance
cont := container.NewVBox(label, blueInput, blueWLContainer, goldInput, goldWLContainer, themeSelectContainer, saveButton)
return cont
}
func BGLMatchSelection(w fyne.Window) *fyne.Container {
label := widget.NewLabel("Select Match Info")
label.Alignment = fyne.TextAlignCenter
label.TextStyle.Bold = true
blueLabel := widget.NewLabel("Blue Team")
goldLabel := widget.NewLabel("Gold Team")
blueTeamSelect := widget.NewSelect([]string{"Blue"}, func(val string) {})
goldTeamSelect := widget.NewSelect([]string{"Gold"}, func(val string) {})
blueTeamContainer := container.NewHBox(layout.NewSpacer(), blueLabel, blueTeamSelect, layout.NewSpacer())
goldTeamContainer := container.NewHBox(layout.NewSpacer(), goldLabel, goldTeamSelect, layout.NewSpacer())
themeSelectLabel := widget.NewLabel("Select Theme")
themeSelect := widget.NewSelect(themes, func(theme string) {
selectedTheme = theme
})
themeSelect.SetSelected("default")
themeSelectContainer := container.NewHBox(layout.NewSpacer(), themeSelectLabel, themeSelect, layout.NewSpacer())
// blueTeamSelect.Resize(fyne.NewSize(500, 100))
blueTeamContainer.Hide()
goldTeamContainer.Hide()
// ch := make(chan []Team)
ch := make(chan MatchMap)
w.SetContent(ProgressIndicator())
go GetMatchInfo(ch)
matchMap := <-ch
var blueTeam Team
var goldTeam Team
saveButton := widget.NewButton("Start Scoreboard", func() {
log.Println("Saved.")
s = Scoreboard{&blueTeam, &goldTeam, 0, 0, 0, 0, []ScoreboardSet{}}
// UpdateTeamLogo(&blueTeam)
// UpdateTeamLogo(&goldTeam)
StartScoreboard(w)
UpdateStaticRoute()
})
saveButton.Importance = widget.HighImportance
saveButton.Disable()
matchOptions := make([]string, 0)
for k, _ := range matchMap {
matchOptions = append(matchOptions, k)
}
matchLabel := widget.NewLabel("Select Match")
matchLabel.Alignment = fyne.TextAlignCenter
matchSelect := widget.NewSelect(matchOptions, func(value string) {
selectedMatchTeams := matchMap[value]
teamOptions := []string{selectedMatchTeams[0].Name, selectedMatchTeams[1].Name}
teamOptionsFormatted := make([]string, len(teamOptions))
for idx, opt := range teamOptions {
teamOptionsFormatted[idx] = formatTeamName(opt)
}
blueTeamSelect.Options = teamOptionsFormatted
blueTeamSelect.OnChanged = func(val string) {
idx := blueTeamSelect.SelectedIndex()
blueTeam = selectedMatchTeams[idx]
log.Println("Select blue team to", value)
if blueTeam.Name != "" && goldTeam.Name != "" {
saveButton.Enable()
}
}
goldTeamSelect.Options = teamOptionsFormatted
goldTeamSelect.OnChanged = func(val string) {
idx := goldTeamSelect.SelectedIndex()
goldTeam = selectedMatchTeams[idx]
log.Println("Select gold team to", value)
if blueTeam.Name != "" && goldTeam.Name != "" {
saveButton.Enable()
}
}
blueTeamContainer.Show()
goldTeamContainer.Show()
})
matchSelectContainer := container.NewHBox(layout.NewSpacer(), matchLabel, matchSelect, layout.NewSpacer())
container := container.NewVBox(label, matchSelectContainer, blueTeamContainer, goldTeamContainer, themeSelectContainer, saveButton)
return container
}
func ScoreboardContent(w fyne.Window, SetupEventHooks func(func())) *fyne.Container {
scoreboardLabel := widget.NewLabel("Scoreboard Controller")
scoreboardLabel.Alignment = fyne.TextAlignCenter
scoreboardLabel.TextStyle.Bold = true
blueLabel := widget.NewLabel(fmt.Sprintf("%s (Blue)", formatTeamName(s.Home.Name)))
blueLabel.Alignment = fyne.TextAlignCenter
goldLabel := widget.NewLabel(fmt.Sprintf("%s (Gold)", formatTeamName(s.Away.Name)))
goldLabel.Alignment = fyne.TextAlignCenter
mapsLabel := widget.NewLabel("Maps: ")
setsLabel := widget.NewLabel("Sets: ")
blueMaps := widget.NewLabel("0")
goldMaps := widget.NewLabel("0")
blueSets := widget.NewLabel("0")
goldSets := widget.NewLabel("0")
blueScoreboard := container.New(layout.NewFormLayout(), mapsLabel, blueMaps, setsLabel, blueSets)
goldScoreboard := container.New(layout.NewFormLayout(), mapsLabel, goldMaps, setsLabel, goldSets)
scoreboardContainer := container.New(layout.NewGridLayout(2), blueLabel, goldLabel, blueScoreboard, goldScoreboard)
RefreshScoreboardUI := func() {
blueMaps.Text = strconv.Itoa(s.HomeMaps)
blueSets.Text = strconv.Itoa(s.HomeGames)
goldMaps.Text = strconv.Itoa(s.AwayMaps)
goldSets.Text = strconv.Itoa(s.AwayGames)
scoreboardContainer.Refresh()
}
SetupEventHooks(RefreshScoreboardUI)
incrementBlue := widget.NewButtonWithIcon("Increment Blue", theme.ContentAddIcon(), func() {
s.IncrementHome()
UpdateScoreBoard(&s)
RefreshScoreboardUI()
})
incrementGold := widget.NewButtonWithIcon("Increment Gold", theme.ContentAddIcon(), func() {
s.IncrementAway()
UpdateScoreBoard(&s)
RefreshScoreboardUI()
})
decrementBlue := widget.NewButtonWithIcon("Decrement Blue", theme.ContentClearIcon(), func() {
s.DecrementHome()
UpdateScoreBoard(&s)
RefreshScoreboardUI()
})
decrementGold := widget.NewButtonWithIcon("Decrement Gold", theme.ContentClearIcon(), func() {
s.DecrementAway()
UpdateScoreBoard(&s)
RefreshScoreboardUI()
})
blueContainer := container.NewHBox(layout.NewSpacer(), incrementBlue, incrementGold, layout.NewSpacer())
goldContainer := container.NewHBox(layout.NewSpacer(), decrementBlue, decrementGold, layout.NewSpacer())
scoreboardURL, _ := url.Parse("http://localhost:8080/static/")
link := widget.NewHyperlink("Scoreboard", scoreboardURL)
link.Alignment = fyne.TextAlignCenter
resetButton := widget.NewButtonWithIcon("Reset", theme.DeleteIcon(), func() {
s.HomeMaps = 0
s.HomeGames = 0
s.AwayGames = 0
s.AwayMaps = 0
s.Sets = []ScoreboardSet{}
RefreshScoreboardUI()
UpdateScoreBoard(&s)
})
resetButtonContainer := container.NewHBox(layout.NewSpacer(), resetButton, layout.NewSpacer())
// starTimerButton := widget.NewButton("Start Timer", func() {
// UpdateTimer("StartTimer")
// })
// stopTimerButton := widget.NewButton("Stop Timer", func() {
// UpdateTimer("StopTimer")
// })
// resetTimerButton := widget.NewButton("Reset Timer", func() {
// UpdateTimer("ResetTimer")
// })
// hideTimerButton := widget.NewButton("Show/Hide Timer", func() {
// UpdateTimer("ToggleTimer")
// })
aboutButton := widget.NewButton("About", func() {
ShowAboutWindow()
})
aboutContainer := container.NewHBox(layout.NewSpacer(), aboutButton, layout.NewSpacer())
// timerContainer := container.NewHBox(layout.NewSpacer(), starTimerButton, stopTimerButton, resetTimerButton, hideTimerButton, layout.NewSpacer())
// container := container.NewVBox(scoreboardLabel, blueContainer, goldContainer, scoreboardContainer, resetButtonContainer, link, timerContainer, aboutContainer)
container := container.NewVBox(scoreboardLabel, blueContainer, goldContainer, scoreboardContainer, resetButtonContainer, link, aboutContainer)
return container
}
func StartScoreboard(w fyne.Window) {
w.Resize(fyne.NewSize(400, 500))
ScoreboardUIContainer := ScoreboardContent(w, AddScoreboardHotkeys)
w.SetContent(ScoreboardUIContainer)
}
func ProgressIndicator() *fyne.Container {
label := widget.NewLabel("Fetching data...")
label.Alignment = fyne.TextAlignCenter
label.TextStyle.Bold = true
infinite := widget.NewProgressBarInfinite()
container := container.NewVBox(label, infinite)
return container
}
func AboutPage() *fyne.Container {
label := widget.NewLabel("About KQB Scoreboard")
label.Alignment = fyne.TextAlignCenter
label.TextStyle.Bold = true
author := widget.NewLabel("Author: Prosive")
author.Alignment = fyne.TextAlignLeading
githubURL, _ := url.Parse("https://github.com/achhabra2/kqb-scoreboard")
githubWidget := widget.NewHyperlink("Github Repo", githubURL)
hotkeys := widget.NewLabel("Hotkeys: \n CTRL + Shift + R: Reset Timer \n CTRL + Shift + T: Toggle Timer Start / Stop \n CTRL + Shift + B: Increment Blue Wins \n CTRL + Shift + G: Increment Gold Wins")
hotkeys.Alignment = fyne.TextAlignLeading
container := container.NewVBox(label, author, githubWidget, hotkeys)
return container
}
func ShowAboutWindow() {
aboutWindow := FyneApp.NewWindow("About")
aboutWindow.SetContent(AboutPage())
aboutWindow.CenterOnScreen()
aboutWindow.Show()
}
func CheckForUpdates(w fyne.Window) {
shouldUpdate, latestVersion := checkForUpdate()
if shouldUpdate {
updateMessage := fmt.Sprintf("New Version Available, would you like to update to v%s", latestVersion)
confirmDialog := dialog.NewConfirm("Update Checker", updateMessage, func(action bool) {
if action {
log.Println("Update clicked")
updated := doSelfUpdate()
if updated {
updatedDialog := dialog.NewInformation("Update Status", "Update Succeeded, please restart", w)
updatedDialog.Show()
} else {
updatedDialog := dialog.NewInformation("Update Status", "Update Failed", w)
updatedDialog.Show()
}
}
}, w)
confirmDialog.Show()
}
}
func formatTeamName(name string) string {
return truncate.Truncate(name, 18, "...", truncate.PositionEnd)
}