Fixed remaining incompatibilities.
This commit is contained in:
parent
b85f4e404d
commit
6493b3165b
@ -1,8 +1,6 @@
|
|||||||
package tins2020
|
package tins2020
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
|
||||||
|
|
||||||
"opslag.de/schobers/zntg/ui"
|
"opslag.de/schobers/zntg/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,7 +9,6 @@ import (
|
|||||||
type ButtonBar struct {
|
type ButtonBar struct {
|
||||||
ui.StackPanel
|
ui.StackPanel
|
||||||
|
|
||||||
Background color.Color
|
|
||||||
ButtonLength float32
|
ButtonLength float32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,123 +1,148 @@
|
|||||||
package tins2020
|
package tins2020
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"image/color"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"opslag.de/schobers/geom"
|
||||||
"opslag.de/schobers/zntg"
|
"opslag.de/schobers/zntg"
|
||||||
"opslag.de/schobers/zntg/ui"
|
"opslag.de/schobers/zntg/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type TextureCache struct {
|
||||||
|
Value ui.Texture
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *TextureCache) Height() float32 {
|
||||||
|
if c.Value == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return c.Value.Height()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *TextureCache) Update(update func() (ui.Texture, error)) error {
|
||||||
|
texture, err := update()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if c.Value != nil {
|
||||||
|
c.Value.Destroy()
|
||||||
|
}
|
||||||
|
c.Value = texture
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *TextureCache) Width() float32 {
|
||||||
|
if c.Value == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return c.Value.Width()
|
||||||
|
}
|
||||||
|
|
||||||
|
func textUpdate(render ui.Renderer, font ui.Font, color color.Color, text string) func() (ui.Texture, error) {
|
||||||
|
return func() (ui.Texture, error) { return render.TextTexture(font, color, text) }
|
||||||
|
}
|
||||||
|
|
||||||
type BuyFlowerButton struct {
|
type BuyFlowerButton struct {
|
||||||
IconButton
|
IconButton
|
||||||
|
|
||||||
|
IconDisabled string
|
||||||
FlowerID string
|
FlowerID string
|
||||||
Flower FlowerDescriptor
|
Flower FlowerDescriptor
|
||||||
|
|
||||||
upToDate bool
|
upToDate bool
|
||||||
hoverAnimation *zntg.Animation
|
hoverAnimation zntg.Animation
|
||||||
hoverOffset int32
|
hoverOffset float32
|
||||||
hoverTexture ui.Texture
|
hoverTexture TextureCache
|
||||||
priceTexture ui.Texture
|
priceTexture TextureCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBuyFlowerButton(icon, iconDisabled, flowerID string, flower FlowerDescriptor, click ui.EventEmptyFn) *BuyFlowerButton {
|
func NewBuyFlowerButton(icon, iconDisabled, flowerID string, flower FlowerDescriptor, click ui.EventEmptyFn) *BuyFlowerButton {
|
||||||
return &BuyFlowerButton{
|
return &BuyFlowerButton{
|
||||||
IconButton: *NewIconButtonConfigure(icon, click, func(b *IconButton) {
|
IconButton: *NewIconButtonConfigure(icon, click, func(b *IconButton) {
|
||||||
// b.IconDisabled = iconDisabled
|
b.Disabled = !flower.Unlocked
|
||||||
// b.Disabled = !flower.Unlocked
|
|
||||||
}),
|
}),
|
||||||
|
IconDisabled: iconDisabled,
|
||||||
FlowerID: flowerID,
|
FlowerID: flowerID,
|
||||||
Flower: flower,
|
Flower: flower,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (b *BuyFlowerButton) animate() {
|
func (b *BuyFlowerButton) animate() {
|
||||||
// b.hoverOffset++
|
b.hoverOffset++
|
||||||
// if b.hoverOffset > b.hoverTexture.Size().X+b.Bounds.W {
|
if b.hoverOffset > b.hoverTexture.Width()+b.Bounds().Dx() {
|
||||||
// b.hoverOffset = 0
|
b.hoverOffset = 0
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// func (b *BuyFlowerButton) fmtTooltipText() string {
|
func (b *BuyFlowerButton) fmtTooltipText() string {
|
||||||
// if !b.Flower.Unlocked {
|
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, "Traits are not known yet.")
|
||||||
// }
|
}
|
||||||
// return fmt.Sprintf("%s - %s - %s", FmtMoney(b.Flower.BuyPrice), b.Flower.Name, b.Flower.Description)
|
return fmt.Sprintf("%s - %s - %s", FmtMoney(b.Flower.BuyPrice), b.Flower.Name, b.Flower.Description)
|
||||||
// }
|
}
|
||||||
|
|
||||||
func (b *BuyFlowerButton) updateTexts(ctx ui.Context) error {
|
func (b *BuyFlowerButton) updateTexts(ctx ui.Context) error {
|
||||||
if b.upToDate {
|
if b.upToDate {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
text := b.fmtTooltipText()
|
||||||
// text := b.fmtTooltipText()
|
font := ctx.Fonts().Font("small")
|
||||||
// font := ctx.Fonts.Font("small")
|
color := zntg.MustHexColor("#FFFFFF")
|
||||||
// color := MustHexColor("#ffffff")
|
if err := b.hoverTexture.Update(textUpdate(ctx.Renderer(), font, color, text)); err != nil {
|
||||||
// texture, err := font.Render(ctx.Renderer, text, color)
|
return err
|
||||||
// if err != nil {
|
}
|
||||||
// return err
|
if err := b.priceTexture.Update(textUpdate(ctx.Renderer(), font, color, FmtMoney(b.Flower.BuyPrice))); 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
|
b.upToDate = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (b *BuyFlowerButton) Init(ctx ui.Context) error {
|
func (b *BuyFlowerButton) Handle(ctx ui.Context, e ui.Event) bool {
|
||||||
// return b.updateTexts(ctx)
|
|
||||||
// }
|
|
||||||
|
|
||||||
func (b *BuyFlowerButton) Handle(ctx ui.Context, event ui.Event) bool {
|
|
||||||
b.updateTexts(ctx)
|
b.updateTexts(ctx)
|
||||||
// if b.IconButton.Handle(ctx, event) {
|
b.IconButton.Handle(ctx, e)
|
||||||
// return true
|
if b.IsOver() && !b.hoverAnimation.IsActive() {
|
||||||
// }
|
b.hoverAnimation.Interval = 10 * time.Millisecond
|
||||||
// if b.IsMouseOver && b.hoverAnimation == nil {
|
b.hoverAnimation.Start()
|
||||||
// b.hoverAnimation = NewAnimationPtr(10 * time.Millisecond)
|
b.hoverOffset = b.priceTexture.Width()
|
||||||
// b.hoverOffset = b.priceTexture.Size().X
|
} else if !b.IsOver() {
|
||||||
// } else if !b.IsMouseOver {
|
b.hoverAnimation.Pause()
|
||||||
// b.hoverAnimation = nil
|
}
|
||||||
// }
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BuyFlowerButton) Render(ctx ui.Context) {
|
func (b *BuyFlowerButton) Render(ctx ui.Context) {
|
||||||
if !b.upToDate {
|
|
||||||
b.updateTexts(ctx)
|
b.updateTexts(ctx)
|
||||||
|
|
||||||
|
bounds := b.Bounds()
|
||||||
|
pos := bounds.Min
|
||||||
|
|
||||||
|
icon := ctx.Textures().Texture(b.Icon)
|
||||||
|
if !b.Flower.Unlocked {
|
||||||
|
disabled := ctx.Textures().Texture(b.IconDisabled)
|
||||||
|
if disabled != nil {
|
||||||
|
icon = disabled
|
||||||
}
|
}
|
||||||
// iconTexture := b.activeTexture(ctx)
|
}
|
||||||
|
ctx.Renderer().DrawTexture(icon, geom.RectRelF32(pos.X, pos.Y-60, bounds.Dx(), 120))
|
||||||
|
b.RenderActive(ctx)
|
||||||
|
|
||||||
// pos := Pt(b.Bounds.X, b.Bounds.Y)
|
b.hoverAnimation.AnimateFn(b.animate)
|
||||||
// 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 {
|
if b.IsOver() {
|
||||||
// b.hoverAnimation.AnimateFn(b.animate)
|
left := bounds.Dx() - 8 - b.hoverOffset
|
||||||
// }
|
top := pos.Y + bounds.Dy() - 20
|
||||||
|
if left < 0 {
|
||||||
// if b.IsMouseOver {
|
part := geom.RectF32(-left, 0, b.hoverTexture.Width(), b.hoverTexture.Height())
|
||||||
// left := b.Bounds.W - 8 - b.hoverOffset
|
ctx.Renderer().DrawTexturePointOptions(b.hoverTexture.Value, geom.PtF32(pos.X, top), ui.DrawOptions{Source: &part})
|
||||||
// top := pos.Y + b.Bounds.H - 20
|
} else {
|
||||||
// if left < 0 {
|
ctx.Renderer().DrawTexturePoint(b.hoverTexture.Value, geom.PtF32(pos.X+left, top))
|
||||||
// part := RectAbs(-left, 0, b.hoverTexture.Size().X, b.hoverTexture.Size().Y)
|
}
|
||||||
// b.hoverTexture.CopyPart(ctx.Renderer, part, Pt(pos.X, top))
|
} else {
|
||||||
// } else {
|
ctx.Renderer().DrawTexturePoint(b.priceTexture.Value, geom.PtF32(pos.X+bounds.Dx()-8-b.priceTexture.Width(), pos.Y+bounds.Dy()-20))
|
||||||
// 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) {
|
func (b *BuyFlowerButton) Update(desc FlowerDescriptor) {
|
||||||
|
@ -9,10 +9,11 @@ import (
|
|||||||
"opslag.de/schobers/geom"
|
"opslag.de/schobers/geom"
|
||||||
"opslag.de/schobers/zntg"
|
"opslag.de/schobers/zntg"
|
||||||
"opslag.de/schobers/zntg/addons/res"
|
"opslag.de/schobers/zntg/addons/res"
|
||||||
|
"opslag.de/schobers/zntg/play"
|
||||||
"opslag.de/schobers/zntg/ui"
|
"opslag.de/schobers/zntg/ui"
|
||||||
|
|
||||||
_ "opslag.de/schobers/zntg/sdlui" // rendering backend
|
// _ "opslag.de/schobers/zntg/sdlui" // rendering backend
|
||||||
// _ "opslag.de/schobers/zntg/allg5ui" // rendering backend
|
_ "opslag.de/schobers/zntg/allg5ui" // rendering backend
|
||||||
|
|
||||||
rice "github.com/GeertJohan/go.rice"
|
rice "github.com/GeertJohan/go.rice"
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
@ -74,13 +75,13 @@ func (a *app) Init(ctx ui.Context) error {
|
|||||||
textureLoader := tins2020.NewResourceLoader()
|
textureLoader := tins2020.NewResourceLoader()
|
||||||
textures := ctx.Textures()
|
textures := ctx.Textures()
|
||||||
if err := textureLoader.LoadFromFile(ctx.Resources(), "textures.txt", func(name, content string) error {
|
if err := textureLoader.LoadFromFile(ctx.Resources(), "textures.txt", func(name, content string) error {
|
||||||
_, err := textures.CreateTexturePath(name, content, false)
|
_, err := textures.CreateTexturePath(name, content, true)
|
||||||
return err
|
return err
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ctx.Overlays().AddOnTop("fps", &tins2020.FPS{Show: &a.game.Debug})
|
ctx.Overlays().AddOnTop("fps", &play.FPS{}, false)
|
||||||
|
|
||||||
content := tins2020.NewContent(a.dialogs)
|
content := tins2020.NewContent(a.dialogs)
|
||||||
content.AddChild(tins2020.NewTerrainRenderer(a.game))
|
content.AddChild(tins2020.NewTerrainRenderer(a.game))
|
||||||
@ -168,8 +169,9 @@ func run() error {
|
|||||||
}
|
}
|
||||||
style := ui.DefaultStyle()
|
style := ui.DefaultStyle()
|
||||||
style.Palette = &ui.Palette{
|
style.Palette = &ui.Palette{
|
||||||
Background: zntg.MustHexColor(`#5388C3`),
|
Background: zntg.MustHexColor(`#356DAD`),
|
||||||
Primary: zntg.MustHexColor(`#5388C3`),
|
Disabled: zntg.MustHexColor(`#DEDEDE`),
|
||||||
|
Primary: zntg.MustHexColor(`#356DAD`),
|
||||||
PrimaryDark: zntg.MustHexColor(`#15569F`),
|
PrimaryDark: zntg.MustHexColor(`#15569F`),
|
||||||
PrimaryLight: zntg.MustHexColor(`#ABCAED`),
|
PrimaryLight: zntg.MustHexColor(`#ABCAED`),
|
||||||
Secondary: zntg.MustHexColor(`#4AC69A`),
|
Secondary: zntg.MustHexColor(`#4AC69A`),
|
||||||
@ -178,8 +180,8 @@ func run() error {
|
|||||||
Text: color.White,
|
Text: color.White,
|
||||||
TextOnPrimary: color.White,
|
TextOnPrimary: color.White,
|
||||||
TextOnSecondary: color.White,
|
TextOnSecondary: color.White,
|
||||||
TextNegative: zntg.MustHexColor(`F3590E`),
|
TextNegative: zntg.MustHexColor(`#F3590E`),
|
||||||
TextPositive: zntg.MustHexColor(`65D80D`),
|
TextPositive: zntg.MustHexColor(`#65D80D`),
|
||||||
}
|
}
|
||||||
return ui.Run(renderer, style, app)
|
return ui.Run(renderer, style, app)
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,6 @@ import (
|
|||||||
"opslag.de/schobers/zntg/ui"
|
"opslag.de/schobers/zntg/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
// import "github.com/veandco/go-sdl2/sdl"
|
|
||||||
|
|
||||||
// Content shortcuts events when a dialog is opened.
|
// Content shortcuts events when a dialog is opened.
|
||||||
type Content struct {
|
type Content struct {
|
||||||
ui.Proxy
|
ui.Proxy
|
||||||
|
46
context.go
46
context.go
@ -1,46 +0,0 @@
|
|||||||
package tins2020
|
|
||||||
|
|
||||||
// import (
|
|
||||||
// rice "github.com/GeertJohan/go.rice"
|
|
||||||
// "github.com/veandco/go-sdl2/sdl"
|
|
||||||
// )
|
|
||||||
|
|
||||||
// type Context struct {
|
|
||||||
// Renderer *sdl.Renderer
|
|
||||||
// Fonts Fonts
|
|
||||||
// Resources Resources
|
|
||||||
// Textures Textures
|
|
||||||
// Settings Settings
|
|
||||||
// MousePosition geom.Point
|
|
||||||
// ShouldQuit bool
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func NewContext(res *rice.Box) (ui.Context, error) {
|
|
||||||
// ctx := &Context{}
|
|
||||||
// err := ctx.Settings.Init()
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
// err = ctx.Resources.Open(res)
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
// return ctx, nil
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (c ui.Context) Destroy() {
|
|
||||||
// c.Fonts.Destroy()
|
|
||||||
// c.Resources.Destroy()
|
|
||||||
// c.Textures.Destroy()
|
|
||||||
// c.Settings.Store()
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (c ui.Context) Init(renderer *sdl.Renderer) {
|
|
||||||
// c.Renderer = renderer
|
|
||||||
// c.Fonts.Init(c.Resources.Copy())
|
|
||||||
// c.Textures.Init(renderer, c.Resources.Copy())
|
|
||||||
|
|
||||||
// c.Renderer.SetDrawBlendMode(sdl.BLENDMODE_BLEND)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (c ui.Context) Quit() { c.ShouldQuit = true }
|
|
@ -1,46 +0,0 @@
|
|||||||
package tins2020
|
|
||||||
|
|
||||||
// import (
|
|
||||||
// "fmt"
|
|
||||||
// "time"
|
|
||||||
|
|
||||||
// "github.com/veandco/go-sdl2/sdl"
|
|
||||||
// )
|
|
||||||
|
|
||||||
// type FPS struct {
|
|
||||||
// ControlBase
|
|
||||||
|
|
||||||
// Show *bool
|
|
||||||
// start time.Time
|
|
||||||
// stamp time.Duration
|
|
||||||
// slot int
|
|
||||||
// ticks []int
|
|
||||||
// total int
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (f *FPS) Init(ui.Context) error {
|
|
||||||
// f.start = time.Now()
|
|
||||||
// f.stamp = 0
|
|
||||||
// f.ticks = make([]int, 51)
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (f *FPS) Render(ctx ui.Context) {
|
|
||||||
// if f.Show == nil || !*f.Show {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// elapsed := time.Since(f.start)
|
|
||||||
// stamp := elapsed / (20 * time.Millisecond)
|
|
||||||
// for f.stamp < stamp {
|
|
||||||
// f.total += f.ticks[f.slot]
|
|
||||||
// f.slot = (f.slot + 1) % len(f.ticks)
|
|
||||||
// f.total -= f.ticks[f.slot]
|
|
||||||
// f.ticks[f.slot] = 0
|
|
||||||
// f.stamp++
|
|
||||||
// }
|
|
||||||
// f.ticks[f.slot]++
|
|
||||||
|
|
||||||
// font := ctx.Fonts.Font("debug")
|
|
||||||
// font.RenderCopy(ctx.Renderer, fmt.Sprintf("FPS: %d", f.total), Pt(5, 17), sdl.Color{R: 255, G: 255, B: 255, A: 255})
|
|
||||||
// }
|
|
@ -3,9 +3,12 @@ package tins2020
|
|||||||
import (
|
import (
|
||||||
"opslag.de/schobers/geom"
|
"opslag.de/schobers/geom"
|
||||||
"opslag.de/schobers/zntg"
|
"opslag.de/schobers/zntg"
|
||||||
|
"opslag.de/schobers/zntg/play"
|
||||||
"opslag.de/schobers/zntg/ui"
|
"opslag.de/schobers/zntg/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const fpsOverlayName = "fps"
|
||||||
|
|
||||||
type GameControls struct {
|
type GameControls struct {
|
||||||
ui.ContainerBase
|
ui.ContainerBase
|
||||||
|
|
||||||
@ -30,6 +33,7 @@ func NewGameControls(game *Game, dialogs *Dialogs) *GameControls {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *GameControls) Init(ctx ui.Context) {
|
func (c *GameControls) Init(ctx ui.Context) {
|
||||||
|
ctx.Overlays().AddOnTop(fpsOverlayName, &play.FPS{}, false)
|
||||||
c.game.SpeedChanged().AddHandler(c.speedChanged)
|
c.game.SpeedChanged().AddHandler(c.speedChanged)
|
||||||
c.game.ToolChanged().AddHandler(c.toolChanged)
|
c.game.ToolChanged().AddHandler(c.toolChanged)
|
||||||
c.dialogs.DialogOpened().AddHandlerEmpty(func(ctx ui.Context) { c.game.Pause(ctx) })
|
c.dialogs.DialogOpened().AddHandlerEmpty(func(ctx ui.Context) { c.game.Pause(ctx) })
|
||||||
@ -38,7 +42,7 @@ func (c *GameControls) Init(ctx ui.Context) {
|
|||||||
c.game.Resume(ctx)
|
c.game.Resume(ctx)
|
||||||
})
|
})
|
||||||
|
|
||||||
c.flowers.Background = zntg.MustHexColor("#356dad")
|
c.flowers.Background = zntg.MustHexColor("#356DAD")
|
||||||
c.flowers.ButtonLength = 64
|
c.flowers.ButtonLength = 64
|
||||||
|
|
||||||
for _, id := range c.game.Herbarium.Flowers() {
|
for _, id := range c.game.Herbarium.Flowers() {
|
||||||
@ -49,29 +53,29 @@ func (c *GameControls) Init(ctx ui.Context) {
|
|||||||
c.pause = NewIconButtonConfigure("control-pause", func(ctx ui.Context) {
|
c.pause = NewIconButtonConfigure("control-pause", func(ctx ui.Context) {
|
||||||
c.game.Pause(ctx)
|
c.game.Pause(ctx)
|
||||||
}, func(b *IconButton) {
|
}, func(b *IconButton) {
|
||||||
b.IconDisabled = "control-pause-disabled"
|
b.DisabledColor = ctx.Style().Palette.Secondary
|
||||||
b.Tooltip = "Pause game"
|
b.Tooltip = "Pause game"
|
||||||
})
|
})
|
||||||
c.run = NewIconButtonConfigure("control-run", func(ctx ui.Context) {
|
c.run = NewIconButtonConfigure("control-run", func(ctx ui.Context) {
|
||||||
c.game.Run(ctx)
|
c.game.Run(ctx)
|
||||||
}, func(b *IconButton) {
|
}, func(b *IconButton) {
|
||||||
b.IconDisabled = "control-run-disabled"
|
b.DisabledColor = ctx.Style().Palette.Secondary
|
||||||
b.Tooltip = "Run game at normal speed"
|
b.Tooltip = "Run game at normal speed"
|
||||||
})
|
})
|
||||||
c.runFast = NewIconButtonConfigure("control-run-fast", func(ctx ui.Context) {
|
c.runFast = NewIconButtonConfigure("control-run-fast", func(ctx ui.Context) {
|
||||||
c.game.RunFast(ctx)
|
c.game.RunFast(ctx)
|
||||||
}, func(b *IconButton) {
|
}, func(b *IconButton) {
|
||||||
b.IconDisabled = "control-run-fast-disabled"
|
b.DisabledColor = ctx.Style().Palette.Secondary
|
||||||
b.Tooltip = "Run game at fast speed"
|
b.Tooltip = "Run game at fast speed"
|
||||||
})
|
})
|
||||||
c.speedChanged(nil, c.game.Speed)
|
c.speedChanged(nil, c.game.Speed)
|
||||||
c.top.Children = []ui.Control{c.pause, c.run, c.runFast}
|
c.top.Children = []ui.Control{c.pause, c.run, c.runFast}
|
||||||
|
|
||||||
c.menu.Background = zntg.MustHexColor("#356dad")
|
c.menu.Background = zntg.MustHexColor("#356DAD")
|
||||||
c.menu.Children = []ui.Control{
|
c.menu.Children = []ui.Control{
|
||||||
NewIconButtonConfigure("control-settings", c.dialogs.ShowSettings, func(b *IconButton) {
|
NewIconButtonConfigure("control-settings", c.dialogs.ShowSettings, func(b *IconButton) {
|
||||||
b.Disabled = true
|
b.Disabled = true
|
||||||
b.IconDisabled = "#afafaf"
|
b.DisabledColor = zntg.MustHexColor("#AFAFAF")
|
||||||
}),
|
}),
|
||||||
NewIconButtonConfigure("control-save", func(ui.Context) { c.game.Save() }, func(b *IconButton) {
|
NewIconButtonConfigure("control-save", func(ui.Context) { c.game.Save() }, func(b *IconButton) {
|
||||||
b.Tooltip = "Save game (overwrites previous save; no confirmation)"
|
b.Tooltip = "Save game (overwrites previous save; no confirmation)"
|
||||||
@ -92,16 +96,20 @@ func (c *GameControls) Init(ctx ui.Context) {
|
|||||||
b.Tooltip = "Show information/intro"
|
b.Tooltip = "Show information/intro"
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
for i, child := range c.menu.Children {
|
||||||
|
c.menu.Children[i] = ui.FixedHeight(child, 96)
|
||||||
|
}
|
||||||
|
|
||||||
c.shovel = NewIconButtonConfigure("control-shovel", func(ctx ui.Context) { c.game.SelectShovel(ctx) }, func(b *IconButton) {
|
c.shovel = NewIconButtonConfigure("control-shovel", func(ctx ui.Context) { c.game.SelectShovel(ctx) }, func(b *IconButton) {
|
||||||
b.IconHeight = 32
|
|
||||||
b.Tooltip = "Select harvest tool (key: H)"
|
b.Tooltip = "Select harvest tool (key: H)"
|
||||||
})
|
})
|
||||||
c.research = NewIconButtonConfigure("control-research", c.dialogs.ShowResearch, func(b *IconButton) {
|
c.research = NewIconButtonConfigure("control-research", c.dialogs.ShowResearch, func(b *IconButton) {
|
||||||
b.IconHeight = 32
|
|
||||||
b.Tooltip = "Conduct research (key: R)"
|
b.Tooltip = "Conduct research (key: R)"
|
||||||
})
|
})
|
||||||
c.otherTools.Children = []ui.Control{c.shovel, c.research}
|
c.otherTools.Children = []ui.Control{c.shovel, c.research}
|
||||||
|
for i, child := range c.otherTools.Children {
|
||||||
|
c.otherTools.Children[i] = ui.FixedHeight(child, 96)
|
||||||
|
}
|
||||||
|
|
||||||
c.AddChild(&c.menu)
|
c.AddChild(&c.menu)
|
||||||
c.AddChild(&c.top)
|
c.AddChild(&c.top)
|
||||||
@ -140,11 +148,11 @@ func (c *GameControls) toolChanged(_ ui.Context, state interface{}) {
|
|||||||
}
|
}
|
||||||
for _, control := range c.flowers.Children {
|
for _, control := range c.flowers.Children {
|
||||||
button := control.(*BuyFlowerButton)
|
button := control.(*BuyFlowerButton)
|
||||||
button.IsActive = button.FlowerID == flowerID
|
button.Active = button.FlowerID == flowerID
|
||||||
button.Disabled = !c.game.Herbarium.IsUnlocked(button.FlowerID)
|
button.Disabled = !c.game.Herbarium.IsUnlocked(button.FlowerID)
|
||||||
}
|
}
|
||||||
_, shovel := tool.(*ShovelTool)
|
_, shovel := tool.(*ShovelTool)
|
||||||
c.shovel.IsActive = shovel
|
c.shovel.Active = shovel
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GameControls) updateFlowerControls() {
|
func (c *GameControls) updateFlowerControls() {
|
||||||
@ -163,7 +171,8 @@ func (c *GameControls) Arrange(ctx ui.Context, bounds geom.RectangleF32, offset
|
|||||||
c.menu.Arrange(ctx, geom.RectRelF32(bounds.Min.X, bounds.Min.Y, buttonBarWidth, bounds.Dy()), offset, c)
|
c.menu.Arrange(ctx, geom.RectRelF32(bounds.Min.X, bounds.Min.Y, buttonBarWidth, bounds.Dy()), offset, c)
|
||||||
c.top.Arrange(ctx, geom.RectF32(bounds.Min.X+bounds.Dx()/2+8, bounds.Min.Y, bounds.Max.X, bounds.Min.Y+64), offset, c)
|
c.top.Arrange(ctx, geom.RectF32(bounds.Min.X+bounds.Dx()/2+8, bounds.Min.Y, bounds.Max.X, bounds.Min.Y+64), offset, c)
|
||||||
c.flowers.Arrange(ctx, geom.RectRelF32(bounds.Max.X-buttonBarWidth, bounds.Min.Y, buttonBarWidth, bounds.Dy()), offset, c)
|
c.flowers.Arrange(ctx, geom.RectRelF32(bounds.Max.X-buttonBarWidth, bounds.Min.Y, buttonBarWidth, bounds.Dy()), offset, c)
|
||||||
c.otherTools.Arrange(ctx, geom.RectRelF32(bounds.Max.X-buttonBarWidth, bounds.Max.Y-2*buttonBarWidth, buttonBarWidth, 2*buttonBarWidth), offset, c)
|
otherToolsSize := c.otherTools.DesiredSize(ctx, bounds.Size())
|
||||||
|
c.otherTools.Arrange(ctx, geom.RectRelF32(bounds.Max.X-buttonBarWidth, bounds.Max.Y-otherToolsSize.Y, buttonBarWidth, 2*buttonBarWidth), offset, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GameControls) Handle(ctx ui.Context, event ui.Event) bool {
|
func (c *GameControls) Handle(ctx ui.Context, event ui.Event) bool {
|
||||||
@ -191,17 +200,18 @@ func (c *GameControls) Handle(ctx ui.Context, event ui.Event) bool {
|
|||||||
c.game.CancelTool(ctx)
|
c.game.CancelTool(ctx)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
case ui.KeyF3:
|
case ui.KeyF4:
|
||||||
c.game.Debug = !c.game.Debug
|
c.game.Debug = !c.game.Debug
|
||||||
|
ctx.Overlays().Toggle(fpsOverlayName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GameControls) Render(ctx ui.Context) {
|
func (c *GameControls) Render(ctx ui.Context) {
|
||||||
topBar := zntg.MustHexColor("#0000007f")
|
topBar := zntg.MustHexColor("#0000007F")
|
||||||
ctx.Renderer().FillRectangle(geom.RectF32(c.menu.Bounds().Max.X, 0, c.flowers.Bounds().Min.X, 64), topBar)
|
ctx.Renderer().FillRectangle(geom.RectF32(c.menu.Bounds().Max.X, 0, c.flowers.Bounds().Min.X, 64), topBar)
|
||||||
ctx.Fonts().TextAlign("balance", geom.PtF32(c.top.Bounds().Min.X-8, 58), zntg.MustHexColor("#4AC69A"), FmtMoney(c.game.Balance), ui.AlignRight)
|
ctx.Fonts().TextAlign("balance", geom.PtF32(c.top.Bounds().Min.X-8, 4), zntg.MustHexColor("#4AC69A"), FmtMoney(c.game.Balance), ui.AlignRight)
|
||||||
|
|
||||||
c.ContainerBase.Render(ctx)
|
c.ContainerBase.Render(ctx)
|
||||||
}
|
}
|
||||||
|
117
iconbutton.go
117
iconbutton.go
@ -1,40 +1,28 @@
|
|||||||
package tins2020
|
package tins2020
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"image/color"
|
||||||
|
|
||||||
|
"opslag.de/schobers/zntg"
|
||||||
"opslag.de/schobers/zntg/ui"
|
"opslag.de/schobers/zntg/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
// import (
|
|
||||||
// "github.com/veandco/go-sdl2/sdl"
|
|
||||||
// )
|
|
||||||
|
|
||||||
// type HoverEffect int
|
|
||||||
|
|
||||||
// const (
|
|
||||||
// HoverEffectLigthen HoverEffect = iota
|
|
||||||
// HoverEffectColor
|
|
||||||
// )
|
|
||||||
|
|
||||||
type IconButton struct {
|
type IconButton struct {
|
||||||
ui.Button
|
ui.Button
|
||||||
|
|
||||||
IconDisabled string
|
Active bool
|
||||||
// IconScale Scale
|
|
||||||
// IconWidth int32
|
|
||||||
|
|
||||||
// IconActive HoverEffect
|
|
||||||
// IconHover HoverEffect
|
|
||||||
|
|
||||||
// Tooltip Tooltip
|
|
||||||
IsActive bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIconButton(icon string, click ui.EventEmptyFn) *IconButton {
|
func NewIconButton(icon string, click ui.EventEmptyFn) *IconButton {
|
||||||
b := &IconButton{
|
b := &IconButton{
|
||||||
Button: ui.Button{
|
Button: ui.Button{
|
||||||
Icon: icon,
|
Icon: icon,
|
||||||
|
IconHeight: 48,
|
||||||
|
Type: ui.ButtonTypeText,
|
||||||
|
HoverColor: hoverTransparentColor,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
b.Font.Color = color.White
|
||||||
b.ButtonClicked().AddHandler(func(ctx ui.Context, _ ui.ControlClickedArgs) { click(ctx) })
|
b.ButtonClicked().AddHandler(func(ctx ui.Context, _ ui.ControlClickedArgs) { click(ctx) })
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
@ -45,84 +33,15 @@ func NewIconButtonConfigure(icon string, click ui.EventEmptyFn, configure func(*
|
|||||||
return button
|
return button
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (b *IconButton) activeTexture(ctx ui.Context) *Texture {
|
var hoverTransparentColor = zntg.MustHexColor(`#FFFFFF1F`)
|
||||||
// if b.Disabled {
|
|
||||||
// texture := ctx.Textures.Texture(b.IconDisabled)
|
|
||||||
// if texture != nil {
|
|
||||||
// return texture
|
|
||||||
// }
|
|
||||||
|
|
||||||
// texture = ctx.Textures.Texture(b.Icon)
|
func (b *IconButton) Render(ctx ui.Context) {
|
||||||
// if len(b.IconDisabled) == 0 {
|
b.RenderActive(ctx)
|
||||||
// return texture
|
b.Button.Render(ctx)
|
||||||
// }
|
}
|
||||||
// color, err := HexColor(b.IconDisabled)
|
|
||||||
// if err == nil {
|
|
||||||
// texture.SetColor(color)
|
|
||||||
// }
|
|
||||||
// return texture
|
|
||||||
// }
|
|
||||||
// return ctx.Textures.Texture(b.Icon)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (b *IconButton) Arrange(ctx ui.Context, bounds Rectangle) {
|
func (b *IconButton) RenderActive(ctx ui.Context) {
|
||||||
// b.ControlBase.Arrange(ctx, bounds)
|
if b.Active && !b.Disabled && !b.IsOver() {
|
||||||
// b.Tooltip.Arrange(ctx, bounds)
|
ctx.Renderer().FillRectangle(b.Bounds(), hoverTransparentColor)
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
// func (b *IconButton) Handle(ctx ui.Context, event sdl.Event) bool {
|
|
||||||
// if b.ControlBase.Handle(ctx, event) {
|
|
||||||
// return true
|
|
||||||
// }
|
|
||||||
// if b.Tooltip.Handle(ctx, event) {
|
|
||||||
// return true
|
|
||||||
// }
|
|
||||||
// return false
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (b *IconButton) Init(ctx ui.Context) error {
|
|
||||||
// if err := b.ControlBase.Init(ctx); err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// if err := b.Tooltip.Init(ctx); err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (b *IconButton) Render(ctx ui.Context) {
|
|
||||||
// iconTexture := b.activeTexture(ctx)
|
|
||||||
|
|
||||||
// hover := b.IsMouseOver && !b.Disabled
|
|
||||||
// if (hover && b.IconHover == HoverEffectColor) || (b.IsActive && b.IconActive == HoverEffectColor) {
|
|
||||||
// iconTexture.SetColor(MustHexColor("#15569F"))
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if b.IconScale == ScaleCenter {
|
|
||||||
// size := iconTexture.Size()
|
|
||||||
// if b.IconWidth != 0 {
|
|
||||||
// size = Pt(b.IconWidth, b.IconWidth*size.Y/size.X)
|
|
||||||
// } else if b.IconHeight != 0 {
|
|
||||||
// size = Pt(b.IconHeight*size.X/size.Y, b.IconHeight)
|
|
||||||
// }
|
|
||||||
// iconTexture.CopyResize(ctx.Renderer, Rect(b.Bounds.X+(b.Bounds.W-size.X)/2, b.Bounds.Y+(b.Bounds.H-size.Y)/2, size.X, size.Y))
|
|
||||||
// } else {
|
|
||||||
// iconTexture.CopyResize(ctx.Renderer, b.Bounds)
|
|
||||||
// }
|
|
||||||
// if (hover && b.IconHover == HoverEffectLigthen) || (b.IsActive && b.IconActive == HoverEffectLigthen) {
|
|
||||||
// SetDrawColor(ctx.Renderer, TransparentWhite)
|
|
||||||
// ctx.Renderer.FillRect(b.Bounds.SDLPtr())
|
|
||||||
// }
|
|
||||||
// iconTexture.SetColor(White)
|
|
||||||
|
|
||||||
// if len(b.Tooltip.Text) > 0 && b.IsMouseOver {
|
|
||||||
// b.Tooltip.Render(ctx)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// type Scale int
|
|
||||||
|
|
||||||
// const (
|
|
||||||
// ScaleCenter Scale = iota
|
|
||||||
// ScaleStretch
|
|
||||||
// )
|
|
||||||
|
@ -34,11 +34,6 @@ func NewLargeDialog(title string, content ui.Control) *LargeDialog {
|
|||||||
|
|
||||||
func (d *LargeDialog) CloseRequested() ui.EventHandler { return &d.closeRequested }
|
func (d *LargeDialog) CloseRequested() ui.EventHandler { return &d.closeRequested }
|
||||||
|
|
||||||
// func (d *LargeDialog) Arrange(ctx ui.Context, bounds geom.RectangleF32, offset geom.PointF32, parent ui.Control) {
|
|
||||||
// d.titleBar.Arrange(ctx, bounds.Min.RectRel2D(bounds.Dx(), titleHeight), offset, d)
|
|
||||||
// d.content.Arrange(ctx, geom.RectRelF32(bounds.Min.X+titleHeight, bounds.Min.Y, bounds.Dx(), bounds.Dy()-titleHeight), offset, d)
|
|
||||||
// }
|
|
||||||
|
|
||||||
func (d *LargeDialog) Handle(ctx ui.Context, e ui.Event) bool {
|
func (d *LargeDialog) Handle(ctx ui.Context, e ui.Event) bool {
|
||||||
if d.StackPanel.Handle(ctx, e) {
|
if d.StackPanel.Handle(ctx, e) {
|
||||||
return true
|
return true
|
||||||
@ -88,6 +83,7 @@ func NewLargeDialogTitleBar(title string, closeRequested ui.EventFn) *LargeDialo
|
|||||||
titleBar.close.Icon = "control-cancel"
|
titleBar.close.Icon = "control-cancel"
|
||||||
titleBar.close.IconHeight = 32
|
titleBar.close.IconHeight = 32
|
||||||
titleBar.close.Type = ui.ButtonTypeIcon
|
titleBar.close.Type = ui.ButtonTypeIcon
|
||||||
|
titleBar.close.HoverColor = zntg.MustHexColor(`#ABCAED`)
|
||||||
|
|
||||||
return titleBar
|
return titleBar
|
||||||
}
|
}
|
||||||
@ -97,7 +93,6 @@ func (b *LargeDialogTitleBar) Arrange(ctx ui.Context, bounds geom.RectangleF32,
|
|||||||
b.title.Arrange(ctx, bounds, offset, parent)
|
b.title.Arrange(ctx, bounds, offset, parent)
|
||||||
height := bounds.Dy()
|
height := bounds.Dy()
|
||||||
b.close.Arrange(ctx, geom.RectRelF32(bounds.Max.X-height, bounds.Min.Y, height, height), offset, parent)
|
b.close.Arrange(ctx, geom.RectRelF32(bounds.Max.X-height, bounds.Min.Y, height, height), offset, parent)
|
||||||
b.close.HoverColor = ctx.Style().Palette.PrimaryDark
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *LargeDialogTitleBar) DesiredSize(ctx ui.Context, size geom.PointF32) geom.PointF32 {
|
func (b *LargeDialogTitleBar) DesiredSize(ctx ui.Context, size geom.PointF32) geom.PointF32 {
|
||||||
|
48
proxy.go
48
proxy.go
@ -1,48 +0,0 @@
|
|||||||
package tins2020
|
|
||||||
|
|
||||||
// import "github.com/veandco/go-sdl2/sdl"
|
|
||||||
|
|
||||||
// var _ Control = &Proxy{}
|
|
||||||
|
|
||||||
// type Proxy struct {
|
|
||||||
// Proxied Control
|
|
||||||
|
|
||||||
// bounds Rectangle
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (p *Proxy) Arrange(ctx ui.Context, bounds Rectangle) {
|
|
||||||
// p.bounds = bounds
|
|
||||||
// if p.Proxied == nil {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// p.Proxied.Arrange(ctx, bounds)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (p *Proxy) Handle(ctx ui.Context, event sdl.Event) bool {
|
|
||||||
// if p.Proxied == nil {
|
|
||||||
// return false
|
|
||||||
// }
|
|
||||||
// return p.Proxied.Handle(ctx, event)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (p *Proxy) Init(ctx ui.Context) error {
|
|
||||||
// if p.Proxied == nil {
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
// return p.Proxied.Init(ctx)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (p *Proxy) Render(ctx ui.Context) {
|
|
||||||
// if p.Proxied == nil {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// p.Proxied.Render(ctx)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (p *Proxy) SetContent(ctx ui.Context, content Control) {
|
|
||||||
// p.Proxied = content
|
|
||||||
// if content == nil {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// content.Arrange(ctx, p.bounds)
|
|
||||||
// }
|
|
@ -57,10 +57,6 @@ type Specialist struct {
|
|||||||
func (r *Research) Arrange(ctx ui.Context, bounds geom.RectangleF32, offset geom.PointF32, parent ui.Control) {
|
func (r *Research) Arrange(ctx ui.Context, bounds geom.RectangleF32, offset geom.PointF32, parent ui.Control) {
|
||||||
r.input.TextAlignment = ui.AlignCenter
|
r.input.TextAlignment = ui.AlignCenter
|
||||||
r.StackPanel.Arrange(ctx, bounds, offset, parent)
|
r.StackPanel.Arrange(ctx, bounds, offset, parent)
|
||||||
|
|
||||||
// size := bounds.Size()
|
|
||||||
// r.specialists.Arrange(ctx, geom.RectRelF32(bounds.Min.X, bounds.Min.Y+40, size.X, size.Y-40), offset, r)
|
|
||||||
// r.input.Arrange(ctx, geom.RectRelF32(bounds.Min.X, bounds.Min.X+size.Y-48, size.X, 24), offset, r)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Research) CanUserType(digit int) bool {
|
func (r *Research) CanUserType(digit int) bool {
|
||||||
|
@ -38,10 +38,8 @@ func (r *terrainRenderer) Init(ctx ui.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isControlKeyDown(ctx ui.Context) bool {
|
func isControlKeyDown(ctx ui.Context) bool {
|
||||||
return false
|
modifiers := ctx.KeyModifiers()
|
||||||
// ctx.MousePosition()
|
return modifiers&(ui.KeyModifierControl|ui.KeyModifierOSCommand) != 0
|
||||||
// state := ui.GetKeyboardState()
|
|
||||||
// return state[ui.SCANCODE_LCTRL] == 1 || state[ui.SCANCODE_RCTRL] == 1 || state[ui.SCANCODE_LGUI] == 1 || state[ui.SCANCODE_RGUI] == 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *terrainRenderer) Handle(ctx ui.Context, event ui.Event) bool {
|
func (r *terrainRenderer) Handle(ctx ui.Context, event ui.Event) bool {
|
||||||
@ -116,16 +114,17 @@ func (r *terrainRenderer) Handle(ctx ui.Context, event ui.Event) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *terrainRenderer) Render(ctx ui.Context) {
|
func (r *terrainRenderer) Render(ctx ui.Context) {
|
||||||
|
zoom := r.project.zoom
|
||||||
terrain := r.game.Terrain
|
terrain := r.game.Terrain
|
||||||
toTileTexture := func(x, y int) ui.Texture {
|
toTileTexture := func(x, y int) ui.Texture {
|
||||||
temp := terrain.Temp.Value(x, y)
|
temp := terrain.Temp.Value(x, y)
|
||||||
if temp < .35 {
|
if temp < .35 {
|
||||||
return ctx.Textures().Texture("tile-snow")
|
return ctx.Textures().ScaledByName("tile-snow", zoom)
|
||||||
}
|
}
|
||||||
if temp > .65 {
|
if temp > .65 {
|
||||||
return ctx.Textures().Texture("tile-dirt")
|
return ctx.Textures().ScaledByName("tile-dirt", zoom)
|
||||||
}
|
}
|
||||||
return ctx.Textures().Texture("tile-grass")
|
return ctx.Textures().ScaledByName("tile-grass", zoom)
|
||||||
}
|
}
|
||||||
|
|
||||||
variantToInt := func(variant float64) int {
|
variantToInt := func(variant float64) int {
|
||||||
@ -146,9 +145,8 @@ func (r *terrainRenderer) Render(ctx ui.Context) {
|
|||||||
|
|
||||||
variantToTexture := func(format string, variant float64) ui.Texture {
|
variantToTexture := func(format string, variant float64) ui.Texture {
|
||||||
textName := fmt.Sprintf(format, variantToInt(variant))
|
textName := fmt.Sprintf(format, variantToInt(variant))
|
||||||
return ctx.Textures().Texture(textName)
|
return ctx.Textures().ScaledByName(textName, zoom)
|
||||||
}
|
}
|
||||||
|
|
||||||
stretch := func(x, from, to float64) float64 { return (x - from) * 1 / (to - from) }
|
stretch := func(x, from, to float64) float64 { return (x - from) * 1 / (to - from) }
|
||||||
|
|
||||||
toPropTexture := func(temp, humid, variant float64) ui.Texture {
|
toPropTexture := func(temp, humid, variant float64) ui.Texture {
|
||||||
@ -186,7 +184,7 @@ func (r *terrainRenderer) Render(ctx ui.Context) {
|
|||||||
flower, ok := terrain.Flowers[geom.Pt(x, y)]
|
flower, ok := terrain.Flowers[geom.Pt(x, y)]
|
||||||
if ok {
|
if ok {
|
||||||
desc, _ := r.game.Herbarium.Find(flower.ID)
|
desc, _ := r.game.Herbarium.Find(flower.ID)
|
||||||
return ctx.Textures().Texture(desc.IconTemplate.Variant(variantToInt(variant)))
|
return ctx.Textures().ScaledByName(desc.IconTemplate.Variant(variantToInt(variant)), zoom)
|
||||||
}
|
}
|
||||||
temp := terrain.Temp.Value(x, y)
|
temp := terrain.Temp.Value(x, y)
|
||||||
humid := terrain.Humid.Value(x, y)
|
humid := terrain.Humid.Value(x, y)
|
||||||
@ -203,7 +201,7 @@ func (r *terrainRenderer) Render(ctx ui.Context) {
|
|||||||
ctx.Renderer().DrawTexture(text, rect.ToF32())
|
ctx.Renderer().DrawTexture(text, rect.ToF32())
|
||||||
|
|
||||||
if r.hover != nil && x == r.hover.X && y == r.hover.Y {
|
if r.hover != nil && x == r.hover.X && y == r.hover.Y {
|
||||||
ctx.Renderer().DrawTexture(ctx.Textures().Texture("tile-hover"), rect.ToF32())
|
ctx.Renderer().DrawTexture(ctx.Textures().ScaledByName("tile-hover", zoom), rect.ToF32())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -217,5 +215,6 @@ func (r *terrainRenderer) Render(ctx ui.Context) {
|
|||||||
pos = r.project.mapToScreenF(float32(x)-.2+float32(.9*placeX-.45), float32(y)-.2+float32(.9*placeY-.45))
|
pos = r.project.mapToScreenF(float32(x)-.2+float32(.9*placeX-.45), float32(y)-.2+float32(.9*placeY-.45))
|
||||||
rect := r.project.screenToTileRect(pos)
|
rect := r.project.screenToTileRect(pos)
|
||||||
ctx.Renderer().DrawTexture(text, rect.ToF32())
|
ctx.Renderer().DrawTexture(text, rect.ToF32())
|
||||||
|
// ctx.Fonts().Text("debug", pos.ToF32(), color.White, fmt.Sprintf("%d, %d", x, y))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user