Some work on implementing underpill.
[poca-love.git] / menu.lua
blob2c254a7b75800f2a70a8076b1abc97b87fb67b2c
1 menu_elements = { -- relative to playfield size and position
2 --levels
3 current_level = {
4 x = .2, y = 0, w = .6, h = .2,
5 content = function () return level_labels[game.currentlevel] .. ' ' .. game.currentlevel end,
6 onclick = function () game:change_screen('playfield') end,
7 },
8 previous_level = {
9 x = 0, y = 0, w = .2, h = .2,
10 content = '-',
11 onclick = function() setuplevel(game.currentlevel - 1) end
13 next_level = {
14 x = .8, y = 0, w = .2, h = .2,
15 content = '+',
16 onclick = function () setuplevel(game.currentlevel + 1) end
18 -- objects
19 object_name = {
20 x = 0, y = 0, w = 1, h = .2,
21 content = function () return trinkets.selected .. '. ' .. trinkets[trinkets.held[trinkets.selected]].name end,
23 big_object = {
24 x = .25, y = .25, w = .5, h = .5,
25 content = '?',
27 previous_object = {
28 x = 0, y = .4, w = .2, h = .2,
29 content = '-',
30 onclick = function () trinkets:show(-1) end,
32 next_object = {
33 x = .8, y = .4, w = .2, h = .2,
34 content = '+',
35 onclick = function () trinkets:show(1) end,
37 -- select screen
38 levels = {
39 x = 0, y = .8, w = .2, h = .2,
40 content = 'levels',
41 onclick = function () game:change_screen('menu_levels') end,
43 knowledge = {
44 x = .2, y = .8, w = .2, h = .2,
45 content = 'known',
46 onclick = function () game:change_screen('playfield') end,
48 objects = {
49 x = .4, y = .8, w = .2, h = .2,
50 content = 'objects',
51 onclick = function () game:change_screen('menu_objects') end,
53 play = {
54 x = .8, y = .8, w = .2, h = .2,
55 content = 'play',
56 onclick = function () game:change_screen('playfield') end,
58 story_beginning = {
59 x = 0, y = 0, w = 1, h = 1,
60 content = 'My journey began when arrows invaded every room of my apartment, including my bedroom.',
61 onclick = function () game:change_screen('playfield') end,
63 story_adventurer_map = {
64 x = 0, y = 0, w = 1, h = 1,
65 content = 'You search the remains of a dead adventurer and find a map.',
66 onclick = function () game:change_screen('playfield') end,
68 story_adventurer_nothing = {
69 x = 0, y = 0, w = 1, h = 1,
70 content = 'You search the remains of a dead adventurer and find nothing special.',
71 onclick = function () game:change_screen('playfield') end,
76 function get_absolute_dimensions(e)
77 return
78 e.x * screen.playfieldsize + screen.playfieldx * screen.tilesize,
79 e.y * screen.playfieldsize + screen.playfieldy * screen.tilesize,
80 e.w * screen.playfieldsize,
81 e.h * screen.playfieldsize
82 end
85 function draw_menu_elements()
86 for i, e in ipairs(menu_elements.drawn) do
87 local x, y, w, h = get_absolute_dimensions(e)
88 local content = e.content
89 love.graphics.setColor(0,0,1)
90 love.graphics.rectangle('fill', x, y, w, h)
91 love.graphics.setColor(0,1,1)
92 love.graphics.rectangle('line', x + 2, y + 2, w - 4, h - 4)
93 love.graphics.setColor(1,1,1)
94 if content then
95 if type(content) == 'function' then content = content() end
96 love.graphics.setFont(screen.defaultfont)
97 local lines = select(2, screen.defaultfont:getWrap(content, w - 4))
98 local offsety = (h - screen.defaultfont:getHeight() * #lines) / 2
99 love.graphics.printf(content, x + 2, y + 2 + offsety, w - 4 ,'center')
105 function draw_menu()
106 love.graphics.setColor(.5,.5,.5)
107 love.graphics.draw(screen.bgcanvas)
108 local e = menu_elements
109 if game.screen == 'menu_levels' then
110 menu_elements.drawn = e.drawn or {
111 e.current_level, e.next_level, e.previous_level,
112 e.levels, e.knowledge, e.objects, e.play,
114 elseif game.screen == 'menu_objects' then
115 menu_elements.drawn = e.drawn or {
116 e.object_name,
117 e.big_object, e.previous_object, e.next_object,
118 e.levels, e.knowledge, e.objects, e.play,
120 elseif game.screen == 'story_beginning' then
121 menu_elements.drawn = e.drawn or {
122 e.story_beginning
124 elseif game.screen == 'story_adventurer_map' then
125 menu_elements.drawn = e.drawn or {
126 e.story_adventurer_map
128 elseif game.screen == 'story_adventurer_nothing' then
129 menu_elements.drawn = e.drawn or {
130 e.story_adventurer_nothing
133 draw_menu_elements()
137 function menu_click(mx, my)
138 for i, e in ipairs(menu_elements.drawn) do
139 if e.onclick and isin(mx, my, get_absolute_dimensions(e)) then
140 e.onclick()