forked from UNO-Creation-Club/uno_cgm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
color_buttons.lua
130 lines (116 loc) · 7.59 KB
/
color_buttons.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
local u = require('utility')
local enums = require('enums')
local color_buttons = {
d_props = {x = love.graphics.getWidth() / 2, y = love.graphics.getHeight() / 2, ca = 0},
}
color_buttons.red_d_props_default = {x = color_buttons.d_props.x - 90, y = color_buttons.d_props.y - 90, width = 90, height = 90, rx = 0, ry = 0, cr = 242, cg = 71, cb = 65, sx = 1, sy = 1, ox = 0, oy = 0}
color_buttons.red_d_props_deactivated = {x = color_buttons.d_props.x - 90, y = color_buttons.d_props.y - 90, width = 90, height = 90, rx = 0, ry = 0, cr = 242, cg = 71, cb = 65, sx = 1, sy = 1, ox = 0, oy = 0}
color_buttons.red_d_props_activated = {x = color_buttons.d_props.x - 90, y = color_buttons.d_props.y - 90, width = 90, height = 90, rx = 15, ry = 15, cr = 255, cg = 129, cb = 125, sx = 1, sy = 1, ox = 0, oy = 0}
color_buttons.blue_d_props_default = {x = color_buttons.d_props.x, y = color_buttons.d_props.y - 90, width = 90, height = 90, rx = 0, ry = 0, cr = 59, cg = 74, cb = 237, sx = 1, sy = 1, ox = 0, oy = 0}
color_buttons.blue_d_props_deactivated = {x = color_buttons.d_props.x, y = color_buttons.d_props.y - 90, width = 90, height = 90, rx = 0, ry = 0, cr = 59, cg = 74, cb = 237, sx = 1, sy = 1, ox = 0, oy = 0}
color_buttons.blue_d_props_activated = {x = color_buttons.d_props.x, y = color_buttons.d_props.y - 90, width = 90, height = 90, rx = 15, ry = 15, cr = 125, cg = 136, cb = 255, sx = 1, sy = 1, ox = 0, oy = 0}
color_buttons.green_d_props_default = {x = color_buttons.d_props.x - 90, y = color_buttons.d_props.y, width = 90, height = 90, rx = 0, ry = 0, cr = 43, cg = 201, cb = 40, sx = 1, sy = 1, ox = 0, oy = 0}
color_buttons.green_d_props_deactivated = {x = color_buttons.d_props.x - 90, y = color_buttons.d_props.y, width = 90, height = 90, rx = 0, ry = 0, cr = 43, cg = 201, cb = 40, sx = 1, sy = 1, ox = 0, oy = 0}
color_buttons.green_d_props_activated = {x = color_buttons.d_props.x - 90, y = color_buttons.d_props.y, width = 90, height = 90, rx = 15, ry = 15, cr = 104, cg = 242, cb = 102, sx = 1, sy = 1, ox = 0, oy = 0}
color_buttons.yellow_d_props_default = {x = color_buttons.d_props.x, y = color_buttons.d_props.y, width = 90, height = 90, rx = 0, ry = 0, cr = 250, cg = 234, cb = 55, sx = 1, sy = 1, ox = 0, oy = 0}
color_buttons.yellow_d_props_deactivated = {x = color_buttons.d_props.x, y = color_buttons.d_props.y, width = 90, height = 90, rx = 0, ry = 0, cr = 250, cg = 234, cb = 55, sx = 1, sy = 1, ox = 0, oy = 0}
color_buttons.yellow_d_props_activated = {x = color_buttons.d_props.x, y = color_buttons.d_props.y, width = 90, height = 90, rx = 15, ry = 15, cr = 255, cg = 244, cb = 122, sx = 1, sy = 1, ox = 0, oy = 0}
color_buttons.red_button = {d_props = color_buttons.red_d_props_default, get_height = function(self) return self.d_props.height end, get_width = function(self) return self.d_props.width end, h_props = {}}
color_buttons.blue_button = {d_props = color_buttons.blue_d_props_default, get_height = function(self) return self.d_props.height end, get_width = function(self) return self.d_props.width end, h_props = {}}
color_buttons.green_button = {d_props = color_buttons.green_d_props_default, get_height = function(self) return self.d_props.height end, get_width = function(self) return self.d_props.width end, h_props = {}}
color_buttons.yellow_button = {d_props = color_buttons.yellow_d_props_default, get_height = function(self) return self.d_props.height end, get_width = function(self) return self.d_props.width end, h_props = {}}
function color_buttons:_animate_background_to(color)
self.anim:move{obj = self.state.bg, to = {r = enums.colors[color][1], g = enums.colors[color][2], b = enums.colors[color][3], a = enums.colors[color][4]}}
end
function color_buttons:initialize(params)
for k, v in pairs(params) do
self[k] = v
end
self.hitbox:define_region(
'color_buttons',
{
x = self.d_props.x - 200,
y = self.d_props.y - 200,
width = 400,
height = 400
}
)
self.hitbox:place{
id = 'color_buttons',
obj = self.red_button,
on_click = function(button)
self:_animate_background_to('R')
self.event_handler:dispatch({name = 'color_selected', type = 'R'})
end,
on_enter = function(button)
self.anim:move{obj = button, to = self.red_d_props_activated, seconds = 0.2}
end,
on_exit = function(button)
self.anim:move{obj = button, to = self.red_d_props_deactivated, seconds = 0.2}
end
}
self.hitbox:place{
id = 'color_buttons',
obj = self.blue_button,
on_click = function(button)
self:_animate_background_to('B')
self.event_handler:dispatch({name = 'color_selected', type = 'B'})
end,
on_enter = function(button)
self.anim:move{obj = button, to = self.blue_d_props_activated, seconds = 0.2}
end,
on_exit = function(button)
self.anim:move{obj = button, to = self.blue_d_props_deactivated, seconds = 0.2}
end
}
self.hitbox:place{
id = 'color_buttons',
obj = self.green_button,
on_click = function(button)
self:_animate_background_to('G')
self.event_handler:dispatch({name = 'color_selected', type = 'G'})
end,
on_enter = function(button)
self.anim:move{obj = button, to = self.green_d_props_activated, seconds = 0.2}
end,
on_exit = function(button)
self.anim:move{obj = button, to = self.green_d_props_deactivated, seconds = 0.2}
end
}
self.hitbox:place{
id = 'color_buttons',
obj = self.yellow_button,
on_click = function(button)
self:_animate_background_to('Y')
self.event_handler:dispatch({name = 'color_selected', type = 'Y'})
end,
on_enter = function(button)
self.anim:move{obj = button, to = self.yellow_d_props_activated, seconds = 0.2}
end,
on_exit = function(button)
self.anim:move{obj = button, to = self.yellow_d_props_deactivated, seconds = 0.2}
end
}
end
function color_buttons:show()
self.hitbox:activate_region('color_buttons')
self.anim:move{obj = self, to = {ca = 255}}
self.bg_darkener:activate()
end
function color_buttons:hide()
self.hitbox:deactivate_region('color_buttons')
self.anim:move{obj = self, to = {ca = 0}}
self.bg_darkener:deactivate()
end
function color_buttons:draw()
love.graphics.setColor(u.normalize(self.red_button.d_props.cr, self.red_button.d_props.cg, self.red_button.d_props.cb, self.d_props.ca))
love.graphics.rectangle('fill', self.red_button.d_props.x, self.red_button.d_props.y, self.red_button.d_props.width, self.red_button.d_props.height, self.red_button.d_props.rx, self.red_button.d_props.ry)
love.graphics.setColor(u.normalize(self.blue_button.d_props.cr, self.blue_button.d_props.cg, self.blue_button.d_props.cb, self.d_props.ca))
love.graphics.rectangle('fill', self.blue_button.d_props.x, self.blue_button.d_props.y, self.blue_button.d_props.width, self.blue_button.d_props.height, self.blue_button.d_props.rx, self.blue_button.d_props.ry)
love.graphics.setColor(u.normalize(self.green_button.d_props.cr, self.green_button.d_props.cg, self.green_button.d_props.cb, self.d_props.ca))
love.graphics.rectangle('fill', self.green_button.d_props.x, self.green_button.d_props.y, self.green_button.d_props.width, self.green_button.d_props.height, self.green_button.d_props.rx, self.green_button.d_props.ry)
love.graphics.setColor(u.normalize(self.yellow_button.d_props.cr, self.yellow_button.d_props.cg, self.yellow_button.d_props.cb, self.d_props.ca))
love.graphics.rectangle('fill', self.yellow_button.d_props.x, self.yellow_button.d_props.y, self.yellow_button.d_props.width, self.yellow_button.d_props.height, self.yellow_button.d_props.rx, self.yellow_button.d_props.ry)
love.graphics.setColor(u.normalize(255, 255, 255))
end
return color_buttons