Skip to content

Commit

Permalink
adding loveframes, and basic implementation.
Browse files Browse the repository at this point in the history
Adding "All" Tab
Adding columnlist under "All" tab populated by games
When games are selected from columnlist, the selectindex is changed
removed arrow key controls as I don't know how to modify the currently selected of the columnlist.
added a ui.info function for more info
added a play/download/etc button
removed sublines and text from cover
added loveframe hooks
Some of this could use some refactoring, especially because I just learned how to use loveframes.
Added src/lib/loveframes to .gitignore
Added a setup.sh script that will clone and patch the proper version of loveframes (until the next version with the fix comes out!)
  • Loading branch information
josefnpat committed Aug 10, 2013
1 parent 0ee5e35 commit ce320c7
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 83 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
src/lib/loveframes/
src/git.lua
._temp.love
13 changes: 13 additions & 0 deletions dev/loveframes.patch
@@ -0,0 +1,13 @@
diff --git a/objects/columnlist.lua b/objects/columnlist.lua
index 7dfcabd..83c6b80 100644
--- a/objects/columnlist.lua
+++ b/objects/columnlist.lua
@@ -262,6 +262,8 @@ end
--]]---------------------------------------------------------
function newobject:AddRow(...)

+ local arg = {...}
+
local internals = self.internals
local list = internals[1]

22 changes: 6 additions & 16 deletions setup.sh
@@ -1,18 +1,8 @@
#!/bin/sh

# Download binaries, and unpack

cd dev/build_data
VERSION=0.8.0

# windows 32 bit
wget -t 2 -c https://bitbucket.org/rude/love/downloads/love-$VERSION\-win-x86.zip
unzip love-$VERSION\-win-x86.zip

# windows 64 bit
wget -t 2 -c https://bitbucket.org/rude/love/downloads/love-$VERSION\-win-x64.zip
unzip love-$VERSION\-win-x64.zip

# os x universal
wget -t 2 -c https://bitbucket.org/rude/love/downloads/love-$VERSION\-macosx-ub.zip
unzip love-$VERSION\-macosx-ub.zip
LOC=src/lib/loveframes
git clone --depth 1 https://github.com/NikolaiResokav/LoveFrames.git $LOC
cd $LOC
git checkout 6947e97cc56d1b1f0a6defe769562f965720bdba
cd -
patch -p1 $LOC/objects/columnlist.lua < dev/loveframes.patch
143 changes: 108 additions & 35 deletions src/core/ui.lua
Expand Up @@ -9,8 +9,90 @@ ui.headerindex = selectindex or 0

ui.snap = 0.01
ui.changespeed = 10
ui.buttonwidth = 210

ui.gameselect_w = (settings.gameshow)*settings.padding
ui.gameselect_h = (settings.gameshow+1)*settings.padding

function ui.create_list(condition)
local list = loveframes.Create("columnlist")

list.OnRowSelected = function(parent, row, data)
for gi,gv in pairs(remote.data.games) do
if data[1] == gv.name then
selectindex = gi
end
end
end

local count = 0
for gi,gv in pairs(remote.data.games) do
if condition(gv) then
list:AddRow(gv.name)
count = count + 1
end
end

list:AddColumn("Application ("..count..")")

return list

end

function ui.update_button(gameobj)

local gameobj = remote.data.games[selectindex]
if gameobj then
local fn = fname(gameobj,gameobj.stable)
if currently_downloading[fn] then
ui.mainbutton:SetText("Downloading ...")
ui.mainbutton.icon = icons.downloading[math.floor(downloader.dt*10)%4+1]
elseif gameobj.invalid then
ui.mainbutton:SetText("Error")
ui.mainbutton.icon = icons.delete
elseif love.filesystem.exists(fn) then
ui.mainbutton:SetText("Play")
ui.mainbutton.icon = icons.play
else
ui.mainbutton:SetText("Download")
ui.mainbutton.icon = icons.view
end
else
ui.mainbutton.icon = icons.download
end
end

function ui.load()

-- Button
ui.mainbutton = loveframes.Create("button")
ui.mainbutton:SetSize(100, 22)
ui.mainbutton:SetPos(ui.gameselect_w+settings.padding*3, settings.heading.h+settings.padding*3)
ui.mainbutton:SetText("Download")
ui.mainbutton.OnClick = function(object)
if remote.data.games[selectindex] then
dogame(remote.data.games[selectindex])
end
end

-- tabs

local tabs = loveframes.Create("tabs")
tabs:SetPos(settings.padding, settings.heading.h+settings.padding)

tabs:SetSize(ui.gameselect_w,ui.gameselect_h)

ui.list_all = ui.create_list(function(g) return true end)
tabs:AddTab("All",ui.list_all,"All games")

--This list isn't updated, so what's the point in showing it?
--ui.list_favorites = ui.create_list(function(g) return settings.data.games[g.id].favorite end)
--tabs:AddTab("Favorites",ui.list_favorites,"Your favorite games")

end

function ui.update(dt)

if selectindex then
if ui.headerindex < selectindex + ui.snap and ui.headerindex > selectindex - ui.snap then
ui.headerindex = selectindex
Expand All @@ -28,6 +110,8 @@ function ui.update(dt)
ui.updatecovers(index)
end

ui.update_button()

end

function ui.header()
Expand All @@ -36,60 +120,49 @@ function ui.header()
local percentoffset = ui.headerindex%1*2

local xoff = (love.graphics.getWidth()-settings.heading.w*(1+percentoffset))/2
local yoff = settings.padding
local yoff = 0

local vapor = {name="Vapor"}

for preload = -2,2 do
love.graphics.setColor(255,255,255,255-191*math.abs(preload))
local preload_gameobj = remote.data.games[centerindex+preload]
if preload_gameobj then
ui.cover(preload_gameobj,xoff+settings.heading.w*preload,yoff,centerindex+preload)
else
ui.cover(vapor,xoff+settings.heading.w*preload,yoff)
end
end

end

function ui.cover(gameobj,xoff,yoff,index)
love.graphics.setColor(colors.reset)

end

love.graphics.draw(ui.images[index] or ui.nogame,xoff,0)
love.graphics.draw(ui.overlay,xoff,0)

love.graphics.setColor(colors.overlaybar)
love.graphics.rectangle(
"fill",
xoff,
settings.padding,
settings.heading.w,
fonts.title:getHeight()+fonts.basic:getHeight())
function ui.info()

love.graphics.setColor(colors.reset)
local x = ui.gameselect_w + settings.padding*2
local y = settings.heading.h + settings.padding
local w = love.graphics.getWidth()-x-settings.padding
local h = love.graphics.getHeight()-y-settings.padding*3
--love.graphics.rectangle("line",x,y,w,h)
local gameobj = remote.data.games[selectindex]
love.graphics.setFont(fonts.title)
love.graphics.print(gameobj.name,xoff+settings.padding,settings.padding)

love.graphics.print(gameobj and gameobj.name or "Vapor",x,y)
love.graphics.setFont(fonts.basic)
local subline
if index then
local game_filename = fname(gameobj,gameobj.stable)
if currently_downloading[game_filename] then
subline = "DOWNLOADING..."
elseif love.filesystem.exists(game_filename) then
subline = "CLICK TO PLAY"
else
subline = "CLICK TO INSTALL"
love.graphics.printf(gameobj and gameobj.description or "No description available.",x,y+settings.padding*3,w,"left")

if gameobj then
love.graphics.draw(ui.mainbutton.icon,ui.gameselect_w+settings.padding*2, settings.heading.h+settings.padding*3)
love.graphics.printf(gameobj.author,x,y+h,w,"right")
if gameobj.link then
love.graphics.printf(gameobj.author,x,y+h+settings.padding,w,"right")
end
else
subline = "DISTRIBUTION CLIENT FOR LÖVE"
end
love.graphics.printf(
subline,
xoff,
settings.padding+fonts.title:getHeight(),
settings.heading.w-settings.padding,
"right"
)
end

function ui.cover(gameobj,xoff,yoff,index)
love.graphics.draw(ui.images[index] or ui.nogame,xoff,yoff)
love.graphics.draw(ui.overlay,xoff,yoff)
end

function ui.updatecovers(index)
Expand Down
55 changes: 23 additions & 32 deletions src/main.lua
Expand Up @@ -4,6 +4,8 @@ pcall(require, "git");
require("lib/json")
async = require("core/async") -- this needs to be required before "socket.http"

require('lib/loveframes')

http = require("socket.http")

currently_downloading = {}
Expand Down Expand Up @@ -92,6 +94,7 @@ function love.load(args)

remote.load()
settings.load()
ui.load()

selectindex = nil

Expand All @@ -100,38 +103,25 @@ function love.load(args)
end

function love.update(dt)

downloader:update()
downloader.dt = downloader.dt + dt

ui.update(dt)
loveframes.update(dt)

end

function love.draw()
ui.header(gameobj)
end

function love.keypressed(key)
ui.header()
ui.info()
loveframes.draw()

end

if key == "right" or key == "down" then
if selectindex then
selectindex = selectindex + 1
if selectindex > #remote.data.games then
selectindex = 1
end
else
selectindex = 1
end
elseif key == "left" or key == "up" then
if selectindex then
selectindex = selectindex - 1
if selectindex < 1 then
selectindex = #remote.data.games
end
else
selectindex = #remote.data.games
end
elseif key == "return" or key == " " then
function love.keypressed(key, unicode)
if key == "return" or key == " " then
if remote.data.games[selectindex] then
dogame(remote.data.games[selectindex])
end
Expand All @@ -147,19 +137,20 @@ function love.keypressed(key)
gameobj.invalid = nil
end
end

loveframes.keypressed(key, unicode)
end

function love.keyreleased(key)
loveframes.keyreleased(key)
end

function love.mousepressed(x,y,button)
local gameobj = remote.data.games[selectindex]
if button == "l" then
if gameobj then
dogame(gameobj)
end
elseif button == "r" then
if gameobj then
settings.data.games[gameobj.id].favorite = not settings.data.games[gameobj.id].favorite
end
end
loveframes.mousepressed(x,y,button)
end

function love.mousereleased(x,y,button)
loveframes.mousereleased(x,y,button)
end

function love.quit()
Expand Down

0 comments on commit ce320c7

Please sign in to comment.