* When playing as the Bird, the dive attack is able to destroy other mobile doodads such as Azulians and Thieves. * The Box has been made invulnerable so it can't be destroyed by Anvils or player-controlled Birds. * Bugfixes with pop-up modals: * The quit game confirm modal doesn't appear if another modal is already active on screen. * The Escape key can dismiss Alert and Confirm modals. * Add "Level" menu items to Play Mode to restart the level or retry from the last checkpoint (in case of softlocks, etc.)
98 lines
1.8 KiB
Go
98 lines
1.8 KiB
Go
package modal
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
|
"git.kirsle.net/go/ui"
|
|
)
|
|
|
|
// Confirm pops up an Ok/Cancel modal.
|
|
func Confirm(message string, args ...interface{}) *Modal {
|
|
if !ready {
|
|
panic("modal.Confirm(): not ready")
|
|
} else if current != nil {
|
|
current.Dismiss(false)
|
|
}
|
|
|
|
// Reset the supervisor.
|
|
supervisor = ui.NewSupervisor()
|
|
|
|
m := &Modal{
|
|
title: "Confirm",
|
|
message: fmt.Sprintf(message, args...),
|
|
cancelable: true,
|
|
}
|
|
m.window = makeConfirm(m)
|
|
|
|
center(m.window)
|
|
current = m
|
|
|
|
return m
|
|
}
|
|
|
|
// makeConfirm creates the ui.Window for the Confirm modal.
|
|
func makeConfirm(m *Modal) *ui.Window {
|
|
win := ui.NewWindow("Confirm")
|
|
_, title := win.TitleBar()
|
|
title.TextVariable = &m.title
|
|
|
|
msgFrame := ui.NewFrame("Confirm Message")
|
|
win.Pack(msgFrame, ui.Pack{
|
|
Side: ui.N,
|
|
})
|
|
|
|
msg := ui.NewLabel(ui.Label{
|
|
TextVariable: &m.message,
|
|
Font: balance.UIFont,
|
|
})
|
|
msgFrame.Pack(msg, ui.Pack{
|
|
Side: ui.N,
|
|
})
|
|
|
|
// Ok/Cancel button bar.
|
|
btnBar := ui.NewFrame("Button Bar")
|
|
msgFrame.Pack(btnBar, ui.Pack{
|
|
Side: ui.N,
|
|
PadY: 4,
|
|
})
|
|
|
|
for _, btn := range []struct {
|
|
Label string
|
|
F func(ui.EventData) error
|
|
}{
|
|
{"Ok", func(ev ui.EventData) error {
|
|
m.Dismiss(true)
|
|
return nil
|
|
}},
|
|
{"Cancel", func(ev ui.EventData) error {
|
|
m.Dismiss(false)
|
|
return nil
|
|
}},
|
|
} {
|
|
btn := btn
|
|
button := ui.NewButton(btn.Label+"Button", ui.NewLabel(ui.Label{
|
|
Text: btn.Label,
|
|
Font: balance.MenuFont,
|
|
}))
|
|
button.Handle(ui.Click, btn.F)
|
|
button.Compute(engine)
|
|
supervisor.Add(button)
|
|
|
|
// OK Button is primary.
|
|
if btn.Label == "Ok" {
|
|
button.SetStyle(&balance.ButtonPrimary)
|
|
}
|
|
|
|
btnBar.Pack(button, ui.Pack{
|
|
Side: ui.W,
|
|
PadX: 2,
|
|
})
|
|
}
|
|
|
|
win.Compute(engine)
|
|
win.Supervise(supervisor)
|
|
|
|
return win
|
|
}
|