Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Rebase of #14 which does basic implementation of credits. #30

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions common/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ function InitUI()
local imgButtonMediumBlank = abyss.loadImage(ResourceDefs.MediumButtonBlank, ResourceDefs.Palette.Sky)
local imgCheckbox = abyss.loadImage(ResourceDefs.Checkbox, ResourceDefs.Palette.Fechar)

-- Colors do not render correctly due to gamma issues in the engine
TextColor = {
--blackHalfOpacity = 0x0000007f
LightBrown = { R = 188, G = 168, B = 140 },
LightGreen = { R = 24, G = 255, B = 0 },
White = { R = 255, G = 255, B = 255 },
Black = { R = 0, G = 0, B = 0 },
Yellowish = { R = 199, G = 179, B = 119 },
LightBrown = { R = 188, G = 168, B = 140, A = 255 },
LightGreen = { R = 24, G = 255, B = 0, A = 255 },
White = { R = 255, G = 255, B = 255, A = 255 },
Red = { R = 219, G = 63, B = 61, A = 255 },
Black = { R = 0, G = 0, B = 0, A = 255 },
Gold = { R = 200, G = 170, B = 140, A = 255 },
Yellowish = { R = 199, G = 179, B = 119, A = 255 },

}

Expand Down
78 changes: 67 additions & 11 deletions screens/credits.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
local Credits = {
}
local function setLabelProperties(this, creditsLabel, index)
creditsLabel:setPosition(400, index * 30)
creditsLabel:setAlignment("middle", "start")
creditsLabel:onUpdate(
function(delta)
local x, y = creditsLabel:getPosition()
y = math.floor(y - delta * 15)
creditsLabel:setPosition(x, y)
if y < -30 then
creditsLabel:setPosition(400, 600)
if this.creditLineOffset <= #this.creditsLines then
local creditsline = this.creditsLines[this.creditLineOffset]
if string.find(creditsline, "*") then
-- red text without first * and last \n
creditsline = string.sub(creditsline, 2, -2)
setLabelColor(creditsLabel, TextColor.Red)
else
-- white text without first * and last \n
creditsline = string.sub(creditsline, 1, -2)
setLabelColor(creditsLabel, TextColor.Gold)
end
creditsLabel.caption = creditsline
else
-- remove the label since there no more credits lines
abyss.getRootNode():removeChild(creditsLabel)
creditsLabel = nil
end
this.creditLineOffset = this.creditLineOffset + 1
end
end
)
end
local Credits = {}
Credits.__index = Credits

function setLabelColor(label, color)
return label:setColorMod(color.R, color.G, color.B)
end

function Credits:new()
local this = {}
Expand All @@ -8,25 +44,45 @@ function Credits:new()
return this
end

function Credits:initialize()
self.creditsLines = abyss.loadString(Language:i18nPath(ResourceDefs.CreditsText))
--default to 2 columns when possible otherwise center last name in section.
--header and section text seperated by one empty line

self.rootNode = abyss.getRootNode()
self.rootNode:removeAllChildren()
function Credits:initialize()
local rootNode = abyss.getRootNode()
rootNode:removeAllChildren()
abyss.resetMouseState()

self.btnExit = CreateButton(ButtonTypes.Medium, 33, 543, "@strExit#5101", function()
SetScreen(Screen.MAIN_MENU)
end)
self.btnExit =
CreateButton(
ButtonTypes.Medium,
33,
543,
"Exit",
function()
SetScreen(Screen.MAIN_MENU)
end
)

-- Main Background
self.mainBg = CreateUniqueSpriteFromFile(ResourceDefs.CreditsBackground, ResourceDefs.Palette.Sky)
self.mainBg:setCellSize(4, 3)

self.rootNode:appendChild(self.mainBg)
rootNode:appendChild(self.mainBg)
self.mainBg:appendChild(self.btnExit)

-- Credits
self.creditLineOffset = 1
self.creditsLines = {}
self.creditsLines = Split(abyss.utf16To8(abyss.loadString(Language:i18nPath(ResourceDefs.CreditsText))), "\n")
self.labelPool = {}
local this = self
-- Populating the pool
for i = 1, 21 do
local creditsLabel = abyss.createLabel(SystemFonts.FntFormal10)
setLabelProperties(this, creditsLabel, i)
table.insert(self.labelPool, creditsLabel)
rootNode:appendChild(creditsLabel)
end
end


return Credits