
--import config.lua
--import uiLib.lua
--import polyUtil.lua

-- examples files:
--import fpsExample.lua
--import thirdPersonExample.lua
--import sideScrollerExample.lua
--import uiExample.lua
--import meshExample.lua
--import microShaderExample.lua
--import renderToSpriteExample.lua
--import spriteEmitterExample.lua
--import audioExample.lua

Menu = {}

Menu.buttonWidth = 140.0
Menu.buttonHeight = 16.0
Menu.updateExample = nil

function start()
	setMouseLocked(false)

	UILib.init()
	
	Menu.background = UILib.panel("", vec3(0.0, 0.0, -1.0), vec2(320.0, 280.0), Config.paletteNames.black)

	Menu.title = UILib.panel("examples", vec3(0.0, 8.0, 0.0), vec2(320.0, 16.0), Config.paletteNames.black, Config.paletteNames.white)
	Menu.title.textOffset = vec2(128.0, 4.0)

	Menu.fpsButton = UILib.button("fps", vec3(16.0, 40.0, 0.0), vec2(Menu.buttonWidth, Menu.buttonHeight), Config.palette[5], 
		function() 
			Menu.updateExample = FpsExample.update
			FpsExample.start()
		end)
	Menu.fpsButton.textOffset = vec2(4.0, 4.0)

	Menu.thirdPersonButton = UILib.button("third person", vec3(164.0, 40.0, 0.0), vec2(Menu.buttonWidth, Menu.buttonHeight), Config.palette[6],
		function()
			Menu.updateExample = ThirdPersonExample.update
			ThirdPersonExample.start()
		end)
	Menu.thirdPersonButton.textOffset = vec2(4.0, 4.0)

	Menu.sideScrollerButton = UILib.button("2d side scroller", vec3(16.0, 62.0, 0.0), vec2(Menu.buttonWidth, Menu.buttonHeight), Config.palette[9], 
		function() 
			Menu.updateExample = SideScrollerExample.update
			SideScrollerExample.start()
		end)
	Menu.sideScrollerButton.textOffset = vec2(4.0, 4.0)

	Menu.uiButton = UILib.button("UI", vec3(164.0, 62.0, 0.0), vec2(Menu.buttonWidth, Menu.buttonHeight), Config.palette[11],
		function()
			UILib.clear()

			Menu.updateExample = UIExample.update
			UIExample.start()
		end)
	Menu.uiButton.textOffset = vec2(4.0, 4.0)

	Menu.meshButton = UILib.button("mesh", vec3(16.0, 84.0, 0.0), vec2(Menu.buttonWidth, Menu.buttonHeight), Config.palette[12],
		function()
			Menu.updateExample = MeshExample.update
			MeshExample.start()
		end)
	Menu.meshButton.textOffset = vec2(4.0, 4.0)

	Menu.renderToSpriteButton = UILib.button("render to sprite", vec3(164.0, 84.0, 0.0), vec2(Menu.buttonWidth, Menu.buttonHeight), Config.palette[18],
		function()
			Menu.updateExample = RenderToSpriteExample.update
			RenderToSpriteExample.start()
		end)
	Menu.renderToSpriteButton.textOffset = vec2(4.0, 4.0)

	Menu.microShaderButton = UILib.button("micro shader", vec3(16.0, 106.0, 0.0), vec2(Menu.buttonWidth, Menu.buttonHeight), Config.palette[7],
		function()
			Menu.updateExample = MicroShaderExample.update
			MicroShaderExample.start()
		end)
	Menu.microShaderButton.textOffset = vec2(4.0, 4.0)

	Menu.spritesEmitterButton = UILib.button("sprites emitter", vec3(164.0, 106.0, 0.0), vec2(Menu.buttonWidth, Menu.buttonHeight), Config.palette[15],
		function()
			Menu.updateExample = SpriteEmitterExample.update
			SpriteEmitterExample.start()
		end)
	Menu.spritesEmitterButton.textOffset = vec2(4.0, 4.0)

	Menu.audioButton = UILib.button("audio", vec3(16.0, 128.0, 0.0), vec2(Menu.buttonWidth, Menu.buttonHeight), Config.palette[19],
		function()
			Menu.updateExample = AudioExample.update
			AudioExample.start()
		end)
	Menu.audioButton.textOffset = vec2(4.0, 4.0)
end

function update()
	clearScreen(Config.paletteNames.black)

	if Menu.updateExample ~= nil then
		Menu.updateExample()

		return
	end

	UILib.update()

	UILib.drawCursor(getMousePosition())
end
