forked from anakrusis/harmony-game
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.lua
More file actions
188 lines (128 loc) · 4.68 KB
/
Copy pathgui.lua
File metadata and controls
188 lines (128 loc) · 4.68 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
function init_gui()
WINDOW_MAIN = {};
topbar = TextBox_TopBar:new{ x=0, y=0, height=200 }
table.insert(WINDOW_MAIN, topbar);
statusbox = TextBox_Status:new{ width=256 }
topbar:appendElement(statusbox);
table.insert(WINDOW_MAIN, statusbox);
chord1box = TextBox_ChordShape:new{text="Z", id=1}
topbar:appendElement(chord1box);
table.insert(WINDOW_MAIN, chord1box);
chord2box = TextBox_ChordShape:new{text="X", id=2}
topbar:appendElement(chord2box);
table.insert(WINDOW_MAIN, chord2box);
chord3box = TextBox_ChordShape:new{text="C", id=3}
topbar:appendElement(chord3box);
table.insert(WINDOW_MAIN, chord3box);
window = WINDOW_MAIN;
end
TextBox = {
x = -1, -- physical x and y of the dom element
y = -1,
-- if not manually assigned, (-1, -1) is the "auto" setting to fill up the parent box
width = 100, height = -1, padding = 10,
-- x and y as they appear on the screen and to the children divs
dispx = -1, dispy = -1,
dispwidth = 100, dispheight = 100,
color = {0.0, 0.0, 0.0, 0.5},
outlinecolor = {1.0, 1.0, 1.0, 1.0},
parent = nil, -- the text box above it in the hierarchy
children = {}, -- other text boxes displayed within it
text = "",
}
function TextBox:appendElement(e)
e.parent = self;
table.insert(self.children, e);
end
function TextBox:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
function TextBox:update()
-- auto positioning setting. Floats left
if (self.x == -1 and self.y == -1) then
p = self.parent;
self.dispx = p.dispx + p.padding;
self.dispy = p.dispy + p.padding;
for i = 1, #p.children do
if p.children[i] == self then
break;
else
self.dispx = self.dispx + p.children[i].dispwidth + (p.padding)
end
end
-- Manual positioning setting
else
self.dispx = self.x + self.padding; self.dispy = self.y + self.padding;
end
self.dispwidth = self.width - (self.padding*2); self.dispheight = self.height - (self.padding*2);
-- Auto height(if set to -1 then it fills up to the height of the parent div)
if (self.height == -1) then
self.dispheight = self.parent.dispheight - self.parent.padding * 2
end
end
function TextBox:draw()
love.graphics.setColor(self.color[1], self.color[2], self.color[3], self.color[4]);
love.graphics.rectangle("fill",self.dispx,self.dispy,self.dispwidth,self.dispheight);
love.graphics.setColor(self.outlinecolor[1], self.outlinecolor[2], self.outlinecolor[3], self.outlinecolor[4]);
love.graphics.rectangle("line",self.dispx,self.dispy,self.dispwidth,self.dispheight);
love.graphics.setColor(1,1,1,1)
love.graphics.printf(self.text, self.dispx, self.dispy, self.dispwidth, "left")
end
TextBox_TopBar = TextBox:new{
};
TextBox_Status = TextBox:new{
};
TextBox_ChordShape = TextBox:new{
id = 1, -- ID corresponds to an id within the room metadata which is the source of the different chordshapes
};
function TextBox_ChordShape:draw()
TextBox.draw(self)
love.graphics.setColor(1,1,1,1)
--love.graphics.line(self.dispx, self.dispy, self.dispx+self.dispwidth, self.dispy+self.dispheight);
shape = room.chordshapes[self.id];
extreme_L = 0; extreme_R = 0; extreme_U = 0; extreme_D = 0;
for i = 1, #shape.xoffsets do
offsetx = shape.xoffsets[i]; offsety = shape.yoffsets[i];
if offsetx > extreme_R then
extreme_R = offsetx;
elseif offsetx < extreme_L then
extreme_L = offsetx;
end
if offsety > extreme_D then
extreme_D = offsety;
elseif offsety < extreme_U then
extreme_U = offsety;
end
end
shapewidth = extreme_R - extreme_L + 1; shapeheight = extreme_D - extreme_U + 1;
TILE_DRAW_SIZE = 32;
self.width = math.max(4*TILE_DRAW_SIZE, shapewidth * TILE_DRAW_SIZE * 2);
--self.text = shapewidth
for i = 1, #shape.xoffsets do
offsetx = shape.xoffsets[i]; offsety = shape.yoffsets[i];
centerx = self.dispx + (self.dispwidth / 2) - ( TILE_DRAW_SIZE / 2 ); centery = self.dispy + (self.dispheight/ 2) - ( TILE_DRAW_SIZE / 2 );
tiledrawx = centerx + (offsetx*TILE_DRAW_SIZE); tiledrawy = centery + (offsety*TILE_DRAW_SIZE);
--love.graphics.rectangle( "fill", tiledrawx, tiledrawy, TILE_DRAW_SIZE, TILE_DRAW_SIZE )
if offsetx == 0 and offsety == 0 then
love.graphics.draw(SPR_HUD_ROOT, tiledrawx, tiledrawy, 0, 4, 4);
else
love.graphics.draw(SPR_HUD_TILE, tiledrawx, tiledrawy, 0, 4, 4);
end
end
end
function TextBox_ChordShape:update()
TextBox.update(self)
self.text = string.sub(self.text, 1, 1)
self.text = self.text .. "- " .. room.chordshapes[self.id].name
end
function TextBox_TopBar:update()
TextBox.update(self)
self.width = love.graphics.getWidth();
end
function TextBox_Status:update()
TextBox.update(self)
self.text = "\n\n\nChords remaining:" .. player.chordsRemaining
end