#include "script/common.lua"
#include "starthub.lua"
#include "missions.lua"

gResetScale = 0

function init()
end

function tick(dt)
	SetBool("game.disablepause", true)
	SetBool("hud.disable", true)
	PlayMusic("MOD/music/menu-loop.ogg")
	if InputPressed("pause") then 
		Menu()
	end
end

function draw()
	UiMakeInteractive()

	UiPush()
		UiColor(0,0,0)
		UiRect(UiWidth(), UiHeight())
	UiPop()
	if UiWidth() > 1920 then
		UiTranslate((UiWidth() - 1920) / 2, 0)
		UiWindow(1920, 1080)
	end
	
	UiImage("menu/background.jpg")
	UiPush()
		UiColor(0, 0, 0, 0.75)
		UiRect(UiWidth(), 150)
		UiColor(1, 1, 1)
		UiFont("bold.ttf", 40)
		UiTranslate(UiCenter(), 60)
		UiAlign("center middle")
		UiPush()
			UiScale(2)
			UiText("ÀÑÓ-ÂÀÎÄÀÌÞ")
		UiPop()
		UiTranslate(0, 45)
		UiScale(1.08)
		UiText("ÑÀÈÑÞÂÎÀâ àËÒÐÀÎÒÉâ")
	UiPop()
	
	UiPush()
		UiColor(0, 0, 0, 0.75)
		UiTranslate(20, 170)
		UiImageBox("ui/common/box-solid-10.png", 256, 256, 10, 10)
		UiButtonImageBox("ui/common/box-outline-fill-6.png", 6, 6, 0.96, 0.96, 0.96)
		UiColor(0.96, 0.96, 0.96)
		UiAlign("center middle")
		UiTranslate(128, 40)
		UiFont("regular.ttf", 26)
		if UiTextButton("Ëãðóãñì¿", 200, 40) then
			startHub()
		end
		UiTranslate(0, 48)
		if UiTextButton("Ðéõòýñìüã", 200, 40) then
			StartLevel("museum_sandbox", "MOD/tillaggaryd.xml", "sandbox")
		end
		UiTranslate(0, 48)

		UiTranslate(0, 30)

		UiPush()
			if not HasKey("savegame.mod") then
				UiColorFilter(1,1,1,0.5)
				UiDisableInput()
			end
			if UiTextButton("Òäôòõ óôòçôéõõã...", 200, 40) then
				if gResetScale == 0 then
					SetValue("gResetScale", 1, "cosine", 0.25)
				else
					SetValue("gResetScale", 0, "cosine", 0.25)
				end
			end
		UiPop()
		
		if gResetScale > 0 then
			UiPush()
				UiTranslate(130, -40)
				UiScale(gResetScale, 1)
				UiColorFilter(1,1,1,gResetScale)
				UiColor(0,0,0)
				UiAlign("top left")
				UiImageBox("ui/common/box-solid-10.png", 500, 80, 10, 10)
				UiTranslate(20, 15)
				UiFont("regular.ttf", 22)
				UiColor(1,1,1)
				local completedMissions = 0
				for m,_ in pairs(gArtMissions) do
					if GetBool("savegame.mod."..m..".complete") then completedMissions = completedMissions + 1 end
				end
				if completedMissions > 0 then
					UiText("àöò ùñìýöòêìö óôòçôéõõ èï¿\n"..completedMissions.." å Àôö-åãñèãïº")
				else
					UiText("àöò ùèãïìö óôòçôéõõ\nåõéû îãðóãñìí Àôö-åãñèãïº")
				end
				UiTranslate(250, 10)
				UiFont("regular.ttf", 26)
				UiPush()
					UiColorFilter(1, 0.8, 0.8)
					if UiTextButton("Òäôòõ", 100, 34) then
						ClearKey("savegame.mod")
						SetValue("gResetScale", 0, "cosine", 0.25)
					end
				UiPop()
				UiTranslate(110, 0)
				if UiTextButton("Ïöðéñã", 100, 34) then
					SetValue("gResetScale", 0, "cosine", 0.25)
				end
			UiPop()
		end
		
		UiTranslate(0, 48)
		if UiTextButton("Ãïãåñòé ðéñ¾", 200, 40) then
			Menu()
		end
		UiTranslate(0, 48)
	UiPop()
end


