wip: other radiance stuff

This commit is contained in:
Kazhnuz 2022-07-27 21:57:34 +02:00
parent c3179dcf9d
commit 5178ee0020
26 changed files with 415 additions and 84 deletions

View file

@ -63,6 +63,10 @@ function TweenManager:removeNamedTween(name)
self.tweens[name] = nil self.tweens[name] = nil
end end
function TweenManager:haveTween()
return #self.tweens > 0
end
-- TIMER FUNCTIONS -- TIMER FUNCTIONS
-- Help to get info from timers -- Help to get info from timers

View file

@ -36,11 +36,9 @@ end
function DataManager:loadDatas() function DataManager:loadDatas()
self.datapacks = {} self.datapacks = {}
if (index.datapacks ~= nil) then for key, datas in pairs(index.datapacks) do
for key, datas in pairs(index.datapacks) do self.core.debug:debug("datamanager", "loading data for " .. key)
self.core.debug:debug("datamanager", "loading data for " .. key) self.datapacks[key] = DataPack(datas[1], datas[2], datas[3], datas[4], datas[5])
self.datapacks[key] = DataPack(datas[1], datas[2], datas[3], datas[4], datas[5])
end
end end
end end

View file

@ -41,10 +41,6 @@ function SceneManager:setScene(scene)
self.nextScene = scene self.nextScene = scene
end end
function SceneManager:getScene()
return self.nextScene or self.currentScene
end
function SceneManager:haveStoredScene(name) function SceneManager:haveStoredScene(name)
return (self.storage[name] ~= nil) return (self.storage[name] ~= nil)
end end
@ -94,14 +90,12 @@ function SceneManager:mousemoved(x, y, dx, dy)
self.currentScene.mouse.x, self.currentScene.mouse.x,
self.currentScene.mouse.y = x, y self.currentScene.mouse.y = x, y
self.currentScene:mousemoved(x, y, dx, dy) self.currentScene:mousemoved(x, y, dx, dy)
self.currentScene.menusystem:mousemoved(x, y, dx, dy)
end end
end end
function SceneManager:mousepressed( x, y, button, istouch ) function SceneManager:mousepressed( x, y, button, istouch )
if (self.currentScene ~= nil) then if (self.currentScene ~= nil) then
self.currentScene:mousepressed( x, y, button, istouch ) self.currentScene:mousepressed( x, y, button, istouch )
self.currentScene.menusystem:mousepressed( x, y, button, istouch )
end end
end end

View file

@ -16,6 +16,8 @@ function CanvasElement:initCanvas()
self.canvas.texture = nil self.canvas.texture = nil
self.canvas.isAnimated = false self.canvas.isAnimated = false
self.canvas.padding = 8 self.canvas.padding = 8
self.canvas.final = nil
self.canvas.dual = false
end end
function CanvasElement:updateElement(dt) function CanvasElement:updateElement(dt)
@ -30,6 +32,18 @@ function CanvasElement:redraw()
if (self.canvas.needRedraw or self.canvas.isAnimated) then if (self.canvas.needRedraw or self.canvas.isAnimated) then
self:generateTexture() self:generateTexture()
end end
if (self.canvas.dual) then
local w, h = self:getDimensions()
local canvas = love.graphics.newCanvas(w + (self.canvas.padding*2), h + (self.canvas.padding*2))
love.graphics.setCanvas(canvas)
love.graphics.draw(self.canvas.texture, 0, 0)
self:drawFinalTexture()
self.canvas.final = canvas
love.graphics.setCanvas()
end
end end
function CanvasElement:generateTexture() function CanvasElement:generateTexture()
@ -55,6 +69,10 @@ function CanvasElement:drawTexture()
end end
function CanvasElement:drawFinalTexture()
end
function CanvasElement:parseOrigin(origin, size) function CanvasElement:parseOrigin(origin, size)
if (origin == "center") then if (origin == "center") then
return size/2 return size/2
@ -67,7 +85,11 @@ end
function CanvasElement:draw() function CanvasElement:draw()
love.graphics.setColor(1, 1, 1, self.opacity) love.graphics.setColor(1, 1, 1, self.opacity)
love.graphics.draw(self.canvas.texture, self.x - self.canvas.padding,self.y - self.canvas.padding,self.r,self.sx,self.sy,self.ox,self.oy) local texture = self.canvas.texture
if (self.canvas.dual) then
texture = self.canvas.final
end
love.graphics.draw(texture, self.x - self.canvas.padding,self.y - self.canvas.padding,self.r,self.sx,self.sy,self.ox,self.oy)
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
end end

View file

@ -19,7 +19,7 @@ function GuiElement:new(name, x, y, w, h)
end end
function GuiElement:initWrapper() function GuiElement:initWrapper()
self.scene = core.scenemanager:getScene() self.scene = core.scenemanager.nextScene or core.scenemanager.currentScene
self.gui = self.scene.gui self.gui = self.scene.gui
self.assets = self.scene.assets self.assets = self.scene.assets
end end
@ -58,8 +58,8 @@ function GuiElement:setVisibility(visibility)
self.isVisible = visibility self.isVisible = visibility
end end
function GuiElement:getFocus() function GuiElement:getFocus(widgetId, page)
self.gui:setFocus(self.name) self.gui:setFocus(self.name, widgetId, page)
end end
function GuiElement:haveFocus() function GuiElement:haveFocus()
@ -72,6 +72,14 @@ function GuiElement:looseFocus()
end end
end end
function GuiElement:setSubFocus()
-- Useless for basic element
end
function GuiElement:isTransforming()
return self.tweens:haveTween()
end
-- UPDATE FUNCTIONS -- UPDATE FUNCTIONS
-- Update the menu every game update -- Update the menu every game update

View file

@ -122,8 +122,9 @@ function Gui:hideScreen(screenname)
end end
function Gui:showScreen(screenname) function Gui:showScreen(screenname, focusElement, widgetId, page, arbitraryDatas)
self.screens[screenname]:show() self.screens[screenname]:show(focusElement, widgetId, page)
self.screens[screenname]:setDatas(arbitraryDatas)
end end
-- SOUND FUNCTIONS -- SOUND FUNCTIONS
@ -151,7 +152,7 @@ function Gui:keycheck(keys)
if (haveFocus) then if (haveFocus) then
local elem = self:getFocusedElement() local elem = self:getFocusedElement()
for key,_ in pairs(keys) do for key,_ in pairs(keys) do
if keys[key].isPressed then if (keys[key].isPressed and not elem:isTransforming()) then
elem:keypressed(key) elem:keypressed(key)
end end
end end
@ -163,7 +164,10 @@ end
-- Draw the menu and its content -- Draw the menu and its content
function Gui:redraw() function Gui:redraw()
for _, element in pairs(self.elements) do for _, element in pairs(self:getVisibleElement(true)) do
element:redraw()
end
for _, element in pairs(self:getVisibleElement(false)) do
element:redraw() element:redraw()
end end
end end

View file

@ -142,7 +142,7 @@ function FlowBox:getGraphicalCursorPosition()
local col, line = self.view:getCoord(self.widget:getSelected()) local col, line = self.view:getCoord(self.widget:getSelected())
local x = (col) * h local x = (col) * h
local y = (line - beginline) * h local y = (line - beginline) * h
return self.x + x, self.y + y, w, h return x, y, w, h
end end
return FlowBox return FlowBox

View file

@ -273,7 +273,7 @@ function GridBox:drawCursor()
local w, h = self:getWidgetSize(slot) local w, h = self:getWidgetSize(slot)
local x = self.slots[slot].x * self.widgetSize.w local x = self.slots[slot].x * self.widgetSize.w
local y = self.slots[slot].y * self.widgetSize.h local y = self.slots[slot].y * self.widgetSize.h
self:drawGraphicalCursor(self.x + x, self.y + y, w, h) self:drawGraphicalCursor(x, y, w, h)
end end
end end

View file

@ -99,7 +99,7 @@ function HListBox:getGraphicalCursorPosition()
local w, h = self:getWidgetSize() local w, h = self:getWidgetSize()
local x = (self.widget:getSelected() - self.view.firstSlot) * w local x = (self.widget:getSelected() - self.view.firstSlot) * w
return self.x + x,self.y, w, h return x, 0, w, h
end end
return HListBox return HListBox

View file

@ -36,6 +36,8 @@ function ListBox:new(name, x, y, w, h, slotNumber)
ListBox.super.new(self, name, x, y, w, h) ListBox.super.new(self, name, x, y, w, h)
self.h = slotNumber * self.widgetSize.h -- On fait en sorte que la hauteur self.h = slotNumber * self.widgetSize.h -- On fait en sorte que la hauteur
-- soit un multiple du nombre de slot et de leur hauteur -- soit un multiple du nombre de slot et de leur hauteur
self.lateralFunc = nil
self.packAtEnd = false
end end
-- UPDATE FUNCTIONS -- UPDATE FUNCTIONS
@ -54,6 +56,10 @@ function ListBox:resetView()
self.view:reset() self.view:reset()
end end
function ListBox:addLateralAction(func)
self.lateralFunc = func
end
-- KEYBOARD FUNCTIONS -- KEYBOARD FUNCTIONS
-- Handle input from keyboard/controllers. -- Handle input from keyboard/controllers.
@ -69,6 +75,10 @@ function ListBox:moveByKeys(key)
self:playNavigationSound() self:playNavigationSound()
self.canvas.needRedraw = true self.canvas.needRedraw = true
end end
if (self.lateralFunc ~= nil and (key == 'left' or key == 'right')) then
self.widget:lateralAction(self.lateralFunc, key)
end
end end
-- POSITION FUNCTIONS -- POSITION FUNCTIONS
@ -82,6 +92,7 @@ end
-- draw the menu and the rest of content. -- draw the menu and the rest of content.
function ListBox:getListPart(relativeNumber) function ListBox:getListPart(relativeNumber)
if (self.packAtEnd) then relativeNumber = relativeNumber + math.max(0, self.view.slotNumber - self.widget:lenght()) end
return 0, (relativeNumber) * self.widgetSize.h, self.w, self.widgetSize.h return 0, (relativeNumber) * self.widgetSize.h, self.w, self.widgetSize.h
end end
@ -99,7 +110,7 @@ end
function ListBox:getGraphicalCursorPosition() function ListBox:getGraphicalCursorPosition()
local x, y, w, h = self:getListPart(self.widget:getSelected() - self.view.firstSlot) local x, y, w, h = self:getListPart(self.widget:getSelected() - self.view.firstSlot)
return self.x - self.ox + x,self.y + y - self.oy, w, h return self:getListPart(self.widget:getSelected() - self.view.firstSlot)
end end
return ListBox return ListBox

View file

@ -21,6 +21,7 @@ function MenuModel:new()
self.cancel = 0 self.cancel = 0
self.limit = -1 self.limit = -1
-- self:updateWidgetSize() -- self:updateWidgetSize()
self.hoverFunc = nil
end end
function MenuModel:clear() function MenuModel:clear()
@ -33,6 +34,7 @@ end
function MenuModel:addPage(pageName) function MenuModel:addPage(pageName)
local page = Page() local page = Page()
page.name = pageName
self.pages[pageName] = page self.pages[pageName] = page
self.currentPage = pageName self.currentPage = pageName
return page return page
@ -58,6 +60,7 @@ end
function MenuModel:switch(pageName) function MenuModel:switch(pageName)
if (self:pageExists(pageName)) then if (self:pageExists(pageName)) then
self.currentPage = pageName self.currentPage = pageName
self:hoverAction()
end end
end end
@ -70,6 +73,10 @@ function MenuModel:getCurrentPage()
return self:getPage(self.currentPage) return self:getPage(self.currentPage)
end end
function MenuModel:getCurrentPageName()
return self.currentPage
end
-- UPDATE/DRAW FUNCTIONS -- UPDATE/DRAW FUNCTIONS
-- All the update functions -- All the update functions
@ -91,6 +98,10 @@ end
-- ACTION FUNCTIONS -- ACTION FUNCTIONS
-- All the actions callback used by the widgets -- All the actions callback used by the widgets
function MenuModel:addHoverAction(func)
self.hoverFunc = func
end
function MenuModel:cancelAction() function MenuModel:cancelAction()
local page = self:getCurrentPage() local page = self:getCurrentPage()
page:cancelAction() page:cancelAction()
@ -106,6 +117,19 @@ function MenuModel:selectedAction()
page:selectedAction() page:selectedAction()
end end
function MenuModel:hoverAction()
local page = self:getCurrentPage()
if (self.hoverFunc ~= nil) then
page:hoverAction(self.hoverFunc)
end
end
function MenuModel:lateralAction(func, key)
local page = self:getCurrentPage()
page:lateralAction(func, key)
end
-- WIDGET FUNCTIONS -- WIDGET FUNCTIONS
-- All the functions to handle widgets -- All the functions to handle widgets
@ -167,22 +191,29 @@ end
function MenuModel:trySelectWidget(cursorid) function MenuModel:trySelectWidget(cursorid)
local page = self:getCurrentPage() local page = self:getCurrentPage()
return page:trySelectWidget(cursorid) local isSuccess = page:trySelectWidget(cursorid)
if (isSuccess) then
self:hoverAction()
end
return isSuccess
end end
function MenuModel:setCursor(cursorid) function MenuModel:setCursor(cursorid)
local page = self:getCurrentPage() local page = self:getCurrentPage()
page:setCursor(cursorid) page:setCursor(cursorid)
self:hoverAction()
end end
function MenuModel:moveCursorAbsolute(newSelected) function MenuModel:moveCursorAbsolute(newSelected)
local page = self:getCurrentPage() local page = self:getCurrentPage()
page:moveCursorAbsolute(newSelected) page:moveCursorAbsolute(newSelected)
self:hoverAction()
end end
function MenuModel:moveCursor(relative) function MenuModel:moveCursor(relative)
local page = self:getCurrentPage() local page = self:getCurrentPage()
page:moveCursor(relative) page:moveCursor(relative)
self:hoverAction()
end end
-- DRAW -- DRAW

View file

@ -84,6 +84,18 @@ function Page:selectedAction()
end end
end end
function Page:hoverAction(func)
if (self:widgetExist(self.selected)) then
func(self.widgets[self.selected])
end
end
function Page:lateralAction(func, key)
if (self:widgetExist(self.selected)) then
func(key, self.widgets[self.selected], self.selected, self.name)
end
end
-- WIDGET FUNCTIONS -- WIDGET FUNCTIONS
-- All the functions to handle widgets -- All the functions to handle widgets

View file

@ -42,6 +42,19 @@ function Menu:new(name, x, y, w, h)
self:updateWidgetSize() self:updateWidgetSize()
self:initCanvas() self:initCanvas()
self.cancelFunc = nil
self.canvas.dual = true
end
-- FUNCTIONS FUNCTIONS
-- Add functions to the menu system
function Menu:addCancelAction(func)
self.cancelFunc = func
end
function Menu:addHoverAction(func)
self.widget:addHoverAction(func)
end end
-- INTERACTION FUNCTIONS -- INTERACTION FUNCTIONS
@ -112,21 +125,38 @@ function Menu:getPage(pageName)
self.widget:getPage(pageName) self.widget:getPage(pageName)
end end
function Menu:getCurrentPageName()
return self.widget:getCurrentPageName()
end
function Menu:switch(pageName) function Menu:switch(pageName)
self.widget:switch(pageName) self.widget:switch(pageName)
self:resetView() self:resetView()
self.canvas.needRedraw = true
end end
function Menu:back() function Menu:back()
self.widget:back() self.widget:back()
self:resetView() self:resetView()
self.canvas.needRedraw = true
end
function GuiElement:setSubFocus(widgetId, pageName)
if (pageName ~= nil) then
self.widget:switch(pageName)
end
self.widget:trySelectWidget(widgetId)
end end
-- ACTION FUNCTIONS -- ACTION FUNCTIONS
-- Send actions to the widgets -- Send actions to the widgets
function Menu:cancelAction() function Menu:cancelAction()
self.widget:cancelAction() if (self.cancelFunc ~= nil) then
self.cancelFunc(self)
else
self.widget:cancelAction()
end
end end
function Menu:clear() function Menu:clear()
@ -151,9 +181,12 @@ end
function Menu:drawElement() function Menu:drawElement()
self:draw() self:draw()
end
function Menu:drawFinalTexture()
if (self:haveFocus()) then if (self:haveFocus()) then
local x, y, w, h = self:getGraphicalCursorPosition() local x, y, w, h = self:getGraphicalCursorPosition()
self:drawGraphicalCursor(x, y, w, h) self:drawGraphicalCursor(self.canvas.padding + x, self.canvas.padding + y, w, h)
end end
end end
@ -179,6 +212,7 @@ end
function Menu:addWidget(newwidget) function Menu:addWidget(newwidget)
self.widget:addWidget(newwidget) self.widget:addWidget(newwidget)
self.canvas.needRedraw = true
end end
function Menu:setCancelWidget(id) function Menu:setCancelWidget(id)

View file

@ -31,7 +31,6 @@ end
function View1D:reset() function View1D:reset()
self.firstSlot = 1 self.firstSlot = 1
print("reset")
end end
function View1D:updateFirstSlot(widgetID) function View1D:updateFirstSlot(widgetID)

View file

@ -37,6 +37,7 @@ function BaseWidget:new(menuName)
self.canvas = {} self.canvas = {}
self.canvas.texture = nil self.canvas.texture = nil
self.canvas.needRedraw = true self.canvas.needRedraw = true
self.canvas.isAnimated = false
self.order = 0 self.order = 0
self:register() self:register()
@ -45,7 +46,7 @@ function BaseWidget:new(menuName)
end end
function BaseWidget:initWrapper() function BaseWidget:initWrapper()
self.scene = core.scenemanager:getScene() self.scene = core.scenemanager.nextScene or core.scenemanager.currentScene
self.gui = self.scene.gui self.gui = self.scene.gui
self.assets = self.scene.assets self.assets = self.scene.assets
end end
@ -60,11 +61,11 @@ function BaseWidget:getMenuByName(name)
end end
function BaseWidget:getScene() function BaseWidget:getScene()
return core.scenemanager:getScene() return core.scenemanager.nextScene or core.scenemanager.currentScene
end end
function BaseWidget:getAssets() function BaseWidget:getAssets()
local scene = core.scenemanager:getScene() local scene = core.scenemanager.nextScene or core.scenemanager.currentScene
return scene.assets return scene.assets
end end
@ -74,7 +75,7 @@ function BaseWidget:register()
end end
function BaseWidget:redraw() function BaseWidget:redraw()
if (self.canvas.needRedraw) then if (self.canvas.needRedraw or self.canvas.isAnimated) then
self:generateTexture() self:generateTexture()
end end
end end

View file

@ -40,8 +40,9 @@ end
function TextWidget:addLabel(label, position) function TextWidget:addLabel(label, position)
local complexLabel = {} local complexLabel = {}
assert(label ~= nil, "Label can't be nil")
complexLabel.label = label complexLabel.label = label
complexLabel.position = position complexLabel.position = position or "left"
table.insert(self.labels, complexLabel) table.insert(self.labels, complexLabel)
end end

View file

@ -17,11 +17,14 @@ function ElementList:deleteElement(name)
self.elements[name] = nil self.elements[name] = nil
end end
function ElementList:setFocus(name) function ElementList:setFocus(name, widgetId, page)
assert(self:elementExists(name), "Element " .. name .. " doesn't exists") assert(self:elementExists(name), "Element " .. name .. " doesn't exists")
self:storeLastFocus() self:storeLastFocus()
self.focusedElement = name self.focusedElement = name
self.elements[name].isVisible = true self.elements[name].isVisible = true
if (widgetId ~= nil) then
self.elements[name]:setSubFocus(widgetId, page)
end
end end
function ElementList:removeFocus() function ElementList:removeFocus()

View file

@ -13,4 +13,8 @@ function ScreenList:deleteScreen(name)
self.screens[name] = nil self.screens[name] = nil
end end
function ScreenList:getScreen(name)
return self.screens[name]
end
return ScreenList return ScreenList

View file

@ -0,0 +1,160 @@
local GuiScreen = Object:extend()
local ElementList = require "birb.modules.gui.mixins.elements"
GuiScreen:implement(ElementList)
local TweenManager = require "birb.classes.time"
local ScreenSet = require "birb.modules.gui.screen.screenset"
local elementDataStruct = require "birb.structures.elementData"
function GuiScreen:new(name)
self:initWrapper()
self.name = name
self.isVisible = false
self.transforms = {}
self.tweens = TweenManager(self)
self:reset()
self:registerElements()
self.gui:addScreen(name, self)
self.defaultFocus = nil
end
function GuiScreen:initWrapper()
local scene = core.scenemanager.nextScene or core.scenemanager.currentScene
self.scene = scene
self.gui = scene.gui
-- Présent pour la compatibilité
self.controller = self.gui
self.assets = scene.assets
end
function GuiScreen:update(dt)
self.tweens:update(dt)
end
function GuiScreen:show(focusElement, widgetId, page)
self:showSimple(focusElement, widgetId, page)
if (self.set ~= nil) then
self.set.owner:show()
end
end
function GuiScreen:showSimple(focusElement, widgetId, page)
focusElement = focusElement or self.defaultFocus
if (not self.isVisible) then
self.isVisible = true
local delay = 0
if (self.set ~= nil) then
delay = self.set:setCurrentScreen(self.name)
end
if (self.transforms["show"] ~= nil) then
if (delay == 0) then
self:showWithSubScreen(focusElement, widgetId, page)
else
self.tweens:newFunc(delay, "focus", function () self:showWithSubScreen(focusElement, widgetId, page) end)
end
end
end
end
function GuiScreen:showWithSubScreen(focusElement, widgetId, page)
self:playTransform("show")
if (focusElement ~= nil) then
self.gui:setFocus(focusElement, widgetId, page)
end
if (self.subscreens ~= nil) then
self.subscreens:show()
end
end
function GuiScreen:setDatas(datas)
end
function GuiScreen:hide()
local time = 0
if (self.isVisible) then
if (self.transforms["hide"] ~= nil) then
time = self:playTransform("hide")
self.tweens:newFunc(time, "hide", function ()
self.isVisible = false
end)
end
if (self.subscreens ~= nil) then
self.subscreens:hideCurrent()
end
end
return time
end
function GuiScreen:addTransform(name, transform)
self.transforms[name] = transform
end
function GuiScreen:playTransform(name, delay)
return self.gui:transform(self.transforms[name], delay)
end
function GuiScreen:reset()
self:initElements()
end
function GuiScreen:registerElements()
local elementList = self:createElements()
for _, rawElement in ipairs(elementList) do
if (rawElement.is ~= nil) then
self:addElement(rawElement.name, rawElement)
rawElement.screen = self
else
local elemData = utils.table.parse(rawElement, elementDataStruct, 3)
local element = elemData.element
self:addElement(element.name, element)
if (elemData.focus == true) then
element:getFocus()
end
if (elemData.delay > 0) then
element.isVisible = false
element:newSwitch(elemData.delay, {"isVisible"})
end
if (elemData.depth ~= nil) then
element.depth = elemData.depth
end
if (elemData.keypress ~= nil) then
element:setKeyPressAction(elemData.keypress)
end
element.screen = self
end
end
end
function GuiScreen:createElements()
-- Empty function
end
function GuiScreen:setParentSet(set)
self.set = set
end
function GuiScreen:addSubscreen(screen)
self:initSubscreen()
self.subscreens:add(screen)
end
function GuiScreen:showSubscreen(screenname)
if (self.subscreens ~= nil) then
self.subscreens:show(screenname)
end
end
function GuiScreen:initSubscreen()
if (self.subscreens == nil) then
self.subscreens = ScreenSet(self)
end
end
return GuiScreen

View file

@ -0,0 +1,73 @@
-- screens/screenset :: a set of exclusive screens
-- Useful to handle a complexe menu with several screens
--[[
Copyright © 2021 Kazhnuz
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
local ScreenSet = Object:extend()
function ScreenSet:new(owner)
self.set = {}
self.defaultScreen = ""
self.currentScreen = ""
self.owner = owner
self.delay = 0
end
function ScreenSet:show(screenName)
local screenName = screenName
if (screenName == nil) then
if self.currentScreen == "" then
screenName = self.defaultScreen
else
return
end
end
if screenName ~= "" then
self.set[screenName]:showSimple()
end
end
function ScreenSet:setCurrentScreen(screenName)
screenName = screenName or self.defaultScreen
local time = self:hideCurrent() + self.delay
self.currentScreen = screenName
return time
end
function ScreenSet:hideCurrent()
local time = 0
if (self.currentScreen ~= "") then
time = self.set[self.currentScreen]:hide()
self.currentScreen = ""
end
return time
end
function ScreenSet:add(screen, setAsDefault)
self.set[screen.name] = screen
if (setAsDefault == true or self.defaultScreen == "") then
self.defaultScreen = screen.name
end
screen:setParentSet(self)
end
return ScreenSet

View file

@ -41,7 +41,7 @@ function TextMenu:new(name, font, x, y, w, slotNumber, padding, lineSize)
TextMenu.super.new(self, name, x, y, w, (self.lineHeight * slotNumber), slotNumber) TextMenu.super.new(self, name, x, y, w, (self.lineHeight * slotNumber), slotNumber)
end end
function TextMenu:addItem(text, position, func, type, additionnalItems, color) function TextMenu:addItem(text, position, func, type, additionnalItems, color, additionnalDatas)
local widget = TextMenu.baseWidgets.Base(self.name, text, position) local widget = TextMenu.baseWidgets.Base(self.name, text, position)
widget:setFunc(func) widget:setFunc(func)
widget.type = type or "select" widget.type = type or "select"
@ -53,6 +53,9 @@ function TextMenu:addItem(text, position, func, type, additionnalItems, color)
if (color ~= nil) then if (color ~= nil) then
widget:setColor(color[1], color[2], color[3]) widget:setColor(color[1], color[2], color[3])
end end
if (additionnalDatas ~= nil) then
widget.datas = additionnalDatas
end
end end
function TextMenu:generateSubmenu(pageName, label, parent, list, func, backWidget) function TextMenu:generateSubmenu(pageName, label, parent, list, func, backWidget)
@ -63,7 +66,7 @@ function TextMenu:generateSubmenu(pageName, label, parent, list, func, backWidge
end end
function TextMenu:setFont(fontName) function TextMenu:setFont(fontName)
local scene = core.scenemanager:getScene() local scene = core.scenemanager.currentScene
self.font = scene.assets:getFont(fontName) self.font = scene.assets:getFont(fontName)
end end

View file

@ -27,7 +27,6 @@ local cwd = (...):gsub('%.scenes$', '') .. "."
local Scene = Object:extend() local Scene = Object:extend()
local Assets = require(cwd .. "assets") local Assets = require(cwd .. "assets")
local MenuSystem = require(cwd .. "menusystem")
local Gui = require (cwd .. "gui") local Gui = require (cwd .. "gui")
-- INIT FUNCTIONS -- INIT FUNCTIONS
@ -38,7 +37,6 @@ function Scene:new()
self.mouse.x, self.mouse.y = core.screen:getMousePosition() self.mouse.x, self.mouse.y = core.screen:getMousePosition()
self.assets = Assets() self.assets = Assets()
self.menusystem = MenuSystem(self)
self.sources = core.input:getSources() self.sources = core.input:getSources()
self.gui = Gui(self) self.gui = Gui(self)
@ -71,9 +69,7 @@ function Scene:updateScene(dt)
self:updateStart(dt) self:updateStart(dt)
self:setKeys() self:setKeys()
self.assets:update(dt) self.assets:update(dt)
self:updateMenus(dt) self:updateGUI(dt)
self:updateDialog(dt)
self.gui:update(dt)
self:updateWorld(dt) self:updateWorld(dt)
self:update(dt) self:update(dt)
self:updateEnd(dt) self:updateEnd(dt)
@ -97,18 +93,11 @@ function Scene:updateWorld(dt)
end end
end end
function Scene:updateDialog(dt) function Scene:updateGUI(dt)
if (self.dialog ~= nil) then if (self.gui ~= nil) then
self.dialog:update(dt) self.gui:update(dt)
end if (core.screen:isActive()) then
end
function Scene:updateMenus(dt)
if (self.menusystem ~= nil) then
self.menusystem:update(dt)
if (core.screen:isActive() and (self.dialog == nil)) then
self.gui:keycheck(self:getKeys(1)) self.gui:keycheck(self:getKeys(1))
self.menusystem:keycheck()
end end
end end
end end
@ -158,8 +147,6 @@ function Scene:drawScene()
self:drawWorld() self:drawWorld()
self:draw() self:draw()
self.gui:drawBottom() self.gui:drawBottom()
self:drawMenus()
self:drawDialog()
self:drawEnd() self:drawEnd()
core.screen:drawTransition() core.screen:drawTransition()
self.gui:drawTop() self.gui:drawTop()
@ -188,18 +175,6 @@ function Scene:drawWorld(dt)
end end
end end
function Scene:drawDialog(dt)
if (self.dialog ~= nil) then
self.dialog:draw()
end
end
function Scene:drawMenus()
if (self.menusystem ~= nil) then
self.menusystem:draw()
end
end
-- INPUT FUNCTIONS -- INPUT FUNCTIONS
-- Handle inputs from keyboard/controllers -- Handle inputs from keyboard/controllers
@ -209,10 +184,8 @@ function Scene:setKeys()
if (self.inputLockedTimer <= 0 ) then if (self.inputLockedTimer <= 0 ) then
self.inputLocked = false self.inputLocked = false
end end
self.menusystem.keys = self:getKeys(1)
else else
self.sources = core.input.sources self.sources = core.input.sources
self.menusystem.keys = self:getKeys(1)
end end
end end

View file

@ -111,8 +111,4 @@ function BaseActor:drawEnd()
end end
function BaseActor:drawHUD(id, height, width)
end
return BaseActor return BaseActor

View file

@ -134,7 +134,7 @@ end
function Hitbox3D:checkCollisionAtPoint(dx, dy, dz, filter) function Hitbox3D:checkCollisionAtPoint(dx, dy, dz, filter)
self:updatePosition() self:updatePosition()
local dx, dy = self.ox + dx, self.oy + dy, self.oz + dz local dx, dy, dz = self.ox + dx, self.oy + dy, self.oz + dz
local x, y, z, cols, colNumber = self.world:checkCollisionAtPoint(self, dx, dy, dz, filter) local x, y, z, cols, colNumber = self.world:checkCollisionAtPoint(self, dx, dy, dz, filter)
local newx, newy, newz = self:getNewOwnerPosition(x, y, z) local newx, newy, newz = self:getNewOwnerPosition(x, y, z)

View file

@ -214,7 +214,6 @@ function CameraSystem:detachView(id)
local unscale = 1 / view.scale local unscale = 1 / view.scale
love.graphics.scale(unscale, unscale) love.graphics.scale(unscale, unscale)
self:drawHUD(id)
love.graphics.pop() love.graphics.pop()
end end
@ -387,15 +386,4 @@ function CameraSystem:followAllActors(id)
end end
end end
-- DRAW FUNCTIONS
-- Basic callback to draw stuff
function CameraSystem:drawHUD(id)
local view = self:getView(id)
local viewx, viewy, vieww, viewh = self:getOnScreenViewCoordinate(id)
view.target:drawHUD(id, vieww, viewh)
end
return CameraSystem return CameraSystem

View file

@ -64,6 +64,18 @@ function Math.either(bool, val1, val2)
end end
end end
function Math.wrap(val, min, max)
while (val < min) do
local diff = ((min-1) - val)
val = max - diff
end
while (val > max) do
local diff = ((max+1) - val)
val = min + diff
end
return val
end
-- VECTOR/DIRECTION functions -- VECTOR/DIRECTION functions
-- Easy-to-use function to handle point and motion -- Easy-to-use function to handle point and motion