Auto-scale player name, pip count and rating labels
This commit is contained in:
parent
81a5c9d8b0
commit
6b9ace890b
7 changed files with 27 additions and 16 deletions
|
@ -1,3 +1,6 @@
|
|||
1.4.0:
|
||||
- Auto-scale font size to fit text
|
||||
|
||||
1.3.9:
|
||||
- Add shadow behind player rating labels
|
||||
- Add brackets around timestamps in message log
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"log"
|
||||
"math"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
@ -273,6 +272,9 @@ func NewBoard() *board {
|
|||
b.opponentPipCount.SetHorizontal(etk.AlignEnd)
|
||||
b.playerPipCount.SetHorizontal(etk.AlignStart)
|
||||
|
||||
b.opponentPipCount.SetAutoResize(true)
|
||||
b.playerPipCount.SetAutoResize(true)
|
||||
|
||||
b.opponentRatingLabel.SetForeground(color.RGBA{255, 255, 255, 255})
|
||||
b.playerRatingLabel.SetForeground(color.RGBA{0, 0, 0, 255})
|
||||
|
||||
|
@ -1166,8 +1168,6 @@ func (b *board) updateBackgroundImage() {
|
|||
}
|
||||
|
||||
// Draw space numbers.
|
||||
fontMutex.Lock()
|
||||
defer fontMutex.Unlock()
|
||||
|
||||
ff := etk.FontFace(etk.Style.TextFont, etk.Scale(b.fontSize))
|
||||
|
||||
|
@ -1192,7 +1192,9 @@ func (b *board) updateBackgroundImage() {
|
|||
if b.bottomRow(int8(space)) {
|
||||
y = b.h - int(b.verticalBorderSize)
|
||||
}
|
||||
fontMutex.Lock()
|
||||
text.Draw(b.backgroundImage, sp, ff, x, y+(int(b.verticalBorderSize)-b.lineHeight)/2+b.lineOffset, spaceLabelColor)
|
||||
fontMutex.Unlock()
|
||||
}
|
||||
|
||||
// Draw profile icons.
|
||||
|
@ -1375,9 +1377,9 @@ func (b *board) Draw(screen *ebiten.Image) {
|
|||
labelColor = color.RGBA{0, 0, 0, 255}
|
||||
}
|
||||
|
||||
fontMutex.Lock()
|
||||
bounds := etk.BoundString(ff, overlayText)
|
||||
overlayImage := ebiten.NewImage(bounds.Dx()*2, bounds.Dy()*2)
|
||||
fontMutex.Lock()
|
||||
text.Draw(overlayImage, overlayText, ff, 0, bounds.Dy(), labelColor)
|
||||
fontMutex.Unlock()
|
||||
|
||||
|
@ -1769,9 +1771,12 @@ func (b *board) updateOpponentLabel() {
|
|||
label.active = b.gameState.Turn == player.Number
|
||||
label.Text.SetForeground(label.activeColor)
|
||||
|
||||
fontMutex.Lock()
|
||||
bounds := etk.BoundString(etk.FontFace(etk.Style.TextFont, etk.Scale(largeFontSize)), text)
|
||||
fontMutex.Unlock()
|
||||
|
||||
maxWidth := int(b.spaceWidth)*3 - label.Padding()*2
|
||||
if bounds.Dx() > maxWidth {
|
||||
bounds.Max.X = bounds.Min.X + maxWidth
|
||||
}
|
||||
|
||||
padding := 13
|
||||
innerCenter := b.innerBoardCenter(false)
|
||||
|
@ -1848,9 +1853,12 @@ func (b *board) updatePlayerLabel() {
|
|||
label.active = b.gameState.Turn == player.Number
|
||||
label.Text.SetForeground(label.activeColor)
|
||||
|
||||
fontMutex.Lock()
|
||||
bounds := etk.BoundString(etk.FontFace(etk.Style.TextFont, etk.Scale(largeFontSize)), text)
|
||||
defer fontMutex.Unlock()
|
||||
|
||||
maxWidth := int(b.spaceWidth)*3 - label.Padding()*2
|
||||
if bounds.Dx() > maxWidth {
|
||||
bounds.Max.X = bounds.Min.X + maxWidth
|
||||
}
|
||||
|
||||
padding := 13
|
||||
innerCenter := b.innerBoardCenter(true)
|
||||
|
@ -2455,8 +2463,7 @@ func (b *board) _movePiece(sprite *Sprite, from int8, to int8, speed int8, pause
|
|||
func (b *board) movePiece(from int8, to int8, pause bool) {
|
||||
pieces := b.spaceSprites[from]
|
||||
if len(pieces) == 0 {
|
||||
log.Printf("ERROR: NO SPRITE FOR MOVE %d/%d", from, to)
|
||||
return
|
||||
return // No sprite available.
|
||||
}
|
||||
|
||||
sprite := pieces[len(pieces)-1]
|
||||
|
|
|
@ -22,11 +22,13 @@ func (b *board) createRatingLabels() {
|
|||
o.SetVertical(etk.AlignStart)
|
||||
o.SetScrollBarVisible(false)
|
||||
o.SetFont(etk.Style.TextFont, etk.Scale(mediumFontSize))
|
||||
o.SetAutoResize(true)
|
||||
|
||||
p.SetHorizontal(etk.AlignCenter)
|
||||
p.SetVertical(etk.AlignEnd)
|
||||
p.SetScrollBarVisible(false)
|
||||
p.SetFont(etk.Style.TextFont, etk.Scale(mediumFontSize))
|
||||
p.SetAutoResize(true)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ func NewLabel(c color.RGBA) *Label {
|
|||
l.Text.SetSingleLine(true)
|
||||
l.Text.SetHorizontal(etk.AlignCenter)
|
||||
l.Text.SetVertical(etk.AlignCenter)
|
||||
l.Text.SetAutoResize(true)
|
||||
return l
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
version = "v1.3.9"
|
||||
version = "v1.3.9p1"
|
||||
baseButtonHeight = 54
|
||||
MaxDebug = 2
|
||||
DefaultServerAddress = "wss://ws.bgammon.org"
|
||||
|
@ -2850,9 +2850,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
|||
g.lastResize = time.Now()
|
||||
scheduleFrame()
|
||||
|
||||
fontMutex.Lock()
|
||||
g.bufferWidth = etk.BoundString(etk.FontFace(etk.Style.TextFont, etk.Scale(g.Board.fontSize)), strings.Repeat("A", bufferCharacterWidth)).Dx()
|
||||
fontMutex.Unlock()
|
||||
if g.bufferWidth > int(float64(g.screenW)*maxStatusWidthRatio) {
|
||||
g.bufferWidth = int(float64(g.screenW) * maxStatusWidthRatio)
|
||||
}
|
||||
|
|
2
go.mod
2
go.mod
|
@ -5,7 +5,7 @@ go 1.19
|
|||
require (
|
||||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240821181107-92a9180ed2bb
|
||||
code.rocket9labs.com/tslocum/bgammon-bei-bot v0.0.0-20240818174413-cf737ec690f0
|
||||
code.rocket9labs.com/tslocum/etk v0.0.0-20240822064305-4c67a3c44828
|
||||
code.rocket9labs.com/tslocum/etk v0.0.0-20240823205827-89ca46044662
|
||||
code.rocket9labs.com/tslocum/gotext v0.0.0-20240728181248-46f419ff143b
|
||||
code.rocket9labs.com/tslocum/tabula v0.0.0-20240820025521-91065b63f1be
|
||||
github.com/coder/websocket v1.8.12
|
||||
|
|
4
go.sum
4
go.sum
|
@ -4,8 +4,8 @@ code.rocket9labs.com/tslocum/bgammon v0.0.0-20240821181107-92a9180ed2bb h1:njGjS
|
|||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240821181107-92a9180ed2bb/go.mod h1:1wuDH6u2P1SDyyiIDukWOOn0rMcPmsX25a4InIEJYKE=
|
||||
code.rocket9labs.com/tslocum/bgammon-bei-bot v0.0.0-20240818174413-cf737ec690f0 h1:MeEnIjVhdIpdEk+ptkjHtFpSUdVfVMNXYn3TQbU88S0=
|
||||
code.rocket9labs.com/tslocum/bgammon-bei-bot v0.0.0-20240818174413-cf737ec690f0/go.mod h1:FnwPHs0cPAZE7GaJycLrzvx2QKI+Ad4X17q27GmOFh4=
|
||||
code.rocket9labs.com/tslocum/etk v0.0.0-20240822064305-4c67a3c44828 h1:gMagdmiA9d5BEE1qbELhTrYEq5o4n3iPc3pLmnZQ5ws=
|
||||
code.rocket9labs.com/tslocum/etk v0.0.0-20240822064305-4c67a3c44828/go.mod h1:WTYQVskJCspF+9TW7F0iX9BhSagQ6GHk+tmiFkftc1A=
|
||||
code.rocket9labs.com/tslocum/etk v0.0.0-20240823205827-89ca46044662 h1:+KLhLLtQDtItfIlZlDQJxoBYaWvcR0Q70uvfkUQ+1uc=
|
||||
code.rocket9labs.com/tslocum/etk v0.0.0-20240823205827-89ca46044662/go.mod h1:WTYQVskJCspF+9TW7F0iX9BhSagQ6GHk+tmiFkftc1A=
|
||||
code.rocket9labs.com/tslocum/gotext v0.0.0-20240728181248-46f419ff143b h1:KSdR7VPoftY5Bt+osGRBbtHlCWxhe1QbOuf58CG7ieI=
|
||||
code.rocket9labs.com/tslocum/gotext v0.0.0-20240728181248-46f419ff143b/go.mod h1:ZkYZ/IF/ebzhUL2bNp4ALROsuH9iCztUWvUJBWsHXRU=
|
||||
code.rocket9labs.com/tslocum/tabula v0.0.0-20240820025521-91065b63f1be h1:awgpl3vS+d7vciw7X5z+joGSPZHB1OOTpkPKW3mPGDs=
|
||||
|
|
Loading…
Reference in a new issue