id_
This commit is contained in:
parent
b19f58726c
commit
01d272981e
133 changed files with 822 additions and 66 deletions
129
level_editor/gui.lua
Normal file
129
level_editor/gui.lua
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
GUI = class("level_editor/gui")
|
||||
|
||||
GUI.static.pressSound = love.audio.newSource("sounds/ui/button.wav")
|
||||
|
||||
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)
|
||||
self.scale = drawScale * 2 / 3
|
||||
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()
|
||||
if button == "l" then
|
||||
self.clic:left()
|
||||
elseif button == "r" then
|
||||
self.clic:right()
|
||||
end
|
||||
end
|
||||
|
||||
function GUI:sha()
|
||||
return math.random(-worldSha, worldSha) * .5
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue