Noah Petherbridge
190d4be1b6
* When editing a doodad in the Editor Mode, the toolbar has a "Lyr." button that opens the Layers window. * The Layers window allows switching the active doodad layer that you are drawing on, as well as create and rename layers. * With this feature, Doodads may be fully drawn in-game, including adding alternate named layers for animations and multiple-state doodads. * Update the Pager component to have a configurable MaxPageButtons. Controls that have more pages than this limit will stop having buttons drawn after the limit. The "Forward" and "Next" buttons can still navigate into the extra pages. * Refactored and centralized the various popup windows in Editor Mode into editor_ui_popups.go; the SetupPopups() and various methods such as ShowPaletteWindow() and ShowDoodadDropper() make management of popups simple for the editor_ui! * The Menu Bar in Editor Mode now has context-specific tools in the Tools menu: the Doodad Dropper for levels and Layers for doodads. * Bugfix the Palette Editor window to work equally between Levels and Doodads, by only having it care about the Palette and not the Level that owns it.
106 lines
2.5 KiB
Go
106 lines
2.5 KiB
Go
package doodle
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
|
"git.kirsle.net/apps/doodle/pkg/log"
|
|
"git.kirsle.net/go/ui"
|
|
)
|
|
|
|
// Width of the panel frame.
|
|
var paletteWidth = 50
|
|
|
|
// SetupPalette sets up the palette panel.
|
|
func (u *EditorUI) SetupPalette(d *Doodle) *ui.Window {
|
|
window := ui.NewWindow("Palette")
|
|
window.ConfigureTitle(balance.TitleConfig)
|
|
_, label := window.TitleBar()
|
|
label.Font = balance.TitleFont
|
|
window.Configure(ui.Config{
|
|
Background: balance.WindowBackground,
|
|
BorderColor: balance.WindowBorder,
|
|
})
|
|
|
|
// Color Palette Frame.
|
|
u.PaletteTab = u.setupPaletteFrame(window)
|
|
window.Pack(u.PaletteTab, ui.Pack{
|
|
Side: ui.N,
|
|
Fill: true,
|
|
})
|
|
|
|
return window
|
|
}
|
|
|
|
// setupPaletteFrame configures the Color Palette tab for Edit Mode.
|
|
// This is a subroutine of editor_ui.go#SetupPalette()
|
|
func (u *EditorUI) setupPaletteFrame(window *ui.Window) *ui.Frame {
|
|
frame := ui.NewFrame("Palette Tab")
|
|
frame.SetBackground(balance.WindowBackground)
|
|
|
|
// Handler function for the radio buttons being clicked.
|
|
onClick := func(ed ui.EventData) error {
|
|
name := u.selectedSwatch
|
|
swatch, ok := u.Canvas.Palette.Get(name)
|
|
if !ok {
|
|
log.Error("Palette onClick: couldn't get swatch named '%s' from palette", name)
|
|
return nil
|
|
}
|
|
log.Info("Set swatch: %s", swatch)
|
|
u.Canvas.SetSwatch(swatch)
|
|
return nil
|
|
}
|
|
|
|
var buttonSize = 32
|
|
|
|
// Draw the radio buttons for the palette.
|
|
if u.Canvas != nil && u.Canvas.Palette != nil {
|
|
for _, swatch := range u.Canvas.Palette.Swatches {
|
|
swFrame := ui.NewFrame(fmt.Sprintf("Swatch(%s) Button Frame", swatch.Name))
|
|
swFrame.Configure(ui.Config{
|
|
Width: buttonSize,
|
|
Height: buttonSize,
|
|
Background: swatch.Color,
|
|
})
|
|
|
|
btn := ui.NewRadioButton("palette", &u.selectedSwatch, swatch.Name, swFrame)
|
|
btn.Handle(ui.Click, onClick)
|
|
u.Supervisor.Add(btn)
|
|
|
|
// Add a tooltip showing the swatch attributes.
|
|
ui.NewTooltip(btn, ui.Tooltip{
|
|
Text: fmt.Sprintf("Name: %s\nAttributes: %s", swatch.Name, swatch.Attributes()),
|
|
Edge: ui.Left,
|
|
})
|
|
|
|
btn.Compute(u.d.Engine)
|
|
|
|
frame.Pack(btn, ui.Pack{
|
|
Side: ui.N,
|
|
Fill: true,
|
|
PadY: 4,
|
|
})
|
|
}
|
|
}
|
|
|
|
// Draw the Edit Palette button.
|
|
btn := ui.NewButton("Edit Palette", ui.NewLabel(ui.Label{
|
|
Text: "Edit",
|
|
Font: balance.MenuFont,
|
|
}))
|
|
btn.Handle(ui.Click, func(ed ui.EventData) error {
|
|
u.OpenPaletteWindow()
|
|
return nil
|
|
})
|
|
u.Supervisor.Add(btn)
|
|
|
|
btn.Compute(u.d.Engine)
|
|
frame.Pack(btn, ui.Pack{
|
|
Side: ui.N,
|
|
Fill: true,
|
|
PadY: 4,
|
|
})
|
|
|
|
return frame
|
|
}
|