SelectBoxes in Add/Edit Level Window
* Replace the radio buttons for Page Type and Wallpaper with the new SelectBox widgets from the UI toolkit. * Choice of default palette also switched from a MenuButton to a SelectBox widget. * Experimental "Browse..." option added to the Wallpaper drop-down when run in --experimental mode; not yet functional.
This commit is contained in:
parent
3d8eedce35
commit
ba29f407cc
|
@ -3,16 +3,19 @@ package balance
|
|||
// Feature Flags to turn on/off experimental content.
|
||||
var Feature = feature{
|
||||
Zoom: false,
|
||||
CustomWallpaper: false,
|
||||
ChangePalette: false,
|
||||
}
|
||||
|
||||
// FeaturesOn turns on all feature flags, from CLI --experimental option.
|
||||
func FeaturesOn() {
|
||||
Feature.Zoom = true
|
||||
Feature.CustomWallpaper = true
|
||||
Feature.ChangePalette = true
|
||||
}
|
||||
|
||||
type feature struct {
|
||||
Zoom bool
|
||||
CustomWallpaper bool
|
||||
ChangePalette bool
|
||||
}
|
||||
|
|
|
@ -64,31 +64,39 @@ func NewAddEditLevel(config AddEditLevel) *ui.Window {
|
|||
* Frame for selecting Page Type
|
||||
******************/
|
||||
|
||||
label1 := ui.NewLabel(ui.Label{
|
||||
Text: "Page Type",
|
||||
Font: balance.LabelFont,
|
||||
})
|
||||
frame.Pack(label1, ui.Pack{
|
||||
Side: ui.N,
|
||||
FillX: true,
|
||||
})
|
||||
|
||||
typeFrame := ui.NewFrame("Page Type Options Frame")
|
||||
frame.Pack(typeFrame, ui.Pack{
|
||||
Side: ui.N,
|
||||
FillX: true,
|
||||
})
|
||||
|
||||
label1 := ui.NewLabel(ui.Label{
|
||||
Text: "Page Type:",
|
||||
Font: balance.LabelFont,
|
||||
})
|
||||
typeFrame.Pack(label1, ui.Pack{
|
||||
Side: ui.W,
|
||||
})
|
||||
|
||||
type typeObj struct {
|
||||
Name string
|
||||
Value level.PageType
|
||||
}
|
||||
var types = []typeObj{
|
||||
{"Unbounded", level.Unbounded},
|
||||
{"Bounded", level.Bounded},
|
||||
{"Unbounded", level.Unbounded},
|
||||
{"No Negative Space", level.NoNegativeSpace},
|
||||
// {"Bordered (TODO)", level.Bordered},
|
||||
}
|
||||
|
||||
typeBtn := ui.NewSelectBox("Type Select", ui.Label{
|
||||
Font: ui.MenuFont,
|
||||
})
|
||||
typeFrame.Pack(typeBtn, ui.Pack{
|
||||
Side: ui.W,
|
||||
Expand: true,
|
||||
})
|
||||
|
||||
for _, t := range types {
|
||||
// TODO: Hide some options for the free version of the game.
|
||||
// - At launch only Bounded and Bordered will be available
|
||||
|
@ -100,46 +108,44 @@ func NewAddEditLevel(config AddEditLevel) *ui.Window {
|
|||
// continue
|
||||
// }
|
||||
// }
|
||||
typeBtn.AddItem(t.Name, t.Value, func() {})
|
||||
}
|
||||
|
||||
func(t typeObj) {
|
||||
radio := ui.NewRadioButton(t.Name,
|
||||
&newPageType,
|
||||
t.Value.String(),
|
||||
ui.NewLabel(ui.Label{
|
||||
Text: t.Name,
|
||||
Font: balance.MenuFont,
|
||||
}),
|
||||
)
|
||||
radio.Handle(ui.Click, func(ed ui.EventData) error {
|
||||
config.OnChangePageTypeAndWallpaper(t.Value, newWallpaper)
|
||||
// If editing an existing level, pre-select the right page type.
|
||||
if config.EditLevel != nil {
|
||||
typeBtn.SetValue(config.EditLevel.PageType)
|
||||
}
|
||||
|
||||
typeBtn.Handle(ui.Change, func(ed ui.EventData) error {
|
||||
if selection, ok := typeBtn.GetValue(); ok {
|
||||
if pageType, ok := selection.Value.(level.PageType); ok {
|
||||
newPageType = pageType.String()
|
||||
config.OnChangePageTypeAndWallpaper(pageType, newWallpaper)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
config.Supervisor.Add(radio)
|
||||
typeFrame.Pack(radio, ui.Pack{
|
||||
Side: ui.W,
|
||||
PadX: 4,
|
||||
})
|
||||
}(t)
|
||||
}
|
||||
|
||||
typeBtn.Supervise(config.Supervisor)
|
||||
config.Supervisor.Add(typeBtn)
|
||||
|
||||
/******************
|
||||
* Frame for selecting Level Wallpaper
|
||||
******************/
|
||||
|
||||
label2 := ui.NewLabel(ui.Label{
|
||||
Text: "Wallpaper",
|
||||
Font: balance.LabelFont,
|
||||
})
|
||||
frame.Pack(label2, ui.Pack{
|
||||
wpFrame := ui.NewFrame("Wallpaper Frame")
|
||||
frame.Pack(wpFrame, ui.Pack{
|
||||
Side: ui.N,
|
||||
FillX: true,
|
||||
PadY: 2,
|
||||
})
|
||||
|
||||
wpFrame := ui.NewFrame("Wallpaper Frame")
|
||||
frame.Pack(wpFrame, ui.Pack{
|
||||
Side: ui.N,
|
||||
FillX: true,
|
||||
label2 := ui.NewLabel(ui.Label{
|
||||
Text: "Wallpaper:",
|
||||
Font: balance.LabelFont,
|
||||
})
|
||||
wpFrame.Pack(label2, ui.Pack{
|
||||
Side: ui.W,
|
||||
PadY: 2,
|
||||
})
|
||||
|
||||
|
@ -154,34 +160,54 @@ func NewAddEditLevel(config AddEditLevel) *ui.Window {
|
|||
{"Pure White", "white.png"},
|
||||
// {"Placemat", "placemat.png"},
|
||||
}
|
||||
for _, t := range wallpapers {
|
||||
func(t wallpaperObj) {
|
||||
radio := ui.NewRadioButton(t.Name, &newWallpaper, t.Value, ui.NewLabel(ui.Label{
|
||||
Text: t.Name,
|
||||
|
||||
wallBtn := ui.NewSelectBox("Wallpaper Select", ui.Label{
|
||||
Font: balance.MenuFont,
|
||||
}))
|
||||
radio.Handle(ui.Click, func(ed ui.EventData) error {
|
||||
})
|
||||
wallBtn.AlwaysChange = true
|
||||
wpFrame.Pack(wallBtn, ui.Pack{
|
||||
Side: ui.W,
|
||||
Expand: true,
|
||||
})
|
||||
|
||||
for _, t := range wallpapers {
|
||||
wallBtn.AddItem(t.Name, t.Value, func() {})
|
||||
}
|
||||
|
||||
// Add custom wallpaper options.
|
||||
if balance.Feature.CustomWallpaper {
|
||||
wallBtn.AddSeparator()
|
||||
wallBtn.AddItem("Browse...", "_custom", func() {})
|
||||
}
|
||||
|
||||
// If editing a level, select the current wallpaper.
|
||||
if config.EditLevel != nil {
|
||||
wallBtn.SetValue(config.EditLevel.Wallpaper)
|
||||
}
|
||||
|
||||
wallBtn.Handle(ui.Change, func(ed ui.EventData) error {
|
||||
if selection, ok := wallBtn.GetValue(); ok {
|
||||
if filename, ok := selection.Value.(string); ok {
|
||||
// Picking the Custom option?
|
||||
if filename == "_custom" {
|
||||
shmem.Prompt("Enter file path to custom wallpaper:", func(filepath string) {
|
||||
shmem.Flash("Chosen: %s", filepath)
|
||||
newWallpaper = filename
|
||||
})
|
||||
// return nil
|
||||
}
|
||||
|
||||
if pageType, ok := level.PageTypeFromString(newPageType); ok {
|
||||
config.OnChangePageTypeAndWallpaper(pageType, t.Value)
|
||||
config.OnChangePageTypeAndWallpaper(pageType, filename)
|
||||
newWallpaper = filename
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
config.Supervisor.Add(radio)
|
||||
wpFrame.Pack(radio, ui.Pack{
|
||||
Side: ui.W,
|
||||
PadX: 4,
|
||||
})
|
||||
|
||||
// If a new level, the Blueprint button has a tooltip
|
||||
// hinting to pick the Blueprint palette to match.
|
||||
if config.EditLevel == nil && t.Name == "Blueprint" {
|
||||
ui.NewTooltip(radio, ui.Tooltip{
|
||||
Text: "Dark theme! Make sure to also\npick a Blueprint color palette!",
|
||||
Edge: ui.Top,
|
||||
})
|
||||
}
|
||||
}(t)
|
||||
}
|
||||
wallBtn.Supervise(config.Supervisor)
|
||||
config.Supervisor.Add(wallBtn)
|
||||
|
||||
/******************
|
||||
* Frame for picking a default color palette.
|
||||
|
@ -204,32 +230,34 @@ func NewAddEditLevel(config AddEditLevel) *ui.Window {
|
|||
Side: ui.W,
|
||||
})
|
||||
|
||||
palBtn := ui.NewMenuButton("Palette Button", ui.NewLabel(ui.Label{
|
||||
TextVariable: &paletteName,
|
||||
palBtn := ui.NewSelectBox("Palette Select", ui.Label{
|
||||
Font: balance.MenuFont,
|
||||
}))
|
||||
})
|
||||
palBtn.AlwaysChange = true
|
||||
|
||||
palFrame.Pack(palBtn, ui.Pack{
|
||||
Side: ui.W,
|
||||
// FillX: true,
|
||||
Expand: true,
|
||||
})
|
||||
|
||||
if config.EditLevel != nil {
|
||||
palBtn.AddItem(paletteName, func() {
|
||||
paletteName = textCurrentPalette
|
||||
})
|
||||
palBtn.AddItem(paletteName, paletteName, func() {})
|
||||
palBtn.AddSeparator();
|
||||
}
|
||||
|
||||
for _, palName := range level.DefaultPaletteNames {
|
||||
palName := palName
|
||||
// palette := level.DefaultPalettes[palName]
|
||||
palBtn.AddItem(palName, func() {
|
||||
paletteName = palName
|
||||
})
|
||||
palBtn.AddItem(palName, palName, func() {})
|
||||
}
|
||||
|
||||
palBtn.Handle(ui.Change, func(ed ui.EventData) error {
|
||||
if val, ok := palBtn.GetValue(); ok {
|
||||
val2, _ := val.Value.(string)
|
||||
paletteName = val2
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
config.Supervisor.Add(palBtn)
|
||||
palBtn.Supervise(config.Supervisor)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user