Made dialog boxes
This commit is contained in:
parent
b4311064f6
commit
2113917fb1
|
@ -32,7 +32,10 @@ function GameStep()
|
|||
end
|
||||
|
||||
if Keybind:HasPressed(Keybind.debug.reload) then
|
||||
LoadLevel()
|
||||
--LoadLevel()
|
||||
|
||||
menuPage = "example"
|
||||
MenuInit(menuPage)
|
||||
end
|
||||
|
||||
if Keybind:HasPressed(Keybind.debug.editor) then
|
||||
|
|
|
@ -52,6 +52,7 @@ end
|
|||
function Keybind:Default()
|
||||
--Menu
|
||||
Keybind.menu.pause= { keys = {"escape"}}
|
||||
Keybind.menu.confirm= { keys = {"z", "space", 1}}
|
||||
--Move
|
||||
Keybind.move.left = { keys = {"left", "a"}}
|
||||
Keybind.move.right = { keys = {"right", "d"}}
|
||||
|
|
|
@ -27,9 +27,12 @@ function MenuStep(menu)
|
|||
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 == "pauseMenu" then
|
||||
if menu == 0 then
|
||||
elseif menu == "pauseMenu" then
|
||||
if PauseResume:getVariable() == true then
|
||||
MenuExit(menu,0)
|
||||
do_pause = false
|
||||
|
@ -37,7 +40,13 @@ function MenuStep(menu)
|
|||
love.event.quit()
|
||||
end
|
||||
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
|
||||
|
||||
|
@ -50,6 +59,10 @@ function MenuExit(from,to)
|
|||
PauseResume = nil
|
||||
PauseOptions = nil
|
||||
PauseExit = nil
|
||||
else
|
||||
for name, dialogbox in pairs(dialogboxes) do
|
||||
if name == menu then dialogbox.object = nil end
|
||||
end
|
||||
end
|
||||
menuPage = to or nil
|
||||
end
|
||||
|
@ -98,8 +111,14 @@ function MenuInit(menu)
|
|||
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
|
||||
|
||||
UIElement = {}
|
||||
require "data/scripts/ui/button"
|
||||
require "data/scripts/ui/dialog"
|
||||
require "data/scripts/ui/dialogboxes"
|
||||
|
|
|
@ -52,14 +52,14 @@ end
|
|||
function interfaceButton:getVariable()
|
||||
return self.target_variable
|
||||
end
|
||||
|
||||
function AddElement(self)
|
||||
table.insert(UIElement,self)
|
||||
|
||||
self.id = #UIElement
|
||||
end
|
||||
|
||||
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_y < self.pos.y + self.size.h/2
|
||||
|
|
|
@ -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
|
|
@ -0,0 +1,9 @@
|
|||
dialogboxes = {
|
||||
|
||||
example = {
|
||||
object = nil,
|
||||
style = {content = {"test", "tested", "lol"}},
|
||||
exit = {example, 0}
|
||||
}
|
||||
|
||||
}
|
|
@ -28,6 +28,7 @@
|
|||
( ) Draw
|
||||
(X) REHANDLE ANIMATIONS
|
||||
(X) MAKE LIGHTING SYSTEM
|
||||
( ) Pixel perfect lights
|
||||
( ) Player
|
||||
(X) MASKS FUNCTIONALITY
|
||||
( ) Physics
|
||||
|
@ -36,6 +37,9 @@
|
|||
(X) PHYSICS BY FRAME
|
||||
(X) DEACTIVATE ARROWS WHEN STUCK
|
||||
( ) Dialog
|
||||
(X) Object and Basics
|
||||
( ) Fix font and align problems
|
||||
( ) Implement picture displaying
|
||||
( ) Translating framework
|
||||
( ) Debug tools
|
||||
( ) Audio and BGM
|
||||
|
|
Loading…
Reference in New Issue