tins2020/dialogs.go

67 lines
1.3 KiB
Go
Raw Normal View History

package tins2020
type Dialogs struct {
Proxy
intro Control
settings Control
research Control
dialogClosed *Events
dialogOpened *Events
}
func NewDialogs(game *Game) *Dialogs {
return &Dialogs{
intro: &Intro{},
settings: &LargeDialog{},
research: NewResearch(game),
dialogClosed: NewEvents(),
dialogOpened: NewEvents(),
}
}
func (d *Dialogs) showDialog(ctx *Context, control Control) {
d.SetContent(ctx, control)
control.(Dialog).ShowDialog(ctx, d.Close)
d.dialogOpened.Notify(nil)
}
func (d *Dialogs) Arrange(ctx *Context, bounds Rectangle) {
d.Proxy.Arrange(ctx, bounds)
}
func (d *Dialogs) DialogClosed() EventHandler { return d.dialogClosed }
func (d *Dialogs) DialogOpened() EventHandler { return d.dialogOpened }
func (d *Dialogs) Init(ctx *Context) error {
err := d.intro.Init(ctx)
if err != nil {
return err
}
err = d.settings.Init(ctx)
if err != nil {
return err
}
err = d.research.Init(ctx)
return nil
}
func (d *Dialogs) Close() {
d.SetContent(nil, nil)
d.dialogClosed.Notify(nil)
}
func (d *Dialogs) ShowIntro(ctx *Context) {
d.showDialog(ctx, d.intro)
}
func (d *Dialogs) ShowResearch(ctx *Context) {
d.showDialog(ctx, d.research)
}
func (d *Dialogs) ShowSettings(ctx *Context) {
d.showDialog(ctx, d.settings)
}