Compare commits
3 Commits
1008b7b34b
...
ee7f99166c
Author | SHA1 | Date | |
---|---|---|---|
ee7f99166c | |||
bfe0c9003d | |||
8236b65c06 |
8
color.go
8
color.go
@ -11,6 +11,14 @@ var Transparent = sdl.Color{R: 0, G: 0, B: 0, A: 0}
|
||||
var TransparentWhite = sdl.Color{R: 255, G: 255, B: 255, A: 31}
|
||||
var White = sdl.Color{R: 255, G: 255, B: 255, A: 255}
|
||||
|
||||
func HexColor(s string) (sdl.Color, error) {
|
||||
c, err := img.HexColor(s)
|
||||
if err != nil {
|
||||
return sdl.Color{}, err
|
||||
}
|
||||
return sdl.Color(c), nil
|
||||
}
|
||||
|
||||
func MustHexColor(s string) sdl.Color { return sdl.Color(img.MustHexColor(s)) }
|
||||
|
||||
func SetDrawColor(renderer *sdl.Renderer, color sdl.Color) {
|
||||
|
@ -22,6 +22,7 @@ func EmptyEvent(fn EventFn) EventContextFn {
|
||||
type ControlBase struct {
|
||||
Bounds Rectangle
|
||||
|
||||
IsDisabled bool
|
||||
IsMouseOver bool
|
||||
|
||||
OnLeftMouseButtonClick EventContextFn
|
||||
@ -36,7 +37,7 @@ func (b *ControlBase) Handle(ctx *Context, event sdl.Event) bool {
|
||||
case *sdl.MouseMotionEvent:
|
||||
b.IsMouseOver = b.Bounds.IsPointInside(e.X, e.Y)
|
||||
case *sdl.MouseButtonEvent:
|
||||
if b.IsMouseOver && e.Button == sdl.BUTTON_LEFT && e.Type == sdl.MOUSEBUTTONDOWN {
|
||||
if !b.IsDisabled && b.IsMouseOver && e.Button == sdl.BUTTON_LEFT && e.Type == sdl.MOUSEBUTTONDOWN {
|
||||
return b.Invoke(ctx, b.OnLeftMouseButtonClick)
|
||||
}
|
||||
case *sdl.WindowEvent:
|
||||
|
@ -120,7 +120,10 @@ func (c *GameControls) Init(ctx *Context) error {
|
||||
|
||||
c.menu.Background = MustHexColor("#356dad")
|
||||
c.menu.Buttons = []Control{
|
||||
NewIconButton("control-settings", c.dialogs.ShowSettings),
|
||||
NewIconButtonConfig("control-settings", c.dialogs.ShowSettings, func(b *IconButton) {
|
||||
b.IsDisabled = true
|
||||
b.IconDisabled = "#afafaf"
|
||||
}),
|
||||
NewIconButton("control-save", func(*Context) { c.game.Save() }),
|
||||
NewIconButton("control-load", func(ctx *Context) {
|
||||
c.game.Load()
|
||||
|
@ -19,8 +19,7 @@ type IconButton struct {
|
||||
IconActive HoverEffect
|
||||
IconHover HoverEffect
|
||||
|
||||
IsActive bool
|
||||
IsDisabled bool
|
||||
IsActive bool
|
||||
}
|
||||
|
||||
func NewIconButton(icon string, onClick EventContextFn) *IconButton {
|
||||
@ -44,6 +43,16 @@ func (b *IconButton) activeTexture(ctx *Context) *Texture {
|
||||
if texture != nil {
|
||||
return texture
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func (r *terrainRenderer) Init(ctx *Context) error {
|
||||
|
||||
func isControlKeyDown() bool {
|
||||
state := sdl.GetKeyboardState()
|
||||
return state[sdl.SCANCODE_LCTRL] == 1 || state[sdl.SCANCODE_RCTRL] == 1
|
||||
return state[sdl.SCANCODE_LCTRL] == 1 || state[sdl.SCANCODE_RCTRL] == 1 || state[sdl.SCANCODE_LGUI] == 1 || state[sdl.SCANCODE_RGUI] == 1
|
||||
}
|
||||
|
||||
func (r *terrainRenderer) Handle(ctx *Context, event sdl.Event) bool {
|
||||
|
Loading…
Reference in New Issue
Block a user