mirror of
https://codeberg.org/scip/golsky.git
synced 2025-12-16 12:10:58 +01:00
added key bindings help screen, reachable via menu
This commit is contained in:
@@ -52,6 +52,25 @@ const (
|
||||
DEFAULT_GEOM = "640x384"
|
||||
)
|
||||
|
||||
const KEYBINDINGS string = `
|
||||
- SPACE: pause or resume the game
|
||||
- N: while game is paused: forward one step
|
||||
- PAGE UP: speed up
|
||||
- PAGE DOWN: slow down
|
||||
- MOUSE WHEEL: zoom in or out
|
||||
- LEFT MOUSE BUTTON: use to drag canvas, keep clicked and move mouse
|
||||
- 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, o: open options menu
|
||||
- S: save game state to file (can be loaded with -l)
|
||||
- C: enter mark mode. Mark a rectangle with the mouse, when you
|
||||
release the mouse buttonx it is being saved to an RLE file
|
||||
- D: toggle debug output
|
||||
- Q: quit game
|
||||
`
|
||||
|
||||
func (config *Config) SetupCamera() {
|
||||
config.Zoomfactor = DEFAULT_ZOOMFACTOR
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ func NewGame(config *Config, startscene SceneName) *Game {
|
||||
game.Scenes[Play] = NewPlayScene(game, config)
|
||||
game.Scenes[Menu] = NewMenuScene(game, config)
|
||||
game.Scenes[Options] = NewOptionsScene(game, config)
|
||||
game.Scenes[Keybindings] = NewKeybindingsScene(game, config)
|
||||
|
||||
// setup environment
|
||||
ebiten.SetWindowSize(game.ScreenWidth, game.ScreenHeight)
|
||||
|
||||
98
src/keybindings.go
Normal file
98
src/keybindings.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
|
||||
"github.com/ebitenui/ebitenui"
|
||||
"github.com/ebitenui/ebitenui/widget"
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
||||
)
|
||||
|
||||
type SceneKeybindings struct {
|
||||
Game *Game
|
||||
Config *Config
|
||||
Next SceneName
|
||||
Prev SceneName
|
||||
Whoami SceneName
|
||||
Ui *ebitenui.UI
|
||||
FontColor color.RGBA
|
||||
First bool
|
||||
}
|
||||
|
||||
func NewKeybindingsScene(game *Game, config *Config) Scene {
|
||||
scene := &SceneKeybindings{
|
||||
Whoami: Keybindings,
|
||||
Game: game,
|
||||
Next: Keybindings,
|
||||
Config: config,
|
||||
FontColor: color.RGBA{255, 30, 30, 0xff},
|
||||
}
|
||||
|
||||
scene.Init()
|
||||
|
||||
return scene
|
||||
}
|
||||
|
||||
func (scene *SceneKeybindings) GetNext() SceneName {
|
||||
return scene.Next
|
||||
}
|
||||
|
||||
func (scene *SceneKeybindings) SetPrevious(prev SceneName) {
|
||||
scene.Prev = prev
|
||||
}
|
||||
|
||||
func (scene *SceneKeybindings) ResetNext() {
|
||||
scene.Next = scene.Whoami
|
||||
}
|
||||
|
||||
func (scene *SceneKeybindings) SetNext(next SceneName) {
|
||||
scene.Next = next
|
||||
}
|
||||
|
||||
func (scene *SceneKeybindings) Update() error {
|
||||
scene.Ui.Update()
|
||||
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) || inpututil.IsKeyJustPressed(ebiten.KeyQ) {
|
||||
scene.Config.DelayedStart = false
|
||||
scene.Leave()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (scene *SceneKeybindings) IsPrimary() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (scene *SceneKeybindings) Draw(screen *ebiten.Image) {
|
||||
scene.Ui.Draw(screen)
|
||||
}
|
||||
|
||||
func (scene *SceneKeybindings) Leave() {
|
||||
scene.SetNext(Play)
|
||||
}
|
||||
|
||||
func (scene *SceneKeybindings) Init() {
|
||||
rowContainer := NewRowContainer("Key Bindings")
|
||||
|
||||
bindings := widget.NewText(
|
||||
widget.TextOpts.WidgetOpts(widget.WidgetOpts.LayoutData(widget.RowLayoutData{
|
||||
Stretch: true,
|
||||
})),
|
||||
widget.TextOpts.Text(KEYBINDINGS, *FontRenderer.FontSmall, color.NRGBA{0xdf, 0xf4, 0xff, 0xff}))
|
||||
|
||||
cancel := NewMenuButton("Back",
|
||||
func(args *widget.ButtonClickedEventArgs) {
|
||||
scene.Leave()
|
||||
})
|
||||
|
||||
rowContainer.AddChild(bindings)
|
||||
rowContainer.AddChild(cancel)
|
||||
|
||||
scene.Ui = &ebitenui.UI{
|
||||
Container: rowContainer.Container(),
|
||||
}
|
||||
|
||||
}
|
||||
@@ -104,6 +104,11 @@ func (scene *SceneMenu) Init() {
|
||||
scene.SetNext(Options)
|
||||
})
|
||||
|
||||
bindings := NewMenuButton("Show Key Bindings",
|
||||
func(args *widget.ButtonClickedEventArgs) {
|
||||
scene.SetNext(Keybindings)
|
||||
})
|
||||
|
||||
separator1 := NewSeparator(3)
|
||||
separator2 := NewSeparator(3)
|
||||
separator3 := NewSeparator(10)
|
||||
@@ -123,6 +128,7 @@ func (scene *SceneMenu) Init() {
|
||||
rowContainer.AddChild(separator1)
|
||||
rowContainer.AddChild(options)
|
||||
rowContainer.AddChild(copy)
|
||||
rowContainer.AddChild(bindings)
|
||||
rowContainer.AddChild(separator2)
|
||||
rowContainer.AddChild(cancel)
|
||||
rowContainer.AddChild(separator3)
|
||||
|
||||
@@ -24,4 +24,5 @@ const (
|
||||
Menu = iota // main top level menu
|
||||
Play // actual playing happens here
|
||||
Options
|
||||
Keybindings
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user