Files
ordoor/internal/ui/inventory_select.go
Nick Thomas 786d261f98 Allow dialogues to be hidden or shown
To do this, MENU and SUBMENU are split into two types (at last), and
a Widget type is introduced. This should allow lots of code to be
removed at some point.
2020-04-14 03:14:49 +01:00

46 lines
1.0 KiB
Go

package ui
import (
"code.ur.gs/lupine/ordoor/internal/menus"
)
// An inventory select is a sort of radio button. If 2 share the same menu,
// selecting one deselects the other. Otherwise, they act like checkboxes.
//
// TODO: wrap all the behaviour in a single struct to make it easier to drive
type inventorySelect struct {
checkbox
parentPath string
others []*inventorySelect
}
// Called from the menu, which fills "others" for us
func (d *Driver) buildInventorySelect(p *menus.Properties) (*inventorySelect, *Widget, error) {
c, widget, err := d.buildCheckbox(p)
if err != nil {
return nil, nil, err
}
// In an inventorySelect, the frozen and click sprites are reversed
c.clickSpr, c.frozenSpr = c.frozenSpr, c.clickSpr
element := &inventorySelect{checkbox: *c}
return element, widget, nil
}
func (i *inventorySelect) registerMouseClick() {
// Do nothing if we're already selected
if i.value() == "1" {
return
}
// Turn us on, turn everyone else off
for _, other := range i.others {
other.setValue("0")
}
i.setValue("1")
}