Almost stable

This commit is contained in:
Ryan Ward 2020-02-18 21:01:55 -05:00
parent 7ac51cb6e5
commit ae9f731c0d
11 changed files with 168 additions and 121 deletions

View File

@ -0,0 +1,32 @@
-- More work needs to be done tbh
function gui:_Destroy()
for i,v in pairs(self) do
self.Children={}
end
for i,v in pairs(self.threads) do
v:Kill()
end
for i,v in pairs(self.conns) do
v:Destroy()
end
self.Visible = false
self.Active = false
end
function gui:Destroy()
check=self.Parent:getChildren()
local objs = GetAllChildren(self)
local cc=0
for cc=1,#check do
if check[cc]==self then
table.remove(self.Parent.Children,cc)
end
end
self.Destroyed = true
if #self.Parent.Children==0 then
self.Parent.isLeaf = true
end
for i,v in pairs(objs) do
v:_Destroy()
end
self:_Destroy()
end

View File

@ -1,13 +1,19 @@
local multi, thread = require("multi").init() local multi, thread = require("multi").init()
local buttonConv = {"l","r","m","x1","x2"} -- For the old stuff local buttonConv = {"l","r","m","x1","x2"} -- For the old stuff
function gui:addThread(t)
table.insert(self.threads,t)
end
function gui:addConn(t)
table.insert(self.conns,t)
end
function gui:OnClicked(func) function gui:OnClicked(func)
if not self.clickEvnt then if not self.clickEvnt then
self.clickEvnt = true self.clickEvnt = true
self._connClicked = multi:newConnection() self._connClicked = multi:newConnection()
self._connClicked(func) self:addConn(self._connClicked(func))
multi:newThread(self.Name.."_Updater",function() self:addThread(multi:newThread(self.Name.."_Updater",function()
while true do while true do
thread.hold(function() return self.Active or self.Destroyed end) thread.hold(function() return self.Active or not self.Destroyed end)
if love.mouse.isDown(1) and self:canPress() then if love.mouse.isDown(1) and self:canPress() then
self._connClicked:Fire("1",self,love.mouse.getX()-self.x,love.mouse.getY()-self.y) self._connClicked:Fire("1",self,love.mouse.getX()-self.x,love.mouse.getY()-self.y)
end end
@ -27,66 +33,66 @@ function gui:OnClicked(func)
thread.kill() thread.kill()
end end
end end
end) end))
else else
self._connClicked(func) self:addConn(self._connClicked(func))
end end
end end
function gui:OnPressed(func) function gui:OnPressed(func)
multi.OnMousePressed(function(x,y,b) self:addConn(multi.OnMousePressed(function(x,y,b)
if self:canPress() then if self:canPress() then
func(buttonConv[b],self,x,y) func(buttonConv[b],self,x,y)
end end
end) end))
end end
function gui:OnPressedOuter(func) function gui:OnPressedOuter(func)
multi.OnMousePressed(function(x,y,b) self:addConn(multi.OnMousePressed(function(x,y,b)
if not(self:canPress()) then if not(self:canPress()) then
func(buttonConv[b],self) func(buttonConv[b],self)
end end
end,nil,1) end,nil,1))
end end
function gui:OnReleased(func) function gui:OnReleased(func)
multi.OnMouseReleased(function(x,y,b) self:addConn(multi.OnMouseReleased(function(x,y,b)
if self:canPress() then if self:canPress() then
func(buttonConv[b],self,x,y) func(buttonConv[b],self,x,y)
end end
end) end))
end end
function gui:OnReleasedOuter(func) function gui:OnReleasedOuter(func)
multi.OnMouseReleased(function(x,y,b) self:addConn(multi.OnMouseReleased(function(x,y,b)
if not(self:canPress()) then if not(self:canPress()) then
func(buttonConv[b],self) func(buttonConv[b],self)
end end
end,nil,1) end,nil,1))
end end
function gui:OnUpdate(func) function gui:OnUpdate(func)
if not self.updateEvnt then if not self.updateEvnt then
self._connUpdate = multi:newConnection() self._connUpdate = multi:newConnection()
self._connUpdate(func) self:addConn(self._connUpdate(func))
self.updateEvnt = true self.updateEvnt = true
multi:newThread(self.Name.."_Updater",function() self:addThread(multi:newThread(self.Name.."_Updater",function()
while true do while true do
thread.hold(function() return self.Active end) thread.hold(function() return self.Active end)
self._connUpdate:Fire(self) self._connUpdate:Fire(self)
end end
end) end))
else else
self._connUpdate(func) self:addConn(self._connUpdate(func))
end end
end end
function gui:OnMouseMoved(func) function gui:OnMouseMoved(func)
multi.OnMouseMoved(function(x,y,dx,dy) self:addConn(multi.OnMouseMoved(function(x,y,dx,dy)
if self:canPress() then if self:canPress() then
func(self,x-self.x,y-self.y,dx,dy) func(self,x-self.x,y-self.y,dx,dy)
end end
end,nil,1) end,nil,1))
end end
gui.WhileHovering=gui.OnMouseMoved -- To keep older features working gui.WhileHovering=gui.OnMouseMoved -- To keep older features working
local mbenter = multi:newConnection() local mbenter = multi:newConnection()
function gui:OnMouseEnter(func) function gui:OnMouseEnter(func)
self.HE=false self.HE=false
mbenter(func) self:addConn(mbenter(func))
self:OnMouseMoved(function() self:OnMouseMoved(function()
if self.HE == false then if self.HE == false then
self.HE=true self.HE=true
@ -98,10 +104,10 @@ end
function gui:OnMouseExit(func) function gui:OnMouseExit(func)
if not self.exitEvnt then if not self.exitEvnt then
self._connExit = multi:newConnection() self._connExit = multi:newConnection()
self._connExit(func) self:addConn(self._connExit(func))
self.exitEvnt = true self.exitEvnt = true
self.HE=false self.HE=false
multi:newThread(self.Name.."_OnExit",function() self:addThread(multi:newThread(self.Name.."_OnExit",function()
while true do while true do
thread.hold(function() return self.HE or self.Destroyed end) thread.hold(function() return self.HE or self.Destroyed end)
if not(self:canPress()) then if not(self:canPress()) then
@ -112,22 +118,17 @@ function gui:OnMouseExit(func)
thread.kill() thread.kill()
end end
end end
end) end))
else else
self._connExit(func) self:addConn(self._connExit(func))
end end
end end
--[[
x=(love.mouse.getX()-self.x)
y=(love.mouse.getY()-self.y)
self:Move(x,y)
]]
function gui:OnMouseWheelMoved(func) function gui:OnMouseWheelMoved(func)
multi.OnMouseWheelMoved(function(...) self:addConn(multi.OnMouseWheelMoved(function(...)
if self:canPress() then if self:canPress() then
func(self,...) func(self,...)
end end
end) end))
end end
function gui:enableDragging(bool) function gui:enableDragging(bool)
self.draggable = bool self.draggable = bool
@ -154,48 +155,48 @@ function gui:enableDragging(bool)
self._connDragging:Fire(self) self._connDragging:Fire(self)
end end
end) end)
multi.OnMouseReleased(function(x,y,b) self:addConn(multi.OnMouseReleased(function(x,y,b)
if buttonConv[b]~=self.dragbut or not(self.draggable) or not(self.hasDrag) then return end if buttonConv[b]~=self.dragbut or not(self.draggable) or not(self.hasDrag) then return end
self.hasDrag = false self.hasDrag = false
startX = nil startX = nil
startY = nil startY = nil
self._connDragEnd:Fire(self) self._connDragEnd:Fire(self)
end) end))
end end
function gui:OnDragStart(func) function gui:OnDragStart(func)
if not self.dragEvnt then if not self.dragEvnt then
self:enableDragging(true) self:enableDragging(true)
self._connDragStart(func) self:addConn(self._connDragStart(func))
else else
self._connDragStart(func) self:addConn(self._connDragStart(func))
end end
end end
function gui:OnDragging(func) function gui:OnDragging(func)
if not self.dragEvnt then if not self.dragEvnt then
self:enableDragging(true) self:enableDragging(true)
self._connDragging(func) self:addConn(self._connDragging(func))
else else
self._connDragging(func) self:addConn(self._connDragging(func))
end end
end end
function gui:OnDragEnd(func) function gui:OnDragEnd(func)
if not self.dragEvnt then if not self.dragEvnt then
self:enableDragging(true) self:enableDragging(true)
self._connDragEnd(func) self:addConn(self._connDragEnd(func))
else else
self._connDragEnd(func) self:addConn(self._connDragEnd(func))
end end
end end
function gui:OnHotKey(key,func) function gui:OnHotKey(key,func)
local tab=key:split("+") local tab=key:split("+")
multi.OnKeyPressed(function() self:addConn(multi.OnKeyPressed(function()
for i=1,#tab do for i=1,#tab do
if not(love.keyboard.isDown(tab[i])) then if not(love.keyboard.isDown(tab[i])) then
return return
end end
end end
func(self) func(self)
end) end))
end end
gui.addHotKey=gui.OnHotKey gui.addHotKey=gui.OnHotKey
gui.setHotKey=gui.OnHotKey gui.setHotKey=gui.OnHotKey

View File

@ -48,6 +48,8 @@ function gui:newBase(tp,name, x, y, w, h, sx ,sy ,sw ,sh)
c.DPI=love.window.getPixelScale() c.DPI=love.window.getPixelScale()
x, y, w, h=c.DPI*x,c.DPI*y,c.DPI*w,c.DPI*h x, y, w, h=c.DPI*x,c.DPI*y,c.DPI*w,c.DPI*h
end end
c.threads = {}
c.conns = {}
c.centerFontY=true c.centerFontY=true
c.FormFactor="rectangle" c.FormFactor="rectangle"
c.Type=tp c.Type=tp

View File

@ -1,13 +0,0 @@
function gui:Destroy()
check=self.Parent:getChildren()
local cc=0
for cc=1,#check do
if check[cc]==self then
table.remove(self.Parent.Children,cc)
end
end
self.Destroyed = true
if #self.Parent.Children==0 then
self.Parent.isLeaf = true
end
end

View File

@ -64,10 +64,10 @@ local function init(a)
end) end)
app.workspace.Color = Color.Black app.workspace.Color = Color.Black
app.menu.Visible = false app.menu.Visible = false
local search = app.createPage("Search","search") app.workspace.search = app.createPage("Search","search")
local favs = app.createPage("Favorites","favs") app.workspace.view, app.workspace.button = app.createPage("Viewer","view")
search:Goto() --app.workspace.button.Visible = false
--app.createPage("Favorites","favs") app.workspace.search:Goto()
end end
return { return {
init = init init = init

View File

@ -54,34 +54,31 @@ m.getManga = queue:newFunction("queue",function(title)
return tab return tab
end) end)
m.getImage = queue:newFunction("getImage",function(pageurl) m.getImage = queue:newFunction("getImage",function(pageurl)
local http = require("socket.http")
local page = http.request(pageurl) local page = http.request(pageurl)
return page:match([[id="imgholder.-src="([^"]*)]]) return page:match([[id="imgholder.-src="([^"]*)]])
end) end)
m._getPages = queue:newFunction("getPages",function(manga,chapter) m._getPages = queue:newFunction("getPages",function(Link)
local http = require("socket.http")
local tab = {} local tab = {}
local page = http.request(manga.Chapters[chapter].Link) local page = http.request(Link)
tab.pages = {page:match([[id="imgholder.-src="([^"]*)]])} tab.pages = {}
tab.nextChapter = "http://www.mangareader.net"..page:match([[Next Chapter:.-href="([^"]*)]]) tab.nextChapter = "http://www.mangareader.net"..page:match([[Next Chapter:.-href="([^"]*)]])
for link,page in page:gmatch([[<option value="([^"]*)">(%d*)</option>]]) do for link,page in page:gmatch([[<option value="([^"]*)">(%d*)</option>]]) do
table.insert(tab.pages,getImage("http://www.mangareader.net"..link)) table.insert(tab.pages,"http://www.mangareader.net"..link)
end end
return tab return tab
end) end)
-- returns pages -- returns pages
m.getPages = function(manga,chapter) m.getPages = function(chapter)
local http = require("socket.http") local http = require("socket.http")
local tab = {} local tab = {}
local page = http.request(manga.Chapters[chapter].Link) local page = http.request(chapter.Link)
tab.pages = {page:match([[id="imgholder.-src="([^"]*)]])} tab.pages = {chapter.Link}
tab.nextChapter = "http://www.mangareader.net"..page:match([[Next Chapter:.-href="([^"]*)]]) tab.nextChapter = "http://www.mangareader.net"..page:match([[Next Chapter:.-href="([^"]*)]])
for link,page in page:gmatch([[<option value="([^"]*)">(%d*)</option>]]) do for link,page in page:gmatch([[<option value="([^"]*)">(%d*)</option>]]) do
m._getPages("http://www.mangareader.net"..link).connect(function(link) table.insert(tab.pages,"http://www.mangareader.net"..link)
table.insert(tab.pages,link)
end)
end end
thread.hold(function() return tab.pages
return done
end)
return tab
end end
return m return m

View File

@ -783,8 +783,13 @@ function multi:newConnection(protect,func,kill)
c.lock = false c.lock = false
setmetatable(c,{__call=function(self,...) setmetatable(c,{__call=function(self,...)
local t = ... local t = ...
if type(t)=="table" and t.Type ~= nil then if type(t)=="table" then
return self:Fire(args,select(2,...)) for i,v in pairs(t) do
if v==self then
return self:Fire(...)
end
end
return self:connect(...)
else else
return self:connect(...) return self:connect(...)
end end
@ -1559,41 +1564,18 @@ function multi:newThread(name,func,...)
if type(name) == "function" then if type(name) == "function" then
name = "Thread#"..threadCount name = "Thread#"..threadCount
end end
-- local env = {} local env = {}
-- setmetatable(env,{ setmetatable(env,{
-- __index = Gref, __index = Gref,
-- __newindex = function(t,k,v) __newindex = function(t,k,v)
-- if type(v)=="function" then if type(v)=="function" then
-- rawset(t,k,thread:newFunction(v)) rawset(t,k,thread:newFunction(v))
-- else else
-- if type(v)=="table" then Gref[k]=v
-- if v.isTFunc then end
-- if not _G["_stack_"] or #_G["_stack_"]==0 then end
-- _G["_stack_"] = {} })
-- local s = _G["_stack_"] setfenv(func,env)
-- local a,b,c,d,e,f,g = v.wait(true)
-- table.insert(s,a)
-- table.insert(s,b)
-- table.insert(s,c)
-- table.insert(s,d)
-- table.insert(s,e)
-- table.insert(s,f)
-- local x = table.remove(_G["_stack_"])
-- rawset(t,k,x)
-- else
-- local x = table.remove(_G["_stack_"])
-- rawset(t,k,x)
-- end
-- else
-- Gref[k]=v
-- end
-- else
-- Gref[k]=v
-- end
-- end
-- end
-- })
-- setfenv(func,env)
local c={} local c={}
c.TempRets = {nil,nil,nil,nil,nil,nil,nil,nil,nil,nil} c.TempRets = {nil,nil,nil,nil,nil,nil,nil,nil,nil,nil}
c.startArgs = {...} c.startArgs = {...}

View File

@ -179,7 +179,7 @@ function multi:newSystemThreadedJobQueue(n)
queueReturn:push(tab) queueReturn:push(tab)
end end
end end
end).OnError(function(...) end):OnError(function(...)
error(...) error(...)
end) end)
multi:newThread("Idler",function() multi:newThread("Idler",function()

View File

@ -1,7 +0,0 @@
local function init(page)
page.Color = Color.new("7c2d5b")
return page
end
return {
init = init
}

View File

@ -63,6 +63,7 @@ function getFavs()
return {} return {}
end end
end end
local function init(page,workspace) local function init(page,workspace)
local favs = getFavs() local favs = getFavs()
local holder = page:newFrame("",15,80,-30,-95,0,0,1,1) local holder = page:newFrame("",15,80,-30,-95,0,0,1,1)
@ -86,6 +87,14 @@ local function init(page,workspace)
mangaViewer.Visible = false mangaViewer.Visible = false
end) end)
end) end)
function MenuItem(b,self)
multi:newThread(function()
thread.sleep(.1)
mangaViewer.Visible = false
end)
workspace.view:Goto()
workspace.view.doChapter(self.chapter)
end
goback.Color = theme.button goback.Color = theme.button
function setViewer(manga) function setViewer(manga)
menu:reset() menu:reset()
@ -124,10 +133,11 @@ local function init(page,workspace)
menu.header.Color = theme.header menu.header.Color = theme.header
menu.ref = { menu.ref = {
[[setRoundness(5,5,30)]], [[setRoundness(5,5,30)]],
[[OnReleased(MenuItem)]],
Color = theme.menuitem Color = theme.menuitem
} }
for i,v in ipairs(manga.Chapters) do for i,v in ipairs(manga.Chapters) do
menu:addItem(v.Lead, 20, 3) menu:addItem(v.Lead, 20, 3).chapter = v
end end
end end
function addManga(manga,v) function addManga(manga,v)
@ -212,9 +222,7 @@ local function init(page,workspace)
end end
for i,v in pairs(favs) do for i,v in pairs(favs) do
thread.yield() thread.yield()
print(v.Title,v.Link)
mangaReader.getManga(v).connect(function(manga) mangaReader.getManga(v).connect(function(manga)
print(manga.Title)
addManga(manga,{Title=manga.Title,Link=manga.Link}) addManga(manga,{Title=manga.Title,Link=manga.Link})
end) end)
end end
@ -236,7 +244,6 @@ local function init(page,workspace)
end end
for i,v in pairs(list) do for i,v in pairs(list) do
thread.yield() thread.yield()
print(v)
mangaReader.getManga(v).connect(function(manga) mangaReader.getManga(v).connect(function(manga)
addManga(manga,{Title=manga.Title,Link=manga.Link}) addManga(manga,{Title=manga.Title,Link=manga.Link})
end) end)

46
pages/view.lua Normal file
View File

@ -0,0 +1,46 @@
local mangaReader = require("manga")
local function init(page)
local holder
local masterI
page:OnMouseWheelMoved(function(self,x,y)
holder:Move(0,y*60)
end)
function buildPages(img,i)
masterI = masterI + 1
local temp = holder:newImageLabel(nil,0,(masterI-1)*1210,800,1200)
temp:SetImage(img)
temp:centerX()
return temp
end
queuePages = thread:newFunction(function(list)
local last
for i = 1,#list do
local img = mangaReader.getImage(list[i]).wait()
last = buildPages(img,i)
end
last:OnUpdate(function()
if last.loaded then return end
if last.y<_GuiPro.height then
last.loaded = true
local pages = mangaReader.getPages(list.nextChapter)
queuePages(pages).wait()
end
end)
end)
page.doChapter = thread:newFunction(function(chapter)
masterI = 0
if holder then
holder:Destroy()
else
holder = page:newFrame("",15,80,-30,-95,0,0,1,1)
end
holder.Visibility = 0
holder.BorderSize = 0
local pages = mangaReader.getPages(chapter)
print(queuePages(pages).wait())
end)
return page
end
return {
init = init
}