71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"github.com/nsf/termbox-go"
|
||
|
"gogs.bullercodeworks.com/brian/termbox-util"
|
||
|
)
|
||
|
|
||
|
type command struct {
|
||
|
key string
|
||
|
description string
|
||
|
}
|
||
|
|
||
|
type titleScreen struct {
|
||
|
titleArt *termboxUtil.ASCIIArt
|
||
|
menu *termboxUtil.Menu
|
||
|
initialized bool
|
||
|
}
|
||
|
|
||
|
func (screen *titleScreen) handleKeyEvent(event termbox.Event) int {
|
||
|
if screen.menu.HandleKeyPress(event) {
|
||
|
if screen.menu.IsDone() {
|
||
|
selOpt := screen.menu.GetSelectedOption()
|
||
|
if selOpt.GetText() == "Exit" {
|
||
|
return exitScreenIndex
|
||
|
} else if selOpt.GetText() == "New Game" {
|
||
|
screen.initialized = false
|
||
|
return mainScreenIndex
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return titleScreenIndex
|
||
|
}
|
||
|
|
||
|
func (screen *titleScreen) performLayout(style style) {
|
||
|
if !screen.initialized {
|
||
|
var tmplt []string
|
||
|
tmplt = append(tmplt, " ")
|
||
|
tmplt = append(tmplt, " ")
|
||
|
tmplt = append(tmplt, " gopher.bas ")
|
||
|
tmplt = append(tmplt, " ")
|
||
|
tmplt = append(tmplt, " ")
|
||
|
tmplt = append(tmplt, " ")
|
||
|
|
||
|
defaultFg := style.defaultFg
|
||
|
defaultBg := style.defaultBg
|
||
|
screen.titleArt = termboxUtil.CreateASCIIArt(tmplt, 0, 0, defaultFg, defaultBg)
|
||
|
w, h := termbox.Size()
|
||
|
screen.titleArt.Align(termboxUtil.AlignCenter, w)
|
||
|
|
||
|
menuX := w/2 - 10
|
||
|
menuY := h/2 - 5
|
||
|
|
||
|
screen.menu = termboxUtil.CreateMenu("",
|
||
|
[]string{"New Game", "Continue", "Exit"},
|
||
|
menuX, menuY, 20, 10, defaultFg, defaultBg,
|
||
|
)
|
||
|
// TODO: Check if we have a suspended game
|
||
|
screen.menu.SetOptionDisabled(1)
|
||
|
screen.menu.SetBordered(true)
|
||
|
screen.menu.EnableVimMode()
|
||
|
screen.initialized = true
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (screen *titleScreen) update() {}
|
||
|
|
||
|
func (screen *titleScreen) drawScreen(style style) {
|
||
|
screen.titleArt.Draw()
|
||
|
screen.menu.Draw()
|
||
|
}
|