From ecdfc46358f214c911e389cef0db3af072897f4f Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sat, 11 Sep 2021 16:52:22 -0700 Subject: [PATCH] Zoom And Edit Progress on the Zoom feature: when you zoom in and out, you can draw shapes accurately onto the level. Seems a little buggy if you edit while scrolling (as in drawing a very long line). The title screen buttons are now more colorful. --- go.sum | 2 ++ pkg/balance/theme.go | 10 ++++++---- pkg/doodle.go | 23 +++++++++++++++++++++++ pkg/editor_ui_menubar.go | 16 ++-------------- pkg/main_scene.go | 31 +++++++++++++++++++++++-------- pkg/uix/canvas_editable.go | 3 ++- pkg/uix/canvas_zoom.go | 1 - 7 files changed, 58 insertions(+), 28 deletions(-) diff --git a/go.sum b/go.sum index 915fe9b..bf6b2ea 100644 --- a/go.sum +++ b/go.sum @@ -193,6 +193,8 @@ github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/X github.com/veandco/go-sdl2 v0.4.1/go.mod h1:FB+kTpX9YTE+urhYiClnRzpOXbiWgaU3+5F2AB78DPg= github.com/veandco/go-sdl2 v0.4.8 h1:A26KeX6R1CGt/BQGEov6oxYmVGMMEWDVqTvK1tXvahE= github.com/veandco/go-sdl2 v0.4.8/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= +github.com/veandco/go-sdl2 v0.4.10 h1:8QoD2bhWl7SbQDflIAUYWfl9Vq+mT8/boJFAUzAScgY= +github.com/veandco/go-sdl2 v0.4.10/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= github.com/vmihailenco/msgpack v3.3.3+incompatible h1:wapg9xDUZDzGCNFlwc5SqI1rvcciqcxEHac4CYj89xI= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= diff --git a/pkg/balance/theme.go b/pkg/balance/theme.go index 57d88ef..af3c33f 100644 --- a/pkg/balance/theme.go +++ b/pkg/balance/theme.go @@ -165,22 +165,24 @@ var ( ButtonLightRed = style.DefaultButton ) +// Customize the various button styles. func init() { - // Customize button styles. + // Primary: white on rich blue color ButtonPrimary.Background = render.RGBA(0, 60, 153, 255) ButtonPrimary.Foreground = render.RGBA(255, 255, 254, 255) ButtonPrimary.HoverBackground = render.RGBA(0, 153, 255, 255) ButtonPrimary.HoverForeground = ButtonPrimary.Foreground + // Danger: white on red ButtonDanger.Background = render.RGBA(153, 30, 30, 255) ButtonDanger.Foreground = render.RGBA(255, 255, 254, 255) ButtonDanger.HoverBackground = render.RGBA(255, 30, 30, 255) ButtonDanger.HoverForeground = ButtonPrimary.Foreground - ButtonBabyBlue.Background = render.RGBA(0, 153, 255, 255) - ButtonBabyBlue.Foreground = render.White + ButtonBabyBlue.Background = render.RGBA(40, 200, 255, 255) + ButtonBabyBlue.Foreground = render.Black ButtonBabyBlue.HoverBackground = render.RGBA(0, 220, 255, 255) - ButtonBabyBlue.HoverForeground = render.White + ButtonBabyBlue.HoverForeground = render.Black ButtonPink.Background = render.RGBA(255, 153, 255, 255) ButtonPink.HoverBackground = render.RGBA(255, 220, 255, 255) diff --git a/pkg/doodle.go b/pkg/doodle.go index c1a9ade..9e0e816 100644 --- a/pkg/doodle.go +++ b/pkg/doodle.go @@ -3,6 +3,7 @@ package doodle import ( "fmt" "path/filepath" + "strconv" "strings" "time" @@ -259,7 +260,29 @@ func (d *Doodle) NewMap() { } // NewDoodad loads a new Doodad in Edit Mode. +// If size is zero, it prompts the user to select a size or accept the default size. func (d *Doodle) NewDoodad(size int) { + if size == 0 { + d.Prompt(fmt.Sprintf("Doodad size or %d>", balance.DoodadSize), func(answer string) { + size := balance.DoodadSize + if answer != "" { + i, err := strconv.Atoi(answer) + if err != nil { + d.Flash("Error: Doodad size must be a number.") + return + } + size = i + } + + // Recurse with the proper answer. + if size <= 0 { + d.Flash("Error: Doodad size must be a positive number.") + } + d.NewDoodad(size) + }) + return + } + log.Info("Starting a new doodad") scene := &EditorScene{ DrawingType: enum.DoodadDrawing, diff --git a/pkg/editor_ui_menubar.go b/pkg/editor_ui_menubar.go index 236d5cf..69a2f33 100644 --- a/pkg/editor_ui_menubar.go +++ b/pkg/editor_ui_menubar.go @@ -5,8 +5,6 @@ package doodle // The rest of it is controlled in editor_ui.go import ( - "strconv" - "git.kirsle.net/apps/doodle/pkg/balance" "git.kirsle.net/apps/doodle/pkg/drawtool" "git.kirsle.net/apps/doodle/pkg/enum" @@ -56,18 +54,8 @@ func (u *EditorUI) SetupMenuBar(d *Doodle) *ui.MenuBar { fileMenu.AddItemAccel("New level", "Ctrl-N", u.Scene.MenuNewLevel) fileMenu.AddItem("New doodad", func() { u.Scene.ConfirmUnload(func() { - d.Prompt("Doodad size [100]>", func(answer string) { - size := balance.DoodadSize - if answer != "" { - i, err := strconv.Atoi(answer) - if err != nil { - d.Flash("Error: Doodad size must be a number.") - return - } - size = i - } - d.NewDoodad(size) - }) + // New doodad size with prompt. + d.NewDoodad(0) }) }) fileMenu.AddItemAccel("Save", "Ctrl-S", u.Scene.MenuSave(false)) diff --git a/pkg/main_scene.go b/pkg/main_scene.go index eb60876..9882ff1 100644 --- a/pkg/main_scene.go +++ b/pkg/main_scene.go @@ -17,6 +17,7 @@ import ( "git.kirsle.net/go/render" "git.kirsle.net/go/render/event" "git.kirsle.net/go/ui" + "git.kirsle.net/go/ui/style" ) // MainScene implements the main menu of Doodle. @@ -155,24 +156,35 @@ func (s *MainScene) Setup(d *Doodle) error { s.frame = frame var buttons = []struct { - Name string - Func func() + Name string + Func func() + Style *style.Button }{ // { // Name: "Story Mode", // Func: d.GotoStoryMenu, // }, { - Name: "Play a Level", - Func: d.GotoPlayMenu, + Name: "Play a Level", + Func: d.GotoPlayMenu, + Style: &balance.ButtonBabyBlue, }, { - Name: "Create a New Level", - Func: d.GotoNewMenu, + Name: "Create a Level", + Func: d.GotoNewMenu, + Style: &balance.ButtonPink, }, { - Name: "Edit a Level", - Func: d.GotoLoadMenu, + Name: "Create a Doodad", + Func: func() { + d.NewDoodad(0) + }, + Style: &balance.ButtonPink, + }, + { + Name: "Edit a Drawing", + Func: d.GotoLoadMenu, + Style: &balance.ButtonPrimary, }, { Name: "Settings", @@ -194,6 +206,9 @@ func (s *MainScene) Setup(d *Doodle) error { button.Func() return nil }) + if button.Style != nil { + btn.SetStyle(button.Style) + } s.Supervisor.Add(btn) frame.Pack(btn, ui.Pack{ Side: ui.N, diff --git a/pkg/uix/canvas_editable.go b/pkg/uix/canvas_editable.go index cc486e8..51370b9 100644 --- a/pkg/uix/canvas_editable.go +++ b/pkg/uix/canvas_editable.go @@ -28,7 +28,8 @@ func (w *Canvas) commitStroke(tool drawtool.Tool, addHistory bool) { return } - // Zoom the stroke coordinates (this modifies the pointer) + // Zoom the stroke coordinates (this modifies the pointer). + // Note: all the points on the stroke were mouse cursor coordinates on the screen. w.currentStroke = w.ZoomStroke(w.currentStroke) // Mark the canvas as modified. diff --git a/pkg/uix/canvas_zoom.go b/pkg/uix/canvas_zoom.go index 4768fd6..87b3b89 100644 --- a/pkg/uix/canvas_zoom.go +++ b/pkg/uix/canvas_zoom.go @@ -117,7 +117,6 @@ func (w *Canvas) ZoomStroke(stroke *drawtool.Stroke) *drawtool.Stroke { Points: stroke.Points, OriginalPoints: stroke.OriginalPoints, } - return copy // Multiply all coordinates in this stroke, which should be World // Coordinates in the level data, by the zoom multiplier.