--/* Start File Header -------------------------------------------------------
--Copyright (C) 2010 DigiPen Institute of Technology.
--Reproduction or disclosure of this file or its contents without the prior written consent of DigiPen Institute of Technology is prohibited.
--File Name: PauseFunctions.lua
--Purpose: To provide the various lua functions used by the pause menu
--Authors: Robert Francis - 100%
--- End File Header --------------------------------------------------------*/

--Pause menu
function POnOver(go)
  PlaySound("MenuClick");
  s = GetSpriteComp(go);
  SpriteComp_SetVars(s, Vec2(0,0.875), Vec2(.5, .115));
  SpriteComp_TextColor(s, Vec4(0,0,0,255));
end

function POnExit(go)
  s = GetSpriteComp(go);
  SpriteComp_SetVars(s, Vec2(0,0.125), Vec2(.5, .115));
  SpriteComp_TextColor(s, Vec4(255, 255, 255, 255));
end

function HOnOver(go)
  PlaySound("MenuClick");
  s = GetSpriteComp(go);
  SpriteComp_SetVars(s, Vec2(0.25,0.385), Vec2(.25, .23));
  SpriteComp_TextColor(s, Vec4(0,0,0,255));
end

function HOnExit(go)
  s = GetSpriteComp(go);
  SpriteComp_SetVars(s, Vec2(0,0.385), Vec2(.25, .23));
  SpriteComp_TextColor(s, Vec4(255, 255, 255, 255));
end

function HowToPlayPauseButton(name, inst)
	x, y, z = GOGetPos(name, inst);
	  go = GetGOPointer(name, inst);
  s = GetSpriteComp(go);
  r, g, b, a = SpriteComp_GetTextColor(s);
	SetFontColor("ethnocentric", r, g, b, a);
	ScreenText("ethnocentric", x, y + 50, "HOW TO\nPLAY", .4);
end

function ExitPauseButton(name, inst)
	x, y, z = GOGetPos(name, inst);
	  go = GetGOPointer(name, inst);
  s = GetSpriteComp(go);
  r, g, b, a = SpriteComp_GetTextColor(s);
  SetFontColor("ethnocentric", r, g, b, a);
	ScreenText("ethnocentric", x, y+60, "EXIT\nGAME", .4);
end

function OptionsPauseButton(name, inst)
	x, y, z = GOGetPos(name, inst);
  go = GetGOPointer(name, inst);
  s = GetSpriteComp(go);
  r, g, b, a = SpriteComp_GetTextColor(s);
	SetFontColor("ethnocentric", r, g, b, a);
	ScreenText("ethnocentric", x, y+15, "OPTIONS", .4);
end

function CreditsPauseButton(name, inst)
	x, y, z = GOGetPos(name, inst);
	  go = GetGOPointer(name, inst);
  s = GetSpriteComp(go);
  r, g, b, a = SpriteComp_GetTextColor(s);
  SetFontColor("ethnocentric", r, g, b, a);
	ScreenText("ethnocentric", x, y + 17, "CREDITS", .4);
  SetPause(true);
end

function ExitConfirmText(name, inst)
    x, y, z = GOGetPos(name, inst);
	SetFontColor("ethnocentric", 255, 255, 255, 255);
	ScreenText("ethnocentric", x, y, "Are you sure that you\n want to exit the game?", .4);
end

function ExitPauseClick(x, y)
	SetCompString("PauseConfirm", 0, "Lua", "FuncName", "ExitConfirmText");
	SetCompString("PauseYes", 0, "IsClicked", "LuaOnClick", "EndGame");
	TogglePauseConfirm();
end

function MainMenuConfirmText(name, inst)
  x, y, z = GOGetPos(name, inst);
	SetFontColor("ethnocentric", 255, 255, 255, 255);
	ScreenText("ethnocentric", x, y, "Are you sure that you want\n to quit to the main menu?", .4);
end

function MainMenuPauseClick(x, y)
	SetCompString("PauseConfirm", 0, "Lua", "FuncName", "MainMenuConfirmText");
	SetCompString("PauseYes", 0, "IsClicked", "LuaOnClick", "MainMenuYes");
	TogglePauseConfirm();
end

function MainMenuYes(x, y)
	SetNextLevel("MainMenu.xml");
	EndLevel();
end

function MainMenuPauseButton(name, inst)
	x, y, z = GOGetPos(name, inst);
	go = GetGOPointer(name, inst);
  s = GetSpriteComp(go);
  r, g, b, a = SpriteComp_GetTextColor(s);
  SetFontColor("ethnocentric", r, g, b, a);
	ScreenText("ethnocentric", x, y+15, "MAIN MENU", .4);
end

function RestartConfirmText(name, inst)
    x, y, z = GOGetPos(name, inst);
	SetFontColor("ethnocentric", 255, 255, 255, 255);
	ScreenText("ethnocentric", x, y, "Are you sure that\n you want to Restart?", .4);
end

function RestartPauseClick(x, y)
	SetCompString("PauseConfirm", 0, "Lua", "FuncName", "RestartConfirmText");
	SetCompString("PauseYes", 0, "IsClicked", "LuaOnClick", "RestartLevel");
	TogglePauseConfirm();
end

function RestartPauseButton(name, inst)
	x, y, z = GOGetPos(name, inst);
	go = GetGOPointer(name, inst);
  s = GetSpriteComp(go);
  r, g, b, a = SpriteComp_GetTextColor(s);
  SetFontColor("ethnocentric", r, g, b, a);
	ScreenText("ethnocentric", x-15, y+15, "RESTART GAME", .4);
end

function ResumePauseClick(x, y)
	TogglePauseMenu();
end

function CreditsPauseClick(x, y)
	LoadLevel("Credits.xml");
end

function TogglePauseConfirm()
	a = GOGetActive("PauseConfirm", 0);
	PauseActive(a);
	GOActive("PauseConfirm", 0, not a);
	GOActive("PauseYes", 0, not a);
	GOActive("PauseNo", 0, not a);
end

function ResumePauseButton(name, inst)
	x, y, z = GOGetPos(name, inst);
	go = GetGOPointer(name, inst);
  s = GetSpriteComp(go);
  r, g, b, a = SpriteComp_GetTextColor(s);
  SetFontColor("ethnocentric", r, g, b, a);
	ScreenText("ethnocentric", x-15, y+15, "RESUME GAME", .4);
end

function TogglePauseMenu()
	if IsGameObject("ExitPause", 0) == true then
		set = IsPaused();
		PauseActive(not set);
		SetPause(not set);
		PauseSound(not set);
	end
end

function LoadPauseMenu()
	LoadProto("ExitPause");
	LoadProto("HowToPlayPause");
	LoadProto("MainMenuPause");
	LoadProto("OptionsPause");
	LoadProto("PauseBG");
	LoadProto("RestartPause");
	LoadProto("ResumePause");
	LoadProto("PauseConfirm");
	LoadProto("PauseNo");
	LoadProto("PauseYes");
  LoadProto("CreditsPause");
	if IsGameObject("ExitPause", 0) == false then
		GOFromProto("ExitPause", 255.27, -313.39, 0);
		GOFromProto("HowToPlayPause", 389.19, -93.58, 0);
		GOFromProto("MainMenuPause", -100, -49.98, 0);
		GOFromProto("OptionsPause", -100, 52.23, 0);
		GOFromProto("PauseBG", 0, 0, -0.01);
		GOFromProto("RestartPause", -100, 155.49, 0);
		GOFromProto("ResumePause", -100, 258.68, 0);
		GOFromProto("PauseConfirm", 0, 50, 0);
		GOFromProto("PauseNo", 144.1, -150, 0);
		GOFromProto("PauseYes", -121.67, -150, 0);
    GOFromProto("CreditsPause", -100, -155.47, 0);
		GOScale("ExitPause", 0, 256, 256, 1);
		GOScale("HowToPlayPause", 0, 256, 256, 1);
		GOScale("MainMenuPause", 0, 550, 108.05, 1);
		GOScale("OptionsPause", 0, 550, 108.05, 1);
    GOScale("CreditsPause", 0, 550, 108.05, 1);
		GOScale("PauseBG", 0, 1024, 1024, 1);
		GOScale("RestartPause", 0, 550, 108.05, 1);
		GOScale("ResumePause", 0, 550, 108.05, 1);
		GOScale("PauseConfirm", 0, 550, 108.05, 1);
		GOScale("PauseNo", 0, 256, 83, 1);
		GOScale("PauseYes", 0, 256, 83, 1);
		GOExportable("ExitPause", 0, false);
		GOExportable("HowToPlayPause", 0, false);
		GOExportable("MainMenuPause", 0, false);
		GOExportable("OptionsPause", 0, false);
    GOExportable("CreditsPause", 0, false);
		GOExportable("PauseBG", 0, false);
		GOExportable("RestartPause", 0, false);
		GOExportable("ResumePause", 0, false);
		GOExportable("PauseConfirm", 0, false);
		GOExportable("PauseNo", 0, false);
		GOExportable("PauseYes", 0, false);
  end
	CreateKeyboardAction(VK_ESCAPE, "Pause");
	RegisterForInput("Pause", "TogglePauseMenu", ACTION_TRIGGER);
	PauseActive(false);
end

function UnloadPauseMenu()
	UnregisterForInput("Pause", ACTION_TRIGGER);
end

function PauseActive(set)
	GOActive("ExitPause", 0, set);
	GOActive("HowToPlayPause", 0, set);
	GOActive("MainMenuPause", 0, set);
	GOActive("OptionsPause", 0, set);
	GOActive("PauseBG", 0, set);
	GOActive("RestartPause", 0, set);
  GOActive("CreditsPause", 0, set);
	GOActive("ResumePause", 0, set);
	if set == false then
		GOActive("PauseConfirm", 0, set);
		GOActive("PauseYes", 0, set);
		GOActive("PauseNo", 0, set);
    VisibleCursor(set);
	end
end