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.
This commit is contained in:
@@ -157,24 +157,24 @@ func loadMenus() {
|
||||
|
||||
for _, menu := range menus {
|
||||
fmt.Printf(" * `%s`: objects=%v fonts=%v\n", menu.Name, menu.ObjectFiles, menu.FontNames)
|
||||
for _, record := range menu.Records {
|
||||
displayRecord(record, 2)
|
||||
|
||||
for _, group := range menu.Groups {
|
||||
// TODO: display group
|
||||
for _, record := range group.Records {
|
||||
displayRecord(record, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func displayRecord(record *menus.Record, depth int) {
|
||||
content := fmt.Sprintf("id=%v type=%v sprite=%v", record.Id, record.Type, record.SpriteId)
|
||||
content := fmt.Sprintf("id=%v type=%v sprite=%v", record.ID, record.Type, record.SpriteId)
|
||||
|
||||
if !record.Active {
|
||||
content = "(" + content + ")"
|
||||
}
|
||||
|
||||
fmt.Printf("%s* %s\n", strings.Repeat(" ", depth), content)
|
||||
|
||||
for _, child := range record.Children {
|
||||
displayRecord(child, depth+1)
|
||||
}
|
||||
}
|
||||
|
||||
func loadFonts() {
|
||||
|
@@ -5,6 +5,8 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
|
||||
"code.ur.gs/lupine/ordoor/internal/assetstore"
|
||||
"code.ur.gs/lupine/ordoor/internal/ui"
|
||||
)
|
||||
@@ -17,6 +19,12 @@ var (
|
||||
winY = flag.Int("win-y", 1024, "Pre-scaled window Y dimension")
|
||||
)
|
||||
|
||||
type dlg struct {
|
||||
driver *ui.Driver
|
||||
list []string
|
||||
pos int
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
@@ -45,7 +53,38 @@ func main() {
|
||||
log.Fatal("Couldn't create window: %v", err)
|
||||
}
|
||||
|
||||
// Change the active dialogue
|
||||
dialogues := driver.Dialogues()
|
||||
if len(dialogues) > 0 {
|
||||
dlg := &dlg{
|
||||
driver: driver,
|
||||
list: dialogues,
|
||||
}
|
||||
win.OnKeyUp(ebiten.KeyLeft, dlg.changeDialogue(-1))
|
||||
win.OnKeyUp(ebiten.KeyRight, dlg.changeDialogue(+1))
|
||||
for i, dialogue := range dlg.list {
|
||||
log.Printf("Dialogue %v: %v", i, dialogue)
|
||||
}
|
||||
}
|
||||
|
||||
if err := win.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dlg) changeDialogue(by int) func() {
|
||||
return func() {
|
||||
newPos := d.pos + by
|
||||
if newPos < 0 || newPos > len(d.list)-1 {
|
||||
log.Printf("Hiding dialogue %v: %q", d.pos, d.list[d.pos])
|
||||
d.driver.HideDialogue()
|
||||
return
|
||||
}
|
||||
|
||||
locator := d.list[newPos]
|
||||
log.Printf("Showing dialogue %v: %q", newPos, locator)
|
||||
|
||||
d.driver.ShowDialogue(locator)
|
||||
d.pos = newPos
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user