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

@ -0,0 +1,7 @@
DialogSequence = {
Example = {
{Locale.character.fairy.name,Locale.dialogue.example[1]},
{Locale.character.chaos.name,Locale.dialogue.example[2]},
{Locale.character.life.name,Locale.dialogue.example[3]}
}
}

View File

@ -5,6 +5,14 @@ Locale.ui.pause_screen_resume = "Resume"
Locale.ui.pause_screen_options = "Options"
Locale.ui.pause_screen_exit = "Exit"
Locale.entity = {}
Locale.entity.fairy = {}
Locale.entity.fairy.name = "Ozy"
Locale.character = {}
Locale.character.fairy = {}
Locale.character.fairy.name = "Ozy"
Locale.character.chaos = {}
Locale.character.chaos.name = "Aelato"
Locale.character.life = {}
Locale.character.life.name = "Olidia"
Locale.dialogue = {}
Locale.dialogue.example = {"Hello!","Duh.","Lol"}

View File

@ -6,7 +6,18 @@ Locale.ui = {}
Locale.ui.pause_screen_resume = ""
Locale.ui.pause_screen_options = ""
Locale.ui.pause_screen_exit = ""
Locale.character = {}
Locale.character.fairy = {}
Locale.character.fairy.name = ""
Locale.character.chaos = {}
Locale.character.chaos.name = ""
Locale.character.life = {}
Locale.character.life.name = ""
Locale.entity = {}
Locale.entity.fairy = {}
Locale.entity.fairy.name = ""
Locale.dialogue = {}
Locale.dialogue.example = {
"",
"",
""
}

100
data/particle.lua Normal file
View File

@ -0,0 +1,100 @@
Particle = Entity:New(x,y)
function Particle:New(x,y,particle_data)
local o = Entity:New(x,y)
o.pos = {x = x, y = y}
o.speed = particle_data.speed or 0
o.direction = particle_data.direction or o.direction
o.sprite_rotation = particle_data.sprite_rotation or o.sprite_rotation
o.sprite_offset = particle_data.sprite_offset or o.sprite_offset
o.sprite_scale = particle_data.sprite_scale or o.sprite_scale
o.sprite_tint = particle_data.sprite_tint or o.sprite_tint
o.sprite_alpha = particle_data.sprite_alpha or o.sprite_alpha
o.sprite_alpha_base = o.sprite_alpha
o.sprite_flip = particle_data.sprite_flip or o.sprite_flip
o.animation_active = particle_data.animation_active or false
o.time = 0.5
o.timer = 0
o.vel = {
x = o.speed * math.cos(o.direction),
y = o.speed * math.sin(o.direction)
}
o.speed_increase = particle_data.speed_increase or 0
if particle_data.light ~= nil then
o.lightRange = particle_data.light
local flicker = particle_data.light_flicker or nil
local color = particle_data.light_color or nil
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange,flicker,color)
end
-- animations
if particle_data.animation ~= nil then
o.body = Animation:New(particle_data.animation)
o:centerOffset(o.body)
o:getBoundingBox(o.body)
if not o.animation_active then
o.body.speed = 0
end
end
table.insert(LoadedParticles,o)
o.id = #LoadedParticles
setmetatable(o, self)
self.__index = self
return o
end
function Particle:Kill()
if self.light ~= nil then
KillLight(self.light)
end
if self.id ~= nil then
for _, e in pairs(LoadedParticles) do
if e.id > self.id then
e.id = e.id - 1
end
end
table.remove(LoadedParticles,self.id)
end
self = nil
end
function Particle:HandleAnimation()
self.timer = self.timer + current_dt
self.sprite_alpha = self.sprite_alpha_base*(self.time-self.timer)/self.time
if self.light ~= nil then
self:LightAdjust()
self.light.range = self.lightRange * self.sprite_alpha/2
end
if self.sprite_alpha < 0 then self:Kill() end
if self.body ~= nil then
self.body:Animate()
self:Draw(self.body)
end
end
function Particle:DoPhysics()
-- adjust speed
if self.speed_increase ~= 0 then
self.speed = self.speed + self.speed_increase
self.vel.x = self.speed * math.cos(self.direction)
self.vel.y = self.speed * math.sin(self.direction)
end
-- move
self:CollisionMove()
end
function Particle:Debug()
-- draw center CYAN
love.graphics.setColor(0,1,1)
love.graphics.circle("fill", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, 1)
end

View File

@ -1,6 +1,6 @@
-- enums
require "data/scripts/enums"
-- data
require "data/enums"
require "data/scripts/locale"
-- support functions
require "data/scripts/math"
require "data/scripts/hex"
@ -10,18 +10,15 @@ require "data/scripts/entity"
require "data/scripts/animation"
require "data/scripts/collision"
require "data/scripts/level"
-- data
require "data/scripts/camera"
require "data/scripts/lights"
require "data/scripts/objects"
-- UI functions
require "data/scripts/debug"
require "data/scripts/keybind"
require "data/scripts/menu"
require "data/scripts/ui"
-- game loop
require "data/scripts/game"
require "data/scripts/gameworld"
require "data/scripts/editor"
-- locale
require "data/scripts/locale"

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}
}
}

View File

@ -3,8 +3,7 @@ function love.load()
if logging then print("love: "..collectgarbage("count").." kB") end
arrow = 0
do_pause = false
menu_type = "no"
debug = false
debug_collision = false
editor_mode = false
@ -44,7 +43,7 @@ function love.load()
LoadedParticles = {}
LevelLoadTiles()
language = "ENG"
language = "HEON"
LocaleLoad(language)
main_Player = Player:New(75,50)
@ -90,13 +89,13 @@ function love.update(dt)
if do_pause then
do_pause = false
else
menuPage = "pauseMenu"
MenuInit(menuPage)
menu_type = "pause"
MenuInit(menu_type)
end
end
--MenuStep
if menuPage ~= nil then MenuStep(menuPage) end
if menu_type ~= nil then MenuStep(menu_type) end
--editor
if editor_mode then
@ -128,7 +127,7 @@ function love.draw()
GameDraw()
end
if menuPage ~= nil then MenuDraw(menuPage) end
if menu_type ~= nil then MenuDraw(menu_type) end
love.graphics.print(game.scale,10,40)
end