Implement the main menu for the ordoor binary
In this commit, we also remove code that doesn't properly belong in view-menu
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
// mind. The interface transparently scales them all to the current screen size
|
||||
// to compensate.
|
||||
type Interface struct {
|
||||
Name string
|
||||
menu *assetstore.Menu
|
||||
static []*assetstore.Sprite // Static elements in the interface
|
||||
ticks int
|
||||
@@ -28,6 +29,8 @@ type Interface struct {
|
||||
|
||||
func NewInterface(menu *assetstore.Menu) (*Interface, error) {
|
||||
iface := &Interface{
|
||||
Name: menu.Name,
|
||||
|
||||
menu: menu,
|
||||
}
|
||||
|
||||
@@ -59,6 +62,10 @@ func (i *Interface) Update(screenX, screenY int) error {
|
||||
|
||||
// Iterate through all widgets, update mouse state
|
||||
for _, widget := range i.widgets {
|
||||
if widget.disabled {
|
||||
continue // No activity for disabled widgets
|
||||
}
|
||||
|
||||
mouseIsOver := mousePos.In(widget.Bounds)
|
||||
widget.hovering(mouseIsOver)
|
||||
widget.mouseButton(mouseIsOver && ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft))
|
||||
@@ -188,11 +195,17 @@ func (i *Interface) widgetFromRecord(record *menus.Record) (*Widget, error) {
|
||||
}
|
||||
widget.hoverAnimation = hovers
|
||||
|
||||
sprite, err := i.menu.Sprite(record.Share + 1)
|
||||
pressed, err := i.menu.Sprite(record.Share + 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
widget.mouseButtonDownImage = sprite.Image
|
||||
widget.mouseButtonDownImage = pressed.Image
|
||||
|
||||
disabled, err := i.menu.Sprite(record.Share + 2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
widget.disabledImage = disabled.Image
|
||||
}
|
||||
|
||||
return widget, nil
|
||||
|
@@ -25,6 +25,9 @@ type Widget struct {
|
||||
OnMouseClick func()
|
||||
OnMouseUp func()
|
||||
|
||||
disabled bool
|
||||
disabledImage *ebiten.Image
|
||||
|
||||
// These are expected to have the same dimensions as the Bounds
|
||||
hoverAnimation []*ebiten.Image
|
||||
hoverState bool
|
||||
@@ -39,6 +42,13 @@ type Widget struct {
|
||||
sprite *assetstore.Sprite
|
||||
}
|
||||
|
||||
func (w *Widget) Disable() {
|
||||
w.hovering(false)
|
||||
w.mouseButton(false)
|
||||
|
||||
w.disabled = true
|
||||
}
|
||||
|
||||
func (w *Widget) hovering(value bool) {
|
||||
if w.OnHoverEnter != nil && !w.hoverState && value {
|
||||
w.OnHoverEnter()
|
||||
@@ -72,6 +82,10 @@ func (w *Widget) mouseButton(value bool) {
|
||||
}
|
||||
|
||||
func (w *Widget) Image(aniStep int) (*ebiten.Image, error) {
|
||||
if w.disabled {
|
||||
return w.disabledImage, nil
|
||||
}
|
||||
|
||||
if w.hoverState && w.mouseButtonState {
|
||||
return w.mouseButtonDownImage, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user