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:
parent
ba4fbf55ef
commit
661c5f4365
|
@ -139,6 +139,11 @@ func (d *Doodle) Run() error {
|
|||
}
|
||||
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
|
||||
// it will fake the mouse cursor.
|
||||
gamepad.Loop(ev)
|
||||
|
|
|
@ -286,14 +286,8 @@ func (s *EditorScene) Loop(d *Doodle, ev *event.State) error {
|
|||
|
||||
// Has the window been resized?
|
||||
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)
|
||||
return nil
|
||||
}
|
||||
s.UI.Resized(d)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run all of the keybinds.
|
||||
|
|
|
@ -284,10 +284,11 @@ func (u *EditorUI) SetupToolbar(d *Doodle) *ui.Frame {
|
|||
Side: ui.N,
|
||||
})
|
||||
|
||||
ui.NewTooltip(bsLabel, ui.Tooltip{
|
||||
tt := ui.NewTooltip(bsLabel, ui.Tooltip{
|
||||
Text: "Set the line thickness for drawing",
|
||||
Edge: tooltipEdge,
|
||||
})
|
||||
tt.Supervise(u.Supervisor)
|
||||
u.Supervisor.Add(bsLabel)
|
||||
|
||||
sizeLabel := ui.NewLabel(ui.Label{
|
||||
|
|
|
@ -393,10 +393,7 @@ func (s *MainScene) Loop(d *Doodle, ev *event.State) error {
|
|||
s.canvas.Loop(ev)
|
||||
|
||||
if ev.WindowResized {
|
||||
w, h := d.Engine.WindowSize()
|
||||
d.width = w
|
||||
d.height = h
|
||||
s.Resized(w, h)
|
||||
s.Resized(d.width, d.height)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -211,9 +211,6 @@ func (s *MenuScene) Loop(d *Doodle, ev *event.State) error {
|
|||
s.Supervisor.Loop(ev)
|
||||
|
||||
if ev.WindowResized {
|
||||
w, h := d.Engine.WindowSize()
|
||||
d.width = w
|
||||
d.height = h
|
||||
log.Info("Resized to %dx%d", d.width, d.height)
|
||||
s.canvas.Resize(render.Rect{
|
||||
W: d.width,
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
// Configuration values.
|
||||
const (
|
||||
ProgressWidth = 300
|
||||
ProgressHeight = 34
|
||||
ProgressHeight = 16
|
||||
)
|
||||
|
||||
// State variables for the loading screen.
|
||||
|
@ -78,6 +78,14 @@ func IsActive() bool {
|
|||
return visible
|
||||
}
|
||||
|
||||
// Resized the window.
|
||||
func Resized() {
|
||||
if visible {
|
||||
size := render.NewRect(shmem.CurrentRenderEngine.WindowSize())
|
||||
window.Resize(size)
|
||||
}
|
||||
}
|
||||
|
||||
// Hide the loading screen.
|
||||
func Hide() {
|
||||
visible = false
|
||||
|
@ -141,8 +149,9 @@ func setup() {
|
|||
Background: render.DarkGrey,
|
||||
})
|
||||
window.Place(progressTrough, ui.Place{
|
||||
// Nestle it between the Title and Subtitle.
|
||||
Center: true,
|
||||
Middle: true,
|
||||
Top: 128 + label.Size().H + 16,
|
||||
})
|
||||
|
||||
progressBar = ui.NewFrame("Progress Bar")
|
||||
|
|
|
@ -52,6 +52,10 @@ func Reset() {
|
|||
func Handled(ev *event.State) bool {
|
||||
// The loadscreen counts as a modal for this purpose.
|
||||
if loadscreen.IsActive() {
|
||||
// Pass in window resize events in case the user maximizes the window during loading.
|
||||
if ev.WindowResized {
|
||||
loadscreen.Resized()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -640,14 +640,9 @@ func (s *PlayScene) Loop(d *Doodle, ev *event.State) error {
|
|||
|
||||
// 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.drawing.Resize(render.NewRect(d.width, d.height))
|
||||
s.screen.Resize(render.NewRect(d.width, d.height))
|
||||
return nil
|
||||
}
|
||||
s.drawing.Resize(render.NewRect(d.width, d.height))
|
||||
s.screen.Resize(render.NewRect(d.width, d.height))
|
||||
return nil
|
||||
}
|
||||
|
||||
// Switching to Edit Mode?
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user