2020-05-10 15:16:18 +00:00
|
|
|
package tins2020
|
|
|
|
|
|
|
|
import (
|
2020-05-17 08:56:56 +00:00
|
|
|
"opslag.de/schobers/zntg"
|
|
|
|
"opslag.de/schobers/zntg/ui"
|
2020-05-10 15:16:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type BuyFlowerButton struct {
|
|
|
|
IconButton
|
|
|
|
|
2020-05-10 21:00:19 +00:00
|
|
|
FlowerID string
|
|
|
|
Flower FlowerDescriptor
|
2020-05-10 18:44:20 +00:00
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
upToDate bool
|
|
|
|
hoverAnimation *zntg.Animation
|
2020-05-10 15:16:18 +00:00
|
|
|
hoverOffset int32
|
2020-05-17 08:56:56 +00:00
|
|
|
hoverTexture ui.Texture
|
|
|
|
priceTexture ui.Texture
|
2020-05-10 15:16:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
func NewBuyFlowerButton(icon, iconDisabled, flowerID string, flower FlowerDescriptor, click ui.EventEmptyFn) *BuyFlowerButton {
|
2020-05-10 15:16:18 +00:00
|
|
|
return &BuyFlowerButton{
|
2020-05-17 08:56:56 +00:00
|
|
|
IconButton: *NewIconButtonConfigure(icon, click, func(b *IconButton) {
|
|
|
|
// b.IconDisabled = iconDisabled
|
|
|
|
// b.Disabled = !flower.Unlocked
|
2020-05-10 15:16:18 +00:00
|
|
|
}),
|
2020-05-10 21:00:19 +00:00
|
|
|
FlowerID: flowerID,
|
|
|
|
Flower: flower,
|
2020-05-10 15:16:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-10 21:00:19 +00:00
|
|
|
}
|
2020-05-10 15:16:18 +00:00
|
|
|
|
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
|
2020-05-10 15:16:18 +00:00
|
|
|
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
|
|
|
|
// }
|
2020-05-11 09:44:50 +00:00
|
|
|
return false
|
2020-05-10 15:16:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
func (b *BuyFlowerButton) Render(ctx ui.Context) {
|
|
|
|
if !b.upToDate {
|
|
|
|
b.updateTexts(ctx)
|
2020-05-10 15:16:18 +00:00
|
|
|
}
|
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-10 15:16:18 +00:00
|
|
|
}
|
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
|
|
|
}
|