Added disabled flowers (for button bar).

This commit is contained in:
Sander Schobers 2020-05-10 01:40:54 +02:00
parent cbb6e6c144
commit d6502c9080
9 changed files with 49 additions and 4 deletions

View File

@ -26,7 +26,16 @@ func run() error {
for _, path := range flags.Args() {
err := setAlpha(path, alpha)
if err != nil {
return fmt.Errorf("couldn't set alpha for '%s'; error: %v", path, err)
return fmt.Errorf("couldn't set alpha of '%s'; error: %v", path, err)
}
}
case "gray":
flags := flag.NewFlagSet("gray", flag.ContinueOnError)
flags.Parse(args[1:])
for _, path := range flags.Args() {
err := gray(path)
if err != nil {
return fmt.Errorf("couldn't convert to grayscale of '%s'; error: %v", path, err)
}
}
}
@ -57,6 +66,34 @@ func setAlpha(path string, alpha int) error {
return encodePNG(path, dst)
}
func gray(path string) error {
src, err := os.Open(path)
if err != nil {
return err
}
defer src.Close()
im, _, err := image.Decode(src)
if err != nil {
return err
}
bounds := im.Bounds()
dst := image.NewRGBA(bounds)
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
c := im.At(x, y)
rgba := color.NRGBAModel.Convert(c).(color.NRGBA)
if rgba.A > 0 {
gray := color.GrayModel.Convert(c).(color.Gray)
rgba.R, rgba.G, rgba.B = gray.Y, gray.Y, gray.Y
dst.Set(x, y, rgba)
} else {
dst.Set(x, y, c)
}
}
}
return encodePNG(path, dst)
}
func encodePNG(path string, im image.Image) error {
dst, err := os.Create(path)
if err != nil {

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -50,26 +50,31 @@ bush-large-2: images/plant_bushLarge_NW.png
bush-large-3: images/plant_bushLarge_SW.png
bush-large-4: images/plant_bushLarge_SE.png
flower-poppy-disabled: images/flower_yellowC_NE_disabled.png
flower-poppy-1: images/flower_yellowC_NE.png
flower-poppy-2: images/flower_yellowC_NW.png
flower-poppy-3: images/flower_yellowC_SW.png
flower-poppy-4: images/flower_yellowC_SE.png
flower-red-c-disabled: images/flower_redC_NE_disabled.png
flower-red-c-1: images/flower_redC_NE.png
flower-red-c-2: images/flower_redC_NW.png
flower-red-c-3: images/flower_redC_SW.png
flower-red-c-4: images/flower_redC_SE.png
flower-red-a-disabled: images/flower_redA_NE_disabled.png
flower-red-a-1: images/flower_redA_NE.png
flower-red-a-2: images/flower_redA_NW.png
flower-red-a-3: images/flower_redA_SW.png
flower-red-a-4: images/flower_redA_SE.png
flower-purple-a-disabled: images/flower_purpleA_NE_disabled.png
flower-purple-a-1: images/flower_purpleA_NE.png
flower-purple-a-2: images/flower_purpleA_NW.png
flower-purple-a-3: images/flower_purpleA_SW.png
flower-purple-a-4: images/flower_purpleA_SE.png
flower-purple-c-disabled: images/flower_purpleC_NE_disabled.png
flower-purple-c-1: images/flower_purpleC_NE.png
flower-purple-c-2: images/flower_purpleC_NW.png
flower-purple-c-3: images/flower_purpleC_SW.png

View File

@ -91,9 +91,9 @@ func run() error {
app := tins2020.NewContainer()
overlays := tins2020.NewContainer()
overlays.AddChild(&tins2020.FPS{})
gameControls := tins2020.NewGameControls()
overlays.AddChild(gameControls)
overlays.AddChild(&tins2020.FPS{})
content := tins2020.NewContainer()
app.AddChild(content)
app.AddChild(overlays)

View File

@ -39,6 +39,8 @@ func (b *ButtonBar) Handle(ctx *Context, event sdl.Event) {
button = -1
}
b.Hover = button
} else {
b.Hover = -1
}
}
}
@ -70,9 +72,10 @@ func NewGameControls() *GameControls {
}
func (c *GameControls) Init(ctx *Context) error {
c.flowers.Hover = -1
c.flowers.Buttons = []Button{
Button{Icon: "flower-poppy-1", Disabled: "flower-red-c-1"},
Button{Icon: "flower-poppy-1", Disabled: "flower-red-c-1", IsDisabled: true},
Button{Icon: "flower-poppy-1", Disabled: "flower-poppy-disabled"},
Button{Icon: "flower-red-c-1", Disabled: "flower-red-c-disabled", IsDisabled: true},
}
return c.updateBarPositions(ctx)
}