Display match duration and current time when viewing board

This commit is contained in:
Trevor Slocum 2023-11-02 15:03:05 -07:00
parent 9009d2d734
commit 276335af9a
5 changed files with 106 additions and 13 deletions

View file

@ -1,3 +1,6 @@
1.0.8:
- Display match duration and current time when viewing board
1.0.7:
- Optimize user interface for mobile devices

View file

@ -73,6 +73,9 @@ type board struct {
opponentLabel *Label
playerLabel *Label
timerLabel *etk.Text
clockLabel *etk.Text
inputGrid *etk.Grid
showKeyboardButton *etk.Button
uiGrid *etk.Grid
@ -119,7 +122,6 @@ func NewBoard() *board {
fontFace: mediumFont,
Mutex: &sync.Mutex{},
}
b.fontUpdated()
b.bearOffOverlay = etk.NewButton(gotext.Get("Drag here to bear off"), func() error {
return nil
@ -141,11 +143,41 @@ func NewBoard() *board {
b.showKeyboardButton = etk.NewButton(gotext.Get("Show Keyboard"), b.toggleKeyboard)
b.recreateInputGrid()
b.uiGrid.AddChildAt(statusBuffer, 0, 0, 1, 1)
timerLabel := etk.NewText("0:00")
timerLabel.SetForegroundColor(triangleA)
timerLabel.SetScrollBarVisible(false)
timerLabel.SetSingleLine(true)
timerLabel.TextField.SetHorizontal(messeji.AlignCenter)
timerLabel.TextField.SetVertical(messeji.AlignCenter)
b.timerLabel = timerLabel
clockLabel := etk.NewText("12:00")
clockLabel.SetForegroundColor(triangleA)
clockLabel.SetScrollBarVisible(false)
clockLabel.SetSingleLine(true)
clockLabel.TextField.SetHorizontal(messeji.AlignCenter)
clockLabel.TextField.SetVertical(messeji.AlignCenter)
b.clockLabel = clockLabel
btn := etk.NewButton("Settings", func() error {
return nil
})
btn.Label.SetFont(smallFont)
mockUp := etk.NewGrid()
mockUp.AddChildAt(b.timerLabel, 0, 0, 1, 1)
mockUp.AddChildAt(b.clockLabel, 1, 0, 1, 1)
if !AutoEnableTouchInput {
mockUp.AddChildAt(btn, 2, 0, 1, 1)
}
b.uiGrid.AddChildAt(mockUp, 0, 0, 1, 1)
b.uiGrid.AddChildAt(etk.NewBox(), 0, 1, 1, 1)
b.uiGrid.AddChildAt(gameBuffer, 0, 2, 1, 1)
b.uiGrid.AddChildAt(statusBuffer, 0, 2, 1, 1)
b.uiGrid.AddChildAt(etk.NewBox(), 0, 3, 1, 1)
b.uiGrid.AddChildAt(b.inputGrid, 0, 4, 1, 1)
b.uiGrid.AddChildAt(gameBuffer, 0, 4, 1, 1)
b.uiGrid.AddChildAt(etk.NewBox(), 0, 5, 1, 1)
b.uiGrid.AddChildAt(b.inputGrid, 0, 6, 1, 1)
b.frame.AddChild(b.opponentLabel)
b.frame.AddChild(b.playerLabel)
@ -153,6 +185,8 @@ func NewBoard() *board {
b.frame.AddChild(b.bearOffOverlay)
b.frame.AddChild(b.leaveGameGrid)
b.fontUpdated()
b.buttons = []*boardButton{
{
label: gotext.Get("Roll"),
@ -192,6 +226,9 @@ func (b *board) fontUpdated() {
statusBuffer.SetFont(b.fontFace)
gameBuffer.SetFont(b.fontFace)
inputBuffer.Field.SetFont(b.fontFace)
b.timerLabel.SetFont(b.fontFace)
b.clockLabel.SetFont(b.fontFace)
}
func (b *board) recreateInputGrid() {
@ -206,8 +243,8 @@ func (b *board) recreateInputGrid() {
b.inputGrid.AddChildAt(etk.NewBox(), 0, 1, 2, 1)
leaveGameButton := etk.NewButton(gotext.Get("Leave Match"), b.leaveGame)
b.inputGrid.AddChildAt(leaveGameButton, 0, 2, 1, 1)
showMenuButton := etk.NewButton(gotext.Get("Menu"), b.showMenu)
b.inputGrid.AddChildAt(showMenuButton, 0, 2, 1, 1)
b.inputGrid.AddChildAt(b.showKeyboardButton, 1, 2, 1, 1)
b.inputGrid.SetRowSizes(52, int(b.horizontalBorderSize/2), -1)
@ -241,6 +278,12 @@ func (b *board) leaveGame() error {
return nil
}
func (b *board) showMenu() error {
//b.menuGrid.SetVisible(true)
// TODO
return nil
}
func (b *board) toggleKeyboard() error {
if game.keyboard.Visible() {
game.keyboard.Hide()
@ -822,7 +865,11 @@ func (b *board) setRect(x, y, w, h int) {
if game.TouchInput {
inputAndButtons = 52 + int(b.horizontalBorderSize) + game.scale(56)
}
b.uiGrid.SetRowSizes(-1, int(b.horizontalBorderSize/2), -1, int(b.horizontalBorderSize/2), int(inputAndButtons))
matchStatus := 36
if game.scaleFactor >= 1.25 {
matchStatus = 44
}
b.uiGrid.SetRowSizes(matchStatus, int(b.horizontalBorderSize/2), -1, int(b.horizontalBorderSize/2), -1, int(b.horizontalBorderSize/2), int(inputAndButtons))
{
dialogWidth := game.scale(400)

View file

@ -771,11 +771,54 @@ func NewGame() *Game {
etk.SetFocus(g.connectUsername)
go g.handleAutoRefresh()
go g.handleUpdateTimeLabels()
scheduleFrame()
return g
}
func (g *Game) handleUpdateTimeLabels() {
lastTimerHour, lastTimerMinute := -1, -1
lastClockHour, lastClockMinute := -1, -1
t := time.NewTicker(3 * time.Second)
var now time.Time
var d time.Duration
var h, m int
for {
now = time.Now()
// Update match timer.
started := g.Board.gameState.Started
if started.IsZero() {
h, m = 0, 0
} else {
ended := g.Board.gameState.Ended
if ended.IsZero() {
d = now.Sub(started)
} else {
d = ended.Sub(started)
}
h, m = int(d.Hours()), int(d.Minutes())
}
if h != lastTimerHour || m != lastTimerMinute {
g.Board.timerLabel.SetText(fmt.Sprintf("%d:%02d", h, m))
lastTimerHour, lastTimerMinute = h, m
scheduleFrame()
}
// Update clock.
h, m = now.Hour(), now.Minute()
if h != lastClockHour || m != lastClockMinute {
g.Board.clockLabel.SetText(fmt.Sprintf("%d:%02d", h, m))
lastClockHour, lastClockMinute = h, m
scheduleFrame()
}
<-t.C
}
}
func (g *Game) setRoot(w etk.Widget) {
if w != g.Board.frame {
g.rootWidget = w

4
go.mod
View file

@ -3,8 +3,8 @@ module code.rocket9labs.com/tslocum/boxcars
go 1.17
require (
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231102061536-171948e21ccd
code.rocket9labs.com/tslocum/etk v0.0.0-20231102191253-148902fb8d97
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231102214836-522663becc48
code.rocket9labs.com/tslocum/etk v0.0.0-20231102195906-c2c9a228d0aa
code.rocketnine.space/tslocum/kibodo v1.0.2-0.20231102011532-8d3f420207ad
code.rocketnine.space/tslocum/messeji v1.0.5-0.20231102191237-a6fd28a6b52d
github.com/hajimehoshi/ebiten/v2 v2.6.2

8
go.sum
View file

@ -1,7 +1,7 @@
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231102061536-171948e21ccd h1:8gxRh8eJ+NmYZ1UKhH2uUS0DKX1uTSJNVM3ouCv5Un0=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231102061536-171948e21ccd/go.mod h1:U8qo60VHGzKFUHLZZJcvT0yDzwWybJBabsCw3Lyqx4s=
code.rocket9labs.com/tslocum/etk v0.0.0-20231102191253-148902fb8d97 h1:kxP7l0BUh/FAp4kXDX9bXd8SWRV/zm06aoLOq/QOB2c=
code.rocket9labs.com/tslocum/etk v0.0.0-20231102191253-148902fb8d97/go.mod h1:LkiMYCUwPC1JYD/K1G67XoJUDpgzcdvw8O9+vQiCXrU=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231102214836-522663becc48 h1:kZSLjFfPd/ur0/VEaMx5NZQCl8bsnl8Dx/WdF6dcHeA=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231102214836-522663becc48/go.mod h1:U8qo60VHGzKFUHLZZJcvT0yDzwWybJBabsCw3Lyqx4s=
code.rocket9labs.com/tslocum/etk v0.0.0-20231102195906-c2c9a228d0aa h1:twbOyuAP8EdcCz7mDJyj9adN557Qvwn4XdTwOMPtj8Q=
code.rocket9labs.com/tslocum/etk v0.0.0-20231102195906-c2c9a228d0aa/go.mod h1:LkiMYCUwPC1JYD/K1G67XoJUDpgzcdvw8O9+vQiCXrU=
code.rocketnine.space/tslocum/kibodo v1.0.2-0.20231102011532-8d3f420207ad h1:Iyk7JYRCov59+XeIQQbZJMN6VWag007Ro1j5hziuSGw=
code.rocketnine.space/tslocum/kibodo v1.0.2-0.20231102011532-8d3f420207ad/go.mod h1:C7M1NUuVi0Mv+/xraUurjl4XSLRIILmWDWCBBOY4UeM=
code.rocketnine.space/tslocum/messeji v1.0.5-0.20231102191237-a6fd28a6b52d h1:+/yDwjXqp7aKxDEYAKmWJfGNO7uOeo0nraj4aL8zUfQ=