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 08:56:56 +00:00
|
|
|
ui.Proxy
|
2020-05-11 09:44:50 +00:00
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
intro ui.Overlay
|
|
|
|
research ui.Overlay
|
|
|
|
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 08:56:56 +00:00
|
|
|
const dialogsOverlayName = "dialogs"
|
|
|
|
|
2020-05-11 12:41:42 +00:00
|
|
|
func NewDialogs(game *Game) *Dialogs {
|
2020-05-17 08:56:56 +00:00
|
|
|
intro := NewIntro()
|
|
|
|
research := NewResearch(game)
|
|
|
|
settings := NewLargeDialog("Settings", &ui.Label{})
|
2020-05-11 12:41:42 +00:00
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
dialogs := &Dialogs{
|
|
|
|
intro: intro,
|
|
|
|
settings: settings,
|
|
|
|
research: research,
|
|
|
|
nothing: &ui.ControlBase{},
|
2020-05-11 09:44:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
intro.CloseRequested().AddHandlerEmpty(dialogs.Close)
|
|
|
|
research.CloseRequested().AddHandlerEmpty(dialogs.Close)
|
|
|
|
settings.CloseRequested().AddHandlerEmpty(dialogs.Close)
|
2020-05-11 12:41:42 +00:00
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
return dialogs
|
2020-05-11 12:41:42 +00:00
|
|
|
}
|
|
|
|
|
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 09:44:50 +00:00
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
d.Content = d.nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Dialogs) showDialog(ctx ui.Context, control ui.Control) {
|
|
|
|
if control == nil {
|
|
|
|
ctx.Overlays().Hide(dialogsOverlayName)
|
|
|
|
d.closed.Notify(ctx, control)
|
|
|
|
d.Content = d.nothing
|
|
|
|
} 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) {
|
|
|
|
d.showDialog(ctx, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Dialogs) DialogClosed() ui.EventHandler { return &d.closed }
|
|
|
|
func (d *Dialogs) DialogOpened() ui.EventHandler { return &d.opened }
|
|
|
|
|
|
|
|
func (d *Dialogs) Hidden() {
|
|
|
|
d.Proxy.Hidden()
|
2020-05-11 09:44:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 17:52:46 +00:00
|
|
|
func (d *Dialogs) AskConfirmation(ctx ui.Context, caption, question string, confirm, cancel ui.EventFn) {
|
|
|
|
dialog := newConfirmationDialog(caption, question)
|
|
|
|
dialog.userDecided.AddHandler(func(ctx ui.Context, state interface{}) {
|
|
|
|
decision := state.(bool)
|
|
|
|
if decision {
|
|
|
|
confirm(ctx, nil)
|
|
|
|
} else {
|
|
|
|
cancel(ctx, nil)
|
|
|
|
}
|
|
|
|
d.Close(ctx)
|
|
|
|
})
|
|
|
|
d.showDialog(ctx, dialog)
|
|
|
|
}
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
func (d *Dialogs) ShowIntro(ctx ui.Context) {
|
2020-05-11 12:41:42 +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) Shown() {
|
|
|
|
d.Proxy.Shown()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Dialogs) ShowResearch(ctx ui.Context) {
|
2020-05-11 12:41:42 +00:00
|
|
|
d.showDialog(ctx, d.research)
|
|
|
|
}
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
func (d *Dialogs) ShowSettings(ctx ui.Context) {
|
2020-05-11 12:41:42 +00:00
|
|
|
d.showDialog(ctx, d.settings)
|
2020-05-11 09:44:50 +00:00
|
|
|
}
|