Add a partial listbox implementation

This commit is contained in:
2020-04-01 01:38:42 +01:00
parent 31da40e772
commit 7935f78acc
6 changed files with 241 additions and 53 deletions

View File

@@ -41,44 +41,38 @@ const (
TypeSlider MenuType = 232
TypeStatusBar MenuType = 233
TypeDialogue MenuType = 300
TypeListBoxUp MenuType = 400 // FIXME: these have multiple items in MENUTYPE
TypeListBoxDown MenuType = 405
)
// FIXME: certain elements - especially overlays - don't have a DESC specified
// in the .mnu file, but display text specified with a number in i18n. The only
// conclusion I can draw is that they're hardcoded in the binary and set from
// outside. So, do that here.
var DescOverrides = map[string]map[string]int{
"main": {
"2.6": 50992,
},
"newgame": {
"2.5": 50993,
},
"levelply": {
"2.6": 50996,
},
var DescOverrides = map[string]int{
"main:2.6": 50992,
"newgame:2.5": 50993,
"keyboard:3.3": 50995,
"levelply:2.6": 50996,
}
// FIXME: Same idea with text overrides, only these aren't mentioned in the .dta
// file at all!
var TextOverrides = map[string]map[string]string{
"main": {
"2.7": "0.1-ordoor",
},
var TextOverrides = map[string]string{
"main:2.7": "0.1-ordoor",
}
// FIXME: The menu is specified as type 2 (button) in these cases, which is
// weird. Make it a menu for now.
var TypeOverrides = map[string]map[string]MenuType{
"levelply": {
"2": TypeMenu,
},
"savegame": {
"2": TypeMenu,
},
"loadgame": {
"2": TypeMenu,
},
var TypeOverrides = map[string]MenuType{
"levelply:2": TypeMenu,
"savegame:2": TypeMenu,
"loadgame:2": TypeMenu,
// ???
"configure_ultequip:7.5": TypeListBoxUp,
"configure_ultequip:7.6": TypeListBoxDown,
}
type Record struct {
@@ -275,13 +269,15 @@ func setProperty(r *Record, k, v string) {
case "MENUID", "SUBMENUID":
r.Id = vInt
case "MENUTYPE", "SUBMENUTYPE":
r.Type = MenuType(vInt)
if strings.Contains(v, ",") {
r.Type = MenuType(vSplitInt[0]) // FIXME: what are the other values in this case?
} else {
r.Type = MenuType(vInt)
}
// FIXME: Type override. Note that MENUID is specified first, so this works
if overrides, ok := TypeOverrides[r.Menu.Name]; ok {
if newType, ok := overrides[r.Path()]; ok {
r.Type = newType
}
if override, ok := TypeOverrides[r.Locator()]; ok {
r.Type = override
}
case "ACTIVE":
r.Active = (vInt != 0)
@@ -308,17 +304,13 @@ type Replacer interface {
}
func (r *Record) Internationalize(replacer Replacer) {
if overrides, ok := TextOverrides[r.Menu.Name]; ok {
if override, ok := overrides[r.Path()]; ok {
delete(r.properties, "DESC")
r.Text = override
}
if override, ok := TextOverrides[r.Locator()]; ok {
delete(r.properties, "DESC")
r.Text = override
}
if overrides, ok := DescOverrides[r.Menu.Name]; ok {
if override, ok := overrides[r.Path()]; ok {
r.properties["DESC"] = strconv.Itoa(override)
}
if override, ok := DescOverrides[r.Locator()]; ok {
r.properties["DESC"] = strconv.Itoa(override)
}
id, err := strconv.Atoi(r.properties["DESC"])
@@ -348,3 +340,7 @@ func (r *Record) Path() string {
return strings.Join(path, ".")
}
func (r *Record) Locator() string {
return fmt.Sprintf("%v:%v", r.Menu.Name, r.Path())
}