Make the menu buttons work
This commit is contained in:
@@ -2,6 +2,7 @@ package assetstore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -23,12 +24,13 @@ type Object struct {
|
||||
type Sprite struct {
|
||||
obj *Object
|
||||
|
||||
ID string
|
||||
XOffset int
|
||||
XOffset int // TODO: replace these everywhere with Rect
|
||||
YOffset int
|
||||
Width int
|
||||
Height int
|
||||
|
||||
ID string
|
||||
Rect image.Rectangle
|
||||
Image *ebiten.Image
|
||||
}
|
||||
|
||||
@@ -106,13 +108,21 @@ func (o *Object) Sprite(idx int) (*Sprite, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rect := image.Rect(
|
||||
int(raw.XOffset),
|
||||
int(raw.YOffset),
|
||||
int(raw.XOffset+raw.Width),
|
||||
int(raw.YOffset+raw.Height),
|
||||
)
|
||||
|
||||
sprite := &Sprite{
|
||||
ID: fmt.Sprintf("%v:%v", o.raw.Name, idx),
|
||||
obj: o,
|
||||
Width: int(raw.Width),
|
||||
Height: int(raw.Width),
|
||||
XOffset: int(raw.XOffset),
|
||||
YOffset: int(raw.YOffset),
|
||||
Width: rect.Dx(),
|
||||
Height: rect.Dy(),
|
||||
XOffset: rect.Min.X,
|
||||
YOffset: rect.Min.Y,
|
||||
Rect: rect,
|
||||
Image: img,
|
||||
}
|
||||
|
||||
|
@@ -10,15 +10,24 @@ import (
|
||||
"code.ur.gs/lupine/ordoor/internal/util/asciiscan"
|
||||
)
|
||||
|
||||
const (
|
||||
TypeStatic = 0
|
||||
TypeMenu = 1
|
||||
TypeOverlay = 61
|
||||
TypeMainButton = 228
|
||||
)
|
||||
|
||||
type Record struct {
|
||||
Parent *Record
|
||||
Children []*Record
|
||||
|
||||
Id int
|
||||
Type int
|
||||
DrawType int
|
||||
FontType int
|
||||
Active bool
|
||||
SpriteId []int
|
||||
Share int
|
||||
X int
|
||||
Y int
|
||||
Desc string
|
||||
@@ -161,6 +170,29 @@ func (r *Record) Toplevel() *Record {
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *Record) SelectSprite(step int, pressed, focused bool) int {
|
||||
switch r.Type {
|
||||
case TypeStatic:
|
||||
return r.SpriteId[0]
|
||||
case TypeMenu:
|
||||
return r.SpriteId[0] // Probably -1
|
||||
case TypeOverlay:
|
||||
return r.Share
|
||||
case TypeMainButton:
|
||||
// A main button has 4 states: unfocused, focused (animated), mousedown, disabled
|
||||
if focused && pressed {
|
||||
return r.Share + 1
|
||||
} else if focused {
|
||||
return r.SpriteId[0] + (step % r.DrawType)
|
||||
}
|
||||
|
||||
// TODO: disabled
|
||||
return r.Share
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
func setProperty(r *Record, k, v string) {
|
||||
vSplit := strings.Split(v, ",")
|
||||
vInt, _ := strconv.Atoi(v)
|
||||
@@ -187,6 +219,10 @@ func setProperty(r *Record, k, v string) {
|
||||
r.Desc = v
|
||||
case "FONTTYPE":
|
||||
r.FontType = vInt
|
||||
case "DRAW TYPE":
|
||||
r.DrawType = vInt
|
||||
case "SHARE":
|
||||
r.Share = vInt
|
||||
default:
|
||||
r.properties[k] = v
|
||||
}
|
||||
|
Reference in New Issue
Block a user