feat: add the char page structure

Fixes #61
Fixes #62
This commit is contained in:
Kazhnuz 2021-04-23 10:21:54 +02:00
parent f65edf1924
commit e5d8a7f874
9 changed files with 247 additions and 38 deletions

View file

@ -7,6 +7,7 @@ return {
name = "spinattack",
fullname = "Spin Attack",
cost = 03,
description = "Spin to attack. Roll at the right time for more damages",
targetNumber = 1, -- 0 for targeting all ennemies
targetEnnemies = true,

View file

@ -1,6 +1,7 @@
return {
name = "spindash",
fullname = "Spin Dash",
description = "Sonic's signature attack ! Charge for more damage",
cost = 05,
targetNumber = 1, -- 0 for targeting all ennemies
targetEnnemies = true,

View file

@ -214,6 +214,9 @@ function OverWorld:drawScreenTopLayer()
self.assets.fonts["hudnbrs"]:print(game:getTimeString(), 424 - 16, 240 - self.timeBorder, "right")
if (self.currentScreen ~= nil) then
self.currentScreen:drawOverEverything()
end
end
return OverWorld

View file

@ -1,4 +1,5 @@
local BasicPage = Object:extend()
local PageParent = require "scenes.overworld.screens.mainmenu.character.pageparent"
local BasicPage = PageParent:extend()
local menu = require "game.modules.menus.fancy"
local gui = require "game.modules.gui"
@ -21,22 +22,15 @@ function BasicPage:new(view, character)
self.hpbar:setColorBackground(112/255, 0, 0)
self.ppbar:setColorForeground(0, 248/255, 248/255, 1)
self.ppbar:setColorBackground(0, 54/255, 229/255)
end
function BasicPage:getMenuWidgets()
end
function BasicPage:update(dt)
BasicPage.super.new(self, view, character, {})
end
function BasicPage:draw()
self:drawIdentity(const.X, const.Y)
self:drawHPPP(const.X, const.Y + 48)
self:drawLevel(const.X, 100)
self:drawStats(const.X, 160)
--self:drawWeakStrong(const.X, 160)
self:drawWeakStrong(const.X, 160)
end
function BasicPage:drawIdentity(x, y)
@ -63,29 +57,9 @@ function BasicPage:drawLevel(x, y)
self.view.scene.assets.fonts["small"]:draw(levelString, x + 6, y + 4, -1, "left")
end
function BasicPage:drawStats(x, y)
local statString = "ATK " .. self.character.stats.attack .. "\n"
statString = statString .. "DEF " .. self.character.stats.defense .. "\n"
local statString2 = "POW " .. self.character.stats.power .. "\n"
statString2 = statString2 .. "MND " .. self.character.stats.mind .. "\n"
local statString3 = "SPD " .. self.character.stats.speed .. "\n"
statString3 = statString3 .. "TEK " .. self.character.stats.technic
local pos1 = const.CHARPAGESIZE * (1/3)
local pos2 = const.CHARPAGESIZE * (2/3)
love.graphics.draw(self.nameBox, x, y)
self.view.scene.assets.fonts["small"]:draw(statString, x + 6, y + 4, -1, "left")
self.view.scene.assets.fonts["small"]:draw(statString2, x + 6 + pos1, y + 4, -1, "left")
self.view.scene.assets.fonts["small"]:draw(statString3, x + 6 + pos2, y + 4, -1, "left")
end
function BasicPage:drawWeakStrong(x, y)
local weakString = "Weak to: Earth, Lightning"
local strongString = "Resist To: Fire"
local weakString = "Weak to: Nothing"--"Earth, Lightning"
local strongString = "Resist To: Nothing"
love.graphics.draw(self.nameBox, x, y)
self.view.scene.assets.fonts["small"]:draw(weakString .. "\n" .. strongString, x + 6, y + 4, -1, "left")

View file

@ -6,7 +6,9 @@ local gui = require "game.modules.gui"
local const = require "scenes.overworld.screens.mainmenu.const"
local BasicPage = require "scenes.overworld.screens.mainmenu.character.basicpage"
local pageList = {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()
@ -48,18 +50,22 @@ function CharacterScreen:setPage(newPageIndex)
end
function CharacterScreen:setMenu()
local itemNumber = 1
local itemNumber = self.page:getMenuSize()
local y = const.Y2 - (16*itemNumber) + 2
menu.FancyMenu(self.scene, "menu", const.X2 - 128 - 14, y, 128, 1, false)
menu.FancyMenu(self.scene, "menu", const.X2 - 128 - 14, y, 128, itemNumber, false)
self.page:getMenuWidgets()
--menu.BaseWidget(self.scene, "equip", "Change talent", ">")
--menu.BaseWidget(self.scene, "equip", "Battle skills", ">")
--menu.BaseWidget(self.scene, "equip", "Equipement", ">")
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()
@ -67,12 +73,32 @@ function CharacterScreen:draw()
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)

View file

@ -0,0 +1,46 @@
local PageParent = Object:extend()
local menu = require "game.modules.menus.fancy"
local Widget = menu.BaseWidget:extend()
function PageParent:new(view, character, menu)
self.view = view
self.character = game.characters.list[character]
self.menu = menu or {}
end
function PageParent:update(dt)
end
function PageParent:getMenuSize()
return #self.menu + 1
end
function PageParent:getMenuWidgets()
for index, name in ipairs(self.menu) do
Widget(self, name, index)
end
end
function PageParent:menuResponses(i)
end
function PageParent:getCustomMenus()
end
function PageParent:draw()
end
function PageParent:drawOverEverything()
end
function Widget:new(page, name, num)
self.num = num
self.page = page
Widget.super.new(self, self.page.view.scene, "menu", name, ">")
end
function Widget:action()
self.page:menuResponses(self.num)
end
return PageParent

View file

@ -0,0 +1,68 @@
local PageParent = require "scenes.overworld.screens.mainmenu.character.pageparent"
local StatPage = PageParent:extend()
local menu = require "game.modules.menus.list"
local const = require "scenes.overworld.screens.mainmenu.const"
local SkillMenu = menu.ListMenu:extend()
local SkillWidget = menu.DualTextWidget:extend()
local PLAYER_MESSAGE = 240 - 24
function StatPage:new(view, character)
StatPage.super.new(self, view, character, {"See skill"})
self.message = ""
end
function StatPage:getCustomMenus()
return SkillMenu(self, self.character)
end
function StatPage:menuResponses(i)
if (#self.character.skills > 0) then
self.view.scene.menusystem:switchMenu("equip")
end
end
function StatPage:drawOverEverything()
if (not utils.string.isEmpty(self.message)) then
love.graphics.setColor(0,0,0, 0.66)
love.graphics.rectangle("fill", 0, PLAYER_MESSAGE, 424, 16)
self.view.scene.assets.fonts["small"]:setColor(1,1,1, 1)
self.view.scene.assets.fonts["small"]:draw(self.message, 424/2, PLAYER_MESSAGE - 1, -1, "center")
self.view.scene.assets.fonts["small"]:setColor(1,1,1, 1)
utils.graphics.resetColor()
end
end
function StatPage:setMessage(message)
self.message = message
end
function StatPage:removeEquip(type)
self.character:removeEquip(type)
end
function SkillMenu:new(page, character)
self.page = page
SkillMenu.super.new(self, page.view.scene, "equip", const.X, const.Y + 4, const.CHARPAGESIZE, 9, true, true)
for _, skill in ipairs(character.skills) do
SkillWidget(page, skill.name)
end
end
function SkillMenu:cancelAction()
self.scene.menusystem.menus["menu"]:getFocus()
self.page:setMessage("")
end
function SkillWidget:new(page, skill)
self.page = page
self.skillData = game.skills:getSkillData(skill)
SkillWidget.super.new(self, self.page.view.scene, "equip", self.skillData.fullname, utils.math.numberToString(self.skillData.cost, 2))
end
function SkillWidget:selectAction()
self.page:setMessage(self.skillData.description)
end
return StatPage

View file

@ -0,0 +1,87 @@
local PageParent = require "scenes.overworld.screens.mainmenu.character.pageparent"
local StatPage = PageParent:extend()
local menu = require "game.modules.menus.list"
local gui = require "game.modules.gui"
local const = require "scenes.overworld.screens.mainmenu.const"
local EquipMenu = menu.ListMenu:extend()
local EquipWidget = menu.DualTextWidget:extend()
local itemutils = require "game.utils.items"
local STATS = require "datas.stats"
function StatPage:new(view, character)
self.statBox = gui.newTextBox("assets/gui/dialogbox.png", const.CHARPAGESIZE, 40 + 32)
StatPage.super.new(self, view, character, {"Remove item"})
end
function StatPage:getCustomMenus()
return EquipMenu(self)
end
function StatPage:menuResponses(i)
self.view.scene.menusystem:switchMenu("equip")
end
function StatPage:draw()
self:drawStats(const.X, 100)
end
function StatPage:drawStats(x, y)
love.graphics.draw(self.statBox, x, y)
local char = self.character
for i, statName in ipairs(STATS.LIST) do
local xStat = x + (((i - 1) % 2) * (const.CHARPAGESIZE/2)) + 6
local yStat = y + (math.floor((i-1)/2) * 16) + 4
local middle = xStat + 10 + const.CHARPAGESIZE/4
local stat = char.stats[statName]
self.view.scene.assets.fonts["small"]:draw(STATS.SIMPLENAME[statName], xStat, yStat, const.CHARPAGESIZE, "left")
self.view.scene.assets.fonts["small"]:setColor(1, 1, 1, 0.9)
self.view.scene.assets.fonts["small"]:draw(stat, middle, yStat, -1, "center")
self.view.scene.assets.fonts["small"]:setColor(1, 1, 1, 1)
utils.graphics.resetColor()
end
end
function StatPage:removeEquip(type)
self.character:removeEquip(type)
end
function EquipMenu:new(page)
self.page = page
EquipMenu.super.new(self, page.view.scene, "equip", const.X, const.Y + 4, const.CHARPAGESIZE, 3, true, true)
EquipWidget(page, "gloves")
EquipWidget(page, "shoes")
EquipWidget(page, "accessories")
end
function EquipMenu:cancelAction()
self.scene.menusystem.menus["menu"]:getFocus()
end
function EquipWidget:new(page, type)
self.page = page
self.type = type
local label = self:getLabel()
EquipWidget.super.new(self, self.page.view.scene, "equip", label, "")
end
function EquipWidget:getLabel()
local obj = self.page.character.equip[self.type]
if (utils.string.isEmpty(obj)) then
return "No " .. self.type
end
local data = itemutils.getItemData(self.type, obj)
return data.fullname
end
function EquipWidget:action()
self.page:removeEquip(self.type)
self.label = self:getLabel()
self:redrawCanvas()
end
return StatPage

View file

@ -43,4 +43,7 @@ function MenuScreenParent:drawBackground()
end
function MenuScreenParent:drawOverEverything()
end
return MenuScreenParent