move menu color to layout

This commit is contained in:
2023-07-04 13:29:44 +02:00
parent 996d770780
commit 61fb8af716
2 changed files with 22 additions and 13 deletions

View File

@@ -16,6 +16,8 @@ type MenuLayout struct {
Background string
DPI float64
Size float64
Color color.Color
SelectedColor color.Color
}
type MenuItem struct {
@@ -37,24 +39,26 @@ func (e *Engine) MenuDraw(screen *ebiten.Image) {
for i, menu_item := range menu.MenuItems {
var c color.Color
if menu.CurrentSelected == i {
c = color.RGBA{R: 0, G: 255, B: 0, A: 100}
c = menu.MenuLayout.SelectedColor
} else {
c = color.White
c = menu.MenuLayout.Color
}
text.Draw(screen, menu_item.Label+"\n", face, 8, 24*(i+1), c)
offset := int(menu.MenuLayout.Size) * (i + 1)
text.Draw(screen, menu_item.Label+"\n", face, 8, offset, c)
}
}
func (e *Engine) MenuUpdate() {
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--
}
if e.Controller.DownPressed() && menu.CurrentSelected != len(menu.MenuItems)-1 {
menu.CurrentSelected++
}
if e.Controller.Action0Pressed() {
menu.MenuItems[menu.CurrentSelected].Handler()
}

View File

@@ -3,6 +3,7 @@ package main
import (
"game/domain"
"game/konstructor"
"image/color"
"github.com/hajimehoshi/ebiten"
)
@@ -34,6 +35,8 @@ func main() {
MenuLayout: konstructor.MenuLayout{
DPI: 72,
Size: 24,
Color: color.White,
SelectedColor: color.RGBA{R: 0, G: 255, B: 0, A: 100},
},
MenuItems: []konstructor.MenuItem{
{
@@ -58,6 +61,8 @@ func main() {
MenuLayout: konstructor.MenuLayout{
DPI: 72,
Size: 24,
Color: color.White,
SelectedColor: color.RGBA{R: 0, G: 255, B: 0, A: 100},
},
MenuItems: []konstructor.MenuItem{
{