Maded flower buttons smaller (less tall).

This commit is contained in:
Sander Schobers 2020-05-11 02:49:53 +02:00
parent 3a8ad733a4
commit e26de92f1d
3 changed files with 20 additions and 13 deletions

View File

@ -6,6 +6,7 @@ type ButtonBar struct {
Container
Background sdl.Color
ButtonLength int32
Orientation Orientation
Buttons []Control
}
@ -21,19 +22,24 @@ func (b *ButtonBar) Init(ctx *Context) error {
func (b *ButtonBar) Arrange(ctx *Context, bounds Rectangle) {
b.Container.Arrange(ctx, bounds)
length := b.ButtonLength
switch b.Orientation {
case OrientationHorizontal:
length := bounds.H
if length == 0 {
length = bounds.H
}
offset := bounds.X
for i := range b.Buttons {
b.Buttons[i].Arrange(ctx, RectSize(offset, bounds.Y, length, length))
b.Buttons[i].Arrange(ctx, RectSize(offset, bounds.Y, length, bounds.H))
offset += length
}
default:
length := bounds.W
if length == 0 {
length = bounds.W
}
offset := bounds.Y
for i := range b.Buttons {
b.Buttons[i].Arrange(ctx, RectSize(bounds.X, offset, length, length))
b.Buttons[i].Arrange(ctx, RectSize(bounds.X, offset, bounds.W, length))
offset += length
}
}

View File

@ -76,9 +76,9 @@ func (b *BuyFlowerButton) Render(ctx *Context) {
mouseOverTexture := ctx.Textures.Texture("control-hover")
pos := Pt(b.Bounds.X, b.Bounds.Y)
iconTexture.CopyResize(ctx.Renderer, RectSize(pos.X, pos.Y-40, buttonBarWidth, 120))
iconTexture.CopyResize(ctx.Renderer, RectSize(pos.X, pos.Y-60, b.Bounds.W, 120))
if (b.IsMouseOver && !b.IsDisabled) || b.IsActive {
mouseOverTexture.Copy(ctx.Renderer, pos)
mouseOverTexture.CopyResize(ctx.Renderer, b.Bounds)
}
if b.hoverAnimation != nil {
@ -86,8 +86,8 @@ func (b *BuyFlowerButton) Render(ctx *Context) {
}
if b.IsMouseOver {
left := buttonBarWidth - 8 - b.hoverOffset
top := pos.Y + buttonBarWidth - 20
left := b.Bounds.W - 8 - b.hoverOffset
top := pos.Y + b.Bounds.H - 20
if left < 0 {
part := Rect(-left, 0, b.hoverTexture.Size().X, b.hoverTexture.Size().Y)
b.hoverTexture.CopyPart(ctx.Renderer, part, Pt(pos.X, top))
@ -95,6 +95,6 @@ func (b *BuyFlowerButton) Render(ctx *Context) {
b.hoverTexture.Copy(ctx.Renderer, Pt(pos.X+left, top))
}
} else {
b.priceTexture.Copy(ctx.Renderer, Pt(pos.X+buttonBarWidth-8-b.priceTexture.Size().X, pos.Y+buttonBarWidth-20))
b.priceTexture.Copy(ctx.Renderer, Pt(pos.X+b.Bounds.W-8-b.priceTexture.Size().X, pos.Y+b.Bounds.H-20))
}
}

View File

@ -75,7 +75,8 @@ func (c *GameControls) Init(ctx *Context) error {
c.game.SpeedChanged().RegisterItf(c.speedChanged)
c.game.ToolChanged().RegisterItf(c.toolChanged)
c.flowers.Background = MustHexColor("#356dad") // brown alternative? #4ac69a
c.flowers.Background = MustHexColor("#356dad")
c.flowers.ButtonLength = 64
for _, id := range c.game.Herbarium.Flowers() {
c.flowers.Buttons = append(c.flowers.Buttons, c.createBuyFlowerButton(id))