From 127a43fcdf7e7651cb8377b109c742f42c3fd303 Mon Sep 17 00:00:00 2001 From: Zac Date: Mon, 11 Nov 2024 21:42:01 +0000 Subject: [PATCH] Use improved text alignment --- common/arena.go | 12 ++++-------- common/button.go | 8 ++------ common/textbox.go | 8 ++++---- debug/debug.go | 4 ++-- go.mod | 2 +- go.sum | 10 ++++++++++ screen/multiplayer.go | 6 +++--- screen/multiplayer_host.go | 4 ++-- screen/multiplayer_join.go | 8 ++++---- screen/singleplayer.go | 6 +++--- 10 files changed, 35 insertions(+), 33 deletions(-) diff --git a/common/arena.go b/common/arena.go index 4943356..543dd3f 100644 --- a/common/arena.go +++ b/common/arena.go @@ -39,18 +39,14 @@ type tile struct { // newTile constructs a new tile with the correct style. func newTile(sizePx float64, pos turdgl.Vec, val int, posIdx coord) *tile { - r := turdgl.NewCurvedRect(sizePx, sizePx, TileCornerRadius, pos) - tile := tile{ - tb: turdgl.NewTextBox(r, strconv.Itoa(val), tileFont). + return &tile{ + tb: turdgl.NewTextBox(turdgl.NewCurvedRect( + sizePx, sizePx, TileCornerRadius, pos, + ).SetStyle(turdgl.Style{Colour: tileColour(val)}), strconv.Itoa(val), tileFont). SetTextSize(tileFontSize(val)). - SetTextAlignment(turdgl.AlignCustom). SetTextColour(tileTextColour(val)), pos: posIdx, } - tile.tb.Text.SetOffset(turdgl.Vec{X: 0, Y: 15}) - r.SetStyle(turdgl.Style{Colour: tileColour(val)}) - - return &tile } // animationData contains animations and the current game state. diff --git a/common/button.go b/common/button.go index b260a9c..0962c32 100644 --- a/common/button.go +++ b/common/button.go @@ -30,9 +30,7 @@ func NewMenuButton(width, height float64, pos turdgl.Vec, callback func()) *turd b := turdgl.NewButton(r, FontPathMedium). SetLabelText("SET ME"). SetLabelSize(36). - SetLabelColour(WhiteFontColour). - SetLabelAlignment(turdgl.AlignCustom). - SetLabelOffset(turdgl.Vec{X: 0, Y: 15}) + SetLabelColour(WhiteFontColour) b.SetCallback( turdgl.ButtonTrigger{State: turdgl.NoClick, Behaviour: turdgl.OnHold}, @@ -73,9 +71,7 @@ func NewGameButton(width, height float64, pos turdgl.Vec, callback func()) *turd b := turdgl.NewButton(r, FontPathBold). SetLabelText("BUTTON"). SetLabelSize(14). - SetLabelColour(WhiteFontColour). - SetLabelAlignment(turdgl.AlignCustom). - SetLabelOffset(turdgl.Vec{X: 0, Y: 7}) + SetLabelColour(WhiteFontColour) b.SetCallback( turdgl.ButtonTrigger{State: turdgl.NoClick, Behaviour: turdgl.OnHold}, diff --git a/common/textbox.go b/common/textbox.go index c8d6aec..55c8fbc 100644 --- a/common/textbox.go +++ b/common/textbox.go @@ -29,7 +29,7 @@ func NewEntryBox(width, height float64, pos turdgl.Vec, txt string) *EntryBox { bloom := turdgl.NewCurvedRect(width, height, 6, pos).SetStyle(styleUnselected) - tb := NewTextBox(width, height, pos, txt) + tb := NewTextBox(width, height, pos, txt).SetTextAlignment(turdgl.AlignCentre) tb.SetSelectedCB(func() { tb.SetTextColour(turdgl.White) bloom.SetStyle(styleSelected) @@ -91,7 +91,7 @@ type ScoreBox struct { func NewScoreBox(width, height float64, pos turdgl.Vec, colour color.RGBA) *ScoreBox { headingPos := turdgl.Vec{ X: pos.X + width/2, - Y: pos.Y + 25, + Y: pos.Y + 15, } heading := turdgl.NewText("Heading", headingPos, FontPathBold). SetColour(LightGreyTextColour). @@ -104,7 +104,7 @@ func NewScoreBox(width, height float64, pos turdgl.Vec, colour color.RGBA) *Scor ).SetStyle(turdgl.Style{Colour: colour}) body := turdgl.NewTextBox(r, "", FontPathBold). - SetTextOffset(turdgl.Vec{X: 0, Y: 18}). + SetTextOffset(turdgl.Vec{X: 0, Y: 10}). SetTextSize(26). SetTextColour(WhiteFontColour) @@ -146,7 +146,7 @@ func NewLogoBox(size float64, pos turdgl.Vec) *turdgl.TextBox { SetTextSize(32). SetTextColour(WhiteFontColour) - logo.Text.SetAlignment(turdgl.AlignCustom).SetOffset(turdgl.Vec{Y: 15}) + logo.Text.SetAlignment(turdgl.AlignCustom) logo.Shape.(*turdgl.CurvedRect).SetStyle(turdgl.Style{Colour: Tile2048Colour}) return logo diff --git a/debug/debug.go b/debug/debug.go index bb0814b..d212efe 100644 --- a/debug/debug.go +++ b/debug/debug.go @@ -18,11 +18,11 @@ type Widget struct { } func NewDebugWidget(win *turdgl.Window) *Widget { - location := turdgl.NewText("Loc: ", turdgl.Vec{X: 1090, Y: 25}, common.FontPathMedium). + location := turdgl.NewText("Loc: ", turdgl.Vec{X: 1120, Y: 25}, common.FontPathMedium). SetAlignment(turdgl.AlignBottomRight). SetSize(12) - fps := turdgl.NewText("FPS: -", turdgl.Vec{X: 1150, Y: 25}, common.FontPathMedium). + fps := turdgl.NewText("FPS: -", turdgl.Vec{X: 1180, Y: 25}, common.FontPathMedium). SetAlignment(turdgl.AlignBottomRight). SetSize(12) diff --git a/go.mod b/go.mod index 3f6bce9..2b7cf0e 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/brunoga/deep v1.2.4 github.com/google/uuid v1.6.0 github.com/moby/moby v27.3.1+incompatible - github.com/z-riley/turdgl v0.0.0-20241110155312-25280b430bfe + github.com/z-riley/turdgl v0.0.0-20241111212625-8502d81bbf4b github.com/z-riley/turdserve v0.0.0-20241109095301-66eab11d38af golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa ) diff --git a/go.sum b/go.sum index 155d7df..ff863d8 100644 --- a/go.sum +++ b/go.sum @@ -26,6 +26,16 @@ github.com/z-riley/turdgl v0.0.0-20241110155021-280343130dc7 h1:i0KmQ9APd/pzkuwP github.com/z-riley/turdgl v0.0.0-20241110155021-280343130dc7/go.mod h1:PUy0rnENvtQrZRghi9dYinsUUE7gvC9wOz8C/gcwJ8A= github.com/z-riley/turdgl v0.0.0-20241110155312-25280b430bfe h1:eAF2Nn4N/xDvA2WLpUJWcL1lx36se4SKfi8AJJDzIxI= github.com/z-riley/turdgl v0.0.0-20241110155312-25280b430bfe/go.mod h1:PUy0rnENvtQrZRghi9dYinsUUE7gvC9wOz8C/gcwJ8A= +github.com/z-riley/turdgl v0.0.0-20241111205046-14cbbbc7e3fa h1:r9fOAXSEnUoSLiQNYYSdZXlow0JizK2klt5VqNMWm8w= +github.com/z-riley/turdgl v0.0.0-20241111205046-14cbbbc7e3fa/go.mod h1:PUy0rnENvtQrZRghi9dYinsUUE7gvC9wOz8C/gcwJ8A= +github.com/z-riley/turdgl v0.0.0-20241111210007-493f8ad4a7dd h1:8DVIcZh7AnUpd0WZ6LKMr346sdrrAVab9bmX4ycOALk= +github.com/z-riley/turdgl v0.0.0-20241111210007-493f8ad4a7dd/go.mod h1:PUy0rnENvtQrZRghi9dYinsUUE7gvC9wOz8C/gcwJ8A= +github.com/z-riley/turdgl v0.0.0-20241111211348-7f67596fc4c3 h1:KyGahMKTdYnjt1TD46qz1GJPeSgeN04bFBer6CN/QxQ= +github.com/z-riley/turdgl v0.0.0-20241111211348-7f67596fc4c3/go.mod h1:PUy0rnENvtQrZRghi9dYinsUUE7gvC9wOz8C/gcwJ8A= +github.com/z-riley/turdgl v0.0.0-20241111211940-c3cd8a2a4483 h1:70BLpyLJWGuxgRDWuZ7Sr1KSgbLMnKDrc29Ky1X7HkQ= +github.com/z-riley/turdgl v0.0.0-20241111211940-c3cd8a2a4483/go.mod h1:PUy0rnENvtQrZRghi9dYinsUUE7gvC9wOz8C/gcwJ8A= +github.com/z-riley/turdgl v0.0.0-20241111212625-8502d81bbf4b h1:Vf/FWjMHQAcLWjDGTGmhs52EoNHK+ojtG722IWdyduw= +github.com/z-riley/turdgl v0.0.0-20241111212625-8502d81bbf4b/go.mod h1:PUy0rnENvtQrZRghi9dYinsUUE7gvC9wOz8C/gcwJ8A= github.com/z-riley/turdserve v0.0.0-20241103172943-200ed8c9c094 h1:9ldkpBMZ5+BV8GOGH+4QhrBgevotAprFgMVCasm+td0= github.com/z-riley/turdserve v0.0.0-20241103172943-200ed8c9c094/go.mod h1:D5VroZVlQvt0vUtZ2xHL8aQOlCumE/9LFEH1BBLE468= github.com/z-riley/turdserve v0.0.0-20241109095301-66eab11d38af h1:X0XCfUgoGvZaOZtSRcB6UkuEkP4B6EzwvDUkkZkA7p0= diff --git a/screen/multiplayer.go b/screen/multiplayer.go index 92937cf..228ff55 100644 --- a/screen/multiplayer.go +++ b/screen/multiplayer.go @@ -116,7 +116,7 @@ func (s *MultiplayerScreen) Enter(initData InitData) { s.guide = common.NewGameText( "Your grid", - turdgl.Vec{X: anchor.X + s.arena.Width(), Y: anchor.Y - 0.53*unit}, + turdgl.Vec{X: anchor.X + s.arena.Width(), Y: anchor.Y - 0.67*unit}, ).SetAlignment(turdgl.AlignTopRight) s.backend = backend.NewGame(&backend.Opts{ @@ -125,7 +125,7 @@ func (s *MultiplayerScreen) Enter(initData InitData) { s.arenaInputCh = make(chan func(), 100) s.timer = common.NewGameText("", - turdgl.Vec{X: config.WinWidth / 2, Y: anchor.Y - 0.53*unit}, + turdgl.Vec{X: config.WinWidth / 2, Y: anchor.Y - 0.67*unit}, ).SetAlignment(turdgl.AlignTopCentre) } @@ -143,7 +143,7 @@ func (s *MultiplayerScreen) Enter(initData InitData) { s.opponentName = initData[opponentUsernameKey].(string) s.opponentGuide = common.NewGameText( s.opponentName+"'s grid", - turdgl.Vec{X: opponentAnchor.X, Y: opponentAnchor.Y - 0.53*unit}, + turdgl.Vec{X: opponentAnchor.X, Y: opponentAnchor.Y - 0.67*unit}, ) s.opponentBackend = backend.NewGame(&backend.Opts{ diff --git a/screen/multiplayer_host.go b/screen/multiplayer_host.go index 414aaa2..c64b61e 100644 --- a/screen/multiplayer_host.go +++ b/screen/multiplayer_host.go @@ -51,7 +51,7 @@ func (s *MultiplayerHostScreen) Enter(_ InitData) { s.nameHeading = turdgl.NewText( "Your name:", - turdgl.Vec{X: config.WinWidth / 2, Y: 290}, + turdgl.Vec{X: config.WinWidth / 2, Y: 300}, common.FontPathMedium, ). SetColour(common.GreyTextColour). @@ -60,7 +60,7 @@ func (s *MultiplayerHostScreen) Enter(_ InitData) { s.nameEntry = common.NewEntryBox( 440, 60, - turdgl.Vec{X: (config.WinWidth - 440) / 2, Y: s.nameHeading.Pos().Y + 20}, + turdgl.Vec{X: (config.WinWidth - 440) / 2, Y: s.nameHeading.Pos().Y + 30}, namesgenerator.GetRandomName(0), ). SetModifiedCB(func() { diff --git a/screen/multiplayer_join.go b/screen/multiplayer_join.go index 417a07a..3c57487 100644 --- a/screen/multiplayer_join.go +++ b/screen/multiplayer_join.go @@ -51,7 +51,7 @@ func (s *MultiplayerJoinScreen) Enter(_ InitData) { s.nameHeading = turdgl.NewText( "Your name:", - turdgl.Vec{X: config.WinWidth / 2, Y: 230}, + turdgl.Vec{X: config.WinWidth / 2, Y: 250}, common.FontPathMedium, ). SetColour(common.GreyTextColour). @@ -60,7 +60,7 @@ func (s *MultiplayerJoinScreen) Enter(_ InitData) { s.nameEntry = common.NewEntryBox( 440, 60, - turdgl.Vec{X: config.WinWidth/2 - 440/2, Y: s.nameHeading.Pos().Y + 15}, + turdgl.Vec{X: config.WinWidth/2 - 440/2, Y: s.nameHeading.Pos().Y + 30}, namesgenerator.GetRandomName(0), ). SetModifiedCB(func() { @@ -74,7 +74,7 @@ func (s *MultiplayerJoinScreen) Enter(_ InitData) { s.ipHeading = turdgl.NewText( "Host IP:", - turdgl.Vec{X: config.WinWidth / 2, Y: 370}, + turdgl.Vec{X: config.WinWidth / 2, Y: 380}, common.FontPathMedium, ). SetColour(common.GreyTextColour). @@ -90,7 +90,7 @@ func (s *MultiplayerJoinScreen) Enter(_ InitData) { s.ipEntry = common.NewEntryBox( 440, 60, - turdgl.Vec{X: (config.WinWidth - 440) / 2, Y: s.ipHeading.Pos().Y + 15}, + turdgl.Vec{X: (config.WinWidth - 440) / 2, Y: s.ipHeading.Pos().Y + 30}, string(b), ).SetModifiedCB(func() { if err := s.ipStore.SaveBytes([]byte(s.ipEntry.Text())); err != nil { diff --git a/screen/singleplayer.go b/screen/singleplayer.go index d544435..85df02d 100644 --- a/screen/singleplayer.go +++ b/screen/singleplayer.go @@ -58,13 +58,13 @@ func (s *SingleplayerScreen) Enter(_ InitData) { s.heading = turdgl.NewText( "", // to be set and drawn when player loses - turdgl.Vec{X: anchor.X + s.arena.Width()/2, Y: anchor.Y - 2.3*unit}, + turdgl.Vec{X: anchor.X + s.arena.Width()/2, Y: anchor.Y - 2.8*unit}, common.FontPathBold, ).SetSize(40).SetColour(common.GreyTextColour).SetAlignment(turdgl.AlignTopCentre) s.loseDialog = turdgl.NewText( "", // to be set and drawn when player loses - turdgl.Vec{X: anchor.X + s.arena.Width()/2, Y: anchor.Y - 1.7*unit}, + turdgl.Vec{X: anchor.X + s.arena.Width()/2, Y: anchor.Y - 1.9*unit}, common.FontPathBold, ).SetSize(20).SetColour(common.GreyTextColour).SetAlignment(turdgl.AlignTopCentre) @@ -108,7 +108,7 @@ func (s *SingleplayerScreen) Enter(_ InitData) { s.guide = turdgl.NewText( "Join the numbers and get to the 2048 tile!", - turdgl.Vec{X: anchor.X, Y: anchor.Y - 0.53*unit}, + turdgl.Vec{X: anchor.X, Y: anchor.Y - 0.60*unit}, common.FontPathBold, ).SetSize(16).SetColour(common.GreyTextColour)