diff --git a/.gitignore b/.gitignore index 77e14fe..fe5c6de 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ bak dump* rect* *profile +*prof diff --git a/config.go b/config.go index 1d1d156..724d104 100644 --- a/config.go +++ b/config.go @@ -267,3 +267,7 @@ func (config *Config) ToggleGridlines() { config.ShowGrid = !config.ShowGrid config.RestartCache = true } + +func (config *Config) ToggleEvolution() { + config.ShowEvolution = !config.ShowEvolution +} diff --git a/game.go b/game.go index 9f73464..a7313f4 100644 --- a/game.go +++ b/game.go @@ -49,7 +49,10 @@ func (game *Game) Layout(outsideWidth, outsideHeight int) (int, int) { func (game *Game) Update() error { scene := game.GetCurrentScene() - scene.Update() + + if quit := scene.Update(); quit != nil { + return quit + } next := scene.GetNext() if next != game.CurrentScene { diff --git a/options.go b/options.go index 0c883fe..c8a04fd 100644 --- a/options.go +++ b/options.go @@ -95,7 +95,7 @@ func (scene *SceneOptions) Init() { invert := NewCheckbox("Invert", func(args *widget.CheckboxChangedEventArgs) { - scene.Config.Invert = true + scene.Config.ToggleInvert() }) scene.SetInitialValue(invert, scene.Config.Invert) @@ -105,6 +105,12 @@ func (scene *SceneOptions) Init() { }) scene.SetInitialValue(gridlines, scene.Config.ShowGrid) + evolution := NewCheckbox("Show evolution traces", + func(args *widget.CheckboxChangedEventArgs) { + scene.Config.ToggleEvolution() + }) + scene.SetInitialValue(evolution, scene.Config.ShowEvolution) + separator := NewSeparator(3) cancel := NewMenuButton("Close", @@ -116,6 +122,7 @@ func (scene *SceneOptions) Init() { rowContainer.AddChild(debugging) rowContainer.AddChild(invert) rowContainer.AddChild(gridlines) + rowContainer.AddChild(evolution) rowContainer.AddChild(separator) rowContainer.AddChild(cancel) diff --git a/play.go b/play.go index 2c974f3..2bea6d4 100644 --- a/play.go +++ b/play.go @@ -5,7 +5,6 @@ import ( "image" "image/color" "log" - "os" "github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2/inpututil" @@ -162,11 +161,15 @@ func (scene *ScenePlay) Reset() { } // check user input -func (scene *ScenePlay) CheckInput() { +func (scene *ScenePlay) CheckExit() error { if inpututil.IsKeyJustPressed(ebiten.KeyQ) { - os.Exit(0) + return ebiten.Termination } + return nil +} + +func (scene *ScenePlay) CheckInput() { if inpututil.IsKeyJustPressed(ebiten.KeyEscape) { scene.SetNext(Menu) } @@ -176,7 +179,6 @@ func (scene *ScenePlay) CheckInput() { } if inpututil.IsKeyJustPressed(ebiten.KeyC) { - fmt.Println("mark mode on") scene.Config.Markmode = true scene.Config.Paused = true } @@ -297,6 +299,10 @@ func (scene *ScenePlay) CheckMarkInput() { return } + if inpututil.IsKeyJustPressed(ebiten.KeyEscape) { + scene.Config.Markmode = false + } + if ebiten.IsMouseButtonPressed(ebiten.MouseButton0) { if !scene.MarkTaken { scene.Mark = scene.GetWorldCursorPos() @@ -391,6 +397,10 @@ func (scene *ScenePlay) Update() error { return nil } + if quit := scene.CheckExit(); quit != nil { + return quit + } + scene.CheckInput() scene.CheckDraggingInput() scene.CheckMarkInput() @@ -498,6 +508,10 @@ func (scene *ScenePlay) DrawDebug(screen *ebiten.Image) { paused = "-- paused --" } + if scene.Config.Markmode { + paused = "-- mark --" + } + x, y := ebiten.CursorPosition() debug := fmt.Sprintf( DEBUG_FORMAT,