fixed exit function with q, added evolution trace to options fixed inverse

This commit is contained in:
2024-06-03 18:38:18 +02:00
parent 03e1101248
commit 443b5a2bcf
5 changed files with 35 additions and 6 deletions

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@ bak
dump*
rect*
*profile
*prof

View File

@@ -267,3 +267,7 @@ func (config *Config) ToggleGridlines() {
config.ShowGrid = !config.ShowGrid
config.RestartCache = true
}
func (config *Config) ToggleEvolution() {
config.ShowEvolution = !config.ShowEvolution
}

View File

@@ -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 {

View File

@@ -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)

22
play.go
View File

@@ -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,