Fixed remaining incompatibilities.

This commit is contained in:
Sander Schobers 2020-05-23 09:11:08 +02:00
parent b85f4e404d
commit 6493b3165b
12 changed files with 170 additions and 369 deletions

View File

@ -1,8 +1,6 @@
package tins2020
import (
"image/color"
"opslag.de/schobers/zntg/ui"
)
@ -11,7 +9,6 @@ import (
type ButtonBar struct {
ui.StackPanel
Background color.Color
ButtonLength float32
}

View File

@ -1,123 +1,148 @@
package tins2020
import (
"fmt"
"image/color"
"time"
"opslag.de/schobers/geom"
"opslag.de/schobers/zntg"
"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 {
IconButton
IconDisabled string
FlowerID string
Flower FlowerDescriptor
upToDate bool
hoverAnimation *zntg.Animation
hoverOffset int32
hoverTexture ui.Texture
priceTexture ui.Texture
hoverAnimation zntg.Animation
hoverOffset float32
hoverTexture TextureCache
priceTexture TextureCache
}
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
b.Disabled = !flower.Unlocked
}),
IconDisabled: iconDisabled,
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) animate() {
b.hoverOffset++
if b.hoverOffset > b.hoverTexture.Width()+b.Bounds().Dx() {
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) 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
text := b.fmtTooltipText()
font := ctx.Fonts().Font("small")
color := zntg.MustHexColor("#FFFFFF")
if err := b.hoverTexture.Update(textUpdate(ctx.Renderer(), font, color, text)); err != nil {
return err
}
if err := b.priceTexture.Update(textUpdate(ctx.Renderer(), font, color, FmtMoney(b.Flower.BuyPrice))); err != nil {
return err
}
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 {
func (b *BuyFlowerButton) Handle(ctx ui.Context, e 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
// }
b.IconButton.Handle(ctx, e)
if b.IsOver() && !b.hoverAnimation.IsActive() {
b.hoverAnimation.Interval = 10 * time.Millisecond
b.hoverAnimation.Start()
b.hoverOffset = b.priceTexture.Width()
} else if !b.IsOver() {
b.hoverAnimation.Pause()
}
return false
}
func (b *BuyFlowerButton) Render(ctx ui.Context) {
if !b.upToDate {
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)
// 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())
// }
b.hoverAnimation.AnimateFn(b.animate)
// 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))
// }
if b.IsOver() {
left := bounds.Dx() - 8 - b.hoverOffset
top := pos.Y + bounds.Dy() - 20
if left < 0 {
part := geom.RectF32(-left, 0, b.hoverTexture.Width(), b.hoverTexture.Height())
ctx.Renderer().DrawTexturePointOptions(b.hoverTexture.Value, geom.PtF32(pos.X, top), ui.DrawOptions{Source: &part})
} else {
ctx.Renderer().DrawTexturePoint(b.hoverTexture.Value, geom.PtF32(pos.X+left, top))
}
} else {
ctx.Renderer().DrawTexturePoint(b.priceTexture.Value, geom.PtF32(pos.X+bounds.Dx()-8-b.priceTexture.Width(), pos.Y+bounds.Dy()-20))
}
}
func (b *BuyFlowerButton) Update(desc FlowerDescriptor) {

View File

@ -9,10 +9,11 @@ import (
"opslag.de/schobers/geom"
"opslag.de/schobers/zntg"
"opslag.de/schobers/zntg/addons/res"
"opslag.de/schobers/zntg/play"
"opslag.de/schobers/zntg/ui"
_ "opslag.de/schobers/zntg/sdlui" // rendering backend
// _ "opslag.de/schobers/zntg/allg5ui" // rendering backend
// _ "opslag.de/schobers/zntg/sdlui" // rendering backend
_ "opslag.de/schobers/zntg/allg5ui" // rendering backend
rice "github.com/GeertJohan/go.rice"
"github.com/veandco/go-sdl2/sdl"
@ -74,13 +75,13 @@ func (a *app) Init(ctx ui.Context) error {
textureLoader := tins2020.NewResourceLoader()
textures := ctx.Textures()
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
}); err != nil {
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.AddChild(tins2020.NewTerrainRenderer(a.game))
@ -168,8 +169,9 @@ func run() error {
}
style := ui.DefaultStyle()
style.Palette = &ui.Palette{
Background: zntg.MustHexColor(`#5388C3`),
Primary: zntg.MustHexColor(`#5388C3`),
Background: zntg.MustHexColor(`#356DAD`),
Disabled: zntg.MustHexColor(`#DEDEDE`),
Primary: zntg.MustHexColor(`#356DAD`),
PrimaryDark: zntg.MustHexColor(`#15569F`),
PrimaryLight: zntg.MustHexColor(`#ABCAED`),
Secondary: zntg.MustHexColor(`#4AC69A`),
@ -178,8 +180,8 @@ func run() error {
Text: color.White,
TextOnPrimary: color.White,
TextOnSecondary: color.White,
TextNegative: zntg.MustHexColor(`F3590E`),
TextPositive: zntg.MustHexColor(`65D80D`),
TextNegative: zntg.MustHexColor(`#F3590E`),
TextPositive: zntg.MustHexColor(`#65D80D`),
}
return ui.Run(renderer, style, app)
}

View File

@ -4,8 +4,6 @@ import (
"opslag.de/schobers/zntg/ui"
)
// import "github.com/veandco/go-sdl2/sdl"
// Content shortcuts events when a dialog is opened.
type Content struct {
ui.Proxy

View File

@ -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 }

View File

@ -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})
// }

View File

@ -3,9 +3,12 @@ package tins2020
import (
"opslag.de/schobers/geom"
"opslag.de/schobers/zntg"
"opslag.de/schobers/zntg/play"
"opslag.de/schobers/zntg/ui"
)
const fpsOverlayName = "fps"
type GameControls struct {
ui.ContainerBase
@ -30,6 +33,7 @@ func NewGameControls(game *Game, dialogs *Dialogs) *GameControls {
}
func (c *GameControls) Init(ctx ui.Context) {
ctx.Overlays().AddOnTop(fpsOverlayName, &play.FPS{}, false)
c.game.SpeedChanged().AddHandler(c.speedChanged)
c.game.ToolChanged().AddHandler(c.toolChanged)
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.flowers.Background = zntg.MustHexColor("#356dad")
c.flowers.Background = zntg.MustHexColor("#356DAD")
c.flowers.ButtonLength = 64
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.game.Pause(ctx)
}, func(b *IconButton) {
b.IconDisabled = "control-pause-disabled"
b.DisabledColor = ctx.Style().Palette.Secondary
b.Tooltip = "Pause game"
})
c.run = NewIconButtonConfigure("control-run", func(ctx ui.Context) {
c.game.Run(ctx)
}, func(b *IconButton) {
b.IconDisabled = "control-run-disabled"
b.DisabledColor = ctx.Style().Palette.Secondary
b.Tooltip = "Run game at normal speed"
})
c.runFast = NewIconButtonConfigure("control-run-fast", func(ctx ui.Context) {
c.game.RunFast(ctx)
}, func(b *IconButton) {
b.IconDisabled = "control-run-fast-disabled"
b.DisabledColor = ctx.Style().Palette.Secondary
b.Tooltip = "Run game at fast speed"
})
c.speedChanged(nil, c.game.Speed)
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{
NewIconButtonConfigure("control-settings", c.dialogs.ShowSettings, func(b *IconButton) {
b.Disabled = true
b.IconDisabled = "#afafaf"
b.DisabledColor = zntg.MustHexColor("#AFAFAF")
}),
NewIconButtonConfigure("control-save", func(ui.Context) { c.game.Save() }, func(b *IconButton) {
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"
}),
}
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) {
b.IconHeight = 32
b.Tooltip = "Select harvest tool (key: H)"
})
c.research = NewIconButtonConfigure("control-research", c.dialogs.ShowResearch, func(b *IconButton) {
b.IconHeight = 32
b.Tooltip = "Conduct research (key: R)"
})
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.top)
@ -140,11 +148,11 @@ func (c *GameControls) toolChanged(_ ui.Context, state interface{}) {
}
for _, control := range c.flowers.Children {
button := control.(*BuyFlowerButton)
button.IsActive = button.FlowerID == flowerID
button.Active = button.FlowerID == flowerID
button.Disabled = !c.game.Herbarium.IsUnlocked(button.FlowerID)
}
_, shovel := tool.(*ShovelTool)
c.shovel.IsActive = shovel
c.shovel.Active = shovel
}
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.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.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 {
@ -191,17 +200,18 @@ func (c *GameControls) Handle(ctx ui.Context, event ui.Event) bool {
c.game.CancelTool(ctx)
}
return true
case ui.KeyF3:
case ui.KeyF4:
c.game.Debug = !c.game.Debug
ctx.Overlays().Toggle(fpsOverlayName)
}
}
return false
}
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.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)
}

View File

@ -1,40 +1,28 @@
package tins2020
import (
"image/color"
"opslag.de/schobers/zntg"
"opslag.de/schobers/zntg/ui"
)
// import (
// "github.com/veandco/go-sdl2/sdl"
// )
// type HoverEffect int
// const (
// HoverEffectLigthen HoverEffect = iota
// HoverEffectColor
// )
type IconButton struct {
ui.Button
IconDisabled string
// IconScale Scale
// IconWidth int32
// IconActive HoverEffect
// IconHover HoverEffect
// Tooltip Tooltip
IsActive bool
Active bool
}
func NewIconButton(icon string, click ui.EventEmptyFn) *IconButton {
b := &IconButton{
Button: ui.Button{
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) })
return b
}
@ -45,84 +33,15 @@ func NewIconButtonConfigure(icon string, click ui.EventEmptyFn, configure func(*
return button
}
// func (b *IconButton) activeTexture(ctx ui.Context) *Texture {
// if b.Disabled {
// texture := ctx.Textures.Texture(b.IconDisabled)
// if texture != nil {
// return texture
// }
var hoverTransparentColor = zntg.MustHexColor(`#FFFFFF1F`)
// texture = ctx.Textures.Texture(b.Icon)
// if len(b.IconDisabled) == 0 {
// return texture
// }
// color, err := HexColor(b.IconDisabled)
// if err == nil {
// texture.SetColor(color)
// }
// return texture
// }
// return ctx.Textures.Texture(b.Icon)
// }
func (b *IconButton) Render(ctx ui.Context) {
b.RenderActive(ctx)
b.Button.Render(ctx)
}
// func (b *IconButton) Arrange(ctx ui.Context, bounds Rectangle) {
// b.ControlBase.Arrange(ctx, bounds)
// b.Tooltip.Arrange(ctx, bounds)
// }
// 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
// )
func (b *IconButton) RenderActive(ctx ui.Context) {
if b.Active && !b.Disabled && !b.IsOver() {
ctx.Renderer().FillRectangle(b.Bounds(), hoverTransparentColor)
}
}

View File

@ -34,11 +34,6 @@ func NewLargeDialog(title string, content ui.Control) *LargeDialog {
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 {
if d.StackPanel.Handle(ctx, e) {
return true
@ -88,6 +83,7 @@ func NewLargeDialogTitleBar(title string, closeRequested ui.EventFn) *LargeDialo
titleBar.close.Icon = "control-cancel"
titleBar.close.IconHeight = 32
titleBar.close.Type = ui.ButtonTypeIcon
titleBar.close.HoverColor = zntg.MustHexColor(`#ABCAED`)
return titleBar
}
@ -97,7 +93,6 @@ func (b *LargeDialogTitleBar) Arrange(ctx ui.Context, bounds geom.RectangleF32,
b.title.Arrange(ctx, bounds, offset, parent)
height := bounds.Dy()
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 {

View File

@ -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)
// }

View File

@ -57,10 +57,6 @@ type Specialist struct {
func (r *Research) Arrange(ctx ui.Context, bounds geom.RectangleF32, offset geom.PointF32, parent ui.Control) {
r.input.TextAlignment = ui.AlignCenter
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 {

View File

@ -38,10 +38,8 @@ func (r *terrainRenderer) Init(ctx ui.Context) error {
}
func isControlKeyDown(ctx ui.Context) bool {
return false
// ctx.MousePosition()
// state := ui.GetKeyboardState()
// return state[ui.SCANCODE_LCTRL] == 1 || state[ui.SCANCODE_RCTRL] == 1 || state[ui.SCANCODE_LGUI] == 1 || state[ui.SCANCODE_RGUI] == 1
modifiers := ctx.KeyModifiers()
return modifiers&(ui.KeyModifierControl|ui.KeyModifierOSCommand) != 0
}
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) {
zoom := r.project.zoom
terrain := r.game.Terrain
toTileTexture := func(x, y int) ui.Texture {
temp := terrain.Temp.Value(x, y)
if temp < .35 {
return ctx.Textures().Texture("tile-snow")
return ctx.Textures().ScaledByName("tile-snow", zoom)
}
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 {
@ -146,9 +145,8 @@ func (r *terrainRenderer) Render(ctx ui.Context) {
variantToTexture := func(format string, variant float64) ui.Texture {
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) }
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)]
if ok {
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)
humid := terrain.Humid.Value(x, y)
@ -203,7 +201,7 @@ func (r *terrainRenderer) Render(ctx ui.Context) {
ctx.Renderer().DrawTexture(text, rect.ToF32())
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))
rect := r.project.screenToTileRect(pos)
ctx.Renderer().DrawTexture(text, rect.ToF32())
// ctx.Fonts().Text("debug", pos.ToF32(), color.White, fmt.Sprintf("%d, %d", x, y))
})
}