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
Changes from 1 commit
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
Next Next commit
Added Scrolling Credits
Maxim Osin authored and cookta2012 committed Jan 24, 2022
commit c858dee5efdcd370cc7ef8d0aece6140b8bb3329
60 changes: 54 additions & 6 deletions screens/credits.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
local Credits = {
}
function stringToArray(arr, creditsString)
for line in creditsString:gmatch("([^\n]*)\n?") do
table.insert(arr, line)
end
end

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.round(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)
creditsLabel:setColorMod(0xFF, 0x00, 0x00)
else
-- white text without first * and last \n
creditsline = string.sub(creditsline, 1, -2)
creditsLabel:setColorMod(0xFF, 0xFF, 0xFF)
end
creditsLabel.caption = creditsline
else
-- remove the label since there no more credits lines
this.rootNode:removeChild(creditsLabel)
creditsLabel = nil
end
this.creditLineOffset = this.creditLineOffset + 1
end
end
)
end
local Credits = {}
Credits.__index = Credits

function Credits:new()
local this = {}
@@ -9,13 +47,11 @@ function Credits:new()
end

function Credits:initialize()
self.creditsLines = abyss.loadString(Language:i18nPath(ResourceDefs.CreditsText))

self.rootNode = abyss.getRootNode()
self.rootNode:removeAllChildren()
abyss.resetMouseState()

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

@@ -26,7 +62,19 @@ function Credits:initialize()
self.rootNode:appendChild(self.mainBg)
self.mainBg:appendChild(self.btnExit)

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


return Credits