2020-05-11 09:44:50 +00:00
|
|
|
package tins2020
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
import (
|
|
|
|
"opslag.de/schobers/zntg/ui"
|
|
|
|
)
|
|
|
|
|
2020-05-11 09:44:50 +00:00
|
|
|
type Dialogs struct {
|
2020-05-17 14:13:26 +00:00
|
|
|
ui.OverlayProxy
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
intro ui.Overlay
|
|
|
|
research ui.Overlay
|
2020-05-17 14:13:26 +00:00
|
|
|
settings ui.Overlay
|
|
|
|
nothing ui.Control
|
2020-05-11 09:44:50 +00:00
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
closed ui.Events
|
|
|
|
opened ui.Events
|
2020-05-11 09:44:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 14:13:26 +00:00
|
|
|
const dialogsOverlayName = "dialogs"
|
2020-05-17 08:56:56 +00:00
|
|
|
|
2020-05-11 12:41:42 +00:00
|
|
|
func NewDialogs(game *Game) *Dialogs {
|
2020-05-17 14:13:26 +00:00
|
|
|
intro := NewIntro()
|
|
|
|
research := NewResearch(game)
|
|
|
|
settings := NewLargeDialog("settings", &ui.Label{})
|
|
|
|
|
|
|
|
dialogs := &Dialogs{
|
|
|
|
intro: intro,
|
|
|
|
settings: settings,
|
|
|
|
research: research,
|
|
|
|
nothing: &ui.ControlBase{},
|
2020-05-11 09:44:50 +00:00
|
|
|
}
|
2020-05-17 14:13:26 +00:00
|
|
|
|
|
|
|
intro.CloseRequested().AddHandlerEmpty(dialogs.Close)
|
|
|
|
research.CloseRequested().AddHandlerEmpty(dialogs.Close)
|
|
|
|
settings.CloseRequested().AddHandlerEmpty(dialogs.Close)
|
|
|
|
|
|
|
|
return dialogs
|
2020-05-11 09:44:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
func (d *Dialogs) Init(ctx ui.Context) {
|
|
|
|
overlays := ctx.Overlays()
|
2020-05-17 14:13:26 +00:00
|
|
|
overlays.AddOnTop(dialogsOverlayName, d, false)
|
2020-05-11 12:41:42 +00:00
|
|
|
|
2020-05-17 14:13:26 +00:00
|
|
|
d.Content = d.nothing
|
2020-05-11 12:41:42 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 14:13:26 +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-11 09:44:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
func (d *Dialogs) Close(ctx ui.Context) {
|
2020-05-17 14:13:26 +00:00
|
|
|
d.showDialog(ctx, nil)
|
2020-05-11 09:44:50 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2020-05-17 14:13:26 +00:00
|
|
|
d.showDialog(ctx, d.intro)
|
2020-05-11 09:44:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
func (d *Dialogs) ShowResearch(ctx ui.Context) {
|
2020-05-17 14:13:26 +00:00
|
|
|
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) {
|
2020-05-17 14:13:26 +00:00
|
|
|
d.showDialog(ctx, d.settings)
|
2020-05-11 09:44:50 +00:00
|
|
|
}
|