From 59aa44c54495e0231e19ea2286f03f125bc8f1ca Mon Sep 17 00:00:00 2001 From: Josef Patoprsty Date: Sat, 7 Sep 2013 18:28:48 -0400 Subject: [PATCH] Adds Downloads tab Closes #91 Thanks @leafo for async tip! Thanks ThatTreeOverThere for making me think! --- src/core/ui.lua | 14 ++++++++++++-- src/main.lua | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/core/ui.lua b/src/core/ui.lua index 1ee2079..86b40a9 100644 --- a/src/core/ui.lua +++ b/src/core/ui.lua @@ -19,6 +19,9 @@ ui.conditions.all = function(g) return true end ui.conditions.favorites = function(g) return settings.data.games[g.id].favorite end +ui.conditions.downloaded = function(g) + return love.filesystem.exists(fname(g,g.stable)..".sha1") +end function ui.create_list(condition) local list = loveframes.Create("columnlist") @@ -120,6 +123,9 @@ function ui.load() ui.list.favorites = ui.create_list(ui.conditions.favorites) tabs:AddTab("Favorites",ui.list.favorites,"Your favorite games") + + ui.list.downloaded = ui.create_list(ui.conditions.downloaded) + tabs:AddTab("Downloaded",ui.list.downloaded,"Downloaded games.") ui.buttons = {} @@ -173,7 +179,6 @@ function ui.load() visitwebsite_tooltip:SetObject(ui.buttons.visitwebsite) visitwebsite_tooltip:SetPadding(4) visitwebsite_tooltip:SetText("Visit the author's website.") - end @@ -198,7 +203,12 @@ function ui.update(dt) end ui.update_buttons() - + + if ui.download_change then + ui.download_change = nil + ui.list.downloaded = ui.update_list(ui.list.downloaded,ui.conditions.downloaded) + end + end function ui.header() diff --git a/src/main.lua b/src/main.lua index ea8f6f8..fb28ac6 100644 --- a/src/main.lua +++ b/src/main.lua @@ -64,6 +64,7 @@ function dogame(gameobj) currently_downloading[fn] = true downloader:request(url, async.love_filesystem_sink(fn,true), function() currently_downloading[fn] = nil + ui.download_change = true end) end @@ -78,6 +79,7 @@ function deletegame(index) love.filesystem.remove(imgname(gameobj)) ui.images[index] = nil gameobj.invalid = nil + ui.download_change = true end end