-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvocdownload.lua
108 lines (85 loc) · 2.79 KB
/
vocdownload.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
local M = {}
local lg = love.graphics
local la = love.audio
local vocabulary = require("vocabulary")
local util = require("util")
local kana = require("kana")
local images = require("images")
local color = require("color")
local gui = require("gui")
local status = nil
local user = nil
local remote_voc_list = nil
function M.init(data)
print("vocdownload.init()", data)
status = data.status
user = data.user
end
function M.show()
print("vocdownload.show()")
if remote_voc_list == nil then
remote_voc_list = vocabulary.get_server_voc_list()
end
-- local voc = vocabulary.download_voc({ id="Colors" })
--
-- if voc ~= nil then
-- table.insert(vocabulary.vocabularies, voc)
-- end
end
local parts = {}
function M.update(dt, mx, my)
gui.update_kana_parts(dt, parts, 11, "both", 16)
end
function M.mousepressed(x, y, button)
local i
set_parts_pos(parts, x - 16, y - 16)
for i=1,#remote_voc_list,1 do
local voc = remote_voc_list[i]
if status.button.name == voc.name then
status.dl_vocabulary = voc
end
end
if status.button.name == "hajime" then
if status.vocabulary ~= nil then
change_view("voctrain")
end
elseif type(status.button.name) == "number" then
user.vocabulary_level = status.button.name
elseif status.button.name == "#back" then
change_view("vocoptions")
end
end
function M.draw()
local i, col, b, selected, hover
gui.draw_page("Download online vocabularies", util.color(0,100,10), util.color(0,0,0), images.vocabulary)
kana.draw_text("Vocabulary", 24, 90, 60, color.header, "tl")
for i, voc in ipairs(remote_voc_list) do
selected = status.dl_vocabulary == voc
hover = status.button.name == voc.name
col = color.get_highlight_color(selected, hover)
b = { x = 50, y = 110 + (i * 32), w = 300, h = 30, name = voc.name }
kana.draw_text(voc.name, b.x, b.y, 50, col, "tl")
table.insert(status.buttons, b)
end
-- Draw the info about selected vocabulary.
kana.draw_text("Info", 410, 90, 60, color.header, "tl")
if status.dl_vocabulary ~= nil then
kana.draw_text("Author: "..status.dl_vocabulary.author, 430, 130, 40, color.active, "tl")
kana.draw_text("Version: "..status.dl_vocabulary.version, 430, 160, 40, color.active, "tl")
kana.draw_text("Type: "..status.dl_vocabulary.voc_type, 430, 190, 40, color.active, "tl")
end
-- Draw the download button.
hover = status.button.name == "#download"
col = color.get_hover_color(hover, "alt")
b = { x = lg.getWidth() - 270, y = lg.getHeight() - 68, w = 260, h = 60, name = "#download" }
gui.draw_button(b, col, images.download, color.back_icon, images.button_base,
images.button_top, "Download", hover, 50)
table.insert(status.buttons, b)
-- Draw the back button.
b = gui.draw_back(status.button.name == "#back")
table.insert(status.buttons, b)
for k,v in pairs(parts) do
gui.draw_part(v)
end
end
return M