tins2020/dialogs.go

77 lines
1.6 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 {
ui.OverlayProxy
2020-05-17 08:56:56 +00:00
intro ui.Overlay
research ui.Overlay
settings ui.Overlay
nothing ui.Control
2020-05-17 08:56:56 +00:00
closed ui.Events
opened ui.Events
}
const dialogsOverlayName = "dialogs"
2020-05-17 08:56:56 +00:00
2020-05-11 12:41:42 +00:00
func NewDialogs(game *Game) *Dialogs {
intro := NewIntro()
research := NewResearch(game)
settings := NewLargeDialog("settings", &ui.Label{})
dialogs := &Dialogs{
intro: intro,
settings: settings,
research: research,
nothing: &ui.ControlBase{},
}
intro.CloseRequested().AddHandlerEmpty(dialogs.Close)
research.CloseRequested().AddHandlerEmpty(dialogs.Close)
settings.CloseRequested().AddHandlerEmpty(dialogs.Close)
return dialogs
}
2020-05-17 08:56:56 +00:00
func (d *Dialogs) Init(ctx ui.Context) {
overlays := ctx.Overlays()
overlays.AddOnTop(dialogsOverlayName, d, false)
2020-05-11 12:41:42 +00:00
d.Content = d.nothing
2020-05-11 12:41:42 +00:00
}
func (d *Dialogs) showDialog(ctx ui.Context, control ui.Control) {
if control == nil {
d.Content = d.nothing
ctx.Overlays().Hide(dialogsOverlayName)
d.closed.Notify(ctx, control)
} else {
d.Content = control
ctx.Overlays().Show(dialogsOverlayName)
d.opened.Notify(ctx, control)
}
}
2020-05-17 08:56:56 +00:00
func (d *Dialogs) Close(ctx ui.Context) {
d.showDialog(ctx, nil)
}
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, d.intro)
}
2020-05-17 08:56:56 +00:00
func (d *Dialogs) ShowResearch(ctx ui.Context) {
d.showDialog(ctx, d.research)
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, d.settings)
}