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:
@@ -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