From df5756ffcf0b5b17e7dcc5eb21cb565cc3a41bfb Mon Sep 17 00:00:00 2001 From: Hersi Date: Thu, 28 Apr 2022 00:21:10 +0200 Subject: [PATCH] started implementing ModeSelectPage added AudioSample class put mode select screen header into components fix typo in animation.lua --- scripts/api/animation.lua | 2 +- scripts/api/audiosample.lua | 49 +++++++++++++++ .../components/headers/modeSelectHeader.lua | 33 ++++++++++ .../pages/modeselect/modeselectpage.lua | 60 +++++++++++++++++++ 4 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 scripts/api/audiosample.lua create mode 100644 scripts/components/headers/modeSelectHeader.lua diff --git a/scripts/api/animation.lua b/scripts/api/animation.lua index af8641c..d11c440 100644 --- a/scripts/api/animation.lua +++ b/scripts/api/animation.lua @@ -151,7 +151,7 @@ function AnimationState:stop() self.running = false; end ----Updates this AnimationState and then rendersit, passing on the given ImageParams to each frame. +---Updates this AnimationState and then renders it, passing on the given ImageParams to each frame. ---@param deltaTime number ---@param params? ImageParams function AnimationState:render(deltaTime, params) diff --git a/scripts/api/audiosample.lua b/scripts/api/audiosample.lua new file mode 100644 index 0000000..d072f0e --- /dev/null +++ b/scripts/api/audiosample.lua @@ -0,0 +1,49 @@ +require "common.class" + +---@type AudioSample +local exclusiveAudioSample = nil + +---@class AudioSample +---@field path string +---@field exclusive boolean +---@field loop boolean +---@field playing boolean +local AudioSample = {} + +---Create new AudioSample instance +---@param o AudioSample +---@return AudioSample +function AudioSample.new(o) + assert(o.path, "AudioSample.new() did not receive path to audio sample") + o.exclusive = o.exclusive or false + o.loop = o.loop or false + + game.LoadSkinSample(o.path) + + return CreateInstance(AudioSample, o) +end + +function AudioSample:play() + if not self.playing then + if self.exclusive then + if exclusiveAudioSample and self ~= exclusiveAudioSample then + exclusiveAudioSample:stop() + end + exclusiveAudioSample = self + end + self.playing = true + game.PlaySample(self.path) + end +end + +function AudioSample:stop() + if self.playing then + if self.exclusive and self == exclusiveAudioSample then + exclusiveAudioSample = nil + end + self.playing = false + game.StopSample(self.path) + end +end + +return AudioSample diff --git a/scripts/components/headers/modeSelectHeader.lua b/scripts/components/headers/modeSelectHeader.lua new file mode 100644 index 0000000..3fa1d42 --- /dev/null +++ b/scripts/components/headers/modeSelectHeader.lua @@ -0,0 +1,33 @@ +require "common.globals" +local Dim = require "common.dimensions" +local Image = require "api.image" + +local BAR_ALPHA = 191 +local HEADER_HEIGHT = 100 + +local titleImage = Image.new("titlescreen/title.png") +titleImage.centered = true +titleImage:setPosition(Dim.design.width / 2, HEADER_HEIGHT / 2) + +local function drawHeader() + gfx.BeginPath() + gfx.FillColor(0, 0, 0, BAR_ALPHA) + gfx.Rect(0, 0, Dim.design.width, HEADER_HEIGHT) + gfx.Fill() + + titleImage:render() +end + +local function draw() + gfx.Save() + + gfx.ResetTransform() + + Dim.transformToScreenSpace() + + drawHeader() + + gfx.Restore() +end + +return {draw = draw} \ No newline at end of file diff --git a/scripts/titlescreen/pages/modeselect/modeselectpage.lua b/scripts/titlescreen/pages/modeselect/modeselectpage.lua index e69de29..26afb69 100644 --- a/scripts/titlescreen/pages/modeselect/modeselectpage.lua +++ b/scripts/titlescreen/pages/modeselect/modeselectpage.lua @@ -0,0 +1,60 @@ +require "common.class" +local Dim = require "common.dimensions" +local Lang = require "language.call" +local AudioSample = require "api.audiosample" +local Animation = require "api.animation" +local Page = require "api.page.page" + +local Footer = require "components.footer" +local Header = require "components.headers.modeSelectHeader" + +local crew = game.GetSkinSetting("single_idol") + +---@class ModeSelectPage: Page +---@field _idolAnimationState AnimationState +local ModeSelectPage = { + images = { + selectorBgImage = gfx.CreateSkinImage("titlescreen/selector_bg.png", 0), + selectorArrowsImage = gfx.CreateSkinImage("titlescreen/selector_arrows.png", 0), + unselectedButtonImage = gfx.CreateSkinImage("titlescreen/unselected_button.png", 0), + selectedButtonBgImage = gfx.CreateSkinImage("titlescreen/selected_button_bg.png", 0), + selectedButtonOverImage = gfx.CreateSkinImage("titlescreen/selected_button_over.png", 0) + }, + anims = { + idolAnimation = Animation.new("crew/anim/" .. crew, { + fps = 30, loop = true, + centered = true, x = Dim.design.width / 2, y = Dim.design.height / 2, + width = Dim.design.width, height = Dim.design.height, + }) + }, + audiosamples = { + bgm = AudioSample.new{path = "titlescreen/bgm.wav", exclusive = true, loop = true}, + cursorChange = AudioSample.new{path = "titlescreen/cursor_change.wav"}, + cursorSelect = AudioSample.new{path = "titlescreen/cursor_select.wav"} + }, + labels = { + selectorDescriptionLabel = gfx.CreateLabel(Lang.Start.desc, 22, 0), + selectorLegendScrollLabel = gfx.CreateLabel(Lang.Start.sc, 20, 0), + selectorLegendSelectLabel = gfx.CreateLabel(Lang.Start.st3, 20, 0) + } +} + +function ModeSelectPage.new(o) + local this = CreateInstance(ModeSelectPage, o, Page) + + this._idolAnimationState = this.anims.idolAnimation:start() + this.audiosamples.bgm:play() + + return this +end + +function ModeSelectPage:drawBackground(deltaTime) + self._idolAnimationState:render(deltaTime) +end + +function ModeSelectPage:drawForeground(deltaTime) + Header.draw() + Footer.draw(deltaTime) +end + +return ModeSelectPage