e5d8a7f874
Fixes #61 Fixes #62
120 lines
3.5 KiB
Lua
120 lines
3.5 KiB
Lua
local ParentScreen = require "scenes.overworld.screens.parent"
|
|
local CharacterScreen = ParentScreen:extend()
|
|
|
|
local menu = require "game.modules.menus.fancy"
|
|
local gui = require "game.modules.gui"
|
|
local const = require "scenes.overworld.screens.mainmenu.const"
|
|
|
|
local BasicPage = require "scenes.overworld.screens.mainmenu.character.basicpage"
|
|
local StatPage = require "scenes.overworld.screens.mainmenu.character.statpage"
|
|
local SkillPage = require "scenes.overworld.screens.mainmenu.character.skillpage"
|
|
local pageList = {BasicPage, StatPage, SkillPage}
|
|
|
|
local ReturnWidget = menu.BaseWidget:extend()
|
|
|
|
function CharacterScreen:new(scene, character)
|
|
self.character = game.characters.list[character]
|
|
self.charName = character
|
|
|
|
self.page = BasicPage(self, character)
|
|
self.pageIndex = 1
|
|
|
|
self.artwork = love.graphics.newImage("datas/gamedata/characters/" .. character .. "/artwork.png")
|
|
self.artworkOrigin = require("datas.gamedata.characters." .. character .. ".artwork")
|
|
CharacterScreen.super.new(self, scene, self.character.name)
|
|
end
|
|
|
|
function CharacterScreen:update(dt)
|
|
local keys = self.scene:getKeys(1)
|
|
if (keys["left"].isPressed) then
|
|
self:setPage(self.pageIndex - 1)
|
|
end
|
|
if (keys["right"].isPressed) then
|
|
self:setPage(self.pageIndex + 1)
|
|
end
|
|
end
|
|
|
|
function CharacterScreen:setPage(newPageIndex)
|
|
local newPageIndex = newPageIndex or 1
|
|
if (newPageIndex > #pageList) then
|
|
newPageIndex = 1
|
|
end
|
|
if (newPageIndex < 1) then
|
|
newPageIndex = #pageList
|
|
end
|
|
|
|
self.pageIndex = newPageIndex
|
|
self.page = pageList[self.pageIndex](self, self.charName)
|
|
self.scene.menusystem:reset()
|
|
self:setMenu()
|
|
end
|
|
|
|
function CharacterScreen:setMenu()
|
|
local itemNumber = self.page:getMenuSize()
|
|
local y = const.Y2 - (16*itemNumber) + 2
|
|
menu.FancyMenu(self.scene, "menu", const.X2 - 128 - 14, y, 128, itemNumber, false)
|
|
self.page:getMenuWidgets()
|
|
ReturnWidget(self.scene, self.charName)
|
|
|
|
local customMenu = self.page:getCustomMenus()
|
|
|
|
self.scene.menusystem:switchMenu("menu")
|
|
self.scene.menusystem.menus["menu"]:getFocus()
|
|
self.scene.menusystem.menus["menu"]:setCancelWidget()
|
|
self.scene.menusystem.menus["menu"].isLocked = true
|
|
if (customMenu ~= nil) then
|
|
customMenu.isLocked = true
|
|
customMenu.isVisible = true
|
|
end
|
|
end
|
|
|
|
function CharacterScreen:draw()
|
|
self.scene.assets.fonts["small"]:setLineHeight(16/18)
|
|
if (self.page ~= nil) then
|
|
self.page:draw()
|
|
end
|
|
|
|
for i = 1, #pageList, 1 do
|
|
local radius = 2
|
|
if (i == self.pageIndex) then
|
|
radius = 3
|
|
end
|
|
local x = (16*i) + 240 + 64
|
|
local y = 17
|
|
local outlineLight = 0.15
|
|
love.graphics.circle("fill", x + 8, y + 8, radius, 8)
|
|
love.graphics.setColor(outlineLight, outlineLight, outlineLight, 1)
|
|
love.graphics.circle("line", x + 8, y + 8, radius, 8)
|
|
utils.graphics.resetColor()
|
|
end
|
|
end
|
|
|
|
function CharacterScreen:drawBackground()
|
|
love.graphics.draw(self.artwork, self.artworkOrigin.x, self.artworkOrigin.y)
|
|
end
|
|
|
|
function CharacterScreen:drawOverEverything()
|
|
if (self.page ~= nil) then
|
|
self.page:drawOverEverything()
|
|
end
|
|
end
|
|
|
|
-- Widgets
|
|
|
|
function ReturnWidget:new(scene, charName)
|
|
self.charName = charName
|
|
ReturnWidget.super.new(self, scene, "menu", "Back", "")
|
|
end
|
|
|
|
function ReturnWidget:action()
|
|
for i, name in ipairs(game.characters.team) do
|
|
if (name == self.charName) then
|
|
self.widgetSelected = i
|
|
end
|
|
end
|
|
self.scene.assets:playSFX("mBack")
|
|
|
|
self.scene.screens.mainmenu["pause"](self.scene, "character", self.widgetSelected)
|
|
end
|
|
|
|
return CharacterScreen
|