Skip to content

Commit

Permalink
Fix #180, fix #179, fix #172, fix #126, fix #91, editor UI tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoBDesigner committed Sep 22, 2021
1 parent 7a20ce5 commit b1c33bb
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 90 deletions.
11 changes: 10 additions & 1 deletion animationguiline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,15 @@ end
function animationguiline:unclick(x, y, button)
self.downbutton:unclick(x, y, button)
self.upbutton:unclick(x, y, button)

-- Why is it even done this way, and not with "for i = 1, #self.elements do"?
local i = 1
while i <= #self.elements do
if self.elements[i].gui then
self.elements[i].gui:unclick(x, y, button)
end
i = i + 1
end
end

function animationguiline:delete()
Expand Down Expand Up @@ -1287,4 +1296,4 @@ function animationguiline:haspriority()
end

return false
end
end
159 changes: 102 additions & 57 deletions editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ function editor_load()

mtsavehighlighttime = 5
mtsavetimer = 0
mtjustsaved = false
mtsavecolors = {1, 0.44, 0.44, 0.7}
mtjustsaved = 0

pastingtiles = false
pastemode = false -- 1 transparent, 2 opaque
Expand Down Expand Up @@ -527,14 +526,14 @@ function editor_update(dt)
next = "down"
end

if mushroomplatform then
if advanceddrawtool == "mushroom" then
powerlinedrawtable = { --mushroom platform
{"down", "up", 65, false},
{"left", "right", 22, false, hprev, 0, 20, false, (hprev/math.abs(hprev)), 0, 21, false, hprev-(hprev/math.abs(hprev)), 0, 21},
{"right", "left", 20, false, hprev, 0, 22, false, (hprev/math.abs(hprev)), 0, 21, false, hprev-(hprev/math.abs(hprev)), 0, 21},
{"down", "right", 21, false, 0, 1, 43},
{"down", "left", 21, false, 0, 1, 43}}
else
elseif advanceddrawtool == "powerlines" then
powerlinedrawtable = { --powerlines
{"up", "down", 43, true},
{"down", "up", 43, true},
Expand Down Expand Up @@ -590,6 +589,7 @@ function editor_update(dt)
elseif love.mouse.isDown("m") and not middlemode[1] then
if math.abs(love.mouse.getX() - middlemode[2]) >= 8*scale or math.abs(love.mouse.getY() - middlemode[3]) >= 8*scale then
middlemode[1] = true
love.mouse.setVisible(false)
end
end

Expand Down Expand Up @@ -894,46 +894,38 @@ function editor_draw()
lx2 = math.max(tileselectionclick1x, tileselectionclick2x)
ly2 = math.max(tileselectionclick1y, tileselectionclick2y)

love.graphics.setColor(0.67,1,0.67,0.3)
if mtjustsaved then
local r, g, b, a = unpack(mtsavecolors)
if r > 172 then
r = r - math.floor(mtsavetimer*3)
end
if r < 172 then
r = 172
end
if g < 255 then
g = g + math.floor(mtsavetimer*3)
end
if g > 255 then
g = 255
end
if b > 172 then
b = b - math.floor(mtsavetimer*3)
end
if b < 172 then
b = 172
end
if a > 72 then
a = a - math.floor(mtsavetimer*3)
end
if a < 72 then
a = 72
end
love.graphics.setColor(r / 255, g / 255, b / 255, a / 255)
if r == 172 and g == 255 and b == 172 and a == 72 then
mtsavehighlighttime = 5
mtsavetimer = 0
mtjustsaved = false
r = 255
g = 112
b = 112
a = 128
-- Laziness or cleverness?
local px, py = math.floor((lx1-xscroll-1)*16*scale), ((ly1-yscroll-1)*16+8)*scale
local pw, ph = (lx2-lx1)*16*scale+16*scale, (ly2-ly1)*16*scale+16*scale

love.graphics.setColor(0.67,1,0.67,0.7)
local timeOscilator = love.timer.getTime() % 2
timeOscilator = 1 - math.abs( math.cos(timeOscilator * math.pi) )

-- Highlight thing
love.graphics.rectangle("fill", px - (2 + timeOscilator*3)*scale, py - (2 + timeOscilator*3)*scale, 5*scale, scale)
love.graphics.rectangle("fill", px - (2 + timeOscilator*3)*scale, py - (1 + timeOscilator*3)*scale, scale, 4*scale)
love.graphics.rectangle("fill", px + pw + (2 + timeOscilator*3 - 5)*scale, py - (2 + timeOscilator*3)*scale, 5*scale, scale)
love.graphics.rectangle("fill", px + pw + (1 + timeOscilator*3)*scale, py - (1 + timeOscilator*3)*scale, scale, 4*scale)
love.graphics.rectangle("fill", px - (2 + timeOscilator*3)*scale, py + ph + (1 + timeOscilator*3)*scale, 5*scale, scale)
love.graphics.rectangle("fill", px - (2 + timeOscilator*3)*scale, py + ph + (1 + timeOscilator*3 - 4)*scale, scale, 4*scale)
love.graphics.rectangle("fill", px + pw + (2 + timeOscilator*3 - 5)*scale, py + ph + (1 + timeOscilator*3)*scale, 5*scale, scale)
love.graphics.rectangle("fill", px + pw + (1 + timeOscilator*3)*scale, py + ph + (1 + timeOscilator*3 - 4)*scale, scale, 4*scale)

local saveColors = {1, 0.44, 0.44, 0.7}
local selectColors = {0.67, 1, 0.67, 0.3}
love.graphics.setColor(selectColors)

if mtjustsaved > 0 then
local r, g, b, a = gradient(selectColors, saveColors, mtjustsaved)
love.graphics.setColor(r, g, b, a)

mtjustsaved = math.max(mtjustsaved - love.timer.getDelta(), 0)
if mtjustsaved == 0 then -- Negative 0 thing
mtjustsaved = 0
end
mtsavecolors = {r, g, b, a}
end
love.graphics.rectangle("fill",math.floor((lx1-xscroll-1)*16*scale), ((ly1-yscroll-1)*16+8)*scale, (lx2-lx1)*16*scale+16*scale, (ly2-ly1)*16*scale+16*scale)
love.graphics.rectangle("fill", px, py, pw, ph)
end
elseif middlemode[1] then
love.graphics.push()
Expand Down Expand Up @@ -1225,6 +1217,38 @@ function editor_draw()
rightclickm:draw()
end

-- EDITOR UI
local mode = "tiles"
local submode = false
if editorstate == "selection" then
mode = "selection"
elseif editorstate == "lightdraw" then
mode = "advanced draw tool"
submode = "power line draw"
if advanceddrawtool == "mushroom" then
submode = "mushroom platforms"
end
else
submode = "tiles"
if editenemies then
submode = "enemies"
elseif editentities then
submode = "entities"
end
end
love.graphics.setColor(1, 1, .8, .75)
properprint(" editor mode", 10*scale, 10*scale)
if submode then
properprint("tool submode", 10*scale, 18*scale)
end
properprint("f1 for help", (400-10-8*11)*scale, 10*scale)

love.graphics.setColor(1, 1, 1, .75)
properprint(":" .. mode, (10+12*8)*scale, 10*scale)
if submode then
properprint(":" .. submode, (10+12*8)*scale, 18*scale)
end

if love.keyboard.isDown("f1") and not rightclickm then
love.graphics.setColor(0, 0, 0, .85)
love.graphics.rectangle("fill", helpui[1]*scale, helpui[2]*scale, (helpui[3]-helpui[1])*scale, (helpui[4]-helpui[2])*scale)
Expand All @@ -1244,7 +1268,7 @@ function editor_draw()
{"ctrl+g","transforms the selected tiles into a|" ..
"group bound to the top-left-most tile.", 1},
{"u","on the tile screen, removes the tile group|" ..
"bound to the tile.", 1},-- |
"bound to the highlighted tile.", 1},-- |
{"ctrl+z/ctrl+y","undo/redo the last changes.", 0},
{"ctrl+c/ctrl+x/ctrl+v","copy/cut/paste region.", 0},
{"ctrl+a","select the entire level.", 0},-- |
Expand Down Expand Up @@ -1768,11 +1792,14 @@ function editor_draw()
properprint("delete", 10*scale, 210*scale)
end
elseif editorstate == "lightdrawcustomize" then
love.graphics.setColor(0.5, 0.5, 0.5)
properprint("more coming soon", 5*scale, 55*scale)
guielements["tabtools"].textcolor = {math.random(),math.random(),math.random()}
guielements["tabtools"].fillcolor = {math.random(),math.random(),math.random()}
guielements["tabtools"].bordercolor = {math.random(),math.random(),math.random()}
-- love.graphics.setColor(0.5, 0.5, 0.5)
-- properprint("more coming soon", 5*scale, 55*scale)

-- I'm cancelling this stroke-inducing nightmare

-- guielements["tabtools"].textcolor = {math.random(),math.random(),math.random()}
-- guielements["tabtools"].fillcolor = {math.random(),math.random(),math.random()}
-- guielements["tabtools"].bordercolor = {math.random(),math.random(),math.random()}
end
end
end
Expand Down Expand Up @@ -2080,7 +2107,7 @@ function powerlinestab()
v.active = false
end

guielements["tabtools"].text = "party"
-- guielements["tabtools"].text = "party"
guielements["tabmain"].active = true
guielements["tabtiles"].active = true
guielements["tabtools"].active = true
Expand Down Expand Up @@ -2927,10 +2954,13 @@ function savestate()
table.remove(savestates, 1)
end
local t = {}
t.coinmap = {}
for x = 1, #map do
t[x] = {}
t.coinmap[x] = {}
for y = 1, #map[x] do
t[x][y] = {}
t.coinmap[x][y] = coinmap[x][y]
for i, v in pairs(map[x][y]) do
t[x][y][i] = v
end
Expand All @@ -2945,10 +2975,13 @@ function loadstate(s)

local v = savestates[s]
map = {}
coinmap = {}
for x = 1, #v do
map[x] = {}
coinmap[x] = {}
for y = 1, #v[x] do
map[x][y] = {}
coinmap[x][y] = v.coinmap[x][y]
for i, w in pairs(v[x][y]) do
map[x][y][i] = w
end
Expand Down Expand Up @@ -3234,6 +3267,9 @@ function editor_mousepressed(x, y, button)
loadmtobjects()
elseif mtbutton == 4 then
deleteline("mappacks/" .. mappack .. "/objects.txt", tile+1)
if guielements["renamebar"] and guielements["renamebar"].active then
guielements["renamebar"].active = false
end
loadmtobjects()
end
end
Expand All @@ -3242,6 +3278,7 @@ function editor_mousepressed(x, y, button)
end
elseif button == "m" then
middlemode = {false, x, y}
love.mouse.setVisible(true)
elseif button == "wu" then
if not editormenuopen then
if love.keyboard.isDown("lshift") or love.keyboard.isDown("rshift") then
Expand Down Expand Up @@ -3424,14 +3461,16 @@ function editor_mousereleased(x, y, button)
elseif button == "m" then
if middlemode[1] == false then
local cox, coy = getMouseTile(love.mouse.getX(), love.mouse.getY()+8*scale)
print("cox, coy = " .. cox .. ", " .. coy)
if inmap(cox, coy) == false then
return
end
print("Tile selected")
if not editentities then
tilesall()
currenttile = map[cox][coy][1]

if currenttile == 1 and coinmap[cox][coy] then
currenttile = 116 -- Let's be nice to the map maker, alright?
end
elseif not editenemies then
tilesentities()
generateentitylist()
Expand All @@ -3450,6 +3489,7 @@ function editor_mousereleased(x, y, button)
end
end
middlemode[1] = false
love.mouse.setVisible(true)
end
allowdrag = true
hprev = 0
Expand Down Expand Up @@ -3515,6 +3555,7 @@ function editor_keypressed(key)

savemtobject(group, tostring(name), "groups")
loadmtgroups()
notice.new("Saved as group!", notice.white, 2)
end
elseif key == "c" or key == "x" then
if tileselectionclick1 == true and tileselectionclick2 == true then
Expand Down Expand Up @@ -3831,8 +3872,8 @@ function toggleskiplevelscreen(var)
end

function changepastemode(var)
-- pastemode = var
-- guielements["pastemodedropdown"].var = var
-- pastemode = var
-- guielements["pastemodedropdown"].var = var
if var ~= nil then
pastemode = var
else
Expand Down Expand Up @@ -3941,17 +3982,21 @@ function test_level()
end

function drawpowerlines()
mushroomplatform = false

advanceddrawtool = "powerlines"

editenemies = false
editentities = true
editorstate = "lightdraw"
lightdrawX = nil
lightdrawY = nil
editorclose()
end

function drawmushrooms()
mushroomplatform = true
advanceddrawtool = "mushroom"

editenemies = false
editentities = false
editorstate = "lightdraw"
lightdrawX = nil
lightdrawY = nil
Expand Down Expand Up @@ -4166,7 +4211,7 @@ function savemtobject(objecttable, name, file)
data = string.gsub(data, "mtobjsize", m .. " * " .. n)
data = data .. "\n"
love.filesystem.write("mappacks/" .. mappack .. "/" .. file .. ".txt", data)
mtjustsaved = true
mtjustsaved = 1
end

function objectclipboardcopy(objecttable)
Expand Down
16 changes: 11 additions & 5 deletions emancipationgrill.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ function emancipationgrill:init(x, y, r)
self.active = true
self.inputstate = "off"

self.thickness = 4 -- For aabb checks

table.remove(self.r, 1)
table.remove(self.r, 1)

Expand Down Expand Up @@ -135,10 +137,12 @@ function emancipationgrill:draw()
parstartleft = math.floor((self.startx-1-xscroll)*16*scale)
parstartright = math.floor((self.endx-1-xscroll)*16*scale)
if self.active then
love.graphics.setScissor(parstartleft, ((self.y-yscroll-1)*16-2)*scale, self.range - emanceimgwidth*scale, scale*4)
love.graphics.setScissor(parstartleft, ((self.y-yscroll-1)*16-self.thickness/2)*scale,
self.range - emanceimgwidth*scale, self.thickness*scale)

love.graphics.setColor(unpack(emancelinecolor))
love.graphics.rectangle("fill", math.floor((self.startx-1-xscroll)*16*scale), ((self.y-yscroll-1)*16-2)*scale, self.range, scale*4)
love.graphics.rectangle("fill", math.floor((self.startx-1-xscroll)*16*scale), ((self.y-yscroll-1)*16-self.thickness/2)*scale,
self.range, self.thickness*scale)
love.graphics.setColor(1, 1, 1)

for i, v in pairs(self.particles.i) do
Expand All @@ -162,10 +166,12 @@ function emancipationgrill:draw()
parstartup = math.floor((self.starty-yscroll-1)*16*scale)
parstartdown = math.floor((self.endy-yscroll-1)*16*scale)
if self.active then
love.graphics.setScissor(math.floor(((self.x-1-xscroll)*16+6)*scale), parstartup-8*scale, scale*4, self.range - emanceimgwidth*scale)
love.graphics.setScissor(math.floor(((self.x-1-xscroll)*16+self.thickness*1.5)*scale), parstartup-8*scale,
self.thickness*scale, self.range - emanceimgwidth*scale)

love.graphics.setColor(unpack(emancelinecolor))
love.graphics.rectangle("fill", math.floor(((self.x-1-xscroll)*16+6)*scale), parstartup-8*scale, scale*4, self.range - emanceimgwidth*scale)
love.graphics.rectangle("fill", math.floor(((self.x-1-xscroll)*16+self.thickness*1.5)*scale), parstartup-8*scale,
self.thickness*scale, self.range - emanceimgwidth*scale)
love.graphics.setColor(1, 1, 1)

for i, v in pairs(self.particles.i) do
Expand Down Expand Up @@ -221,4 +227,4 @@ function emancipationgrill:input(t, input)

self.inputstate = t
end
end
end
Loading

0 comments on commit b1c33bb

Please sign in to comment.