Display overlay text in the UI

We still have fonts to do, so this is very ugly, but it at least shows
*something* on the screen now.
This commit is contained in:
2020-03-26 22:09:26 +00:00
parent a0fd653c24
commit e4ce932324
7 changed files with 107 additions and 34 deletions

View File

@@ -41,6 +41,7 @@ const (
)
type Record struct {
Menu *Menu
Parent *Record
Children []*Record
@@ -53,7 +54,10 @@ type Record struct {
Share int
X int
Y int
Desc string
// From i18n
Text string
Help string
// FIXME: turn these into first-class data
properties map[string]string
@@ -75,6 +79,8 @@ type Menu struct {
func LoadMenu(filename string) (*Menu, error) {
name := filepath.Base(filename)
name = strings.Replace(name, filepath.Ext(name), "", -1)
name = strings.ToLower(name)
// FIXME: this needs turning into a real parser sometime
scanner, err := asciiscan.New(filename)
@@ -132,9 +138,9 @@ func LoadMenu(filename string) (*Menu, error) {
k, v := asciiscan.ConsumeProperty(str)
switch k {
case "MENUID":
record = newRecord(nil)
record = newRecord(out, nil)
case "SUBMENUID":
record = newRecord(record.Toplevel())
record = newRecord(out, record.Toplevel())
}
setProperty(record, k, v)
}
@@ -172,8 +178,9 @@ func LoadMenus(dir string) (map[string]*Menu, error) {
return out, nil
}
func newRecord(parent *Record) *Record {
func newRecord(menu *Menu, parent *Record) *Record {
out := &Record{
Menu: menu,
Parent: parent,
properties: map[string]string{},
}
@@ -215,8 +222,6 @@ func setProperty(r *Record, k, v string) {
r.X = vInt
case "Y-CORD":
r.Y = vInt
case "DESC":
r.Desc = v
case "FONTTYPE":
r.FontType = vInt
case "DRAW TYPE":
@@ -229,13 +234,26 @@ func setProperty(r *Record, k, v string) {
}
type Replacer interface {
Replace(int, *string)
ReplaceText(int, *string)
ReplaceHelp(int, *string)
}
func (r *Record) Internationalize(replacer Replacer) {
id, err := strconv.Atoi(r.Desc)
// FIXME: I can't see how else this would happen in the original
if r.Menu.Name == "main" {
switch r.Path() {
case "2.6":
r.properties["DESC"] = "50992" // Chaos Gate
case "2.7":
r.Text = "ordoor-0.0.0"
}
}
id, err := strconv.Atoi(r.properties["DESC"])
if err == nil {
replacer.Replace(id, &r.Desc)
delete(r.properties, "DESC")
replacer.ReplaceText(id, &r.Text)
replacer.ReplaceHelp(id, &r.Help)
}
for _, child := range r.Children {