////////////////////////////////////////////////////////////////////////////////
// AVP_GUIMenu_System.cpp
//
// Created by GJDH - 15/03/2007
//
// Copyright (C) 2003 Rebellion, All Rights Reserved.
//
////////////////////////////////////////////////////////////////////////////////


#include "Core/Asura.h"

#if defined(ASURA_USE_GUI_MENU_SYSTEM)

#include "Rendering//Asura_Viewport.h"
#include "Camera/Asura_Camera.h"

#include "Blueprint/Asura_Blueprint.h"
#include "Blueprint/Asura_Blueprint_System.h"
#include "Core/Asura_Core.h"
#include "Core/Asura_Timers.h"
#include "ChunkSystem/Asura_Chunk_Loaders.h"
#include "Debugging/Asura_CPUProfile_Renderer.h"
#include "GUIMenu/Asura_GUIMenu_Menu_Page.h"
#include "GUIMenu/Asura_GUIMenu_Element_Text.h"
#include "Input/Asura_ControlManager.h"
#include "Interface/Asura_CommandConsole.h"
#ifdef ASURA_USE_CURSOR
#include "Interface/Asura_Cursor.h"
#endif
#include "Sound/Asura_Dynamic_Music_System.h"
#include "Sound/Asura_MetaMusic_System.h"
#include "Sound/Asura_Sound.h"
#ifdef ASURA_TOOLS
#include "Interface/Asura_Overlay_System.h"
#include "Misc/Tools_Render_Options.h"
#endif


// This file's header file
#include "GUIMenu/AVP_GUIMenu_System.h"


// AVP header files
#include "Actor/AVP_Actor_InputHandler.h"
#include "Actor/AVP_Actor_HUDHandler.h"
#include "Actor/Vertebrates/Human/AVP_Human_HUDHandler.h"
#include "Core/AVP_Core.h"
#include "Core/AVP_Game_Core.h"
#include "Core/AVP_Settings.h"
#include "Entity/AVP_Entity_Classification.h"
#include "Entity/AVP_Messages.h"
#include "Entity/PhysicalObject/Actor/Vertebrates/AVP_ClientActor_Vertebrate.h"

#include "Entity/PhysicalObject/Actor/Vertebrates/Alien/AVP_ServerActor_Alien.h"
#include "Entity/PhysicalObject/Actor/Vertebrates/Human/Marine/AVP_ServerActor_Marine.h"
#include "Entity/PhysicalObject/Actor/Vertebrates/Predator/AVP_ServerActor_Predator.h"

#include "FrontEnd/AVP_GameFrontEnd.h"
#include "GUIMenu/AVP_GUIMenu_AudioDiaries.h"
#include "GUIMenu/AVP_GUIMenu_PlayerObjectives.h"
#include "Multiplayer/AVP_Multiplayer_HashIds.h"
#include "Multiplayer/AVP_Multiplayer_ScoreBoard.h"
#include "Network/AVP_Player.h"

#include "FMV/AVP_FMV.h"
#include "Inventory/AVP_Inventory_System.h"
#include "Inventory/AVP_Inventory_Item.h"
#include "Inventory/AVP_Inventory_HashIDs.h"
#include "GUIMenu/Asura_GUIMenu_Element_Image.h"
#include "GUIMenu/Asura_GUIMenu_Menu_Page.h"
#include "SpecialFX/pfx/AVP_DamagePFX.h"

////////////////////////////////////////////////////////////////////////////////
// Nasty hard-coded level-select and character-select tables...
////////////////////////////////////////////////////////////////////////////////
struct CharacterData
{
	AVP_Settings::Species	m_eSpecies;
	bool					m_bStartGame;
};

struct LevelData
{
	char const*				m_szFilename;
	AVP_Settings::Species	m_eSpecies;
	bool					m_bStartGame;
};

static const LevelData	g_axLevelData[] =
{
	// Marine levels...
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Colony\\M01_Colony"),		AVP_Settings::AVP_SPECIES_HUMAN,	true},	// 0
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Refinery\\M02_Refinery"),	AVP_Settings::AVP_SPECIES_HUMAN,	true},	// 1
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Jungle\\M03_Jungle"),		AVP_Settings::AVP_SPECIES_HUMAN,	true},	// 2
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Ruins\\M04_Ruins"),			AVP_Settings::AVP_SPECIES_HUMAN,	true},	// 3
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Lab\\M05_Lab"),				AVP_Settings::AVP_SPECIES_HUMAN,	true},	// 4
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Pyramid\\M06_Pyramid"),		AVP_Settings::AVP_SPECIES_HUMAN,	true},	// 5

	// Alien levels...
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Lab\\A01_Lab"),				AVP_Settings::AVP_SPECIES_ALIEN,	true},	// 6
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Ruins\\A02_Ruins"),			AVP_Settings::AVP_SPECIES_ALIEN,	true},	// 7
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Jungle\\A03_Jungle"),		AVP_Settings::AVP_SPECIES_ALIEN,	true},	// 8
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Refinery\\A04_Refinery"),	AVP_Settings::AVP_SPECIES_ALIEN,	true},	// 9
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Colony\\A05_Colony"),		AVP_Settings::AVP_SPECIES_ALIEN,	true},	// 10
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Pyramid\\A06_Pyramid"),		AVP_Settings::AVP_SPECIES_ALIEN,	true},	// 11

	// Predator levels...
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Jungle\\P01_Jungle"),		AVP_Settings::AVP_SPECIES_PREDATOR,	true},	// 12
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Colony\\P02_Colony"),		AVP_Settings::AVP_SPECIES_PREDATOR,	true},	// 13
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Refinery\\P03_Refinery"),	AVP_Settings::AVP_SPECIES_PREDATOR,	true},	// 14
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Lab\\P04_Lab"),				AVP_Settings::AVP_SPECIES_PREDATOR,	true},	// 15
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Ruins\\P05_Ruins"),			AVP_Settings::AVP_SPECIES_PREDATOR,	true},	// 16
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Pyramid\\P06_Pyramid"),		AVP_Settings::AVP_SPECIES_PREDATOR,	true},	// 17

	// Test levels...
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Tests\\M00_TestArena"),		AVP_Settings::AVP_SPECIES_HUMAN,	true},	// 18
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Tests\\A00_TestArena"),		AVP_Settings::AVP_SPECIES_ALIEN,	true},	// 19
	{AVP_GENERATE_FULL_LEVEL_FILENAME("Tests\\P00_TestArena"),		AVP_Settings::AVP_SPECIES_PREDATOR,	true},	// 20

	{AVP_GENERATE_FULL_LEVEL_FILENAME("Tests\\Test_Corridors"),		AVP_Settings::AVP_SPECIES_HUMAN,	true},	// 21

	// Demo Levels...
};

static const u_int	g_uNumLevels	= sizeof(g_axLevelData) / sizeof(g_axLevelData[0]);

// Defines
#define PAUSEMENU_RESUMEGAME		L"PauseMenu.ResumeGame"
#define PAUSEMENU_CHEATS			L"PauseMenu.Cheats"
#define PAUSEMENU_CONTROLS			L"PauseMenu.Controls"
#define PAUSEMENU_DEBUGVARS			L"PauseMenu.DisplayDebugVars"
#define PAUSEMENU_RESTART			L"PauseMenu.Restart"
#define PAUSEMENU_CHECKPOINT		L"PauseMenu.Checkpoint"
#define PAUSEMENU_QUIT				L"PauseMenu.Quit"
#define PAUSEMENU_QUITAPPLICATION	L"PauseMenu.QuitApplication"

#define CONTROLSMENU_AUTOCENTER		L"ControlsMenu.AutoCenterCamera"
#define GENERALMENU_TRUECOND		L"GeneralMenu.AlwaysTrueReference"

#define CHEATMENU_ENABLEGODMODE		L"CheatMenu.EnableGodMode"
#define CHEATMENU_ENABLEINFINITEAMMO L"CheatMenu.EnableInfiniteAmmo"
#define CHEATMENU_CAMERAMODE		L"CheatMenu.CameraMode"
#define CHEATMENU_FREEZETIME		L"CheatMenu.FreezeTime"
#define CHEATMENU_COMPLETELEVEL		L"CheatMenu.CompleteLevel"
#define CHEATMENU_ISMULTIPLAYER		L"CheatMenu.IsSinglePlayer"
#define CHEATMENU_ACID				L"CheatMenu.AllDmgIsAcid"

#define CHEATMENU_KILLMARINE		L"CheatMenu.KillMarine"
#define CHEATMENU_KILLALIEN			L"CheatMenu.KillAlien"
#define CHEATMENU_KILLPREDATOR		L"CheatMenu.KillPredator"

#define CHEATMENU_SEEVOLUMES		L"CheatMenu.SeeVolumes"

#define SAVESCREEN_EXIT					L"SaveScreen.Exit"
#define MISSIONCOMPLETE_LEVELSELECT		L"MissionComplete.NextLevel"

#define SAVESCREEN_EXIT				L"SaveScreen.Exit"
#define MISSIONCOMPLETE_LEVELSELECT	L"MissionComplete.NextLevel"

#define FRONTENDMENU_TESTLEVELSELECT	L"FrontEnd.TestLevelSelect"
#define FRONTENDMENU_DEVLOBBY			L"FrontEnd.DevLobby"
#define FRONTENDMENU_GAMELOBBY			L"FrontEnd.GameLobby"
#define FRONTEND_EXIT_APP				L"FrontEnd.ExitApplication"
#define FRONTEND_SELECTCHARTYPE			L"FrontEnd.SelectCharType"
#define FRONTEND_SELECTDIFFICULTY		L"FrontEnd.SelectDifficulty"

// static variables

//Pause Menu
bool	AVP_GUIMenu_System::s_bIsInitialised				= false;
bool	AVP_GUIMenu_System::s_bShowLocation					= false;
bool	AVP_GUIMenu_System::s_bOpenDebugVariableMenu		= false;
bool	AVP_GUIMenu_System::s_bQuitApplication				= false;
bool	AVP_GUIMenu_System::s_bQuit							= false;
bool	AVP_GUIMenu_System::s_bRequestRestart				= false;
bool	AVP_GUIMenu_System::s_bRequestRestartFromCheckpoint	= false;

//Cheat Menu 
bool	AVP_GUIMenu_System::s_bFreezeTime					= false;
int		AVP_GUIMenu_System::s_iCameraMode					= 0;

//Other Menus
bool	AVP_GUIMenu_System::s_bChooseNextLevel				= false;
bool	AVP_GUIMenu_System::s_bExitSaveScreen				= false;

//FrontEnd Choice Toggle
#if defined(ASURA_SUPPORT_LOBBY)
AVP_GUIMenu_System::LOBBY_TYPE	AVP_GUIMenu_System::s_eLobbyType			= LT_NONE;
#endif	//defined(ASURA_SUPPORT_LOBBY)
bool							AVP_GUIMenu_System::s_bGeneralTrueReference	= true;

#ifdef ASURA_SUPPORT_COMMAND_CONSOLE
static bool g_bHudWasEnabled = true;
#endif // #ifdef ASURA_SUPPORT_COMMAND_CONSOLE

Asura_Hash_ID AVP_GUIMenu_System::s_auHashed_GUIMenuNames[NUM_MENU_SPECIES][GUIMENU_ID_MAX] =
{
	{
		0x676667c4,	//"Alien_Loading"
		0x11cd94ec,	//"Alien_AwaitingHost"
		0x65ef9f7f,	//"Alien_HUD"
		0xA98851B7, //"Alien_HUD_Elements"
		0xa8edae7e,	//"Alien_Pause"
		0xadf48a3e,	//"Alien_GameOver"
		0xd429e54d,	//"Alien_MissionComplete"
		0xED52FAD2, //"Alien_Objectives
		0x00000000  //"Alien_WeaponSelect"
	},
	
	{
		0x212c33bf,	//"Marine_Loading"
		0xbf3f0dd1,	//"Marine_AwaitingHost"
		0xe758a0fa,	//"Marine_HUD"
		0x56F9CA9C, //"Marine_HUD_Elements"
		0x741c3d39,	//"Marine_Pause"
		0x2ce83da3,	//"Marine_GameOver"
		0x9c0d8648,	//"Marine_MissionComplete"
		0x7E2768F7, //"Marine_Objectives
		0x07D4B975  //"Marine_WeaponSelect"
	},

	{
		0xf01823f4,	//"Predator_Loading"
		0x70b9f6bc,	//"Predator_AwaitingHost"
		0x0fc6f3af,	//"Predator_HUD"
		0x0874B387, //"Predator_HUD_Elements"
		0x3a40b6ae,	//"Predator_Pause"
		0x3b7a540e,	//"Predator_GameOver"
		0x2a34717d,	//"Predator_MissionComplete"
		0x308D90A2, //"Predator_Objectives
		0xB94FA260  //"Predator_WeaponSelect"
	}
};

FadingWidgetInfo AVP_GUIMenu_System::s_axFadingWidgets[FADING_WIDGET_MAX] =
{
	{ "InteractionPrompt", 2, 2, 0, 0 }
};

bool				AVP_GUIMenu_System::s_abWidgetLookedUp[NUM_STORED_WIDGETS];
Asura_GUIMenu_Root*	AVP_GUIMenu_System::s_apxStoredHUDWidgets[NUM_STORED_WIDGETS];
Asura_Hash_ID		AVP_GUIMenu_System::s_auStoredHUDWidgetHashes[NUM_STORED_WIDGETS] = {
	0x3A5F1EC2,	//	MOTION_TRACKER, Asura_GetHashID( "MotionTracker" )
	
	0x973506B5, //	MOTION_TRACKER_SCANNER1, Asura_GetHashID( "MotionTrackerScanner1" )
	0x973506B6, //	MOTION_TRACKER_SCANNER2, Asura_GetHashID( "MotionTrackerScanner2" )
	0x973506B7, //	MOTION_TRACKER_SCANNER3, Asura_GetHashID( "MotionTrackerScanner3" )
	0x8798850B, //  MOTION_TRACKER_DOT_CONTAINER, Asura_GetHashID( "Dot_Container" )
	0x8E4BDCFA, //  MOTION_TRACKER_PULSE1,     Asura_GetHashID( "MotionTrackerPulse1" )
	0x8E4BDCFB, //  MOTION_TRACKER_PULSE2,     Asura_GetHashID( "MotionTrackerPulse2" )
	0xC33DD747, //  MOTION_TRACKER_DOT,        Asura_GetHashID( MotionTrackerDot" )
	0xA47D1206, //  MOTION_TRACKER_DOT_MARINE, Asura_GetHashID( MotionTrackerDotM" )
	0xEB4273EB, //  MOTION_TRACKER_BASE0,  Asura_GetHashID( MotionTrackerFrame" )
	0xFF811078, //  MOTION_TRACKER_BASE1,  Asura_GetHashID( Motion_Tracker_Base_Blue" )
	0xF1C6EFCB, //  MOTION_TRACKER_BASE2,  Asura_GetHashID( Motion_Tracker_Base_White" )
	0xD06A4E5A, //  MOTION_TRACKER_DISTANCE1,  Asura_GetHashID( MotionTrackerDistance1" )
	0xD06A4E5B, //  MOTION_TRACKER_DISTANCE2,  Asura_GetHashID( MotionTrackerDistance2" )
	0xD06A4E5C, //  MOTION_TRACKER_DISTANCE3,  Asura_GetHashID( MotionTrackerDistance3" )

	0x6f72f019,	//	VISION_SELECTOR_BACKGROUND1, Asura_GetHashID( "VisionModeSelectorBackground1" )
	0x6f72f01a,	//	VISION_SELECTOR_BACKGROUND2, Asura_GetHashID( "VisionModeSelectorBackground2" )

	0xe06cb685,	// VisionModeSelectorUp
	0x8ae019f2,	// VisionModeSelectorRight
	0x78117a0c,	// VisionModeSelectorDown
	0x7814f571,	// VisionModeSelectorLeft

	0x1e3ffbe8,	// WEAPON_SELECTOR_BACKGROUND1, Asura_GetHashID( "WeaponSelectorBackground1" )
	0x1e3ffbe9,	// WEAPON_SELECTOR_BACKGROUND2, Asura_GetHashID( "WeaponSelectorBackground2" )
	0x15642EC8, // button_top
	0x4CF49ECF, // button_right
	0x36AC53D8, // button_bottom
	0x971DE0F4, // button_left

	0xa02d9189,	// ReticleCenter
	0xb3758dcf,	// ReticleUp
	0xdcb58668,	// ReticleRight
	0xac41a6d6,	// ReticleDown
	0xac45223b,	// ReticleLeft

	0xdc1ebacb, // ReticleGroup

	0xda69fd8c,	// HealthPointerEmpty
	0x7aa92670,	// HealthPointerFull
	0xb2901c61,	// HealthPointer

	0x62894bb8,	// EnergyPointerEmpty
	0x8f9162c4,	// EnergyPointerFull
	0x980ba2b5,	// EnergyPointer

	0xC91B5132,	// ActiveGrapple_HudBar
	0xCA5E23AC,	// ActiveGrapple_Image1
	0xCA5E23AD,	// ActiveGrapple_Image2
	0x723F7876,	// ActiveGrapple_Path1

	0xC9BFAA15, // DynLabel_Objective
	0x9CDCAEC1, // OBJ_ARROW

	0x74c41556,	// GP_DamageEffect

	0xed2410a6,	// GP_Counter

	0x836c9b70,	// DamageDirectionIndicator 1
	0x836c9b71, // DamageDirectionIndicator 2

	0xF32F4DC7, // Target_Actor
	0x4173BC34, // Reticle

	0xfbc0bed7,		// Ticker 01
	0xfbc0bed8,		// Ticker 02
	0xfbc0bed9,		// Ticker 03
	0xfbc0beda,		// Ticker 04
	0xfbc0bedb,		// Ticker 05
	0xfbc0bedc,		// Ticker 06
	0xfbc0bedd,		// Ticker 07
	0xfbc0bede,		// Ticker 08
	0xfbc0bedf,		// Ticker 09
	0xfbc0bef5,		// Ticker 10
	0xfbc0bef6,		// Ticker 11
	0xfbc0bef7,		// Ticker 12
	0xfbc0bef8,		// Ticker 13
	0xfbc0bef9,		// Ticker 14
	0xfbc0befa,		// Ticker 15
	0xfbc0befb,		// Ticker 16
	0xfbc0befc,		// Ticker 17
	0xfbc0befd,		// Ticker 18
	0xfbc0befe,		// Ticker 19
	0xfbc0bf14,		// Ticker 20
	0xfbc0bf15,		// Ticker 21
	0xfbc0bf16,		// Ticker 22
	0xfbc0bf17,		// Ticker 23
	0xfbc0bf18,		// Ticker 24

	0x1823e092,		// "Enemy_Arrow"
	0xba491fa7,		// "Team_Arrow"
	0x8fedbf60,		// "Persecutor_Arrow"

	0xC90058A6,		// "BackDrop_Team"
	0xB0D18F25,		// "Title_GameType_1"
	0xD1DBFB69,		// "IM_BG_GP_RedTeam_1"
	0x815D4977,		// "IM_GP_BackgroundAddOn"

	0x20452848,		// "TeamScore_List"
	0x69F64FEA,		// "Team0_List"
	0x6BAB2889,		// "Team1_List"
	0x6D600128,		// "Team2_List"
	0x6F14D9C7,		// "Team3_List"

	0xE1CDFA61,		// MULTIPLAYER_STATS_MATCH_KILLSMARINE, "TXT_Kills_Marine_Match"
	0x9B469AC1,		// MULTIPLAYER_STATS_MATCH_KILLSMARINE_SP, "TXT_Kills_MarineHead_Match"
	0x547B8DC0,		// MULTIPLAYER_STATS_MATCH_KILLSPRED, "TXT_Kills_Pred_Match"
	0x0C2D66A0,		// MULTIPLAYER_STATS_MATCH_KILLSPRED_SP, "TXT_Kills_PredHead_Match"
	0x830449D4,		// MULTIPLAYER_STATS_MATCH_KILLSALIEN, "TXT_Kills_Alien_Match"
	0x1111F8B4,		// MULTIPLAYER_STATS_MATCH_KILLSALIEN_SP, "TXT_Kills_AlienHead_Match"
	0xC2797C91,		// MULTIPLAYER_STATS_MATCH_KILLSTOTAL, "TXT_Kills_Total_Match"
	0xF422CF80,		// MULTIPLAYER_STATS_MATCH_SCORETOTAL, "TXT_Score_Final_Match"
	0x47B45F7E,		// MULTIPLAYER_STATS_MATCH_KILLASSISTS, "TXT_Kill_Assists_Match"
	0xB2117CF6,		// MULTIPLAYER_STATS_MATCH_KILLSTREAK, "TXT_Kill_Streak_Match"
	0x4DB77B74,		// MULTIPLAYER_STATS_MATCH_DEATHS, "TXT_Deaths_Match"
	0xC5D51142,		// MULTIPLAYER_STATS_MATCH_RATIO, "TXT_Ratio_Match"
	0x5C59C981,		// MULTIPLAYER_STATS_MATCH_XPPOINTS, "TXT_XP_Points_Match"

	0x46DFFA62,		// MULTIPLAYER_STATS_CAREER_KILLSMARINE, "TXT_Kills_Marine_Career"
	0xBC7B6602,		// MULTIPLAYER_STATS_CAREER_KILLSMARINE_SP, "TXT_Kills_MarineHead_Career"
	0x29E4D2E3,		// MULTIPLAYER_STATS_CAREER_KILLSPRED, "TXT_Kills_Pred_Career"
	0x686E1603,		// MULTIPLAYER_STATS_CAREER_KILLSPRED_SP, "TXT_Kills_PredHead_Career"
	0xCC73994F,		// MULTIPLAYER_STATS_CAREER_KILLSALIEN, "TXT_Kills_Alien_Career"
	0x001BC66F,		// MULTIPLAYER_STATS_CAREER_KILLSALIEN_SP, "TXT_Kills_AlienHead_Career"
	0x7BA4BE32,		// MULTIPLAYER_STATS_CAREER_KILLSTOTAL, "TXT_Kills_Total_Career"
	0x7F25C923,		// MULTIPLAYER_STATS_CAREER_SCORETOTAL, "TXT_Score_Final_Career"
	0x9DC638E5,		// MULTIPLAYER_STATS_CAREER_KILLASSISTS, "TXT_Kill_Assists_Career"
	0x7F0CCA6D,		// MULTIPLAYER_STATS_CAREER_KILLSTREAK, "TXT_Kill_Streak_Career"
	0x58269BAF,		// MULTIPLAYER_STATS_CAREER_DEATHS, "TXT_Deaths_Career"
	0xE3BBBFA1,		// MULTIPLAYER_STATS_CAREER_RATIO, "TXT_Ratio_Career"
	0x1DCE0F42,		// MULTIPLAYER_STATS_CAREER_XPPOINTS, "TXT_XP_Points_Career"

	0x5FD6693A,		// MULTIPLAYER_STATS_WINNINGTEAM, "TXT_TeamNum"
	0xF1E86E07,		// MULTIPLAYER_STATS_WINNINGPLAYER, "TXT_WinnerIndividual"
	0xD5408BCA,		// MULTIPLAYER_STATS_WINNINGSCORE, "TXT_IndividualScore"

	0xFA69C2DA,		// "RespawnTimer_Counter"
	0x31214FD5,		// "SpamBox_Entry"

	0x5e17b734,		// "Rank_Place"
	0x3710c89f,		// "Rank_Players"

	0xe8ce870a,		// "TeamScore_Team1"
	0xe8ce870b,		// "TeamScore_Team2"
	0xe8ce870c,		// "TeamScore_Team3"

	0x7A2D29D3,		// RECON_HEALTH, "TX_ReconHealthFILL"
	0xD0199487,		// RECON_CLASS, "TX_ReconClassFILL"
	0xFE512691,		// RECON_THREAT, "TX_ReconThreatFILL"

	0x07BFBA92		// PREDATOR_LOCKON_GROUP, "Predator_LockOn"
};

// AVP_GUIMenu_System

void AVP_GUIMenu_System::Update(void)
{
	// Temp, to test Resolution menu. AJK
	AVP_Settings::GetCurrentProfile()->Update();

	bool bInMenuBeforeUpdate = IsCurrentlyInNonHudOrLoadingMenu();
	
#ifdef ASURA_DEBUG_VARIABLE_SYSTEM
	if( s_bOpenDebugVariableMenu && !Asura_DebugVariableSystem::IsOpen() )
	{
		Asura_DebugVariableSystem::OpenDisplayDVS();
		s_bOpenDebugVariableMenu = false;
	}
#endif

#ifdef ASURA_USE_CURSOR
	Asura_GUIMenu_System::SetUseCursor(Asura_GUIMenu_System::GetFocusedMenuHashID() != ASURA_HASH_ID_UNSET);
#endif
	Asura_GUIMenu_System::Update();

	//Check for quit application
	if( s_bQuitApplication )
	{
		s_bQuitApplication = false;
		AVP_Core::RequestQuit();
	}

	//Check for quit
	if( s_bQuit )
	{
		s_bQuit = false;
#ifdef ASURA_TOOLS
		AVP_Core::SetToolsRequested(true);
#endif //#ifdef ASURA_TOOLS
		AVP_Core::RequestGameExit();
	}
	
	//Check for restart
	if( s_bRequestRestart )
	{
		s_bRequestRestart = false;
		AVP_Core::RequestRestartLevel();
	}

	//Check for restart from checkpoint
	if( s_bRequestRestartFromCheckpoint )
	{
		s_bRequestRestartFromCheckpoint = false;
		AVP_Core::RequestRestartAtCheckPoint();
	}
	
	//Check for leaving the save screen
	if( s_bExitSaveScreen )
	{
		s_bExitSaveScreen = false;
		Deactivate();
		Activate( GetMenuHash( GUIMENU_ID_MISSIONCOMPLETE ), true, true );
	}

	//Check for mission complete level advancement
	if( s_bChooseNextLevel )
	{
		s_bChooseNextLevel = false;
		Deactivate();
	}

	//Restore music and game input etc. if we just closed the last menu
	if( bInMenuBeforeUpdate && !IsCurrentlyInNonHudOrLoadingMenu() )
	{
		AVP_Game_Core::SetPausedFSFX(false);
		AVP_Game_Core::SetupPausedDSP( false );
		AVP_GUIMenu_AudioDiaries::StopDialogue();
		SetSettingsOnClosure();

		AVP_Actor_HUDHandler::SetHUDAmmoState( AVP_Actor_HUDHandler::HUD_RESUME_GAME );
		AVP_Actor_HUDHandler::SetHUDHealthState( AVP_Actor_HUDHandler::HUD_RESUME_GAME );
		AVP_Actor_HUDHandler::SetHUDEnergyState( AVP_Actor_HUDHandler::HUD_RESUME_GAME );
	}
#ifdef ASURA_TOOLS
	if(Asura_Overlay_System::AreAnyOverlaysVisible())
	{
		Asura_Cursor::SetType(ASURA_CURSOR_CROSSHAIR);
	}
	else
	{
		Asura_Cursor::SetTypeByHash(Asura_GetHashID("Pointer"));
	}
#else
#ifdef ASURA_USE_CURSOR
	Asura_Cursor::SetTypeByHash(Asura_GetHashID("Pointer"));
	Asura_Cursor::OncePerFrameUpdate();
#endif //ASURA_USE_CURSOR
#endif //ASURA_TOOLS

	AVP_GUIMenu_AudioDiaries::Update();

	Platform_Update();
}

void AVP_GUIMenu_System::Render( const bool bClearScreenIfNoRender )
{
	if( s_bIsInitialised )
	{
		Asura_GUIMenu_System::Render();

	//	RenderHUDCounters();

		// If we haven't rendered anything, do we want to blank the screen?
		if(bClearScreenIfNoRender)
		{
			const Asura_Hash_ID	uMenuPageID	= Asura_GUIMenu_System::GetFocusedMenuHashID();

			if((uMenuPageID == ASURA_HASH_ID_UNSET) || !Asura_GUIMenu_System::IsMenuPageHashActive(uMenuPageID))
			{
				const float	fScreenWidth	= static_cast<float>(Asura_Viewport::GetWidth());
				const float	fScreenHeight	= static_cast<float>(Asura_Viewport::GetHeight());

				Asura_Render::Overlay.m_bGouraudShaded	= false;
				Asura_Render::Overlay.m_bNonRotated		= true;
				Asura_Render::Overlay.TextureIndex		= ASURA_TEXTURE_INVALID;
				Asura_Render::Overlay.TranslucencyMode	= ASURA_TRANSLUCENCY_OFF;
				Asura_Render::Overlay.Colour			= 0xFF000000;

				Asura_Render::Overlay.SetRectXY(0.0f, 0.0f, fScreenWidth, fScreenHeight);
				Asura_Render::Overlay.Render();
			}
		}
		#ifdef ASURA_USE_CURSOR
		if( Asura_GUIMenu_System::GetUseCursor() )
		{
			Asura_Cursor::Render();
		}
		#endif
	}
}

bool AVP_GUIMenu_System::IsCurrentlyInNonHudOrLoadingMenu( void )
{
	//Basically: do we have any active menu pages other than the HUD?
	// JG - 26 September 2008 - Included some multiplayer HUD stuff here as well
	// CAH - 2 December 2008  -	Included some SubLevel HUD stuff here as well. 

	bool bRet = false;
	u_int uNumMenuPages = Asura_GUIMenu_System::GetCurrentMenuListCount();

	for( u_int uPageCtr=0; uPageCtr<uNumMenuPages; uPageCtr++ )
	{
		u_int uWeaponSelectorHash = AVP_GUIMenu_System::GetMenuHash(GUIMENU_ID_WEAPONSELECTOR);
		u_int uHudHash = AVP_GUIMenu_System::GetMenuHash(GUIMENU_ID_HUD);
		u_int uLoadHash = AVP_GUIMenu_System::GetMenuHash(GUIMENU_ID_LOADING);
		u_int uMultiplayerHash = s_uAVP_MULTIPLAYER_GAME_MESSAGE_SYSTEM_MENU; 
		u_int uSubHudHash = ASURA_HASH_ID_UNSET;
		if( AVP_Actor_HUDHandler::GetHUDSubLevelLoaded() )
		{
			uSubHudHash = AVP_Actor_HUDHandler::GetHUDSubLevelHashID(); 
		}
		
		Asura_GUIMenu_Menu_Page* pxWeaponSelectorPage = (uWeaponSelectorHash == ASURA_HASH_ID_UNSET ? NULL : Asura_GUIMenu_System::GetMenuPageByID(uWeaponSelectorHash));
		Asura_GUIMenu_Menu_Page* pxHUDPage		= (uHudHash == ASURA_HASH_ID_UNSET ? NULL : Asura_GUIMenu_System::GetMenuPageByID(uHudHash));
		Asura_GUIMenu_Menu_Page* pxLoadPage		= (uLoadHash == ASURA_HASH_ID_UNSET ? NULL : Asura_GUIMenu_System::GetMenuPageByID(uLoadHash));
		Asura_GUIMenu_Menu_Page* pxMultiplayerPage	= (uLoadHash == ASURA_HASH_ID_UNSET ? NULL : Asura_GUIMenu_System::GetMenuPageByID(uMultiplayerHash));
		Asura_GUIMenu_Menu_Page* pxSubHudPage = NULL;
		if( AVP_Actor_HUDHandler::GetHUDSubLevelLoaded() )
		{
			pxSubHudPage	= (uSubHudHash == ASURA_HASH_ID_UNSET ? NULL : Asura_GUIMenu_System::GetMenuPageByID( uSubHudHash ));
		}

		Asura_GUIMenu_Menu_Page* pxCurrentPage = static_cast<Asura_GUIMenu_Menu_Page*>(Asura_GUIMenu_System::GetMenuPageByIndex( uPageCtr ));

		bool bDoHUDCheck	 = true;
		bool bHUDCheckFailed = false;

		bDoHUDCheck = (pxCurrentPage!=NULL && (pxHUDPage != NULL || pxMultiplayerPage != NULL ))? true : false;
		if( AVP_Actor_HUDHandler::GetHUDSubLevelLoaded() )
		{
			bDoHUDCheck = bDoHUDCheck || (pxCurrentPage!=NULL && pxSubHudPage != NULL );
		}
		
		if(bDoHUDCheck == false)
		{
			bHUDCheckFailed = true;
		}
		else
		{
			bHUDCheckFailed = (pxCurrentPage != pxHUDPage && pxCurrentPage != pxMultiplayerPage && pxCurrentPage != pxWeaponSelectorPage);
			if( AVP_Actor_HUDHandler::GetHUDSubLevelLoaded() )
			{
				bHUDCheckFailed = bHUDCheckFailed && ( pxCurrentPage != pxSubHudPage );
			}
		}

		bool bDoLoadCheck	 = true;
		bool bLoadCheckFailed = false;

		bDoLoadCheck = (pxCurrentPage!=NULL && pxLoadPage != NULL)? true : false;

		if(bDoLoadCheck == false)
		{
			bLoadCheckFailed = true;
		}
		else
		{
			bLoadCheckFailed = (pxCurrentPage != pxLoadPage);
		}

		if(bHUDCheckFailed && bLoadCheckFailed && Asura_GUIMenu_System::IsMenuPageActive( uPageCtr ))
		{
			bRet = true;
			break;
		}
	}

	return bRet;
}


void AVP_GUIMenu_System::Activate( GUIMENU_ID eID, AVP_Settings::Species eRequiredSpecies /*=AVP_Settings::AVP_SPECIES_UNKNOWN*/ )
{
	Asura_Hash_ID uHashPageToActivate = GetMenuHash( eID, eRequiredSpecies );

	if(uHashPageToActivate != ASURA_HASH_ID_UNSET)
	{
		s_bFreezeTime = false;
	}

	if( eID == GUIMENU_ID_HUD )
	{
		AVP_ClientEntity_Actor* pxClientActor = AVP_ClientEntity_Actor::FindEntity( AVP_Game_Core::GetPlayer()->GetPuppetGuid() );
		if ( pxClientActor )
		{
			pxClientActor->GetHUDHandler()->Reset();
		}
	}

	bool bStealControls = (eID == GUIMENU_ID_HUD || eID == GUIMENU_ID_WEAPONSELECTOR) ? false : true;
	bool bPause = (eID == GUIMENU_ID_LOADING || eID == GUIMENU_ID_HUD || eID == GUIMENU_ID_WEAPONSELECTOR)?false:true;
	Activate( uHashPageToActivate , bPause, bStealControls );
}

void AVP_GUIMenu_System::Activate( Asura_Hash_ID uHashPageToActivate, bool bPausedInMenu, bool bStealControls )
{
#ifdef ASURA_SUPPORT_COMMAND_CONSOLE
	g_bHudWasEnabled = Asura_Render::IsSystemEnabled( ASURA_RENDER_SYSTEM_HUD );
#endif // #ifdef ASURA_SUPPORT_COMMAND_CONSOLE

	if( uHashPageToActivate != ASURA_HASH_ID_UNSET )
	{
#ifdef ASURA_SUPPORT_COMMAND_CONSOLE
		// Close the console before opening a new menu page
		if ( Asura_CommandConsole::IsConsoleDown() )	
		{ 
			Asura_CommandConsole::Hide( true, true ); 
		}
#endif // #ifdef ASURA_SUPPORT_COMMAND_CONSOLE

#if defined(ASURA_DEBUG_VARIABLE_SYSTEM)
		// Close the DVS menu before opening a new menu page
		if ( Asura_DebugVariableSystem::IsOpen() )
		{
			Asura_DebugVariableSystem::CloseDisplayDVS();
		}
#endif // defined(ASURA_DEBUG_VARIABLE_SYSTEM)

		//Assume (for now) we want to give focus to the page we're activating
		if( Asura_GUIMenu_System::OpenMenuPage( uHashPageToActivate , bStealControls, bStealControls ) && bPausedInMenu )
		{
			if (!AVP_Settings::GetExternalNetworkActive())
			{
				//Stop character receiving input
				Asura_Timers::SetGameTimeScale(0.0f);
				Asura_Dynamic_Music_System::Pause();
			}

			// if we are here it means a page other than the HUD has been opened, so the HUD should be hidden. 
			Asura_Render::SetSystemEnabled( ASURA_RENDER_SYSTEM_HUD, false );
		}
	}
}

void AVP_GUIMenu_System::Deactivate( void )
{
	int iNumMenuPages = static_cast<int>( Asura_GUIMenu_System::GetCurrentMenuListCount() );

	//Loop down the way just in case higher indices are children that'd get closed anyway
	//i.e. close children first (explicitly) and avoid confusing duplication of work
	for( int iPageCtr=(iNumMenuPages-1); iPageCtr>=0; iPageCtr-- )
	{
		if( Asura_GUIMenu_System::IsMenuPageActive( iPageCtr ) )
		{
			Asura_GUIMenu_Root* pMenuPage = Asura_GUIMenu_System::GetMenuPageByIndex( iPageCtr );

			if( pMenuPage )
			{	
				Asura_GUIMenu_System::CloseMenuPage( pMenuPage->GetID() );

				if( IsCurrentlyInNonHudOrLoadingMenu() )
				{
					SetSettingsOnClosure();
				}
			}
		}
	}
}

void AVP_GUIMenu_System::Deactivate( GUIMENU_ID eID, AVP_Settings::Species eRequiredSpecies /*=AVP_Settings::AVP_SPECIES_UNKNOWN*/ )
{
	Asura_Hash_ID uHashPageToDeactivate = GetMenuHash( eID, eRequiredSpecies );
	Deactivate( uHashPageToDeactivate );
}

void AVP_GUIMenu_System::Deactivate( Asura_Hash_ID uHashPageToDeactivate )
{
	//If no hash is provided, default action is to close all open (but not necessarily focused) pages.
	if( uHashPageToDeactivate != ASURA_HASH_ID_UNSET )
	{
		Asura_GUIMenu_System::CloseMenuPage( uHashPageToDeactivate );

		if( IsCurrentlyInNonHudOrLoadingMenu() )
		{
			SetSettingsOnClosure();
		}
	}
}

void AVP_GUIMenu_System::Initialise( void )
{
	if( !s_bIsInitialised )
	{	
		ClearStoredHUDWidgets();

		//Add console commands/vars
		Asura_CommandConsole::AddCmd( PAUSEMENU_RESUMEGAME, ResumeGame, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddCmd( PAUSEMENU_DEBUGVARS, ShowDebugVariablesMenu, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddCmd( PAUSEMENU_RESTART, Restart, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddCmd( PAUSEMENU_CHECKPOINT, RestartFromCheckPoint, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddCmd( PAUSEMENU_QUIT, Quit, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddCmd( PAUSEMENU_QUITAPPLICATION, QuitApplication, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );

		Asura_CommandConsole::AddVar( CHEATMENU_ENABLEGODMODE, &AVP_Settings::s_bGodMode, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddVar( CHEATMENU_ENABLEINFINITEAMMO, &AVP_Settings::s_bInfiniteAmmo, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddVar( CHEATMENU_CAMERAMODE, &s_iCameraMode , 0, 4, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddVar( CHEATMENU_FREEZETIME, &s_bFreezeTime, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddCmd( CHEATMENU_COMPLETELEVEL, CompleteLevel, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddCmd( CHEATMENU_ISMULTIPLAYER, IsSinglePlayer, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddVar( CHEATMENU_ACID, &AVP_Settings::s_bAcidCheat, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );

		Asura_CommandConsole::AddVar( CHEATMENU_SEEVOLUMES, &AVP_DamagePFX::s_bDebugRender, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );


		Asura_CommandConsole::AddCmd( CHEATMENU_KILLMARINE	, AVP_ServerActor_Marine::AwardLoadsOfDamageToAllMarines, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddCmd( CHEATMENU_KILLALIEN	, AVP_ServerActor_Alien::AwardLoadsOfDamageToAllAliens, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddCmd( CHEATMENU_KILLPREDATOR, AVP_ServerActor_Predator::AwardLoadsOfDamageToAllPredators, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );

		Asura_CommandConsole::AddCmd( SAVESCREEN_EXIT, ExitSaveScreen, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddCmd( MISSIONCOMPLETE_LEVELSELECT, ReturnToLevelSelect, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );

		//Add console commands/vars
		Asura_CommandConsole::AddCmd( FRONTENDMENU_DEVLOBBY, StartDevLobby, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddCmd( FRONTENDMENU_GAMELOBBY, StartGameLobby, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );

		Asura_CommandConsole::AddCmd( FRONTENDMENU_TESTLEVELSELECT, StartSpecificLevel, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddCmd( FRONTEND_EXIT_APP, QuitApplication, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddCmd( FRONTEND_SELECTCHARTYPE, SelectCharType, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
		Asura_CommandConsole::AddCmd( FRONTEND_SELECTDIFFICULTY, SelectDifficulty, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );

		Asura_CommandConsole::AddVar( GENERALMENU_TRUECOND, &s_bGeneralTrueReference, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );

		AVP_Multiplayer_ScoreBoard::InitialiseScoreBoardHudCommands();
		AVP_GUIMenu_PlayerObjectives::SetupConsoleCommands();
		AVP_FMV::InitialiseFMVConsoleCommands();
		AVP_GUIMenu_AudioDiaries::SetupConsoleCommands();
#if defined(AVP_USE_GAME_FRONTEND)
		AVP_GameFrontEnd::SetupConsoleCommands();
#endif

#if defined AVP_ALLOW_DEBUG_MOVEMENT
		s_iCameraMode		= AVP_Actor_InputHandler::GetMovementType();
#endif

		s_bOpenDebugVariableMenu = false;
		s_bQuitApplication = false;
		s_bQuit = false;
		s_bRequestRestart = false;
		s_bRequestRestartFromCheckpoint = false;
		s_bExitSaveScreen = false;
		s_bIsInitialised = true;

		float fWidth = Asura_Viewport::GetWidth() * Asura_Camera::GetViewingArea()->m_fWidth;
		float fHeight = Asura_Viewport::GetHeight() * Asura_Camera::GetViewingArea()->m_fHeight;
		Asura_GUIMenu_System::SetAutoMenuSizes( fWidth, fHeight );

		const float fXOffset = Asura_Viewport::GetWidth() * Asura_Camera::GetViewingArea()->m_fXOffset;
		const float fYOffset = Asura_Viewport::GetHeight() * Asura_Camera::GetViewingArea()->m_fYOffset;
		Asura_GUIMenu_System::SetAutoMenuOffsets( fXOffset, fYOffset );

		Asura_GUIMenu_System::RegisterExternalMessageCallback( GUIMenuExternalMessageCallback );

#ifdef ASURA_USE_CURSOR
		//Initialise mouse settings
		Asura_Cursor_RenderInfo xInfo;
		xInfo.m_fCursorWidth = 16.0f;
		xInfo.m_fCursorHeight = 16.0f;
		// Default to full extent of texture.
		xInfo.m_fTileU1 = xInfo.m_fTileV1 = 0.0f;
		xInfo.m_fTileU2 = xInfo.m_fTileV2 = 1.0f;

		xInfo.m_iTextureID = Asura_Texture_Management::GetTextureIndex("\\Pointer.tga");
		xInfo.m_fHotSpotX = 0.0f;
		xInfo.m_fHotSpotY = 0.0f;
		Asura_Cursor::AddCursorType(Asura_GetHashID("Pointer"), xInfo);
		Asura_Cursor::SetCursorIndex( 0 );
		Asura_Cursor::SetTypeByHash(Asura_GetHashID("Pointer"));
#endif //ASURA_USE_CURSOR

		Platform_Initialise();
	}
}

void AVP_GUIMenu_System::Shutdown( void )
{
	if( s_bIsInitialised )
	{
		Deactivate();
		ClearStoredHUDWidgets();

		Platform_Shutdown();

		s_bIsInitialised = false;
	}

	AVP_GUIMenu_AudioDiaries::Shutdown();
}

bool AVP_GUIMenu_System::ResumeGame( bool bHelp )
{
	if( bHelp )
	{
        Asura_CommandConsole::Printf( L"Returns to game action" );
	}
	else
	{
		// Called when the resume button was pressed, as this is not called on backing out of the page, the contents have been moved else where...
	}

	return true;
}

bool AVP_GUIMenu_System::CompleteLevel( bool bHelp )
{
	bool bRetVal = true;

	if( bHelp )
	{
		Asura_CommandConsole::Printf( L"Cheat: Completes the level" );
	}
	else
	{
		//Send message here
		Asura_Message*	pxMessage	= Asura_Network::CreateMessage(AVP_MSGID_END_OF_LEVEL, sizeof(Asura_Message));

		pxMessage->To = ASURA_GUID_SERVER;
		
		Asura_Network::Send(pxMessage);
	}

	return bRetVal;
}

bool AVP_GUIMenu_System::IsSinglePlayer( bool bHelp )
{
	if( bHelp )
	{
		Asura_CommandConsole::Printf( L"Is this a Single Player game? Returns 1 is so or 0 if not." );
		return true;
	}
	else
	{
		if( AVP_Settings::IsSinglePlayer() )
		{
			Asura_CommandConsole::Printf( L"1" );
		}
		else
		{
			Asura_CommandConsole::Printf( L"0" );
		}
		return true;
	}
}

void AVP_GUIMenu_System::SetSettingsOnClosure( void )
{

	AVP_Settings::GetCurrentProfile()->Save();
	
	#if defined AVP_ALLOW_DEBUG_MOVEMENT
		AVP_Actor_InputHandler::SetMovementType(s_iCameraMode);
	#endif

	//AVP_Settings::SetPlayerIgnoresTime( s_bFreezeTime );

	//AVP_Settings::SetFrozenTime(s_bFrozenTime);

	//Allow character to receive input again
	if(!s_bFreezeTime)
	{
		Asura_Timers::SetGameTimeScale(1.0f);
		Asura_Dynamic_Music_System::Unpause();
		//Asura_Sound_System::UnpauseAllSystems();
		// AUDIOTODO: The audio system should unpause here
	}
	else
	{
		Asura_Timers::SetGameTimeScale(0.0f);
		Asura_Dynamic_Music_System::Pause();
	}

	// No matter what was closed enable the HUD system, 
	// if it was a pause menu it needs to be back on, 
	// if it was the HUD have it ready to be renered when it is next loaded. 
#ifdef ASURA_SUPPORT_COMMAND_CONSOLE
	Asura_Render::SetSystemEnabled( ASURA_RENDER_SYSTEM_HUD, g_bHudWasEnabled );
#else
	Asura_Render::SetSystemEnabled( ASURA_RENDER_SYSTEM_HUD, true );
#endif // #ifdef ASURA_SUPPORT_COMMAND_CONSOLE
}

bool AVP_GUIMenu_System::ShowDebugVariablesMenu( bool bHelp )
{
	bool bRetVal = true;

	if( bHelp )
	{
		Asura_CommandConsole::Printf( L"Displays the debug variable menu" );
	}
	else
	{
		s_bOpenDebugVariableMenu = !(s_bOpenDebugVariableMenu);
	}

	return bRetVal;
}

Asura_Hash_ID AVP_GUIMenu_System::GetMenuHash( GUIMENU_ID eID, AVP_Settings::Species eRequiredSpecies /*=AVP_Settings::AVP_SPECIES_UNKNOWN*/ )
{
	if ( eID < GUIMENU_ID_MAX )
	{
		MENU_SPECIES eMenuSpecies;
		AVP_Settings::Species eSpecies = eRequiredSpecies;
		if (eSpecies == AVP_Settings::AVP_SPECIES_UNKNOWN)
		{
			eSpecies = AVP_Settings::GetPlayerSpecies(); 
		}
		switch(eSpecies)
		{
			case AVP_Settings::AVP_SPECIES_PREDATOR:
				eMenuSpecies = MENU_SPECIES_PREDATOR;
				break;

			case AVP_Settings::AVP_SPECIES_ALIEN:
				eMenuSpecies	= MENU_SPECIES_ALIEN;
				break;

			case AVP_Settings::AVP_SPECIES_HUMAN:
				eMenuSpecies	= MENU_SPECIES_MARINE;
				break;
			
			case AVP_Settings::AVP_SPECIES_UNKNOWN:
			default:
				return ASURA_HASH_ID_UNSET;

		}

		return s_auHashed_GUIMenuNames[eMenuSpecies][eID];
	}
	else
	{
		return ASURA_HASH_ID_UNSET;
	}
}

bool AVP_GUIMenu_System::Restart( bool bHelp )
{
	bool bRetVal = true;

	if( bHelp )
	{
		Asura_CommandConsole::Printf( L"Restarts the current level" );
	}
	else
	{
		s_bRequestRestart = !(s_bRequestRestart);
#if defined(AVP_ALLOW_DEBUG_MOVEMENT)
		// Loading from levelstartblock will reset the camera, so we need to reset the menu too... :/
		s_iCameraMode = AVP_Actor_InputHandler::MT_PLAYER_FIRST_PERSON;
#endif
	}

	return bRetVal;
}

bool AVP_GUIMenu_System::RestartFromCheckPoint( bool bHelp )
{
	bool bRetVal = true;

	if( bHelp )
	{
		Asura_CommandConsole::Printf( L"Restarts from the previous checkpoint" );
	}
	else
	{
		s_bRequestRestartFromCheckpoint = !(s_bRequestRestartFromCheckpoint);
	}

	return bRetVal;
}

bool AVP_GUIMenu_System::Quit( bool bHelp )
{
	bool bRetVal = true;

	if( bHelp )
	{
		Asura_CommandConsole::Printf( L"Quits to Tools" );
	}
	else
	{
		s_bQuit = !(s_bQuit);
	}

	return bRetVal;
}

bool AVP_GUIMenu_System::QuitApplication( bool bHelp )
{
	bool bRetVal = true;

	if( bHelp )
	{
		Asura_CommandConsole::Printf( L"Quits to Desktop" );
	}
	else
	{
		s_bQuitApplication = !(s_bQuitApplication);
	}

	return bRetVal;
}

bool AVP_GUIMenu_System::ExitSaveScreen( int uIn, bool bInterrogate, bool bHelp )
{
	bool bRetVal = true;

	if( bHelp || bInterrogate )
	{
		Asura_CommandConsole::Printf( L"Exits the save screen - to the mission complete menu" );
		bRetVal = false; //Is this right!?
	}
	else
	{
		if( uIn )
		{
			//Save game progress
		}

		s_bExitSaveScreen = !(s_bExitSaveScreen);
	}

	return bRetVal;
}

bool AVP_GUIMenu_System::ReturnToLevelSelect( bool bHelp )
{
	bool bRetVal = true;

	if( bHelp )
	{
		Asura_CommandConsole::Printf( L"Takes the player back to the level select screen to choose their next level" );
	}
	else
	{
		AVP_Core::RequestLevelComplete();
		s_bChooseNextLevel = !(s_bChooseNextLevel );
	}

	return bRetVal;
}

void AVP_GUIMenu_System::GUIMenuExternalMessageCallback( const Asura_Message_GUIMenu_Notify* pxData )
{
	//Does nothing at the moment
	//Provided to stop assert on menu initialisation
}

void AVP_GUIMenu_System::Fade( FADING_WIDGET eWidgetToFade, bool bFadeIn )
{
	Asura_Hash_ID uPageHash = GetWidgetOwningPage( eWidgetToFade );
	
	if( uPageHash != ASURA_HASH_ID_UNSET )
	{
		Asura_GUIMenu_Menu_Page* pxPage = Asura_GUIMenu_System::GetMenuPageByID( uPageHash );

		if( pxPage )
		{
			const char* szFadingWidgetName = s_axFadingWidgets[eWidgetToFade].xLocalName.GetString();
			Asura_Hash_ID uFadingWidgetNameHash = Asura_GetHashID( szFadingWidgetName );
			
			Asura_GUIMenu_Root* pxRootItem = pxPage->FindContainerItemByLocalNameHash( uFadingWidgetNameHash );
			
			if( pxRootItem )
			{
				u_int uColour = pxRootItem->GetColour().ToUIntRGBA();
				
				int iAlpha = static_cast<int>( uColour  & 0x000000FF );
				
				if( bFadeIn ) 
				{	
					iAlpha += s_axFadingWidgets[eWidgetToFade].iFadeInRate;
					if( iAlpha >  s_axFadingWidgets[eWidgetToFade].iFadeInTarget )
					{
						iAlpha =  s_axFadingWidgets[eWidgetToFade].iFadeInTarget;
					}
				}
				else
				{
					iAlpha -= s_axFadingWidgets[eWidgetToFade].iFadeOutRate;
					if( iAlpha <  s_axFadingWidgets[eWidgetToFade].iFadeOutTarget )
					{
						iAlpha =  s_axFadingWidgets[eWidgetToFade].iFadeOutTarget;
					}
				}

				uColour &= 0xFFFFFF00;
				uColour |= static_cast<u_int>(iAlpha);
				
				Asura_RGBA rgba;
				pxRootItem->SetColour( rgba.FromUIntRGBA( uColour ) );
			}			
		}
	}
}


Asura_Hash_ID AVP_GUIMenu_System::GetWidgetOwningPage( FADING_WIDGET eWidgetToFade )
{
	Asura_Hash_ID uRetVal = ASURA_HASH_ID_UNSET;

	switch( eWidgetToFade )
	{

		case FADING_WIDGET_INTERACTION_PROMPT:
			uRetVal  = GetMenuHash( GUIMENU_ID_HUD );
			break;

		default:
			break;
	}
	
	return uRetVal;
}

bool AVP_GUIMenu_System::IsFadingWidgetFullyFadedIn( FADING_WIDGET eWidgetToFade )
{
	bool bRetVal = false;
	
	Asura_Hash_ID uPageHash = GetWidgetOwningPage( eWidgetToFade );
	
	if( uPageHash != ASURA_HASH_ID_UNSET )
	{
		Asura_GUIMenu_Menu_Page* pxPage = Asura_GUIMenu_System::GetMenuPageByID( uPageHash );

		if( pxPage )
		{
			const char* szFadingWidgetName = s_axFadingWidgets[eWidgetToFade].xLocalName.GetString();
			Asura_Hash_ID uFadingWidgetNameHash = Asura_GetHashID( szFadingWidgetName );
			
			Asura_GUIMenu_Root* pxRootItem = pxPage->FindContainerItemByLocalNameHash( uFadingWidgetNameHash );
			
			if( pxRootItem )
			{
				u_int uColour = pxRootItem->GetColour().ToUIntRGBA();
				
				int iAlpha = static_cast<int>( uColour  & 0x000000FF );
				
				if( iAlpha == s_axFadingWidgets[eWidgetToFade].iFadeInTarget )
				{
					bRetVal = true;
				}
			}
		}
	}
	
	return bRetVal;
}

bool AVP_GUIMenu_System::IsMenuActive( GUIMENU_ID eID )
{
	bool bRet = false;

	bRet = Asura_GUIMenu_System::IsMenuPageHashActive( GetMenuHash( eID ) );

	return bRet;
}


void AVP_GUIMenu_System::RenderHUDCounters(void)
{
	Asura_Hash_ID uHUDPageHash = GetMenuHash( GUIMENU_ID_HUD );
	if( Asura_GUIMenu_System::IsMenuPageHashActive( uHUDPageHash ) )
	{
		Asura_GUIMenu_Menu_Page* pxPage = Asura_GUIMenu_System::GetMenuPageByID( uHUDPageHash );
		if( pxPage )
		{
			AVP_Player* pxPlayer = AVP_Game_Core::GetPlayer();
			if( pxPlayer )
			{
				AVP_ClientActor_Vertebrate* pxPlayerActor = AVP_ClientActor_Vertebrate::FindEntity( pxPlayer->GetPuppetGuid() );
				if( pxPlayerActor )
				{
					Asura_UnicodeChar wszText[32] = L"";
					Asura_GUIMenu_Element_Text* pxTextItem = NULL;

					pxTextItem = static_cast<Asura_GUIMenu_Element_Text*>( pxPage->FindContainerItemByLocalNameHash( 0x7C4A1F66 ) ); //"TX_ammo_counter"
					if( pxTextItem )
					{
						Asura_PrintfToBfr( wszText, L"%02d", 32, true, AVP_Human_HUDHandler::GetStaticAmmo() );
						pxTextItem->SetText( wszText );
					}
					pxTextItem = static_cast<Asura_GUIMenu_Element_Text*>( pxPage->FindContainerItemByLocalNameHash( 0x01ECD10B ) ); //"TX_ammo_counter_max"
					if( pxTextItem )
					{
						Asura_PrintfToBfr( wszText, L"%02d", 32, true, AVP_Human_HUDHandler::GetStaticAmmoMax() );
						pxTextItem->SetText( wszText );
					}



					pxTextItem = static_cast<Asura_GUIMenu_Element_Text*>( pxPage->FindContainerItemByLocalNameHash( 0xD6ECB850 ) ); //"TX_grenade_counter"
					if( pxTextItem )
					{
						Asura_PrintfToBfr( wszText, L"%02d", 32, true, AVP_Human_HUDHandler::GetStaticGrenadeAmmo() );
						pxTextItem->SetText( wszText );
					}
					pxTextItem = static_cast<Asura_GUIMenu_Element_Text*>( pxPage->FindContainerItemByLocalNameHash( 0xA664E4F5 ) ); //"TX_grenade_counter_max"
					if( pxTextItem )
					{
						Asura_PrintfToBfr( wszText, L"%02d", 32, true, AVP_Human_HUDHandler::GetStaticGrenadeAmmoMax() );
						pxTextItem->SetText( wszText );
					}



					pxTextItem = static_cast<Asura_GUIMenu_Element_Text*>( pxPage->FindContainerItemByLocalNameHash( 0x94DBFFE8 ) ); //"TX_heartrate_counter"
					if( pxTextItem )
					{
						Asura_PrintfToBfr( wszText, L"%03d", 32, true, AVP_Human_HUDHandler::GetStaticHeartRate() );
						pxTextItem->SetText( wszText );
					}
					pxTextItem = static_cast<Asura_GUIMenu_Element_Text*>( pxPage->FindContainerItemByLocalNameHash( 0xB4A55B48 ) ); //"TX_armour_counter"
					if( pxTextItem )
					{
						Asura_PrintfToBfr( wszText, L"%03d", 32, true, AVP_Human_HUDHandler::GetStaticArmour() );
						pxTextItem->SetText( wszText );
					}


					pxTextItem = static_cast<Asura_GUIMenu_Element_Text*>( pxPage->FindContainerItemByLocalNameHash( 0x1F5A00DD ) ); //"TX_stim_counter"
					if( pxTextItem )
					{
						Asura_PrintfToBfr( wszText, L"%02d", 32, true, AVP_Human_HUDHandler::GetStaticStimAmmo() );
						pxTextItem->SetText( wszText );
					}
				}
			}
		}
	}
}

float AVP_GUIMenu_System::GetHUDFadeParamentric(void)
{
	Asura_Hash_ID uHUDPageHash = GetMenuHash( GUIMENU_ID_HUD );
	if( Asura_GUIMenu_System::IsMenuPageHashActive( uHUDPageHash ) )
	{
		Asura_GUIMenu_Menu_Page* pxPage = Asura_GUIMenu_System::GetMenuPageByID( uHUDPageHash );
		if( pxPage )
		{
			if(pxPage->IsFadingIn())
			{
				Asura_GUIMenu_Animator* pxAnim = pxPage->GetAnimatorBySequenceHash(0x4AAF2381); // Menu_FadeIn
				if(pxAnim)
				{
					return(pxAnim->GetFloatData());
				}
			}
			else if(pxPage->IsFadingOut())
			{
				Asura_GUIMenu_Animator* pxAnim = pxPage->GetAnimatorBySequenceHash(0x0B356472); // Menu_FadeOut
				if(pxAnim)
				{
					return(pxAnim->GetFloatData());
				}
			}
			else if(pxPage->GetState()==ASURA_GUIMENU_ACTION_FLAG_IS_MENU_ACTIVE)
			{
				return 1.0f;
			}
		}
	}
	return 0.0f;
}

////////////////////////////////////////////////
// AVP_GUIMenu_System::GetHUDElement
//
// Gets a widget from the guimenu, later calls 
// will used the stored value to save time
////////////////////////////////////////////////

Asura_GUIMenu_Root* AVP_GUIMenu_System::GetHUDElement(STORED_WIDGETS eWidget, Asura_Hash_ID uFromMenuPageHash /*=ASURA_HASH_ID_UNSET*/, bool bCheckMenuPageIsActive /*=true*/, bool bForceLookUp /*=false*/ )
{
	if( ( !s_abWidgetLookedUp[eWidget] ) || bForceLookUp )
	{
		// Force to look up in particular page
		Asura_Hash_ID uHUDPageHash = uFromMenuPageHash;
		if (!uHUDPageHash)
		{
			uHUDPageHash = AVP_GUIMenu_System::GetMenuHash( AVP_GUIMenu_System::GUIMENU_ID_HUD );
		}

		// Check if the page is active only if requested
		if( !bCheckMenuPageIsActive || Asura_GUIMenu_System::IsMenuPageHashActive( uHUDPageHash ) )
		{
			Asura_GUIMenu_Menu_Page* pxPage = Asura_GUIMenu_System::GetMenuPageByID( uHUDPageHash );
			if( pxPage )
			{
				Asura_GUIMenu_Root* pxItem = pxPage->FindContainerItemByLocalNameHash( s_auStoredHUDWidgetHashes[eWidget] );
				s_apxStoredHUDWidgets[eWidget] = pxItem;
				s_abWidgetLookedUp[eWidget] = true;
			}
		}
	}

	return(s_apxStoredHUDWidgets[eWidget]);
}

void AVP_GUIMenu_System::ClearStoredHUDWidgets(void)
{
	for(int i=0;i<NUM_STORED_WIDGETS;i++)
	{
		s_abWidgetLookedUp[i] = false;
		s_apxStoredHUDWidgets[i] = NULL;
	}
}

////////////////////////////////////////////////////////////////////////////////
//  CLASS    :  AVP_GUIMenu_System
//  NAME     :  SelectCharType()
//  CREATED  :  ????  moved to AVP_GUIMenu_System from AVP_GameFrontEnd by CAH ( 2.9.2008 )
//  DESC     :  Function is here to be the code interface to the menu system, 
//				allows the character species stored in AVP_Settings to be changed via button presses. 
////////////////////////////////////////////////////////////////////////////////

bool AVP_GUIMenu_System::SelectCharType( u_int uCharacter, bool bInterrogate, bool bHelp )
{
	if( bHelp || bInterrogate )
	{
		Asura_CommandConsole::Printf( L"Selects character type: alien, marine, predator" );
		return(false);
	}
	else
	{
		// Decide what level to use (along with the species)...
		if( uCharacter < AVP_Settings::AVP_NUM_SPECIES  )
		{
			AVP_Settings::SetPlayerSpecies( static_cast<AVP_Settings::Species>( uCharacter ) );
			return(true);
		}
		else
		{
			Asura_Assertf( false, ( "Unexpected character index found - %d (max %d)", uCharacter, ( AVP_Settings::AVP_NUM_SPECIES - 1) ) );
			return(false);
		}
	}
}

////////////////////////////////////////////////////////////////////////////////
//  CLASS    :  AVP_GUIMenu_System
//  NAME     :  SelectDifficulty()
//  CREATED  :  CAH ( 2.9.2008 )
//  DESC     :  Function is here to be the code interface to the menu system, 
//				allows the difficulty stored in AVP_Settings to be changed via button presses. 
////////////////////////////////////////////////////////////////////////////////

bool AVP_GUIMenu_System::SelectDifficulty( u_int uDifficulty, bool bInterrogate, bool bHelp )
{
	if( bHelp || bInterrogate )
	{
		Asura_CommandConsole::Printf( L"Selects Difficulty Type: Easy = 0, Med = 1, Hard = 2" );
		return(false);
	}
	else
	{
		// Decide what level to use (along with the species)...
		if( uDifficulty < AVP_Settings::AVP_NUM_SPECIES  )
		{
			AVP_Settings::SetPlayerDifficulty( static_cast<AVP_Settings::Difficulty>( uDifficulty ) );
			return(true);
		}
		else
		{
			Asura_Assertf( false, ( "Unexpected Difficulty index found - %d (max %d)", uDifficulty, ( AVP_Settings::AVP_NUM_DIFFICULTIES - 1) ) );
			return(false);
		}
	}
}

////////////////////////////////////////////////////////////////////////////////

bool AVP_GUIMenu_System::StartSpecificLevel(u_int uLevel, bool bInterrogate, bool bHelp )
{
	if( bHelp || bInterrogate)
	{
		Asura_CommandConsole::Printf( L"Starts a specific level with specific character." );
		return(true);
	}
	else
	{
#if defined(AVP_USE_GAME_FRONTEND)
		// Decide what level to use (along with the species)...
		if(uLevel < g_uNumLevels)
		{
			const LevelData&			xLevelData	= g_axLevelData[uLevel];
			char const* const			szLevelName	= xLevelData.m_szFilename;
			const AVP_Settings::Species	eSpecies	= xLevelData.m_eSpecies;

			AVP_Settings::SetLevelName(szLevelName);

			if(eSpecies != AVP_Settings::AVP_NUM_SPECIES)
			{
				AVP_Settings::SetPlayerSpecies(eSpecies);
			}

			if(xLevelData.m_bStartGame)
			{
				AVP_Game_Core::SetRespawnSpecies(AVP_Settings::GetPlayerSpecies());
				AVP_GameFrontEnd::RequestStartGame();
			}

#if defined(AVP_SUBMISSION)
			// ARTTODO: This offends me greatly - remove ASAP...
			if(strcmp(szLevelName, AVP_GENERATE_FULL_LEVEL_FILENAME("Demo_SPS")) == 0)
			{
				AVP_Settings::SetGodMode(true);
			}
#endif	// defined(AVP_SUBMISSION)

			// Reset network settings before starting playing a campaign map
			AVP_Settings::SetIsServer(true);
			AVP_Settings::SetExternalNetworkActive(false);
			AVP_Settings::SetOnlineGame(false);

			return(true);
		}
		else
		{
			Asura_Assertf(false, ("Unexpected level index found - %d (max %d)", uLevel, g_uNumLevels));
			return(false);
		}
#else
		return(true);
#endif	//defined(AVP_USE_GAME_FRONTEND)
	}
}

bool AVP_GUIMenu_System::StartDevLobby( bool bHelp )
{
	if( bHelp )
	{
		Asura_CommandConsole::Printf( L"Starts the development lobby." );
		return(true);
	}
	else
	{
#if defined(AVP_USE_DEV_LOBBY)
		AVP_GUIMenu_System::SetLobbyType(AVP_GUIMenu_System::LT_DEVELOPMENT);
		AVP_GameFrontEnd::RequestDevLobby();
#endif	//defined(AVP_USE_DEV_LOBBY)
		return(true);
	}
}

bool AVP_GUIMenu_System::StartGameLobby( bool bHelp )
{
	if( bHelp )
	{
		Asura_CommandConsole::Printf( L"Starts the game lobby." );
		return(true);
	}
	else
	{
#if defined(AVP_USE_GAME_LOBBY)
		AVP_GUIMenu_System::SetLobbyType(AVP_GUIMenu_System::LT_GAME);
		AVP_GameFrontEnd::RequestGameLobby();
#endif	//defined(AVP_USE_GAME_LOBBY)
		return(true);
	}
}

#endif //#if defined(ASURA_USE_GUI_MENU_SYSTEM)]
