I finally updated this thing
I need to keep a consistant record. I have small updates that exist everywhere sigh.
This commit is contained in:
parent
76fd457833
commit
277cd5c553
@ -1,15 +0,0 @@
|
||||
function gui:Clickable()
|
||||
local x,y,w,h=love.graphics.getScissor()
|
||||
local mx=love.mouse.getX()
|
||||
local my=love.mouse.getY()
|
||||
if _GuiPro.HasStencel then
|
||||
local obj=_GuiPro.StencelHolder
|
||||
if self:isDescendant(obj) then
|
||||
return math.sqrt((mx-obj.x)^2+(my-obj.y)^2)<=(obj.offset.size.x or 0)
|
||||
end
|
||||
end
|
||||
if not(x) then
|
||||
return true
|
||||
end
|
||||
return not(mx>x+w or mx<x or my>y+h or my<y)
|
||||
end
|
||||
@ -1,5 +0,0 @@
|
||||
function DrawThings(items)
|
||||
for i=1,#items do
|
||||
items[i]:draw()
|
||||
end
|
||||
end
|
||||
@ -1,85 +1,200 @@
|
||||
local buttonConv = {"l","r","m","x1","x2"} -- For the old stuff
|
||||
function gui:OnClicked(func)
|
||||
table.insert(self.funcs,func)
|
||||
if not self.clickEvnt then
|
||||
self.clickEvnt = true
|
||||
self._connClicked = multi:newConnection()
|
||||
self._connClicked(func)
|
||||
multi:newThread(self.Name.."_Updater",function()
|
||||
while true do
|
||||
thread.hold(function() return self.Active or self.Destroyed end)
|
||||
if love.mouse.isDown(1) and self:canPress() then
|
||||
self._connClicked:Fire("1",self,love.mouse.getX()-self.x,love.mouse.getY()-self.y)
|
||||
end
|
||||
if love.mouse.isDown(2) and self:canPress() then
|
||||
self._connClicked:Fire("r",self,love.mouse.getX()-self.x,love.mouse.getY()-self.y)
|
||||
end
|
||||
if love.mouse.isDown(3) and self:canPress() then
|
||||
self._connClicked:Fire("m",self,love.mouse.getX()-self.x,love.mouse.getY()-self.y)
|
||||
end
|
||||
if love.mouse.isDown(4) and self:canPress() then
|
||||
self._connClicked:Fire("x1",self,love.mouse.getX()-self.x,love.mouse.getY()-self.y)
|
||||
end
|
||||
if love.mouse.isDown(5) and self:canPress() then
|
||||
self._connClicked:Fire("x2",self,love.mouse.getX()-self.x,love.mouse.getY()-self.y)
|
||||
end
|
||||
if self.Destroyed then
|
||||
thread.kill()
|
||||
end
|
||||
end
|
||||
end)
|
||||
else
|
||||
self._connClicked(func)
|
||||
end
|
||||
end
|
||||
function gui:OnPressed(func)
|
||||
multi.OnMousePressed(function(x,y,b)
|
||||
if self:canPress() then
|
||||
func(buttonConv[b],self,x,y)
|
||||
end
|
||||
end)
|
||||
end
|
||||
function gui:OnPressedOuter(func)
|
||||
multi.OnMousePressed(function(x,y,b)
|
||||
if not(self:canPress()) then
|
||||
func(buttonConv[b],self)
|
||||
end
|
||||
end,nil,1)
|
||||
end
|
||||
function gui:OnReleased(func)
|
||||
table.insert(self.funcs2,func)
|
||||
multi.OnMouseReleased(function(x,y,b)
|
||||
if self:canPress() then
|
||||
func(buttonConv[b],self,x,y)
|
||||
end
|
||||
end)
|
||||
end
|
||||
function gui:OnEnter(func)
|
||||
table.insert(self.funcs3,func)
|
||||
end
|
||||
function gui:OnExit(func)
|
||||
table.insert(self.funcs4,func)
|
||||
function gui:OnReleasedOuter(func)
|
||||
multi.OnMouseReleased(function(x,y,b)
|
||||
if not(self:canPress()) then
|
||||
func(buttonConv[b],self)
|
||||
end
|
||||
end,nil,1)
|
||||
end
|
||||
function gui:OnUpdate(func)
|
||||
table.insert(self.funcs5,func)
|
||||
end
|
||||
function gui:OnDragStart(func)
|
||||
table.insert(self.func8,func)
|
||||
end
|
||||
function gui:OnDragging(func)
|
||||
table.insert(self.func6,func)
|
||||
end
|
||||
function gui:OnDragEnd(func)
|
||||
table.insert(self.func7,func)
|
||||
end
|
||||
function gui:WhileHovering(func)
|
||||
table.insert(self.func9,func)
|
||||
if not self.updateEvnt then
|
||||
self._connUpdate = multi:newConnection()
|
||||
self._connUpdate(func)
|
||||
self.updateEvnt = true
|
||||
multi:newThread(self.Name.."_Updater",function()
|
||||
while true do
|
||||
thread.hold(function() return self.Active end)
|
||||
self._connUpdate:Fire(self)
|
||||
end
|
||||
end)
|
||||
else
|
||||
self._connUpdate(func)
|
||||
end
|
||||
end
|
||||
function gui:OnMouseMoved(func)
|
||||
table.insert(self.func10,func)
|
||||
multi.OnMouseMoved(function(x,y,dx,dy)
|
||||
if self:canPress() then
|
||||
func(self,x-self.x,y-self.y,dx,dy)
|
||||
end
|
||||
end,nil,1)
|
||||
end
|
||||
function gui:getChildren()
|
||||
return self.Children
|
||||
gui.WhileHovering=gui.OnMouseMoved -- To keep older features working
|
||||
local mbenter = multi:newConnection()
|
||||
function gui:OnMouseEnter(func)
|
||||
self.HE=false
|
||||
mbenter(func)
|
||||
self:OnMouseMoved(function()
|
||||
if self.HE == false then
|
||||
self.HE=true
|
||||
self._HE = true
|
||||
mbenter:Fire(self)
|
||||
end
|
||||
end)
|
||||
end
|
||||
function gui:LClicked()
|
||||
return self.lclicked
|
||||
end
|
||||
function gui:RClicked()
|
||||
return self.rclicked
|
||||
end
|
||||
function gui:MClicked()
|
||||
return self.mclicked
|
||||
end
|
||||
function gui:Clicked()
|
||||
return (self.lclicked or self.rclicked)
|
||||
end
|
||||
function gui:Hovering()
|
||||
return self.hovering
|
||||
end
|
||||
function gui:FreeConnections()
|
||||
self.funcs={function(b,self) if b=="l" then self.LRE=true end end,function(b,self) if b=="r" then self.RRE=true end end,function(b,self) if b=="m" then self.MRE=true end end}
|
||||
self.funcs2={function(b,self) if b=="l" then self.LRE=false end end,function(b,self) if b=="r" then self.RRE=false end end,function(b,self) if b=="m" then self.MRE=false end end}
|
||||
self.funcs3={function(self) self.HE=true end}
|
||||
self.funcs4={function(self) self.HE=false end}
|
||||
self.funcs5={function(self) self.x=(self.Parent.width*self.scale.pos.x)+self.offset.pos.x+self.Parent.x self.y=(self.Parent.height*self.scale.pos.y)+self.offset.pos.y+self.Parent.y self.width=(self.Parent.width*self.scale.size.x)+self.offset.size.x self.height=(self.Parent.height*self.scale.size.y)+self.offset.size.y end}
|
||||
end
|
||||
function gui:LClick()
|
||||
for i=1,#self.funcs do
|
||||
self.funcs[i]("l",self)
|
||||
function gui:OnMouseExit(func)
|
||||
if not self.exitEvnt then
|
||||
self._connExit = multi:newConnection()
|
||||
self._connExit(func)
|
||||
self.exitEvnt = true
|
||||
self.HE=false
|
||||
multi:newThread(self.Name.."_OnExit",function()
|
||||
while true do
|
||||
thread.hold(function() return self.HE or self.Destroyed end)
|
||||
if not(self:canPress()) then
|
||||
self.HE=false
|
||||
self._connExit:Fire(self)
|
||||
end
|
||||
if self.Destroyed then
|
||||
thread.kill()
|
||||
end
|
||||
end
|
||||
end)
|
||||
else
|
||||
self._connExit(func)
|
||||
end
|
||||
end
|
||||
function gui:RClick()
|
||||
for i=1,#self.funcs do
|
||||
self.funcs[i]("r",self)
|
||||
--[[
|
||||
x=(love.mouse.getX()-self.x)
|
||||
y=(love.mouse.getY()-self.y)
|
||||
self:Move(x,y)
|
||||
]]
|
||||
function gui:OnMouseWheelMoved(func)
|
||||
multi.OnMouseWheelMoved(function(...)
|
||||
if self:canPress() then
|
||||
func(self,...)
|
||||
end
|
||||
end)
|
||||
end
|
||||
function gui:enableDragging(bool)
|
||||
self.draggable = bool
|
||||
if self.dragEvnt then
|
||||
return
|
||||
end
|
||||
self.dragEvnt = true
|
||||
self._connDragStart = multi:newConnection()
|
||||
self._connDragging = multi:newConnection()
|
||||
self._connDragEnd = multi:newConnection()
|
||||
self.hasDrag = false
|
||||
local startX
|
||||
local startY
|
||||
self:OnPressed(function(b,self,x,y)
|
||||
if b~=self.dragbut or not(self.draggable) then return end
|
||||
self._connDragStart:Fire(self)
|
||||
self.hasDrag = true
|
||||
startX = x
|
||||
startY = y
|
||||
end)
|
||||
multi.OnMouseMoved(function(x,y,dx,dy)
|
||||
if self.hasDrag and self.draggable then
|
||||
self:Move(dx,dy)
|
||||
self._connDragging:Fire(self)
|
||||
end
|
||||
end)
|
||||
multi.OnMouseReleased(function(x,y,b)
|
||||
if buttonConv[b]~=self.dragbut or not(self.draggable) or not(self.hasDrag) then return end
|
||||
self.hasDrag = false
|
||||
startX = nil
|
||||
startY = nil
|
||||
self._connDragEnd:Fire(self)
|
||||
end)
|
||||
end
|
||||
function gui:OnDragStart(func)
|
||||
if not self.dragEvnt then
|
||||
self:enableDragging(true)
|
||||
self._connDragStart(func)
|
||||
else
|
||||
self._connDragStart(func)
|
||||
end
|
||||
end
|
||||
function gui:MClick()
|
||||
for i=1,#self.funcs do
|
||||
self.funcs[i]("m",self)
|
||||
function gui:OnDragging(func)
|
||||
if not self.dragEvnt then
|
||||
self:enableDragging(true)
|
||||
self._connDragging(func)
|
||||
else
|
||||
self._connDragging(func)
|
||||
end
|
||||
end
|
||||
function gui:LRelease()
|
||||
for i=1,#self.funcs2 do
|
||||
self.funcs2[i]("l",self)
|
||||
function gui:OnDragEnd(func)
|
||||
if not self.dragEvnt then
|
||||
self:enableDragging(true)
|
||||
self._connDragEnd(func)
|
||||
else
|
||||
self._connDragEnd(func)
|
||||
end
|
||||
end
|
||||
function gui:RRelease()
|
||||
for i=1,#self.funcs2 do
|
||||
self.funcs2[i]("r",self)
|
||||
end
|
||||
end
|
||||
function gui:MRelease()
|
||||
for i=1,#self.funcs2 do
|
||||
self.funcs2[i]("m",self)
|
||||
end
|
||||
function gui:OnHotKey(key,func)
|
||||
local tab=key:split("+")
|
||||
multi.OnKeyPressed(function()
|
||||
for i=1,#tab do
|
||||
if not(love.keyboard.isDown(tab[i])) then
|
||||
return
|
||||
end
|
||||
end
|
||||
func(self)
|
||||
end)
|
||||
end
|
||||
gui.addHotKey=gui.OnHotKey
|
||||
gui.setHotKey=gui.OnHotKey
|
||||
@ -1,46 +0,0 @@
|
||||
function UpdateThings(items)
|
||||
for i=#items,1,-1 do
|
||||
if items[i]:LClicked() then
|
||||
for g=1,#items[i].funcs do
|
||||
items[i].funcs[g]("l",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
elseif items[i]:RClicked() then
|
||||
for g=1,#items[i].funcs do
|
||||
items[i].funcs[g]("r",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
elseif items[i]:MClicked() then
|
||||
for g=1,#items[i].funcs do
|
||||
items[i].funcs[g]("m",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
end
|
||||
if not(items[i]:LClicked()) and items[i].LRE then
|
||||
for g=1,#items[i].funcs2 do
|
||||
items[i].funcs2[g]("l",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
elseif not(items[i]:RClicked()) and items[i].RRE then
|
||||
for g=1,#items[i].funcs2 do
|
||||
items[i].funcs2[g]("r",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
elseif not(items[i]:MClicked()) and items[i].MRE then
|
||||
for g=1,#items[i].funcs2 do
|
||||
items[i].funcs2[g]("m",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
end
|
||||
if items[i]:Hovering() and items[i].HE==false then
|
||||
for g=1,#items[i].funcs3 do
|
||||
items[i].funcs3[g](items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
elseif not(items[i]:Hovering()) and items[i].HE==true then
|
||||
for g=1,#items[i].funcs4 do
|
||||
items[i].funcs4[g](items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
elseif items[i]:Hovering() then
|
||||
for g=1,#items[i].func9 do
|
||||
items[i].func9[g](items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
end
|
||||
for g=1,#items[i].funcs5 do
|
||||
items[i].funcs5[g](items[i])
|
||||
end
|
||||
end
|
||||
end
|
||||
72
GuiManager/Core/canPress.int
Normal file
72
GuiManager/Core/canPress.int
Normal file
@ -0,0 +1,72 @@
|
||||
function gui:getParents()
|
||||
local c,me = {}, self.Parent
|
||||
while me.Parent~=nil do
|
||||
c[#c+1]=me
|
||||
me = me.Parent
|
||||
end
|
||||
return c
|
||||
end
|
||||
function gui:eventable()
|
||||
if self.important then
|
||||
return true
|
||||
end
|
||||
if _GuiPro.Hierarchy then
|
||||
if _GuiPro.TopHovered~=nil then
|
||||
return self:isDescendant(_GuiPro.TopHovered) or _GuiPro.TopHovered==self
|
||||
else
|
||||
return true
|
||||
end
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
function gui:parentVisible()
|
||||
local c = self:getParents()
|
||||
for i=#c,1,-1 do
|
||||
if not c[i].Visible then return false end
|
||||
end
|
||||
return true
|
||||
end
|
||||
function gui:isBeingCovering()
|
||||
return false
|
||||
-- if self.allowOverlapping then return false end
|
||||
-- local ref = self.FrameRef or gui
|
||||
-- local x,y = love.mouse.getX(),love.mouse.getY()
|
||||
-- for i = 1,#_GuiPro.Frames do
|
||||
-- if _GuiPro.Frames[i]~=ref then
|
||||
-- if (ref.depth or 0)<(_GuiPro.Frames[i].depth or math.huge) then
|
||||
-- local pos = (x > self.x and x < self.x+self.width and y > self.y and y < self.y+self.height) and (x > _GuiPro.Frames[i].x and x < _GuiPro.Frames[i].x+_GuiPro.Frames[i].width and y > _GuiPro.Frames[i].y and y < _GuiPro.Frames[i].y+_GuiPro.Frames[i].height) and (x > self.x and x < self.x+self.width and y > self.y and y < self.y+self.height )
|
||||
-- if not pos then return true end
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
function gui:Clickable()
|
||||
local x,y,w,h=love.graphics.getScissor()
|
||||
local mx=love.mouse.getX()
|
||||
local my=love.mouse.getY()
|
||||
if _GuiPro. HasStencel then
|
||||
local obj=_GuiPro.StencelHolder
|
||||
if self:isDescendant(obj) then
|
||||
return math.sqrt((mx-obj.x)^2+(my-obj.y)^2)<=(obj.offset.size.x or 0)
|
||||
end
|
||||
end
|
||||
if not(x) then
|
||||
return true
|
||||
end
|
||||
return not(mx>x+w or mx<x or my>y+h or my<y)
|
||||
end
|
||||
function gui:canPress()
|
||||
local ref = self
|
||||
if self.ClipReference then ref = self.ClipReference end
|
||||
if self.Visible==true and self:parentVisible() and not(self:isBeingCovering()) then
|
||||
local x,y = love.mouse.getX(),love.mouse.getY()
|
||||
if (x > ref.x and x < ref.x+ref.width and y > ref.y and y < ref.y+ref.height) and (x > self.x and x < self.x+self.width and y > self.y and y < self.y+self.height and self:Clickable() and (self:eventable() or self:touchable())) then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
@ -1,14 +0,0 @@
|
||||
function gui:eventable()
|
||||
if self.important then
|
||||
return true
|
||||
end
|
||||
if _GuiPro.Hierarchy then
|
||||
if _GuiPro.TopHovered~=nil then
|
||||
return self:isDescendant(_GuiPro.TopHovered) or _GuiPro.TopHovered==self
|
||||
else
|
||||
return true
|
||||
end
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
@ -1,3 +1,6 @@
|
||||
_GuiPro.Frames = {}
|
||||
_GuiPro.Type = "Window"
|
||||
_GuiPro.depth = 0
|
||||
function gui.enableAutoWindowScaling(b)
|
||||
_GuiPro.DPI_ENABLED=b or true
|
||||
_defaultfont=love.graphics.newFont(12*love.window.getPixelScale())
|
||||
@ -15,6 +18,9 @@ function filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
end
|
||||
return x,y,w,h,sx,sy,sw,sh
|
||||
end
|
||||
function gui:getChildren()
|
||||
return self.Children
|
||||
end
|
||||
function gui:newBase(tp,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
_GuiPro.count=_GuiPro.count+1
|
||||
local c = {}
|
||||
@ -24,10 +30,20 @@ function gui:newBase(tp,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
else
|
||||
c.Parent=self
|
||||
end
|
||||
if tp:match("Frame") then
|
||||
_GuiPro.Frames[#_GuiPro.Frames+1] = c
|
||||
end
|
||||
if self.Type and self.Type:match("Frame") then
|
||||
c.FrameRef = self
|
||||
else
|
||||
c.FrameRef = self.FrameRef
|
||||
end
|
||||
c.segments=nil
|
||||
c.ry=nil
|
||||
c.rx=nil
|
||||
c.DPI=1
|
||||
c.isLeaf = true
|
||||
c.Parent.isLeaf = false
|
||||
if _GuiPro.DPI_ENABLED then
|
||||
c.DPI=love.window.getPixelScale()
|
||||
x, y, w, h=c.DPI*x,c.DPI*y,c.DPI*w,c.DPI*h
|
||||
@ -52,7 +68,6 @@ function gui:newBase(tp,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
c.mclicked=false
|
||||
c.clicked=false
|
||||
c.Visibility=1
|
||||
c.ClipDescendants=false
|
||||
c.TextWrap=true
|
||||
c.scale={}
|
||||
c.scale.size={}
|
||||
@ -74,66 +89,23 @@ function gui:newBase(tp,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
c.RRE=false
|
||||
c.MRE=false
|
||||
c.Color = {255, 255, 255}
|
||||
function c:setRoundness(rx,ry,segments)
|
||||
self.segments=segments
|
||||
self.ry=ry
|
||||
self.rx=rx
|
||||
end
|
||||
function c.stfunc()
|
||||
love.graphics.rectangle("fill", c.x, c.y, c.width, c.height,c.rx,c.ry,c.segments)
|
||||
end
|
||||
function c:hasRoundness()
|
||||
return (self.ry or self.rx)
|
||||
end
|
||||
c.funcs={function(b,self)
|
||||
if b=="l" then
|
||||
self.LRE=true
|
||||
end
|
||||
end,
|
||||
function(b,self)
|
||||
if b=="r" then
|
||||
self.RRE=true
|
||||
end
|
||||
end,
|
||||
function(b,self)
|
||||
if b=="m" then
|
||||
self.MRE=true
|
||||
end
|
||||
end}
|
||||
c.funcs2={function(b,self)
|
||||
if b=="l" then
|
||||
self.LRE=false
|
||||
end
|
||||
end,
|
||||
function(b,self)
|
||||
if b=="r" then
|
||||
self.RRE=false
|
||||
end
|
||||
end,
|
||||
function(b,self)
|
||||
if b=="m" then
|
||||
self.MRE=false
|
||||
end
|
||||
end}
|
||||
c.HE=false
|
||||
c.funcs3={function(self)
|
||||
self.HE=true
|
||||
end}
|
||||
c.funcs4={function(self)
|
||||
self.HE=false
|
||||
end}
|
||||
c.funcs5={}
|
||||
function c:setRoundness(rx,ry,segments)
|
||||
self.segments=segments
|
||||
self.ry=ry
|
||||
self.rx=rx
|
||||
end
|
||||
function c.stfunc()
|
||||
love.graphics.rectangle("fill", c.x, c.y, c.width, c.height,c.rx,c.ry,c.segments)
|
||||
end
|
||||
function c:hasRoundness()
|
||||
return (self.ry or self.rx)
|
||||
end
|
||||
c.tid={}
|
||||
c.touchcount=0
|
||||
c.x=(c.Parent.width*c.scale.pos.x)+c.offset.pos.x+c.Parent.x
|
||||
c.y=(c.Parent.height*c.scale.pos.y)+c.offset.pos.y+c.Parent.y
|
||||
c.width=(c.Parent.width*c.scale.size.x)+c.offset.size.x
|
||||
c.height=(c.Parent.height*c.scale.size.y)+c.offset.size.y
|
||||
c.func6={}
|
||||
c.func7={function() _GuiPro.DragItem={} end}
|
||||
c.func8={function(self) _GuiPro.DragItem=self end}
|
||||
c.func9={}
|
||||
c.func10={}
|
||||
function c:ImageRule()
|
||||
if self.Image then
|
||||
local sx=self.width/self.ImageWidth
|
||||
@ -190,55 +162,6 @@ function gui:newBase(tp,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
end
|
||||
return self
|
||||
end
|
||||
c:WhileHovering(function(self)
|
||||
self.omx=self.nmx
|
||||
self.omy=self.nmy
|
||||
self.nmx=love.mouse.getX()
|
||||
self.nmy=love.mouse.getY()
|
||||
if self.omx~=self.nmx or self.omy~=self.nmy then
|
||||
for i=1,#self.func10 do
|
||||
if self and self.nmx and self.nmy and self.omx and self.omy then
|
||||
self.func10[i](self,self.nmx,self.nmy,self.omx,self.omy)
|
||||
end
|
||||
end
|
||||
end
|
||||
if self.WasBeingDragged==true and love.mouse.isDown(self.dragbut or "m")==false and self.Type~="TextImageButtonFrameDrag" then
|
||||
for i=1,#self.func7 do
|
||||
self.func7[i](self,(love.mouse.getX())-self.width/2,(love.mouse.getY())-self.height/2)
|
||||
end
|
||||
end
|
||||
if _GuiPro.hasDrag==false and love.mouse.isDown(self.dragbut or "m") then
|
||||
for i=1,#self.func8 do
|
||||
self.func8[i](self,(love.mouse.getX())-self.width/2,(love.mouse.getY())-self.height/2)
|
||||
end
|
||||
end
|
||||
if self.IsBeingDragged==true then
|
||||
_GuiPro.hasDrag=true
|
||||
self.WasBeingDragged=true
|
||||
elseif self.WasBeingDragged==true and self.IsBeingDragged==false then
|
||||
self.WasBeingDragged=false
|
||||
_GuiPro.hasDrag=false
|
||||
end
|
||||
if self.Draggable==true and love.mouse.isDown(self.dragbut or "m") and _GuiPro.hasDrag==false then
|
||||
for i=1,#self.func6 do
|
||||
self.func6[i](self,(love.mouse.getX())-self.width/2,(love.mouse.getY())-self.height/2)
|
||||
end
|
||||
_GuiPro.hasDrag=true
|
||||
if self.FormFactor:lower()=="circle" or self.FormFactor:lower()=="c" or self.FormFactor:lower()=="cir" then
|
||||
self.IsBeingDragged=true
|
||||
x=(love.mouse.getX()-self.x)
|
||||
y=(love.mouse.getY()-self.y)
|
||||
self:Move(x,y)
|
||||
elseif self.FormFactor:lower()=="rectangle" or self.FormFactor:lower()=="r" or self.FormFactor:lower()=="rect" then
|
||||
self.IsBeingDragged=true
|
||||
x=(love.mouse.getX()-self.x)-self.width/2
|
||||
y=(love.mouse.getY()-self.y)-self.height/2
|
||||
self:Move(x,y)
|
||||
end
|
||||
else
|
||||
self.IsBeingDragged=false
|
||||
end
|
||||
end)
|
||||
table.insert(c.Parent.Children,c)
|
||||
return c
|
||||
end
|
||||
@ -26,7 +26,7 @@ function gui:touchable(t)
|
||||
end
|
||||
self.id=-1
|
||||
end
|
||||
multi:newTask(function() -- A bit of post-loading haha
|
||||
--multi:newTask(function() -- A bit of post-loading haha
|
||||
gui.touchpressed=multi:newConnection()
|
||||
gui.touchreleased=multi:newConnection()
|
||||
gui.touchmoved=multi:newConnection()
|
||||
@ -83,7 +83,7 @@ multi:newTask(function() -- A bit of post-loading haha
|
||||
end
|
||||
end
|
||||
end)
|
||||
end)
|
||||
--end)
|
||||
-- now that that is done lets set up some more post loading checks
|
||||
_GuiPro.int=multi:newProcess()
|
||||
_GuiPro.int:Start()
|
||||
|
||||
0
GuiManager/Drawing/canvas.int
Normal file
0
GuiManager/Drawing/canvas.int
Normal file
@ -71,7 +71,7 @@ function gui:drawC()
|
||||
love.graphics.setStencilTest("notequal",0)
|
||||
end
|
||||
love.graphics.circle("fill",x,y,r,s)
|
||||
love.graphics.setColor(self.BorderColor[1], self.BorderColor[2], self.BorderColor[3],self.Visibility)
|
||||
love.graphics.setColor(self.BorderColor[1], self.BorderColor[2], self.BorderColor[3],(self.BorderVisibility or 1))
|
||||
for b=0,self.BorderSize-1 do
|
||||
love.graphics.circle("line",x,y,r+b,s)
|
||||
end
|
||||
|
||||
@ -3,7 +3,18 @@ function gui:drawR()
|
||||
_GuiPro.DragItem={}
|
||||
_GuiPro.hasDrag=false
|
||||
end
|
||||
if self.hidden then
|
||||
self.x=(self.Parent.width*self.scale.pos.x)+self.offset.pos.x+self.Parent.x
|
||||
self.y=(self.Parent.height*self.scale.pos.y)+self.offset.pos.y+self.Parent.y
|
||||
self.width=(self.Parent.width*self.scale.size.x)+self.offset.size.x
|
||||
self.height=(self.Parent.height*self.scale.size.y)+self.offset.size.y
|
||||
self.VIS = false
|
||||
end
|
||||
if self.Visible==true and self.VIS==true then
|
||||
self.x=(self.Parent.width*self.scale.pos.x)+self.offset.pos.x+self.Parent.x
|
||||
self.y=(self.Parent.height*self.scale.pos.y)+self.offset.pos.y+self.Parent.y
|
||||
self.width=(self.Parent.width*self.scale.size.x)+self.offset.size.x
|
||||
self.height=(self.Parent.height*self.scale.size.y)+self.offset.size.y
|
||||
local b=true
|
||||
for i,v in pairs(_GuiPro.Clips) do
|
||||
if self:isDescendant(v)==true then
|
||||
@ -14,112 +25,43 @@ function gui:drawR()
|
||||
love.graphics.setStencilTest()
|
||||
love.graphics.setScissor()
|
||||
end
|
||||
self.x=(self.Parent.width*self.scale.pos.x)+self.offset.pos.x+self.Parent.x
|
||||
self.y=(self.Parent.height*self.scale.pos.y)+self.offset.pos.y+self.Parent.y
|
||||
self.width=(self.Parent.width*self.scale.size.x)+self.offset.size.x
|
||||
self.height=(self.Parent.height*self.scale.size.y)+self.offset.size.y
|
||||
if self.DrawRulesB then
|
||||
for dr=1,#self.DrawRulesB do
|
||||
self.DrawRulesB[dr](self)
|
||||
end
|
||||
end
|
||||
if (love.mouse.getX() > self.x and love.mouse.getX() < self.x+self.width and love.mouse.getY() > self.y and love.mouse.getY() < self.y+self.height and self:Clickable() and self:eventable()) or self:touchable("r") and self.Active==true then
|
||||
self.hovering=true
|
||||
if love.mouse.isDown("l") or self:touchable("r") and _GuiPro.hasDrag==false then
|
||||
if string.find(self.Type, "Button") then
|
||||
love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility)
|
||||
else
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility)
|
||||
end
|
||||
self.lclicked=true
|
||||
elseif love.mouse.isDown("r") or self:touchable("r") and _GuiPro.hasDrag==false then
|
||||
if string.find(self.Type, "Button") then
|
||||
love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility)
|
||||
else
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility)
|
||||
end
|
||||
self.rclicked=true
|
||||
elseif love.mouse.isDown("m") or self:touchable("r") and _GuiPro.hasDrag==false then
|
||||
if string.find(self.Type, "Button") then
|
||||
love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility)
|
||||
else
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility)
|
||||
end
|
||||
self.mclicked=true
|
||||
else
|
||||
if string.find(self.Type, "Button") or self:touchable("r") and _GuiPro.hasDrag==false then
|
||||
love.graphics.setColor(self.Color[1]-5, self.Color[2]-5, self.Color[3]-5,self.Visibility)
|
||||
else
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility)
|
||||
end
|
||||
self.rclicked=false
|
||||
self.lclicked=false
|
||||
self.mclicked=false
|
||||
end
|
||||
else
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility)
|
||||
self.hovering=false
|
||||
self.rclicked=false
|
||||
self.lclicked=false
|
||||
self.mclicked=false
|
||||
end
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility)
|
||||
if self.ClipDescendants==true then
|
||||
_GuiPro.Clips[tostring(self)]=self
|
||||
love.graphics.setScissor(self.x, self.y, self.width, self.height)
|
||||
end
|
||||
if self:hasRoundness() then
|
||||
love.graphics.stencil(self.stfunc, "replace", 1)
|
||||
love.graphics.setStencilTest("greater", 0)
|
||||
end
|
||||
|
||||
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height,(self.rx or 1)*self.DPI,(self.ry or 1)*self.DPI,(self.segments or 1)*self.DPI)
|
||||
if string.find(self.Type, "Image") then
|
||||
self:ImageRule()
|
||||
end
|
||||
if self.Type=="Video" then
|
||||
self:VideoRule()
|
||||
end
|
||||
if self:hasRoundness() then
|
||||
love.graphics.setStencilTest()
|
||||
end
|
||||
love.graphics.setColor(self.BorderColor[1], self.BorderColor[2], self.BorderColor[3],self.Visibility)
|
||||
if self:hasRoundness() then
|
||||
-- love.graphics.stencil(self.stfunc, "replace", 1)
|
||||
-- love.graphics.setStencilTest("greater", 0)
|
||||
end
|
||||
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height,(self.rx or 1)*self.DPI,(self.ry or 1)*self.DPI,(self.segments or 1)*self.DPI)
|
||||
if string.find(self.Type, "Image") then
|
||||
self:ImageRule()
|
||||
end
|
||||
if self.Type=="Video" then
|
||||
self:VideoRule()
|
||||
end
|
||||
if self:hasRoundness() then
|
||||
-- love.graphics.setStencilTest()
|
||||
end
|
||||
love.graphics.setColor(self.BorderColor[1], self.BorderColor[2], self.BorderColor[3],(self.BorderVisibility or 1))
|
||||
for b=0,self.BorderSize-1 do
|
||||
love.graphics.rectangle("line", self.x-(b/2), self.y-(b/2), self.width+b, self.height+b,(self.rx or 1)*self.DPI,(self.ry or 1)*self.DPI,(self.segments or 1)*self.DPI)
|
||||
end
|
||||
if string.find(self.Type, "Text") then
|
||||
if self.text~=nil then
|
||||
if self.AutoScaleText then
|
||||
self.FontSize=math.floor(self.height/1.45833)
|
||||
end
|
||||
if self.text~=nil and self.TextFormat ~= "center" then
|
||||
love.graphics.setColor(self.TextColor[1],self.TextColor[2],self.TextColor[3],self.TextVisibility)
|
||||
if self.Font==_defaultfont then
|
||||
love.graphics.setFont(self.Font)
|
||||
love.graphics.printf(
|
||||
self.text,
|
||||
(self.x+2+(self.marginL or 0) or self.XTween)*self.DPI,
|
||||
(self.y+math.floor((self.FontHeight-self.FontSize)/2)+self.Tween)*self.DPI,
|
||||
(self.width+(0 or (self.marginR or 0)))*self.DPI,
|
||||
self.TextFormat,
|
||||
self.TextRotation)
|
||||
else
|
||||
if type(self.Font)=="string" then
|
||||
self.Font=love.graphics.newFont(self.Font,self.FontSize)
|
||||
self.FontHeight=self.Font:getHeight()
|
||||
else
|
||||
love.graphics.setFont(self.Font)
|
||||
end
|
||||
if type(self.FontSize)=="string" then
|
||||
self.FontSize=tonumber(self.FontSize)
|
||||
love.graphics.setNewFont(self.FontSize)
|
||||
end
|
||||
love.graphics.printf(
|
||||
self.text,
|
||||
(self.x+2+(self.marginL or 0) or self.XTween)*self.DPI,
|
||||
(self.y+math.floor((self.FontHeight-self.FontSize)/2)+self.Tween)*self.DPI,
|
||||
(self.width+(0 or (self.marginR or 0)))*self.DPI,
|
||||
self.TextFormat,
|
||||
self.TextRotation)
|
||||
end
|
||||
love.graphics.setFont(self.Font)
|
||||
love.graphics.printf(self.text, self.x, self.y, self.width, self.TextFormat,self.TextRotaion)
|
||||
elseif self.text~=nil and self.TextFormat == "center" then
|
||||
love.graphics.setColor(self.TextColor[1],self.TextColor[2],self.TextColor[3],self.TextVisibility)
|
||||
love.graphics.setFont(self.Font)
|
||||
love.graphics.printf(self.text, self.x+(self.width-self.Font:getWidth(self.text))/2, self.y+(self.height-self.Font:getHeight())/2, self.width, "left",self.TextRotaion)
|
||||
end
|
||||
end
|
||||
if self.DrawRulesE then
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
function gui:SetImage(i)
|
||||
if type(i)=="string" or tostring(i):find("ImageData") then
|
||||
self.Image=love.graphics.newImage(i)
|
||||
else
|
||||
self.Image=i
|
||||
end
|
||||
if self.Image then
|
||||
self.ImageHeigth=self.Image:getHeight()
|
||||
self.ImageWidth=self.Image:getWidth()
|
||||
self.Quad=love.graphics.newQuad(0,0,self.width,self.height,self.ImageWidth,self.ImageHeigth)
|
||||
end
|
||||
return self.ImageWidth,self.ImageHeigth
|
||||
end
|
||||
@ -21,7 +21,7 @@ function gui:newAnim(file,delay, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
step.parent.AnimStart[i](step.parent)
|
||||
end
|
||||
end)
|
||||
c.step:OnStep(function(pos,step)
|
||||
c.step:OnStep(function(step,pos)
|
||||
step.parent:SetImage(step.parent.files[pos])
|
||||
end)
|
||||
c.step:OnEnd(function(step)
|
||||
@ -43,6 +43,7 @@ function gui:newAnim(file,delay, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
end
|
||||
function c:Reset()
|
||||
self.step.pos=1
|
||||
self.step:Reset()
|
||||
end
|
||||
function c:getFrames()
|
||||
return #self.files
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
function gui:newAnimFromTiles(file,xd,yd,delay, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(file, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("ImageAnimation",file, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local im=love.graphics.newImage(file)
|
||||
local im=love.image.newImageData(file)
|
||||
local _x,_y=im:getDimensions()
|
||||
c.Visibility=0
|
||||
c.ImageVisibility=1
|
||||
@ -23,7 +23,7 @@ function gui:newAnimFromTiles(file,xd,yd,delay, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
step.parent.AnimStart[i](step.parent)
|
||||
end
|
||||
end)
|
||||
c.step:OnStep(function(pos,step)
|
||||
c.step:OnStep(function(step,pos)
|
||||
step.parent:SetImage(step.parent.files[pos])
|
||||
end)
|
||||
c.step:OnEnd(function(step)
|
||||
|
||||
@ -1,20 +1,10 @@
|
||||
function gui:newImageButton(i,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("ImageButton",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
if type(i)=="string" or type(i):find("ImageData") then
|
||||
c.Image=love.graphics.newImage(i)
|
||||
else
|
||||
c.Image=i
|
||||
end
|
||||
c:SetImage(i)
|
||||
c.Visibility=0
|
||||
c.ImageVisibility=1
|
||||
c.rotation=0
|
||||
if c.Image~=nil then
|
||||
c.ImageHeigth=c.Image:getHeight()
|
||||
c.ImageHeight=c.Image:getHeight()
|
||||
c.ImageWidth=c.Image:getWidth()
|
||||
c.Quad=love.graphics.newQuad(0,0,w,h,c.ImageWidth,c.ImageHeigth)
|
||||
end
|
||||
c:OnEnter(function()
|
||||
love.mouse.setCursor(_GuiPro.CursorH)
|
||||
end)
|
||||
|
||||
@ -1,18 +1,9 @@
|
||||
function gui:newImageLabel(i,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("ImageLabel",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
if type(i)=="string" or type(i):find("ImageData") then
|
||||
c.Image=love.graphics.newImage(i)
|
||||
else
|
||||
c.Image=i
|
||||
end
|
||||
c:SetImage(i)
|
||||
c.Visibility=0
|
||||
c.ImageVisibility=1
|
||||
c.rotation=0
|
||||
if c.Image then
|
||||
c.ImageHeigth=c.Image:getHeight()
|
||||
c.ImageWidth=c.Image:getWidth()
|
||||
c.Quad=love.graphics.newQuad(0,0,w,h,c.ImageWidth,c.ImageHeigth)
|
||||
end
|
||||
return c
|
||||
return c
|
||||
end
|
||||
18
GuiManager/Misc/ClipDescendants.int
Normal file
18
GuiManager/Misc/ClipDescendants.int
Normal file
@ -0,0 +1,18 @@
|
||||
function gui:ClipDescendants(bool)
|
||||
local c = self:GetAllChildren()
|
||||
if not c[#c] then return end
|
||||
if bool then
|
||||
self.clipParent = self.Parent
|
||||
self.Clipping = true
|
||||
c[#c].resetClip = true
|
||||
for i = 1,#c do
|
||||
c[i].ClipReference = self
|
||||
end
|
||||
else
|
||||
self.Clipping = nil
|
||||
c[#c].resetClip = nil
|
||||
for i = 1,#c do
|
||||
c[i].ClipReference = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -7,4 +7,7 @@ function gui:Destroy()
|
||||
end
|
||||
end
|
||||
self.Destroyed = true
|
||||
if #self.Parent.Children==0 then
|
||||
self.Parent.isLeaf = true
|
||||
end
|
||||
end
|
||||
35
GuiManager/Misc/SetImage.int
Normal file
35
GuiManager/Misc/SetImage.int
Normal file
@ -0,0 +1,35 @@
|
||||
_GuiPro.jobqueue:registerJob("LoadImage",function(path)
|
||||
local dat = love.image.newImageData(path)
|
||||
return dat
|
||||
end)
|
||||
local cache = {}
|
||||
_GuiPro.jobqueue.OnJobCompleted(function(JOBID,n)
|
||||
cache[JOBID].Image=_GuiPro.imagecache[n]
|
||||
cache[JOBID].ImageHeigth=cache[JOBID].Image:getHeight()
|
||||
cache[JOBID].ImageWidth=cache[JOBID].Image:getWidth()
|
||||
cache[JOBID].Quad=love.graphics.newQuad(0,0,cache[JOBID].width,cache[JOBID].height,cache[JOBID].ImageWidth,cache[JOBID].ImageHeigth)
|
||||
end)
|
||||
function gui:SetImage(i)
|
||||
local temp = self.Image
|
||||
if _GuiPro.imagecache[i] then
|
||||
self.Image=_GuiPro.imagecache[i]
|
||||
self.ImageHeigth=self.Image:getHeight()
|
||||
self.ImageWidth=self.Image:getWidth()
|
||||
self.Quad=love.graphics.newQuad(0,0,self.width,self.height,self.ImageWidth,self.ImageHeigth)
|
||||
else
|
||||
if type(i)=="string" then
|
||||
local ii = _GuiPro.jobqueue:pushJob("LoadImage",i)
|
||||
cache[ii] = self
|
||||
elseif tostring(i):find("ImageData") then
|
||||
self.Image=love.graphics.newImage(i)
|
||||
self.ImageHeigth=self.Image:getHeight()
|
||||
self.ImageWidth=self.Image:getWidth()
|
||||
self.Quad=love.graphics.newQuad(0,0,self.width,self.height,self.ImageWidth,self.ImageHeigth)
|
||||
elseif i then
|
||||
self.Image=i
|
||||
self.ImageHeigth=self.Image:getHeight()
|
||||
self.ImageWidth=self.Image:getWidth()
|
||||
self.Quad=love.graphics.newQuad(0,0,self.width,self.height,self.ImageWidth,self.ImageHeigth)
|
||||
end
|
||||
end
|
||||
end
|
||||
797
GuiManager/Misc/Utils.int
Normal file
797
GuiManager/Misc/Utils.int
Normal file
@ -0,0 +1,797 @@
|
||||
-- os Additions
|
||||
function os.getSystemBit()
|
||||
if (os.getenv('PROCESSOR_ARCHITEW6432')=='AMD64' or os.getenv('PROCESSOR_ARCHITECTURE')=='AMD64') then
|
||||
return 64
|
||||
else
|
||||
return 32
|
||||
end
|
||||
end
|
||||
function os.sleep(n)
|
||||
if not n then n=0 end
|
||||
local t0 = os.clock()
|
||||
while os.clock() - t0 <= n do end
|
||||
end
|
||||
function os.pause(msg)
|
||||
if msg ~= nil then
|
||||
print(msg)
|
||||
end
|
||||
io.read()
|
||||
end
|
||||
function os.batCmd(cmd)
|
||||
io.mkFile('temp.bat',cmd)
|
||||
local temp = os.execute([[temp.bat]])
|
||||
io.delFile('temp.bat')
|
||||
return temp
|
||||
end
|
||||
function os._getOS()
|
||||
if package.config:sub(1,1)=='\\' then
|
||||
return 'windows'
|
||||
else
|
||||
return 'unix'
|
||||
end
|
||||
end
|
||||
function os.getOS(t)
|
||||
if not t then
|
||||
return os._getOS()
|
||||
end
|
||||
if os._getOS()=='unix' then
|
||||
fh,err = io.popen('uname -o 2>/dev/null','r')
|
||||
if fh then
|
||||
osname = fh:read()
|
||||
end
|
||||
if osname then return osname end
|
||||
end
|
||||
local winver='Unknown Version'
|
||||
local a,b,c=os.capture('ver'):match('(%d+).(%d+).(%d+)')
|
||||
local win=a..'.'..b..'.'..c
|
||||
if type(t)=='string' then
|
||||
win=t
|
||||
end
|
||||
if win=='4.00.950' then
|
||||
winver='95'
|
||||
elseif win=='4.00.1111' then
|
||||
winver='95 OSR2'
|
||||
elseif win=='4.00.1381' then
|
||||
winver='NT 4.0'
|
||||
elseif win=='4.10.1998' then
|
||||
winver='98'
|
||||
elseif win=='4.10.2222' then
|
||||
winver='98 SE'
|
||||
elseif win=='4.90.3000' then
|
||||
winver='ME'
|
||||
elseif win=='5.00.2195' then
|
||||
winver='2000'
|
||||
elseif win=='5.1.2600' then
|
||||
winver='XP'
|
||||
elseif win=='5.2.3790' then
|
||||
winver='Server 2003'
|
||||
elseif win=='6.0.6000' then
|
||||
winver='Vista/Windows Server 2008'
|
||||
elseif win=='6.0.6002' then
|
||||
winver='Vista SP2'
|
||||
elseif win=='6.1.7600' then
|
||||
winver='7/Windows Server 2008 R2'
|
||||
elseif win=='6.1.7601' then
|
||||
winver='7 SP1/Windows Server 2008 R2 SP1'
|
||||
elseif win=='6.2.9200' then
|
||||
winver='8/Windows Server 2012'
|
||||
elseif win=='6.3.9600' then
|
||||
winver='8.1/Windows Server 2012'
|
||||
elseif win=='6.4.9841' then
|
||||
winver='10 Technical Preview 1'
|
||||
elseif win=='6.4.9860' then
|
||||
winver='10 Technical Preview 2'
|
||||
elseif win=='6.4.9879' then
|
||||
winver='10 Technical Preview 3'
|
||||
elseif win=='10.0.9926' then
|
||||
winver='10 Technical Preview 4'
|
||||
end
|
||||
return 'Windows '..winver
|
||||
end
|
||||
function os.getLuaArch()
|
||||
return (#tostring({})-7)*4
|
||||
end
|
||||
if os.getOS()=='windows' then
|
||||
function os.sleep(n)
|
||||
if n > 0 then os.execute('ping -n ' .. tonumber(n+1) .. ' localhost > NUL') end
|
||||
end
|
||||
else
|
||||
function os.sleep(n)
|
||||
os.execute('sleep ' .. tonumber(n))
|
||||
end
|
||||
end
|
||||
function os.capture(cmd, raw)
|
||||
local f = assert(io.popen(cmd, 'r'))
|
||||
local s = assert(f:read('*a'))
|
||||
f:close()
|
||||
if raw then return s end
|
||||
s = string.gsub(s, '^%s+', '')
|
||||
s = string.gsub(s, '%s+$', '')
|
||||
s = string.gsub(s, '[\n\r]+', ' ')
|
||||
return s
|
||||
end
|
||||
function os.getCurrentUser()
|
||||
return os.getenv('$USER') or os.getenv('USERNAME')
|
||||
end
|
||||
-- string Additions
|
||||
function string.trim(s)
|
||||
local from = s:match"^%s*()"
|
||||
return from > #s and "" or s:match(".*%S", from)
|
||||
end
|
||||
function string.random(n)
|
||||
local str = ''
|
||||
strings = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}
|
||||
for i=1,n do
|
||||
h = math.random(1,#strings)
|
||||
str = str..''..strings[h]
|
||||
end
|
||||
return str
|
||||
end
|
||||
function string.linesToTable(s)
|
||||
local t = {}
|
||||
local i = 0
|
||||
while true do
|
||||
i = string.find(s, '\n', i+1)
|
||||
if i == nil then return t end
|
||||
table.insert(t, i)
|
||||
end
|
||||
end
|
||||
function string.lines(str)
|
||||
local t = {}
|
||||
local function helper(line) table.insert(t, line) return '' end
|
||||
helper((str:gsub('(.-)\r?\n', helper)))
|
||||
return t
|
||||
end
|
||||
function string.split(str, pat)
|
||||
local t = {} -- NOTE: use {n = 0} in Lua-5.0
|
||||
local fpat = '(.-)' .. pat
|
||||
local last_end = 1
|
||||
local s, e, cap = str:find(fpat, 1)
|
||||
while s do
|
||||
if s ~= 1 or cap ~= '' then
|
||||
table.insert(t,cap)
|
||||
end
|
||||
last_end = e+1
|
||||
s, e, cap = str:find(fpat, last_end)
|
||||
end
|
||||
if last_end <= #str then
|
||||
cap = str:sub(last_end)
|
||||
table.insert(t, cap)
|
||||
end
|
||||
return t
|
||||
end
|
||||
function string.shuffle(inputStr)
|
||||
math.randomseed(os.time());
|
||||
local outputStr = '';
|
||||
local strLength = string.len(inputStr);
|
||||
while (strLength ~=0) do
|
||||
local pos = math.random(strLength);
|
||||
outputStr = outputStr..string.sub(inputStr,pos,pos);
|
||||
inputStr = inputStr:sub(1, pos-1) .. inputStr:sub(pos+1);
|
||||
strLength = string.len(inputStr);
|
||||
end
|
||||
return outputStr;
|
||||
end
|
||||
function string.genKeys(chars,a,f,s,GG)
|
||||
if GG then
|
||||
chars=string.rep(chars,a)
|
||||
end
|
||||
if s then
|
||||
chars=string.shuffle(chars)
|
||||
end
|
||||
b=#chars
|
||||
if a==0 then return end
|
||||
local taken = {} local slots = {}
|
||||
for i=1,a do slots[i]=0 end
|
||||
for i=1,b do taken[i]=false end
|
||||
local index = 1
|
||||
local tab={}
|
||||
for i=1,#chars do
|
||||
table.insert(tab,chars:sub(i,i))
|
||||
end
|
||||
while index > 0 do repeat
|
||||
repeat slots[index] = slots[index] + 1
|
||||
until slots[index] > b or not taken[slots[index]]
|
||||
if slots[index] > b then
|
||||
slots[index] = 0
|
||||
index = index - 1
|
||||
if index > 0 then
|
||||
taken[slots[index]] = false
|
||||
end
|
||||
break
|
||||
else
|
||||
taken[slots[index]] = true
|
||||
end
|
||||
if index == a then
|
||||
local tt={}
|
||||
for i=1,a do
|
||||
table.insert(tt,tab[slots[i]])
|
||||
end
|
||||
f(table.concat(tt))
|
||||
taken[slots[index]] = false
|
||||
break
|
||||
end
|
||||
index = index + 1
|
||||
until true end
|
||||
end
|
||||
-- io Additions
|
||||
function io.getInput(msg)
|
||||
if msg ~= nil then
|
||||
io.write(msg)
|
||||
end
|
||||
return io.read()
|
||||
end
|
||||
function io.scanDir(directory)
|
||||
directory=directory or io.getDir()
|
||||
local i, t, popen = 0, {}, io.popen
|
||||
if os.getOS()=='unix' then
|
||||
for filename in popen('ls -a \''..directory..'\''):lines() do
|
||||
i = i + 1
|
||||
t[i] = filename
|
||||
end
|
||||
else
|
||||
for filename in popen('dir \''..directory..'\' /b'):lines() do
|
||||
i = i + 1
|
||||
t[i] = filename
|
||||
end
|
||||
end
|
||||
return t
|
||||
end
|
||||
function io.buildFromTree(tbl, indent,folder)
|
||||
if not indent then indent = 0 end
|
||||
if not folder then folder = '' end
|
||||
for k, v in pairs(tbl) do
|
||||
formatting = string.rep(' ', indent) .. k .. ':'
|
||||
if type(v) == 'table' then
|
||||
if not(io.dirExists(folder..string.sub(formatting,1,-2))) then
|
||||
io.mkDir(folder..string.sub(formatting,1,-2))
|
||||
end
|
||||
io.buildFromTree(v,0,folder..string.sub(formatting,1,-2)..'\\')
|
||||
else
|
||||
a=string.find(tostring(v),':',1,true)
|
||||
if a then
|
||||
file=string.sub(tostring(v),1,a-1)
|
||||
data=string.sub(tostring(v),a+1)
|
||||
io.mkFile(folder..file,data,'wb')
|
||||
else
|
||||
io.mkFile(folder..v,'','wb')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
function io.cpFile(path,topath)
|
||||
if os.getOS()=='unix' then
|
||||
os.execute('cp '..file1..' '..file2)
|
||||
else
|
||||
os.execute('Copy '..path..' '..topath)
|
||||
end
|
||||
end
|
||||
function io.delDir(directoryname)
|
||||
if os.getOS()=='unix' then
|
||||
os.execute('rm -rf '..directoryname)
|
||||
else
|
||||
os.execute('rmdir '..directoryname..' /s /q')
|
||||
end
|
||||
end
|
||||
function io.delFile(path)
|
||||
os.remove(path)
|
||||
end
|
||||
function io.mkDir(dirname)
|
||||
os.execute('mkdir "' .. dirname..'"')
|
||||
end
|
||||
function io.mkFile(filename,data,tp)
|
||||
if not(tp) then tp='wb' end
|
||||
if not(data) then data='' end
|
||||
file = io.open(filename, tp)
|
||||
if file==nil then return end
|
||||
file:write(data)
|
||||
file:close()
|
||||
end
|
||||
function io.movFile(path,topath)
|
||||
io.cpFile(path,topath)
|
||||
io.delFile(path)
|
||||
end
|
||||
function io.listFiles(dir)
|
||||
if not(dir) then dir='' end
|
||||
local f = io.popen('dir \''..dir..'\'')
|
||||
if f then
|
||||
return f:read('*a')
|
||||
else
|
||||
print('failed to read')
|
||||
end
|
||||
end
|
||||
function io.getDir(dir)
|
||||
if not dir then return io.getWorkingDir() end
|
||||
if os.getOS()=='unix' then
|
||||
return os.capture('cd '..dir..' ; cd')
|
||||
else
|
||||
return os.capture('cd '..dir..' & cd')
|
||||
end
|
||||
end
|
||||
function io.getWorkingDir()
|
||||
return io.popen'cd':read'*l'
|
||||
end
|
||||
function io.fileExists(path)
|
||||
g=io.open(path or '','r')
|
||||
if path =='' then
|
||||
p='empty path'
|
||||
return nil
|
||||
end
|
||||
if g~=nil and true or false then
|
||||
p=(g~=nil and true or false)
|
||||
end
|
||||
if g~=nil then
|
||||
io.close(g)
|
||||
else
|
||||
return false
|
||||
end
|
||||
return p
|
||||
end
|
||||
function io.fileCheck(file_name)
|
||||
if not file_name then print('No path inputed') return false end
|
||||
local file_found=io.open(file_name, 'r')
|
||||
if file_found==nil then
|
||||
file_found=false
|
||||
else
|
||||
file_found=true
|
||||
end
|
||||
return file_found
|
||||
end
|
||||
function io.dirExists(strFolderName)
|
||||
strFolderName = strFolderName or io.getDir()
|
||||
local fileHandle, strError = io.open(strFolderName..'\\*.*','r')
|
||||
if fileHandle ~= nil then
|
||||
io.close(fileHandle)
|
||||
return true
|
||||
else
|
||||
if string.match(strError,'No such file or directory') then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
function io.getAllItems(dir)
|
||||
local t=os.capture("cd \""..dir.."\" & dir /a-d | find",true):lines()
|
||||
return t
|
||||
end
|
||||
function io.listItems(dir)
|
||||
if io.dirExists(dir) then
|
||||
temp=io.listFiles(dir) -- current directory if blank
|
||||
if io.getDir(dir)=='C:\\\n' then
|
||||
a,b=string.find(temp,'C:\\',1,true)
|
||||
a=a+2
|
||||
else
|
||||
a,b=string.find(temp,'..',1,true)
|
||||
end
|
||||
temp=string.sub(temp,a+2)
|
||||
list=string.linesToTable(temp)
|
||||
temp=string.sub(temp,1,list[#list-2])
|
||||
slist=string.lines(temp)
|
||||
table.remove(slist,1)
|
||||
table.remove(slist,#slist)
|
||||
temp={}
|
||||
temp2={}
|
||||
for i=1,#slist do
|
||||
table.insert(temp,string.sub(slist[i],40,-1))
|
||||
end
|
||||
return temp
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
function io.getDirectories(dir,l)
|
||||
if dir then
|
||||
dir=dir..'\\'
|
||||
else
|
||||
dir=''
|
||||
end
|
||||
local temp2=io.scanDir(dir)
|
||||
for i=#temp2,1,-1 do
|
||||
if io.fileExists(dir..temp2[i]) then
|
||||
table.remove(temp2,i)
|
||||
elseif l then
|
||||
temp2[i]=dir..temp2[i]
|
||||
end
|
||||
end
|
||||
return temp2
|
||||
end
|
||||
function io.getFiles(dir,l)
|
||||
if dir then
|
||||
dir=dir..'\\'
|
||||
else
|
||||
dir=''
|
||||
end
|
||||
local temp2=io.scanDir(dir)
|
||||
for i=#temp2,1,-1 do
|
||||
if io.dirExists(dir..temp2[i]) then
|
||||
table.remove(temp2,i)
|
||||
elseif l then
|
||||
temp2[i]=dir..temp2[i]
|
||||
end
|
||||
end
|
||||
return temp2
|
||||
end
|
||||
function io.getFullName(name)
|
||||
local temp=name or arg[0]
|
||||
if string.find(temp,'\\',1,true) or string.find(temp,'/',1,true) then
|
||||
temp=string.reverse(temp)
|
||||
a,b=string.find(temp,'\\',1,true)
|
||||
if not(a) or not(b) then
|
||||
a,b=string.find(temp,'/',1,true)
|
||||
end
|
||||
return string.reverse(string.sub(temp,1,b-1))
|
||||
end
|
||||
return temp
|
||||
end
|
||||
function io.getName(file)
|
||||
local name=io.getFullName(file)
|
||||
name=string.reverse(name)
|
||||
a,b=string.find(name,'.',1,true)
|
||||
name=string.sub(name,a+1,-1)
|
||||
return string.reverse(name)
|
||||
end
|
||||
function io.readFile(file)
|
||||
local f = io.open(file, 'rb')
|
||||
local content = f:read('*all')
|
||||
f:close()
|
||||
return content
|
||||
end
|
||||
function io.getExtension(file)
|
||||
local file=io.getFullName(file)
|
||||
file=string.reverse(file)
|
||||
local a,b=string.find(file,'.',0,true)
|
||||
local temp=string.sub(file,1,b)
|
||||
return string.reverse(temp)
|
||||
end
|
||||
function io.pathToTable(path)
|
||||
local p=io.splitPath(path)
|
||||
local temp={}
|
||||
temp[p[1]]={}
|
||||
local last=temp[p[1]]
|
||||
for i=2,#p do
|
||||
snd=last
|
||||
last[p[i]]={}
|
||||
last=last[p[i]]
|
||||
end
|
||||
return temp,last,snd
|
||||
end
|
||||
function io.splitPath(str)
|
||||
return string.split(str,'[\\/]+')
|
||||
end
|
||||
|
||||
function io.parseDir(dir,t)
|
||||
io.tempFiles={}
|
||||
function _p(dir)
|
||||
local dirs=io.getDirectories(dir,true)
|
||||
local files=io.getFiles(dir,true)
|
||||
for i=1,#files do
|
||||
p,l,s=io.pathToTable(files[i])
|
||||
if t then
|
||||
s[io.getFullName(files[i])]=io.readFile(files[i])
|
||||
else
|
||||
s[io.getFullName(files[i])]=io.open(files[i],'r+')
|
||||
end
|
||||
table.merge(io.tempFiles,p)
|
||||
end
|
||||
for i=1,#dirs do
|
||||
table.merge(io.tempFiles,io.pathToTable(dirs[i]))
|
||||
_p(dirs[i],t)
|
||||
end
|
||||
end
|
||||
_p(dir)
|
||||
return io.tempFiles
|
||||
end
|
||||
function io.parsedir(dir,f)
|
||||
io.tempFiles={}
|
||||
function _p(dir,f)
|
||||
local dirs=io.getDirectories(dir,true)
|
||||
local files=io.getFiles(dir,true)
|
||||
for i=1,#files do
|
||||
if not f then
|
||||
table.insert(io.tempFiles,files[i])
|
||||
else
|
||||
f(files[i])
|
||||
end
|
||||
end
|
||||
for i=1,#dirs do
|
||||
_p(dirs[i],f)
|
||||
end
|
||||
end
|
||||
_p(dir,f)
|
||||
return io.tempFiles
|
||||
end
|
||||
function io.driveReady(drive)
|
||||
drive=drive:upper()
|
||||
if not(drive:find(':',1,true)) then
|
||||
drive=drive..':'
|
||||
end
|
||||
drives=io.getDrives()
|
||||
for i=1,#drives do
|
||||
if drives[i]==drive then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
function io.getDrives()
|
||||
if os.getOS()=='windows' then
|
||||
local temp={}
|
||||
local t1=os.capture('wmic logicaldisk where drivetype=2 get deviceid, volumename',true)
|
||||
local t2=os.capture('wmic logicaldisk where drivetype=3 get deviceid, volumename',true)
|
||||
for drive,d2 in t1:gmatch('(.:)%s-(%w+)') do
|
||||
if #d2>1 then
|
||||
table.insert(temp,drive)
|
||||
end
|
||||
end
|
||||
for drive in t2:gmatch('(.:)') do
|
||||
table.insert(temp,drive)
|
||||
end
|
||||
return temp
|
||||
end
|
||||
error('Command is windows only!')
|
||||
end
|
||||
-- table Additions
|
||||
function table.dump(t,indent)
|
||||
local names = {}
|
||||
if not indent then indent = '' end
|
||||
for n,g in pairs(t) do
|
||||
table.insert(names,n)
|
||||
end
|
||||
table.sort(names)
|
||||
for i,n in pairs(names) do
|
||||
local v = t[n]
|
||||
if type(v) == 'table' then
|
||||
if(v==t) then
|
||||
print(indent..tostring(n)..': <-')
|
||||
else
|
||||
print(indent..tostring(n)..':')
|
||||
table.dump(v,indent..' ')
|
||||
end
|
||||
else
|
||||
if type(v) == 'function' then
|
||||
print(indent..tostring(n)..'()')
|
||||
else
|
||||
print(indent..tostring(n)..': '..tostring(v))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
function table.alphanumsort(o)
|
||||
local function padnum(d) local dec, n = string.match(d, '(%.?)0*(.+)')
|
||||
return #dec > 0 and ('%.12f'):format(d) or ('%s%03d%s'):format(dec, #n, n)
|
||||
end
|
||||
table.sort(o, function(a,b) return tostring(a):gsub('%.?%d+',padnum)..('%3d'):format(#b)< tostring(b):gsub('%.?%d+',padnum)..('%3d'):format(#a) end)
|
||||
return o
|
||||
end
|
||||
function table.foreach(t,f)
|
||||
for i,v in pairs(t) do
|
||||
f(v)
|
||||
end
|
||||
end
|
||||
function table.merge(t1, t2)
|
||||
for k,v in pairs(t2) do
|
||||
if type(v) == 'table' then
|
||||
if type(t1[k] or false) == 'table' then
|
||||
table.merge(t1[k] or {}, t2[k] or {})
|
||||
else
|
||||
t1[k] = v
|
||||
end
|
||||
else
|
||||
t1[k] = v
|
||||
end
|
||||
end
|
||||
return t1
|
||||
end
|
||||
function table.print(tbl, indent)
|
||||
if not indent then indent = 0 end
|
||||
for k, v in pairs(tbl) do
|
||||
formatting = string.rep(' ', indent) .. k .. ': '
|
||||
if type(v) == 'table' then
|
||||
print(formatting)
|
||||
table.print(v, indent+1)
|
||||
else
|
||||
print(formatting .. tostring(v))
|
||||
end
|
||||
end
|
||||
end
|
||||
function table.merge(t1, t2)
|
||||
for k,v in pairs(t2) do
|
||||
if type(v) == 'table' then
|
||||
if type(t1[k] or false) == 'table' then
|
||||
table.merge(t1[k] or {}, t2[k] or {})
|
||||
else
|
||||
t1[k] = v
|
||||
end
|
||||
else
|
||||
t1[k] = v
|
||||
end
|
||||
end
|
||||
return t1
|
||||
end
|
||||
function table.clear(t)
|
||||
for k in pairs (t) do
|
||||
t[k] = nil
|
||||
end
|
||||
end
|
||||
function table.copy(t)
|
||||
function deepcopy(orig)
|
||||
local orig_type = type(orig)
|
||||
local copy
|
||||
if orig_type == 'table' then
|
||||
copy = {}
|
||||
for orig_key, orig_value in next, orig, nil do
|
||||
copy[deepcopy(orig_key)] = deepcopy(orig_value)
|
||||
end
|
||||
setmetatable(copy, deepcopy(getmetatable(orig)))
|
||||
else -- number, string, boolean, etc
|
||||
copy = orig
|
||||
end
|
||||
return copy
|
||||
end
|
||||
return deepcopy(t)
|
||||
end
|
||||
function table.swap(tab,i1,i2)
|
||||
tab[i1],tab[i2]=tab[i2],tab[i1]
|
||||
end
|
||||
function table.append(t1, ...)
|
||||
t1,t2= t1 or {},{...}
|
||||
for k,v in pairs(t2) do
|
||||
t1[#t1+1]=t2[k]
|
||||
end
|
||||
return t1
|
||||
end
|
||||
function table.compare(t1, t2,d)
|
||||
if d then
|
||||
return table.deepCompare(t1,t2)
|
||||
end
|
||||
--if #t1 ~= #t2 then return false end
|
||||
if #t2>#t1 then
|
||||
for i=1,#t2 do
|
||||
if t1[i] ~= t2[i] then
|
||||
return false,t2[i]
|
||||
end
|
||||
end
|
||||
else
|
||||
for i=1,#t1 do
|
||||
if t1[i] ~= t2[i] then
|
||||
return false,t2[i]
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
function table.deepCompare(t1,t2)
|
||||
if t1==t2 then return true end
|
||||
if (type(t1)~='table') then return false end
|
||||
local mt1 = getmetatable(t1)
|
||||
local mt2 = getmetatable(t2)
|
||||
if( not table.deepCompare(mt1,mt2) ) then return false end
|
||||
for k1,v1 in pairs(t1) do
|
||||
local v2 = t2[k1]
|
||||
if( not table.deepCompare(v1,v2) ) then return false end
|
||||
end
|
||||
for k2,v2 in pairs(t2) do
|
||||
local v1 = t1[k2]
|
||||
if( not table.deepCompare(v1,v2) ) then return false end
|
||||
end
|
||||
return true
|
||||
end
|
||||
function table.has(t,_v)
|
||||
for i,v in pairs(t) do
|
||||
if v==_v then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
function table.reverse(tab)
|
||||
local size = #tab
|
||||
local newTable = {}
|
||||
for i,v in ipairs (tab) do
|
||||
newTable[size-i] = v
|
||||
end
|
||||
for i=1,#newTable do
|
||||
tab[i]=newTable[i]
|
||||
end
|
||||
end
|
||||
-- Math Additions
|
||||
local Y = function(g) local a = function(f) return f(f) end return a(function(f) return g(function(x) local c=f(f) return c(x) end) end) end
|
||||
local F = function(f) return function(n)if n == 0 then return 1 else return n*f(n-1) end end end
|
||||
math.factorial = Y(F)
|
||||
math.fib={}
|
||||
math.fib.fibL={}
|
||||
setmetatable(math.fib,{__call=function(self,n)
|
||||
if n<=2 then
|
||||
return 1
|
||||
else
|
||||
if self.fibL[n] then
|
||||
return self.fibL[n]
|
||||
else
|
||||
local t=math.fib(n-1)+math.fib(n-2)
|
||||
self.fibL[n]=t
|
||||
return t
|
||||
end
|
||||
end
|
||||
end})
|
||||
local floor,insert = math.floor, table.insert
|
||||
function math.basen(n,b)
|
||||
n = floor(n)
|
||||
if not b or b == 10 then return tostring(n) end
|
||||
local digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
local t = {}
|
||||
local sign = ''
|
||||
if n < 0 then
|
||||
sign = '-'
|
||||
n = -n
|
||||
end
|
||||
repeat
|
||||
local d = (n % b) + 1
|
||||
n = floor(n / b)
|
||||
insert(t, 1, digits:sub(d,d))
|
||||
until n == 0
|
||||
return sign .. table.concat(t,'')
|
||||
end
|
||||
function math.convbase(n,b,tb)
|
||||
return math.basen(tonumber(tostring(n),b),tb)
|
||||
end
|
||||
if BigNum then
|
||||
function BigNum.mod(a,b)
|
||||
return a-((a/b)*b)
|
||||
end
|
||||
local floor,insert = math.floor, table.insert
|
||||
function math.basen(n,b)
|
||||
n = BigNum.new(n)
|
||||
if not b or b == 10 then return tostring(n) end
|
||||
local digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
local t = {}
|
||||
local sign = ''
|
||||
if n < BigNum.new(0) then
|
||||
sign = '-'
|
||||
n = -n
|
||||
end
|
||||
repeat
|
||||
local d = BigNum.mod(n , b) + 1
|
||||
n = n/b
|
||||
d=tonumber(tostring(d))
|
||||
insert(t, 1, digits:sub(d,d))
|
||||
until tonumber(tostring(n)) == 0
|
||||
return sign .. table.concat(t,'')
|
||||
end
|
||||
function math.to10(n,b)
|
||||
local num=tostring(n)
|
||||
local sum=BigNum.new()
|
||||
local digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
for i=1,#num do
|
||||
local v=digits:find(num:sub(i,i),1,true)
|
||||
sum=sum+BigNum.new(tonumber(v)-1)*BigNum.pow(BigNum.new(b),BigNum.new(#num-i))
|
||||
end
|
||||
return sum
|
||||
end
|
||||
function math.convbase(n,b,tb)
|
||||
return math.basen(math.to10(n,b),tb)
|
||||
end
|
||||
end
|
||||
function math.numfix(n,x)
|
||||
local str=tostring(n)
|
||||
if #str<x then
|
||||
str=('0'):rep(x-#str)..str
|
||||
end
|
||||
return str
|
||||
end
|
||||
-- Misc Additions
|
||||
function smartPrint(...)
|
||||
local args={...}
|
||||
for i=1,#args do
|
||||
if type(args[i])=='table' then
|
||||
table.print(args[i])
|
||||
else
|
||||
print(args[i])
|
||||
end
|
||||
end
|
||||
end
|
||||
function totable(v)
|
||||
if type(v)=='table' then return v end
|
||||
return {v}
|
||||
end
|
||||
print(math.factorial(2))
|
||||
@ -1,3 +1,3 @@
|
||||
function gui:addDominance()
|
||||
_GuiPro.TopHovered=self
|
||||
--_GuiPro.TopHovered=self
|
||||
end
|
||||
@ -1,6 +0,0 @@
|
||||
function gui:addHotKey(key)
|
||||
local temp=self:newFrame(0,0,0,0)
|
||||
temp.Visible=false
|
||||
temp:setHotKey(key)
|
||||
return temp
|
||||
end
|
||||
@ -1,12 +1,14 @@
|
||||
function gui:getFullSize()
|
||||
local maxx,maxy=-math.huge,-math.huge
|
||||
local maxx,maxy=self.width,self.height
|
||||
local px,py=self.x,self.y
|
||||
local temp = self:GetAllChildren()
|
||||
for i=1,#temp do
|
||||
if temp[i].width+temp[i].offset.pos.x>maxx then
|
||||
maxx=temp[i].width+temp[i].offset.pos.x
|
||||
elseif temp[i].height+temp[i].offset.pos.y>maxy then
|
||||
maxy=temp[i].height+temp[i].offset.pos.y
|
||||
if temp[i].width+temp[i].x>maxx then
|
||||
maxx=temp[i].width+temp[i].x
|
||||
end
|
||||
if temp[i].height+temp[i].y>maxy then
|
||||
maxy=temp[i].height+temp[i].y
|
||||
end
|
||||
end
|
||||
return maxx,maxy
|
||||
return maxx,maxy,px,py
|
||||
end
|
||||
@ -1,7 +1,7 @@
|
||||
function gui:isDescendant(obj)
|
||||
local things=obj:GetAllChildren()
|
||||
local things = obj:GetAllChildren()
|
||||
for i=1,#things do
|
||||
if things[i]==self then
|
||||
if things[i] == self then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,98 +1,81 @@
|
||||
function gui:newScrollMenu(title,tabN,onloop,x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local Main = self:newFrame(x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local Title=Main:newTextButton(title,"Title",0,0,0,20,0,0,1)
|
||||
Title.Tween=-4
|
||||
Title.FontSize=12
|
||||
Title:OnReleased(function(b,self)
|
||||
self.Parent.Tick=not(self.Parent.Tick)
|
||||
end)
|
||||
local scroll=Main:newTextButton("","Scroll",-20,20,20,-20,1,0,0,1)
|
||||
scroll:OnClicked(function(b,self,x,y)
|
||||
self.Parent.Mover:SetDualDim(0,y-10,20,20)
|
||||
if self.Parent.Mover.offset.pos.y<0 then
|
||||
self.Parent.Mover:SetDualDim(0,0,20,20)
|
||||
end
|
||||
if self.Parent.Mover.offset.pos.y>self.Parent.height-40 then
|
||||
self.Parent.Mover:SetDualDim(0,self.Parent.height-40,20,20)
|
||||
end
|
||||
local temp = #self.Parent.TList
|
||||
self.Parent.pos=(math.floor((temp*self.Parent.Mover.offset.pos.y)/self.height))+1
|
||||
end)
|
||||
Main:OnUpdate(function(self)
|
||||
if self.Tick==false then
|
||||
self.Visibility=0
|
||||
end
|
||||
end)
|
||||
scroll:OnUpdate(function(self)
|
||||
self.Visible=self.Parent.Tick
|
||||
end)
|
||||
local Mover=scroll:newTextLabel("",0,0,20,20)
|
||||
Main.Mover=Mover
|
||||
Main.TList=tabN
|
||||
Main.pos=1
|
||||
Main.Tick=true
|
||||
function Main:Update(title,tabN,onloop)
|
||||
ch=self:getChildren()
|
||||
for i=#ch,1,-1 do
|
||||
ch[i]:Destroy()
|
||||
end
|
||||
Title=Main:newTextButton(title,"Title",0,0,0,20,0,0,1)
|
||||
Title.Tween=-4
|
||||
Title.FontSize=12
|
||||
Title:OnReleased(function(b,self)
|
||||
self.Parent.Tick=not(self.Parent.Tick)
|
||||
end)
|
||||
scroll=Main:newTextButton("","Scroll",-20,20,20,-20,1,0,0,1)
|
||||
scroll:OnClicked(function(b,self,x,y)
|
||||
self.Parent.Mover:SetDualDim(0,y-10,20,20)
|
||||
if self.Parent.Mover.offset.pos.y<0 then
|
||||
self.Parent.Mover:SetDualDim(0,0,20,20)
|
||||
end
|
||||
if self.Parent.Mover.offset.pos.y>self.Parent.height-40 then
|
||||
self.Parent.Mover:SetDualDim(0,self.Parent.height-40,20,20)
|
||||
end
|
||||
local temp = #self.Parent.TList
|
||||
self.Parent.pos=(math.floor((temp*self.Parent.Mover.offset.pos.y)/self.height))+1
|
||||
end)
|
||||
local Mover=scroll:newTextLabel("",0,0,20,20)
|
||||
Main.Mover=Mover
|
||||
Main.TList=tabN
|
||||
Main.pos=1
|
||||
Main.Tick=true
|
||||
scroll:OnUpdate(function(self)
|
||||
self.Visible=self.Parent.Tick
|
||||
end)
|
||||
for i=1,math.floor(Main.height/20)-1 do
|
||||
local temp=Main:newTextButton("","Item"..i,0,i*20,-20,20,0,0,1)
|
||||
temp.FontSize=10
|
||||
temp.Tween=-4
|
||||
temp.pos=i
|
||||
temp:OnUpdate(function(self)
|
||||
self.text=self.Parent.TList[(self.Parent.pos+self.pos)-1]
|
||||
self.Visible=self.Parent.Tick
|
||||
end)
|
||||
if onloop then
|
||||
onloop(temp,i)
|
||||
function gui:newScrollMenu(name)
|
||||
local temp = self:newFullFrame(name)
|
||||
temp.ref = {
|
||||
[[setNewFont(16)]],
|
||||
[[setRoundness(10,10,180)]],
|
||||
Tween = 6
|
||||
}
|
||||
temp.allowOverlapping = true
|
||||
temp.Visibility = 0
|
||||
local ScrollY = temp:newFrame(name.."ScrollY",-20,0,20,0,1,0,0,1)
|
||||
temp.scroll = ScrollY
|
||||
ScrollY.Color=Color.new(80,80,80)
|
||||
ScrollY.allowOverlapping = true
|
||||
ScrollY.Mover = ScrollY:newFrame(name.."MoverY",5,5,10,80)
|
||||
ScrollY.Mover.Color = Color.new(60,60,60)
|
||||
local func = function(b,self,x,y,nn)
|
||||
temp.symbolicY = y
|
||||
if y>45 and y<self.height-45 then
|
||||
self.Mover:SetDualDim(nil,y-40)
|
||||
temp.first:setDualDim(nil,nil,nil,nil,nil,-((y-46)/(self.height-92))*((temp.max-temp.height+60)/temp.height))
|
||||
if not nn then
|
||||
self:setMouseXY(10)
|
||||
end
|
||||
end
|
||||
end
|
||||
io.write(tostring(Main.height).."\n")
|
||||
for i=1,math.floor(Main.height/20)-1 do
|
||||
local temp=Main:newTextButton("Item"..i,0,i*20,-20,20,0,0,1)
|
||||
temp.FontSize=10
|
||||
temp.Tween=-4
|
||||
temp.pos=i
|
||||
temp:OnUpdate(function(self)
|
||||
if self.Parent.TList[(self.Parent.pos+self.pos)-1]~=nil then
|
||||
self.text=self.Parent.TList[(self.Parent.pos+self.pos)-1]
|
||||
ScrollY:OnClicked(func)
|
||||
temp.symbolicY = 45
|
||||
temp.scrollM = 2
|
||||
temp:OnMouseWheelMoved(function(self,x,y)
|
||||
temp.symbolicY=temp.symbolicY-(y*temp.scrollM)
|
||||
if temp.symbolicY<45 then
|
||||
temp.symbolicY = 45
|
||||
elseif temp.symbolicY>ScrollY.height-40 then
|
||||
temp.symbolicY = ScrollY.height-40
|
||||
end
|
||||
func("l",ScrollY,x,temp.symbolicY,true)
|
||||
end)
|
||||
temp.ClipDescendants=true
|
||||
temp.first = temp:newTextLabel("","",15,10,-50,40,0,0,1)
|
||||
local nice = temp:newTextLabel(name,name,15,10,-50,40,0,0,1)
|
||||
temp.header = nice
|
||||
temp.last = temp.first
|
||||
temp.last.BorderSize = 0
|
||||
temp.last.Visibility = 0
|
||||
nice:setNewFont(26)
|
||||
nice.Tween = 6
|
||||
temp.list = {}
|
||||
local alarm
|
||||
multi:newLoop(function()
|
||||
for i=1,#temp.list do
|
||||
local val = (temp.first.y+(temp.list[i].staticpos)+10)
|
||||
if val>temp.y and val<temp.height+temp.y+temp.height then
|
||||
temp.list[i].Visible = true
|
||||
else
|
||||
self.text=""
|
||||
temp.list[i].Visible = false
|
||||
end
|
||||
self.Visible=self.Parent.Tick
|
||||
end)
|
||||
if onloop then
|
||||
onloop(temp,i)
|
||||
end
|
||||
end)
|
||||
function temp:setRef(ref)
|
||||
self.ref = ref
|
||||
end
|
||||
return Main
|
||||
temp.max = 40
|
||||
function temp:addItem(text, height, padding, obj)
|
||||
local padding = padding or 10
|
||||
local height = height or 30
|
||||
temp.max = temp.max + padding-- + height
|
||||
if obj then
|
||||
obj:SetDualDim(nil,temp.max-padding,nil,height,nil,nil,1)
|
||||
obj:setParent(self.first)
|
||||
end
|
||||
local c = obj or self.first:newTextLabel(text,text,0,temp.max-padding,0,height,0,0,1)
|
||||
if not obj then
|
||||
c:Mutate(temp.ref)
|
||||
end
|
||||
temp.max = temp.max + height
|
||||
c.staticpos = temp.max
|
||||
temp.list[#temp.list+1] = c
|
||||
return c
|
||||
end
|
||||
return temp
|
||||
end
|
||||
15
GuiManager/Misc/preloadImages.int
Normal file
15
GuiManager/Misc/preloadImages.int
Normal file
@ -0,0 +1,15 @@
|
||||
_GuiPro.jobqueue.OnJobCompleted(function(JOBID,n,i,t)
|
||||
if t~="PRE" then return end
|
||||
_GuiPro.imagecache[i]=n
|
||||
end)
|
||||
function gui:preloadImages(tab)
|
||||
local t
|
||||
if type(tab)=="string" then
|
||||
t = {tab}
|
||||
else
|
||||
t = tab
|
||||
end
|
||||
for i = 1,#t do
|
||||
_GuiPro.jobqueue:pushJob("LoadImage",t[i],"PRE")
|
||||
end
|
||||
end
|
||||
@ -1,24 +0,0 @@
|
||||
function gui:setHotKey(key)
|
||||
local tab=key:split("+")
|
||||
self.hotkeys=tab
|
||||
self.cooldown=false
|
||||
self.Alarm=multi:newAlarm(1)
|
||||
self.Alarm.parent=self
|
||||
self.args={}
|
||||
self.funcHK=multi:newConnection()
|
||||
self.Alarm:OnRing(function(alarm) alarm.parent.cooldown=false end)
|
||||
function self:OnHotKey(func)
|
||||
self.funcHK:connect(func)
|
||||
end
|
||||
self:OnUpdate(function(self)
|
||||
if self.cooldown then return end
|
||||
for i=1,#self.hotkeys do
|
||||
if not(love.keyboard.isDown(self.hotkeys[i])) then
|
||||
return
|
||||
end
|
||||
end
|
||||
self.cooldown=true
|
||||
self.funcHK:Fire(self)
|
||||
self.Alarm:Reset()
|
||||
end)
|
||||
end
|
||||
8
GuiManager/Misc/setMouseXY.int
Normal file
8
GuiManager/Misc/setMouseXY.int
Normal file
@ -0,0 +1,8 @@
|
||||
function gui:setMouseXY(x,y)
|
||||
if x then
|
||||
love.mouse.setX(x+self.x)
|
||||
end
|
||||
if y then
|
||||
love.mouse.setY(y+self.y)
|
||||
end
|
||||
end
|
||||
@ -1,7 +0,0 @@
|
||||
function gui:setNewFont(FontSize,filename)
|
||||
if filename then
|
||||
self.Font = love.graphics.newFont(filename, tonumber(FontSize))
|
||||
else
|
||||
self.Font=love.graphics.setNewFont(tonumber(FontSize))
|
||||
end
|
||||
end
|
||||
28
GuiManager/Text/fitFont.int
Normal file
28
GuiManager/Text/fitFont.int
Normal file
@ -0,0 +1,28 @@
|
||||
function gui:fitFont()
|
||||
local font
|
||||
if self.FontFile then
|
||||
if self.FontFile:match("ttf") then
|
||||
font = function(n)
|
||||
return love.graphics.newFont(self.FontFile, n,"normal")
|
||||
end
|
||||
else
|
||||
font = function(n)
|
||||
return love.graphics.newFont(self.FontFile, n)
|
||||
end
|
||||
end
|
||||
else
|
||||
font = function(n)
|
||||
return love.graphics.newFont(n)
|
||||
end
|
||||
end
|
||||
local Font,width,height,text=self.Font,self.width,self.height,self.text
|
||||
local s = 3
|
||||
Font = font(s)
|
||||
while Font:getHeight()<height and Font:getWidth(text)<width do
|
||||
s = s + 1
|
||||
Font = font(s)
|
||||
end
|
||||
Font = font(s - 2)
|
||||
Font:setFilter("linear","nearest",4)
|
||||
self.Font = Font
|
||||
end
|
||||
17
GuiManager/Text/newTextBase.int
Normal file
17
GuiManager/Text/newTextBase.int
Normal file
@ -0,0 +1,17 @@
|
||||
function gui:newTextBase(tp,t,name,x,y,w,h,sx,sy,sw,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase(tp,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
c.Tween=0
|
||||
c.XTween=0
|
||||
c.FontHeight=_defaultfont:getHeight()
|
||||
c.Font=_defaultfont
|
||||
c.Font:setFilter("linear","nearest",4)
|
||||
c.FontSize=15
|
||||
c.TextFormat="center"
|
||||
c.text = t
|
||||
c.AutoScaleText=false
|
||||
c.TextVisibility=1
|
||||
c.Color = {220, 220, 220}
|
||||
c.TextColor = {0, 0, 0}
|
||||
return c
|
||||
end
|
||||
@ -1,181 +1,152 @@
|
||||
function string:insert(p,s)
|
||||
return ("%s%s%s"):format(self:sub(1,p), s, self:sub(p+1))
|
||||
end
|
||||
function string:remove(p,l)
|
||||
l=l or 1
|
||||
return ("%s%s"):format(self:sub(1,p-1), self:sub(p+l))
|
||||
end
|
||||
function gui:newTextBox(t,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("TextBox",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newTextBase("TextBox",t,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local realText = {}
|
||||
local hiddenText = {}
|
||||
for i = 1,#t do
|
||||
table.insert(realText,t:sub(i,i))
|
||||
table.insert(hiddenText,t:sub(i,i))
|
||||
end
|
||||
local curpos = 1
|
||||
c.ClearOnFocus=false
|
||||
c.LoseFocusOnEnter=true
|
||||
c.Tween=0
|
||||
c.XTween=0
|
||||
c.FontHeight=_defaultfont:getHeight()
|
||||
c.Font=_defaultfont
|
||||
c.FontSize=15
|
||||
c.TextFormat="center"
|
||||
c.text = t
|
||||
c.ttext= t
|
||||
c.AutoScaleText=false
|
||||
c.TextVisibility=1
|
||||
c.Color = {220, 220, 220}
|
||||
c.TextColor = {0, 0, 0}
|
||||
c.Active=false
|
||||
c.hidden=false
|
||||
c.cursor={0,1}
|
||||
c.mark=nil
|
||||
c.arrowkeys=false
|
||||
c.hideText = false
|
||||
local funcE = {}
|
||||
local clear = true
|
||||
local Focused = false
|
||||
local autoScaleFont = false
|
||||
local moved = false
|
||||
local alarm = multi:newAlarm(.5):OnRing(function(a)
|
||||
moved = false
|
||||
end)
|
||||
function c:AutoScaleFont(bool)
|
||||
autoScaleFont = bool
|
||||
self:fitFont()
|
||||
end
|
||||
function c:ClearOnFocus(bool)
|
||||
clear = bool
|
||||
end
|
||||
c.funcF={function()
|
||||
love.keyboard.setTextInput(true,0,200,400,200)
|
||||
love.keyboard.setTextInput(true)
|
||||
end}
|
||||
c.cooldown=false
|
||||
c.cooldown2=false
|
||||
c.funcE={function()
|
||||
love.keyboard.setTextInput(false)
|
||||
end}
|
||||
function c:triggerEnter()
|
||||
for cc=1,#self.funcE do
|
||||
self.funcE[cc](self,self.ttext)
|
||||
end
|
||||
self.text=""
|
||||
self.ttext=""
|
||||
end
|
||||
c.Enter=true
|
||||
c.Alarm=multi:newAlarm(.1)
|
||||
c.Alarm.parent=c
|
||||
c.Alarm:OnRing(function(alarm) alarm.parent.cooldown=false end)
|
||||
c.Alarm2=multi:newAlarm(.5)
|
||||
c.Alarm2.parent=c
|
||||
c.Alarm2:OnRing(function(alarm) alarm.parent.cooldown2=false end)
|
||||
c.ArrowAlarm=multi:newAlarm(.1)
|
||||
c.ArrowAlarm.parent=c
|
||||
c.ArrowAlarm:OnRing(function(alarm) alarm.parent.arrowkeys=false end)
|
||||
function c:OnFocus(func)
|
||||
table.insert(self.funcF,func)
|
||||
end
|
||||
function c:OnEnter(func)
|
||||
table.insert(self.funcE,func)
|
||||
table.insert(funcE,func)
|
||||
end
|
||||
c:OnClicked(function(b,self)
|
||||
self:focus()
|
||||
end)
|
||||
function c:focus()
|
||||
for cc=1,#self.funcF do
|
||||
self.funcF[cc](self)
|
||||
end
|
||||
if self.Active==false then
|
||||
if self.ClearOnFocus==true then
|
||||
self.text=""
|
||||
self.ttext=""
|
||||
Focused = true
|
||||
love.keyboard.setKeyRepeat(true)
|
||||
love.keyboard.setTextInput(true)
|
||||
end
|
||||
function c:unfocus()
|
||||
Focused = false
|
||||
love.keyboard.setKeyRepeat(false)
|
||||
love.keyboard.setTextInput(false)
|
||||
end
|
||||
c:OnPressed(function(b,self,x,y)
|
||||
if not Focused then
|
||||
if clear then
|
||||
realText = {}
|
||||
hiddenText = {}
|
||||
curpos = 1
|
||||
end
|
||||
for tb=1,#gui.TB do
|
||||
if gui.TB[tb]~=nil then
|
||||
gui.TB[tb].Active=false
|
||||
tags:ClearOnFocus(false)
|
||||
self:focus()
|
||||
end
|
||||
moved = true
|
||||
alarm:Reset()
|
||||
local width = self.Font:getWidth(self.text)
|
||||
if x > self.x+width then
|
||||
curpos = #hiddenText+1
|
||||
elseif x < self.x then
|
||||
curpos = 1
|
||||
else
|
||||
for i = 1,#hiddenText do
|
||||
width = self.Font:getWidth(self.text:sub(1,i))
|
||||
if x-self.x < width then
|
||||
curpos = i
|
||||
break
|
||||
end
|
||||
end
|
||||
self.Active=true
|
||||
end
|
||||
end
|
||||
c:OnClicked(function(b,self,x,y)
|
||||
local dwidth, wrappedtext = _defaultfont:getWrap(self.text:sub(1,self.cursor[1]), self.width)
|
||||
local height = _defaultfont:getHeight()
|
||||
if #wrappedtext>=1 then
|
||||
width= _defaultfont:getWidth(wrappedtext[#wrappedtext])
|
||||
self.cursor[2]=#wrappedtext
|
||||
else
|
||||
self.cursor[2]=1
|
||||
width=0
|
||||
end
|
||||
yc=math.ceil(((y/self.DPI)-(self.FontHeight/2)+self.Tween-self.y)/height)
|
||||
xc=math.floor(x)
|
||||
end)
|
||||
c:AddDrawRuleE(function(self)
|
||||
if self.Active then
|
||||
local dwidth, wrappedtext = _defaultfont:getWrap(self.text:sub(1,self.cursor[1]), self.width)
|
||||
local height = _defaultfont:getHeight()
|
||||
if #wrappedtext>=1 then
|
||||
width= _defaultfont:getWidth(wrappedtext[#wrappedtext])
|
||||
self.cursor[2]=#wrappedtext
|
||||
else
|
||||
self.cursor[2]=1
|
||||
width=0
|
||||
end
|
||||
x1=width+2+self.x+self.XTween
|
||||
y1=(self.y+(height*(self.cursor[2]-1))+(self.FontHeight/2)+self.Tween)*self.DPI
|
||||
x2=width+2+self.x+self.XTween
|
||||
y2=(self.y+(self.FontHeight/2)+self.Tween*self.DPI)+height*self.cursor[2]
|
||||
love.graphics.line(x1,y1,x2,y2)
|
||||
end
|
||||
c:OnPressedOuter(function(b,self)
|
||||
if Focused then
|
||||
self:unfocus()
|
||||
end
|
||||
end)
|
||||
c:OnUpdate(function(self)
|
||||
if love.keyboard.isDown("backspace") and self.Active and self.cooldown==false then
|
||||
if #self.text>0 then
|
||||
self.text = self.text:remove(self.cursor[1])
|
||||
self.ttext = self.ttext:remove(self.cursor[1])
|
||||
self.cursor[1]=self.cursor[1]-1
|
||||
end
|
||||
self.cooldown=true
|
||||
self.Alarm:Reset()
|
||||
elseif love.keyboard.isDown("backspace")==false then
|
||||
self.cooldown=false
|
||||
if #hiddenText==0 then self.text = "" return end
|
||||
if self.hideText then
|
||||
self.text = table.concat(hiddenText)
|
||||
else
|
||||
self.text = table.concat(realText)
|
||||
end
|
||||
if love.keyboard.isDown("left") and self.arrowkeys==false and self.Active then
|
||||
self.arrowkeys=true
|
||||
self.cursor[1]=self.cursor[1]-1
|
||||
if self.cursor[1]<0 then
|
||||
self.cursor[1]=0
|
||||
end
|
||||
self.ArrowAlarm:Reset()
|
||||
elseif love.keyboard.isDown("right") and self.arrowkeys==false and self.Active then
|
||||
self.arrowkeys=true
|
||||
self.cursor[1]=self.cursor[1]+1
|
||||
if self.cursor[1]>#self.text then
|
||||
self.cursor[1]=#self.text
|
||||
end
|
||||
self.ArrowAlarm:Reset()
|
||||
end
|
||||
if love.keyboard.isDown("delete") and self.Active then
|
||||
if #self.text>0 then
|
||||
self.text = ""
|
||||
self.ttext = ""
|
||||
self.cursor[1]=1
|
||||
end
|
||||
elseif (love.keyboard.isDown("lshift") or love.keyboard.isDown("rshift")) and love.keyboard.isDown("return") and self.cooldown2==false then
|
||||
self.text=self.text.."\n"
|
||||
self.ttext=self.ttext.."\n"
|
||||
self.cooldown2=true
|
||||
c.Alarm2:Reset()
|
||||
elseif (love.keyboard.isDown("return") or love.keyboard.isDown("kpenter")) and self.Active and self.Enter and not(love.keyboard.isDown("lshift") or love.keyboard.isDown("rshift")) then
|
||||
if self.LoseFocusOnEnter then
|
||||
self.Active=false
|
||||
else
|
||||
self.Active=true
|
||||
end
|
||||
for cc=1,#self.funcE do
|
||||
self.funcE[cc](self,self.ttext)
|
||||
end
|
||||
self.TextFormat = "left"
|
||||
end)
|
||||
multi.OnTextInput(function(t)
|
||||
table.insert(hiddenText,curpos,"*")
|
||||
table.insert(realText,curpos,t)
|
||||
curpos = curpos + 1
|
||||
if autoScaleFont then
|
||||
c:fitFont()
|
||||
end
|
||||
end)
|
||||
table.insert(gui.TB,c)
|
||||
return c
|
||||
end
|
||||
--TEXT BOX HELPER FUNCTION
|
||||
function love.textinput(t)
|
||||
for tb=1,#gui.TB do
|
||||
if gui.TB[tb]~=nil then
|
||||
if gui.TB[tb].Active then
|
||||
if gui.TB[tb].hidden then
|
||||
--gui.TB[tb].text=gui.TB[tb].text.."*"
|
||||
gui.TB[tb].text=gui.TB[tb].text:insert(gui.TB[tb].cursor[1],"*")
|
||||
else
|
||||
--gui.TB[tb].text=gui.TB[tb].text..t
|
||||
gui.TB[tb].text=gui.TB[tb].text:insert(gui.TB[tb].cursor[1],t)
|
||||
end
|
||||
gui.TB[tb].ttext=gui.TB[tb].ttext:insert(gui.TB[tb].cursor[1],t)
|
||||
gui.TB[tb].cursor[1]=gui.TB[tb].cursor[1]+1
|
||||
multi.OnKeyPressed(function(key, scancode, isrepeat )
|
||||
if key == "backspace" then
|
||||
table.remove(hiddenText,curpos-1)
|
||||
table.remove(realText,curpos-1)
|
||||
curpos = curpos - 1
|
||||
if curpos < 1 then
|
||||
curpos = 1
|
||||
end
|
||||
if autoScaleFont then
|
||||
c:fitFont()
|
||||
end
|
||||
elseif key == "enter" then
|
||||
|
||||
elseif key == "delete" then
|
||||
realText = {}
|
||||
hiddenText = {}
|
||||
curpos = 1
|
||||
elseif key == "left" then
|
||||
curpos = curpos - 1
|
||||
if curpos < 1 then
|
||||
curpos = 1
|
||||
end
|
||||
moved = true
|
||||
alarm:Reset()
|
||||
elseif key == "right" then
|
||||
curpos = curpos + 1
|
||||
if curpos > #realText+1 then
|
||||
curpos = #realText+1
|
||||
end
|
||||
moved = true
|
||||
alarm:Reset()
|
||||
end
|
||||
end)
|
||||
local blink = false
|
||||
multi:newThread("TextCursonBlinker",function()
|
||||
while true do
|
||||
thread.sleep(1.5)
|
||||
blink = not blink
|
||||
end
|
||||
end)
|
||||
self.DrawRulesE = {function()
|
||||
if --[[blink or moved]] true then
|
||||
local width = c.Font:getWidth(c.text:sub(1,curpos-1))
|
||||
local height = c.Font:getHeight()
|
||||
if c.TextFormat == "center" then
|
||||
-- print(c.x+(c.width/2+width),c.height,c.x+(c.width/2+width),c.height+height)
|
||||
-- love.graphics.line(c.x+(c.width/2+width),c.height,c.x+(c.width/2+width),c.height+height)
|
||||
elseif c.TextFormat == "right" then
|
||||
--love.graphics.line(c.x+width,c.y,c.x+width,c.y+c.Font:getHeight())
|
||||
elseif c.TextFormat == "left" then
|
||||
love.graphics.line(c.x+width,c.y,c.x+width,c.y+height)
|
||||
end
|
||||
end
|
||||
end
|
||||
end}
|
||||
return c
|
||||
end
|
||||
@ -1,21 +1,10 @@
|
||||
function gui:newTextButton(t,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("TextButton",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
c.Tween=0
|
||||
c.XTween=0
|
||||
c.FontHeight=_defaultfont:getHeight()
|
||||
c.Font=_defaultfont
|
||||
c.FontSize=15
|
||||
c.TextFormat="center"
|
||||
c.text = t
|
||||
c.AutoScaleText=false
|
||||
c.TextVisibility=1 -- 0=invisible,1=solid (self.TextVisibility*254+1)
|
||||
c.Color = {220, 220, 220}
|
||||
c.TextColor = {0, 0, 0}
|
||||
c:OnEnter(function()
|
||||
local x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newTextBase("TextButton",t,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
c:OnMouseEnter(function()
|
||||
love.mouse.setCursor(_GuiPro.CursorH)
|
||||
end)
|
||||
c:OnExit(function()
|
||||
c:OnMouseExit(function()
|
||||
love.mouse.setCursor(_GuiPro.CursorN)
|
||||
end)
|
||||
return c
|
||||
|
||||
@ -1,16 +1,4 @@
|
||||
function gui:newTextLabel(t,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("TextLabel",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
c.Tween=0
|
||||
c.XTween=0
|
||||
c.FontHeight=_defaultfont:getHeight()
|
||||
c.Font=_defaultfont
|
||||
c.FontSize=15
|
||||
c.TextFormat="center"
|
||||
c.text = t
|
||||
c.AutoScaleText=false
|
||||
c.TextVisibility=1 -- 0=invisible,1=solid (self.TextVisibility*254+1)
|
||||
c.Color = {220, 220, 220}
|
||||
c.TextColor = {0, 0, 0}
|
||||
return c
|
||||
local x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
return self:newTextBase("TextLabel",t,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
end
|
||||
9
GuiManager/Text/setNewFont.int
Normal file
9
GuiManager/Text/setNewFont.int
Normal file
@ -0,0 +1,9 @@
|
||||
function gui:setNewFont(filename,FontSize)
|
||||
if type(filename)=="string" then
|
||||
self.FontFile = filename
|
||||
self.Font = love.graphics.newFont(filename, tonumber(FontSize))
|
||||
else
|
||||
self.Font=love.graphics.newFont(tonumber(filename))
|
||||
end
|
||||
self.Font:setFilter("linear","nearest",4)
|
||||
end
|
||||
@ -1,9 +1,34 @@
|
||||
local multi = require("multi")
|
||||
local GLOBAL,THREAD=require("multi.integration.loveManager").init()
|
||||
-- automatic resource loading will be added soonish
|
||||
utf8 = require("utf8")
|
||||
gui = {}
|
||||
gui.__index = gui
|
||||
gui.TB={}
|
||||
gui.Version="VERSION" -- Is it really ready for release?
|
||||
_GuiPro={GBoost=true,hasDrag=false,DragItem={},Children={},Visible=true,count=0,x=0,y=0,height=0,width=0,update=function(self) local things=GetAllChildren2(self) UpdateThings(things) end,draw=function(self) local things=GetAllChildren(self) DrawThings(things) end,getChildren=function(self) return self.Children end}
|
||||
_GuiPro={
|
||||
GLOBAL = GLOBAL,
|
||||
THREAD = THREAD,
|
||||
jobqueue = multi:newSystemThreadedJobQueue(4),
|
||||
imagecache = {},
|
||||
GBoost=true,
|
||||
hasDrag=false,
|
||||
DragItem={},
|
||||
Children={},
|
||||
Visible=true,
|
||||
count=0,
|
||||
x=0,
|
||||
y=0,
|
||||
height=0,
|
||||
width=0,
|
||||
getChildren=function(self)
|
||||
return self.Children
|
||||
end
|
||||
}
|
||||
_GuiPro.jobqueue:registerJob("LoadImage",function(path,t)
|
||||
local dat = love.image.newImageData(path)
|
||||
return dat,path,t
|
||||
end)
|
||||
_GuiPro.Clips={}
|
||||
_GuiPro.rotate=0
|
||||
_defaultfont = love.graphics.setNewFont(12)
|
||||
@ -16,8 +41,7 @@ function gui:LoadInterface(file)
|
||||
if a then
|
||||
--print("Loaded: "..file)
|
||||
else
|
||||
print("Error loading file: "..file)
|
||||
print(a,b)
|
||||
print("Error loading file: "..file,b)
|
||||
end
|
||||
else
|
||||
print("File does not exist!")
|
||||
@ -42,14 +66,18 @@ gui.LoadAll("GuiManager/Misc")
|
||||
gui.LoadAll("GuiManager/Text")
|
||||
gui.LoadAll("GuiManager/Drawing")
|
||||
|
||||
multi.boost=2
|
||||
-- End of Load
|
||||
gui:respectHierarchy()
|
||||
_GuiPro.width,_GuiPro.height=love.graphics.getDimensions()
|
||||
multi:newLoop():OnLoop(function() _GuiPro.width,_GuiPro.height=love.graphics.getDimensions() _GuiPro:update() end)
|
||||
multi:onDraw(function() _GuiPro:draw() end)
|
||||
multi:newLoop(function() _GuiPro.width,_GuiPro.height=love.graphics.getDimensions() end)
|
||||
multi:onDraw(function()
|
||||
local items=GetAllChildren(_GuiPro)
|
||||
for i=1,#items do
|
||||
items[i]:draw()
|
||||
end
|
||||
end)
|
||||
gui.ff=gui:newFrame("",0,0,0,0,0,0,1,1)
|
||||
gui.ff.Color={255,255,255}
|
||||
gui.ff.Color={0,0,0}
|
||||
gui.ff:OnUpdate(function(self)
|
||||
self:BottomStack()
|
||||
end)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user