doodle/pkg/windows/text_tool.go
Noah Petherbridge 647124495b Level Difficulty + UI Polish
Added a new level property: Difficulty

* An enum ranging from -1, 0, 1 (Peaceful, Normal, Hard)
* Default difficulty is Normal; pre-existing levels are Normal by
  default per the zero value.

Doodad scripts can read the difficulty via the new global variable
`Level.Difficulty` and some doodads have been updated:

* Azulians: on Peaceful they ignore all player characters, and on Hard
  they are in "hunt mode": infinite aggro radius and they're aggressive
  to all characters.
* Bird: on Peaceful they will not dive and attack any player character.

Other spit and polish:

* New Level/Level Properties UI reworked into a magicform.
* New "PromptPre(question, answer, func)" function for prompting the
  user with the developer shell, but pre-filling in an answer for them
  to either post or edit.
* magicform has a PromptUser field option for simple Text/Int fields
  which present as buttons, so magicform can prompt and update the
  variable itself.
* Don't show the _autosave.doodad in the Doodad Dropper window.
2022-03-06 22:20:53 -08:00

125 lines
2.9 KiB
Go

package windows
import (
"strconv"
"git.kirsle.net/apps/doodle/assets"
"git.kirsle.net/apps/doodle/pkg/balance"
"git.kirsle.net/apps/doodle/pkg/branding"
"git.kirsle.net/apps/doodle/pkg/shmem"
magicform "git.kirsle.net/apps/doodle/pkg/uix/magic-form"
"git.kirsle.net/go/render"
"git.kirsle.net/go/ui"
)
// TextTool window.
type TextTool struct {
// Settings passed in by doodle
Supervisor *ui.Supervisor
Engine render.Engine
// Callback when font settings are changed.
OnChangeSettings func(font string, size int, message string)
}
// NewTextToolWindow initializes the window.
func NewTextToolWindow(cfg TextTool) *ui.Window {
window := ui.NewWindow("Text Tool")
window.SetButtons(ui.CloseButton)
window.Configure(ui.Config{
Width: 330,
Height: 170,
Background: render.Grey,
})
// Text variables
var (
currentText = branding.AppName
fontName = balance.TextToolDefaultFont
fontSize = 16
)
// Get a listing of the available fonts.
fonts, _ := assets.AssetDir("assets/fonts")
var fontOption = []magicform.Option{}
for _, font := range fonts {
// Select the first font by default.
if fontName == "" {
fontName = font
}
fontOption = append(fontOption, magicform.Option{
Label: font,
Value: font,
})
}
// Send the default config out.
if cfg.OnChangeSettings != nil {
cfg.OnChangeSettings(fontName, fontSize, currentText)
}
form := magicform.Form{
Supervisor: cfg.Supervisor,
Engine: cfg.Engine,
Vertical: true,
LabelWidth: 100,
PadY: 2,
}
form.Create(window.ContentFrame(), []magicform.Field{
{
Label: "Font Face:",
Font: balance.LabelFont,
Options: fontOption,
SelectValue: fontName,
OnSelect: func(v interface{}) {
fontName = v.(string)
if cfg.OnChangeSettings != nil {
cfg.OnChangeSettings(fontName, fontSize, currentText)
}
},
},
{
Label: "Font Size:",
Font: balance.LabelFont,
IntVariable: &fontSize,
OnClick: func() {
shmem.Prompt("Enter new font size: ", func(answer string) {
if answer != "" {
if i, err := strconv.Atoi(answer); err == nil {
fontSize = i
if cfg.OnChangeSettings != nil {
cfg.OnChangeSettings(fontName, fontSize, currentText)
}
} else {
shmem.FlashError("Not a valid font size: %s", answer)
}
}
})
},
},
{
Label: "Message:",
Font: balance.LabelFont,
TextVariable: &currentText,
OnClick: func() {
shmem.PromptPre("Enter new message: ", currentText, func(answer string) {
if answer != "" {
currentText = answer
if cfg.OnChangeSettings != nil {
cfg.OnChangeSettings(fontName, fontSize, currentText)
}
}
})
},
},
{
Label: "Be sure the Text Tool is selected, and click onto your\n" +
"drawing to place this text onto it.",
Font: balance.UIFont,
},
})
return window
}