Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
cadin committed Nov 25, 2023
2 parents 836d0b0 + 4c9e20e commit 8ded0d7
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 21 deletions.
19 changes: 14 additions & 5 deletions Panels.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Panels version 1.6.2
-- Panels version 1.7
-- https://cadin.github.io/panels/

import "CoreLibs/object"
Expand Down Expand Up @@ -807,7 +807,8 @@ end

local function drawComic(offset)
gfx.clear(sequence.backgroundColor)

--
-- setDefaultFont()

if shouldFadeBG then
local pct = 1 -
Expand All @@ -820,8 +821,7 @@ local function drawComic(offset)
for i, panel in ipairs(panels) do
if (panel:isOnScreen(offset)) then
panel:render(offset, sequence.foregroundColor, sequence.backgroundColor)
panel.canvas:draw(panel.frame.x + offset.x, panel.frame.y + offset.y)

panel.canvas:draw(0, 0)
elseif panel.wasOnScreen then
if panel.targetSequenceFunction then
targetSequence = panel.targetSequenceFunction()
Expand All @@ -831,7 +831,6 @@ local function drawComic(offset)
panel.wasOnScreen = false
end
end

end

-- Playdate update loop
Expand Down Expand Up @@ -1033,7 +1032,16 @@ local function createCreditsSequence()
table.insert(Panels.comicData, seq)
end

function setDefaultFont()
if Panels.Settings.defaultFontFamily then
gfx.setFontFamily(Panels.Font.getFamily(Panels.Settings.defaultFontFamily))
elseif Panels.Settings.defaultFont then
gfx.setFont(Panels.Font.get(Panels.Settings.defaultFont))
end
end

function Panels.startCutscene(comicData, callback)
setDefaultFont()
isCutscene = true
cutsceneFinishCallback = callback
Panels.comicData = comicData
Expand All @@ -1054,6 +1062,7 @@ function Panels.startCutscene(comicData, callback)
end

function Panels.start(comicData)
setDefaultFont()
Panels.comicData = comicData
maxScrollVelocity = Panels.Settings.maxScrollSpeed
alert = Panels.Alert.new("Start Over?", "All progress will be lost.", { "Cancel", "Start Over" })
Expand Down
15 changes: 14 additions & 1 deletion modules/Alert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ function Panels.Alert.new(title, text, options, callback, selection)
local x = (ScreenWidth - width) / 2
local y = (ScreenHeight - height) / 2 - 8
local offset = 0

if Panels.Settings.menuFontFamily then
local family = Panels.Font.getFamily(Panels.Settings.menuFontFamily)
titleFont = family
textFont = family
listFont = family

elseif Panels.Settings.defaultFontFamily then
local family = Panels.Font.getFamily(Panels.Settings.defaultFontFamily)
titleFont = family
textFont = family
listFont = family
end

gridView = playdate.ui.gridview.new((width - 32) / 2 - 8, 32)
gridView:setNumberOfRows(1)
Expand Down Expand Up @@ -84,7 +97,7 @@ function Panels.Alert.new(title, text, options, callback, selection)

function alert:drawText()
gfx.setFont(titleFont)
gfx.drawTextInRect(self.title, x + 16, y + 16, width - 32, 32, nil, "...", kTextAlignment.center)
gfx.drawTextInRect("*".. self.title .. "*", x + 16, y + 16, width - 32, 32, nil, "...", kTextAlignment.center)
gfx.setFont(textFont)
gfx.drawTextInRect(self.text, x + 16, y + 48, width - 32, height - 128, nil, "...", kTextAlignment.center)
end
Expand Down
4 changes: 2 additions & 2 deletions modules/Font.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function Panels.Font.getFamily(paths)

if families[key] == nil then
clipExtensions(paths)
cache[key] = playdate.graphics.font.newFamily(paths)
families[key] = playdate.graphics.font.newFamily(paths)
end
return cache[key]
return families[key]
end
19 changes: 17 additions & 2 deletions modules/Menus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ local hideSound = playdate.sound.sampleplayer.new(Panels.Settings.path .. "asset
local showSound = playdate.sound.sampleplayer.new(Panels.Settings.path .. "assets/audio/swish-in.wav")

local headerFont = gfx.getSystemFont("bold")
-- local listFont = Panels.Font.get(Panels.Settings.path .. "assets/fonts/Asheville-Narrow-14-Bold")--gfx.getSystemFont()

local listFont = gfx.getSystemFont()

Panels.Menu = {}
Expand All @@ -42,6 +40,17 @@ function Panels.Menu.new(height, redrawContent, inputHandlers)
menu.onDidShow = nil
menu.onDidHide = nil

if Panels.Settings.menuFontFamily then
local family = Panels.Font.getFamily(Panels.Settings.menuFontFamily)
headerFont = family
listFont = family

elseif Panels.Settings.defaultFontFamily then
local family = Panels.Font.getFamily(Panels.Settings.defaultFontFamily)
headerFont = family
listFont = family
end

local function drawBG(yPos)
gfx.setColor(Panels.Color.WHITE)
gfx.fillRoundRect(0, yPos, 400, ScreenHeight + 5, 4)
Expand Down Expand Up @@ -168,6 +177,7 @@ local function updateMainMenu(gameDidFinish, gameDidStart)
mainMenuList:setSelection(1, 1, #menuOptions)

function mainMenuList:drawCell(section, row, column, selected, x, y, width, height)
gfx.pushContext()
local text = menuOptions[column]
if selected then
gfx.setColor(gfx.kColorBlack)
Expand All @@ -181,6 +191,7 @@ local function updateMainMenu(gameDidFinish, gameDidStart)

gfx.setFont(listFont)
gfx.drawTextInRect(text, x, y+8, width, height+2, nil, "...", kTextAlignment.center)
gfx.popContext()
end
end

Expand Down Expand Up @@ -397,6 +408,7 @@ local function createChapterMenu(data)
end

function chapterList:drawCell(section, row, column, selected, x, y, width, height)
gfx.pushContext()
if selected then
gfx.setColor(gfx.kColorBlack)
gfx.fillRoundRect(x, y + chapterOffset, width, height, 4)
Expand All @@ -408,9 +420,11 @@ function chapterList:drawCell(section, row, column, selected, x, y, width, heigh

gfx.setFont(listFont)
gfx.drawTextInRect("" .. sections[row].title.. "", x + 16, y+8, width -32, height+2, nil, "...", kTextAlignment.left)
gfx.popContext()
end

function chapterList:drawSectionHeader(section, x, y, width, height)
gfx.pushContext()
if Panels.Settings.chapterMenuHeaderImage then
headerImage:drawAnchored(x + width / 2, y + 7, 0.5, 0)
else
Expand All @@ -421,6 +435,7 @@ function chapterList:drawSectionHeader(section, x, y, width, height)
gfx.drawLine(x, y + 20, x + 120, y + 20)
gfx.drawLine(x + width - 120, y + 20, x + width, y + 20)
end
gfx.popContext()
end


Expand Down
51 changes: 42 additions & 9 deletions modules/Panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ function Panels.Panel.new(data)
panel.prevPct = 0
panel.frame = createFrameFromPartialFrame(panel.frame)
panel.buttonsPressed = {}
panel.canvas = gfx.image.new(panel.frame.width, panel.frame.height, gfx.kColorBlack)
-- panel.canvas = gfx.image.new(ScreenWidth, ScreenHeight, gfx.kColorBlack)
panel.canvas = gfx.image.new( ScreenWidth, ScreenHeight, gfx.kColorClear)

if not panel.backgroundColor then panel.backgroundColor = Panels.Color.WHITE end

Expand Down Expand Up @@ -415,6 +414,11 @@ function Panels.Panel.new(data)
yPos = yPos + shake.y * (1 - p * p)
end

if layer.pixelLock then
xPos = math.floor((xPos + offset.x) / layer.pixelLock) * layer.pixelLock - offset.x + self.frame.margin
yPos = math.floor((yPos + offset.y) / layer.pixelLock) * layer.pixelLock - offset.y + self.frame.margin
end

if layer.effect then
doLayerEffect(layer, xPos, yPos)
end
Expand Down Expand Up @@ -452,8 +456,8 @@ function Panels.Panel.new(data)
img:drawFaded(xPos, yPos, layer.alpha, playdate.graphics.image.kDitherTypeBayer8x8)
else
if layer.maskImg then
local maskX = math.floor((self.parallaxDistance * pct.x - self.parallaxDistance / 2) * p) - panel.frame.margin
local maskY = math.floor((self.parallaxDistance * pct.y - self.parallaxDistance / 2) * p) - panel.frame.margin
local maskX = math.floor((self.parallaxDistance * pct.x - self.parallaxDistance / 2) * p) - panel.frame.margin + offset.x + panel.frame.x
local maskY = math.floor((self.parallaxDistance * pct.y - self.parallaxDistance / 2) * p) - panel.frame.margin + offset.y + panel.frame.y

local maskImg = gfx.image.new(ScreenWidth, ScreenHeight)
gfx.lockFocus(maskImg)
Expand Down Expand Up @@ -585,9 +589,7 @@ function Panels.Panel.new(data)
gfx.setFontFamily(Panels.Font.getFamily(layer.fontFamily))
elseif self.fontFamily then
gfx.setFontFamily(Panels.Font.getFamily(self.fontFamily))
end

if layer.font then
elseif layer.font then
gfx.setFont(Panels.Font.get(layer.font))
elseif self.font then
gfx.setFont(Panels.Font.get(self.font))
Expand Down Expand Up @@ -650,6 +652,7 @@ function Panels.Panel.new(data)
gfx.popContext()
end
layer.cachedTextImg:draw(xPos - textMarginLeft, yPos - textMarginTop)
layer.needsRedraw = false
end

function panel:drawBorder(color, bgColor)
Expand Down Expand Up @@ -728,15 +731,45 @@ function Panels.Panel.new(data)
self.advanceButton:draw()
end
end


-- function panel:getClipRect(offset)
-- local frame = self.frame
-- local posX = frame.x + offset.x
-- local posY = frame.y + offset.y
--
-- local x = math.max(posX, 0)
-- local y = math.max(posY, 0)
--
-- local width = math.min(frame.width, frame.width + posX)
-- local height = math.min(frame.height, frame.height + posY)
--
-- if width > ScreenWidth then
-- width = ScreenWidth - x
-- end
--
-- if height > ScreenHeight then
-- height = ScreenHeight - y
-- end
--
-- return {x = x, y = y, width = width, height = height}
-- end


function panel:render(offset, borderColor, bgColor)
local frame = self.frame
self.wasOnScreen = true
gfx.pushContext(self.canvas)
gfx.clear(self.backgroundColor)
gfx.clear(gfx.kColorClear)


if self.updateFunction then
self:updateFunction(offset)
end

gfx.setDrawOffset(offset.x + frame.x, offset.y + frame.y)
gfx.setClipRect(0, 0, frame.width, frame.height)
gfx.clear(self.backgroundColor)

if self.renderFunction then
self:renderFunction(offset)
Expand All @@ -750,7 +783,7 @@ function Panels.Panel.new(data)
end
self.borderImage:draw(0, 0)
end

if self.advanceButton then
self:updateAdvanceButton()
end
Expand Down
9 changes: 7 additions & 2 deletions modules/Settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ Panels.Settings = {
imageFolder = "images/",
audioFolder = "audio/",

-- project settings
defaultFont = nil,
defaultFontFamily = nil,
menuFontFamily = nil,
resetVarsOnGameOver = true,

-- panel settings
defaultFrame = {gap = 50, margin = 8},
snapToPanels = true,
sequenceTransitionDuration = 750,
defaultFont = nil,
borderWidth = 2,
borderRadius = 2,
typingSound = Panels.Audio.TypingSound.DEFAULT,
maxScrollSpeed = 8,

resetVarsOnGameOver = true,


-- menu settings
menuImage = "menuImage.png",
Expand Down

0 comments on commit 8ded0d7

Please sign in to comment.