2020-04-07 06:21:17 +00:00
|
|
|
package windows
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-08-16 03:26:47 +00:00
|
|
|
"sort"
|
|
|
|
"strings"
|
2020-04-07 06:21:17 +00:00
|
|
|
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/level"
|
WIP Publish Dialog + UI Improvements
* File->Publish Level in the Level Editor opens the Publish window,
where you can embed custom doodads into your level and export a
portable .level file you can share with others.
* Currently does not actually export a level file yet.
* The dialog lists all unique doodad names in use in your level, and
designates which are built-ins and which are custom (paginated).
* A checkbox would let the user embed built-in doodads into their level,
as well, locking it in to those versions and not using updated
versions from future game releases.
UI Improvements:
* Added styling for a "Primary" UI button, rendered in deep blue.
* Pop-up modals (Alert, Confirm) color their Ok button as Primary.
* The Enter key pressed during an Alert or Confirm modal will invoke its
default button and close the modal, corresponding to its Primary
button.
* The developer console is now opened with the tilde/grave key ` instead
of the Enter key, so that the Enter key is free to click through
modals.
* In the "Open/Edit Drawing" window, a "Browse..." button is added to
the level and doodad sections, spawning a native File Open dialog to
pick a .level or .doodad outside the config root.
2021-06-11 05:31:30 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/log"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/native"
|
2020-04-07 06:21:17 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/userdir"
|
|
|
|
"git.kirsle.net/go/render"
|
|
|
|
"git.kirsle.net/go/ui"
|
|
|
|
)
|
|
|
|
|
|
|
|
// OpenLevelEditor is the "Open a Level to Edit It" window
|
|
|
|
type OpenLevelEditor struct {
|
|
|
|
Supervisor *ui.Supervisor
|
|
|
|
Engine render.Engine
|
|
|
|
|
|
|
|
// Load it for playing instead of editing?
|
|
|
|
LoadForPlay bool
|
|
|
|
|
|
|
|
// Callback functions.
|
|
|
|
OnPlayLevel func(filename string)
|
|
|
|
OnEditLevel func(filename string)
|
|
|
|
OnCancel func()
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewOpenLevelEditor initializes the window.
|
|
|
|
func NewOpenLevelEditor(config OpenLevelEditor) *ui.Window {
|
|
|
|
var (
|
|
|
|
width, height = config.Engine.WindowSize()
|
|
|
|
)
|
|
|
|
|
|
|
|
window := ui.NewWindow("Open Drawing")
|
|
|
|
window.Configure(ui.Config{
|
|
|
|
Width: int(float64(width) * 0.75),
|
|
|
|
Height: int(float64(height) * 0.75),
|
|
|
|
Background: render.Grey,
|
|
|
|
})
|
|
|
|
|
|
|
|
{
|
|
|
|
frame := ui.NewFrame("Open Drawing Frame")
|
|
|
|
window.Pack(frame, ui.Pack{
|
|
|
|
Side: ui.N,
|
|
|
|
Fill: true,
|
|
|
|
Expand: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
/******************
|
|
|
|
* Frame for selecting User Levels
|
|
|
|
******************/
|
|
|
|
|
|
|
|
label1 := ui.NewLabel(ui.Label{
|
|
|
|
Text: "Levels",
|
|
|
|
Font: balance.LabelFont,
|
|
|
|
})
|
|
|
|
frame.Pack(label1, ui.Pack{
|
|
|
|
Side: ui.N,
|
|
|
|
FillX: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Get the user's levels.
|
|
|
|
levels, _ := userdir.ListLevels()
|
|
|
|
|
|
|
|
// Embedded levels, TODO
|
|
|
|
sysLevels, _ := level.ListSystemLevels()
|
|
|
|
levels = append(levels, sysLevels...)
|
|
|
|
|
2021-08-16 03:26:47 +00:00
|
|
|
// Sort them!
|
|
|
|
sort.Slice(
|
|
|
|
levels, func(i, j int) bool {
|
|
|
|
return strings.ToLower(levels[i]) < strings.ToLower(levels[j])
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2020-04-07 06:21:17 +00:00
|
|
|
lvlRow := ui.NewFrame("Level Row 0")
|
|
|
|
frame.Pack(lvlRow, ui.Pack{
|
|
|
|
Side: ui.N,
|
|
|
|
FillX: true,
|
|
|
|
PadY: 1,
|
|
|
|
})
|
|
|
|
for i, lvl := range levels {
|
|
|
|
func(i int, lvl string) {
|
|
|
|
btn := ui.NewButton("Level Btn", ui.NewLabel(ui.Label{
|
|
|
|
Text: lvl,
|
|
|
|
Font: balance.MenuFont,
|
|
|
|
}))
|
|
|
|
btn.Handle(ui.Click, func(ed ui.EventData) error {
|
|
|
|
if config.LoadForPlay {
|
|
|
|
config.OnPlayLevel(lvl)
|
|
|
|
} else {
|
|
|
|
config.OnEditLevel(lvl)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
config.Supervisor.Add(btn)
|
|
|
|
lvlRow.Pack(btn, ui.Pack{
|
|
|
|
Side: ui.W,
|
|
|
|
Expand: true,
|
|
|
|
Fill: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
if i > 0 && (i+1)%4 == 0 {
|
|
|
|
lvlRow = ui.NewFrame(fmt.Sprintf("Level Row %d", i))
|
|
|
|
frame.Pack(lvlRow, ui.Pack{
|
|
|
|
Side: ui.N,
|
|
|
|
FillX: true,
|
|
|
|
PadY: 1,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}(i, lvl)
|
|
|
|
}
|
|
|
|
|
WIP Publish Dialog + UI Improvements
* File->Publish Level in the Level Editor opens the Publish window,
where you can embed custom doodads into your level and export a
portable .level file you can share with others.
* Currently does not actually export a level file yet.
* The dialog lists all unique doodad names in use in your level, and
designates which are built-ins and which are custom (paginated).
* A checkbox would let the user embed built-in doodads into their level,
as well, locking it in to those versions and not using updated
versions from future game releases.
UI Improvements:
* Added styling for a "Primary" UI button, rendered in deep blue.
* Pop-up modals (Alert, Confirm) color their Ok button as Primary.
* The Enter key pressed during an Alert or Confirm modal will invoke its
default button and close the modal, corresponding to its Primary
button.
* The developer console is now opened with the tilde/grave key ` instead
of the Enter key, so that the Enter key is free to click through
modals.
* In the "Open/Edit Drawing" window, a "Browse..." button is added to
the level and doodad sections, spawning a native File Open dialog to
pick a .level or .doodad outside the config root.
2021-06-11 05:31:30 +00:00
|
|
|
// Browse button for local filesystem.
|
|
|
|
browseLevelFrame := ui.NewFrame("Browse Level Frame")
|
|
|
|
frame.Pack(browseLevelFrame, ui.Pack{
|
|
|
|
Side: ui.N,
|
|
|
|
Expand: true,
|
|
|
|
FillX: true,
|
|
|
|
PadY: 1,
|
|
|
|
})
|
|
|
|
|
|
|
|
browseLevelButton := ui.NewButton("Browse Level", ui.NewLabel(ui.Label{
|
|
|
|
Text: "Browse...",
|
|
|
|
Font: balance.MenuFont,
|
|
|
|
}))
|
|
|
|
browseLevelButton.SetStyle(&balance.ButtonPrimary)
|
|
|
|
browseLevelFrame.Pack(browseLevelButton, ui.Pack{
|
|
|
|
Side: ui.W,
|
|
|
|
})
|
|
|
|
|
|
|
|
browseLevelButton.Handle(ui.Click, func(ed ui.EventData) error {
|
|
|
|
filename, err := native.OpenFile("Choose a .level file", "*.level")
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Couldn't show file dialog: %s", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.LoadForPlay {
|
|
|
|
config.OnPlayLevel(filename)
|
|
|
|
} else {
|
|
|
|
config.OnEditLevel(filename)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
config.Supervisor.Add(browseLevelButton)
|
|
|
|
|
2020-04-07 06:21:17 +00:00
|
|
|
/******************
|
|
|
|
* Frame for selecting User Doodads
|
|
|
|
******************/
|
|
|
|
|
|
|
|
// Doodads not shown if we're loading a map to play, nor are they
|
|
|
|
// available to the free version.
|
|
|
|
if !config.LoadForPlay && !balance.FreeVersion {
|
|
|
|
label2 := ui.NewLabel(ui.Label{
|
|
|
|
Text: "Doodads",
|
|
|
|
Font: balance.LabelFont,
|
|
|
|
})
|
|
|
|
frame.Pack(label2, ui.Pack{
|
|
|
|
Side: ui.N,
|
|
|
|
FillX: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
files, _ := userdir.ListDoodads()
|
2021-08-16 03:26:47 +00:00
|
|
|
|
|
|
|
// Sort them!
|
|
|
|
sort.Slice(
|
|
|
|
files, func(i, j int) bool {
|
|
|
|
return strings.ToLower(files[i]) < strings.ToLower(files[j])
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2020-04-07 06:21:17 +00:00
|
|
|
ddRow := ui.NewFrame("Doodad Row 0")
|
|
|
|
frame.Pack(ddRow, ui.Pack{
|
|
|
|
Side: ui.N,
|
|
|
|
FillX: true,
|
|
|
|
PadY: 1,
|
|
|
|
})
|
|
|
|
for i, dd := range files {
|
|
|
|
func(i int, dd string) {
|
|
|
|
btn := ui.NewButton("Doodad Btn", ui.NewLabel(ui.Label{
|
|
|
|
Text: dd,
|
|
|
|
Font: balance.MenuFont,
|
|
|
|
}))
|
|
|
|
btn.Handle(ui.Click, func(ed ui.EventData) error {
|
|
|
|
config.OnEditLevel(dd)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
config.Supervisor.Add(btn)
|
|
|
|
ddRow.Pack(btn, ui.Pack{
|
|
|
|
Side: ui.W,
|
|
|
|
Expand: true,
|
|
|
|
Fill: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
if i > 0 && (i+1)%4 == 0 {
|
|
|
|
ddRow = ui.NewFrame(fmt.Sprintf("Doodad Row %d", i))
|
|
|
|
frame.Pack(ddRow, ui.Pack{
|
|
|
|
Side: ui.N,
|
|
|
|
FillX: true,
|
|
|
|
PadY: 1,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}(i, dd)
|
|
|
|
}
|
|
|
|
|
2021-06-13 21:53:21 +00:00
|
|
|
// Browse button for local filesystem.
|
|
|
|
browseDoodadFrame := ui.NewFrame("Browse Doodad Frame")
|
|
|
|
frame.Pack(browseDoodadFrame, ui.Pack{
|
|
|
|
Side: ui.N,
|
|
|
|
Expand: true,
|
|
|
|
FillX: true,
|
|
|
|
PadY: 1,
|
|
|
|
})
|
WIP Publish Dialog + UI Improvements
* File->Publish Level in the Level Editor opens the Publish window,
where you can embed custom doodads into your level and export a
portable .level file you can share with others.
* Currently does not actually export a level file yet.
* The dialog lists all unique doodad names in use in your level, and
designates which are built-ins and which are custom (paginated).
* A checkbox would let the user embed built-in doodads into their level,
as well, locking it in to those versions and not using updated
versions from future game releases.
UI Improvements:
* Added styling for a "Primary" UI button, rendered in deep blue.
* Pop-up modals (Alert, Confirm) color their Ok button as Primary.
* The Enter key pressed during an Alert or Confirm modal will invoke its
default button and close the modal, corresponding to its Primary
button.
* The developer console is now opened with the tilde/grave key ` instead
of the Enter key, so that the Enter key is free to click through
modals.
* In the "Open/Edit Drawing" window, a "Browse..." button is added to
the level and doodad sections, spawning a native File Open dialog to
pick a .level or .doodad outside the config root.
2021-06-11 05:31:30 +00:00
|
|
|
|
2021-06-13 21:53:21 +00:00
|
|
|
browseDoodadButton := ui.NewButton("Browse Doodad", ui.NewLabel(ui.Label{
|
|
|
|
Text: "Browse...",
|
|
|
|
Font: balance.MenuFont,
|
|
|
|
}))
|
|
|
|
browseDoodadButton.SetStyle(&balance.ButtonPrimary)
|
|
|
|
browseDoodadFrame.Pack(browseDoodadButton, ui.Pack{
|
|
|
|
Side: ui.W,
|
|
|
|
})
|
WIP Publish Dialog + UI Improvements
* File->Publish Level in the Level Editor opens the Publish window,
where you can embed custom doodads into your level and export a
portable .level file you can share with others.
* Currently does not actually export a level file yet.
* The dialog lists all unique doodad names in use in your level, and
designates which are built-ins and which are custom (paginated).
* A checkbox would let the user embed built-in doodads into their level,
as well, locking it in to those versions and not using updated
versions from future game releases.
UI Improvements:
* Added styling for a "Primary" UI button, rendered in deep blue.
* Pop-up modals (Alert, Confirm) color their Ok button as Primary.
* The Enter key pressed during an Alert or Confirm modal will invoke its
default button and close the modal, corresponding to its Primary
button.
* The developer console is now opened with the tilde/grave key ` instead
of the Enter key, so that the Enter key is free to click through
modals.
* In the "Open/Edit Drawing" window, a "Browse..." button is added to
the level and doodad sections, spawning a native File Open dialog to
pick a .level or .doodad outside the config root.
2021-06-11 05:31:30 +00:00
|
|
|
|
2021-06-13 21:53:21 +00:00
|
|
|
browseDoodadButton.Handle(ui.Click, func(ed ui.EventData) error {
|
|
|
|
filename, err := native.OpenFile("Choose a .doodad file", "*.doodad")
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Couldn't show file dialog: %s", err)
|
|
|
|
return nil
|
|
|
|
}
|
WIP Publish Dialog + UI Improvements
* File->Publish Level in the Level Editor opens the Publish window,
where you can embed custom doodads into your level and export a
portable .level file you can share with others.
* Currently does not actually export a level file yet.
* The dialog lists all unique doodad names in use in your level, and
designates which are built-ins and which are custom (paginated).
* A checkbox would let the user embed built-in doodads into their level,
as well, locking it in to those versions and not using updated
versions from future game releases.
UI Improvements:
* Added styling for a "Primary" UI button, rendered in deep blue.
* Pop-up modals (Alert, Confirm) color their Ok button as Primary.
* The Enter key pressed during an Alert or Confirm modal will invoke its
default button and close the modal, corresponding to its Primary
button.
* The developer console is now opened with the tilde/grave key ` instead
of the Enter key, so that the Enter key is free to click through
modals.
* In the "Open/Edit Drawing" window, a "Browse..." button is added to
the level and doodad sections, spawning a native File Open dialog to
pick a .level or .doodad outside the config root.
2021-06-11 05:31:30 +00:00
|
|
|
|
2021-06-13 21:53:21 +00:00
|
|
|
if config.LoadForPlay {
|
|
|
|
config.OnPlayLevel(filename)
|
|
|
|
} else {
|
|
|
|
config.OnEditLevel(filename)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
config.Supervisor.Add(browseDoodadButton)
|
|
|
|
}
|
WIP Publish Dialog + UI Improvements
* File->Publish Level in the Level Editor opens the Publish window,
where you can embed custom doodads into your level and export a
portable .level file you can share with others.
* Currently does not actually export a level file yet.
* The dialog lists all unique doodad names in use in your level, and
designates which are built-ins and which are custom (paginated).
* A checkbox would let the user embed built-in doodads into their level,
as well, locking it in to those versions and not using updated
versions from future game releases.
UI Improvements:
* Added styling for a "Primary" UI button, rendered in deep blue.
* Pop-up modals (Alert, Confirm) color their Ok button as Primary.
* The Enter key pressed during an Alert or Confirm modal will invoke its
default button and close the modal, corresponding to its Primary
button.
* The developer console is now opened with the tilde/grave key ` instead
of the Enter key, so that the Enter key is free to click through
modals.
* In the "Open/Edit Drawing" window, a "Browse..." button is added to
the level and doodad sections, spawning a native File Open dialog to
pick a .level or .doodad outside the config root.
2021-06-11 05:31:30 +00:00
|
|
|
|
2020-04-07 06:21:17 +00:00
|
|
|
/******************
|
|
|
|
* Confirm/cancel buttons.
|
|
|
|
******************/
|
|
|
|
|
|
|
|
bottomFrame := ui.NewFrame("Button Frame")
|
|
|
|
// bottomFrame.Configure(ui.Config{
|
|
|
|
// BorderSize: 1,
|
|
|
|
// BorderStyle: ui.BorderSunken,
|
|
|
|
// BorderColor: render.Black,
|
|
|
|
// })
|
|
|
|
// bottomFrame.SetBackground(render.Grey)
|
|
|
|
frame.Pack(bottomFrame, ui.Pack{
|
|
|
|
Side: ui.N,
|
|
|
|
FillX: true,
|
|
|
|
PadY: 8,
|
|
|
|
})
|
|
|
|
|
|
|
|
var buttons = []struct {
|
|
|
|
Label string
|
|
|
|
F func(ui.EventData) error
|
|
|
|
}{
|
|
|
|
{"Cancel", func(ed ui.EventData) error {
|
|
|
|
config.OnCancel()
|
|
|
|
return nil
|
|
|
|
}},
|
|
|
|
}
|
|
|
|
for _, t := range buttons {
|
|
|
|
btn := ui.NewButton(t.Label, ui.NewLabel(ui.Label{
|
|
|
|
Text: t.Label,
|
|
|
|
Font: balance.MenuFont,
|
|
|
|
}))
|
|
|
|
btn.Handle(ui.Click, t.F)
|
|
|
|
config.Supervisor.Add(btn)
|
|
|
|
bottomFrame.Pack(btn, ui.Pack{
|
|
|
|
Side: ui.W,
|
|
|
|
PadX: 4,
|
|
|
|
PadY: 8,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return window
|
|
|
|
}
|