auto-formatting

This commit is contained in:
Hersi 2022-03-12 15:18:41 +01:00
parent 6e011b19eb
commit edcb7b8407
3 changed files with 104 additions and 201 deletions

View File

@ -1,26 +1,10 @@
local dimtable = {
design = {
width = 1080,
height = 1920
},
screen = {
width = nil,
height = nil
},
view = {
width = nil,
height = nil
},
ratio = {
landscapeUW = 21 / 9,
landscapeWide = 16 / 9,
landscapeStd = 4 / 3,
portrait = 9 / 16
}
design = {width = 1080, height = 1920},
screen = {width = nil, height = nil},
view = {width = nil, height = nil},
ratio = {landscapeUW = 21 / 9, landscapeWide = 16 / 9, landscapeStd = 4 / 3, portrait = 9 / 16},
}
dimtable.screen.width, dimtable.screen.height = game.GetResolution()
local function transformToScreenSpace()
gfx.Translate((dimtable.screen.width - dimtable.view.width) / 2, 0);
gfx.Scale(dimtable.view.width / dimtable.design.width, dimtable.view.height / dimtable.design.height);
@ -28,9 +12,7 @@ local function transformToScreenSpace()
end
local function updateResolution(ratio)
if not ratio then
ratio = dimtable.ratio.portrait
end
if not ratio then ratio = dimtable.ratio.portrait end
local screenWidth, screenHeight = game.GetResolution()
if screenWidth ~= dimtable.screen.width or screenHeight ~= dimtable.screen.height then
@ -39,10 +21,9 @@ local function updateResolution(ratio)
end
end
-- return by reference trickery:
local t = dimtable
t.transformToScreenSpace = transformToScreenSpace
t.updateResolution = updateResolution
return t
return t

View File

@ -1,6 +1,6 @@
require('common')
local Footer = require('components.footer');
local Background = require('components.background');
require("common")
local Footer = require("components.footer");
local Background = require("components.background");
local lang = require("language.call")
@ -18,41 +18,32 @@ local desw = 1080
local desh = 1920
local scale;
local backgroundImage = gfx.CreateSkinImage("bg_pattern.png",
gfx.IMAGE_REPEATX |
gfx.IMAGE_REPEATY)
local headerTitleImage = gfx.CreateSkinImage('titlescreen/title.png', 0);
local selectorBgImage = gfx.CreateSkinImage('titlescreen/selector_bg.png', 0);
local selectorArrowsImage = gfx.CreateSkinImage(
'titlescreen/selector_arrows.png', 0);
local backgroundImage = gfx.CreateSkinImage("bg_pattern.png", gfx.IMAGE_REPEATX | gfx.IMAGE_REPEATY)
local headerTitleImage = gfx.CreateSkinImage("titlescreen/title.png", 0);
local selectorBgImage = gfx.CreateSkinImage("titlescreen/selector_bg.png", 0);
local selectorArrowsImage = gfx.CreateSkinImage("titlescreen/selector_arrows.png", 0);
local unselectedButtonImage = gfx.CreateSkinImage(
'titlescreen/unselected_button.png', 0);
local unselectedButtonImage = gfx.CreateSkinImage("titlescreen/unselected_button.png", 0);
local selectedButtonBgImage = gfx.CreateSkinImage(
'titlescreen/selected_button_bg.png', 0);
local selectedButtonOverImage = gfx.CreateSkinImage(
'titlescreen/selected_button_over.png', 0);
local selectedButtonBgImage = gfx.CreateSkinImage("titlescreen/selected_button_bg.png", 0);
local selectedButtonOverImage = gfx.CreateSkinImage("titlescreen/selected_button_over.png", 0);
local skillLabelImage = gfx.CreateSkinImage('titlescreen/labels/skill.png', 0);
local friendLabelImage = gfx.CreateSkinImage('titlescreen/labels/friend.png', 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 skillLabelImage = gfx.CreateSkinImage("titlescreen/labels/skill.png", 0);
local friendLabelImage = gfx.CreateSkinImage("titlescreen/labels/friend.png", 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")
-- ANIMS
local idolAnimation = gfx.LoadSkinAnimation('crew/anim/' .. creww, 1 / 30, 0,
true);
local idolAnimation = gfx.LoadSkinAnimation("crew/anim/" .. creww, 1 / 30, 0, true);
-- AUDIO
game.LoadSkinSample('titlescreen/bgm.wav');
game.LoadSkinSample('titlescreen/cursor_change.wav');
game.LoadSkinSample('titlescreen/cursor_select.wav');
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);
@ -103,13 +94,12 @@ draw_button = function(button, x, y, selected, index)
if (selected) then
-- Draw button background
gfx.BeginPath();
gfx.ImageRect(x, y + (196 / 2 * (1 - scrollTransitionScale)), 505,
196 * scrollTransitionScale, selectedButtonBgImage, 1, 0);
gfx.ImageRect(x, y + (196 / 2 * (1 - scrollTransitionScale)), 505, 196 * scrollTransitionScale,
selectedButtonBgImage, 1, 0);
-- Draw button main label
gfx.BeginPath();
gfx.ImageRect(x + 256 - (labelWidth / 2),
(y + 58) + (64 / 2 * (1 - scrollTransitionScale)),
labelWidth, 64 * scrollTransitionScale, labelImage, 1, 0);
gfx.ImageRect(x + 256 - (labelWidth / 2), (y + 58) + (64 / 2 * (1 - scrollTransitionScale)), labelWidth,
64 * scrollTransitionScale, labelImage, 1, 0);
-- Draw description
@ -122,40 +112,28 @@ draw_button = function(button, x, y, selected, index)
-- Draw the glow overlay
gfx.BeginPath();
gfx.ImageRect(x + 2, (y - 42) + (277 / 2 * (1 - scrollTransitionScale)),
501, 277 * scrollTransitionScale, selectedButtonOverImage,
1, 0);
gfx.ImageRect(x + 2, (y - 42) + (277 / 2 * (1 - scrollTransitionScale)), 501, 277 * scrollTransitionScale,
selectedButtonOverImage, 1, 0);
else
if scrollingUp then
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 == 3 or index == 0) then gfx.GlobalAlpha(1 - scrollTransitionScale); end
if (index == 2 or index == 5) then gfx.GlobalAlpha(scrollTransitionScale); end
else
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 == 3 or index == 6) then gfx.GlobalAlpha(1 - scrollTransitionScale); end
if (index == 1 or index == 4) then gfx.GlobalAlpha(scrollTransitionScale); end
end
-- Draw button background
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, unselectedButtonImage, 1, 0);
-- Draw button main label
gfx.BeginPath();
gfx.ImageRect(x + 64, y + 28 + buttonsMovementScale * buttonHeight,
labelWidth, 64, labelImage, 1, 0);
gfx.ImageRect(x + 64, y + 28 + buttonsMovementScale * buttonHeight, labelWidth, 64, labelImage, 1, 0);
-- Draw description
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
gfx.FontSize(28);
gfx.BeginPath();
gfx.Text(descriptionText, x + 64,
y + 18 + buttonsMovementScale * buttonHeight);
gfx.Text(descriptionText, x + 64, y + 18 + buttonsMovementScale * buttonHeight);
gfx.GlobalAlpha(1)
end
@ -164,9 +142,10 @@ end;
draw_buttons = function()
indexes = {
getCorrectedButtonIndex(cursorIndex, -2),
getCorrectedButtonIndex(cursorIndex, -1), cursorIndex,
getCorrectedButtonIndex(cursorIndex, -1),
cursorIndex,
getCorrectedButtonIndex(cursorIndex, 1),
getCorrectedButtonIndex(cursorIndex, 2)
getCorrectedButtonIndex(cursorIndex, 2),
}
local yBase = desh / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER;
@ -175,32 +154,25 @@ draw_buttons = function()
marginFromDesHCenter = 128;
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]], desw - 512, yBase - marginFromDesHCenter - buttonHeight * 3, false, 0); -- Placeholder for fadeout transition
end
draw_button(buttons[indexes[1]], desw - 512,
yBase - marginFromDesHCenter - buttonHeight * 2, false, 1);
draw_button(buttons[indexes[2]], desw - 512,
yBase - marginFromDesHCenter - buttonHeight, false, 2);
draw_button(buttons[indexes[1]], desw - 512, yBase - marginFromDesHCenter - buttonHeight * 2, false, 1);
draw_button(buttons[indexes[2]], desw - 512, yBase - marginFromDesHCenter - buttonHeight, false, 2);
draw_button(buttons[indexes[3]], desw - 512, centerButtonY, true); -- The main selected center button
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]], desw - 512, yBase + marginFromDesHCenter - buttonHeight, false, 3); -- Placeholder for transition that goes to the bottom
else
draw_button(buttons[indexes[3]], desw - 512, centerButtonY, false, 3); -- Placeholder for transition that goes to the top
end
draw_button(buttons[indexes[4]], desw - 512,
yBase + marginFromDesHCenter + 10, false, 4);
draw_button(buttons[indexes[5]], desw - 512,
yBase + marginFromDesHCenter + buttonHeight + 10, false, 5);
draw_button(buttons[indexes[4]], desw - 512, yBase + marginFromDesHCenter + 10, false, 4);
draw_button(buttons[indexes[5]], desw - 512, yBase + marginFromDesHCenter + buttonHeight + 10, false, 5);
if not scrollingUp then
draw_button(buttons[indexes[1]], desw - 512,
yBase + marginFromDesHCenter + buttonHeight * 2, false, 6);
draw_button(buttons[indexes[1]], desw - 512, yBase + marginFromDesHCenter + buttonHeight * 2, false, 6);
end
end;
@ -236,19 +208,16 @@ function drawTexts()
-- Description
gfx.FillColor(255, 255, 255, math.floor(scrollTransitionScale * 255));
gfx.BeginPath();
gfx.DrawLabel(selectorDescriptionLabel, 64,
desh / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER - 52);
gfx.DrawLabel(selectorDescriptionLabel, 64, desh / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER - 52);
-- Legend on the selector
gfx.FillColor(217, 177, 126);
gfx.BeginPath();
gfx.DrawLabel(selectorLegendScrollLabel, 118,
desh / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER + 56);
gfx.DrawLabel(selectorLegendScrollLabel, 118, desh / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER + 56);
gfx.BeginPath();
gfx.DrawLabel(selectorLegendSelectLabel, 360,
desh / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER + 56);
gfx.DrawLabel(selectorLegendSelectLabel, 360, desh / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER + 56);
gfx.FillColor(255, 255, 255);
end
@ -256,28 +225,12 @@ end
function setButtons()
if buttons == nil then
buttons = {}
buttons[1] = {
skillLabelImage, 412, Menu.Challenges, lang.Challanges.ch,
lang.Challanges.ch1
}
buttons[2] = {
friendLabelImage, 169, Menu.Multiplayer, lang.Multiplayer.mp,
lang.Multiplayer.mp2
}
buttons[3] = {
normalLabelImage, 210, Menu.Start, lang.Start.st, lang.Start.st2
}
buttons[4] = {
nauticaLabelImage, 230, Menu.DLScreen, lang.Nautica.dls,
lang.Nautica.dls2
}
buttons[5] = {
settingsLabelImage, 247, Menu.Settings, lang.Settings.se,
lang.Settings.se1
}
buttons[6] = {
exitLabelImage, 110, Menu.Exit, lang.Exit.ex, lang.Exit.ex2
}
buttons[1] = {skillLabelImage, 412, Menu.Challenges, lang.Challanges.ch, lang.Challanges.ch1}
buttons[2] = {friendLabelImage, 169, Menu.Multiplayer, lang.Multiplayer.mp, lang.Multiplayer.mp2}
buttons[3] = {normalLabelImage, 210, Menu.Start, lang.Start.st, lang.Start.st2}
buttons[4] = {nauticaLabelImage, 230, Menu.DLScreen, lang.Nautica.dls, lang.Nautica.dls2}
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
@ -288,27 +241,25 @@ function drawHeader()
gfx.Fill();
gfx.ClosePath()
gfx.ImageRect(desw / 2 - 200, HEADER_HEIGHT / 2 - 20, 400, 40,
headerTitleImage, 1, 0)
gfx.ImageRect(desw / 2 - 200, HEADER_HEIGHT / 2 - 20, 400, 40, headerTitleImage, 1, 0)
end
local onKnobsChange = function(direction)
-- game.Log(direction, game.LOGGER_ERROR);
cursorIndex = cursorIndex + direction
if (cursorIndex==0) then
if (cursorIndex == 0) then
cursorIndex = #buttons
elseif (cursorIndex == #buttons+1) then
elseif (cursorIndex == #buttons + 1) then
cursorIndex = 1
end
scrollTransitionScale = 0; -- Reset transitions and play them
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
game.PlaySample('titlescreen/cursor_change.wav');
game.PlaySample("titlescreen/cursor_change.wav");
oldCursorIndex = cursorIndex;
end
@ -329,9 +280,7 @@ draw_titlescreen = function(x, y, w, h, deltaTime)
gfx.GlobalAlpha(idolAnimTransitionScale);
idolAnimTransitionScale = idolAnimTransitionScale + 1 / 60;
if (idolAnimTransitionScale > 1) then
idolAnimTransitionScale = 1;
end
if (idolAnimTransitionScale > 1) then idolAnimTransitionScale = 1; end
gfx.BeginPath();
gfx.ImageRect(0, 0, desw, desh, idolAnimation, 1, 0);
@ -340,8 +289,7 @@ draw_titlescreen = function(x, y, w, h, deltaTime)
-- Draw selector background
gfx.BeginPath();
gfx.ImageRect(0, (desh / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER) - 280 / 2,
1079, 280, selectorBgImage, 1, 0);
gfx.ImageRect(0, (desh / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER) - 280 / 2, 1079, 280, selectorBgImage, 1, 0);
setButtons()
@ -352,8 +300,8 @@ draw_titlescreen = function(x, y, w, h, deltaTime)
-- Draw the arrows around the selected button
gfx.BeginPath();
gfx.ImageRect(desw - 512, desh / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER -
buttonHeight - 8, 501, 300, selectorArrowsImage, 1, 0);
gfx.ImageRect(desw - 512, desh / 2 + SELECTOR_BAR_OFFSET_FROM_CENTER - buttonHeight - 8, 501, 300,
selectorArrowsImage, 1, 0);
-- Draw top and bottom bars
drawHeader();
@ -364,11 +312,11 @@ end
local render = function(deltaTime)
if not playedBgm then
game.PlaySample('titlescreen/bgm.wav', true);
game.PlaySample("titlescreen/bgm.wav", true);
playedBgm = true;
end
game.SetSkinSetting('_currentScreen', 'title')
game.SetSkinSetting("_currentScreen", "title")
-- detect resolution change
local resx, resy = game.GetResolution();
@ -377,8 +325,7 @@ local render = function(deltaTime)
gfx.BeginPath()
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.FillPaint(gfx.ImagePattern(0, 0, bgImageWidth, bgImageHeight, 0, backgroundImage, 0.2))
gfx.Fill()
draw_titlescreen((resX - fullX) / 2, 0, fullX, fullY, deltaTime);
@ -394,10 +341,7 @@ local render = function(deltaTime)
if (triggerServiceMenu) then
triggerServiceMenu = false;
return {
eventType = 'switch',
toScreen = 'service'
}
return {eventType = "switch", toScreen = "service"}
end
gfx.BeginPath();
@ -405,8 +349,8 @@ end;
local onButtonPressed = function(button)
if button == game.BUTTON_STA then
game.PlaySample('titlescreen/cursor_select.wav');
game.StopSample('titlescreen/bgm.wav');
game.PlaySample("titlescreen/cursor_select.wav");
game.StopSample("titlescreen/bgm.wav");
buttons[cursorIndex][3]()
elseif button == game.BUTTON_BCK then
Menu.Exit()
@ -422,5 +366,5 @@ return {
render = render,
onKnobsChange = onKnobsChange,
onButtonPressed = onButtonPressed,
onMousePressed = function () return false end
onMousePressed = function() return false end,
}

View File

@ -4,43 +4,28 @@ local Wallpaper = require("components.wallpaper")
local triggerSplashScreen = false
local rootMenu = {
{label = "IDOLS", children = {{label = "GRACEv6"}, {label = "NEARNOAHv6"}, {label = "IDKv6"}}},
{
label = 'IDOLS',
children = {
{label = 'GRACEv6'},
{label = 'NEARNOAHv6'},
{label = 'IDKv6'}
}
}, {
label = 'LASER COLORS',
label = "LASER COLORS",
children = {
{
label = 'LEFT LASER',
label = "LEFT LASER",
children = {
{label='BLUE', color={0,128,255}},
{label='PINK', color={255,0,255}},
{label='GREEN', color={0,255,0}},
{label='YELLOW', color={255,255,0}},
}
{label = "BLUE", color = {0, 128, 255}},
{label = "PINK", color = {255, 0, 255}},
{label = "GREEN", color = {0, 255, 0}},
{label = "YELLOW", color = {255, 255, 0}},
},
},
{
label = 'RIGHT LASER',
children = {
{label='BLUE'},
{label='PINK'},
{label='GREEN'},
{label='YELLOW'},
}
}
}
}, {
label = 'MORE OPTIONS',
children = {{label = 'TEST'}}
}, {
label = 'OH YOU SUSSY BAKA',
children = {{label = 'TEST'}}
label = "RIGHT LASER",
children = {{label = "BLUE"}, {label = "PINK"}, {label = "GREEN"}, {label = "YELLOW"}},
},
},
},
{label = "BACK TO TITLE SCREEN", type="back", handler = function() triggerSplashScreen = true; end}
{label = "MORE OPTIONS", children = {{label = "TEST"}}},
{label = "OH YOU SUSSY BAKA", children = {{label = "TEST"}}},
{label = "BACK TO TITLE SCREEN", type = "back", handler = function() triggerSplashScreen = true; end},
}
local menu = rootMenu
@ -65,15 +50,15 @@ local function render(deltaTime)
gfx.FontSize(24);
gfx.BeginPath();
gfx.Text('SERIVCE MENU', 1080 / 2, 128);
gfx.Text('BT-A/BT-B = GO UP/DOWN', 1080 / 2, 1920 - 256 - 28);
gfx.Text('START = SELECT', 1080 / 2, 1920 - 256);
gfx.Text("SERIVCE MENU", 1080 / 2, 128);
gfx.Text("BT-A/BT-B = UP/DOWN", 1080 / 2, 1920 - 256 - 28);
gfx.Text("START = SELECT", 1080 / 2, 1920 - 256);
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
local yOffset = 256;
for i, menuItem in ipairs(menu) do
if menuItem.type == 'back' then
if menuItem.type == "back" then
yOffset = yOffset + 28 * 2;
else
yOffset = yOffset + 28;
@ -81,11 +66,7 @@ local function render(deltaTime)
if (i == index) then
if menuItem.color then
gfx.FillColor(
menuItem.color[1],
menuItem.color[2],
menuItem.color[3]
)
gfx.FillColor(menuItem.color[1], menuItem.color[2], menuItem.color[3])
else
gfx.FillColor(0, 255, 0, 255);
end
@ -99,7 +80,7 @@ local function render(deltaTime)
if (triggerSplashScreen) then
triggerSplashScreen = false;
return {eventType = 'switch', toScreen = 'splash'}
return {eventType = "switch", toScreen = "splash"}
end
end
@ -109,31 +90,28 @@ local onButtonPressed = function(button)
menu[index].handler()
elseif menu[index].children ~= nil then
menu = menu[index].children
index=1;
index = 1;
-- If the back button does not exist, add it.
if (menu[#menu].type ~= 'back') then
menu[#menu+1] = {
type="back",
if (menu[#menu].type ~= "back") then
menu[#menu + 1] = {
type = "back",
label = "BACK TO MAIN MENU",
handler = function()
index=1;
index = 1;
menu = rootMenu
end
end,
}
end
end
elseif button == game.BUTTON_BTA then
index = index - 1;
if (index == 0) then index = #menu end
elseif button == game.BUTTON_BTB then
index = index + 1;
if (index == #menu+1) then index = 1 end
if (index == #menu + 1) then index = 1 end
end
end
return {
render = render,
onButtonPressed = onButtonPressed
}
return {render = render, onButtonPressed = onButtonPressed}