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 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)
if not self.clickEvnt then
self.clickEvnt = true
self._connClicked = multi:newConnection()
self._connClicked(func)
multi:newThread(self.Name.."_Updater",function()
self:addConn(self._connClicked(func))
self:addThread(multi:newThread(self.Name.."_Updater",function()
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
self._connClicked:Fire("1",self,love.mouse.getX()-self.x,love.mouse.getY()-self.y)
end
@ -27,66 +33,66 @@ function gui:OnClicked(func)
thread.kill()
end
end
end)
end))
else
self._connClicked(func)
self:addConn(self._connClicked(func))
end
end
function gui:OnPressed(func)
multi.OnMousePressed(function(x,y,b)
self:addConn(multi.OnMousePressed(function(x,y,b)
if self:canPress() then
func(buttonConv[b],self,x,y)
end
end)
end))
end
function gui:OnPressedOuter(func)
multi.OnMousePressed(function(x,y,b)
self:addConn(multi.OnMousePressed(function(x,y,b)
if not(self:canPress()) then
func(buttonConv[b],self)
end
end,nil,1)
end,nil,1))
end
function gui:OnReleased(func)
multi.OnMouseReleased(function(x,y,b)
self:addConn(multi.OnMouseReleased(function(x,y,b)
if self:canPress() then
func(buttonConv[b],self,x,y)
end
end)
end))
end
function gui:OnReleasedOuter(func)
multi.OnMouseReleased(function(x,y,b)
self:addConn(multi.OnMouseReleased(function(x,y,b)
if not(self:canPress()) then
func(buttonConv[b],self)
end
end,nil,1)
end,nil,1))
end
function gui:OnUpdate(func)
if not self.updateEvnt then
self._connUpdate = multi:newConnection()
self._connUpdate(func)
self:addConn(self._connUpdate(func))
self.updateEvnt = true
multi:newThread(self.Name.."_Updater",function()
self:addThread(multi:newThread(self.Name.."_Updater",function()
while true do
thread.hold(function() return self.Active end)
self._connUpdate:Fire(self)
end
end)
end))
else
self._connUpdate(func)
self:addConn(self._connUpdate(func))
end
end
function gui:OnMouseMoved(func)
multi.OnMouseMoved(function(x,y,dx,dy)
self:addConn(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,nil,1))
end
gui.WhileHovering=gui.OnMouseMoved -- To keep older features working
local mbenter = multi:newConnection()
function gui:OnMouseEnter(func)
self.HE=false
mbenter(func)
self:addConn(mbenter(func))
self:OnMouseMoved(function()
if self.HE == false then
self.HE=true
@ -98,10 +104,10 @@ end
function gui:OnMouseExit(func)
if not self.exitEvnt then
self._connExit = multi:newConnection()
self._connExit(func)
self:addConn(self._connExit(func))
self.exitEvnt = true
self.HE=false
multi:newThread(self.Name.."_OnExit",function()
self:addThread(multi:newThread(self.Name.."_OnExit",function()
while true do
thread.hold(function() return self.HE or self.Destroyed end)
if not(self:canPress()) then
@ -112,22 +118,17 @@ function gui:OnMouseExit(func)
thread.kill()
end
end
end)
end))
else
self._connExit(func)
self:addConn(self._connExit(func))
end
end
--[[
x=(love.mouse.getX()-self.x)
y=(love.mouse.getY()-self.y)
self:Move(x,y)
]]
function gui:OnMouseWheelMoved(func)
multi.OnMouseWheelMoved(function(...)
self:addConn(multi.OnMouseWheelMoved(function(...)
if self:canPress() then
func(self,...)
end
end)
end))
end
function gui:enableDragging(bool)
self.draggable = bool
@ -154,48 +155,48 @@ function gui:enableDragging(bool)
self._connDragging:Fire(self)
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
self.hasDrag = false
startX = nil
startY = nil
self._connDragEnd:Fire(self)
end)
end))
end
function gui:OnDragStart(func)
if not self.dragEvnt then
self:enableDragging(true)
self._connDragStart(func)
self:addConn(self._connDragStart(func))
else
self._connDragStart(func)
self:addConn(self._connDragStart(func))
end
end
function gui:OnDragging(func)
if not self.dragEvnt then
self:enableDragging(true)
self._connDragging(func)
self:addConn(self._connDragging(func))
else
self._connDragging(func)
self:addConn(self._connDragging(func))
end
end
function gui:OnDragEnd(func)
if not self.dragEvnt then
self:enableDragging(true)
self._connDragEnd(func)
self:addConn(self._connDragEnd(func))
else
self._connDragEnd(func)
self:addConn(self._connDragEnd(func))
end
end
function gui:OnHotKey(key,func)
local tab=key:split("+")
multi.OnKeyPressed(function()
self:addConn(multi.OnKeyPressed(function()
for i=1,#tab do
if not(love.keyboard.isDown(tab[i])) then
return
end
end
func(self)
end)
end))
end
gui.addHotKey=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()
x, y, w, h=c.DPI*x,c.DPI*y,c.DPI*w,c.DPI*h
end
c.threads = {}
c.conns = {}
c.centerFontY=true
c.FormFactor="rectangle"
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)
app.workspace.Color = Color.Black
app.menu.Visible = false
local search = app.createPage("Search","search")
local favs = app.createPage("Favorites","favs")
search:Goto()
--app.createPage("Favorites","favs")
app.workspace.search = app.createPage("Search","search")
app.workspace.view, app.workspace.button = app.createPage("Viewer","view")
--app.workspace.button.Visible = false
app.workspace.search:Goto()
end
return {
init = init

View File

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

View File

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

View File

@ -179,7 +179,7 @@ function multi:newSystemThreadedJobQueue(n)
queueReturn:push(tab)
end
end
end).OnError(function(...)
end):OnError(function(...)
error(...)
end)
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 {}
end
end
local function init(page,workspace)
local favs = getFavs()
local holder = page:newFrame("",15,80,-30,-95,0,0,1,1)
@ -86,6 +87,14 @@ local function init(page,workspace)
mangaViewer.Visible = false
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
function setViewer(manga)
menu:reset()
@ -124,10 +133,11 @@ local function init(page,workspace)
menu.header.Color = theme.header
menu.ref = {
[[setRoundness(5,5,30)]],
[[OnReleased(MenuItem)]],
Color = theme.menuitem
}
for i,v in ipairs(manga.Chapters) do
menu:addItem(v.Lead, 20, 3)
menu:addItem(v.Lead, 20, 3).chapter = v
end
end
function addManga(manga,v)
@ -212,9 +222,7 @@ local function init(page,workspace)
end
for i,v in pairs(favs) do
thread.yield()
print(v.Title,v.Link)
mangaReader.getManga(v).connect(function(manga)
print(manga.Title)
addManga(manga,{Title=manga.Title,Link=manga.Link})
end)
end
@ -236,7 +244,6 @@ local function init(page,workspace)
end
for i,v in pairs(list) do
thread.yield()
print(v)
mangaReader.getManga(v).connect(function(manga)
addManga(manga,{Title=manga.Title,Link=manga.Link})
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
}