feat: first try of a start menu
This commit is contained in:
parent
38a1d4b07d
commit
e221a36e74
10 changed files with 315 additions and 7 deletions
BIN
sonic-radiance.love/assets/gui/strings/exp.png
Normal file
BIN
sonic-radiance.love/assets/gui/strings/exp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 648 B |
BIN
sonic-radiance.love/assets/gui/strings/lvl.png
Normal file
BIN
sonic-radiance.love/assets/gui/strings/lvl.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
|
@ -74,12 +74,8 @@ function Player:draw()
|
|||
end
|
||||
|
||||
function Player:drawHUD(id)
|
||||
local border = 16
|
||||
self.assets.images["guiRing"]:draw(border, border)
|
||||
local ringString = utils.math.numberToString(game.loot.rings, 3)
|
||||
self.assets.fonts["hudnbrs"]:print(ringString, border + 14, border + 1)
|
||||
--love.graphics.print(id .. " test", 4, 4)
|
||||
self:drawEmblems(368, 24)
|
||||
self:drawEmblems(self.scene:getEmblemsPosition(), 24)
|
||||
end
|
||||
|
||||
function Player:drawEmblems(x, y)
|
||||
|
|
|
@ -23,7 +23,10 @@ return {
|
|||
{"m_technic", "assets/gui/emblem_technic_mask.png"},
|
||||
{"m_power", "assets/gui/emblem_power_mask.png"},
|
||||
|
||||
{"guiRing", "assets/gui/ring.png"}
|
||||
{"guiRing", "assets/gui/ring.png"},
|
||||
{"lvl", "assets/gui/strings/lvl.png"},
|
||||
{"exp", "assets/gui/strings/exp.png"},
|
||||
|
||||
},
|
||||
["fonts"] = {
|
||||
{"small", "assets/gui/fonts/PixelOperator.ttf", 16},
|
||||
|
@ -32,6 +35,7 @@ return {
|
|||
["imagefonts"] = {
|
||||
{"hudnbrs", "assets/gui/fonts/hudnumbers"},
|
||||
{"hudnbrs_small", "assets/gui/fonts/hudsmallnumbers"},
|
||||
{"SA2font", "assets/gui/fonts/SA2font"},
|
||||
},
|
||||
["sfx"] = {
|
||||
{"hit", "assets/sfx/hit.wav"},
|
||||
|
|
|
@ -27,23 +27,115 @@ local MovePlayer = Scene:extend()
|
|||
local World = require "scenes.overworld.world"
|
||||
local CharsetManager = require "scenes.overworld.charsetmanager"
|
||||
|
||||
local screens = require "scenes.overworld.screens"
|
||||
|
||||
local gui = require "game.modules.gui"
|
||||
local TweenManager = require "game.modules.tweenmanager"
|
||||
|
||||
function MovePlayer:new()
|
||||
MovePlayer.super.new(self)
|
||||
self.charsetManager = CharsetManager(self)
|
||||
self.assets:batchImport("game.modules.gui.assets")
|
||||
self.assets:batchImport("scenes.overworld.assets")
|
||||
|
||||
self.tweens = TweenManager(self)
|
||||
|
||||
World(self, "test", "map")
|
||||
self.world:setPlayerNumber(1)
|
||||
self.world:loadMap()
|
||||
|
||||
self.currentScreen = nil
|
||||
|
||||
self.backGroundOpacity = 0
|
||||
self.borderPosition = 0
|
||||
self.isPaused = false
|
||||
self.canPause = true
|
||||
|
||||
self.borders = gui.newBorder(424, 30, 8)
|
||||
self.emblemPosition = 368
|
||||
self.ringBorder = 16
|
||||
self.timeBorder = -10
|
||||
end
|
||||
|
||||
function MovePlayer:registerScreen(screen)
|
||||
if (self.currentScreen ~= nil) then
|
||||
self.currentScreen:quit()
|
||||
end
|
||||
self.currentScreen = screen
|
||||
end
|
||||
|
||||
function MovePlayer:update(dt)
|
||||
local keys = self:getKeys(1)
|
||||
self.tweens:update(dt)
|
||||
|
||||
if (self.world.isActive) then
|
||||
self.charsetManager:update(dt)
|
||||
end
|
||||
|
||||
function MovePlayer:draw()
|
||||
if (self.currentScreen ~= nil) then
|
||||
self.currentScreen:update(dt)
|
||||
end
|
||||
|
||||
if (keys["start"].isPressed and self.canPause) then
|
||||
if (not self.isPaused) then
|
||||
self:pause()
|
||||
else
|
||||
self:unpause()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function MovePlayer:pause()
|
||||
self.tweens:newTween(0,0.2, {backGroundOpacity=0.75}, "inQuad")
|
||||
self.tweens:newTween(0,0.3, {borderPosition=30}, "inOutQuad")
|
||||
self.tweens:newTween(0, 0.3, {emblemPosition=456}, "inOutQuad")
|
||||
self.tweens:newTween(0, 0.3, {ringBorder=8}, "inOutQuad")
|
||||
self.tweens:newTween(0, 0.3, {timeBorder=19}, "inOutQuad")
|
||||
self.isPaused = true
|
||||
self.world.isActive = false
|
||||
screens.mainmenu.pause(self)
|
||||
end
|
||||
|
||||
function MovePlayer:unpause()
|
||||
self.tweens:newTween(0.1, 0.2, {backGroundOpacity=0}, "inQuad")
|
||||
self.tweens:newTween(0, 0.3, {borderPosition=0}, "inOutQuad")
|
||||
self.tweens:newTween(0, 0.3, {emblemPosition=368}, "inOutQuad")
|
||||
self.tweens:newTween(0, 0.3, {ringBorder=16}, "inOutQuad")
|
||||
self.tweens:newTween(0, 0.3, {timeBorder=-20}, "inOutQuad")
|
||||
self.isPaused = false
|
||||
self.world.isActive = true
|
||||
|
||||
if (self.currentScreen ~= nil) then
|
||||
self.currentScreen:quit()
|
||||
end
|
||||
end
|
||||
|
||||
function MovePlayer:quitScreen()
|
||||
self.currentScreen = nil
|
||||
end
|
||||
|
||||
function MovePlayer:getEmblemsPosition()
|
||||
return self.emblemPosition
|
||||
end
|
||||
|
||||
function MovePlayer:draw()
|
||||
love.graphics.setColor(0, 0, 0, self.backGroundOpacity)
|
||||
love.graphics.rectangle("fill", 0, 0, 424, 240)
|
||||
utils.graphics.resetColor()
|
||||
|
||||
love.graphics.draw(self.borders, 0, self.borderPosition, 0, 1, -1)
|
||||
love.graphics.draw(self.borders, 424, 240 - self.borderPosition, 0, -1, 1)
|
||||
|
||||
self.assets.images["guiRing"]:draw(self.ringBorder, self.ringBorder)
|
||||
local ringString = utils.math.numberToString(game.loot.rings, 3)
|
||||
self.assets.fonts["hudnbrs"]:print(ringString, self.ringBorder + 14, self.ringBorder + 1)
|
||||
|
||||
self.assets.fonts["hudnbrs"]:print(game:getTimeString(), 424 - 16, 240 - self.timeBorder, "right")
|
||||
|
||||
|
||||
if (self.currentScreen ~= nil) then
|
||||
self.currentScreen:draw()
|
||||
end
|
||||
end
|
||||
|
||||
return MovePlayer
|
||||
|
|
3
sonic-radiance.love/scenes/overworld/screens/init.lua
Normal file
3
sonic-radiance.love/scenes/overworld/screens/init.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
return {
|
||||
mainmenu = require "scenes.overworld.screens.mainmenu"
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
return {
|
||||
pause = require "scenes.overworld.screens.mainmenu.pause"
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
local ParentScreen = require "scenes.overworld.screens.parent"
|
||||
local PauseScreen = ParentScreen:extend()
|
||||
|
||||
local ListBox = require "core.modules.menusystem.listbox"
|
||||
local Widget = require "core.modules.menusystem.widgets"
|
||||
|
||||
local Emblem = require "game.modules.gui.emblem"
|
||||
|
||||
local menu = require "game.modules.menus.fancy"
|
||||
local baseMenu = require "game.modules.menus.parents.menu"
|
||||
local baseWidget = require "game.modules.menus.parents.widget"
|
||||
|
||||
local CharacterWidget = baseWidget:extend()
|
||||
|
||||
--local PauseMenu =
|
||||
|
||||
function PauseScreen:new(scene)
|
||||
PauseScreen.super.new(self, scene)
|
||||
end
|
||||
|
||||
function PauseScreen:setMenu()
|
||||
menu.FancyMenu(self.scene, "main", 16, 48, 128, 8, false)
|
||||
menu.BaseWidget(self.scene, "main", "Team", ">")
|
||||
menu.BaseWidget(self.scene, "main", "Items", ">")
|
||||
--self.menuObj.BoxedWidget(self.scene, "main", "Equipments", ">")
|
||||
menu.BaseWidget(self.scene, "main", "Chao", ">")
|
||||
menu.BaseWidget(self.scene, "main", "Encylopedia", ">")
|
||||
menu.BaseWidget(self.scene, "main", "Save", ">")
|
||||
menu.BaseWidget(self.scene, "main", "Options", ">")
|
||||
menu.BaseWidget(self.scene, "main", "Exit game", ">")
|
||||
|
||||
baseMenu(self.scene, "character", 168, 40, 248, 168, 4)
|
||||
CharacterWidget(self.scene, "sonic")
|
||||
CharacterWidget(self.scene, "tails")
|
||||
CharacterWidget(self.scene, "amy")
|
||||
CharacterWidget(self.scene, "sonic")
|
||||
end
|
||||
|
||||
function PauseScreen:draw()
|
||||
self.scene.assets.fonts["SA2font"]:print("MAIN MENU", 158, 16)
|
||||
end
|
||||
|
||||
-- Hero custom widget
|
||||
--
|
||||
function CharacterWidget:new(scene, name)
|
||||
self.charName = name
|
||||
self.emblem = Emblem(game.characters.list[name], scene)
|
||||
self.font2 = scene.assets.fonts["hudnbrs_small"]
|
||||
CharacterWidget.super.new(self, scene, "character")
|
||||
end
|
||||
|
||||
function CharacterWidget:drawCanvas()
|
||||
local character = game.characters.list[self.charName]
|
||||
self.font:setFilter("shadow")
|
||||
local debut = 0
|
||||
local xDebut = 32
|
||||
self.font:draw(character.fullname, xDebut, debut, -1, "left")
|
||||
local yLvl = debut + 16
|
||||
local xLvl = xDebut
|
||||
self.scene.assets.images["lvl"]:draw(xLvl, yLvl)
|
||||
self.scene.assets.images["exp"]:draw(xLvl, yLvl + 10)
|
||||
self.font2:print(character.level, xLvl + 19, yLvl, "left")
|
||||
local expString = character.exp .. "/" .. character.exp_next
|
||||
self.font2:print(expString, xLvl + 19, yLvl + 10, "left")
|
||||
--text, x, y, limit, align
|
||||
end
|
||||
|
||||
function CharacterWidget:draw(x, y)
|
||||
self.emblem:draw(x, y+6)
|
||||
if self.canvas.texture ~= nil then
|
||||
love.graphics.draw(self.canvas.texture, x - self.ox, y - self.oy)
|
||||
end
|
||||
end
|
||||
|
||||
return PauseScreen
|
103
sonic-radiance.love/scenes/overworld/screens/menu.lua
Normal file
103
sonic-radiance.love/scenes/overworld/screens/menu.lua
Normal file
|
@ -0,0 +1,103 @@
|
|||
local ListBox = require "core.modules.menusystem.listbox"
|
||||
local Widget = require "core.modules.menusystem.widgets"
|
||||
|
||||
local menu = {}
|
||||
menu.CustomMenu = ListBox:extend()
|
||||
menu.BasicMenu = ListBox:extend()
|
||||
menu.BoxedMenu = menu.BasicMenu:extend()
|
||||
menu.BasicWidget = Widget.Text:extend()
|
||||
menu.BoxedWidget = menu.BasicWidget:extend()
|
||||
|
||||
local CONST = {}
|
||||
CONST.MENU = {}
|
||||
CONST.MENU.ITEM_HEIGHT = 17
|
||||
|
||||
local gui = require "game.modules.gui"
|
||||
|
||||
-- Custom Menu
|
||||
function menu.CustomMenu:new(scene, name, x, y, w, h, itemNumber)
|
||||
self.scene = scene
|
||||
menu.CustomMenu.super.new(self, scene.menusystem, name, x, y, w, h, itemNumber)
|
||||
end
|
||||
|
||||
-- Basic menu
|
||||
function menu.BasicMenu:new(scene, name, itemNumber, x, y, w)
|
||||
self.scene = scene
|
||||
local h = itemNumber * CONST.MENU.ITEM_HEIGHT
|
||||
menu.BasicMenu.super.new(self, scene.menusystem, name, x, y, w, h, itemNumber)
|
||||
self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png")
|
||||
self.cursorTransition = 0
|
||||
end
|
||||
|
||||
function menu.BasicMenu:update(dt)
|
||||
menu.BasicMenu.super.update(self, dt)
|
||||
|
||||
local relativecursor = self.widget.selected - self.view.firstSlot
|
||||
|
||||
local transition = self.cursorTransition - relativecursor
|
||||
|
||||
if math.abs(transition) < 0.1 then
|
||||
self.cursorTransition = relativecursor
|
||||
else
|
||||
self.cursorTransition = (self.cursorTransition) + ((relativecursor) - (self.cursorTransition)) * dt*45
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function menu.BasicMenu:drawCursor()
|
||||
local addition = 17
|
||||
local x = self.x - 1
|
||||
local y = self.y + ((self.cursorTransition) * addition) + 1
|
||||
love.graphics.draw(self.cursorTexture, x, y)
|
||||
end
|
||||
|
||||
-- Boxed menu
|
||||
function menu.BoxedMenu:new(scene, name, itemNumber, x, y, w)
|
||||
menu.BoxedMenu.super.new(self, scene, name, itemNumber, x, y, w)
|
||||
self.box = gui.newTextBox("assets/gui/dialogbox.png", self.w+16, self.h+16)
|
||||
end
|
||||
|
||||
function menu.BoxedMenu:draw()
|
||||
love.graphics.draw(self.box, self.x-8, self.y-8)
|
||||
menu.BoxedMenu.super.draw(self)
|
||||
end
|
||||
|
||||
-- Basic Widget
|
||||
function menu.BasicWidget:new(scene, menu_name, label, label2)
|
||||
local font = scene.assets.fonts["small"]
|
||||
self.scene = scene
|
||||
local widgetMenu = scene.menusystem.menus[menu_name]
|
||||
self.label2 = label2 or ""
|
||||
menu.BasicWidget.super.new(self, widgetMenu, font, label)
|
||||
end
|
||||
|
||||
function menu.BasicWidget:drawCanvas()
|
||||
local h = math.floor(self.height / 2) - (self.font:getHeight() / 2)
|
||||
love.graphics.setColor(0, 0, 0, 1)
|
||||
self.font:print(self.label, 9, h, "left")
|
||||
self.font:print(self.label2, self.width - 7, h, "right")
|
||||
utils.graphics.resetColor()
|
||||
self.font:print(self.label, 8, h, "left")
|
||||
self.font:print(self.label2, self.width - 8, h, "right")
|
||||
end
|
||||
|
||||
-- Basic Widget
|
||||
function menu.BoxedWidget:new(scene, menu_name, label, label2)
|
||||
menu.BoxedWidget.super.new(self, scene, menu_name, label, label2)
|
||||
self.box = gui.newChoiceBack(self.menu.w + 24)
|
||||
end
|
||||
|
||||
function menu.BoxedWidget:drawCanvas()
|
||||
love.graphics.draw(self.box, 0, 0)
|
||||
|
||||
h = math.floor(self.height / 2) - (self.font:getHeight() / 2) - 1
|
||||
love.graphics.setColor(0, 0, 0, .8)
|
||||
self.font:print(self.label, 17, h, "left")
|
||||
self.font:print(self.label2, self.width - 8, h, "right")
|
||||
utils.graphics.resetColor()
|
||||
self.font:print(self.label, 16, h, "left")
|
||||
self.font:print(self.label2, self.width - 9, h, "right")
|
||||
end
|
||||
|
||||
|
||||
return menu
|
32
sonic-radiance.love/scenes/overworld/screens/parent.lua
Normal file
32
sonic-radiance.love/scenes/overworld/screens/parent.lua
Normal file
|
@ -0,0 +1,32 @@
|
|||
local MenuScreenParent = Object:extend()
|
||||
|
||||
local menu = require "scenes.overworld.screens.menu"
|
||||
|
||||
function MenuScreenParent:new(scene)
|
||||
self.scene = scene
|
||||
self.menusystem = scene.menusystem
|
||||
|
||||
self.menuObj = menu
|
||||
|
||||
self:setMenu()
|
||||
self.scene:registerScreen(self)
|
||||
end
|
||||
|
||||
function MenuScreenParent:update(dt)
|
||||
|
||||
end
|
||||
|
||||
function MenuScreenParent:setMenu()
|
||||
|
||||
end
|
||||
|
||||
function MenuScreenParent:quit()
|
||||
self.scene.menusystem:reset()
|
||||
self.scene:quitScreen()
|
||||
end
|
||||
|
||||
function MenuScreenParent:draw()
|
||||
|
||||
end
|
||||
|
||||
return MenuScreenParent
|
Loading…
Reference in a new issue