mirror of
https://codeberg.org/scip/golsky.git
synced 2025-12-16 12:10:58 +01:00
added explicit insert/draw mode, left mouse by default moves canvas
This commit is contained in:
@@ -76,7 +76,10 @@ While it runs, there are a couple of commands you can use:
|
||||
* page up: speed up
|
||||
* page down: slow down
|
||||
* Mouse wheel: zoom in or out
|
||||
* move mouse while middle mouse button pressed: move canvas
|
||||
* move mouse while left mouse button pressed: move canvas
|
||||
* i: enter "insert" (draw) mode: use left mouse to set cells alife and right
|
||||
button to dead. Leave with "space". While in insert mode, use middle mouse
|
||||
button to drag grid.
|
||||
* r: reset to 1:1 zoom
|
||||
* escape: open menu
|
||||
* s: save game state to file (can be loaded with -l)
|
||||
|
||||
@@ -15,24 +15,24 @@ import (
|
||||
|
||||
// all the settings comming from commandline, but maybe tweaked later from the UI
|
||||
type Config struct {
|
||||
Width, Height, Cellsize, Density int // measurements
|
||||
ScreenWidth, ScreenHeight int
|
||||
TPG int // ticks per generation/game speed, 1==max
|
||||
Debug, Empty, Invert, Paused, Markmode bool // game modi
|
||||
ShowEvolution, ShowGrid, RunOneStep bool // flags
|
||||
Rule *Rule // which rule to use, default: B3/S23
|
||||
RLE *rle.RLE // loaded GOL pattern from RLE file
|
||||
Statefile string // load game state from it if non-nil
|
||||
StateGrid *Grid // a grid from a statefile
|
||||
Wrap bool // wether wraparound mode is in place or not
|
||||
ShowVersion bool
|
||||
UseShader bool // to use a shader to render alife cells
|
||||
Restart, RestartGrid, RestartCache bool
|
||||
StartWithMenu bool
|
||||
Zoomfactor int
|
||||
ZoomOutFactor int
|
||||
InitialCamPos []float64
|
||||
DelayedStart bool // if true game, we wait. like pause but program induced
|
||||
Width, Height, Cellsize, Density int // measurements
|
||||
ScreenWidth, ScreenHeight int
|
||||
TPG int // ticks per generation/game speed, 1==max
|
||||
Debug, Empty, Invert, Paused, Markmode, Drawmode bool // game modi
|
||||
ShowEvolution, ShowGrid, RunOneStep bool // flags
|
||||
Rule *Rule // which rule to use, default: B3/S23
|
||||
RLE *rle.RLE // loaded GOL pattern from RLE file
|
||||
Statefile string // load game state from it if non-nil
|
||||
StateGrid *Grid // a grid from a statefile
|
||||
Wrap bool // wether wraparound mode is in place or not
|
||||
ShowVersion bool
|
||||
UseShader bool // to use a shader to render alife cells
|
||||
Restart, RestartGrid, RestartCache bool
|
||||
StartWithMenu bool
|
||||
Zoomfactor int
|
||||
ZoomOutFactor int
|
||||
InitialCamPos []float64
|
||||
DelayedStart bool // if true game, we wait. like pause but program induced
|
||||
|
||||
// for internal profiling
|
||||
ProfileFile string
|
||||
|
||||
48
src/play.go
48
src/play.go
@@ -48,7 +48,7 @@ type ScenePlay struct {
|
||||
MarkDone bool // true when mouse1 released, copy cells between Mark+Point
|
||||
Mark, Point image.Point // area to marks+save
|
||||
RunOneStep bool // mutable flags from config
|
||||
TPG int
|
||||
TPG int // current game speed (ticks per game)
|
||||
}
|
||||
|
||||
func NewPlayScene(game *Game, config *Config) Scene {
|
||||
@@ -188,6 +188,11 @@ func (scene *ScenePlay) CheckInput() {
|
||||
scene.Config.Paused = true
|
||||
}
|
||||
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyI) {
|
||||
scene.Config.Drawmode = true
|
||||
scene.Config.Paused = true
|
||||
}
|
||||
|
||||
if scene.Config.Markmode {
|
||||
return
|
||||
}
|
||||
@@ -196,16 +201,6 @@ func (scene *ScenePlay) CheckInput() {
|
||||
scene.Config.TogglePaused()
|
||||
}
|
||||
|
||||
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
|
||||
scene.ToggleCellOnCursorPos(Alive)
|
||||
scene.Config.Paused = true // drawing while running makes no sense
|
||||
}
|
||||
|
||||
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonRight) {
|
||||
scene.ToggleCellOnCursorPos(Dead)
|
||||
scene.Config.Paused = true // drawing while running makes no sense
|
||||
}
|
||||
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyPageDown) {
|
||||
if scene.TPG < 120 {
|
||||
scene.TPG++
|
||||
@@ -233,6 +228,22 @@ func (scene *ScenePlay) CheckInput() {
|
||||
}
|
||||
}
|
||||
|
||||
func (scene *ScenePlay) CheckDrawingInput() {
|
||||
if scene.Config.Drawmode {
|
||||
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
|
||||
scene.ToggleCellOnCursorPos(Alive)
|
||||
}
|
||||
|
||||
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonRight) {
|
||||
scene.ToggleCellOnCursorPos(Dead)
|
||||
}
|
||||
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
|
||||
scene.Config.Drawmode = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check dragging input. move the canvas with the mouse while pressing
|
||||
// the middle mouse button, zoom in and out using the wheel.
|
||||
func (scene *ScenePlay) CheckDraggingInput() {
|
||||
@@ -240,13 +251,19 @@ func (scene *ScenePlay) CheckDraggingInput() {
|
||||
return
|
||||
}
|
||||
|
||||
dragbutton := ebiten.MouseButtonLeft
|
||||
|
||||
if scene.Config.Drawmode {
|
||||
dragbutton = ebiten.MouseButtonMiddle
|
||||
}
|
||||
|
||||
// move canvas
|
||||
if scene.Dragging && !ebiten.IsMouseButtonPressed(ebiten.MouseButton1) {
|
||||
if scene.Dragging && !ebiten.IsMouseButtonPressed(dragbutton) {
|
||||
// release
|
||||
scene.Dragging = false
|
||||
}
|
||||
|
||||
if !scene.Dragging && ebiten.IsMouseButtonPressed(ebiten.MouseButton1) {
|
||||
if !scene.Dragging && ebiten.IsMouseButtonPressed(dragbutton) {
|
||||
// start dragging
|
||||
scene.Dragging = true
|
||||
scene.LastCursorPos[0], scene.LastCursorPos[1] = ebiten.CursorPosition()
|
||||
@@ -408,6 +425,7 @@ func (scene *ScenePlay) Update() error {
|
||||
}
|
||||
|
||||
scene.CheckInput()
|
||||
scene.CheckDrawingInput()
|
||||
scene.CheckDraggingInput()
|
||||
scene.CheckMarkInput()
|
||||
|
||||
@@ -519,6 +537,10 @@ func (scene *ScenePlay) DrawDebug(screen *ebiten.Image) {
|
||||
paused = "-- mark --"
|
||||
}
|
||||
|
||||
if scene.Config.Drawmode {
|
||||
paused = "-- insert --"
|
||||
}
|
||||
|
||||
x, y := ebiten.CursorPosition()
|
||||
debug := fmt.Sprintf(
|
||||
DEBUG_FORMAT,
|
||||
|
||||
Reference in New Issue
Block a user