tins2020/buyflowerbutton.go

127 lines
3.3 KiB
Go
Raw Normal View History

package tins2020
import (
2020-05-17 08:56:56 +00:00
"opslag.de/schobers/zntg"
"opslag.de/schobers/zntg/ui"
)
type BuyFlowerButton struct {
IconButton
FlowerID string
Flower FlowerDescriptor
2020-05-17 08:56:56 +00:00
upToDate bool
hoverAnimation *zntg.Animation
hoverOffset int32
2020-05-17 08:56:56 +00:00
hoverTexture ui.Texture
priceTexture ui.Texture
}
2020-05-17 08:56:56 +00:00
func NewBuyFlowerButton(icon, iconDisabled, flowerID string, flower FlowerDescriptor, click ui.EventEmptyFn) *BuyFlowerButton {
return &BuyFlowerButton{
2020-05-17 08:56:56 +00:00
IconButton: *NewIconButtonConfigure(icon, click, func(b *IconButton) {
// b.IconDisabled = iconDisabled
// b.Disabled = !flower.Unlocked
}),
FlowerID: flowerID,
Flower: flower,
}
}
2020-05-17 08:56:56 +00:00
// func (b *BuyFlowerButton) animate() {
// b.hoverOffset++
// if b.hoverOffset > b.hoverTexture.Size().X+b.Bounds.W {
// b.hoverOffset = 0
// }
// }
// func (b *BuyFlowerButton) fmtTooltipText() string {
// if !b.Flower.Unlocked {
// return fmt.Sprintf("%s - %s - %s", FmtMoney(b.Flower.BuyPrice), b.Flower.Name, "Traits are not known yet.")
// }
// return fmt.Sprintf("%s - %s - %s", FmtMoney(b.Flower.BuyPrice), b.Flower.Name, b.Flower.Description)
// }
func (b *BuyFlowerButton) updateTexts(ctx ui.Context) error {
if b.upToDate {
return nil
}
2020-05-17 08:56:56 +00:00
// text := b.fmtTooltipText()
// font := ctx.Fonts.Font("small")
// color := MustHexColor("#ffffff")
// texture, err := font.Render(ctx.Renderer, text, color)
// if err != nil {
// return err
// }
// if b.hoverTexture != nil {
// b.hoverTexture.Destroy()
// }
// b.hoverTexture = texture
// texture, err = font.Render(ctx.Renderer, FmtMoney(b.Flower.BuyPrice), color)
// if err != nil {
// return err
// }
// if b.priceTexture != nil {
// b.priceTexture.Destroy()
// }
// b.priceTexture = texture
b.upToDate = true
return nil
}
2020-05-17 08:56:56 +00:00
// func (b *BuyFlowerButton) Init(ctx ui.Context) error {
// return b.updateTexts(ctx)
// }
2020-05-11 01:09:01 +00:00
2020-05-17 08:56:56 +00:00
func (b *BuyFlowerButton) Handle(ctx ui.Context, event ui.Event) bool {
b.updateTexts(ctx)
// if b.IconButton.Handle(ctx, event) {
// return true
// }
// if b.IsMouseOver && b.hoverAnimation == nil {
// b.hoverAnimation = NewAnimationPtr(10 * time.Millisecond)
// b.hoverOffset = b.priceTexture.Size().X
// } else if !b.IsMouseOver {
// b.hoverAnimation = nil
// }
return false
}
2020-05-17 08:56:56 +00:00
func (b *BuyFlowerButton) Render(ctx ui.Context) {
if !b.upToDate {
b.updateTexts(ctx)
}
2020-05-17 08:56:56 +00:00
// iconTexture := b.activeTexture(ctx)
// pos := Pt(b.Bounds.X, b.Bounds.Y)
// iconTexture.CopyResize(ctx.Renderer, Rect(pos.X, pos.Y-60, b.Bounds.W, 120))
// if (b.IsMouseOver && !b.Disabled) || b.IsActive {
// SetDrawColor(ctx.Renderer, TransparentWhite)
// ctx.Renderer.FillRect(b.Bounds.SDLPtr())
// }
// if b.hoverAnimation != nil {
// b.hoverAnimation.AnimateFn(b.animate)
// }
// if b.IsMouseOver {
// left := b.Bounds.W - 8 - b.hoverOffset
// top := pos.Y + b.Bounds.H - 20
// if left < 0 {
// part := RectAbs(-left, 0, b.hoverTexture.Size().X, b.hoverTexture.Size().Y)
// b.hoverTexture.CopyPart(ctx.Renderer, part, Pt(pos.X, top))
// } else {
// b.hoverTexture.Copy(ctx.Renderer, Pt(pos.X+left, top))
// }
// } else {
// b.priceTexture.Copy(ctx.Renderer, Pt(pos.X+b.Bounds.W-8-b.priceTexture.Size().X, pos.Y+b.Bounds.H-20))
// }
}
2020-05-11 01:09:01 +00:00
2020-05-17 08:56:56 +00:00
func (b *BuyFlowerButton) Update(desc FlowerDescriptor) {
2020-05-11 01:09:01 +00:00
b.Flower = desc
2020-05-17 08:56:56 +00:00
b.upToDate = false
2020-05-11 01:09:01 +00:00
}