refactor and format document for mode_select

add wallpaper and dim modules to mode_select
This commit is contained in:
Hersi 2022-03-26 02:21:54 +01:00
parent 408feed832
commit 5d3e4457eb
1 changed files with 223 additions and 220 deletions

View File

@ -1,146 +1,173 @@
require("common") require("common")
local Footer = require("components.footer"); local Footer = require("components.footer")
local Background = require("components.background"); local Wallpaper = require("components.wallpaper")
local Background = require("components.background")
local Dim = require("common.dimensions")
local lang = require("language.call") local lang = require("language.call")
local cursorIndex = 3; local cursorIndex = 3
local buttonHeight = 128 + 16; local buttonHeight = 128 + 16
local SELECTOR_BAR_OFFSET_FROM_CENTER = 128; local SELECTOR_BAR_OFFSET_FROM_CENTER = 128
local BAR_ALPHA = 191; local BAR_ALPHA = 191
local HEADER_HEIGHT = 100 local HEADER_HEIGHT = 100
local buttons = nil local crew = game.GetSkinSetting("single_idol")
local resx, resy = game.GetResolution()
local desw = 1080
local desh = 1920
local scale;
local backgroundImage = gfx.CreateSkinImage("bg_pattern.png", gfx.IMAGE_REPEATX | gfx.IMAGE_REPEATY) local resources = {
local headerTitleImage = gfx.CreateSkinImage("titlescreen/title.png", 0); images = {
local selectorBgImage = gfx.CreateSkinImage("titlescreen/selector_bg.png", 0); headerTitleImage = gfx.CreateSkinImage("titlescreen/title.png", 0),
local selectorArrowsImage = gfx.CreateSkinImage("titlescreen/selector_arrows.png", 0); 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 = gfx.LoadSkinAnimation("crew/anim/" .. crew, 1 / 30, 0, true)
},
audiosamples = {
bgm = "titlescreen/bgm.wav",
cursorChange = "titlescreen/cursor_change.wav",
cursorSelect = "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)
}
}
local unselectedButtonImage = gfx.CreateSkinImage("titlescreen/unselected_button.png", 0); -- load audio samples
for _, path in pairs(resources.audiosamples) do
game.LoadSkinSample(path)
end
local selectedButtonBgImage = gfx.CreateSkinImage("titlescreen/selected_button_bg.png", 0); local buttons = {
local selectedButtonOverImage = gfx.CreateSkinImage("titlescreen/selected_button_over.png", 0); {
labelImage = gfx.CreateSkinImage("titlescreen/labels/skill.png", 0),
labelWidth = 412,
action = nil, -- Menu.Challenges,
description = lang.Challanges.ch,
details = lang.Challanges.ch1,
},
{
labelImage = gfx.CreateSkinImage("titlescreen/labels/friend.png", 0),
labelWidth = 169,
action = nil, -- Menu.Multiplayer,
description = lang.Multiplayer.mp,
details = lang.Multiplayer.mp2,
},
{
labelImage = gfx.CreateSkinImage("titlescreen/labels/normal.png", 0),
labelWidth = 210,
action = nil, -- Menu.Start,
description = lang.Start.st,
details = lang.Start.st2,
},
{
labelImage = gfx.CreateSkinImage("titlescreen/labels/nautica.png", 0),
labelWidth = 230,
action = nil, -- Menu.DLScreen,
description = lang.Nautica.dls,
details = lang.Nautica.dls2,
},
{
labelImage = gfx.CreateSkinImage("titlescreen/labels/settings.png", 0),
labelWidth = 247,
action = nil, -- Menu.Settings,
description = lang.Settings.se,
details = lang.Settings.se1,
},
{
labelImage = gfx.CreateSkinImage("titlescreen/labels/exit.png", 0),
labelWidth = 110,
action = nil, -- Menu.Exit,
description = lang.Exit.ex,
details = lang.Exit.ex2,
},
}
local skillLabelImage = gfx.CreateSkinImage("titlescreen/labels/skill.png", 0); local scrollTransitionScale = 1 -- Goes from 0 to 1 when transition is happening, sits at 1 when it's not.
local friendLabelImage = gfx.CreateSkinImage("titlescreen/labels/friend.png", 0); local buttonsMovementScale = 0 -- Basically same as `scrollTransitionScale` but with a +/- sign for the scroll direction and goes from 1 to 0
local normalLabelImage = gfx.CreateSkinImage("titlescreen/labels/normal.png", 0);
local nauticaLabelImage = gfx.CreateSkinImage("titlescreen/labels/nautica.png", 0);
local settingsLabelImage = gfx.CreateSkinImage("titlescreen/labels/settings.png", 0);
local exitLabelImage = gfx.CreateSkinImage("titlescreen/labels/exit.png", 0);
local creww = game.GetSkinSetting("single_idol") local idolAnimTransitionScale = 0
-- ANIMS local oldCursorIndex = 3
local idolAnimation = gfx.LoadSkinAnimation("crew/anim/" .. creww, 1 / 30, 0, true); local scrollingUp = false
local playedBgm = false
-- AUDIO
game.LoadSkinSample("titlescreen/bgm.wav");
game.LoadSkinSample("titlescreen/cursor_change.wav");
game.LoadSkinSample("titlescreen/cursor_select.wav");
local selectorDescriptionLabel = gfx.CreateLabel(lang.Start.desc, 22, 0);
local selectorLegendScrollLabel = gfx.CreateLabel(lang.Start.sc, 20, 0);
local selectorLegendSelectLabel = gfx.CreateLabel(lang.Start.st3, 20, 0);
local scrollTransitionScale = 1; -- Goes from 0 to 1 when transition is happening, sits at 1 when it's not.
local buttonsMovementScale = 0; -- Basically same as `scrollTransitionScale` but with a +/- sign for the scroll direction and goes from 1 to 0
local idolAnimTransitionScale = 0;
local oldCursorIndex = 3;
local scrollingUp = false;
local playedBgm = false;
local triggerServiceMenu = false local triggerServiceMenu = false
-- Window variables local function draw_button(button, x, y, selected, index)
local resX, resY
-- Aspect Ratios
local landscapeWidescreenRatio = 16 / 9
local landscapeStandardRatio = 4 / 3
local portraitWidescreenRatio = 9 / 16
-- Portrait sizes
local fullX, fullY
local resolutionChange = function(x, y)
resX = x
resY = y
fullX = portraitWidescreenRatio * y
fullY = y
end
function resetLayoutInformation()
resx, resy = game.GetResolution()
desw = 1080
desh = 1920
scale = resx / desw
end
draw_button = function(button, x, y, selected, index)
local labelImage = button[1];
local labelWidth = button[2];
local descriptionText = button[4];
if (selected) then if (selected) then
-- Draw button background -- Draw button background
gfx.BeginPath(); gfx.BeginPath()
gfx.ImageRect(x, y + (196 / 2 * (1 - scrollTransitionScale)), 505, 196 * scrollTransitionScale, gfx.ImageRect(x, y + (196 / 2 * (1 - scrollTransitionScale)), 505, 196 * scrollTransitionScale,
selectedButtonBgImage, 1, 0); resources.images.selectedButtonBgImage, 1, 0)
-- Draw button main label -- Draw button main label
gfx.BeginPath(); gfx.BeginPath()
gfx.ImageRect(x + 256 - (labelWidth / 2), (y + 58) + (64 / 2 * (1 - scrollTransitionScale)), labelWidth, gfx.ImageRect(x + 256 - (button.labelWidth / 2), (y + 58) + (64 / 2 * (1 - scrollTransitionScale)),
64 * scrollTransitionScale, labelImage, 1, 0); button.labelWidth, 64 * scrollTransitionScale, button.labelImage, 1, 0)
-- Draw description -- Draw description
gfx.GlobalAlpha((scrollTransitionScale - 0.8) * 5) gfx.GlobalAlpha((scrollTransitionScale - 0.8) * 5)
gfx.TextAlign(gfx.TEXT_ALIGN_CENTER + gfx.TEXT_ALIGN_MIDDLE) gfx.TextAlign(gfx.TEXT_ALIGN_CENTER + gfx.TEXT_ALIGN_MIDDLE)
gfx.FontSize(40); gfx.FontSize(40)
gfx.BeginPath(); gfx.BeginPath()
gfx.Text(descriptionText, x + 256, y + 28); gfx.Text(button.description, x + 256, y + 28)
gfx.GlobalAlpha(1) gfx.GlobalAlpha(1)
-- Draw the glow overlay -- Draw the glow overlay
gfx.BeginPath(); gfx.BeginPath()
gfx.ImageRect(x + 2, (y - 42) + (277 / 2 * (1 - scrollTransitionScale)), 501, 277 * scrollTransitionScale, gfx.ImageRect(x + 2, (y - 42) + (277 / 2 * (1 - scrollTransitionScale)), 501, 277 * scrollTransitionScale,
selectedButtonOverImage, 1, 0); resources.images.selectedButtonOverImage, 1, 0)
else else
if scrollingUp then if scrollingUp then
if (index == 3 or index == 0) then gfx.GlobalAlpha(1 - scrollTransitionScale); end if (index == 3 or index == 0) then gfx.GlobalAlpha(1 - scrollTransitionScale) end
if (index == 2 or index == 5) then gfx.GlobalAlpha(scrollTransitionScale); end if (index == 2 or index == 5) then gfx.GlobalAlpha(scrollTransitionScale) end
else else
if (index == 3 or index == 6) then gfx.GlobalAlpha(1 - scrollTransitionScale); end if (index == 3 or index == 6) then gfx.GlobalAlpha(1 - scrollTransitionScale) end
if (index == 1 or index == 4) then gfx.GlobalAlpha(scrollTransitionScale); end if (index == 1 or index == 4) then gfx.GlobalAlpha(scrollTransitionScale) end
end end
-- Draw button background -- Draw button background
gfx.BeginPath(); gfx.BeginPath()
gfx.ImageRect(x, y + buttonsMovementScale * buttonHeight, 1026 / 2, 257 / 2, unselectedButtonImage, 1, 0); gfx.ImageRect(x, y + buttonsMovementScale * buttonHeight, 1026 / 2, 257 / 2, resources.images.unselectedButtonImage, 1, 0)
-- Draw button main label -- Draw button main label
gfx.BeginPath(); gfx.BeginPath()
gfx.ImageRect(x + 64, y + 28 + buttonsMovementScale * buttonHeight, labelWidth, 64, labelImage, 1, 0); gfx.ImageRect(x + 64, y + 28 + buttonsMovementScale * buttonHeight, button.labelWidth, 64, button.labelImage, 1,
0)
-- Draw description -- Draw description
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE) gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
gfx.FontSize(28); gfx.FontSize(28)
gfx.BeginPath(); gfx.BeginPath()
gfx.Text(descriptionText, x + 64, y + 18 + buttonsMovementScale * buttonHeight); gfx.Text(button.description, x + 64, y + 18 + buttonsMovementScale * buttonHeight)
gfx.GlobalAlpha(1) gfx.GlobalAlpha(1)
end end
end; end
draw_buttons = function() local function getCorrectedButtonIndex(from, offset)
indexes = { local buttonsNum = #buttons
local index = from + offset
if index < 1 then
index = buttonsNum + (from + offset) -- this only happens if the offset is negative
end
if index > buttonsNum then
index = offset - (buttonsNum - from) -- this only happens if the offset is positive
end
return index
end
local function draw_buttons()
local indexes = {
getCorrectedButtonIndex(cursorIndex, -2), getCorrectedButtonIndex(cursorIndex, -2),
getCorrectedButtonIndex(cursorIndex, -1), getCorrectedButtonIndex(cursorIndex, -1),
cursorIndex, cursorIndex,
@ -148,104 +175,86 @@ draw_buttons = function()
getCorrectedButtonIndex(cursorIndex, 2), getCorrectedButtonIndex(cursorIndex, 2),
} }
local yBase = desh / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER; local yBase = Dim.design.height / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER
centerButtonY = yBase - buttonHeight / 2 - 28; -- to fit with the selector bg local centerButtonY = yBase - buttonHeight / 2 - 28 -- to fit with the selector bg
marginFromDesHCenter = 128; local marginFromDesHCenter = 128
if scrollingUp then if scrollingUp then
draw_button(buttons[indexes[5]], desw - 512, yBase - marginFromDesHCenter - buttonHeight * 3, false, 0); -- Placeholder for fadeout transition draw_button(buttons[indexes[5]], Dim.design.width - 512, yBase - marginFromDesHCenter - buttonHeight * 3, false,
0) -- Placeholder for fadeout transition
end end
draw_button(buttons[indexes[1]], desw - 512, yBase - marginFromDesHCenter - buttonHeight * 2, false, 1); draw_button(buttons[indexes[1]], Dim.design.width - 512, yBase - marginFromDesHCenter - buttonHeight * 2, false, 1)
draw_button(buttons[indexes[2]], desw - 512, yBase - marginFromDesHCenter - buttonHeight, false, 2); draw_button(buttons[indexes[2]], Dim.design.width - 512, yBase - marginFromDesHCenter - buttonHeight, false, 2)
draw_button(buttons[indexes[3]], desw - 512, centerButtonY, true); -- The main selected center button draw_button(buttons[indexes[3]], Dim.design.width - 512, centerButtonY, true) -- The main selected center button
if scrollingUp then if scrollingUp then
draw_button(buttons[indexes[3]], desw - 512, yBase + marginFromDesHCenter - buttonHeight, false, 3); -- Placeholder for transition that goes to the bottom draw_button(buttons[indexes[3]], Dim.design.width - 512, yBase + marginFromDesHCenter - buttonHeight, false, 3) -- Placeholder for transition that goes to the bottom
else else
draw_button(buttons[indexes[3]], desw - 512, centerButtonY, false, 3); -- Placeholder for transition that goes to the top draw_button(buttons[indexes[3]], Dim.design.width - 512, centerButtonY, false, 3) -- Placeholder for transition that goes to the top
end end
draw_button(buttons[indexes[4]], desw - 512, yBase + marginFromDesHCenter + 10, false, 4); draw_button(buttons[indexes[4]], Dim.design.width - 512, yBase + marginFromDesHCenter + 10, false, 4)
draw_button(buttons[indexes[5]], desw - 512, yBase + marginFromDesHCenter + buttonHeight + 10, false, 5); draw_button(buttons[indexes[5]], Dim.design.width - 512, yBase + marginFromDesHCenter + buttonHeight + 10, false, 5)
if not scrollingUp then if not scrollingUp then
draw_button(buttons[indexes[1]], desw - 512, yBase + marginFromDesHCenter + buttonHeight * 2, false, 6); draw_button(buttons[indexes[1]], Dim.design.width - 512, yBase + marginFromDesHCenter + buttonHeight * 2, false,
6)
end end
end;
function getCorrectedButtonIndex(from, offset)
buttonsNum = #buttons;
index = from + offset;
if index < 1 then
index = buttonsNum + (from + offset) -- this only happens if the offset is negative
end
if index > buttonsNum then
indexesUntilEnd = buttonsNum - from;
index = offset - indexesUntilEnd -- this only happens if the offset is positive
end
return index;
end end
function drawTexts() local function drawTexts()
currentFullDescriptionText = buttons[cursorIndex][5]; local currentFullDescriptionText = buttons[cursorIndex].details
gfx.BeginPath(); gfx.BeginPath()
gfx.UpdateLabel(selectorDescriptionLabel, currentFullDescriptionText, 22) gfx.UpdateLabel(resources.labels.selectorDescriptionLabel, currentFullDescriptionText, 22)
gfx.BeginPath(); gfx.BeginPath()
-- gfx.UpdateLabel(selectorLegendScrollLabel, 'SCROLL', 20); -- gfx.UpdateLabel(resources.labels.selectorLegendScrollLabel, 'SCROLL', 20)
-- descriptionAlpha = math.abs(selectedButtonScaleY - 0.5) * 2; -- descriptionAlpha = math.abs(selectedButtonScaleY - 0.5) * 2
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE); gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
-- Description -- Description
gfx.FillColor(255, 255, 255, math.floor(scrollTransitionScale * 255)); gfx.FillColor(255, 255, 255, math.floor(scrollTransitionScale * 255))
gfx.BeginPath(); gfx.BeginPath()
gfx.DrawLabel(selectorDescriptionLabel, 64, desh / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER - 52); gfx.DrawLabel(resources.labels.selectorDescriptionLabel, 64, Dim.design.height / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER - 52)
-- Legend on the selector -- Legend on the selector
gfx.FillColor(217, 177, 126); gfx.FillColor(217, 177, 126)
gfx.BeginPath(); gfx.BeginPath()
gfx.DrawLabel(selectorLegendScrollLabel, 118, desh / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER + 56); gfx.DrawLabel(resources.labels.selectorLegendScrollLabel, 118, Dim.design.height / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER + 56)
gfx.BeginPath(); gfx.BeginPath()
gfx.DrawLabel(selectorLegendSelectLabel, 360, desh / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER + 56); gfx.DrawLabel(resources.labels.selectorLegendSelectLabel, 360, Dim.design.height / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER + 56)
gfx.FillColor(255, 255, 255); gfx.FillColor(255, 255, 255)
end end
function setButtons() local function setButtonActions()
if buttons == nil then buttons[1].action = Menu.Challenges
buttons = {} buttons[2].action = Menu.Multiplayer
buttons[1] = {skillLabelImage, 412, Menu.Challenges, lang.Challanges.ch, lang.Challanges.ch1} buttons[3].action = Menu.Start
buttons[2] = {friendLabelImage, 169, Menu.Multiplayer, lang.Multiplayer.mp, lang.Multiplayer.mp2} buttons[4].action = Menu.DLScreen
buttons[3] = {normalLabelImage, 210, Menu.Start, lang.Start.st, lang.Start.st2} buttons[5].action = Menu.Settings
buttons[4] = {nauticaLabelImage, 230, Menu.DLScreen, lang.Nautica.dls, lang.Nautica.dls2} buttons[6].action = Menu.Exit
buttons[5] = {settingsLabelImage, 247, Menu.Settings, lang.Settings.se, lang.Settings.se1}
buttons[6] = {exitLabelImage, 110, Menu.Exit, lang.Exit.ex, lang.Exit.ex2}
end
end end
function drawHeader() local function drawHeader()
gfx.BeginPath(); gfx.BeginPath()
gfx.FillColor(0, 0, 0, BAR_ALPHA); gfx.FillColor(0, 0, 0, BAR_ALPHA)
gfx.Rect(0, 0, desw, HEADER_HEIGHT); gfx.Rect(0, 0, Dim.design.width, HEADER_HEIGHT)
gfx.Fill(); gfx.Fill()
gfx.ClosePath() gfx.ClosePath()
gfx.ImageRect(desw / 2 - 200, HEADER_HEIGHT / 2 - 20, 400, 40, headerTitleImage, 1, 0) gfx.ImageRect(Dim.design.width / 2 - 200, HEADER_HEIGHT / 2 - 20, 400, 40, resources.images.headerTitleImage, 1, 0)
end end
local onKnobsChange = function(direction) local function onKnobsChange(direction)
-- game.Log(direction, game.LOGGER_ERROR); -- game.Log(direction, game.LOGGER_ERROR)
cursorIndex = cursorIndex + direction cursorIndex = cursorIndex + direction
if (cursorIndex == 0) then if (cursorIndex == 0) then
cursorIndex = #buttons cursorIndex = #buttons
@ -253,85 +262,74 @@ local onKnobsChange = function(direction)
cursorIndex = 1 cursorIndex = 1
end end
scrollTransitionScale = 0; -- Reset transitions and play them scrollTransitionScale = 0 -- Reset transitions and play them
scrollingUp = false; scrollingUp = false
if ((cursorIndex > oldCursorIndex and not (cursorIndex == 6 and oldCursorIndex == 1)) or if ((cursorIndex > oldCursorIndex and not (cursorIndex == 6 and oldCursorIndex == 1)) or
(cursorIndex == 1 and oldCursorIndex == 6)) then scrollingUp = true; end (cursorIndex == 1 and oldCursorIndex == 6)) then scrollingUp = true end
game.PlaySample("titlescreen/cursor_change.wav"); game.PlaySample("titlescreen/cursor_change.wav")
oldCursorIndex = cursorIndex; oldCursorIndex = cursorIndex
end end
draw_titlescreen = function(x, y, w, h, deltaTime) local function draw_titlescreen(deltaTime)
gfx.Scissor(x, y, w, h);
gfx.Translate(x, y);
gfx.Scale(w / 1080, h / 1920);
gfx.LoadSkinFont("segoeui.ttf") gfx.LoadSkinFont("segoeui.ttf")
-- Draw background -- Draw background
gfx.BeginPath(); gfx.BeginPath()
Background.draw(deltaTime) Background.draw(deltaTime)
local idolAnimTickRes = gfx.TickAnimation(idolAnimation, deltaTime); local idolAnimTickRes = gfx.TickAnimation(resources.anims.idolAnimation, deltaTime)
if idolAnimTickRes == 1 then if idolAnimTickRes == 1 then
gfx.GlobalAlpha(idolAnimTransitionScale); gfx.GlobalAlpha(idolAnimTransitionScale)
idolAnimTransitionScale = idolAnimTransitionScale + 1 / 60; idolAnimTransitionScale = idolAnimTransitionScale + 1 / 60
if (idolAnimTransitionScale > 1) then idolAnimTransitionScale = 1; end if (idolAnimTransitionScale > 1) then idolAnimTransitionScale = 1 end
gfx.BeginPath(); gfx.BeginPath()
gfx.ImageRect(0, 0, desw, desh, idolAnimation, 1, 0); gfx.ImageRect(0, 0, Dim.design.width, Dim.design.height, resources.anims.idolAnimation, 1, 0)
gfx.GlobalAlpha(1); gfx.GlobalAlpha(1)
end end
-- Draw selector background -- Draw selector background
gfx.BeginPath(); gfx.BeginPath()
gfx.ImageRect(0, (desh / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER) - 280 / 2, 1079, 280, selectorBgImage, 1, 0); gfx.ImageRect(0, (Dim.design.height / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER) - 280 / 2, 1079, 280, resources.images.selectorBgImage, 1,
0)
setButtons() buttonY = (Dim.design.height / 2) - 2 * (257 + 5)
buttonY = (desh / 2) - 2 * (257 + 5); draw_buttons()
drawTexts()
draw_buttons();
drawTexts();
-- Draw the arrows around the selected button -- Draw the arrows around the selected button
gfx.BeginPath(); gfx.BeginPath()
gfx.ImageRect(desw - 512, desh / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER - buttonHeight - 8, 501, 300, gfx.ImageRect(Dim.design.width - 512, Dim.design.height / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER - buttonHeight - 8,
selectorArrowsImage, 1, 0); 501, 300, resources.images.selectorArrowsImage, 1, 0)
-- Draw top and bottom bars -- Draw top and bottom bars
drawHeader(); drawHeader()
Footer.draw(deltaTime); Footer.draw(deltaTime)
gfx.ResetTransform(); gfx.ResetTransform()
end end
local render = function(deltaTime) local function render(deltaTime)
if not playedBgm then if not playedBgm then
game.PlaySample("titlescreen/bgm.wav", true); game.PlaySample("titlescreen/bgm.wav", true)
playedBgm = true; playedBgm = true
end end
game.SetSkinSetting("_currentScreen", "title") Dim.updateResolution()
-- detect resolution change Wallpaper.render()
local resx, resy = game.GetResolution();
if resx ~= resX or resy ~= resY then resolutionChange(resx, resy) end
gfx.BeginPath() Dim.transformToScreenSpace()
local bgImageWidth, bgImageHeight = gfx.ImageSize(backgroundImage)
gfx.Rect(0, 0, resX, resY)
gfx.FillPaint(gfx.ImagePattern(0, 0, bgImageWidth, bgImageHeight, 0, backgroundImage, 0.2))
gfx.Fill()
draw_titlescreen((resX - fullX) / 2, 0, fullX, fullY, deltaTime); draw_titlescreen(deltaTime)
scrollTransitionScale = scrollTransitionScale + deltaTime / 0.2; scrollTransitionScale = scrollTransitionScale + deltaTime / 0.2
if (scrollTransitionScale > 1) then scrollTransitionScale = 1; end if (scrollTransitionScale > 1) then scrollTransitionScale = 1 end
if scrollingUp then if scrollingUp then
buttonsMovementScale = 1 - scrollTransitionScale buttonsMovementScale = 1 - scrollTransitionScale
@ -340,27 +338,32 @@ local render = function(deltaTime)
end end
if (triggerServiceMenu) then if (triggerServiceMenu) then
triggerServiceMenu = false; triggerServiceMenu = false
return {eventType = "switch", toScreen = "service"} return {eventType = "switch", toScreen = "service"}
end end
gfx.BeginPath(); gfx.BeginPath()
end; end
local onButtonPressed = function(button) local function onButtonPressed(button)
if button == game.BUTTON_STA then if button == game.BUTTON_STA then
game.PlaySample("titlescreen/cursor_select.wav"); game.PlaySample("titlescreen/cursor_select.wav")
game.StopSample("titlescreen/bgm.wav"); game.StopSample("titlescreen/bgm.wav")
buttons[cursorIndex][3]()
if buttons[cursorIndex].action == nil then setButtonActions() end
buttons[cursorIndex].action()
elseif button == game.BUTTON_BCK then elseif button == game.BUTTON_BCK then
Menu.Exit() Menu.Exit()
elseif button == game.BUTTON_FXR then elseif button == game.BUTTON_FXR then
triggerServiceMenu = true; triggerServiceMenu = true
end end
end end
-- the thing is... titlescreen script does not have a call to reset function... WHYYYYY -- the thing is... titlescreen script does not have a call to reset function... WHYYYYY
function reset() playedBgm = false; end function reset() playedBgm = false end
return { return {
render = render, render = render,