Add connect button
This commit is contained in:
parent
1c92d69374
commit
3cd7e3d44e
5 changed files with 43 additions and 64 deletions
|
@ -1,3 +1,6 @@
|
|||
1.0.3:
|
||||
- Add connect button
|
||||
|
||||
1.0.2:
|
||||
- Allow specifying match points
|
||||
- Add doubling cube
|
||||
|
|
81
game/game.go
81
game/game.go
|
@ -16,7 +16,7 @@ import (
|
|||
"time"
|
||||
|
||||
"code.rocket9labs.com/tslocum/bgammon"
|
||||
"code.rocketnine.space/tslocum/etk"
|
||||
"code.rocket9labs.com/tslocum/etk"
|
||||
"code.rocketnine.space/tslocum/kibodo"
|
||||
"code.rocketnine.space/tslocum/messeji"
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
|
@ -413,34 +413,43 @@ func NewGame() *Game {
|
|||
etk.Style.TextColorDark = triangleA
|
||||
etk.Style.InputBgColor = color.RGBA{40, 24, 9, 255}
|
||||
|
||||
etk.Style.ButtonTextColor = color.RGBA{0, 0, 0, 255}
|
||||
etk.Style.ButtonBgColor = color.RGBA{225, 188, 125, 255}
|
||||
|
||||
{
|
||||
headerLabel := etk.NewText("Welcome to bgammon.org")
|
||||
nameLabel := etk.NewText("Username")
|
||||
passwordLabel := etk.NewText("Password")
|
||||
|
||||
infoLabel := etk.NewText("To log in as a guest, enter a username (if you want) and do not enter a password. Press Enter to log in.")
|
||||
connectButton := etk.NewButton("Connect", func() error {
|
||||
g.Username = g.connectUsername.Text()
|
||||
g.Password = g.connectPassword.Text()
|
||||
g.Connect()
|
||||
return nil
|
||||
})
|
||||
|
||||
infoLabel := etk.NewText("To log in as a guest, enter a username (if you want) and do not enter a password.")
|
||||
|
||||
g.connectUsername = etk.NewInput("", "", func(text string) (handled bool) {
|
||||
return false
|
||||
})
|
||||
g.connectUsername.Field.SetHandleKeyboard(true)
|
||||
|
||||
g.connectPassword = etk.NewInput("", "", func(text string) (handled bool) {
|
||||
return false
|
||||
})
|
||||
g.connectPassword.Field.SetHandleKeyboard(false)
|
||||
|
||||
grid := etk.NewGrid()
|
||||
grid.SetColumnPadding(int(g.Board.horizontalBorderSize / 2))
|
||||
grid.SetRowPadding(20)
|
||||
grid.SetColumnSizes(10, 200)
|
||||
grid.SetRowSizes(60, 50, 50)
|
||||
grid.SetRowSizes(60, 50, 50, 75)
|
||||
grid.AddChildAt(headerLabel, 0, 0, 3, 1)
|
||||
grid.AddChildAt(nameLabel, 1, 1, 1, 1)
|
||||
grid.AddChildAt(g.connectUsername, 2, 1, 1, 1)
|
||||
grid.AddChildAt(passwordLabel, 1, 2, 1, 1)
|
||||
grid.AddChildAt(g.connectPassword, 2, 2, 1, 1)
|
||||
grid.AddChildAt(infoLabel, 0, 3, 3, 1)
|
||||
grid.AddChildAt(connectButton, 2, 3, 1, 1)
|
||||
grid.AddChildAt(infoLabel, 1, 4, 2, 1)
|
||||
connectGrid = grid
|
||||
}
|
||||
|
||||
|
@ -453,17 +462,14 @@ func NewGame() *Game {
|
|||
g.lobby.createGameName = etk.NewInput("", "", func(text string) (handled bool) {
|
||||
return false
|
||||
})
|
||||
g.lobby.createGameName.Field.SetHandleKeyboard(true)
|
||||
|
||||
g.lobby.createGamePoints = etk.NewInput("", "", func(text string) (handled bool) {
|
||||
return false
|
||||
})
|
||||
g.lobby.createGamePoints.Field.SetHandleKeyboard(false)
|
||||
|
||||
g.lobby.createGamePassword = etk.NewInput("", "", func(text string) (handled bool) {
|
||||
return false
|
||||
})
|
||||
g.lobby.createGamePassword.Field.SetHandleKeyboard(false)
|
||||
|
||||
grid := etk.NewGrid()
|
||||
grid.SetColumnPadding(int(g.Board.horizontalBorderSize / 2))
|
||||
|
@ -488,7 +494,6 @@ func NewGame() *Game {
|
|||
g.lobby.joinGamePassword = etk.NewInput("", "", func(text string) (handled bool) {
|
||||
return false
|
||||
})
|
||||
g.lobby.joinGamePassword.Field.SetHandleKeyboard(true)
|
||||
|
||||
grid := etk.NewGrid()
|
||||
grid.SetColumnPadding(int(g.Board.horizontalBorderSize / 2))
|
||||
|
@ -502,6 +507,7 @@ func NewGame() *Game {
|
|||
}
|
||||
|
||||
etk.SetRoot(connectGrid)
|
||||
etk.SetFocus(g.connectUsername)
|
||||
|
||||
return g
|
||||
}
|
||||
|
@ -637,6 +643,9 @@ func (g *Game) handleEvents() {
|
|||
}
|
||||
|
||||
func (g *Game) Connect() {
|
||||
if g.loggedIn {
|
||||
return
|
||||
}
|
||||
g.loggedIn = true
|
||||
|
||||
l(fmt.Sprintf("*** Connecting..."))
|
||||
|
@ -733,15 +742,9 @@ func (g *Game) Update() error {
|
|||
|
||||
if connectFocusPassword != lastFocus {
|
||||
if connectFocusPassword {
|
||||
g.connectUsername.Field.SetHandleKeyboard(false)
|
||||
g.connectUsername.Field.SetSuffix("")
|
||||
g.connectPassword.Field.SetHandleKeyboard(true)
|
||||
g.connectPassword.Field.SetSuffix("_")
|
||||
etk.SetFocus(g.connectPassword)
|
||||
} else {
|
||||
g.connectUsername.Field.SetHandleKeyboard(true)
|
||||
g.connectUsername.Field.SetSuffix("_")
|
||||
g.connectPassword.Field.SetHandleKeyboard(false)
|
||||
g.connectPassword.Field.SetSuffix("")
|
||||
etk.SetFocus(g.connectUsername)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -779,28 +782,13 @@ func (g *Game) Update() error {
|
|||
p := image.Point{cx, cy}
|
||||
if p.In(g.lobby.createGameName.Rect()) {
|
||||
g.lobby.createGameFocus = 0
|
||||
g.lobby.createGameName.Field.SetHandleKeyboard(true)
|
||||
g.lobby.createGameName.Field.SetSuffix("_")
|
||||
g.lobby.createGamePoints.Field.SetHandleKeyboard(false)
|
||||
g.lobby.createGamePoints.Field.SetSuffix("")
|
||||
g.lobby.createGamePassword.Field.SetHandleKeyboard(false)
|
||||
g.lobby.createGamePassword.Field.SetSuffix("")
|
||||
etk.SetFocus(g.lobby.createGameName)
|
||||
} else if p.In(g.lobby.createGamePoints.Rect()) {
|
||||
g.lobby.createGameFocus = 1
|
||||
g.lobby.createGameName.Field.SetHandleKeyboard(false)
|
||||
g.lobby.createGameName.Field.SetSuffix("")
|
||||
g.lobby.createGamePoints.Field.SetHandleKeyboard(true)
|
||||
g.lobby.createGamePoints.Field.SetSuffix("_")
|
||||
g.lobby.createGamePassword.Field.SetHandleKeyboard(false)
|
||||
g.lobby.createGamePassword.Field.SetSuffix("")
|
||||
etk.SetFocus(g.lobby.createGamePoints)
|
||||
} else if p.In(g.lobby.createGamePassword.Rect()) {
|
||||
g.lobby.createGameFocus = 2
|
||||
g.lobby.createGameName.Field.SetHandleKeyboard(false)
|
||||
g.lobby.createGameName.Field.SetSuffix("")
|
||||
g.lobby.createGamePoints.Field.SetHandleKeyboard(false)
|
||||
g.lobby.createGamePoints.Field.SetSuffix("")
|
||||
g.lobby.createGamePassword.Field.SetHandleKeyboard(true)
|
||||
g.lobby.createGamePassword.Field.SetSuffix("_")
|
||||
etk.SetFocus(g.lobby.createGamePassword)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -818,26 +806,11 @@ func (g *Game) Update() error {
|
|||
}
|
||||
|
||||
if g.lobby.createGameFocus == 0 {
|
||||
g.lobby.createGameName.Field.SetHandleKeyboard(true)
|
||||
g.lobby.createGameName.Field.SetSuffix("_")
|
||||
g.lobby.createGamePoints.Field.SetHandleKeyboard(false)
|
||||
g.lobby.createGamePoints.Field.SetSuffix("")
|
||||
g.lobby.createGamePassword.Field.SetHandleKeyboard(false)
|
||||
g.lobby.createGamePassword.Field.SetSuffix("")
|
||||
etk.SetFocus(g.lobby.createGameName)
|
||||
} else if g.lobby.createGameFocus == 1 {
|
||||
g.lobby.createGameName.Field.SetHandleKeyboard(false)
|
||||
g.lobby.createGameName.Field.SetSuffix("")
|
||||
g.lobby.createGamePoints.Field.SetHandleKeyboard(true)
|
||||
g.lobby.createGamePoints.Field.SetSuffix("_")
|
||||
g.lobby.createGamePassword.Field.SetHandleKeyboard(false)
|
||||
g.lobby.createGamePassword.Field.SetSuffix("")
|
||||
etk.SetFocus(g.lobby.createGamePoints)
|
||||
} else {
|
||||
g.lobby.createGameName.Field.SetHandleKeyboard(false)
|
||||
g.lobby.createGameName.Field.SetSuffix("")
|
||||
g.lobby.createGamePoints.Field.SetHandleKeyboard(false)
|
||||
g.lobby.createGamePoints.Field.SetSuffix("")
|
||||
g.lobby.createGamePassword.Field.SetHandleKeyboard(true)
|
||||
g.lobby.createGamePassword.Field.SetSuffix("_")
|
||||
etk.SetFocus(g.lobby.createGamePassword)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"time"
|
||||
|
||||
"code.rocket9labs.com/tslocum/bgammon"
|
||||
"code.rocketnine.space/tslocum/etk"
|
||||
"code.rocket9labs.com/tslocum/etk"
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
||||
"github.com/hajimehoshi/ebiten/v2/text"
|
||||
|
@ -367,6 +367,7 @@ func (l *lobby) click(x, y int) {
|
|||
case lobbyButtonCreate:
|
||||
l.showCreateGame = true
|
||||
etk.SetRoot(createGameGrid)
|
||||
etk.SetFocus(l.createGameName)
|
||||
namePlural := l.c.Username
|
||||
lastLetter := namePlural[len(namePlural)-1]
|
||||
if lastLetter == 's' || lastLetter == 'S' {
|
||||
|
@ -394,6 +395,7 @@ func (l *lobby) click(x, y int) {
|
|||
if l.games[l.selected].Password {
|
||||
l.showJoinGame = true
|
||||
etk.SetRoot(joinGameGrid)
|
||||
etk.SetFocus(l.joinGamePassword)
|
||||
l.joinGameLabel.SetText(fmt.Sprintf("Join match: %s", l.games[l.selected].Name))
|
||||
l.joinGamePassword.Field.SetText("")
|
||||
l.joinGameID = l.games[l.selected].ID
|
||||
|
@ -419,6 +421,7 @@ func (l *lobby) click(x, y int) {
|
|||
if entry.Password {
|
||||
l.showJoinGame = true
|
||||
etk.SetRoot(joinGameGrid)
|
||||
etk.SetFocus(l.joinGamePassword)
|
||||
l.joinGameLabel.SetText(fmt.Sprintf("Join match: %s", entry.Name))
|
||||
l.joinGamePassword.Field.SetText("")
|
||||
l.joinGameID = entry.ID
|
||||
|
|
6
go.mod
6
go.mod
|
@ -3,10 +3,10 @@ module code.rocket9labs.com/tslocum/boxcars
|
|||
go 1.17
|
||||
|
||||
require (
|
||||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231020212418-70d2ccb39b35
|
||||
code.rocketnine.space/tslocum/etk v0.0.0-20230930052629-6c8d555b7d99
|
||||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231020215337-c4aa14d514fb
|
||||
code.rocket9labs.com/tslocum/etk v0.0.0-20231021231204-5c6a4b870885
|
||||
code.rocketnine.space/tslocum/kibodo v1.0.0
|
||||
code.rocketnine.space/tslocum/messeji v1.0.4-0.20230929042029-6dd617c348a7
|
||||
code.rocketnine.space/tslocum/messeji v1.0.4-0.20231021230727-3fa5b72a505d
|
||||
github.com/hajimehoshi/ebiten/v2 v2.6.2
|
||||
github.com/llgcode/draw2d v0.0.0-20230723155556-e595d7c7e75e
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
|
|
12
go.sum
12
go.sum
|
@ -1,11 +1,11 @@
|
|||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231020212418-70d2ccb39b35 h1:vmnNgvmS3EUOxN8h9jrrmBKQORKjFZZI3B79lSl62tk=
|
||||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231020212418-70d2ccb39b35/go.mod h1:LS/m5Zq7/93dP8XJrLkL1T5ZTwtddkN8X9TyRrrdCkQ=
|
||||
code.rocketnine.space/tslocum/etk v0.0.0-20230930052629-6c8d555b7d99 h1:mpNRo6zUdHlpZnxiqfF/1ZoiC1SBvnfAYPVbNpZjWfU=
|
||||
code.rocketnine.space/tslocum/etk v0.0.0-20230930052629-6c8d555b7d99/go.mod h1:WmeSEakGsdgM/dmfUbEQrL5ueFAdoozlwCVUOz8j1mg=
|
||||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231020215337-c4aa14d514fb h1:vw+4pXdMl2adEW65pJYf0cMO+VFPkoKe2LPku33eaa4=
|
||||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231020215337-c4aa14d514fb/go.mod h1:LS/m5Zq7/93dP8XJrLkL1T5ZTwtddkN8X9TyRrrdCkQ=
|
||||
code.rocket9labs.com/tslocum/etk v0.0.0-20231021231204-5c6a4b870885 h1:KiyE1E5er4D3lnuFnJsetnGkkec4UbSiFZd48XlIwT8=
|
||||
code.rocket9labs.com/tslocum/etk v0.0.0-20231021231204-5c6a4b870885/go.mod h1:JgdDn5bbIGwLYkngQK5CrRd7XfJe3h+K+YfAxvXW2mg=
|
||||
code.rocketnine.space/tslocum/kibodo v1.0.0 h1:/xs59UCuo+NGs89ABilARlowQnmIsjbNVjss57W5O7k=
|
||||
code.rocketnine.space/tslocum/kibodo v1.0.0/go.mod h1:xYmBfho98sIbB+Gtf8SU5GDQD9HOSqOtZ64eZnlHmRI=
|
||||
code.rocketnine.space/tslocum/messeji v1.0.4-0.20230929042029-6dd617c348a7 h1:XpXCx/kAO2SMTpPDzPWMTuzPUFJRD/t+I25yfHyGX8Y=
|
||||
code.rocketnine.space/tslocum/messeji v1.0.4-0.20230929042029-6dd617c348a7/go.mod h1:0bn7Ansm3z51Auw2TmHr2q3g0vjuUxLr3RcXnZfQA+Q=
|
||||
code.rocketnine.space/tslocum/messeji v1.0.4-0.20231021230727-3fa5b72a505d h1:YawBCDIsfoAE7JGhHiUC4FVw99W9I3/AnubzfOG5nAQ=
|
||||
code.rocketnine.space/tslocum/messeji v1.0.4-0.20231021230727-3fa5b72a505d/go.mod h1:xszLyTZtpyjCVaGmznizLSAlnvraPOSoanlzUBeqGco=
|
||||
github.com/ebitengine/purego v0.5.0 h1:JrMGKfRIAM4/QVKaesIIT7m/UVjTj5GYhRSQYwfVdpo=
|
||||
github.com/ebitengine/purego v0.5.0/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||
|
|
Loading…
Reference in a new issue