#region Copyright & License Information /* * Copyright 2007-2011 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. For more information, * see COPYING. */ #endregion using OpenRA.Mods.RA.Orders; using OpenRA.Widgets; namespace OpenRA.Mods.RA.Widgets.Logic { public class OrderButtonsChromeLogic { [ObjectCreator.UseCtor] public OrderButtonsChromeLogic(Widget widget, World world) { var sell = widget.GetOrNull("SELL_BUTTON"); if (sell != null) { sell.GetKey = _ => Game.Settings.Keys.SellKey; BindOrderButton(world, sell, "sell"); } var repair = widget.GetOrNull("REPAIR_BUTTON"); if (repair != null) { repair.GetKey = _ => Game.Settings.Keys.RepairKey; BindOrderButton(world, repair, "repair"); } var beacon = widget.GetOrNull("BEACON_BUTTON"); if (beacon != null) { beacon.GetKey = _ => Game.Settings.Keys.PlaceBeaconKey; BindOrderButton(world, beacon, "beacon"); } var power = widget.GetOrNull("POWER_BUTTON"); if (power != null) { power.GetKey = _ => Game.Settings.Keys.PowerDownKey; BindOrderButton(world, power, "power"); } } static void BindOrderButton(World world, ButtonWidget w, string icon) where T : IOrderGenerator, new() { w.OnClick = () => world.ToggleInputMode(); w.IsHighlighted = () => world.OrderGenerator is T; w.Get("ICON").GetImageName = () => world.OrderGenerator is T ? icon + "-active" : icon; } } }