Update NyoUI.lua
This commit is contained in:
189
NyoUI.lua
189
NyoUI.lua
@@ -7,7 +7,7 @@ local object = {} -- Base class for all UI elements
|
|||||||
|
|
||||||
local activeFrame
|
local activeFrame
|
||||||
local _frames = {}
|
local _frames = {}
|
||||||
local animations = {}
|
local animationQueue = {}
|
||||||
local keyModifier = {}
|
local keyModifier = {}
|
||||||
local parentTerminal = term.current()
|
local parentTerminal = term.current()
|
||||||
|
|
||||||
@@ -72,76 +72,6 @@ local function callAll(tab,...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------
|
|
||||||
--Animation System
|
|
||||||
animation.new = function(name)
|
|
||||||
local newElement = {name=name,animations={},nextWaitTimer=0,index=1,infiniteloop=false}
|
|
||||||
setmetatable(newElement, animation)
|
|
||||||
table.insert(animations, newElement)
|
|
||||||
return newElement
|
|
||||||
end
|
|
||||||
|
|
||||||
function animation:addAnimation(func)
|
|
||||||
table.insert(self.animations, {f=func,t=self.nextWaitTimer})
|
|
||||||
self.nextWaitTimer = 0
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
function animation:wait(timer)
|
|
||||||
self.nextWaitTimer = timer
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
function animation:onPlay() -- internal function, don't use it unless you know what you do!
|
|
||||||
if(self.playing)then
|
|
||||||
self.animations[self.index].f(self)
|
|
||||||
self.index = self.index+1
|
|
||||||
|
|
||||||
if(self.animations[self.index]~=nil)then
|
|
||||||
if(self.animations[self.index].t>0)then
|
|
||||||
self.timeObj = os.startTimer(self.animations[self.index].t)
|
|
||||||
else
|
|
||||||
self:onPlay()
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if(self.infiniteloop)then
|
|
||||||
self.index = 1
|
|
||||||
if(self.animations[self.index].t>0)then
|
|
||||||
self.timeObj = os.startTimer(self.animations[self.index].t)
|
|
||||||
else
|
|
||||||
self:onPlay()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function animation:play(infiniteloop)
|
|
||||||
if(infiniteloop~=nil)then self.infiniteloop=infiniteloop end
|
|
||||||
self.playing = true
|
|
||||||
if(self.animations[self.index]~=nil)then
|
|
||||||
if(self.animations[self.index].t>0)then
|
|
||||||
self.timeObj = os.startTimer(self.animations[self.index].t)
|
|
||||||
else
|
|
||||||
self:onPlay()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
function animation:cancel()
|
|
||||||
os.cancelTimer(self.timeObj)
|
|
||||||
self.playing = false
|
|
||||||
self.infiniteloop = false
|
|
||||||
self.index = 0
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
-----------
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--Object Constructors:
|
--Object Constructors:
|
||||||
--(base class for every element/object even frames)
|
--(base class for every element/object even frames)
|
||||||
function object:new()
|
function object:new()
|
||||||
@@ -236,6 +166,13 @@ function program:new()
|
|||||||
return newElement
|
return newElement
|
||||||
end
|
end
|
||||||
|
|
||||||
|
animation = object:new()
|
||||||
|
function animation:new()
|
||||||
|
local newElement = {__type = "Animation",animations={},nextWaitTimer=0,index=1,infiniteloop=false}
|
||||||
|
setmetatable(newElement, {__index = self})
|
||||||
|
return newElement
|
||||||
|
end
|
||||||
|
|
||||||
frame = object:new()
|
frame = object:new()
|
||||||
function frame:new(name,scrn,frameObj)
|
function frame:new(name,scrn,frameObj)
|
||||||
local parent = scrn~=nil and scrn or term.current()
|
local parent = scrn~=nil and scrn or term.current()
|
||||||
@@ -282,9 +219,14 @@ function object:getName()
|
|||||||
return self.name
|
return self.name
|
||||||
end
|
end
|
||||||
|
|
||||||
function object:setPosition(x,y)
|
function object:setPosition(x,y,typ)
|
||||||
self.x = tonumber(x)
|
if(typ=="r")or(typ=="relative")then
|
||||||
self.y = tonumber(y)
|
self.x = self.x+tonumber(x)
|
||||||
|
self.y = self.y+tonumber(y)
|
||||||
|
else
|
||||||
|
self.x = tonumber(x)
|
||||||
|
self.y = tonumber(y)
|
||||||
|
end
|
||||||
self.changed = true
|
self.changed = true
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@@ -364,12 +306,11 @@ function object:linkTo(obj)
|
|||||||
obj:link(self)
|
obj:link(self)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
local a = 0
|
|
||||||
function object:link(obj) -- does not work correctly needs a fix dsfgsdfgfsdg
|
function object:link(obj) -- does not work correctly needs a fix dsfgsdfgfsdg
|
||||||
if(obj.__type==self.__type)then
|
if(obj.__type==self.__type)then
|
||||||
self.links[obj.name] = obj
|
self.links[obj.name] = obj
|
||||||
end
|
end
|
||||||
a = a+1
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -629,9 +570,9 @@ function frame:setSize(width, height) -- frame size
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
function frame:setPosition(x,y) -- pos
|
function frame:setPosition(x,y,typ) -- pos
|
||||||
object.setPosition(self,x,y)
|
object.setPosition(self,x,y,typ)
|
||||||
self.fWindow.reposition(x,y)
|
self.fWindow.reposition(self.x,self.y)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -2015,8 +1956,8 @@ function program:hide()
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
function program:setPosition(x,y)
|
function program:setPosition(x,y,typ)
|
||||||
object.setPosition(self,x,y)
|
object.setPosition(self,x,y,typ)
|
||||||
self.pWindow.reposition(self.x, self.y)
|
self.pWindow.reposition(self.x, self.y)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@@ -2097,6 +2038,81 @@ function program:eventListener(event,p1,p2,p3,p4)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--------------
|
||||||
|
--Animation System
|
||||||
|
function frame:addAnimation(name)
|
||||||
|
if(self:getObject(name) == nil)then
|
||||||
|
local obj = animation:new()
|
||||||
|
obj.name = name;obj.frame=self;
|
||||||
|
self:addObject(obj)
|
||||||
|
return obj;
|
||||||
|
else
|
||||||
|
return nil, "id "..name.." already exists";
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function animation:add(func)
|
||||||
|
table.insert(self.animations, {f=func,t=self.nextWaitTimer})
|
||||||
|
self.nextWaitTimer = 0
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function animation:wait(timer)
|
||||||
|
self.nextWaitTimer = timer
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function animation:onPlay() -- internal function, don't use it unless you know what you do!
|
||||||
|
if(self.playing)then
|
||||||
|
self.animations[self.index].f(self)
|
||||||
|
self.index = self.index+1
|
||||||
|
|
||||||
|
if(self.animations[self.index]~=nil)then
|
||||||
|
if(self.animations[self.index].t>0)then
|
||||||
|
self.timeObj = os.startTimer(self.animations[self.index].t)
|
||||||
|
else
|
||||||
|
self:onPlay()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if(self.infiniteloop)then
|
||||||
|
self.index = 1
|
||||||
|
if(self.animations[self.index].t>0)then
|
||||||
|
self.timeObj = os.startTimer(self.animations[self.index].t)
|
||||||
|
else
|
||||||
|
self:onPlay()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self.playing = false
|
||||||
|
self.index = 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function animation:play(infiniteloop)
|
||||||
|
if(infiniteloop~=nil)then self.infiniteloop=infiniteloop end
|
||||||
|
self.playing = true
|
||||||
|
if(self.animations[self.index]~=nil)then
|
||||||
|
if(self.animations[self.index].t>0)then
|
||||||
|
self.timeObj = os.startTimer(self.animations[self.index].t)
|
||||||
|
else
|
||||||
|
self:onPlay()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function animation:cancel()
|
||||||
|
os.cancelTimer(self.timeObj)
|
||||||
|
self.playing = false
|
||||||
|
self.infiniteloop = false
|
||||||
|
self.index = 1
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
-----------
|
||||||
|
|
||||||
|
|
||||||
local function checkTimer(timeObject)
|
local function checkTimer(timeObject)
|
||||||
for a,b in pairs(activeFrame.objects)do
|
for a,b in pairs(activeFrame.objects)do
|
||||||
for k,v in pairs(b)do
|
for k,v in pairs(b)do
|
||||||
@@ -2109,17 +2125,16 @@ local function checkTimer(timeObject)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
if(v.__type=="Animation")and(v.playing)then
|
||||||
end
|
if(v.timeObj == timeObject)then
|
||||||
if(#animations>0)then
|
v:onPlay()
|
||||||
for k,v in pairs(animations)do
|
end
|
||||||
if(v.timeObj==timeObject)then
|
|
||||||
v:onPlay()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function handleChangedObjectsEvent()
|
local function handleChangedObjectsEvent()
|
||||||
local changed = activeFrame.changed
|
local changed = activeFrame.changed
|
||||||
for a,b in pairs(activeFrame.objects)do
|
for a,b in pairs(activeFrame.objects)do
|
||||||
|
|||||||
Reference in New Issue
Block a user