menu poc
This commit is contained in:
@@ -1,25 +1,65 @@
|
||||
package konstructor
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"os"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/examples/resources/fonts"
|
||||
"github.com/hajimehoshi/ebiten/text"
|
||||
"golang.org/x/image/font"
|
||||
"golang.org/x/image/font/opentype"
|
||||
)
|
||||
|
||||
type Engine struct {
|
||||
Konstructor *Konstructor
|
||||
Logic *Logic
|
||||
Domain DomainInterface
|
||||
Controller *Controller
|
||||
Settings *Settings
|
||||
KContext *KContext
|
||||
MenuMap MenuMap
|
||||
}
|
||||
|
||||
func (g *Engine) Layout(outsideWidth, outsideHeight int) (int, int) {
|
||||
return g.Logic.Settings.Screen.Width, g.Logic.Settings.Screen.Height
|
||||
func (e *Engine) Layout(outsideWidth, outsideHeight int) (int, int) {
|
||||
return e.Settings.Screen.Width, e.Settings.Screen.Height
|
||||
}
|
||||
|
||||
func (g *Engine) Update(screen *ebiten.Image) error {
|
||||
g.Logic.Controller.Watch()
|
||||
g.Logic.Update(screen)
|
||||
func (e *Engine) Update(screen *ebiten.Image) error {
|
||||
e.Controller.Watch()
|
||||
if e.KContext.Screen.Type == "menu" {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Engine) Draw(screen *ebiten.Image) {
|
||||
g.Logic.Draw(screen)
|
||||
g.Logic.Controller.Clear()
|
||||
func (e *Engine) Draw(screen *ebiten.Image) {
|
||||
if e.KContext.Screen.Type == "menu" {
|
||||
menu := e.MenuMap[e.KContext.Screen.Value]
|
||||
|
||||
if e.Controller.DownPressed() && menu.CurrentSelected != len(menu.MenuItems)-1 {
|
||||
menu.CurrentSelected++
|
||||
}
|
||||
|
||||
if e.Controller.UpPressed() && menu.CurrentSelected != 0 {
|
||||
menu.CurrentSelected--
|
||||
}
|
||||
|
||||
e.MenuMap[e.KContext.Screen.Value] = menu
|
||||
|
||||
tt, _ := opentype.Parse(fonts.MPlus1pRegular_ttf)
|
||||
menu_face, _ := opentype.NewFace(tt, &opentype.FaceOptions{
|
||||
Size: menu.MenuLayout.DPI,
|
||||
DPI: menu.MenuLayout.Size,
|
||||
Hinting: font.HintingVertical,
|
||||
})
|
||||
for i, menu_item := range menu.MenuItems {
|
||||
if menu.CurrentSelected == i {
|
||||
text.Draw(screen, menu_item.Label+"\n", menu_face, 8, 24*(i+1), color.RGBA{R: 0, G: 255, B: 0, A: 100})
|
||||
} else {
|
||||
text.Draw(screen, menu_item.Label+"\n", menu_face, 8, 24*(i+1), color.White)
|
||||
}
|
||||
}
|
||||
if e.Controller.Action3Pressed() {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
e.Controller.Clear()
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ type ContextInterface interface {
|
||||
}
|
||||
|
||||
type DomainInterface interface {
|
||||
GetMenuMap() MenuMap
|
||||
Init()
|
||||
}
|
||||
|
||||
@@ -19,6 +18,15 @@ type ScreenSettings struct {
|
||||
Height int
|
||||
}
|
||||
|
||||
type KContextScreen struct {
|
||||
Type string
|
||||
Value string
|
||||
}
|
||||
|
||||
type KContext struct {
|
||||
Screen KContextScreen
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
Name string
|
||||
Screen *ScreenSettings
|
||||
@@ -28,17 +36,20 @@ type Konstructor struct {
|
||||
Domain DomainInterface
|
||||
Controller *Controller
|
||||
Settings *Settings
|
||||
KContext *KContext
|
||||
MenuMap MenuMap
|
||||
}
|
||||
|
||||
func (k Konstructor) Init() {
|
||||
k.Domain.Init()
|
||||
ebiten.SetWindowSize(k.Settings.Screen.Width, k.Settings.Screen.Height)
|
||||
ebiten.SetWindowTitle(k.Settings.Name)
|
||||
if err := ebiten.RunGame(&Engine{
|
||||
Logic: &Logic{
|
||||
Domain: k.Domain,
|
||||
Controller: k.Controller,
|
||||
Settings: k.Settings,
|
||||
},
|
||||
MenuMap: k.MenuMap,
|
||||
KContext: k.KContext,
|
||||
Domain: k.Domain,
|
||||
Controller: k.Controller,
|
||||
Settings: k.Settings,
|
||||
}); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package konstructor
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
)
|
||||
|
||||
type Logic struct {
|
||||
Domain DomainInterface
|
||||
Controller *Controller
|
||||
Settings *Settings
|
||||
}
|
||||
|
||||
func (l *Logic) Update(screen *ebiten.Image) {
|
||||
}
|
||||
|
||||
func (l *Logic) Draw(screen *ebiten.Image) {
|
||||
if l.Controller.UpPressed() {
|
||||
screen.Fill(color.White)
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ type MenuMap map[string]Menu
|
||||
|
||||
type MenuLayout struct {
|
||||
Background string
|
||||
DPI float64
|
||||
Size float64
|
||||
}
|
||||
|
||||
type MenuItem struct {
|
||||
@@ -13,6 +15,7 @@ type MenuItem struct {
|
||||
}
|
||||
|
||||
type Menu struct {
|
||||
MenuLayout MenuLayout
|
||||
MenuItems []MenuItem
|
||||
CurrentSelected int
|
||||
MenuLayout MenuLayout
|
||||
MenuItems []MenuItem
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user