chroma_solstice/level_editor/gui.lua

130 lines
2.9 KiB
Lua
Raw Permalink Normal View History

2015-03-25 01:38:53 -04:00
GUI = class("level_editor/gui")
2026-08-07 20:56:42 -04:00
GUI.static.pressSound = love.audio.newSource("sounds/ui/button.wav", "static")
2015-03-25 01:38:53 -04:00
GUI.static.defaultCallbac = function() print("this button has not been configured") end
function GUI:initialize(t)
print("i exist", t.name, t.text)
self.offset = {x = 0, y = 0}
self.name = t.name
self.text = t.text
if not t.onClic then
t.onClic = {}
end
if not t.onClic.right then
t.onClic.right = GUI.defaultCallbac
end
if not t.onClic.left then
t.onClic.left = GUI.defaultCallbac
end
self.clic = t.onClic
self.x, self.y = t.x, t.y
if t.sprite then
print(self.name)
2026-08-07 01:39:47 -04:00
self.scale = t.scale or drawScale * 2 / 3
2015-03-25 01:38:53 -04:00
self.w = t.sprite:getWidth() * self.scale
self.h = t.sprite:getHeight() * self.scale
self.sprite = t.sprite
self.offset = {x = self.w / 2, y = self.h / 2}
self.x, self.y = t.x - self.offset.x, t.y - self.offset.y
elseif t.sprites then
self.sprites = t.sprites
local w, h
for color, sprite in pairs(t.sprites) do
w = sprite:getWidth()
h = sprite:getHeight()
end
if w > h then
self.scale = (drawScale * (2 / 3)) / (w / 16)
elseif w < h then
self.scale = (drawScale * (2 / 3)) / (h / 16)
else
self.scale = (drawScale * (2 / 3)) / (w / 16)
end
self.w = sideBarBox.w - (self.x * 2)
self.h = h * self.scale
else
-- this is text
self.x, self.y = t.x, t.y
self.w, self.h = sideBarBox.w - self.x * 2, 50
end
if self.name == "folder" then
self.w = sideBarBox.w - self.x * 2
end
end
function GUI:clicIsInBox(x, y)
if x > self.x and x < self.x + self.w and y > self.y and y < self.y + self.h then
return true
end
return false
end
function GUI:getBox()
return {x = self.x, y = self.y, w = self.w, h = self.h}
end
function GUI:editText(text)
self.text = text
end
function GUI:draw()
love.graphics.setColor(gColor.white:set())
love.graphics.setLineWidth(4)
local box = self:getBox()
box.x = box.x + self:sha()
box.y = box.y + self:sha()
if name == "forward" then
print(box.x, box.y)
end
if selectedColor == self.name then
love.graphics.rectangle("line", box.x, box.y, box.w, box.h)
end
if self.sprite then
love.graphics.draw(self.sprite, box.x, box.y, 0, self.scale, self.scale)
end
if self.sprites then
for color, sprite in pairs(self.sprites) do
love.graphics.setColor(gColor[color]:set())
love.graphics.draw(sprite, box.x, box.y, 0, self.scale, self.scale)
end
end
if self.text then
love.graphics.setColor(gColor.white:set())
if not self.sprites and not self.sprite then
love.graphics.rectangle("line", box.x, box.y, box.w, box.h)
end
love.graphics.print(self.text, box.x + 50, box.y + 15)
end
end
function GUI:onClic(button)
print(button)
print("hey!!! u cliced on me. my name is ", self.name, self.text)
GUI.pressSound:play()
2026-08-06 23:54:49 -04:00
if button == 1 then
2015-03-25 01:38:53 -04:00
self.clic:left()
2026-08-06 23:54:49 -04:00
elseif button == 2 then
2015-03-25 01:38:53 -04:00
self.clic:right()
end
end
function GUI:sha()
return math.random(-worldSha, worldSha) * .5
2026-08-07 01:39:47 -04:00
end