Allow muting individual sound effects

This commit is contained in:
Trevor Slocum 2024-07-22 15:34:27 -07:00
parent 1f651d9c92
commit 3d09bb09e1
6 changed files with 277 additions and 29 deletions

View file

@ -1,4 +1,5 @@
1.3.8:
- Allow muting individual sound effects
- Play sound when bearing off checker
1.3.7:

View file

@ -122,6 +122,13 @@ type board struct {
changePasswordNew *Input
changePasswordGrid *etk.Grid
muteJoinLeaveCheckbox *etk.Checkbox
muteChatCheckbox *etk.Checkbox
muteRollCheckbox *etk.Checkbox
muteMoveCheckbox *etk.Checkbox
muteBearOffCheckbox *etk.Checkbox
muteSoundsGrid *etk.Grid
highlightCheckbox *etk.Checkbox
showPipCountCheckbox *etk.Checkbox
showMovesCheckbox *etk.Checkbox
@ -157,6 +164,11 @@ type board struct {
flipBoard bool
traditional bool
advancedMovement bool
muteJoinLeave bool
muteChat bool
muteRoll bool
muteMove bool
muteBearOff bool
widget *BoardWidget
@ -217,6 +229,7 @@ func NewBoard() *board {
buttonsUndoOKGrid: etk.NewGrid(),
selectRollGrid: etk.NewGrid(),
menuGrid: etk.NewGrid(),
muteSoundsGrid: etk.NewGrid(),
accountGrid: etk.NewGrid(),
settingsGrid: etk.NewGrid(),
changePasswordGrid: etk.NewGrid(),
@ -350,6 +363,123 @@ func NewBoard() *board {
b.changePasswordGrid.SetVisible(false)
}
cGrid := func(checkbox *etk.Checkbox) *etk.Grid {
g := etk.NewGrid()
g.SetColumnSizes(7, -1)
g.AddChildAt(checkbox, 1, 0, 1, 1)
return g
}
{
headerLabel := etk.NewText(gotext.Get("Mute Sounds"))
headerLabel.SetHorizontal(etk.AlignCenter)
rowCount := 5
b.muteJoinLeaveCheckbox = etk.NewCheckbox(b.toggleMuteJoinLeave)
b.muteJoinLeaveCheckbox.SetBorderColor(triangleA)
b.muteJoinLeaveCheckbox.SetCheckColor(triangleA)
b.muteJoinLeaveCheckbox.SetSelected(b.muteJoinLeave)
muteJoinLeaveLabel := &ClickableText{
Text: etk.NewText(gotext.Get("Join/Leave")),
onSelected: func() {
b.muteJoinLeaveCheckbox.SetSelected(!b.muteJoinLeaveCheckbox.Selected())
b.toggleMuteJoinLeave()
},
}
muteJoinLeaveLabel.SetVertical(etk.AlignCenter)
b.muteChatCheckbox = etk.NewCheckbox(b.toggleMuteChat)
b.muteChatCheckbox.SetBorderColor(triangleA)
b.muteChatCheckbox.SetCheckColor(triangleA)
b.muteChatCheckbox.SetSelected(b.muteChat)
muteChatLabel := &ClickableText{
Text: etk.NewText(gotext.Get("Chat")),
onSelected: func() {
b.muteChatCheckbox.SetSelected(!b.muteChatCheckbox.Selected())
b.toggleMuteChat()
},
}
muteChatLabel.SetVertical(etk.AlignCenter)
b.muteRollCheckbox = etk.NewCheckbox(b.toggleMuteRoll)
b.muteRollCheckbox.SetBorderColor(triangleA)
b.muteRollCheckbox.SetCheckColor(triangleA)
b.muteRollCheckbox.SetSelected(b.muteRoll)
muteRollLabel := &ClickableText{
Text: etk.NewText(gotext.Get("Roll")),
onSelected: func() {
b.muteRollCheckbox.SetSelected(!b.muteRollCheckbox.Selected())
b.toggleMuteRoll()
},
}
muteRollLabel.SetVertical(etk.AlignCenter)
b.muteMoveCheckbox = etk.NewCheckbox(b.toggleMuteMove)
b.muteMoveCheckbox.SetBorderColor(triangleA)
b.muteMoveCheckbox.SetCheckColor(triangleA)
b.muteMoveCheckbox.SetSelected(b.muteMove)
muteMoveLabel := &ClickableText{
Text: etk.NewText(gotext.Get("Move")),
onSelected: func() {
b.muteMoveCheckbox.SetSelected(!b.muteMoveCheckbox.Selected())
b.toggleMuteMove()
},
}
muteMoveLabel.SetVertical(etk.AlignCenter)
b.muteBearOffCheckbox = etk.NewCheckbox(b.toggleMuteBearOff)
b.muteBearOffCheckbox.SetBorderColor(triangleA)
b.muteBearOffCheckbox.SetCheckColor(triangleA)
b.muteBearOffCheckbox.SetSelected(b.muteBearOff)
muteBearOffLabel := &ClickableText{
Text: etk.NewText(gotext.Get("Bear Off")),
onSelected: func() {
b.muteBearOffCheckbox.SetSelected(!b.muteBearOffCheckbox.Selected())
b.toggleMuteBearOff()
},
}
muteBearOffLabel.SetVertical(etk.AlignCenter)
checkboxGrid := etk.NewGrid()
checkboxGrid.SetColumnSizes(72, 20, -1)
sizes := []int{-1}
for i := 1; i < rowCount; i++ {
sizes = append(sizes, 20, -1)
}
checkboxGrid.SetRowSizes(sizes...)
gridY := 0
checkboxGrid.AddChildAt(cGrid(b.muteJoinLeaveCheckbox), 0, gridY, 1, 1)
checkboxGrid.AddChildAt(muteJoinLeaveLabel, 2, gridY, 1, 1)
gridY += 2
checkboxGrid.AddChildAt(cGrid(b.muteChatCheckbox), 0, gridY, 1, 1)
checkboxGrid.AddChildAt(muteChatLabel, 2, gridY, 1, 1)
gridY += 2
checkboxGrid.AddChildAt(cGrid(b.muteRollCheckbox), 0, gridY, 1, 1)
checkboxGrid.AddChildAt(muteRollLabel, 2, gridY, 1, 1)
gridY += 2
checkboxGrid.AddChildAt(cGrid(b.muteMoveCheckbox), 0, gridY, 1, 1)
checkboxGrid.AddChildAt(muteMoveLabel, 2, gridY, 1, 1)
gridY += 2
checkboxGrid.AddChildAt(cGrid(b.muteBearOffCheckbox), 0, gridY, 1, 1)
checkboxGrid.AddChildAt(muteBearOffLabel, 2, gridY, 1, 1)
b.muteSoundsGrid.SetBackground(color.RGBA{40, 24, 9, 255})
b.muteSoundsGrid.SetColumnSizes(20, -1, -1, 20)
b.muteSoundsGrid.SetRowSizes(72, fieldHeight+((fieldHeight+20)*(rowCount-1)), -1, etk.Scale(baseButtonHeight))
b.muteSoundsGrid.AddChildAt(headerLabel, 1, 0, 2, 1)
b.muteSoundsGrid.AddChildAt(checkboxGrid, 1, 1, 2, 1)
b.muteSoundsGrid.AddChildAt(etk.NewBox(), 1, 2, 1, 1)
b.muteSoundsGrid.AddChildAt(etk.NewButton(gotext.Get("Return"), b.showSettings), 0, 3, 4, 1)
b.muteSoundsGrid.SetVisible(false)
}
{
b.rematchButton = etk.NewButton(gotext.Get("Rematch"), b.selectRematch)
b.rematchButton.SetVisible(false)
@ -459,9 +589,9 @@ func NewBoard() *board {
checkboxGrid := etk.NewGrid()
checkboxGrid.SetColumnSizes(72, 20, -1)
if !AutoEnableTouchInput {
checkboxGrid.SetRowSizes(-1, 20, -1, 20, -1, 20, -1, 20, -1, 20, -1, 20, -1, 20, -1, 20, -1)
checkboxGrid.SetRowSizes(-1, 20, -1, 20, -1, 20, -1, 20, -1, 20, -1, 20, -1, 20, -1, 20, -1, 20, -1)
} else {
checkboxGrid.SetRowSizes(-1, 20, -1, 20, -1, 20, -1, 20, -1, 20, -1, 20, -1, 20, -1)
checkboxGrid.SetRowSizes(-1, 20, -1, 20, -1, 20, -1, 20, -1, 20, -1, 20, -1, 20, -1, 20, -1)
}
{
accountLabel := etk.NewText(gotext.Get("Account"))
@ -472,6 +602,18 @@ func NewBoard() *board {
grid.AddChildAt(b.accountGrid, 1, 0, 2, 1)
checkboxGrid.AddChildAt(grid, 0, 0, 3, 1)
}
{
muteLabel := etk.NewText(gotext.Get("Sound"))
muteLabel.SetVertical(etk.AlignCenter)
openMute := etk.NewButton(gotext.Get("Mute Sounds"), b.showMuteSounds)
openMute.SetHorizontal(etk.AlignStart)
grid := etk.NewGrid()
grid.AddChildAt(muteLabel, 0, 0, 1, 1)
grid.AddChildAt(openMute, 1, 0, 2, 1)
checkboxGrid.AddChildAt(grid, 0, 2, 3, 1)
}
{
speedLabel := etk.NewText(gotext.Get("Speed"))
speedLabel.SetVertical(etk.AlignCenter)
@ -487,25 +629,24 @@ func NewBoard() *board {
grid := etk.NewGrid()
grid.AddChildAt(speedLabel, 0, 0, 1, 1)
grid.AddChildAt(b.selectSpeed, 1, 0, 2, 1)
checkboxGrid.AddChildAt(grid, 0, 2, 3, 1)
checkboxGrid.AddChildAt(grid, 0, 4, 3, 1)
}
cGrid := func(checkbox *etk.Checkbox) *etk.Grid {
g := etk.NewGrid()
g.SetColumnSizes(7, -1)
g.AddChildAt(checkbox, 1, 0, 1, 1)
return g
}
checkboxGrid.AddChildAt(cGrid(b.highlightCheckbox), 0, 4, 1, 1)
checkboxGrid.AddChildAt(highlightLabel, 2, 4, 1, 1)
checkboxGrid.AddChildAt(cGrid(b.showPipCountCheckbox), 0, 6, 1, 1)
checkboxGrid.AddChildAt(pipCountLabel, 2, 6, 1, 1)
checkboxGrid.AddChildAt(cGrid(b.showMovesCheckbox), 0, 8, 1, 1)
checkboxGrid.AddChildAt(movesLabel, 2, 8, 1, 1)
checkboxGrid.AddChildAt(cGrid(b.flipBoardCheckbox), 0, 10, 1, 1)
checkboxGrid.AddChildAt(flipBoardLabel, 2, 10, 1, 1)
checkboxGrid.AddChildAt(cGrid(b.traditionalCheckbox), 0, 12, 1, 1)
checkboxGrid.AddChildAt(traditionalLabel, 2, 12, 1, 1)
gridY := 14
gridY := 6
checkboxGrid.AddChildAt(cGrid(b.highlightCheckbox), 0, gridY, 1, 1)
checkboxGrid.AddChildAt(highlightLabel, 2, gridY, 1, 1)
gridY += 2
checkboxGrid.AddChildAt(cGrid(b.showPipCountCheckbox), 0, gridY, 1, 1)
checkboxGrid.AddChildAt(pipCountLabel, 2, gridY, 1, 1)
gridY += 2
checkboxGrid.AddChildAt(cGrid(b.showMovesCheckbox), 0, gridY, 1, 1)
checkboxGrid.AddChildAt(movesLabel, 2, gridY, 1, 1)
gridY += 2
checkboxGrid.AddChildAt(cGrid(b.flipBoardCheckbox), 0, gridY, 1, 1)
checkboxGrid.AddChildAt(flipBoardLabel, 2, gridY, 1, 1)
gridY += 2
checkboxGrid.AddChildAt(cGrid(b.traditionalCheckbox), 0, gridY, 1, 1)
checkboxGrid.AddChildAt(traditionalLabel, 2, gridY, 1, 1)
gridY += 2
if !AutoEnableTouchInput {
checkboxGrid.AddChildAt(cGrid(b.advancedMovementCheckbox), 0, gridY, 1, 1)
checkboxGrid.AddChildAt(advancedMovementLabel, 2, gridY, 1, 1)
@ -514,7 +655,7 @@ func NewBoard() *board {
checkboxGrid.AddChildAt(cGrid(b.autoPlayCheckbox), 0, gridY, 1, 1)
checkboxGrid.AddChildAt(autoPlayLabel, 2, gridY, 1, 1)
gridSize := 72 + 20 + 72 + 20 + 72 + 20 + 72 + 20 + 72 + 20 + 72 + 20 + 72
gridSize := 72 + 20 + 72 + 20 + 72 + 20 + 72 + 20 + 72 + 20 + 72 + 20 + 72 + 20 + 72
if !AutoEnableTouchInput {
gridSize += 20 + 72
}
@ -639,6 +780,7 @@ func NewBoard() *board {
}
f.AddChild(children[0])
f.AddChild(b.changePasswordGrid)
f.AddChild(b.muteSoundsGrid)
f.AddChild(b.leaveGameGrid)
b.frame.AddChild(f)
}
@ -867,6 +1009,10 @@ func (b *board) leaveGame() error {
func (b *board) showSettings() error {
b.menuGrid.SetVisible(false)
b.settingsGrid.SetVisible(false)
b.selectSpeed.SetMenuVisible(false)
b.changePasswordGrid.SetVisible(false)
b.muteSoundsGrid.SetVisible(false)
b.settingsGrid.SetVisible(true)
return nil
}
@ -879,6 +1025,14 @@ func (b *board) showChangePassword() error {
return nil
}
func (b *board) showMuteSounds() error {
b.settingsGrid.SetVisible(false)
b.selectSpeed.SetMenuVisible(false)
b.changePasswordGrid.SetVisible(false)
b.muteSoundsGrid.SetVisible(true)
return nil
}
func (b *board) hideMenu() error {
b.menuGrid.SetVisible(false)
b.settingsGrid.SetVisible(false)
@ -1233,6 +1387,61 @@ func (b *board) toggleAdvancedMovementCheckbox() error {
return nil
}
func (b *board) toggleMuteJoinLeave() error {
b.muteJoinLeave = b.muteJoinLeaveCheckbox.Selected()
value := 0
if b.muteJoinLeave {
value = 1
}
b.Client.Out <- []byte(fmt.Sprintf("set mutejoinleave %d", value))
return nil
}
func (b *board) toggleMuteChat() error {
b.muteChat = b.muteChatCheckbox.Selected()
value := 0
if b.muteChat {
value = 1
}
b.Client.Out <- []byte(fmt.Sprintf("set mutechat %d", value))
return nil
}
func (b *board) toggleMuteRoll() error {
b.muteRoll = b.muteRollCheckbox.Selected()
value := 0
if b.muteRoll {
value = 1
}
b.Client.Out <- []byte(fmt.Sprintf("set muteroll %d", value))
return nil
}
func (b *board) toggleMuteMove() error {
b.muteMove = b.muteMoveCheckbox.Selected()
value := 0
if b.muteMove {
value = 1
}
b.Client.Out <- []byte(fmt.Sprintf("set mutemove %d", value))
return nil
}
func (b *board) toggleMuteBearOff() error {
b.muteBearOff = b.muteBearOffCheckbox.Selected()
value := 0
if b.muteBearOff {
value = 1
}
b.Client.Out <- []byte(fmt.Sprintf("set mutebearoff %d", value))
return nil
}
func (b *board) newSprite(white bool) *Sprite {
s := &Sprite{}
s.colorWhite = white
@ -1928,7 +2137,7 @@ func (b *board) setRect(x, y, w, h int) {
if dialogWidth > game.screenW {
dialogWidth = game.screenW
}
dialogHeight := 72 + 72 + 20 + 72 + 20 + 72 + 20 + 72 + 20 + 72 + 20 + 72 + 20 + 72 + 20 + etk.Scale(baseButtonHeight)
dialogHeight := 72 + 72 + 20 + 72 + 20 + 72 + 20 + 72 + 20 + 72 + 20 + 72 + 20 + 72 + 20 + 72 + 20 + etk.Scale(baseButtonHeight)
if dialogHeight > game.screenH {
dialogHeight = game.screenH
}
@ -1936,6 +2145,7 @@ func (b *board) setRect(x, y, w, h int) {
x, y := game.screenW/2-dialogWidth/2, game.screenH/2-dialogHeight/2
b.settingsGrid.SetRect(image.Rect(x, y, x+dialogWidth, y+dialogHeight))
b.changePasswordGrid.SetRect(image.Rect(x, y, x+dialogWidth, y+dialogHeight))
b.muteSoundsGrid.SetRect(image.Rect(x, y, x+dialogWidth, y+dialogHeight))
b.selectRollGrid.SetRect(image.Rect(x, y, x+dialogWidth, y+dialogHeight))
}

View file

@ -38,7 +38,7 @@ import (
)
const (
version = "v1.3.7p2"
version = "v1.3.7p3"
baseButtonHeight = 54
MaxDebug = 2
DefaultServerAddress = "wss://ws.bgammon.org"
@ -1643,6 +1643,16 @@ func (g *Game) handleEvent(e interface{}) {
b.flipBoardCheckbox.SetSelected(b.flipBoard)
b.traditional = ev.Traditional
b.traditionalCheckbox.SetSelected(b.traditional)
b.muteJoinLeave = ev.MuteJoinLeave
b.muteJoinLeaveCheckbox.SetSelected(b.muteJoinLeave)
b.muteChat = ev.MuteChat
b.muteChatCheckbox.SetSelected(b.muteChat)
b.muteRoll = ev.MuteRoll
b.muteRollCheckbox.SetSelected(b.muteRoll)
b.muteMove = ev.MuteMove
b.muteMoveCheckbox.SetSelected(b.muteMove)
b.muteBearOff = ev.MuteBearOff
b.muteBearOffCheckbox.SetSelected(b.muteBearOff)
if !AutoEnableTouchInput {
b.advancedMovement = ev.Advanced
b.advancedMovementCheckbox.SetSelected(b.advancedMovement)
@ -2932,10 +2942,19 @@ func playSoundEffect(effect SoundEffect) {
var b []byte
switch effect {
case effectSay:
if game.Board.muteChat {
return
}
b = SoundSay
case effectJoinLeave:
if game.Board.muteJoinLeave {
return
}
b = SoundJoinLeave
case effectDie:
if game.Board.muteRoll {
return
}
b = dieSounds[dieSoundPlays]
dieSoundPlays++
@ -2944,6 +2963,9 @@ func playSoundEffect(effect SoundEffect) {
dieSoundPlays = 0
}
case effectDice:
if game.Board.muteRoll {
return
}
b = diceSounds[diceSoundPlays]
diceSoundPlays++
@ -2952,6 +2974,9 @@ func playSoundEffect(effect SoundEffect) {
diceSoundPlays = 0
}
case effectMove:
if game.Board.muteMove {
return
}
b = moveSounds[moveSoundPlays]
moveSoundPlays++
@ -2960,8 +2985,14 @@ func playSoundEffect(effect SoundEffect) {
moveSoundPlays = 0
}
case effectHomeSingle:
if game.Board.muteBearOff {
return
}
b = SoundHomeSingle
case effectHomeMulti:
if game.Board.muteBearOff {
return
}
b = homeMultiSounds[homeMultiSoundPlays]
homeMultiSoundPlays++

View file

@ -193,6 +193,9 @@ msgstr ""
msgid "Multi"
msgstr ""
msgid "Mute Sounds"
msgstr ""
msgid "Name"
msgstr ""
@ -301,6 +304,9 @@ msgstr ""
msgid "Slow"
msgstr ""
msgid "Sound"
msgstr ""
msgid "Speed"
msgstr ""

4
go.mod
View file

@ -3,9 +3,9 @@ module code.rocket9labs.com/tslocum/boxcars
go 1.19
require (
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240722091556-dd38c10f32a3
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240722222718-3069f96568cf
code.rocket9labs.com/tslocum/bgammon-bei-bot v0.0.0-20240721175208-e769215e74fc
code.rocket9labs.com/tslocum/etk v0.0.0-20240722093150-1d8a55632df0
code.rocket9labs.com/tslocum/etk v0.0.0-20240722214147-c1f1fe1adb37
code.rocket9labs.com/tslocum/gotext v0.0.0-20240722063358-6067ad4d7a58
code.rocket9labs.com/tslocum/tabula v0.0.0-20240703054156-ce0b448f0999
github.com/hajimehoshi/ebiten/v2 v2.7.8

8
go.sum
View file

@ -1,11 +1,11 @@
code.rocket9labs.com/tslocum/bei v0.0.0-20240108012722-6db380cc190b h1:Y0a14Kf/hSYepSmp4ZfDeE4CZZGBGBS97CNjCbKJm0c=
code.rocket9labs.com/tslocum/bei v0.0.0-20240108012722-6db380cc190b/go.mod h1:tS60/VNAJphKvDBkSLQhKALa15msIAuWWfEKNc4oFZc=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240722091556-dd38c10f32a3 h1:cnPJf7geTOpORBJiEA5kmkJRRpOK2yAtsk6O+3DWPsg=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240722091556-dd38c10f32a3/go.mod h1:wiLaPGmIrwggJJ/girtcsY2mTG4PGXr748Y52+JHEyw=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240722222718-3069f96568cf h1:lxfnmCaGB0OQUUfxbGOZxEcElPELw6kRKGtq1NWp0Vg=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240722222718-3069f96568cf/go.mod h1:ueagvK626vpCnfWwJR4P9PVBhTb8MzofVkiJFZUWdM8=
code.rocket9labs.com/tslocum/bgammon-bei-bot v0.0.0-20240721175208-e769215e74fc h1:zKspzJaha5v9qsfV1sy920JxCMgXNLRxux0DmQOPPlA=
code.rocket9labs.com/tslocum/bgammon-bei-bot v0.0.0-20240721175208-e769215e74fc/go.mod h1:odKdJABSCpTEsL/AfUJ4FX3Lb1dn2bjiL0tc5qV15G8=
code.rocket9labs.com/tslocum/etk v0.0.0-20240722093150-1d8a55632df0 h1:bkOEMek9ArKv+eBqDLl0ecYYG0EFEkPS3sjTQP3s3P8=
code.rocket9labs.com/tslocum/etk v0.0.0-20240722093150-1d8a55632df0/go.mod h1:mRWb5b3UIBMlu5F4tjFgtwqLUsytvLhROSsoVaaM9Uw=
code.rocket9labs.com/tslocum/etk v0.0.0-20240722214147-c1f1fe1adb37 h1:A40EvxTo0L/tA4D9DqQJmU8bbT4JzLZtmp5icnYu2yU=
code.rocket9labs.com/tslocum/etk v0.0.0-20240722214147-c1f1fe1adb37/go.mod h1:DNci8/XmC0Y4METoZ7yPa2TnI0u+EVV0lb1rpxpZkZU=
code.rocket9labs.com/tslocum/gotext v0.0.0-20240722063358-6067ad4d7a58 h1:8A+LPX/j9qYaE/tSJcaYONIh28JX5CN9i+4ZfRefvPo=
code.rocket9labs.com/tslocum/gotext v0.0.0-20240722063358-6067ad4d7a58/go.mod h1:ZkYZ/IF/ebzhUL2bNp4ALROsuH9iCztUWvUJBWsHXRU=
code.rocket9labs.com/tslocum/tabula v0.0.0-20240703054156-ce0b448f0999 h1:PwfoDBtxVT3TwL2KpoijPKi6NQsGu6cXhPVoQeqKJWM=