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.
zoom-hell
Noah 2021-09-11 16:52:22 -07:00
parent 13ae66e1fa
commit ecdfc46358
7 changed files with 58 additions and 28 deletions

2
go.sum
View File

@ -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.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 h1:A26KeX6R1CGt/BQGEov6oxYmVGMMEWDVqTvK1tXvahE=
github.com/veandco/go-sdl2 v0.4.8/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= 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 h1:wapg9xDUZDzGCNFlwc5SqI1rvcciqcxEHac4CYj89xI=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= 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= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=

View File

@ -165,22 +165,24 @@ var (
ButtonLightRed = style.DefaultButton ButtonLightRed = style.DefaultButton
) )
// Customize the various button styles.
func init() { func init() {
// Customize button styles. // Primary: white on rich blue color
ButtonPrimary.Background = render.RGBA(0, 60, 153, 255) ButtonPrimary.Background = render.RGBA(0, 60, 153, 255)
ButtonPrimary.Foreground = render.RGBA(255, 255, 254, 255) ButtonPrimary.Foreground = render.RGBA(255, 255, 254, 255)
ButtonPrimary.HoverBackground = render.RGBA(0, 153, 255, 255) ButtonPrimary.HoverBackground = render.RGBA(0, 153, 255, 255)
ButtonPrimary.HoverForeground = ButtonPrimary.Foreground ButtonPrimary.HoverForeground = ButtonPrimary.Foreground
// Danger: white on red
ButtonDanger.Background = render.RGBA(153, 30, 30, 255) ButtonDanger.Background = render.RGBA(153, 30, 30, 255)
ButtonDanger.Foreground = render.RGBA(255, 255, 254, 255) ButtonDanger.Foreground = render.RGBA(255, 255, 254, 255)
ButtonDanger.HoverBackground = render.RGBA(255, 30, 30, 255) ButtonDanger.HoverBackground = render.RGBA(255, 30, 30, 255)
ButtonDanger.HoverForeground = ButtonPrimary.Foreground ButtonDanger.HoverForeground = ButtonPrimary.Foreground
ButtonBabyBlue.Background = render.RGBA(0, 153, 255, 255) ButtonBabyBlue.Background = render.RGBA(40, 200, 255, 255)
ButtonBabyBlue.Foreground = render.White ButtonBabyBlue.Foreground = render.Black
ButtonBabyBlue.HoverBackground = render.RGBA(0, 220, 255, 255) 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.Background = render.RGBA(255, 153, 255, 255)
ButtonPink.HoverBackground = render.RGBA(255, 220, 255, 255) ButtonPink.HoverBackground = render.RGBA(255, 220, 255, 255)

View File

@ -3,6 +3,7 @@ package doodle
import ( import (
"fmt" "fmt"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
"time" "time"
@ -259,7 +260,29 @@ func (d *Doodle) NewMap() {
} }
// NewDoodad loads a new Doodad in Edit Mode. // 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) { 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") log.Info("Starting a new doodad")
scene := &EditorScene{ scene := &EditorScene{
DrawingType: enum.DoodadDrawing, DrawingType: enum.DoodadDrawing,

View File

@ -5,8 +5,6 @@ package doodle
// The rest of it is controlled in editor_ui.go // The rest of it is controlled in editor_ui.go
import ( import (
"strconv"
"git.kirsle.net/apps/doodle/pkg/balance" "git.kirsle.net/apps/doodle/pkg/balance"
"git.kirsle.net/apps/doodle/pkg/drawtool" "git.kirsle.net/apps/doodle/pkg/drawtool"
"git.kirsle.net/apps/doodle/pkg/enum" "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.AddItemAccel("New level", "Ctrl-N", u.Scene.MenuNewLevel)
fileMenu.AddItem("New doodad", func() { fileMenu.AddItem("New doodad", func() {
u.Scene.ConfirmUnload(func() { u.Scene.ConfirmUnload(func() {
d.Prompt("Doodad size [100]>", func(answer string) { // New doodad size with prompt.
size := balance.DoodadSize d.NewDoodad(0)
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)
})
}) })
}) })
fileMenu.AddItemAccel("Save", "Ctrl-S", u.Scene.MenuSave(false)) fileMenu.AddItemAccel("Save", "Ctrl-S", u.Scene.MenuSave(false))

View File

@ -17,6 +17,7 @@ import (
"git.kirsle.net/go/render" "git.kirsle.net/go/render"
"git.kirsle.net/go/render/event" "git.kirsle.net/go/render/event"
"git.kirsle.net/go/ui" "git.kirsle.net/go/ui"
"git.kirsle.net/go/ui/style"
) )
// MainScene implements the main menu of Doodle. // MainScene implements the main menu of Doodle.
@ -155,24 +156,35 @@ func (s *MainScene) Setup(d *Doodle) error {
s.frame = frame s.frame = frame
var buttons = []struct { var buttons = []struct {
Name string Name string
Func func() Func func()
Style *style.Button
}{ }{
// { // {
// Name: "Story Mode", // Name: "Story Mode",
// Func: d.GotoStoryMenu, // Func: d.GotoStoryMenu,
// }, // },
{ {
Name: "Play a Level", Name: "Play a Level",
Func: d.GotoPlayMenu, Func: d.GotoPlayMenu,
Style: &balance.ButtonBabyBlue,
}, },
{ {
Name: "Create a New Level", Name: "Create a Level",
Func: d.GotoNewMenu, Func: d.GotoNewMenu,
Style: &balance.ButtonPink,
}, },
{ {
Name: "Edit a Level", Name: "Create a Doodad",
Func: d.GotoLoadMenu, Func: func() {
d.NewDoodad(0)
},
Style: &balance.ButtonPink,
},
{
Name: "Edit a Drawing",
Func: d.GotoLoadMenu,
Style: &balance.ButtonPrimary,
}, },
{ {
Name: "Settings", Name: "Settings",
@ -194,6 +206,9 @@ func (s *MainScene) Setup(d *Doodle) error {
button.Func() button.Func()
return nil return nil
}) })
if button.Style != nil {
btn.SetStyle(button.Style)
}
s.Supervisor.Add(btn) s.Supervisor.Add(btn)
frame.Pack(btn, ui.Pack{ frame.Pack(btn, ui.Pack{
Side: ui.N, Side: ui.N,

View File

@ -28,7 +28,8 @@ func (w *Canvas) commitStroke(tool drawtool.Tool, addHistory bool) {
return 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) w.currentStroke = w.ZoomStroke(w.currentStroke)
// Mark the canvas as modified. // Mark the canvas as modified.

View File

@ -117,7 +117,6 @@ func (w *Canvas) ZoomStroke(stroke *drawtool.Stroke) *drawtool.Stroke {
Points: stroke.Points, Points: stroke.Points,
OriginalPoints: stroke.OriginalPoints, OriginalPoints: stroke.OriginalPoints,
} }
return copy
// Multiply all coordinates in this stroke, which should be World // Multiply all coordinates in this stroke, which should be World
// Coordinates in the level data, by the zoom multiplier. // Coordinates in the level data, by the zoom multiplier.