From baf04a055dbc66b80c29a406907a0a595ac55f00 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 27 Jun 2017 09:02:03 +0200 Subject: Moved ui elements to use new oop lib --- not/Button.lua | 29 ++++++++++------------------- not/Element.lua | 16 +++++++--------- not/Header.lua | 20 ++++++-------------- not/Selector.lua | 50 +++++++++++++++++++++----------------------------- 4 files changed, 44 insertions(+), 71 deletions(-) (limited to 'not') diff --git a/not/Button.lua b/not/Button.lua index 91aca45..a2f7a19 100644 --- a/not/Button.lua +++ b/not/Button.lua @@ -1,27 +1,18 @@ +require "not.Element" + --- `Button` -- Menu element that can be activated by user. -Button = { - parent = --[[not.Menu]]nil, - x = 0, - y = 0, - text = "", - focused = false, - sprite, - quads, - delay = 2, - parent, -} +Button = Element:extends() --- `Button` is a child of `Element`. -require "not.Element" -Button.__index = Button -setmetatable(Button, Element) +Button.text = "" +Button.focused = false +Button.sprite = --[[]]nil +Button.quads = --[[]]nil +Button.delay = 2 function Button:new (parent) - local o = setmetatable({}, self) - o.parent = parent - o.sprite, o.quads = parent:getSheet() - return o + Button.__super.new(self, parent) + self.sprite, self.quads = parent:getSheet() end function Button:setText (text) diff --git a/not/Element.lua b/not/Element.lua index e6d91da..24576e6 100644 --- a/not/Element.lua +++ b/not/Element.lua @@ -1,17 +1,15 @@ +require "not.Object" + --- `Element` -- Empty element used inside `Menu`. -Element = { - parent = --[[not.Menu]]nil, - x = 0, - y = 0 -} +Element = Object:extends() -Element.__index = Element +Element.parent = --[[not.Menu]]nil +Element.x = 0 +Element.y = 0 function Element:new (parent) - local o = setmetatable({}, self) - o.parent = parent - return o + self.parent = parent end function Element:delete () end -- deletes Element diff --git a/not/Header.lua b/not/Header.lua index a563ab2..8b2ec0d 100644 --- a/not/Header.lua +++ b/not/Header.lua @@ -1,22 +1,14 @@ +require "not.Element" + --- `Header` -- Swinging title. -Header = { - parent = --[[not.Menu]]nil, - x = 0, - y = 0, - text = "", - bounce = 2, -} +Header = Element:extends() --- `Header` is a child of `Element`. -require "not.Element" -Header.__index = Header -setmetatable(Header, Element) +Header.text = "" +Header.bounce = 2 function Header:new (parent) - local o = setmetatable({}, self) - o.parent = parent - return o + Header.__super.new(self, parent) end function Header:setText (text) diff --git a/not/Selector.lua b/not/Selector.lua index 8e03457..ef78778 100644 --- a/not/Selector.lua +++ b/not/Selector.lua @@ -1,3 +1,5 @@ +require "not.Element" + --- `Selector` -- Used in Menu for selecting various things from list. Works for each Controller set or globally. --[[ @@ -12,39 +14,29 @@ selector:new(menu) :set("global", false) -- true: single selector; false: selector for each controller set present :init() ]] -Selector = { - parent = --[[not.Menu]]nil, - x = 0, - y = 0, - width = 0, - height = 0, - margin = 0, - focused = false, - global = false, - delay = 2, - first = false, - list, - sets, - locks, - selections, - shape = "portrait", - sprite, - quads, - icons_i, - icons_q -} +Selector = Element:extends() --- `Selector` is a child of `Element`. -require "not.Element" -Selector.__index = Selector -setmetatable(Selector, Element) +Selector.width = 0 +Selector.height = 0 +Selector.margin = 0 +Selector.focused = false +Selector.global = false +Selector.delay = 2 +Selector.first = false +Selector.list = --[[]]nil +Selector.sets = --[[]]nil +Selector.locks = --[[]]nil +Selector.selections = --[[]]nil +Selector.shape = "portrait" +Selector.sprite = --[[]]nil +Selector.quads = --[[]]nil +Selector.icons_i = --[[]]nil +Selector.icons_q = --[[]]nil -- Constructor function Selector:new (parent) - local o = setmetatable({}, self) - o.parent = parent - o.sprite, o.quads = parent:getSheet() - return o + Selector.__super.new(self, parent) + self.sprite, self.quads = parent:getSheet() end -- Size of single block -- cgit v1.1