-
Notifications
You must be signed in to change notification settings - Fork 23
/
horizontallist.gui_script
88 lines (78 loc) · 2.87 KB
/
horizontallist.gui_script
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
local gooey = require "gooey.gooey"
local image_cache = require "gooey.image_cache"
local cache = image_cache.create()
local function refresh_dynamiclist(list)
for _,item in ipairs(list.items) do
local pos = gui.get_position(item.root)
if item == list.selected_item then
pos.y = 4
elseif item == list.pressed_item then
pos.y = 4
elseif item == list.over_item_now then
pos.y = -4
elseif item == list.out_item_now then
pos.y = 0
elseif item ~= list.over_item then
pos.y = 0
end
gui.set_position(item.root, pos)
if item.data then
local image_node = item.nodes[hash("listitem_image")]
local text_node = item.nodes[hash("listitem_text")]
local url = ("https://dummyimage.com/40x40/%s/%s.png"):format(item.data.color, item.data.color)
gui.set_text(text_node, tostring(item.data.text))
gui.set_enabled(image_node, false)
image_cache.load(cache, url, image_node, function()
gui.set_enabled(image_node, true)
end)
end
end
end
local function refresh_carousel(list)
for _,item in ipairs(list.items) do
if item.data then
gui.play_flipbook(item.nodes[hash("carousel_listitem")], item.data)
end
end
end
function init(self)
gooey.acquire_input()
self.list_data = {
{ text = "Red", color = "f00" },
{ text = "Blue", color = "00f" },
{ text = "Green", color = "0f0" },
{ text = "Yellow", color = "ff0" },
{ text = "Orange", color = "f70" },
{ text = "Light grey", color = "ddd" },
{ text = "White", color = "fff" },
{ text = "Black", color = "000" },
}
gooey.horizontal_dynamic_list("dynamiclist_bg", "dynamiclist_stencil", "listitem_bg", self.list_data, nil, nil, nil, nil, refresh_dynamiclist)
self.carousel_data = {
"flyMan",
"spikeBall",
"spikeMan",
"sun",
"wingMan",
}
gooey.horizontal_dynamic_list("carousel_bg", "carousel_stencil", "carousel_listitem", self.carousel_data, nil, nil, { carousel = true }, nil, refresh_carousel)
end
function final(self)
image_cache.clear(cache)
end
function on_input(self, action_id, action)
gooey.button("back_button", action_id, action, function(button)
msg.post("controller:/go", "show_menu")
end)
local list = gooey.horizontal_dynamic_list("dynamiclist_bg", "dynamiclist_stencil", "listitem_bg", self.list_data, action_id, action, nil, function(list)
print("selected dynamic list item", list.selected_item.index, list.data[list.selected_item.index].text)
table.remove(list.data, list.selected_item.index)
return true
end, refresh_dynamiclist)
gooey.horizontal_scrollbar("scrollbar_handle", "scrollbar_bg", action_id, action, function(scrollbar)
list.scroll_to(scrollbar.scroll.x, 0)
end)
gooey.horizontal_dynamic_list("carusel_bg", "carousel_stencil", "carousel_listitem", self.carousel_data, action_id, action, { carousel = true }, function(list)
print("selected carousel list item", list.selected_item.index, list.data[list.selected_item.index])
end, refresh_carousel)
end