Add 'Leave Match' button
This commit is contained in:
parent
fc634d033e
commit
5ef17e8353
5 changed files with 66 additions and 20 deletions
|
@ -1,6 +1,6 @@
|
|||
1.0.3:
|
||||
- Add connect button
|
||||
- Support touch input
|
||||
- Add touch input support
|
||||
- Change layout based on portrait or landscape view
|
||||
- Automatically refresh match listings
|
||||
- Automatically reconnect
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"code.rocket9labs.com/tslocum/bgammon"
|
||||
"code.rocket9labs.com/tslocum/etk"
|
||||
"code.rocketnine.space/tslocum/messeji"
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
||||
|
@ -71,6 +72,9 @@ type board struct {
|
|||
showKeyboardButton *etk.Button
|
||||
frame *etk.Frame
|
||||
|
||||
leaveGameGrid *etk.Grid
|
||||
confirmLeaveGameFrame *etk.Frame
|
||||
|
||||
fontFace font.Face
|
||||
lineHeight int
|
||||
lineOffset int
|
||||
|
@ -94,17 +98,33 @@ func NewBoard() *board {
|
|||
gameState: &bgammon.GameState{
|
||||
Game: bgammon.NewGame(),
|
||||
},
|
||||
spaceHighlight: ebiten.NewImage(1, 1),
|
||||
inputGrid: etk.NewGrid(),
|
||||
frame: etk.NewFrame(),
|
||||
fontFace: mediumFont,
|
||||
Mutex: &sync.Mutex{},
|
||||
spaceHighlight: ebiten.NewImage(1, 1),
|
||||
inputGrid: etk.NewGrid(),
|
||||
frame: etk.NewFrame(),
|
||||
confirmLeaveGameFrame: etk.NewFrame(),
|
||||
fontFace: mediumFont,
|
||||
Mutex: &sync.Mutex{},
|
||||
}
|
||||
b.fontUpdated()
|
||||
|
||||
{
|
||||
leaveGameLabel := etk.NewText("Leave match?")
|
||||
leaveGameLabel.SetHorizontal(messeji.AlignCenter)
|
||||
|
||||
b.leaveGameGrid = etk.NewGrid()
|
||||
b.leaveGameGrid.SetBackground(color.RGBA{40, 24, 9, 255})
|
||||
b.leaveGameGrid.AddChildAt(leaveGameLabel, 0, 0, 2, 1)
|
||||
b.leaveGameGrid.AddChildAt(etk.NewButton("No", b.cancelLeaveGame), 0, 1, 1, 1)
|
||||
b.leaveGameGrid.AddChildAt(etk.NewButton("Yes", b.confirmLeaveGame), 1, 1, 1, 1)
|
||||
b.leaveGameGrid.SetVisible(false)
|
||||
}
|
||||
|
||||
leaveGameButton := etk.NewButton("Leave Match", b.leaveGame)
|
||||
b.showKeyboardButton = etk.NewButton("Show Keyboard", b.toggleKeyboard)
|
||||
b.inputGrid.AddChildAt(b.showKeyboardButton, 0, 0, 1, 1)
|
||||
b.inputGrid.AddChildAt(leaveGameButton, 0, 0, 1, 1)
|
||||
b.inputGrid.AddChildAt(b.showKeyboardButton, 1, 0, 1, 1)
|
||||
b.frame.AddChild(b.inputGrid)
|
||||
b.frame.AddChild(b.leaveGameGrid)
|
||||
|
||||
b.buttons = []*boardButton{
|
||||
{
|
||||
|
@ -155,6 +175,21 @@ func (b *board) setKeyboardRect() {
|
|||
game.keyboard.SetRect(0, game.screenH/2, game.screenW, (game.screenH - game.screenH/2 - heightOffset))
|
||||
}
|
||||
|
||||
func (b *board) cancelLeaveGame() error {
|
||||
b.leaveGameGrid.SetVisible(false)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *board) confirmLeaveGame() error {
|
||||
b.Client.Out <- []byte("leave")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *board) leaveGame() error {
|
||||
b.leaveGameGrid.SetVisible(true)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *board) toggleKeyboard() error {
|
||||
if game.keyboard.Visible() {
|
||||
game.keyboard.Hide()
|
||||
|
@ -764,6 +799,10 @@ func (b *board) setRect(x, y, w, h int) {
|
|||
b.updateBackgroundImage()
|
||||
b.processState()
|
||||
|
||||
dialogWidth := 400
|
||||
dialogHeight := 100
|
||||
b.leaveGameGrid.SetRect(image.Rect(game.screenW/2-dialogWidth/2, game.screenH/2-dialogHeight/2, game.screenW/2+dialogWidth/2, game.screenH/2+dialogHeight/2))
|
||||
|
||||
if viewBoard && game.keyboard.Visible() {
|
||||
b.setKeyboardRect()
|
||||
}
|
||||
|
|
15
game/game.go
15
game/game.go
|
@ -331,6 +331,8 @@ func setViewBoard(view bool) {
|
|||
} else {
|
||||
game.setRoot(game.lobby.frame)
|
||||
}
|
||||
|
||||
game.Board.leaveGameGrid.SetVisible(false)
|
||||
}
|
||||
game.updateStatusBufferPosition()
|
||||
|
||||
|
@ -1139,14 +1141,19 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
|||
statusBufferRect = image.Rect(x, y, x+w, y+h/2-bufferPaddingY/2)
|
||||
g.updateStatusBufferPosition()
|
||||
|
||||
gameBuffer.SetRect(image.Rect(x, y+h/2+bufferPaddingX, x+w, y+h))
|
||||
gameBufferY1 := y + h
|
||||
|
||||
y1 := g.screenH - bufferPaddingX - inputBufferHeight
|
||||
if game.TouchInput {
|
||||
w = w / 2
|
||||
g.Board.inputGrid.SetRect(image.Rect(x+w+bufferPaddingX, g.screenH-bufferPaddingX-inputBufferHeight, g.screenW-bufferPaddingX, g.screenH-bufferPaddingY))
|
||||
gameBufferY1 = gameBufferY1 - inputBufferHeight
|
||||
|
||||
g.Board.inputGrid.SetRect(image.Rect(x, y1, g.screenW-bufferPaddingX, g.screenH-bufferPaddingY))
|
||||
y1 = y1 - inputBufferHeight - bufferPaddingX
|
||||
}
|
||||
x1 := x + w
|
||||
inputBuffer.SetRect(image.Rect(x, g.screenH-bufferPaddingX-inputBufferHeight, x1, g.screenH-bufferPaddingY))
|
||||
inputBuffer.SetRect(image.Rect(x, y1, x1, y1+inputBufferHeight))
|
||||
|
||||
gameBuffer.SetRect(image.Rect(x, y+h/2+bufferPaddingX, x+w, gameBufferY1))
|
||||
}
|
||||
|
||||
g.lobby.showKeyboardButton.SetVisible(g.TouchInput)
|
||||
|
|
6
go.mod
6
go.mod
|
@ -3,15 +3,15 @@ module code.rocket9labs.com/tslocum/boxcars
|
|||
go 1.17
|
||||
|
||||
require (
|
||||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231023071513-07e9c3dc1e6a
|
||||
code.rocket9labs.com/tslocum/etk v0.0.0-20231025023538-7515991afce8
|
||||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231025044036-bd2cb2c880a8
|
||||
code.rocket9labs.com/tslocum/etk v0.0.0-20231026035119-af162c64b6d1
|
||||
code.rocketnine.space/tslocum/kibodo v1.0.2-0.20231024233002-77bb43ba6fe8
|
||||
code.rocketnine.space/tslocum/messeji v1.0.5-0.20231025021922-5c431f2514b3
|
||||
github.com/hajimehoshi/ebiten/v2 v2.6.2
|
||||
github.com/llgcode/draw2d v0.0.0-20231022063514-1acb54133d2a
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
golang.org/x/image v0.13.0
|
||||
nhooyr.io/websocket v1.8.9
|
||||
nhooyr.io/websocket v1.8.10
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
12
go.sum
12
go.sum
|
@ -1,7 +1,7 @@
|
|||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231023071513-07e9c3dc1e6a h1:gUrDw8cVAWMFgjHZsiwPNj7Dl8TSe/3uoFJQOGO8haE=
|
||||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231023071513-07e9c3dc1e6a/go.mod h1:LS/m5Zq7/93dP8XJrLkL1T5ZTwtddkN8X9TyRrrdCkQ=
|
||||
code.rocket9labs.com/tslocum/etk v0.0.0-20231025023538-7515991afce8 h1:KaQxBj2aEEoExMDVO6Tr4XpHG4ywJY6L+r17zegmaLM=
|
||||
code.rocket9labs.com/tslocum/etk v0.0.0-20231025023538-7515991afce8/go.mod h1:rJ62XnzCl3crN13IBnA1j7xR9Hji/CIO4vcy9wX2zZY=
|
||||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231025044036-bd2cb2c880a8 h1:HIimtfAQSX5oikw9GaBjeWUZsH7Gk5ylDABRNN0OI/I=
|
||||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231025044036-bd2cb2c880a8/go.mod h1:LS/m5Zq7/93dP8XJrLkL1T5ZTwtddkN8X9TyRrrdCkQ=
|
||||
code.rocket9labs.com/tslocum/etk v0.0.0-20231026035119-af162c64b6d1 h1:3RAYiLwFGkMPDrV4GQjTmKmQfZHdbgOjdPan0tn5AWc=
|
||||
code.rocket9labs.com/tslocum/etk v0.0.0-20231026035119-af162c64b6d1/go.mod h1:rJ62XnzCl3crN13IBnA1j7xR9Hji/CIO4vcy9wX2zZY=
|
||||
code.rocketnine.space/tslocum/kibodo v1.0.2-0.20231024233002-77bb43ba6fe8 h1:i1NzTMQA1DAAUIpFh2bnHVnH5j9hUkG6F3tqzsdD16Y=
|
||||
code.rocketnine.space/tslocum/kibodo v1.0.2-0.20231024233002-77bb43ba6fe8/go.mod h1:C7M1NUuVi0Mv+/xraUurjl4XSLRIILmWDWCBBOY4UeM=
|
||||
code.rocketnine.space/tslocum/messeji v1.0.5-0.20231025021922-5c431f2514b3 h1:eSfyZjG9rgzOZALpEQWF/cCz5DpM0w2ZhVh+tSIOLkc=
|
||||
|
@ -32,5 +32,5 @@ golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
|||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
nhooyr.io/websocket v1.8.9 h1:+U/9DCNIH1XnzrWKs7yZp4jO0e/m6mUEh2kRPKRQYeg=
|
||||
nhooyr.io/websocket v1.8.9/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=
|
||||
nhooyr.io/websocket v1.8.10 h1:mv4p+MnGrLDcPlBoWsvPP7XCzTYMXP9F9eIGoKbgx7Q=
|
||||
nhooyr.io/websocket v1.8.10/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=
|
||||
|
|
Loading…
Reference in a new issue