public static void HandleInput(InputState input, ContentManager content) { _screenMouse = new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y); _gridTexture = content.Load<Texture2D>(@"Maps\Grid"); HUD.HandleInput(input, Selection.SelectedSprite); if (Selection.IsNull) { foreach (var sprite in Sprites) { if (sprite.Intersects(Mouse) && input.IsNewLeftMouseClick() && !Selection.IsUnit) { Selection.Set(sprite); break; } } } else { if (Selection.HasControls) { Control control = Selection.SelectedSprite.Controls.Selection; _HandleResourceMechanism(input); if (control == null) { if (input.CurrentMouseState.Y < (Camera.ViewSize.Y)) { if (input.IsNewLeftMouseClick()) { Selection.UnSet(); } else if (Selection.IsUnit) { var unit = Selection.SelectedSprite as Unit; unit.HandleWayPoint(input, Mouse); } } else { Selection.SelectedSprite.Controls.HandleInput(input); } } else { // some control is selected if (Selection.IsUnit) { _HandleUnitControlSelection(input, control, content); } else if (Selection.SelectedSprite is HeadQuarter) { if (control.Name.Contains("Deploy")) { _HandleDeployCommandAtHeadQuarter(control, content); } else { var hq = Selection.SelectedSprite as HeadQuarter; hq.HandleBuildCommand(control, ResourcesManager); } } else if (Selection.SelectedSprite is Village) { var village = Selection.SelectedSprite as Village; if (control.Name == "BuildFarm") { village.HandleBuildFarm(control, ResourcesManager); } } } } else { // sprite with no control if (input.CurrentMouseState.Y < (Camera.ViewSize.Y)) { if (input.IsNewLeftMouseClick()) { Selection.UnSet(); } } } } }
private static void _HandleUnitControlSelection(InputState input, Control control, ContentManager content) { if (Selection.IsUnit) { var unit = Selection.SelectedSprite as Unit; if (control.Name == "Move"){ if (input.CurrentMouseState.Y < (Camera.ViewSize.Y) && input.IsNewLeftMouseClick()) { unit.Destination = new Vector2(Mouse.X - unit.Bounds.Width/2, Mouse.Y - unit.Bounds.Height/2); control.IsSelected = false; } } else if (control.Name == "BuildSolarPanel") { if (!_isBuildingSolarPanel) { unit = Selection.SelectedSprite as Truck; unit.IsBuilding = true; _isBuildingSolarPanel = true; _solarPanelTexture = content.Load<Texture2D>(@"Textures\Buildings\SolarPlant"); } if (_isBuildingSolarPanel && input.IsNewLeftMouseClick()) { var solarPanel = new StaticBuilding(Mouse, @"Textures\Buildings\SolarPlant", 30); solarPanel.LoadContent(content); Sprites.Add(solarPanel); ResourcesManager.Money -= Settings.SolarPanelCost; ResourcesManager.MaxEnergy += Settings.SolarPanelEnergy; control.IsSelected = false; _isBuildingSolarPanel = false; } if (input.CurrentMouseState.Y < (Camera.ViewSize.Y) && input.IsNewRightMouseClick()) { _isBuildingSolarPanel = false; unit.IsBuilding = false; control.IsSelected = false; } } else if (control.Name == "BuildWindTurbine") { unit = Selection.SelectedSprite as Truck; unit.IsBuilding = true; _isBuildingWindTurbine = true; _windTurbineTexture = content.Load<Texture2D>(@"Textures\Buildings\WindTurbineSingleSprite"); if ((Vector2.Distance(Mouse, unit.Position) <= unit.Range) && input.IsNewLeftMouseClick()) { var windTurbine = new AnimatedBuilding(Mouse, @"Textures\Buildings\WindTurbine", 30); windTurbine.LoadContent(content); Sprites.Add(windTurbine); ResourcesManager.Money -= Settings.WindTurbineCost; ResourcesManager.MaxEnergy += Settings.WindTurbineEnergy; control.IsSelected = false; _isBuildingWindTurbine = false; } if (input.CurrentMouseState.Y < (Camera.ViewSize.Y) && input.IsNewRightMouseClick()) { unit.IsBuilding = false; _isBuildingWindTurbine = false; control.IsSelected = false; } } else if (!control.Name.ToLower().Contains("load")) { unit.HandleEnergyUpgrade(ResourcesManager.Money); control.IsSelected = false; } } }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> public override void HandleInput(InputState input) { // Move to the previous menu entry? if (input.IsMenuUp(ControllingPlayer)) { selectedEntry--; if (selectedEntry < 0) selectedEntry = menuEntries.Count - 1; EvaFrontier.buttonOver.Play(); } // Move to the next menu entry? if (input.IsMenuDown(ControllingPlayer)) { selectedEntry++; if (selectedEntry >= menuEntries.Count) selectedEntry = 0; EvaFrontier.buttonOver.Play(); } // Accept or cancel the menu? We pass in our ControllingPlayer, which may // either be null (to accept input from any player) or a specific index. // If we pass a null controlling player, the InputState helper returns to // us which player actually provided the input. We pass that through to // OnSelectEntry and OnCancel, so they can tell which player triggered them. PlayerIndex playerIndex; if (input.IsMenuSelect(ControllingPlayer, out playerIndex) || input.IsNewLeftMouseClick()) { OnSelectEntry(selectedEntry, playerIndex); } else if (input.IsMenuCancel(ControllingPlayer, out playerIndex)) { OnCancel(playerIndex); } }