127 lines
3.3 KiB
Go
127 lines
3.3 KiB
Go
package tins2020
|
|
|
|
import (
|
|
"opslag.de/schobers/zntg"
|
|
"opslag.de/schobers/zntg/ui"
|
|
)
|
|
|
|
type BuyFlowerButton struct {
|
|
IconButton
|
|
|
|
FlowerID string
|
|
Flower FlowerDescriptor
|
|
|
|
upToDate bool
|
|
hoverAnimation *zntg.Animation
|
|
hoverOffset int32
|
|
hoverTexture ui.Texture
|
|
priceTexture ui.Texture
|
|
}
|
|
|
|
func NewBuyFlowerButton(icon, iconDisabled, flowerID string, flower FlowerDescriptor, click ui.EventEmptyFn) *BuyFlowerButton {
|
|
return &BuyFlowerButton{
|
|
IconButton: *NewIconButtonConfigure(icon, click, func(b *IconButton) {
|
|
// b.IconDisabled = iconDisabled
|
|
// b.Disabled = !flower.Unlocked
|
|
}),
|
|
FlowerID: flowerID,
|
|
Flower: flower,
|
|
}
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// func (b *BuyFlowerButton) Init(ctx ui.Context) error {
|
|
// return b.updateTexts(ctx)
|
|
// }
|
|
|
|
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
|
|
}
|
|
|
|
func (b *BuyFlowerButton) Render(ctx ui.Context) {
|
|
if !b.upToDate {
|
|
b.updateTexts(ctx)
|
|
}
|
|
// 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))
|
|
// }
|
|
}
|
|
|
|
func (b *BuyFlowerButton) Update(desc FlowerDescriptor) {
|
|
b.Flower = desc
|
|
b.upToDate = false
|
|
}
|