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.
|
// 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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
|
||||||
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)
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
config.Supervisor.Add(radio)
|
|
||||||
typeFrame.Pack(radio, ui.Pack{
|
|
||||||
Side: ui.W,
|
|
||||||
PadX: 4,
|
|
||||||
})
|
|
||||||
}(t)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
})
|
||||||
|
|
||||||
|
typeBtn.Supervise(config.Supervisor)
|
||||||
|
config.Supervisor.Add(typeBtn)
|
||||||
|
|
||||||
/******************
|
/******************
|
||||||
* 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,35 +160,55 @@ 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) {
|
|
||||||
radio := ui.NewRadioButton(t.Name, &newWallpaper, t.Value, ui.NewLabel(ui.Label{
|
|
||||||
Text: t.Name,
|
|
||||||
Font: balance.MenuFont,
|
|
||||||
}))
|
|
||||||
radio.Handle(ui.Click, func(ed ui.EventData) error {
|
|
||||||
if pageType, ok := level.PageTypeFromString(newPageType); ok {
|
|
||||||
config.OnChangePageTypeAndWallpaper(pageType, t.Value)
|
|
||||||
}
|
|
||||||
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 := ui.NewSelectBox("Wallpaper Select", ui.Label{
|
||||||
// hinting to pick the Blueprint palette to match.
|
Font: balance.MenuFont,
|
||||||
if config.EditLevel == nil && t.Name == "Blueprint" {
|
})
|
||||||
ui.NewTooltip(radio, ui.Tooltip{
|
wallBtn.AlwaysChange = true
|
||||||
Text: "Dark theme! Make sure to also\npick a Blueprint color palette!",
|
wpFrame.Pack(wallBtn, ui.Pack{
|
||||||
Edge: ui.Top,
|
Side: ui.W,
|
||||||
})
|
Expand: true,
|
||||||
}
|
})
|
||||||
}(t)
|
|
||||||
|
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, filename)
|
||||||
|
newWallpaper = filename
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
wallBtn.Supervise(config.Supervisor)
|
||||||
|
config.Supervisor.Add(wallBtn)
|
||||||
|
|
||||||
/******************
|
/******************
|
||||||
* 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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user