chore:move around menus sub-objects
This commit is contained in:
parent
a72dfc0711
commit
bb6cf14437
9 changed files with 56 additions and 63 deletions
|
@ -26,7 +26,7 @@ local cwd = (...):gsub('%.flowbox$', '') .. "."
|
||||||
local Menu = require(cwd .. "parent")
|
local Menu = require(cwd .. "parent")
|
||||||
local FlowBox = Menu:extend()
|
local FlowBox = Menu:extend()
|
||||||
|
|
||||||
local View2D = require(cwd .. "utils.view2D")
|
local View2D = require(cwd .. "views.view2D")
|
||||||
|
|
||||||
-- INIT FUNCTIONS
|
-- INIT FUNCTIONS
|
||||||
-- Initialize and configure the flowbox
|
-- Initialize and configure the flowbox
|
||||||
|
|
|
@ -26,20 +26,16 @@ local cwd = (...):gsub('%.grid$', '') .. "."
|
||||||
local Menu = require(cwd .. "parent")
|
local Menu = require(cwd .. "parent")
|
||||||
local GridBox = Menu:extend()
|
local GridBox = Menu:extend()
|
||||||
|
|
||||||
local menuutils = require(cwd .. "widgets.utils")
|
local View2D = require "birb.modules.menusystem.menus.views.view2D"
|
||||||
|
|
||||||
-- INIT FUNCTIONS
|
-- INIT FUNCTIONS
|
||||||
-- Initialize and configure the menu
|
-- Initialize and configure the menu
|
||||||
|
|
||||||
function GridBox:new(menusystem, name, x, y, w, h, colNumber, lineNumber)
|
function GridBox:new(menusystem, name, x, y, w, h, colNumber, lineNumber)
|
||||||
self.view = {}
|
self.view = View2D(colNumber, lineNumber)
|
||||||
self.view.slotNumber = colNumber * lineNumber
|
|
||||||
self.view.colNumber = colNumber
|
|
||||||
self.view.lineNumber = lineNumber
|
|
||||||
self.view.firstSlot = 1
|
|
||||||
GridBox.super.new(self, menusystem, name, x, y, w, h)
|
GridBox.super.new(self, menusystem, name, x, y, w, h)
|
||||||
self.h = lineNumber * self.widget.h -- On fait en sorte que la hauteur
|
self.h = lineNumber * self.widgetSize.h -- On fait en sorte que la hauteur
|
||||||
self.w = colNumber * self.widget.w -- et la largeur
|
self.w = colNumber * self.widgetSize.w -- et la largeur
|
||||||
-- soit un multiple du nombre de slot et de leur dimensions
|
-- soit un multiple du nombre de slot et de leur dimensions
|
||||||
self.cursor = {}
|
self.cursor = {}
|
||||||
self.cursor.x = 0
|
self.cursor.x = 0
|
||||||
|
@ -56,14 +52,13 @@ function GridBox:addSlot(widgetID, x, y, w, h)
|
||||||
slot.y = y
|
slot.y = y
|
||||||
slot.w = w
|
slot.w = w
|
||||||
slot.h = h
|
slot.h = h
|
||||||
slot.widgetID = widgetID
|
|
||||||
|
|
||||||
table.insert(self.slots, slot)
|
table.insert(self.slots, slot)
|
||||||
end
|
end
|
||||||
|
|
||||||
function GridBox:updateWidgetSize()
|
function GridBox:updateWidgetSize()
|
||||||
self.widget.h = math.floor( self.h / self.view.lineNumber )
|
self.widgetSize.h = math.floor( self.h / self.view.lineNumber )
|
||||||
self.widget.w = math.floor( self.w / self.view.colNumber )
|
self.widgetSize.w = math.floor( self.w / self.view.colNumber )
|
||||||
end
|
end
|
||||||
|
|
||||||
-- INFO FUNCTIONS
|
-- INFO FUNCTIONS
|
||||||
|
@ -71,19 +66,19 @@ end
|
||||||
|
|
||||||
function GridBox:getWidgetSize(id)
|
function GridBox:getWidgetSize(id)
|
||||||
local slot = self:getWidgetSlot(id)
|
local slot = self:getWidgetSlot(id)
|
||||||
if slot == 0 then
|
if (slot == 0) then
|
||||||
return 1, 1
|
return 1, 1
|
||||||
else
|
else
|
||||||
return self.widget.w * self.slots[slot].w, self.widget.h * self.slots[slot].h
|
return self.widgetSize.w * self.slots[slot].w, self.widgetSize.h * self.slots[slot].h
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function GridBox:getSlotHitbox(slot)
|
function GridBox:getSlotHitbox(slot)
|
||||||
local x, y, w, h
|
local x, y, w, h
|
||||||
x = self.slots[slot].x * self.widget.w
|
x = self.slots[slot].x * self.widgetSize.w
|
||||||
y = self.slots[slot].y * self.widget.h
|
y = self.slots[slot].y * self.widgetSize.h
|
||||||
w = self.slots[slot].w * self.widget.w
|
w = self.slots[slot].w * self.widgetSize.w
|
||||||
h = self.slots[slot].h * self.widget.h
|
h = self.slots[slot].h * self.widgetSize.h
|
||||||
|
|
||||||
return x, y, w, h
|
return x, y, w, h
|
||||||
end
|
end
|
||||||
|
@ -146,7 +141,7 @@ end
|
||||||
-- Handle the keyboard/manette functions
|
-- Handle the keyboard/manette functions
|
||||||
|
|
||||||
function GridBox:keyreleased(key, code)
|
function GridBox:keyreleased(key, code)
|
||||||
local slotID = self:getWidgetSlot(self.widget.selected)
|
local slotID = self:getWidgetSlot(self.widget:getSelected())
|
||||||
local col, line = self.cursor.x, self.cursor.y
|
local col, line = self.cursor.x, self.cursor.y
|
||||||
if key == 'left' then
|
if key == 'left' then
|
||||||
self:moveCol(-1)
|
self:moveCol(-1)
|
||||||
|
@ -164,13 +159,13 @@ function GridBox:keyreleased(key, code)
|
||||||
self:moveLine(1)
|
self:moveLine(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
if key == "A" and self.widget.selected <= #self.widget.list then
|
if key == "A" and self.widget:getSelected() <= self.widget:lenght() then
|
||||||
self.widget.list[self.widget.selected]:action("key")
|
self.widget.list[self.widget:getSelected()]:action("key")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function GridBox:moveCol(direction)
|
function GridBox:moveCol(direction)
|
||||||
local orig_x, orig_y = self:getSlotCenter(self.widget.selected)
|
local orig_x, orig_y = self:getSlotCenter(self.widget:getSelected())
|
||||||
local distance = self.w -- on met directement à la distance max possible le système
|
local distance = self.w -- on met directement à la distance max possible le système
|
||||||
local nearestWidget = 0
|
local nearestWidget = 0
|
||||||
for i,v in ipairs(self.slots) do
|
for i,v in ipairs(self.slots) do
|
||||||
|
@ -185,13 +180,13 @@ function GridBox:moveCol(direction)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if nearestWidget ~= 0 then
|
if (nearestWidget ~= 0) then
|
||||||
self.widget.selected = nearestWidget
|
self.widget:setCursor(nearestWidget)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function GridBox:moveLine(direction)
|
function GridBox:moveLine(direction)
|
||||||
local orig_x, orig_y = self:getSlotCenter(self.widget.selected)
|
local orig_x, orig_y = self:getSlotCenter(self.widget:getSelected())
|
||||||
local distance = self.h -- on met directement à la distance max possible le système
|
local distance = self.h -- on met directement à la distance max possible le système
|
||||||
local nearestWidget = 0
|
local nearestWidget = 0
|
||||||
for i,v in ipairs(self.slots) do
|
for i,v in ipairs(self.slots) do
|
||||||
|
@ -206,8 +201,8 @@ function GridBox:moveLine(direction)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if nearestWidget ~= 0 then
|
if (nearestWidget ~= 0) then
|
||||||
self.widget.selected = nearestWidget
|
self.widget:setCursor(nearestWidget)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -217,31 +212,31 @@ end
|
||||||
function GridBox:mousemoved(x, y)
|
function GridBox:mousemoved(x, y)
|
||||||
local widgetID = self:getWidgetAtPoint(x, y)
|
local widgetID = self:getWidgetAtPoint(x, y)
|
||||||
|
|
||||||
if widgetID ~= nil then
|
-- if (widgetID ~= nil) then
|
||||||
self.widget.selected = widgetID
|
-- self.widget:getSelected() = widgetID
|
||||||
self:getFocus()
|
-- self:getFocus()
|
||||||
end
|
-- end
|
||||||
|
|
||||||
if self.widget.selected < 1 then
|
-- if self.widget:getSelected() < 1 then
|
||||||
self.widget.selected = 1
|
-- self.widget:getSelected() = 1
|
||||||
end
|
-- end
|
||||||
if self.widget.selected > #self.widget.list then
|
-- if self.widget:getSelected() > self.widget:lenght() then
|
||||||
self.widget.selected = #self.widget.list
|
-- self.widget:getSelected() = self.widget:lenght()
|
||||||
end
|
-- end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function GridBox:mousepressed(x, y, button, isTouch)
|
function GridBox:mousepressed(x, y, button, isTouch)
|
||||||
local widgetID = self:getWidgetAtPoint(x, y)
|
local widgetID = self:getWidgetAtPoint(x, y)
|
||||||
|
|
||||||
if widgetID ~= nil then
|
-- if (widgetID ~= nil) then
|
||||||
self.widget.selected = widgetID
|
-- self.widget:getSelected() = widgetID
|
||||||
self:getFocus()
|
-- self:getFocus()
|
||||||
|
|
||||||
if #self.widget.list > 0 and self.widget.selected > 1 and self.widget.selected <= #self.widget.list then
|
-- if self.widget:lenght() > 0 and self.widget:getSelected() > 1 and self.widget:getSelected() <= self.widget:lenght() then
|
||||||
self.widget.list[self.widget.selected]:action("pointer")
|
-- self.widget.list[self.widget:getSelected()]:action("pointer")
|
||||||
end
|
-- end
|
||||||
end
|
-- end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- DRAW FUNCTIONS
|
-- DRAW FUNCTIONS
|
||||||
|
@ -251,9 +246,9 @@ function GridBox:draw()
|
||||||
|
|
||||||
for i,v in ipairs(self.slots) do
|
for i,v in ipairs(self.slots) do
|
||||||
if self:haveWidget(i) then
|
if self:haveWidget(i) then
|
||||||
local widgetx = self.x + (v.x * self.widget.w)
|
local widgetx = self.x + (v.x * self.widgetSize.w)
|
||||||
local widgety = self.y + (v.y * self.widget.h)
|
local widgety = self.y + (v.y * self.widgetSize.h)
|
||||||
if self.widget.selected == v.widgetID and self:haveFocus() == true then
|
if self.widget:getSelected() == v.widgetID and self:haveFocus() == true then
|
||||||
self.widget.list[v.widgetID]:drawSelected(widgetx, widgety)
|
self.widget.list[v.widgetID]:drawSelected(widgetx, widgety)
|
||||||
else
|
else
|
||||||
self.widget.list[v.widgetID]:draw(widgetx, widgety)
|
self.widget.list[v.widgetID]:draw(widgetx, widgety)
|
||||||
|
@ -264,12 +259,12 @@ end
|
||||||
|
|
||||||
function GridBox:drawCursor()
|
function GridBox:drawCursor()
|
||||||
self:updateView()
|
self:updateView()
|
||||||
if (self.widget.selected >= 1 and self.widget.selected <= #self.widget.list) then
|
if (self.widget:getSelected() >= 1 and self.widget:getSelected() <= self.widget:lenght()) then
|
||||||
local slot = self:getWidgetSlot(self.widget.selected)
|
local slot = self:getWidgetSlot(self.widget:getSelected())
|
||||||
local w, h = self:getWidgetSize(slot)
|
local w, h = self:getWidgetSize(slot)
|
||||||
local x = self.slots[slot].x * self.widget.w
|
local x = self.slots[slot].x * self.widgetSize.w
|
||||||
local y = self.slots[slot].y * self.widget.h
|
local y = self.slots[slot].y * self.widgetSize.h
|
||||||
menuutils.drawCursor(self.x + x, self.y + y, w, h)
|
self:drawGraphicalCursor(self.x + x, self.y + y, w, h)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,7 @@ local cwd = (...):gsub('%.hlistbox$', '') .. "."
|
||||||
local Menu = require(cwd .. "parent")
|
local Menu = require(cwd .. "parent")
|
||||||
local HListBox = Menu:extend()
|
local HListBox = Menu:extend()
|
||||||
|
|
||||||
local menuutils = require(cwd .. "widgets.utils")
|
local View1D = require(cwd .. "views.view1D")
|
||||||
local View1D = require(cwd .. "utils.view1D")
|
|
||||||
|
|
||||||
-- INIT FUNCTIONS
|
-- INIT FUNCTIONS
|
||||||
-- Initialize and configure functions.
|
-- Initialize and configure functions.
|
||||||
|
|
|
@ -26,8 +26,7 @@ local Menu = require(cwd .. "parent")
|
||||||
|
|
||||||
local ListBox = Menu:extend()
|
local ListBox = Menu:extend()
|
||||||
|
|
||||||
local menuutils = require(cwd .. "widgets.utils")
|
local View1D = require(cwd .. "views.view1D")
|
||||||
local View1D = require(cwd .. "utils.view1D")
|
|
||||||
|
|
||||||
-- INIT FUNCTIONS
|
-- INIT FUNCTIONS
|
||||||
-- Initialize and configure functions.
|
-- Initialize and configure functions.
|
||||||
|
|
|
@ -24,9 +24,9 @@
|
||||||
local GuiElement = require "birb.modules.menusystem.parent"
|
local GuiElement = require "birb.modules.menusystem.parent"
|
||||||
|
|
||||||
local Menu = GuiElement:extend()
|
local Menu = GuiElement:extend()
|
||||||
local MenuModel = require "birb.modules.menusystem.menus.utils.menumodel"
|
local MenuModel = require "birb.modules.menusystem.menus.model"
|
||||||
|
|
||||||
local menuUtils = require "birb.modules.menusystem.menus.widgets.utils"
|
local menuUtils = require "birb.modules.menusystem.utils"
|
||||||
-- INIT FUNCTIONS
|
-- INIT FUNCTIONS
|
||||||
-- Initialize and configure functions.
|
-- Initialize and configure functions.
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
]]
|
]]
|
||||||
local View1D = require "birb.modules.menusystem.menus.utils.menumodel"
|
local View1D = require "birb.modules.menusystem.menus.views.view1D"
|
||||||
local View2D = View1D:extend()
|
local View2D = View1D:extend()
|
||||||
|
|
||||||
function View2D:new(colNumber, lineNumber)
|
function View2D:new(colNumber, lineNumber)
|
|
@ -1,4 +1,4 @@
|
||||||
-- widgets/utils :: basic utility functions for the widgets
|
-- menusystem/utils :: basic utility functions for the gui
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Copyright © 2019 Kazhnuz
|
Copyright © 2019 Kazhnuz
|
||||||
|
@ -21,9 +21,9 @@
|
||||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local menuUtils = {}
|
local guiUtils = {}
|
||||||
|
|
||||||
function menuUtils.drawCursor(x, y, w, h)
|
function guiUtils.drawCursor(x, y, w, h)
|
||||||
love.graphics.setColor(0,0,0)
|
love.graphics.setColor(0,0,0)
|
||||||
|
|
||||||
love.graphics.rectangle("fill", x, y, 4, 8)
|
love.graphics.rectangle("fill", x, y, 4, 8)
|
||||||
|
@ -54,4 +54,4 @@ function menuUtils.drawCursor(x, y, w, h)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return menuUtils
|
return guiUtils
|
Loading…
Reference in a new issue