Compare commits

..

3 Commits

5 changed files with 26 additions and 5 deletions

View File

@ -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 TransparentWhite = sdl.Color{R: 255, G: 255, B: 255, A: 31}
var White = sdl.Color{R: 255, G: 255, B: 255, A: 255} 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 MustHexColor(s string) sdl.Color { return sdl.Color(img.MustHexColor(s)) }
func SetDrawColor(renderer *sdl.Renderer, color sdl.Color) { func SetDrawColor(renderer *sdl.Renderer, color sdl.Color) {

View File

@ -22,6 +22,7 @@ func EmptyEvent(fn EventFn) EventContextFn {
type ControlBase struct { type ControlBase struct {
Bounds Rectangle Bounds Rectangle
IsDisabled bool
IsMouseOver bool IsMouseOver bool
OnLeftMouseButtonClick EventContextFn OnLeftMouseButtonClick EventContextFn
@ -36,7 +37,7 @@ func (b *ControlBase) Handle(ctx *Context, event sdl.Event) bool {
case *sdl.MouseMotionEvent: case *sdl.MouseMotionEvent:
b.IsMouseOver = b.Bounds.IsPointInside(e.X, e.Y) b.IsMouseOver = b.Bounds.IsPointInside(e.X, e.Y)
case *sdl.MouseButtonEvent: 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) return b.Invoke(ctx, b.OnLeftMouseButtonClick)
} }
case *sdl.WindowEvent: case *sdl.WindowEvent:

View File

@ -120,7 +120,10 @@ func (c *GameControls) Init(ctx *Context) error {
c.menu.Background = MustHexColor("#356dad") c.menu.Background = MustHexColor("#356dad")
c.menu.Buttons = []Control{ 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-save", func(*Context) { c.game.Save() }),
NewIconButton("control-load", func(ctx *Context) { NewIconButton("control-load", func(ctx *Context) {
c.game.Load() c.game.Load()

View File

@ -19,8 +19,7 @@ type IconButton struct {
IconActive HoverEffect IconActive HoverEffect
IconHover HoverEffect IconHover HoverEffect
IsActive bool IsActive bool
IsDisabled bool
} }
func NewIconButton(icon string, onClick EventContextFn) *IconButton { func NewIconButton(icon string, onClick EventContextFn) *IconButton {
@ -44,6 +43,16 @@ func (b *IconButton) activeTexture(ctx *Context) *Texture {
if texture != nil { if texture != nil {
return texture 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) return ctx.Textures.Texture(b.Icon)
} }

View File

@ -34,7 +34,7 @@ func (r *terrainRenderer) Init(ctx *Context) error {
func isControlKeyDown() bool { func isControlKeyDown() bool {
state := sdl.GetKeyboardState() 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 { func (r *terrainRenderer) Handle(ctx *Context, event sdl.Event) bool {