move menu color to layout
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
5
main.go
5
main.go
@@ -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{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user