public void MouseUp(int x, int y, int whichButton)
{
if (whichButton == 1)
{
var currentEmpire = _gameMain.EmpireManager.CurrentEmpire;
if (_taskBar.MouseUp(x, y, whichButton))
{
//clear the fleet/planet window
currentEmpire.SelectedSystem = null;
currentEmpire.SelectedFleetGroup = null;
return;
}
if (_windowShowing != null)
{
_windowShowing.MouseUp(x, y);
return;
}
if (currentEmpire.SelectedSystem != null)
{
if (_systemView.MouseUp(x, y))
{
return;
}
if (_systemView.IsTransferring)
{
Point point = new Point();
point.X = (int)((x / _camera.ZoomDistance) + _camera.CameraX);
point.Y = (int)((y / _camera.ZoomDistance) + _camera.CameraY);
StarSystem system = _gameMain.Galaxy.GetStarAtPoint(point);
if (system != null)
{
var path = _gameMain.Galaxy.GetPath(currentEmpire.SelectedSystem.X, currentEmpire.SelectedSystem.Y, null, system, false, currentEmpire);
if (path.Count > 0)
{
if (!path[0].StarSystem.IsThisSystemExploredByEmpire(currentEmpire) || path[0].StarSystem.Planets[0].Owner == null)
{
path[0].IsValid = false;
}
_systemView.TransferSystem = path[0];
}
}
else
{
//Clicked to clear the option
_systemView.IsTransferring = false;
_systemView.TransferSystem = null;
}
return;
}
if (_systemView.IsRelocating)
{
Point point = new Point();
point.X = (int)((x / _camera.ZoomDistance) + _camera.CameraX);
point.Y = (int)((y / _camera.ZoomDistance) + _camera.CameraY);
StarSystem system = _gameMain.Galaxy.GetStarAtPoint(point);
if (system != null)
{
var path = _gameMain.Galaxy.GetPath(currentEmpire.SelectedSystem.X, currentEmpire.SelectedSystem.Y, null, system, false, currentEmpire);
if (path.Count > 0)
{
if (path[0].StarSystem.Planets[0].Owner != currentEmpire)
{
path[0].IsValid = false;
}
_systemView.RelocateSystem = path[0];
}
}
else
{
//Clicked to clear the option
_systemView.IsRelocating = false;
_systemView.RelocateSystem = null;
}
return;
}
}
if (_gameMain.EmpireManager.CurrentEmpire.SelectedFleetGroup != null)
{
if (_fleetView.MouseUp(x, y))
{
RefreshETAText();
return;
}
}
//If a window is open, but the player didn't click on another system or fleet, the action is to close the current window
bool clearingUI = _gameMain.EmpireManager.CurrentEmpire.SelectedSystem != null || _gameMain.EmpireManager.CurrentEmpire.SelectedFleetGroup != null;
Point pointClicked = new Point();
pointClicked.X = (int)((x / _camera.ZoomDistance) + _camera.CameraX);
pointClicked.Y = (int)((y / _camera.ZoomDistance) + _camera.CameraY);
StarSystem selectedSystem = _gameMain.Galaxy.GetStarAtPoint(pointClicked);
if (selectedSystem != null && selectedSystem == _gameMain.EmpireManager.CurrentEmpire.SelectedSystem)
{
return;
}
_gameMain.EmpireManager.CurrentEmpire.SelectedSystem = selectedSystem;
if (selectedSystem != null)
{
_gameMain.EmpireManager.CurrentEmpire.LastSelectedSystem = selectedSystem;
_gameMain.EmpireManager.CurrentEmpire.SelectedFleetGroup = null;
_systemView.LoadSystem();
return;
}
FleetGroup selectedFleetGroup = _gameMain.EmpireManager.GetFleetsAtPoint(pointClicked.X, pointClicked.Y);
_gameMain.EmpireManager.CurrentEmpire.SelectedFleetGroup = selectedFleetGroup;
if (selectedFleetGroup != null)
{
_fleetView.LoadFleetGroup(selectedFleetGroup);
RefreshETAText();
return;
}
if (!clearingUI)
{
_camera.ScrollToPosition(pointClicked.X, pointClicked.Y);
}
}
else if (whichButton == 2)
{
if (_windowShowing != null)
{
return;
}
var selectedFleetGroup = _gameMain.EmpireManager.CurrentEmpire.SelectedFleetGroup;
if (selectedFleetGroup != null && selectedFleetGroup.FleetToSplit.Empire == _gameMain.EmpireManager.CurrentEmpire)
{
bool isIdling = selectedFleetGroup.SelectedFleet.AdjacentSystem != null;
bool hasDestination = selectedFleetGroup.SelectedFleet.TravelNodes != null;
if (selectedFleetGroup.FleetToSplit.ConfirmPath())
{
_gameMain.EmpireManager.CurrentEmpire.SelectedFleetGroup.SplitFleet(_gameMain.EmpireManager.CurrentEmpire);
_gameMain.EmpireManager.CurrentEmpire.FleetManager.MergeIdleFleets();
if (isIdling && !hasDestination) //Select the remaining idling ships on right of star
{
Point point = new Point((int)selectedFleetGroup.SelectedFleet.GalaxyX + 32, (int)selectedFleetGroup.SelectedFleet.GalaxyY);
selectedFleetGroup = _gameMain.EmpireManager.GetFleetsAtPoint(point.X, point.Y);
if (selectedFleetGroup == null) // No ships left, select the fleet on left of star
{
selectedFleetGroup = _gameMain.EmpireManager.GetFleetsAtPoint(point.X - 64, point.Y);
}
}
else if (isIdling)
{
if (selectedFleetGroup.SelectedFleet.TravelNodes == null) //cleared out movement order
{
selectedFleetGroup = _gameMain.EmpireManager.GetFleetsAtPoint((int)selectedFleetGroup.SelectedFleet.GalaxyX + 32, (int)selectedFleetGroup.SelectedFleet.GalaxyY);
}
else
{
selectedFleetGroup = _gameMain.EmpireManager.GetFleetsAtPoint((int)selectedFleetGroup.SelectedFleet.GalaxyX - 32, (int)selectedFleetGroup.SelectedFleet.GalaxyY);
}
}
else
{
selectedFleetGroup = _gameMain.EmpireManager.GetFleetsAtPoint((int)selectedFleetGroup.SelectedFleet.GalaxyX, (int)selectedFleetGroup.SelectedFleet.GalaxyY);
}
_gameMain.EmpireManager.CurrentEmpire.SelectedFleetGroup = selectedFleetGroup;
_fleetView.LoadFleetGroup(selectedFleetGroup);
}
}
}
}