//-------------------------------------------------
// RegionGui.cs
//-------------------------------------------------

new ActionMap(RegMap);
    RegMap.bindCmd(keyboard, "ctrl r", "closeRegionGui();", "");
    RegMap.bindCmd(keyboard, "escape", "closeRegionGui();", "");

function closeRegionGui()
{
	Canvas.setContent(PlayGui);

	RegMap.pop();
}

function showRegionGui()
{
	RegMap.push();
	Canvas.setContent( RegionGui );
}


// DAN event handling for clicking each region.
function EvtLRegion1::onMouseDown(%this, %obj)
{
	//echo("Region1 clicked!");
	
	
	if($RegionSelected == 1)		//unselects the region if clicked on it more than once
	{
		//echo ("Region1 unselected");
		Canvas.setContent(PlayGui);
		RegMap.pop();
		$RegionSelected = 0;
	}
	else if($localRegionList.count >= 1)	//Checks if there a region at that slot. If there is, then the click goes through
	{
		Canvas.setContent(PlayGui);
		RegMap.pop();
		$RegionSelected = 1;
	}
	
	
}

function EvtLRegion2::onMouseDown(%this, %obj)
{
//	echo("Region2 clicked!");

	if($RegionSelected == 2)		//unselects the region if clicked on it more than once
	{
		//echo ("Region1 unselected");
		Canvas.setContent(PlayGui);
		RegMap.pop();
		$RegionSelected = 0;
	}
	else if($localRegionList.count >= 2)
	{
		Canvas.setContent(PlayGui);
		RegMap.pop();
		$RegionSelected = 2;
	}
}

function EvtLRegion3::onMouseDown(%this, %obj)
{
//	echo("Region3 clicked!");

	if($RegionSelected == 3)		//unselects the region if clicked on it more than once
	{
		//echo ("Region1 unselected");
		Canvas.setContent(PlayGui);
		RegMap.pop();
		$RegionSelected = 0;
	}
	else if($localRegionList.count >= 3)
	{
		Canvas.setContent(PlayGui);
		RegMap.pop();
		$RegionSelected = 3;
	}
}

function EvtLRegion4::onMouseDown(%this, %obj)
{
//	echo("Region4 clicked!");

	if($RegionSelected == 4)		//unselects the region if clicked on it more than once
	{
		//echo ("Region1 unselected");
		Canvas.setContent(PlayGui);
		RegMap.pop();
		$RegionSelected = 0;
	}
	else if($localRegionList.count >= 4)
	{
		Canvas.setContent(PlayGui);
		RegMap.pop();
		$RegionSelected = 4;
	}
}

function EvtLRegion5::onMouseDown(%this, %obj)
{
//	echo("Region5 clicked!");

	if($RegionSelected == 5)		//unselects the region if clicked on it more than once
	{
		//echo ("Region1 unselected");
		Canvas.setContent(PlayGui);
		RegMap.pop();
		$RegionSelected = 0;
	}
	else if($localRegionList.count >= 5)
	{
		Canvas.setContent(PlayGui);
		RegMap.pop();
		$RegionSelected = 5;
	}
}