2020-03-31 23:45:11 +01:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"code.ur.gs/lupine/ordoor/internal/menus"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// These menu types don't need driving, so we can ignore them
|
|
|
|
registerBuilder(menus.TypeMenu, registerMenu)
|
|
|
|
registerBuilder(menus.TypeDragMenu, nil) // Menus are just containers
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerMenu(d *Driver, r *menus.Record) ([]*menus.Record, error) {
|
2020-04-01 01:38:42 +01:00
|
|
|
childrenLeft, err := listBoxFromMenu(d, r, r.Children)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
childrenLeft, err = inventorySelectFromMenu(d, r, childrenLeft)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return all the unhandled children to be processed further
|
|
|
|
return childrenLeft, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func listBoxFromMenu(d *Driver, menu *menus.Record, children []*menus.Record) ([]*menus.Record, error) {
|
|
|
|
ok := false
|
|
|
|
for _, rec := range children {
|
|
|
|
if rec.Type == menus.TypeThumb { // FIXME: we're using this to indicate a listbox
|
|
|
|
ok = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
return children, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return registerListBox(d, menu)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Group all inventory selects that share a menu together
|
|
|
|
func inventorySelectFromMenu(d *Driver, menu *menus.Record, children []*menus.Record) ([]*menus.Record, error) {
|
2020-03-31 23:45:11 +01:00
|
|
|
var childrenLeft []*menus.Record
|
|
|
|
var inventorySelects []*inventorySelect
|
|
|
|
|
2020-04-01 01:38:42 +01:00
|
|
|
for _, child := range children {
|
2020-03-31 23:45:11 +01:00
|
|
|
switch child.Type {
|
|
|
|
case menus.TypeInventorySelect:
|
|
|
|
is, err := registerInventorySelect(d, child)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
inventorySelects = append(inventorySelects, is)
|
|
|
|
default:
|
|
|
|
childrenLeft = append(childrenLeft, child)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(inventorySelects) > 0 {
|
|
|
|
inventorySelects[0].setValue("1") // Always start with one selected
|
|
|
|
|
|
|
|
for _, is := range inventorySelects {
|
|
|
|
is.others = inventorySelects
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return childrenLeft, nil
|
|
|
|
}
|