I made one of these before, but this one's a little different:
It can load a save with one click instead of 2
It has a better UI
You can hide the UI if it gets in the way, and
It works with every TPT, not just on jacob1's mod!
The code is this:
local col, buttonx
local draw = true
function tpt.load(id, n)
if not n then n = 0 end
simulation.loadSave(id, n)
end
local function drawButton()
tpt.drawrect(2, 372, 84, 10, 255, 255, 255, 255)
if tpt.mousex >= 2 and tpt.mousey >= 372 and tpt.mousex <= 86 and tpt.mousey <= 382 then
tpt.fillrect(2, 372, 84, 10, 255, 255, 255, 125)
end
tpt.drawtext(4, 374, 'Load random save', 0, 255, 0, 255)
tpt.drawrect(88, 372, 95, 10, 255, 255, 255, 255)
if tpt.mousex >= 88 and tpt.mousey >= 372 and tpt.mousex <= 183 and tpt.mousey <= 382 then
tpt.fillrect(88, 372, 95, 10, 255, 255, 255, 125)
end
tpt.drawtext(90, 374, 'Reload current save', 0, 255, 0, 255)
tpt.drawtext(185, 374, 'Current save ID: ' .. (simulation.getSaveID() or 'nil'), 0, 255, 0, 255)
buttonx = tpt.textwidth('Current save ID: ' .. (simulation.getSaveID() or 'nil')) + 187
if tpt.mousex >= buttonx and tpt.mousex <= buttonx + 8 and tpt.mousey >= 372 and tpt.mousey <= 380 then
col = 255
else
col = 200
end
tpt.drawtext(buttonx, 372, '\170', 255, 0, 0, col)
end
tpt.register_step(drawButton)
local function unDrawButton()
if tpt.mousex >= 2 and tpt.mousex <= 10 and tpt.mousey >= 372 and tpt.mousey <= 380 then
col = 255
else
col = 200
end
tpt.drawtext(2, 372, '\207', 0, 255, 0, col)
end
local function buttonMouseTest(x, y, b, e)
local ret = true
if tpt.mousex >= 2 and tpt.mousey >= 374 and tpt.mousex <= 86 and tpt.mousey <= 383 and e == 2 and draw == true then
tpt.load(math.floor(math.random(1, 1333000))) -- 1333000: Fairly recent
elseif tpt.mousex >= 88 and tpt.mousey >= 372 and tpt.mousex <= 183 and tpt.mousey <= 382 and e == 2 and simulation.getSaveID() then
tpt.load(simulation.getSaveID(), 1)
elseif tpt.mousex >= buttonx and tpt.mousex <= buttonx + 8 and tpt.mousey >= 372 and tpt.mousey <= 380 and draw == true and e == 2 then
draw = false
tpt.unregister_step(drawButton)
tpt.register_step(unDrawButton)
elseif tpt.mousex >= 2 and tpt.mousex <= 10 and tpt.mousey >= 372 and tpt.mousey <= 380 and draw == false and e == 2 then
draw = true
tpt.register_step(drawButton)
tpt.unregister_step(unDrawButton)
end
if (tpt.mousex >= 2 and tpt.mousey >= 374 and tpt.mousex <= 86 and tpt.mousey <= 383 and draw == true) or
(tpt.mousex >= 88 and tpt.mousey >= 372 and tpt.mousex <= 183 and tpt.mousey <= 382) or
(tpt.mousex >= buttonx and tpt.mousex <= buttonx + 8 and tpt.mousey >= 372 and tpt.mousey <= 380 and draw == true) or
(tpt.mousex >= 2 and tpt.mousex <= 10 and tpt.mousey >= 372 and tpt.mousey <= 380 and draw == false) then
ret = false
end
return ret
end
tpt.register_mouseclick(buttonMouseTest)
Current version: 2.0.3
CHANGELOG:
Added ability to show/hide contols
Fixed bug preventing random save load because of control hiding/showing
Changed color of buttons (not shown in images)
Click 'Load random save' to...well, you can figure it out...and 'reload current save' to show the dialog you usually get when you manually open a save. Click the 'x' (Yay character encodings!) to close the dialog, and the check mark to open it again after you closed it.
There, it should be fixed. The formatting is a bit odd, since I'm doing this from my iPad, but it at least works now.
Yeah, I suppose. I'll do that when I get back to my computer.
...Maybe. Can tpt.load in yours load a save without displaying the info first?