Loadscreen Update & Window Resize Fixes

* Loadscreen: put the progress bar between the Title and Subtitle so it
  looks good even on mobile landscape orientation (narrow height)
* Bugfixes around window OnResize events: the loadscreen handles
  resizing correctly now and the Level Editor (or w/e) will also be the
  right size if you resized the window during loading.
This commit is contained in:
Noah 2022-03-06 12:07:59 -08:00
parent ba4fbf55ef
commit 661c5f4365
9 changed files with 28 additions and 170 deletions

View File

@ -139,6 +139,11 @@ func (d *Doodle) Run() error {
} }
d.event = ev d.event = ev
// Always have an accurate idea of the window size.
if ev.WindowResized {
d.width, d.height = d.Engine.WindowSize()
}
// Let the gamepad controller check for events, if it's in MouseMode // Let the gamepad controller check for events, if it's in MouseMode
// it will fake the mouse cursor. // it will fake the mouse cursor.
gamepad.Loop(ev) gamepad.Loop(ev)

View File

@ -286,15 +286,9 @@ func (s *EditorScene) Loop(d *Doodle, ev *event.State) error {
// Has the window been resized? // Has the window been resized?
if ev.WindowResized { if ev.WindowResized {
w, h := d.Engine.WindowSize()
if w != d.width || h != d.height {
// Not a false alarm.
d.width = w
d.height = h
s.UI.Resized(d) s.UI.Resized(d)
return nil return nil
} }
}
// Run all of the keybinds. // Run all of the keybinds.
binders := []struct { binders := []struct {

View File

@ -284,10 +284,11 @@ func (u *EditorUI) SetupToolbar(d *Doodle) *ui.Frame {
Side: ui.N, Side: ui.N,
}) })
ui.NewTooltip(bsLabel, ui.Tooltip{ tt := ui.NewTooltip(bsLabel, ui.Tooltip{
Text: "Set the line thickness for drawing", Text: "Set the line thickness for drawing",
Edge: tooltipEdge, Edge: tooltipEdge,
}) })
tt.Supervise(u.Supervisor)
u.Supervisor.Add(bsLabel) u.Supervisor.Add(bsLabel)
sizeLabel := ui.NewLabel(ui.Label{ sizeLabel := ui.NewLabel(ui.Label{

View File

@ -393,10 +393,7 @@ func (s *MainScene) Loop(d *Doodle, ev *event.State) error {
s.canvas.Loop(ev) s.canvas.Loop(ev)
if ev.WindowResized { if ev.WindowResized {
w, h := d.Engine.WindowSize() s.Resized(d.width, d.height)
d.width = w
d.height = h
s.Resized(w, h)
} }
return nil return nil

View File

@ -211,9 +211,6 @@ func (s *MenuScene) Loop(d *Doodle, ev *event.State) error {
s.Supervisor.Loop(ev) s.Supervisor.Loop(ev)
if ev.WindowResized { if ev.WindowResized {
w, h := d.Engine.WindowSize()
d.width = w
d.height = h
log.Info("Resized to %dx%d", d.width, d.height) log.Info("Resized to %dx%d", d.width, d.height)
s.canvas.Resize(render.Rect{ s.canvas.Resize(render.Rect{
W: d.width, W: d.width,

View File

@ -16,7 +16,7 @@ import (
// Configuration values. // Configuration values.
const ( const (
ProgressWidth = 300 ProgressWidth = 300
ProgressHeight = 34 ProgressHeight = 16
) )
// State variables for the loading screen. // State variables for the loading screen.
@ -78,6 +78,14 @@ func IsActive() bool {
return visible return visible
} }
// Resized the window.
func Resized() {
if visible {
size := render.NewRect(shmem.CurrentRenderEngine.WindowSize())
window.Resize(size)
}
}
// Hide the loading screen. // Hide the loading screen.
func Hide() { func Hide() {
visible = false visible = false
@ -141,8 +149,9 @@ func setup() {
Background: render.DarkGrey, Background: render.DarkGrey,
}) })
window.Place(progressTrough, ui.Place{ window.Place(progressTrough, ui.Place{
// Nestle it between the Title and Subtitle.
Center: true, Center: true,
Middle: true, Top: 128 + label.Size().H + 16,
}) })
progressBar = ui.NewFrame("Progress Bar") progressBar = ui.NewFrame("Progress Bar")

View File

@ -52,6 +52,10 @@ func Reset() {
func Handled(ev *event.State) bool { func Handled(ev *event.State) bool {
// The loadscreen counts as a modal for this purpose. // The loadscreen counts as a modal for this purpose.
if loadscreen.IsActive() { if loadscreen.IsActive() {
// Pass in window resize events in case the user maximizes the window during loading.
if ev.WindowResized {
loadscreen.Resized()
}
return true return true
} }

View File

@ -640,15 +640,10 @@ func (s *PlayScene) Loop(d *Doodle, ev *event.State) error {
// Has the window been resized? // Has the window been resized?
if ev.WindowResized { if ev.WindowResized {
w, h := d.Engine.WindowSize()
if w != d.width || h != d.height {
d.width = w
d.height = h
s.drawing.Resize(render.NewRect(d.width, d.height)) s.drawing.Resize(render.NewRect(d.width, d.height))
s.screen.Resize(render.NewRect(d.width, d.height)) s.screen.Resize(render.NewRect(d.width, d.height))
return nil return nil
} }
}
// Switching to Edit Mode? // Switching to Edit Mode?
if keybind.GotoEdit(ev) { if keybind.GotoEdit(ev) {

View File

@ -1,144 +0,0 @@
package doodle
import (
"git.kirsle.net/apps/doodle/pkg/balance"
"git.kirsle.net/apps/doodle/pkg/campaign"
"git.kirsle.net/apps/doodle/pkg/level"
"git.kirsle.net/apps/doodle/pkg/log"
"git.kirsle.net/apps/doodle/pkg/uix"
"git.kirsle.net/apps/doodle/pkg/windows"
"git.kirsle.net/go/render"
"git.kirsle.net/go/render/event"
"git.kirsle.net/go/ui"
)
// StoryScene manages the "Story Mode" menu selection screen.
type StoryScene struct {
// Private variables.
d *Doodle
running bool
// Background wallpaper canvas.
canvas *uix.Canvas
// UI widgets.
supervisor *ui.Supervisor
campaignFrame *ui.Frame // Select a Campaign screen
levelSelectFrame *ui.Window // Select a level in the campaign screen
// Pointer to the currently active frame.
activeFrame *ui.Frame
}
// Name of the scene.
func (s *StoryScene) Name() string {
return "Story"
}
// GotoStoryMenu initializes the story menu scene.
func (d *Doodle) GotoStoryMenu() {
log.Info("Loading Story Scene")
scene := &StoryScene{}
d.Goto(scene)
}
// Setup the play scene.
func (s *StoryScene) Setup(d *Doodle) error {
s.d = d
// Set up the background wallpaper canvas.
s.canvas = uix.NewCanvas(100, false)
s.canvas.Resize(render.NewRect(d.width, d.height))
s.canvas.LoadLevel(&level.Level{
Chunker: level.NewChunker(100),
Palette: level.NewPalette(),
PageType: level.Bounded,
Wallpaper: "notebook.png",
})
s.supervisor = ui.NewSupervisor()
// Set up the sub-screens of this scene.
s.campaignFrame = s.setupCampaignFrame()
s.levelSelectFrame = windows.NewLevelPackWindow(windows.LevelPack{
Supervisor: s.supervisor,
Engine: d.Engine,
})
s.levelSelectFrame.Show()
s.activeFrame = s.campaignFrame
return nil
}
// setupCampaignFrame sets up the Campaign List screen.
func (s *StoryScene) setupCampaignFrame() *ui.Frame {
var frame = ui.NewFrame("List Frame")
frame.SetBackground(render.RGBA(0, 0, 255, 20))
// Title label
labelTitle := ui.NewLabel(ui.Label{
Text: "Select a Story",
Font: balance.TitleScreenFont,
})
labelTitle.Compute(s.d.Engine)
frame.Place(labelTitle, ui.Place{
Top: 120,
Center: true,
})
// Buttons for campaign selection.
{
campaignFiles, err := campaign.List()
if err != nil {
log.Error("campaign.List: %s", err)
}
_ = campaignFiles
// for _, file := range campaignFiles {
//
// }
}
frame.Resize(render.NewRect(s.d.width, s.d.height))
frame.Compute(s.d.Engine)
return frame
}
// Loop the story scene.
func (s *StoryScene) Loop(d *Doodle, ev *event.State) error {
s.supervisor.Loop(ev)
// Has the window been resized?
if ev.WindowResized {
w, h := d.Engine.WindowSize()
if w != d.width || h != d.height {
d.width = w
d.height = h
s.canvas.Resize(render.NewRect(d.width, d.height))
s.activeFrame.Resize(render.NewRect(d.width, d.height))
s.activeFrame.Compute(d.Engine)
return nil
}
}
return nil
}
// Draw the pixels on this frame.
func (s *StoryScene) Draw(d *Doodle) error {
// Draw the background canvas.
s.canvas.Present(d.Engine, render.Origin)
// Draw the active screen.
s.activeFrame.Present(d.Engine, render.Origin)
s.supervisor.Present(d.Engine)
return nil
}
// Destroy the scene.
func (s *StoryScene) Destroy() error {
return nil
}