Wire up inventory select to ship state

Also mixed into this commit:

* Use returning drivers where possible
* Make the credits screen returnable via click
This commit is contained in:
2020-04-14 15:11:25 +01:00
parent 26c976353f
commit 2f65cd312a
11 changed files with 158 additions and 53 deletions

View File

@@ -86,15 +86,10 @@ func New(assets *assetstore.AssetStore, config *config.Config, ship *ship.Ship)
out.drivers[name] = driver
}
// Initial load of the config into the options UI
if err := out.configIntoOptions(); err != nil {
return nil, err
}
out.linkDrivers()
out.setDriverNow(main)
out.reset()
return out, nil
return out, out.exit
}
func buildDriver(assets *assetstore.AssetStore, name driverName) (*ui.Driver, error) {
@@ -164,11 +159,11 @@ func (f *Flow) Cursor() (*ebiten.Image, *ebiten.DrawImageOptions, error) {
func (f *Flow) linkDrivers() {
// linkMain
f.onClick(main, "2.1", f.setDriver(newGame)) // New game
f.onClick(main, "2.2", f.setDriver(loadGame)) // Load game
f.setFreeze(main, "2.3", true) // Multiplayer - disable for now
f.onClick(main, "2.4", f.setReturningDriver(main, options)) // Options
f.onClick(main, "2.5", f.setExit) // Quit
f.onClick(main, "2.1", f.setReturningDriver(main, newGame)) // New game
f.onClick(main, "2.2", f.setReturningDriver(main, loadGame)) // Load game
f.setFreeze(main, "2.3", true) // Multiplayer - disable for now
f.onClick(main, "2.4", f.setReturningDriver(main, options)) // Options
f.onClick(main, "2.5", f.setExit) // Quit
// Now link immediate children. They will link their children, and so on
f.linkNewGame()
@@ -217,6 +212,18 @@ func (f *Flow) setValueBool(driver driverName, id string, value bool) {
f.exit = f.drivers[driver].SetValueBool(id, value)
}
func (f *Flow) valueBool(driver driverName, id string) bool {
if f.exit != nil {
return false
}
var value bool
f.exit = f.drivers[driver].ValueBool(id, &value)
return value
}
func (f *Flow) playNextScenario(from driverName) func() {
return func() {
log.Printf("Loading scenario: %v", f.ship.NextScenario)
@@ -244,11 +251,26 @@ func (f *Flow) hideDialogue(driver driverName) func() {
return f.drivers[driver].HideDialogue
}
func (f *Flow) reset() {
if f.exit != nil {
return
}
f.setDriverNow(main) // Back to the main interface
// Wipe out any returns that may exist
f.returns = make(map[driverName]driverName)
// FIXME: these should really happen via data binding.
f.resetLevelPlyInventorySelect()
f.exit = f.configIntoOptions()
}
func (f *Flow) setExit() {
f.exit = ErrExit
}
// TODO: convert all to locators
func locator(d driverName, id string) string {
return fmt.Sprintf("%v:%v", strings.ToLower(string(d)), id)
func locator(driver driverName, id string) string {
return fmt.Sprintf("%v:%v", strings.ToLower(string(driver)), id)
}