Noah Petherbridge
6d3ffcd98c
* The "Story Mode" button on the MainScene opens the levelpacks window. * Levelpacks from all places are shown (built-in and user files), basic level picker works. * When playing a level out of a levelpack: the PlayScene gets the file data from the zipfile and plays it OK. * When a levelpack level is solved, the "Next Level" button appears on the success modal and hitting Return will advance to the next level in the pack. The final level doesn't show this button. * The user can edit levelpack levels! Clicking the "Edit" button on the Play Mode moves the loaded level over to the EditScene and the user could save it to disk or edit/playtest it perfectly OK! The link to the levelpack is lost upon opening in the editor, so the "Next Level" victory button doesn't appear.
145 lines
3.2 KiB
Go
145 lines
3.2 KiB
Go
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
|
|
}
|