Mothback/data/scripts/menu.lua

147 lines
3.2 KiB
Lua
Raw Normal View History

function MenuDraw(menu)
2022-02-03 06:08:15 +00:00
local font = love.graphics.getFont()
love.graphics.setFont(LocaleFont)
-- Set scale to 1
love.graphics.scale(0.5,0.5)
2022-02-03 10:32:39 +00:00
if menu == "pause" then
MenuDrawPauseScreen()
elseif menu == "dialog" then
MenuDrawDialog()
end
for _, element in pairs(UIElement) do
element:Draw()
end
-- Reset scale
love.graphics.scale(2,2)
2022-02-03 06:08:15 +00:00
love.graphics.setFont(font)
end
function MenuDrawPauseScreen()
-- Parameters
local pauseWidth = 640
local pauseHeight = 480
local pauseX = (game.width/2)-(pauseWidth/2)
local pauseY = (game.height/2)-(pauseHeight/2)
local mouse_x, mouse_y = love.mouse.getPosition()
-- Base items
love.graphics.setColor(0,0,0,0.3)
love.graphics.rectangle("fill", 0, 0, game.width, game.height)
love.graphics.setColor(1,1,1,1)
love.graphics.rectangle("fill", pauseX, pauseY, pauseWidth, pauseHeight)
end
function MenuDrawDialog()
end
function MenuStep(menu)
-- first get mouse
local mouse_x, mouse_y = love.mouse.getPosition()
for _, element in pairs(UIElement) do
if element.type == "Button" then
element:checkMouse(mouse_x, mouse_y)
elseif element.type == "Dialog" then
element:checkConfirm()
end
end
if menu == 0 then
elseif menu == "pause" then
MenuStepPauseScreen()
elseif menu == "dialog" then
MenuStepDialog()
end
end
function MenuStepPauseScreen()
if PauseResume:getVariable() == true then
PauseResume = nil
PauseOptions = nil
PauseExit = nil
MenuExit()
elseif PauseExit:getVariable() == true then
love.event.quit()
end
end
function MenuStepDialog()
if DialogContainer.value >= DialogContainer.target_value then
DialogContainer = nil
MenuExit()
end
end
function MenuClear()
for _, element in pairs(UIElement) do
element = nil
end
UIElement = {}
end
function MenuExit(to)
MenuClear()
local to = to or "no"
menu_type = to
end
function MenuInit(menu,parameter)
-- main menu
if menu == "pause" then
MenuInitPauseScreen()
elseif menu == "dialog" then
if parameter == nil then
parameter = DialogSequence.Example
end
MenuInitDialog(parameter)
end
end
function MenuInitDialog(parameter)
DialogContainer = interfaceDialog:New()
DialogContainer:loadSequence(parameter)
end
function MenuInitPauseScreen()
local buttonStandard = {width = 200, height = 30, separation = 10}
-- elements
PauseResume = interfaceButton:New(
game.width/2,
game.height/2-buttonStandard.height-buttonStandard.separation,
buttonStandard.width,
buttonStandard.height,
{false,true},
1,
{
text = Locale.ui.pause_screen_resume,
color = {0,0,0.5},
color2 = {1,1,1}
}
)
PauseOptions = interfaceButton:New(
game.width/2,
game.height/2,
buttonStandard.width,
buttonStandard.height,
{false,true},
1,
{
text = Locale.ui.pause_screen_options,
color = {0,0,0.5},
color2 = {1,1,1}
}
)
PauseExit = interfaceButton:New(
game.width/2,
game.height/2+buttonStandard.height+buttonStandard.separation,
buttonStandard.width,
buttonStandard.height,
{false,true},
1,
{
text = Locale.ui.pause_screen_exit,
color = {0,0,0.5},
color2 = {1,1,1}
}
)
end