2025-11-13 21:30:44 +01:00
|
|
|
package cmd
|
2024-05-30 19:45:13 +02:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"image/color"
|
|
|
|
|
|
|
|
|
|
"github.com/ebitenui/ebitenui"
|
|
|
|
|
"github.com/ebitenui/ebitenui/widget"
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type SceneOptions struct {
|
|
|
|
|
Game *Game
|
|
|
|
|
Config *Config
|
|
|
|
|
Next SceneName
|
2024-06-03 17:44:17 +02:00
|
|
|
Prev SceneName
|
2024-05-30 19:45:13 +02:00
|
|
|
Whoami SceneName
|
|
|
|
|
Ui *ebitenui.UI
|
|
|
|
|
FontColor color.RGBA
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewOptionsScene(game *Game, config *Config) Scene {
|
|
|
|
|
scene := &SceneOptions{
|
|
|
|
|
Whoami: Options,
|
|
|
|
|
Game: game,
|
|
|
|
|
Next: Options,
|
|
|
|
|
Config: config,
|
|
|
|
|
FontColor: color.RGBA{255, 30, 30, 0xff},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scene.Init()
|
|
|
|
|
|
|
|
|
|
return scene
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (scene *SceneOptions) GetNext() SceneName {
|
|
|
|
|
return scene.Next
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-03 17:44:17 +02:00
|
|
|
func (scene *SceneOptions) SetPrevious(prev SceneName) {
|
|
|
|
|
scene.Prev = prev
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-30 19:45:13 +02:00
|
|
|
func (scene *SceneOptions) ResetNext() {
|
|
|
|
|
scene.Next = scene.Whoami
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (scene *SceneOptions) SetNext(next SceneName) {
|
|
|
|
|
scene.Next = next
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-01 20:22:28 +02:00
|
|
|
func (scene *SceneOptions) IsPrimary() bool {
|
2024-05-30 19:45:13 +02:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (scene *SceneOptions) Update() error {
|
|
|
|
|
scene.Ui.Update()
|
|
|
|
|
|
|
|
|
|
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) || inpututil.IsKeyJustPressed(ebiten.KeyQ) {
|
|
|
|
|
scene.SetNext(Play)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (scene *SceneOptions) Draw(screen *ebiten.Image) {
|
|
|
|
|
scene.Ui.Draw(screen)
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-31 14:19:30 +02:00
|
|
|
func (scene *SceneOptions) SetInitialValue(w *widget.LabeledCheckbox, value bool) {
|
|
|
|
|
if value {
|
2024-06-08 19:52:20 +02:00
|
|
|
w.SetState(
|
|
|
|
|
widget.WidgetChecked,
|
|
|
|
|
)
|
2024-05-31 14:19:30 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-30 19:45:13 +02:00
|
|
|
func (scene *SceneOptions) Init() {
|
|
|
|
|
rowContainer := NewRowContainer("Options")
|
|
|
|
|
|
|
|
|
|
pause := NewCheckbox("Pause",
|
2024-06-08 20:06:02 +02:00
|
|
|
scene.Config.Paused,
|
2024-05-30 19:45:13 +02:00
|
|
|
func(args *widget.CheckboxChangedEventArgs) {
|
|
|
|
|
scene.Config.TogglePaused()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
debugging := NewCheckbox("Debugging",
|
2024-06-08 20:06:02 +02:00
|
|
|
scene.Config.Debug,
|
2024-05-30 19:45:13 +02:00
|
|
|
func(args *widget.CheckboxChangedEventArgs) {
|
|
|
|
|
scene.Config.ToggleDebugging()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
gridlines := NewCheckbox("Show grid lines",
|
2024-06-08 20:06:02 +02:00
|
|
|
scene.Config.ShowGrid,
|
2024-05-30 19:45:13 +02:00
|
|
|
func(args *widget.CheckboxChangedEventArgs) {
|
|
|
|
|
scene.Config.ToggleGridlines()
|
|
|
|
|
})
|
|
|
|
|
|
2024-06-03 18:38:18 +02:00
|
|
|
evolution := NewCheckbox("Show evolution traces",
|
2024-06-08 20:06:02 +02:00
|
|
|
scene.Config.ShowEvolution,
|
2024-06-03 18:38:18 +02:00
|
|
|
func(args *widget.CheckboxChangedEventArgs) {
|
|
|
|
|
scene.Config.ToggleEvolution()
|
|
|
|
|
})
|
|
|
|
|
|
2024-06-04 18:50:29 +02:00
|
|
|
wrap := NewCheckbox("Wrap around edges",
|
2024-06-08 20:06:02 +02:00
|
|
|
scene.Config.Wrap,
|
2024-06-04 18:50:29 +02:00
|
|
|
func(args *widget.CheckboxChangedEventArgs) {
|
|
|
|
|
scene.Config.ToggleWrap()
|
|
|
|
|
})
|
|
|
|
|
|
2024-06-09 18:00:06 +02:00
|
|
|
themenames := make([]string, len(THEMES))
|
|
|
|
|
i := 0
|
|
|
|
|
for name := range THEMES {
|
|
|
|
|
themenames[i] = name
|
|
|
|
|
i++
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-07 18:39:14 +02:00
|
|
|
themes := NewCombobox(
|
2024-06-09 18:00:06 +02:00
|
|
|
themenames,
|
2024-06-07 18:39:14 +02:00
|
|
|
scene.Config.Theme,
|
|
|
|
|
func(args *widget.ListComboButtonEntrySelectedEventArgs) {
|
|
|
|
|
scene.Config.SwitchTheme(args.Entry.(ListEntry).Name)
|
|
|
|
|
})
|
2024-06-08 20:06:02 +02:00
|
|
|
|
2024-06-07 18:39:14 +02:00
|
|
|
themelabel := NewLabel("Themes")
|
|
|
|
|
combocontainer := NewColumnContainer()
|
|
|
|
|
combocontainer.AddChild(themes)
|
|
|
|
|
combocontainer.AddChild(themelabel)
|
|
|
|
|
|
2024-06-03 17:44:17 +02:00
|
|
|
separator := NewSeparator(3)
|
2024-06-07 18:39:14 +02:00
|
|
|
separator2 := NewSeparator(3)
|
2024-05-30 19:45:13 +02:00
|
|
|
|
|
|
|
|
cancel := NewMenuButton("Close",
|
|
|
|
|
func(args *widget.ButtonClickedEventArgs) {
|
2024-06-03 17:44:17 +02:00
|
|
|
scene.SetNext(scene.Prev)
|
2024-05-30 19:45:13 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
rowContainer.AddChild(pause)
|
|
|
|
|
rowContainer.AddChild(debugging)
|
|
|
|
|
rowContainer.AddChild(gridlines)
|
2024-06-03 18:38:18 +02:00
|
|
|
rowContainer.AddChild(evolution)
|
2024-06-04 18:50:29 +02:00
|
|
|
rowContainer.AddChild(wrap)
|
2024-06-07 18:39:14 +02:00
|
|
|
|
2024-05-30 19:45:13 +02:00
|
|
|
rowContainer.AddChild(separator)
|
2024-06-07 18:39:14 +02:00
|
|
|
|
|
|
|
|
rowContainer.AddChild(combocontainer)
|
|
|
|
|
|
|
|
|
|
rowContainer.AddChild(separator2)
|
|
|
|
|
|
2024-05-30 19:45:13 +02:00
|
|
|
rowContainer.AddChild(cancel)
|
|
|
|
|
|
|
|
|
|
scene.Ui = &ebitenui.UI{
|
|
|
|
|
Container: rowContainer.Container(),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|