Move selection hotkeys out of world interaction widget

- Split SelectionUtils for selecting actors in the world to a static class
- Split selection hotkeys into their own logic classes
This commit is contained in:
Ivaylo Draganov
2021-09-19 21:44:05 +03:00
committed by Matthias Mailänder
parent e9cc89a336
commit a537346580
6 changed files with 248 additions and 141 deletions

View File

@@ -0,0 +1,66 @@
#region Copyright & License Information
/*
* Copyright 2007-2021 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Lint;
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
{
[ChromeLogicArgsHotkeys("SelectAllUnitsKey")]
public class SelectAllUnitsHotkeyLogic : SingleHotkeyBaseLogic
{
readonly World world;
readonly WorldRenderer worldRenderer;
readonly ISelection selection;
public readonly string ClickSound = ChromeMetrics.Get<string>("ClickSound");
[ObjectCreator.UseCtor]
public SelectAllUnitsHotkeyLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, World world, Dictionary<string, MiniYaml> logicArgs)
: base(widget, modData, "SelectAllUnitsKey", "WORLD_KEYHANDLER", logicArgs)
{
this.world = world;
this.worldRenderer = worldRenderer;
selection = world.Selection;
}
protected override bool OnHotkeyActivated(KeyInput e)
{
if (world.IsGameOver)
return false;
var eligiblePlayers = SelectionUtils.GetPlayersToIncludeInSelection(world);
// Select actors on the screen which belong to the current player(s)
var ownUnitsOnScreen = SelectionUtils.SelectActorsOnScreen(world, worldRenderer, null, eligiblePlayers).SubsetWithHighestSelectionPriority(e.Modifiers).ToList();
// Check if selecting actors on the screen has selected new units
if (ownUnitsOnScreen.Count > selection.Actors.Count())
TextNotificationsManager.AddFeedbackLine("Selected across screen.");
else
{
// Select actors in the world that have highest selection priority
ownUnitsOnScreen = SelectionUtils.SelectActorsInWorld(world, null, eligiblePlayers).SubsetWithHighestSelectionPriority(e.Modifiers).ToList();
TextNotificationsManager.AddFeedbackLine("Selected across map.");
}
selection.Combine(world, ownUnitsOnScreen, false, false);
Game.Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Sounds", ClickSound, null);
return true;
}
}
}