public void Update(InputState input) { if (input.WentActive(Keys.F1)) { _dialogMgr.Add(new Prompt(Console.WriteLine)); } AABB selectionBox = new AABB(_selectionBoxP1, _selectionBoxP2); int id; if (_provinces.TryGetProvinceFromPoint(input.Mouse, out id)) { if (input.WentActive(Buttons.LeftButton) && _labelClickableBoundaries.ContainsKey(id) && _labelClickableBoundaries[id].IsPointInside(input.ScreenMouse) && _units.IsPlayerArmy(id)) { _unitsSelection.Select(id, input.IsActive(Keys.LeftControl)); } // Only handle new selections. else if (input.WentActive(Buttons.LeftButton)) { _provinceSelection.Select(id); } else if (input.WentInactive(Buttons.LeftButton) && selectionBox.Area < _minimumSelectionSize && _unitsSelection.Count > 0) { _units.AddOrder(_unitsSelection.Set, id); } SwapInstrs(_provinceSelection.Hovering); _provinceSelection.Hover(id); SwapInstrs(id); } else { SwapInstrs(_provinceSelection.Hovering); _provinceSelection.StopHovering(); } if (input.WentActive(Keys.G)) MergeSelectedArmies(); if (input.WentActive(Keys.Escape)) _unitsSelection.DeselectAll(); if (input.WentActive(Keys.Delete)) DeleteSelectedArmies(); if (input.WentInactive(Buttons.LeftButton) && selectionBox.Area > _minimumSelectionSize) { _unitsSelection.DeselectAll(); // Find all units within the area and select them. _labelClickableBoundaries .FindAll(p => _units.IsPlayerArmy(p.Key) && p.Value.Intersects(selectionBox)) .ForEach(p => _unitsSelection.Select(p.Key, true)); } UpdateSelectionBox(input); if (_unitsSelection.Count > 0) { Debug.WriteToScreen("Armies", _unitsSelection.Set.Join(", ")); } }
public void UpdateSelectionBox(InputState input) { if (input.WentInactive(Buttons.LeftButton)) { _selectionBoxP1 = Vector2.Zero; _selectionBoxP2 = Vector2.Zero; } else if (input.WentActive(Buttons.LeftButton)) { _selectionBoxP1 = input.ScreenMouse; _selectionBoxP2 = input.ScreenMouse; } else if (input.IsActive(Buttons.LeftButton)) { _selectionBoxP2 = input.ScreenMouse; } }