Rehandled menus; reworked dialog, added dialogsequences instead of dialogboxes

This commit is contained in:
lustlion
2022-02-03 05:31:25 +01:00
parent 26fe8f2c33
commit 7595ed3b90
14 changed files with 324 additions and 185 deletions

View File

@@ -1,143 +0,0 @@
-- animationsç
-- all these are linear animations, maybe in the future make proper animations?
animation = {
cursed_book = {
attack_loop = {
path = "assets/entities/cursed_book/attack_loop",
frames = 1,
speed = 0
},
attack_transition = {
path = "assets/entities/cursed_book/attack_transition",
frames = 5,
speed = 1/16
},
flying = {
path = "assets/entities/cursed_book/flying",
frames = 11,
speed = 1/16
},
spawn = {
path = "assets/entities/cursed_book/spawn",
frames = 5,
speed = 0
}
},
particle = {
simple = {
path = "assets/entities/particle/simple",
frames = 4,
speed = 1/4
}
},
fairy = {
flying = {
path = "assets/entities/fairy/flying",
frames = 2,
speed = 1/30
}
},
decoration = {
candelabra = {
path = "assets/entities/decoration/candelabra",
frames = 8,
speed = 1/6
}
},
kupo = {
body = {
path = "assets/entities/kupo/kupo",
frames = 4,
speed = 1/8
},
bow = {
path = "assets/entities/kupo/kupo_bow",
frames = 6,
speed = 1/10
},
arrow = {
path = "assets/entities/kupo/kupo_arrow",
frames = 1,
speed = 0
}
},
moth_mask = {
idle = {
path = "assets/entities/nancy/moth_mask/idle",
frames = 4,
speed = 1/8
},
run = {
path = "assets/entities/nancy/moth_mask/run",
frames = 6,
speed = 1/8
},
fall = {
path = "assets/entities/nancy/moth_mask/fall",
frames = 3,
speed = 1/8
},
jump = {
path = "assets/entities/nancy/moth_mask/jump",
frames = 3,
speed = 1/8
}
},
nancy = {
idle = {
path = "assets/entities/nancy/idle",
frames = 4,
speed = 1/8
},
run = {
path = "assets/entities/nancy/run",
frames = 6,
speed = 1/8
},
fall = {
path = "assets/entities/nancy/fall",
frames = 3,
speed = 1/8
},
jump = {
path = "assets/entities/nancy/jump",
frames = 3,
speed = 1/8
}
}
}
-- animation loader
-- im unsure if this is too memory expensive (probably)
-- this should go elsewhere, maybe
for _, object in pairs(animation) do
for _, anim in pairs(object) do
anim.imgs = {}
for i = 1, anim.frames do
table.insert(anim.imgs,love.graphics.newImage(anim.path..tostring(i)..".png"))
end
end
end
levelProperties = {
pos = {
x = 0,
y = 0
},
-- im unsure why there's offset at all, here
offset = {
x = 0,
y = 0
}
}
tileset = {
bricks = love.graphics.newImage("assets/tileset/bricks.png"),
library = love.graphics.newImage("assets/tileset/library.png")
}
tileProperties = {
width = 16,
height = 16,
scale = 1,
}

View File

@@ -1,6 +1,5 @@
function GameStep()
if not do_pause then
SetCollisionFlags(main_Player)
if menu_type == "no" then
for _, particle in pairs(LoadedParticles) do
particle:Smart()
particle:DoPhysics()
@@ -32,10 +31,9 @@ function GameStep()
end
if Keybind:HasPressed(Keybind.debug.reload) then
--LoadLevel()
menuPage = "example"
MenuInit(menuPage)
MenuClear()
menu_type = "dialog"
MenuInit("dialog",DialogSequence.Example)
end
if Keybind:HasPressed(Keybind.debug.editor) then

View File

@@ -1,4 +1,5 @@
function LocaleLoad(ISO639)
local ISO639 = ISO639 or "ENG"
dofile("Mothback/data/locale/"..ISO639..".lua")
dofile("Mothback/data/dialog_sequences.lua")
end

143
data/scripts/menu.lua Normal file
View File

@@ -0,0 +1,143 @@
function MenuDraw(menu)
-- Set scale to 1
love.graphics.scale(0.5,0.5)
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)
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
print("WARNING -- what dialog?")
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

View File

@@ -1,124 +1,9 @@
function MenuDraw(menu)
-- Set scale to 1
love.graphics.scale(0.5,0.5)
if menu == "pauseMenu" then
-- 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)
-- Reset scale
end
for _, element in pairs(UIElement) do
element:Draw()
end
love.graphics.scale(2,2)
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 == "pauseMenu" then
if PauseResume:getVariable() == true then
MenuExit(menu,0)
do_pause = false
elseif PauseExit:getVariable() == true then
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
function MenuExit(from,to)
for _, element in pairs(UIElement) do
element = nil
end
UIElement = {}
if from == "pauseMenu" then
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
function MenuInit(menu)
local buttonStandard = {width = 200, height = 30, separation = 10}
-- main menu
if menu == "pauseMenu" then
-- 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}
}
)
else
for name, dialogbox in pairs(dialogboxes) do
if name == menu then dialogbox.object = interfaceDialog:New(dialogbox.style) end
end
end
end
UIElement = {}
function AddElement(self)
table.insert(UIElement,self)
self.id = #UIElement
end
require "data/scripts/ui/button"
require "data/scripts/ui/dialog"
require "data/scripts/ui/dialogboxes"

View File

@@ -53,18 +53,13 @@ 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 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
and mouse_y > self.pos.y - self.size.h/2 then
o.style.scale_proportion = o.style.selected.scale_proportion
self.style.scale_proportion = o.style.selected.scale_proportion
if love.mouse.isDown(1) then
self.clicked = true
self.value = self.value + 1
@@ -73,8 +68,8 @@ function interfaceButton:checkMouse(mouse_x, mouse_y)
end
self.target_variable = self.values[self.value]
end
else
o.style.scale_proportion = o.style.unselected.scale_proportion
elseif not love.mouse.isDown(1) then
self.style.scale_proportion = o.style.unselected.scale_proportion
self.clicked = false
end
end

View File

@@ -1,6 +1,5 @@
interfaceDialog = {type = "Dialog"}
-- centered buttons
-- dialog boxes
function interfaceDialog:New(style)
o = {}
@@ -14,11 +13,10 @@ function interfaceDialog:New(style)
}
o.values = {false,true}
o.value = 1
o.target_variable = o.values[o.value]
o.value = 0
o.target_value = 0
o.clicked = false
local style = {}
o.style = {
content = style.content or nil,
@@ -40,26 +38,31 @@ function interfaceDialog:New(style)
return o
end
function interfaceDialog:getVariable()
return self.target_variable
function interfaceDialog:updateContents()
if self.value < self.target_value then
self.contents = self.sequence[self.value]
if self.contents[1] == nil then self.contents[1] = "" end
if self.contents[2] == nil then self.contents[2] = "" end
if self.contents[3] == nil then self.contents[3] = "" end
end
end
function AddElement(self)
table.insert(UIElement,self)
self.id = #UIElement
function interfaceDialog:loadSequence(sequence)
self.sequence = sequence
self.value = 1
self.target_value = 1+#sequence
self:updateContents()
end
function interfaceDialog:checkConfirm()
if not self.clicked then
if Keybind:HasPressed(Keybind.menu.confirm) then
if love.mouse.isDown(1) 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]
print(self.value.." of "..self.target_value)
self:updateContents()
end
else
elseif not love.mouse.isDown(1) then
self.clicked = false
end
end
@@ -82,12 +85,13 @@ function interfaceDialog:Draw()
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")
if self.contents ~= nil then
love.graphics.printf(self.contents[1],self.pos.x+10,self.pos.y+(self.size.h/2),100,"left")
love.graphics.printf(self.contents[2],self.pos.x+(self.size.w/2),self.pos.y+(self.size.h/2),100,"center")
love.graphics.printf(self.contents[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

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