tins2020/dialogs.go

71 lines
1.4 KiB
Go

package tins2020
import (
"opslag.de/schobers/zntg/ui"
)
type Dialogs struct {
intro ui.Overlay
settings ui.Overlay
research ui.Overlay
open string
closed ui.Events
opened ui.Events
}
const introDialogName = "dialog-intro"
const settingsDialogName = "dialog-settings"
const researchDialogName = "dialog-research"
func NewDialogs(game *Game) *Dialogs {
return &Dialogs{
intro: NewIntro(),
settings: &LargeDialog{},
research: NewResearch(game),
}
}
func (d *Dialogs) Init(ctx ui.Context) {
overlays := ctx.Overlays()
overlays.AddOnTop(introDialogName, d.intro, false)
overlays.AddOnTop(settingsDialogName, d.settings, false)
overlays.AddOnTop(researchDialogName, d.research, false)
}
func (d *Dialogs) showDialog(ctx ui.Context, name string) {
d.Close(ctx)
ctx.Overlays().Show(name)
d.open = name
d.opened.Notify(ctx, name)
}
func (d *Dialogs) Close(ctx ui.Context) {
name := d.open
if name == "" {
return
}
ctx.Overlays().Hide(name)
d.open = ""
d.closed.Notify(ctx, name)
}
func (d *Dialogs) DialogClosed() ui.EventHandler { return &d.closed }
func (d *Dialogs) DialogOpened() ui.EventHandler { return &d.opened }
func (d *Dialogs) ShowIntro(ctx ui.Context) {
d.showDialog(ctx, introDialogName)
}
func (d *Dialogs) ShowResearch(ctx ui.Context) {
d.showDialog(ctx, researchDialogName)
}
func (d *Dialogs) ShowSettings(ctx ui.Context) {
d.showDialog(ctx, settingsDialogName)
}