visible = 0

function init()
	SetValue("visible", 1.0, "cosine", 0.5)
end

function tick()
	--Put a scripting menu button on the pause menu for all levels, except the main menu
	if not string.find(GetString("game.levelpath"), "main.xml") then
		if PauseMenuButton(GetTranslatedStringByKey("SCRIPTING_SHOWCASE")) then
			StartLevel("", "MOD/main.xml")
		end
	end
end


function draw()	
	local path = GetString("game.levelpath")
	if string.find(path, "lightswitch.xml") then
		infoBox(GetTranslatedStringByKey("THIS_EXAMPLE"))
	elseif string.find(path, "radio.xml") then
		infoBox(GetTranslatedStringByKey("A_RADIO"))
	elseif string.find(path, "elevator.xml") then
		infoBox(GetTranslatedStringByKey("THERE_ARE"))
	elseif string.find(path, "laser.xml") then
		infoBox(GetTranslatedStringByKey("THIS_EXAMPLE_2"))
	elseif string.find(path, "turret.xml") then
		infoBox(GetTranslatedStringByKey("A_TURRET"))
	elseif string.find(path, "forcefield.xml") then
		infoBox(GetTranslatedStringByKey("THIS_EXAMPLE_3"))
	elseif string.find(path, "weather.xml") then
		infoBox(GetTranslatedStringByKey("A_DYNAMIC"))
	elseif string.find(path, "flyover.xml") then
		infoBox(GetTranslatedStringByKey("A_CAMERA"))
	elseif string.find(path, "savegame.xml") then
		infoBox(GetTranslatedStringByKey("SHOOT_THE"))
	elseif string.find(path, "pathfinding.xml") then
		infoBox(GetTranslatedStringByKey("THIS_EXAMPLE_4"))
	elseif string.find(path, "constraints.xml") then
		infoBox(GetTranslatedStringByKey("CONSTRAINTS_ARE"))
	elseif string.find(path, "spawning.xml") then
		infoBox(GetTranslatedStringByKey("SPAWNING_CAN"))
	elseif string.find(path, "shapemanipulation.xml") then
		infoBox("Scripts can create, rearrange and manipulate shapes by dynamically adding and removing voxels at run-time. This example includes a script that grows procedural sculptures.")
	else
		--Print message about making a local copy only if it's not already a local copy
		local localMsg = ""
		if string.sub(GetString("game.mod"), 0, 5) ~= "local" then
			localMsg = GetTranslatedStringByKey("LOCALMSG_WELCOME_TO")
		end
		infoBox(localMsg .. GetTranslatedStringByKey("THIS_IS"))
	end
end


function infoBox(txt)
	UiPush()
		UiFont("regular.ttf", 22)
		UiWordWrap(500)

		local w,h = UiGetTextSize(txt)
		UiTranslate(20-600*(1-visible), UiHeight()-h-50)
		UiColor(0,0,0, 0.7)
		UiImageBox("ui/common/box-solid-10.png", w+40, h+30, 10, 10)
		UiTranslate(20, 35)
		
		UiColor(1,1,1)
		UiText(txt)
	UiPop()
end
