diff --git a/cmd/imadapt/imadapt.go b/cmd/imadapt/imadapt.go index e3ae6fc..c04bbcd 100644 --- a/cmd/imadapt/imadapt.go +++ b/cmd/imadapt/imadapt.go @@ -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 { diff --git a/cmd/tins2020/res/images/flower_purpleA_NE_disabled.png b/cmd/tins2020/res/images/flower_purpleA_NE_disabled.png new file mode 100644 index 0000000..36644e2 Binary files /dev/null and b/cmd/tins2020/res/images/flower_purpleA_NE_disabled.png differ diff --git a/cmd/tins2020/res/images/flower_purpleC_NE_disabled.png b/cmd/tins2020/res/images/flower_purpleC_NE_disabled.png new file mode 100644 index 0000000..a585a57 Binary files /dev/null and b/cmd/tins2020/res/images/flower_purpleC_NE_disabled.png differ diff --git a/cmd/tins2020/res/images/flower_redA_NE_disabled.png b/cmd/tins2020/res/images/flower_redA_NE_disabled.png new file mode 100644 index 0000000..593c473 Binary files /dev/null and b/cmd/tins2020/res/images/flower_redA_NE_disabled.png differ diff --git a/cmd/tins2020/res/images/flower_redC_NE_disabled.png b/cmd/tins2020/res/images/flower_redC_NE_disabled.png new file mode 100644 index 0000000..f19b2c1 Binary files /dev/null and b/cmd/tins2020/res/images/flower_redC_NE_disabled.png differ diff --git a/cmd/tins2020/res/images/flower_yellowC_NE_disabled.png b/cmd/tins2020/res/images/flower_yellowC_NE_disabled.png new file mode 100644 index 0000000..a74d37a Binary files /dev/null and b/cmd/tins2020/res/images/flower_yellowC_NE_disabled.png differ diff --git a/cmd/tins2020/res/textures.txt b/cmd/tins2020/res/textures.txt index befdadc..75fa049 100644 --- a/cmd/tins2020/res/textures.txt +++ b/cmd/tins2020/res/textures.txt @@ -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 diff --git a/cmd/tins2020/tins2020.go b/cmd/tins2020/tins2020.go index 0767cd2..a0083ab 100644 --- a/cmd/tins2020/tins2020.go +++ b/cmd/tins2020/tins2020.go @@ -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) diff --git a/gamecontrols.go b/gamecontrols.go index 31abc65..d4c877d 100644 --- a/gamecontrols.go +++ b/gamecontrols.go @@ -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) }