krampus19/cmd/krampus19/navigation.go
2019-12-28 21:20:56 +01:00

50 lines
797 B
Go

package main
import (
"opslag.de/schobers/krampus19/alui"
)
type navigation struct {
game *game
curr scene
}
type scene interface {
alui.Control
Enter(ctx *Context) error
Leave()
}
func (n *navigation) ChangeSettings() {
n.switchTo(&changeSettings{})
}
func (n *navigation) PlayLevel(packID, levelID string) {
n.switchTo(&playLevel{packID: packID, levelID: levelID})
}
func (n *navigation) SelectLevel(packID string) {
n.switchTo(&levelSelect{packID: packID})
}
func (n *navigation) ShowMainMenu() {
n.switchTo(&mainMenu{})
}
func (n *navigation) Quit() {
n.switchTo(nil)
}
func (n *navigation) switchTo(s scene) {
if n.curr != nil {
n.curr.Leave()
}
n.curr = s
n.game.scene.Proxy = s
n.game.scene.Visible = s != nil
if n.curr != nil {
n.curr.Enter(n.game.ctx)
}
}