Updated for new scenes.
This commit is contained in:
@@ -2,52 +2,22 @@ package splashmenu
|
||||
|
||||
import (
|
||||
"cosmos/diego/groovy"
|
||||
splashmenu "cosmos/diego/groovy/examples/splashmenu/fonts"
|
||||
"image/color"
|
||||
"log"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
|
||||
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
||||
"github.com/hajimehoshi/ebiten/v2/text"
|
||||
"golang.org/x/image/font"
|
||||
"golang.org/x/image/font/opentype"
|
||||
)
|
||||
|
||||
var (
|
||||
titleFont font.Face
|
||||
menuFont font.Face
|
||||
backgroundBaseColor color.RGBA
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
backgroundBaseColor = color.RGBA{0x33, 0x33, 0x99, 0xFF}
|
||||
|
||||
tt, err := opentype.Parse(fonts.PressStart2P_ttf)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
const dpi = 72
|
||||
titleFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
|
||||
Size: 16,
|
||||
DPI: dpi,
|
||||
Hinting: font.HintingVertical,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
menuFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
|
||||
Size: 10,
|
||||
DPI: dpi,
|
||||
Hinting: font.HintingVertical,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
type Menu struct {
|
||||
@@ -66,49 +36,6 @@ func NewMenu() Menu {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Menu) Draw(screen *ebiten.Image) {
|
||||
screen.Fill(m.bgcolor)
|
||||
text.Draw(screen, "menu", titleFont, 40, 40, color.White)
|
||||
|
||||
m.RenderMetadata(screen)
|
||||
m.RenderMenu(screen)
|
||||
}
|
||||
|
||||
func (m *Menu) RenderMetadata(screen *ebiten.Image) {
|
||||
bgcolor := " 0x" + strconv.FormatUint(uint64(m.bgcolor.R), 16) + " 0x" + strconv.FormatUint(uint64(m.bgcolor.G), 16) + " 0x" + strconv.FormatUint(uint64(m.bgcolor.B), 16)
|
||||
text.Draw(screen, bgcolor, menuFont, 40, 700, color.White)
|
||||
}
|
||||
|
||||
func (m Menu) SetEventHandler(event groovy.SceneEvent, f func()) {
|
||||
m.events[event] = f
|
||||
}
|
||||
|
||||
func (m *Menu) SetOptions(options map[int]MenuOption) {
|
||||
m.options = make(map[int]MenuOption)
|
||||
|
||||
for k, v := range options {
|
||||
m.options[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
// sets sene dimensions
|
||||
func (m *Menu) SetDimensions(a groovy.Area) {
|
||||
m.Dimensions = a
|
||||
}
|
||||
|
||||
func (m *Menu) RenderMenu(screen *ebiten.Image) {
|
||||
|
||||
var offset int = 20
|
||||
|
||||
screen.Set(m.Dimensions.Width/2, m.Dimensions.Height/2, color.RGBA{0xFF, 0x00, 0x00, 0xFF})
|
||||
|
||||
for k, v := range m.options {
|
||||
m.options[k] = v
|
||||
text.Draw(screen, strconv.Itoa(k)+": "+v.Description, menuFont, 40, 60+offset*k, color.White)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (m *Menu) Update() error {
|
||||
m.increment++
|
||||
|
||||
@@ -136,6 +63,49 @@ func (m *Menu) Update() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Menu) Draw(screen *ebiten.Image) {
|
||||
screen.Fill(m.bgcolor)
|
||||
text.Draw(screen, "menu", splashmenu.SplashFont.Title, 40, 40, color.White)
|
||||
|
||||
m.RenderMetadata(screen)
|
||||
m.RenderMenu(screen)
|
||||
}
|
||||
|
||||
func (m *Menu) SetEventHandler(event groovy.SceneEvent, f func()) {
|
||||
m.events[event] = f
|
||||
}
|
||||
|
||||
// sets sene dimensions
|
||||
func (m *Menu) SetDimensions(a groovy.Area) {
|
||||
m.Dimensions = a
|
||||
}
|
||||
|
||||
func (m *Menu) RenderMetadata(screen *ebiten.Image) {
|
||||
bgcolor := " 0x" + strconv.FormatUint(uint64(m.bgcolor.R), 16) + " 0x" + strconv.FormatUint(uint64(m.bgcolor.G), 16) + " 0x" + strconv.FormatUint(uint64(m.bgcolor.B), 16)
|
||||
text.Draw(screen, bgcolor, splashmenu.SplashFont.Menu, 40, 700, color.White)
|
||||
}
|
||||
|
||||
func (m *Menu) SetOptions(options map[int]MenuOption) {
|
||||
m.options = make(map[int]MenuOption)
|
||||
|
||||
for k, v := range options {
|
||||
m.options[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Menu) RenderMenu(screen *ebiten.Image) {
|
||||
|
||||
var offset int = 20
|
||||
|
||||
screen.Set(m.Dimensions.Width/2, m.Dimensions.Height/2, color.RGBA{0xFF, 0x00, 0x00, 0xFF})
|
||||
|
||||
for k, v := range m.options {
|
||||
m.options[k] = v
|
||||
text.Draw(screen, strconv.Itoa(k)+": "+v.Description, splashmenu.SplashFont.Menu, 40, 60+offset*k, color.White)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (m *Menu) GetMenuSelection() uint {
|
||||
return m.menuSelection
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user