tins2020/dialogs.go

71 lines
1.4 KiB
Go
Raw Normal View History

package tins2020
2020-05-17 08:56:56 +00:00
import (
"opslag.de/schobers/zntg/ui"
)
type Dialogs struct {
2020-05-17 08:56:56 +00:00
intro ui.Overlay
settings ui.Overlay
research ui.Overlay
2020-05-17 08:56:56 +00:00
open string
2020-05-17 08:56:56 +00:00
closed ui.Events
opened ui.Events
}
2020-05-17 08:56:56 +00:00
const introDialogName = "dialog-intro"
const settingsDialogName = "dialog-settings"
const researchDialogName = "dialog-research"
2020-05-11 12:41:42 +00:00
func NewDialogs(game *Game) *Dialogs {
return &Dialogs{
2020-05-17 08:56:56 +00:00
intro: NewIntro(),
2020-05-11 12:41:42 +00:00
settings: &LargeDialog{},
research: NewResearch(game),
}
}
2020-05-17 08:56:56 +00:00
func (d *Dialogs) Init(ctx ui.Context) {
overlays := ctx.Overlays()
2020-05-11 12:41:42 +00:00
2020-05-17 08:56:56 +00:00
overlays.AddOnTop(introDialogName, d.intro, false)
overlays.AddOnTop(settingsDialogName, d.settings, false)
overlays.AddOnTop(researchDialogName, d.research, false)
2020-05-11 12:41:42 +00:00
}
2020-05-17 08:56:56 +00:00
func (d *Dialogs) showDialog(ctx ui.Context, name string) {
d.Close(ctx)
2020-05-17 08:56:56 +00:00
ctx.Overlays().Show(name)
d.open = name
d.opened.Notify(ctx, name)
}
2020-05-17 08:56:56 +00:00
func (d *Dialogs) Close(ctx ui.Context) {
name := d.open
if name == "" {
return
}
ctx.Overlays().Hide(name)
d.open = ""
d.closed.Notify(ctx, name)
}
2020-05-17 08:56:56 +00:00
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)
}
2020-05-17 08:56:56 +00:00
func (d *Dialogs) ShowResearch(ctx ui.Context) {
d.showDialog(ctx, researchDialogName)
2020-05-11 12:41:42 +00:00
}
2020-05-17 08:56:56 +00:00
func (d *Dialogs) ShowSettings(ctx ui.Context) {
d.showDialog(ctx, settingsDialogName)
}