Sander Schobers
b14f79a61a
Added more icons and placed buttons on the bars. Implemented pause/run/fast.
78 lines
2.4 KiB
Go
78 lines
2.4 KiB
Go
package tins2020
|
|
|
|
type GameControls struct {
|
|
Container
|
|
|
|
game *Game
|
|
|
|
menu ButtonBar
|
|
top ButtonBar
|
|
flowers ButtonBar
|
|
|
|
pause *IconButton
|
|
run *IconButton
|
|
runFast *IconButton
|
|
}
|
|
|
|
func NewGameControls(game *Game) *GameControls {
|
|
return &GameControls{game: game}
|
|
}
|
|
|
|
func (c *GameControls) updateSpeedControls() {
|
|
}
|
|
|
|
func (c *GameControls) Arrange(ctx *Context, bounds Rectangle) {
|
|
c.Bounds = bounds
|
|
c.menu.Arrange(ctx, RectSize(bounds.X, bounds.Y, buttonBarWidth, bounds.H))
|
|
c.top.Arrange(ctx, Rect(bounds.X+bounds.W/2+8, bounds.Y, bounds.Right(), bounds.Y+64))
|
|
c.flowers.Arrange(ctx, RectSize(bounds.Right()-buttonBarWidth, bounds.Y, buttonBarWidth, bounds.H))
|
|
}
|
|
|
|
func (c *GameControls) buyPoppy(ctx *Context) {
|
|
c.game.Balance -= 10
|
|
}
|
|
|
|
func (c *GameControls) Init(ctx *Context) error {
|
|
c.flowers.Background = MustHexColor("#356dad") // brown alternative? #4ac69a
|
|
c.flowers.Buttons = []Control{
|
|
NewBuyFlowerButton("flower-poppy-1", "flower-poppy-disabled", "Poppy", 10, "A very generic flower that thrives in a moderate climate.", false, c.buyPoppy),
|
|
NewBuyFlowerButton("flower-red-c-1", "flower-poppy-disabled", "Unknown", 100, "Traits are not known yet.", true, nil),
|
|
}
|
|
|
|
c.top.Orientation = OrientationHorizontal
|
|
c.pause = NewIconButton("control-pause", EmptyEvent(func() {
|
|
c.game.Pause()
|
|
c.updateSpeedControls()
|
|
}))
|
|
c.run = NewIconButton("control-run", EmptyEvent(func() {
|
|
c.game.Run()
|
|
c.updateSpeedControls()
|
|
}))
|
|
c.runFast = NewIconButton("control-run-fast", EmptyEvent(func() {
|
|
c.game.RunFast()
|
|
c.updateSpeedControls()
|
|
}))
|
|
c.top.Buttons = []Control{c.pause, c.run, c.runFast}
|
|
|
|
c.menu.Background = MustHexColor("#356dad")
|
|
c.menu.Buttons = []Control{
|
|
NewIconButton("control-settings", EmptyEvent(func() {})),
|
|
NewIconButton("control-save", EmptyEvent(func() {})),
|
|
NewIconButton("control-load", EmptyEvent(func() {})),
|
|
}
|
|
|
|
c.Container.AddChild(&c.menu)
|
|
c.Container.AddChild(&c.top)
|
|
c.Container.AddChild(&c.flowers)
|
|
return c.Container.Init(ctx)
|
|
}
|
|
|
|
func (c *GameControls) Render(ctx *Context) {
|
|
topBar := MustHexColor("#0000007f")
|
|
ctx.Renderer.SetDrawColor(topBar.R, topBar.G, topBar.B, topBar.A)
|
|
ctx.Renderer.FillRect(Rect(c.menu.Bounds.Right(), 0, c.flowers.Bounds.X, 64).SDLPtr())
|
|
ctx.Fonts.Font("balance").RenderCopyAlign(ctx.Renderer, FmtMoney(c.game.Balance), Pt(c.top.Bounds.X-8, 58), MustHexColor("#79A6D9"), TextAlignmentRight)
|
|
|
|
c.Container.Render(ctx)
|
|
}
|