Made dialog boxes

This commit is contained in:
bizcochito 2022-02-01 15:05:36 +01:00
parent b4311064f6
commit 2113917fb1
7 changed files with 134 additions and 5 deletions

View File

@ -32,7 +32,10 @@ function GameStep()
end end
if Keybind:HasPressed(Keybind.debug.reload) then if Keybind:HasPressed(Keybind.debug.reload) then
LoadLevel() --LoadLevel()
menuPage = "example"
MenuInit(menuPage)
end end
if Keybind:HasPressed(Keybind.debug.editor) then if Keybind:HasPressed(Keybind.debug.editor) then

View File

@ -52,6 +52,7 @@ end
function Keybind:Default() function Keybind:Default()
--Menu --Menu
Keybind.menu.pause= { keys = {"escape"}} Keybind.menu.pause= { keys = {"escape"}}
Keybind.menu.confirm= { keys = {"z", "space", 1}}
--Move --Move
Keybind.move.left = { keys = {"left", "a"}} Keybind.move.left = { keys = {"left", "a"}}
Keybind.move.right = { keys = {"right", "d"}} Keybind.move.right = { keys = {"right", "d"}}

View File

@ -27,9 +27,12 @@ function MenuStep(menu)
for _, element in pairs(UIElement) do for _, element in pairs(UIElement) do
if element.type == "Button" then if element.type == "Button" then
element:checkMouse(mouse_x, mouse_y) element:checkMouse(mouse_x, mouse_y)
elseif element.type == "Dialog" then
element:checkConfirm()
end end
end end
if menu == "pauseMenu" then if menu == 0 then
elseif menu == "pauseMenu" then
if PauseResume:getVariable() == true then if PauseResume:getVariable() == true then
MenuExit(menu,0) MenuExit(menu,0)
do_pause = false do_pause = false
@ -37,7 +40,13 @@ function MenuStep(menu)
love.event.quit() love.event.quit()
end end
else else
for name, dialogbox in pairs(dialogboxes) do
if name == menu then
if dialogbox.object:getVariable() then
MenuExit(dialogbox.exit[1],dialogbox.exit[2])
end
end
end
end end
end end
@ -50,6 +59,10 @@ function MenuExit(from,to)
PauseResume = nil PauseResume = nil
PauseOptions = nil PauseOptions = nil
PauseExit = nil PauseExit = nil
else
for name, dialogbox in pairs(dialogboxes) do
if name == menu then dialogbox.object = nil end
end
end end
menuPage = to or nil menuPage = to or nil
end end
@ -98,8 +111,14 @@ function MenuInit(menu)
color2 = {1,1,1} color2 = {1,1,1}
} }
) )
else
for name, dialogbox in pairs(dialogboxes) do
if name == menu then dialogbox.object = interfaceDialog:New(dialogbox.style) end
end
end end
end end
UIElement = {} UIElement = {}
require "data/scripts/ui/button" require "data/scripts/ui/button"
require "data/scripts/ui/dialog"
require "data/scripts/ui/dialogboxes"

View File

@ -52,14 +52,14 @@ end
function interfaceButton:getVariable() function interfaceButton:getVariable()
return self.target_variable return self.target_variable
end end
function AddElement(self) function AddElement(self)
table.insert(UIElement,self) table.insert(UIElement,self)
self.id = #UIElement self.id = #UIElement
end end
function interfaceButton:checkMouse(mouse_x, mouse_y) function interfaceButton:checkMouse(mouse_x, mouse_y)
if self.clicked == false if not self.clicked
and mouse_x < self.pos.x + self.size.w/2 and mouse_x < self.pos.x + self.size.w/2
and mouse_x > self.pos.x - self.size.w/2 and mouse_x > self.pos.x - self.size.w/2
and mouse_y < self.pos.y + self.size.h/2 and mouse_y < self.pos.y + self.size.h/2

View File

@ -0,0 +1,93 @@
interfaceDialog = {type = "Dialog"}
-- centered buttons
function interfaceDialog:New(style)
o = {}
o.pos = {
x = 0,
y = game.height*80/100
}
o.size = {
w = game.width,
h = game.height*20/100
}
o.values = {false,true}
o.value = 1
o.target_variable = o.values[o.value]
o.clicked = false
o.style = {
content = style.content or nil,
color = style.color or {1,1,1},
color2 = style.color2 or {0,0,0},
--color3 = style.color3 or style.color2 or {0,0,0},
alpha = style.alpha or 1,
scale = style.scale or 1,
scale_x = style.scale_x or 1,
scale_y = style.scale_y or 1,
scale_proportion = 1
}
AddElement(o)
setmetatable(o, self)
self.__index = self
return o
end
function interfaceDialog:getVariable()
return self.target_variable
end
function AddElement(self)
table.insert(UIElement,self)
self.id = #UIElement
end
function interfaceDialog:checkConfirm()
if not self.clicked then
if Keybind:HasPressed(Keybind.menu.confirm) then
self.clicked = true
self.value = self.value + 1
if self.value > #self.values then
self.value = 1
end
self.target_variable = self.values[self.value]
end
else
self.clicked = false
end
end
function interfaceDialog:Draw()
local c1, c2, c3, a = love.graphics.getColor()
love.graphics.setColor(self.style.color[1],self.style.color[2],self.style.color[3],self.style.alpha)
love.graphics.rectangle(
"fill",
self.pos.x*self.style.scale_x*self.style.scale_proportion,
self.pos.y*self.style.scale_y*self.style.scale_proportion,
self.size.w*self.style.scale_x*self.style.scale_proportion,
self.size.h*self.style.scale_y*self.style.scale_proportion)
love.graphics.setColor(self.style.color2[1],self.style.color2[2],self.style.color2[3],self.style.alpha)
love.graphics.rectangle(
"line",
self.pos.x*self.style.scale_x*self.style.scale_proportion,
self.pos.y*self.style.scale_y*self.style.scale_proportion,
self.size.w*self.style.scale_x*self.style.scale_proportion,
self.size.h*self.style.scale_y*self.style.scale_proportion)
if self.style.content ~= nil then
love.graphics.printf(self.style.content[1],self.pos.x+10,self.pos.y+(self.size.h/2),100,"left")
love.graphics.printf(self.style.content[2],self.pos.x+(self.size.w/2),self.pos.y+(self.size.h/2),100,"center")
love.graphics.printf(self.style.content[3],self.pos.x+(self.size.w)-10,self.pos.y+(self.size.h/2),100,"right")
else
love.graphics.printf("ERROR",self.pos.x+(self.size.w/2),self.pos.y+(self.size.h/2),100,"center")
end
love.graphics.setColor(c1,c2,c3,a)
end

View File

@ -0,0 +1,9 @@
dialogboxes = {
example = {
object = nil,
style = {content = {"test", "tested", "lol"}},
exit = {example, 0}
}
}

View File

@ -28,6 +28,7 @@
( ) Draw ( ) Draw
(X) REHANDLE ANIMATIONS (X) REHANDLE ANIMATIONS
(X) MAKE LIGHTING SYSTEM (X) MAKE LIGHTING SYSTEM
( ) Pixel perfect lights
( ) Player ( ) Player
(X) MASKS FUNCTIONALITY (X) MASKS FUNCTIONALITY
( ) Physics ( ) Physics
@ -36,6 +37,9 @@
(X) PHYSICS BY FRAME (X) PHYSICS BY FRAME
(X) DEACTIVATE ARROWS WHEN STUCK (X) DEACTIVATE ARROWS WHEN STUCK
( ) Dialog ( ) Dialog
(X) Object and Basics
( ) Fix font and align problems
( ) Implement picture displaying
( ) Translating framework ( ) Translating framework
( ) Debug tools ( ) Debug tools
( ) Audio and BGM ( ) Audio and BGM