-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutt.lua
More file actions
412 lines (335 loc) · 8.44 KB
/
butt.lua
File metadata and controls
412 lines (335 loc) · 8.44 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
--[[
This software is released under the MIT License. See LICENSE.txt for details.
Also, on a non-legal note: I do not recommend reading my code, especially not for educative
purposes. It was written over like three years, and I often forgot how I implemented several
things over time. Also, I was mostly drunk and listening to the Katamari Damacy soundtrack.
So yeah.
]]
buttClass = newClass()
if smallMode then
buttClass.margin = 10
buttClass.extraw = 15
buttClass.extrah = 6
buttClass.smallnumber = 6
else
buttClass.margin = 20
buttClass.extraw = 30
buttClass.extrah = 15
buttClass.smallnumber = 0
end
function newTween()
local tween = {}
tween.fact = 1
tween.clicktime = 0
tween.mclicktime = 0.5
return tween
end
function newButt(s,x,y,f,w,h,t)
local o = buttClass:newInstance()
o:setS(s)
o.x = x
o.y = y
local tween = newTween()
o.click = function()
tween.clicktime = tween.mclicktime
f()
audio:playSfx("butt")
end
o.tween = tween
return o
end
function buttClass:setS(s)
self.s = s
self.w = font:getWidth(s) + self.extraw
self.h = font:getHeight() + self.extrah
end
function buttClass:troll()
self.flagAsTrollLol = true
return self
end
function buttClass:drawlol(transparent)
self:draw(transparent)
end
function buttClass:draw(transparent, purple)
if self.flagNoAnimLol then
return self:draw2(transparent, purple)
end
love.graphics.setColor(255,255,255)
love.graphics.push()
local tween = self.tween
local x,y = love.mouse.getPosition()
if state.flagOptionsState and not exit_prompt then
-- modify x, y
x = x - centerx + x_corr
y = y - centery + y_corr
end
local dt = love.timer.getDelta()
local upperbound = 1.2
if self:inside(x,y) and (self.popup or not exit_prompt) and (self.popup or not state.tryAgainScreen) and not love.mouse.isDown("l") then
if self.keyshortcut then
local w = font:getWidth(self.keyshortcut)
local y = self.y - self.h - 15
if y < 0 then
y = self.y + self.h - 15
end
love.graphics.print(self.keyshortcut, self.x - w/2, y - self.smallnumber)
end
tween.fact = tween.fact + 1.5*dt
tween.fact = math.min(tween.fact, upperbound)
else
tween.fact = tween.fact - 1.5*dt
tween.fact = math.max(tween.fact, 1)
end
local fact = goodsmoothstep(tween.fact, 1, upperbound)
local fact2 = 1
if tween.clicktime > 0 then
local diff = tween.mclicktime - tween.clicktime
fact2 = 0.1429*(6+math.cos(2*math.pi*diff/tween.mclicktime))
fact = fact * fact2
fact2 = (19+fact2)*0.05
tween.clicktime = tween.clicktime - 2*dt
end
love.graphics.translate(self.x, self.y)
love.graphics.scale(fact, fact)
love.graphics.rotate(2*math.pi*fact2)
love.graphics.translate(-self.x, -self.y)
self:draw2(transparent, purple, true)
love.graphics.pop()
love.graphics.print(self.s, self.x - self.w/2 + self.extraw/2,self.y - self.h/2 + 10 - self.smallnumber)
end
function buttClass:draw2(transparent, purple, henshin)
local t = 100
local t2 = 255
if transparent then
t = 50
t2 = 50
end
if purple or (self.lolf and self.lolf()) then
self:trollDraw(henshin)
return
end
if not self.noborder then
love.graphics.setColor(0,0,0,t)
love.graphics.rectangle("fill",self.x-self.w/2,self.y-self.h/2,self.w-1,self.h-1)
end
love.graphics.setColor(255,255,255,t2)
if not self.noborder then
love.graphics.rectangle("line",self.x-self.w/2,self.y-self.h/2,self.w,self.h)
end
if not henshin then
love.graphics.print(self.s, self.x - self.w/2 + self.extraw/2,self.y - self.h/2 + 10 - self.smallnumber)
end
end
function buttClass:trollDraw(henshin)
love.graphics.setColor(0,0,0)
love.graphics.rectangle("fill",self.x-self.w/2,self.y-self.h/2,self.w-1,self.h-1)
love.graphics.setColor(255,0,255)
love.graphics.rectangle("line",self.x-self.w/2,self.y-self.h/2,self.w,self.h)
if not henshin then
love.graphics.print(self.s, self.x - self.w/2 + self.extraw/2,self.y - self.h/2 + 10 - self.smallnumber)
end
end
function buttClass:inside(x,y)
return x > self.x-self.w/2 - self.margin and y > self.y - self.h/2 - self.margin and x < self.x + self.w/2 + self.margin and y < self.y + self.h/2 + self.margin
end
function buttClass:mousepressed()
if self:inside(love.mouse.getPosition()) then
self:click()
end
end
buttListClass = newClass({"list"})
function newButtList()
return buttListClass:newInstance()
end
function buttListClass:add(b)
table.insert(self.list,b)
end
function buttListClass:draw(transparent,t2)
for i = 1,#self.list do
if self.flagLolCoords then
self.list[i]:drawlol(transparent,t2)
else
self.list[i]:draw(transparent,t2)
end
end
end
function buttListClass:click()
local x,y = love.mouse.getPosition()
if self.flagLolCoords then
x = -centerx + x_corr + x
y = -centery + y_corr + y
end
if self.corr then
x = x - self.corr.x
y = y - self.corr.y
end
local res = false
for i = 1,#self.list do
if self.list[i]:inside(x,y) then
self.list[i].click()
res = true
break
end
end
return res
end
function buttListClass:lolInside()
local x,y = love.mouse.getPosition()
if self.flagLolCoords then
x = -centerx + x_corr + x
y = -centery + y_corr + y
end
if self.corr then
x = x - self.corr.x
y = y - self.corr.y
end
local res = false
for i = 1,#self.list do
if self.list[i]:inside(x,y) then
--self.list[i].click()
res = true
break
end
end
return res
end
function buttListClass:update(dt) --TODO så vitt jag vet används denna inte..?
--behövs endast om LPButts finns i listan
if not love.mouse.isDown('l') then
return
end
for i = 1,#self.list do
if self.list[i].flagLP then
self.list[i]:update(dt)
end
end
end
buttListClassPro = buttListClass:newSubClass()
function newButtListPro()
local o = buttListClassPro:newInstance()
o.yes = false
o.troll = newButtList()
o.troll2 = newButtList()
return o
end
function buttListClassPro:add2(b)
self.troll:add(b)
end
function buttListClassPro:add3(b,f)
self.troll2:add(b)
b.lolf = f
end
function buttListClassPro:draw(transparent)
for i = 1,#self.list do
self.list[i]:draw(transparent)
end
--if self.yes then
self.troll:draw(transparent)
--else
self.troll2:draw(transparent)
--end
end
function buttListClassPro:click()
local x,y = love.mouse.getPosition()
local res = false
for i = 1,#self.list do
if self.list[i]:inside(x,y) then
self.list[i].click()
res = true
break
end
end
--if self.yes then
local trollres1 = self.troll:click()
res = trollres1 or res
--else
local trollres2 = self.troll2:click()
res = trollres2 or res
--end
return res
end
function buttListClassPro:lolInside()
local x,y = love.mouse.getPosition()
local res = false
for i = 1,#self.list do
if self.list[i]:inside(x,y) then
--self.list[i].click()
res = true
break
end
end
--if self.yes then
local trollres = self.troll:lolInside()
res = trollres or res
--else
local trollres = self.troll2:lolInside()
res = trollres or res
--end
return res
end
function buttListClassPro:update(dt)
--behövs endast om LPButts finns i listan
if not love.mouse.isDown('l') then
return
end
for i = 1,#self.troll.list do
if self.troll.list[i].flagLP then
self.troll.list[i]:update(dt)
end
end
end
local MLButt = buttClass:newSubClass()
function newMLButt(s,x,y,f,w,h)
local o = MLButt:newInstance()
o:setS(s)
o.x = x
o.y = y
o.click = f
o.extraw = o.extraw + 40
return o
end
function MLButt:setS(ss)
self.n = #ss
self.s = ss
local s = ss[1]
for i=1,#ss do
if #ss[i] > #s then
s = ss[i]
end
end
self.w = font:getWidth(s) + self.extraw
self.h = self.n*font:getHeight() + self.extrah
end
function MLButt:draw(dx)
local dx = dx or 0
love.graphics.setColor(0,0,0,100)
love.graphics.rectangle("fill",self.x-self.w/2,self.y-self.h/2,self.w-1,self.h-1)
love.graphics.setColor(255,255,255)
love.graphics.rectangle("line",self.x-self.w/2,self.y-self.h/2,self.w,self.h)
for i=1,#self.s do
love.graphics.print(self.s[i], self.x - self.w/2 + self.extraw/2 + dx,self.y - self.h/2 + (i-1)*32 + 10 - self.smallnumber)
end
end
local LPButt = buttClass:newSubClass()
function LPButt:update(dt,mx,my)
--utgår ifrån att musen trycks ner
mx = mx or love.mouse.getX()
my = my or love.mouse.getY()
if self:inside(mx,my) then
self.click(dt)
end
end
function newLPButt(s,x,y,f)
local o = LPButt:newInstance()
o:setS(s)
o.x = x
o.y = y
local tween = newTween()
o.click = function()
tween.clicktime = tween.mclicktime
f()
end
o.tween = tween
o.flagLP = true
return o
end