Unify all mods on the C&C order button logic.
This commit is contained in:
@@ -406,7 +406,6 @@
|
||||
<Compile Include="Widgets\MoneyBinWidget.cs" />
|
||||
<Compile Include="Widgets\ObserverProductionIconsWidget.cs" />
|
||||
<Compile Include="Widgets\ObserverSupportPowerIconsWidget.cs" />
|
||||
<Compile Include="Widgets\OrderButtonWidget.cs" />
|
||||
<Compile Include="Widgets\RadarWidget.cs" />
|
||||
<Compile Include="Widgets\StrategicProgressWidget.cs" />
|
||||
<Compile Include="Widgets\SupportPowerTimerWidget.cs" />
|
||||
@@ -488,6 +487,7 @@
|
||||
<Compile Include="Attack\AttackFollow.cs" />
|
||||
<Compile Include="Attack\AttackGarrisoned.cs" />
|
||||
<Compile Include="Widgets\Logic\LobbyMapPreviewLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\ButtonTooltipLogic.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
36
OpenRA.Mods.RA/Widgets/Logic/ButtonTooltipLogic.cs
Normal file
36
OpenRA.Mods.RA/Widgets/Logic/ButtonTooltipLogic.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
public class ButtonTooltipLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public ButtonTooltipLogic(Widget widget, ButtonWidget button)
|
||||
{
|
||||
var label = widget.Get<LabelWidget>("LABEL");
|
||||
var hotkey = widget.Get<LabelWidget>("HOTKEY");
|
||||
|
||||
label.GetText = () => button.TooltipText;
|
||||
var labelWidth = Game.Renderer.Fonts[label.Font].Measure(button.TooltipText).X;
|
||||
label.Bounds.Width = labelWidth;
|
||||
|
||||
var hotkeyLabel = "({0})".F(button.Key.DisplayString());
|
||||
hotkey.GetText = () => hotkeyLabel;
|
||||
hotkey.Bounds.X = labelWidth + 2 * label.Bounds.X;
|
||||
|
||||
var panelWidth = hotkey.Bounds.X + label.Bounds.X
|
||||
+ Game.Renderer.Fonts[label.Font].Measure(hotkeyLabel).X;
|
||||
widget.Bounds.Width = panelWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,11 +111,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
objectivesButton.OnClick += () => objectivesWidget.Visible ^= true;
|
||||
}
|
||||
|
||||
var moneyBin = playerWidgets.Get("INGAME_MONEY_BIN");
|
||||
moneyBin.Get<OrderButtonWidget>("SELL").GetKey = _ => Game.Settings.Keys.SellKey;
|
||||
moneyBin.Get<OrderButtonWidget>("POWER_DOWN").GetKey = _ => Game.Settings.Keys.PowerDownKey;
|
||||
moneyBin.Get<OrderButtonWidget>("REPAIR").GetKey = _ => Game.Settings.Keys.RepairKey;
|
||||
|
||||
bool radarActive = false;
|
||||
RadarBinState binState = RadarBinState.Closed;
|
||||
var radarBin = playerWidgets.Get<SlidingContainerWidget>("INGAME_RADAR_BIN");
|
||||
|
||||
@@ -16,32 +16,38 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
public class OrderButtonsChromeLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public OrderButtonsChromeLogic(World world)
|
||||
public OrderButtonsChromeLogic(Widget widget, World world)
|
||||
{
|
||||
/* TODO: attach this to the correct widget, to remove the lookups below */
|
||||
var r = Ui.Root;
|
||||
var gameRoot = r.Get("INGAME_ROOT");
|
||||
var sell = widget.GetOrNull<ButtonWidget>("SELL_BUTTON");
|
||||
if (sell != null)
|
||||
{
|
||||
sell.GetKey = _ => Game.Settings.Keys.SellKey;
|
||||
BindOrderButton<SellOrderGenerator>(world, sell, "sell");
|
||||
}
|
||||
|
||||
var moneybin = gameRoot.Get("INGAME_MONEY_BIN");
|
||||
moneybin.IsVisible = () => {
|
||||
return world.LocalPlayer.WinState == WinState.Undefined;
|
||||
};
|
||||
var repair = widget.GetOrNull<ButtonWidget>("REPAIR_BUTTON");
|
||||
if (repair != null)
|
||||
{
|
||||
repair.GetKey = _ => Game.Settings.Keys.RepairKey;
|
||||
BindOrderButton<RepairOrderGenerator>(world, repair, "repair");
|
||||
}
|
||||
|
||||
BindOrderButton<SellOrderGenerator>(world, moneybin, "SELL");
|
||||
BindOrderButton<PowerDownOrderGenerator>(world, moneybin, "POWER_DOWN");
|
||||
BindOrderButton<RepairOrderGenerator>(world, moneybin, "REPAIR");
|
||||
var power = widget.GetOrNull<ButtonWidget>("POWER_BUTTON");
|
||||
if (power != null)
|
||||
{
|
||||
power.GetKey = _ => Game.Settings.Keys.PowerDownKey;
|
||||
BindOrderButton<PowerDownOrderGenerator>(world, power, "power");
|
||||
}
|
||||
}
|
||||
|
||||
static void BindOrderButton<T>(World world, Widget parent, string button)
|
||||
static void BindOrderButton<T>(World world, ButtonWidget w, string icon)
|
||||
where T : IOrderGenerator, new()
|
||||
{
|
||||
var w = parent.GetOrNull<OrderButtonWidget>(button);
|
||||
if (w != null)
|
||||
{
|
||||
w.Pressed = () => world.OrderGenerator is T;
|
||||
w.OnMouseDown = mi => world.ToggleInputMode<T>();
|
||||
w.OnKeyPress = ki => world.ToggleInputMode<T>();
|
||||
}
|
||||
w.OnClick = () => world.ToggleInputMode<T>();
|
||||
w.IsHighlighted = () => world.OrderGenerator is T;
|
||||
|
||||
w.Get<ImageWidget>("ICON").GetImageName =
|
||||
() => world.OrderGenerator is T ? icon + "-active" : icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
#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 System;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets
|
||||
{
|
||||
public class OrderButtonWidget : ButtonWidget
|
||||
{
|
||||
public Func<bool> Enabled = () => true;
|
||||
public Func<bool> Pressed = () => false;
|
||||
|
||||
public string Image, Description, LongDesc = "";
|
||||
|
||||
public Func<string> GetImage, GetDescription, GetLongDesc;
|
||||
|
||||
public OrderButtonWidget()
|
||||
{
|
||||
GetImage = () => Enabled() ? Pressed() ? "pressed" : "normal" : "disabled";
|
||||
GetDescription = () => Key.IsValid() ? "{0} ({1})".F(Description, Key.DisplayString()) : Description;
|
||||
GetLongDesc = () => LongDesc;
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
var image = ChromeProvider.GetImage(Image + "-button", GetImage());
|
||||
var rect = new Rectangle(RenderBounds.X, RenderBounds.Y, (int)image.size.X, (int)image.size.Y);
|
||||
|
||||
if (rect.Contains(Viewport.LastMousePos))
|
||||
{
|
||||
rect = rect.InflateBy(3, 3, 3, 3);
|
||||
var pos = new int2(rect.Left, rect.Top);
|
||||
var m = pos + new int2(rect.Width, rect.Height);
|
||||
var br = pos + new int2(rect.Width, rect.Height + 20);
|
||||
|
||||
var u = Game.Renderer.Fonts["Regular"].Measure(GetLongDesc().Replace("\\n", "\n"));
|
||||
|
||||
br.X -= u.X;
|
||||
br.Y += u.Y;
|
||||
br += new int2(-15, 25);
|
||||
|
||||
var border = WidgetUtils.GetBorderSizes("dialog4");
|
||||
|
||||
WidgetUtils.DrawPanelPartial("dialog4", rect
|
||||
.InflateBy(0, 0, 0, border[1]),
|
||||
PanelSides.Top | PanelSides.Left | PanelSides.Right | PanelSides.Center);
|
||||
|
||||
WidgetUtils.DrawPanelPartial("dialog4", new Rectangle(br.X, m.Y, pos.X - br.X, br.Y - m.Y)
|
||||
.InflateBy(0, 0, border[3], 0),
|
||||
PanelSides.Top | PanelSides.Left | PanelSides.Bottom | PanelSides.Center);
|
||||
|
||||
WidgetUtils.DrawPanelPartial("dialog4", new Rectangle(pos.X, m.Y, m.X - pos.X, br.Y - m.Y)
|
||||
.InflateBy(border[2], border[0], 0, 0),
|
||||
PanelSides.Right | PanelSides.Bottom | PanelSides.Center);
|
||||
|
||||
pos.X = br.X + 8;
|
||||
pos.Y = m.Y + 8;
|
||||
Game.Renderer.Fonts["Bold"].DrawText(GetDescription(), pos, Color.White);
|
||||
|
||||
pos += new int2(0, 20);
|
||||
Game.Renderer.Fonts["Regular"].DrawText(GetLongDesc().Replace("\\n", "\n"), pos, Color.White);
|
||||
}
|
||||
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(image, new int2(RenderBounds.X, RenderBounds.Y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user