dialog skeleton

This commit is contained in:
2023-07-04 19:36:40 +02:00
parent 7874fc022f
commit 1451bd90c0
8 changed files with 162 additions and 51 deletions

View File

@@ -4,20 +4,14 @@ import (
"image/color"
"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 MenuMap map[string]Menu
type MenuLayout struct {
Background string
DPI float64
Size float64
Color color.Color
SelectedColor color.Color
Background string
MenuItemFont FontLayout
}
type MenuItem struct {
@@ -28,23 +22,26 @@ type MenuItem struct {
type Menu struct {
CurrentSelected int
MenuLayout MenuLayout
Layout MenuLayout
MenuItems []MenuItem
}
func (menu *Menu) GetMenuItemColor(i int) color.Color {
if menu.CurrentSelected == i {
return menu.Layout.MenuItemFont.SelectedColor
} else {
return menu.Layout.MenuItemFont.Color
}
}
func (e *Engine) MenuDraw(screen *ebiten.Image) {
menu := e.MenuMap[e.KContext.Screen.Value]
face := e.menuGetFontFace(menu)
face := GetFontFace(menu.Layout.MenuItemFont)
for i, menu_item := range menu.MenuItems {
var c color.Color
if menu.CurrentSelected == i {
c = menu.MenuLayout.SelectedColor
} else {
c = menu.MenuLayout.Color
}
offset := int(menu.MenuLayout.Size) * (i + 1)
text.Draw(screen, menu_item.Label+"\n", face, 8, offset, c)
color := menu.GetMenuItemColor(i)
offset := int(menu.Layout.MenuItemFont.Size) * (i + 1)
text.Draw(screen, menu_item.Label+"\n", face, 8, offset, color)
}
}
@@ -65,13 +62,3 @@ func (e *Engine) MenuUpdate() {
e.MenuMap[e.KContext.Screen.Value] = menu
}
func (e *Engine) menuGetFontFace(menu Menu) font.Face {
tt, _ := opentype.Parse(fonts.MPlus1pRegular_ttf)
face, _ := opentype.NewFace(tt, &opentype.FaceOptions{
Size: menu.MenuLayout.DPI,
DPI: menu.MenuLayout.Size,
Hinting: font.HintingVertical,
})
return face
}