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:
Noah 2021-06-06 14:32:52 -07:00
parent 3d8eedce35
commit ba29f407cc
2 changed files with 107 additions and 76 deletions

View File

@ -3,16 +3,19 @@ package balance
// Feature Flags to turn on/off experimental content. // Feature Flags to turn on/off experimental content.
var Feature = feature{ var Feature = feature{
Zoom: false, Zoom: false,
CustomWallpaper: false,
ChangePalette: false, ChangePalette: false,
} }
// FeaturesOn turns on all feature flags, from CLI --experimental option. // FeaturesOn turns on all feature flags, from CLI --experimental option.
func FeaturesOn() { func FeaturesOn() {
Feature.Zoom = true Feature.Zoom = true
Feature.CustomWallpaper = true
Feature.ChangePalette = true Feature.ChangePalette = true
} }
type feature struct { type feature struct {
Zoom bool Zoom bool
CustomWallpaper bool
ChangePalette bool ChangePalette bool
} }

View File

@ -64,31 +64,39 @@ func NewAddEditLevel(config AddEditLevel) *ui.Window {
* Frame for selecting Page Type * 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") typeFrame := ui.NewFrame("Page Type Options Frame")
frame.Pack(typeFrame, ui.Pack{ frame.Pack(typeFrame, ui.Pack{
Side: ui.N, Side: ui.N,
FillX: true, FillX: true,
}) })
label1 := ui.NewLabel(ui.Label{
Text: "Page Type:",
Font: balance.LabelFont,
})
typeFrame.Pack(label1, ui.Pack{
Side: ui.W,
})
type typeObj struct { type typeObj struct {
Name string Name string
Value level.PageType Value level.PageType
} }
var types = []typeObj{ var types = []typeObj{
{"Unbounded", level.Unbounded},
{"Bounded", level.Bounded}, {"Bounded", level.Bounded},
{"Unbounded", level.Unbounded},
{"No Negative Space", level.NoNegativeSpace}, {"No Negative Space", level.NoNegativeSpace},
// {"Bordered (TODO)", level.Bordered}, // {"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 { for _, t := range types {
// TODO: Hide some options for the free version of the game. // TODO: Hide some options for the free version of the game.
// - At launch only Bounded and Bordered will be available // - At launch only Bounded and Bordered will be available
@ -100,46 +108,44 @@ func NewAddEditLevel(config AddEditLevel) *ui.Window {
// continue // continue
// } // }
// } // }
typeBtn.AddItem(t.Name, t.Value, func() {})
}
func(t typeObj) { // If editing an existing level, pre-select the right page type.
radio := ui.NewRadioButton(t.Name, if config.EditLevel != nil {
&newPageType, typeBtn.SetValue(config.EditLevel.PageType)
t.Value.String(), }
ui.NewLabel(ui.Label{
Text: t.Name, typeBtn.Handle(ui.Change, func(ed ui.EventData) error {
Font: balance.MenuFont, if selection, ok := typeBtn.GetValue(); ok {
}), if pageType, ok := selection.Value.(level.PageType); ok {
) newPageType = pageType.String()
radio.Handle(ui.Click, func(ed ui.EventData) error { config.OnChangePageTypeAndWallpaper(pageType, newWallpaper)
config.OnChangePageTypeAndWallpaper(t.Value, newWallpaper) }
}
return nil return nil
}) })
config.Supervisor.Add(radio)
typeFrame.Pack(radio, ui.Pack{ typeBtn.Supervise(config.Supervisor)
Side: ui.W, config.Supervisor.Add(typeBtn)
PadX: 4,
})
}(t)
}
/****************** /******************
* Frame for selecting Level Wallpaper * Frame for selecting Level Wallpaper
******************/ ******************/
label2 := ui.NewLabel(ui.Label{ wpFrame := ui.NewFrame("Wallpaper Frame")
Text: "Wallpaper", frame.Pack(wpFrame, ui.Pack{
Font: balance.LabelFont,
})
frame.Pack(label2, ui.Pack{
Side: ui.N, Side: ui.N,
FillX: true, FillX: true,
PadY: 2, PadY: 2,
}) })
wpFrame := ui.NewFrame("Wallpaper Frame") label2 := ui.NewLabel(ui.Label{
frame.Pack(wpFrame, ui.Pack{ Text: "Wallpaper:",
Side: ui.N, Font: balance.LabelFont,
FillX: true, })
wpFrame.Pack(label2, ui.Pack{
Side: ui.W,
PadY: 2, PadY: 2,
}) })
@ -154,34 +160,54 @@ func NewAddEditLevel(config AddEditLevel) *ui.Window {
{"Pure White", "white.png"}, {"Pure White", "white.png"},
// {"Placemat", "placemat.png"}, // {"Placemat", "placemat.png"},
} }
for _, t := range wallpapers {
func(t wallpaperObj) { wallBtn := ui.NewSelectBox("Wallpaper Select", ui.Label{
radio := ui.NewRadioButton(t.Name, &newWallpaper, t.Value, ui.NewLabel(ui.Label{
Text: t.Name,
Font: balance.MenuFont, 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 { if pageType, ok := level.PageTypeFromString(newPageType); ok {
config.OnChangePageTypeAndWallpaper(pageType, t.Value) config.OnChangePageTypeAndWallpaper(pageType, filename)
newWallpaper = filename
}
}
} }
return nil 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 wallBtn.Supervise(config.Supervisor)
// hinting to pick the Blueprint palette to match. config.Supervisor.Add(wallBtn)
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)
}
/****************** /******************
* Frame for picking a default color palette. * Frame for picking a default color palette.
@ -204,32 +230,34 @@ func NewAddEditLevel(config AddEditLevel) *ui.Window {
Side: ui.W, Side: ui.W,
}) })
palBtn := ui.NewMenuButton("Palette Button", ui.NewLabel(ui.Label{ palBtn := ui.NewSelectBox("Palette Select", ui.Label{
TextVariable: &paletteName,
Font: balance.MenuFont, Font: balance.MenuFont,
})) })
palBtn.AlwaysChange = true
palFrame.Pack(palBtn, ui.Pack{ palFrame.Pack(palBtn, ui.Pack{
Side: ui.W, Side: ui.W,
// FillX: true,
Expand: true, Expand: true,
}) })
if config.EditLevel != nil { if config.EditLevel != nil {
palBtn.AddItem(paletteName, func() { palBtn.AddItem(paletteName, paletteName, func() {})
paletteName = textCurrentPalette
})
palBtn.AddSeparator(); palBtn.AddSeparator();
} }
for _, palName := range level.DefaultPaletteNames { for _, palName := range level.DefaultPaletteNames {
palName := palName palName := palName
// palette := level.DefaultPalettes[palName] palBtn.AddItem(palName, palName, func() {})
palBtn.AddItem(palName, func() {
paletteName = palName
})
} }
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) config.Supervisor.Add(palBtn)
palBtn.Supervise(config.Supervisor) palBtn.Supervise(config.Supervisor)
} }