Merge tooltip support into Button and remove ToggleButton.
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
|
||||||
namespace OpenRA.Widgets
|
namespace OpenRA.Widgets
|
||||||
@@ -36,6 +37,11 @@ namespace OpenRA.Widgets
|
|||||||
public Action<MouseInput> OnMouseDown = _ => {};
|
public Action<MouseInput> OnMouseDown = _ => {};
|
||||||
public Action<MouseInput> OnMouseUp = _ => {};
|
public Action<MouseInput> OnMouseUp = _ => {};
|
||||||
|
|
||||||
|
public readonly string TooltipTemplate = "BUTTON_TOOLTIP";
|
||||||
|
public readonly string TooltipText;
|
||||||
|
public readonly string TooltipContainer;
|
||||||
|
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||||
|
|
||||||
// Equivalent to OnMouseUp, but without an input arg
|
// Equivalent to OnMouseUp, but without an input arg
|
||||||
public Action OnClick = () => {};
|
public Action OnClick = () => {};
|
||||||
public Action OnDoubleClick = () => {};
|
public Action OnDoubleClick = () => {};
|
||||||
@@ -49,24 +55,32 @@ namespace OpenRA.Widgets
|
|||||||
OnKeyPress = _ => OnClick();
|
OnKeyPress = _ => OnClick();
|
||||||
IsDisabled = () => Disabled;
|
IsDisabled = () => Disabled;
|
||||||
IsHighlighted = () => Highlighted;
|
IsHighlighted = () => Highlighted;
|
||||||
|
tooltipContainer = Lazy.New(() =>
|
||||||
|
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ButtonWidget(ButtonWidget widget)
|
protected ButtonWidget(ButtonWidget other)
|
||||||
: base(widget)
|
: base(other)
|
||||||
{
|
{
|
||||||
Text = widget.Text;
|
Text = other.Text;
|
||||||
Font = widget.Font;
|
Font = other.Font;
|
||||||
Depressed = widget.Depressed;
|
Depressed = other.Depressed;
|
||||||
VisualHeight = widget.VisualHeight;
|
VisualHeight = other.VisualHeight;
|
||||||
GetText = widget.GetText;
|
GetText = other.GetText;
|
||||||
OnMouseDown = widget.OnMouseDown;
|
OnMouseDown = other.OnMouseDown;
|
||||||
Disabled = widget.Disabled;
|
Disabled = other.Disabled;
|
||||||
IsDisabled = widget.IsDisabled;
|
IsDisabled = other.IsDisabled;
|
||||||
Highlighted = widget.Highlighted;
|
Highlighted = other.Highlighted;
|
||||||
IsHighlighted = widget.IsHighlighted;
|
IsHighlighted = other.IsHighlighted;
|
||||||
|
|
||||||
OnMouseUp = mi => OnClick();
|
OnMouseUp = mi => OnClick();
|
||||||
OnKeyPress = _ => OnClick();
|
OnKeyPress = _ => OnClick();
|
||||||
|
|
||||||
|
TooltipTemplate = other.TooltipTemplate;
|
||||||
|
TooltipText = other.TooltipText;
|
||||||
|
TooltipContainer = other.TooltipContainer;
|
||||||
|
tooltipContainer = Lazy.New(() =>
|
||||||
|
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool LoseFocus(MouseInput mi)
|
public override bool LoseFocus(MouseInput mi)
|
||||||
@@ -137,6 +151,19 @@ namespace OpenRA.Widgets
|
|||||||
return Depressed;
|
return Depressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void MouseEntered()
|
||||||
|
{
|
||||||
|
if (TooltipContainer == null) return;
|
||||||
|
tooltipContainer.Value.SetTooltip(TooltipTemplate,
|
||||||
|
new WidgetArgs() {{ "button", this }});
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void MouseExited()
|
||||||
|
{
|
||||||
|
if (TooltipContainer == null) return;
|
||||||
|
tooltipContainer.Value.RemoveTooltip();
|
||||||
|
}
|
||||||
|
|
||||||
public override int2 ChildOrigin { get { return RenderOrigin +
|
public override int2 ChildOrigin { get { return RenderOrigin +
|
||||||
((Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0)); } }
|
((Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0)); } }
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,6 @@
|
|||||||
<Compile Include="Widgets\ProductionPaletteWidget.cs" />
|
<Compile Include="Widgets\ProductionPaletteWidget.cs" />
|
||||||
<Compile Include="Widgets\ProductionTabsWidget.cs" />
|
<Compile Include="Widgets\ProductionTabsWidget.cs" />
|
||||||
<Compile Include="Widgets\SupportPowersWidget.cs" />
|
<Compile Include="Widgets\SupportPowersWidget.cs" />
|
||||||
<Compile Include="Widgets\ToggleButtonWidget.cs" />
|
|
||||||
<Compile Include="WithFire.cs" />
|
<Compile Include="WithFire.cs" />
|
||||||
<Compile Include="WithRoof.cs" />
|
<Compile Include="WithRoof.cs" />
|
||||||
<Compile Include="Widgets\ResourceBarWidget.cs" />
|
<Compile Include="Widgets\ResourceBarWidget.cs" />
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
public class ButtonTooltipLogic
|
public class ButtonTooltipLogic
|
||||||
{
|
{
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public ButtonTooltipLogic(Widget widget, ToggleButtonWidget button)
|
public ButtonTooltipLogic(Widget widget, ButtonWidget button)
|
||||||
{
|
{
|
||||||
var label = widget.Get<LabelWidget>("LABEL");
|
var label = widget.Get<LabelWidget>("LABEL");
|
||||||
var hotkey = widget.Get<LabelWidget>("HOTKEY");
|
var hotkey = widget.Get<LabelWidget>("HOTKEY");
|
||||||
|
|||||||
@@ -90,8 +90,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
BindOrderButton<SellOrderGenerator>(world, sidebarRoot, "SELL_BUTTON", "sell");
|
BindOrderButton<SellOrderGenerator>(world, sidebarRoot, "SELL_BUTTON", "sell");
|
||||||
BindOrderButton<RepairOrderGenerator>(world, sidebarRoot, "REPAIR_BUTTON", "repair");
|
BindOrderButton<RepairOrderGenerator>(world, sidebarRoot, "REPAIR_BUTTON", "repair");
|
||||||
|
|
||||||
sidebarRoot.Get<ToggleButtonWidget>("SELL_BUTTON").Key = Game.Settings.Keys.SellKey;
|
sidebarRoot.Get<ButtonWidget>("SELL_BUTTON").Key = Game.Settings.Keys.SellKey;
|
||||||
sidebarRoot.Get<ToggleButtonWidget>("REPAIR_BUTTON").Key = Game.Settings.Keys.RepairKey;
|
sidebarRoot.Get<ButtonWidget>("REPAIR_BUTTON").Key = Game.Settings.Keys.RepairKey;
|
||||||
|
|
||||||
var powerManager = world.LocalPlayer.PlayerActor.Trait<PowerManager>();
|
var powerManager = world.LocalPlayer.PlayerActor.Trait<PowerManager>();
|
||||||
var playerResources = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
|
var playerResources = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
|
||||||
@@ -139,7 +139,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
static void BindOrderButton<T>(World world, Widget parent, string button, string icon)
|
static void BindOrderButton<T>(World world, Widget parent, string button, string icon)
|
||||||
where T : IOrderGenerator, new()
|
where T : IOrderGenerator, new()
|
||||||
{
|
{
|
||||||
var w = parent.Get<ToggleButtonWidget>(button);
|
var w = parent.Get<ButtonWidget>(button);
|
||||||
w.OnClick = () => world.ToggleInputMode<T>();
|
w.OnClick = () => world.ToggleInputMode<T>();
|
||||||
w.IsHighlighted = () => world.OrderGenerator is T;
|
w.IsHighlighted = () => world.OrderGenerator is T;
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ using OpenRA.Widgets;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Cnc.Widgets
|
namespace OpenRA.Mods.Cnc.Widgets
|
||||||
{
|
{
|
||||||
public class ProductionTypeButtonWidget : ToggleButtonWidget
|
public class ProductionTypeButtonWidget : ButtonWidget
|
||||||
{
|
{
|
||||||
public readonly string ProductionGroup;
|
public readonly string ProductionGroup;
|
||||||
|
|
||||||
|
|||||||
@@ -1,55 +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.FileFormats;
|
|
||||||
using OpenRA.Widgets;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.Cnc.Widgets
|
|
||||||
{
|
|
||||||
public class ToggleButtonWidget : ButtonWidget
|
|
||||||
{
|
|
||||||
public readonly string TooltipTemplate = "BUTTON_TOOLTIP";
|
|
||||||
public readonly string TooltipText;
|
|
||||||
public readonly string TooltipContainer;
|
|
||||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
|
||||||
|
|
||||||
public ToggleButtonWidget()
|
|
||||||
: base()
|
|
||||||
{
|
|
||||||
tooltipContainer = Lazy.New(() =>
|
|
||||||
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ToggleButtonWidget(ToggleButtonWidget other)
|
|
||||||
: base(other)
|
|
||||||
{
|
|
||||||
TooltipTemplate = other.TooltipTemplate;
|
|
||||||
TooltipText = other.TooltipText;
|
|
||||||
TooltipContainer = other.TooltipContainer;
|
|
||||||
tooltipContainer = Lazy.New(() =>
|
|
||||||
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void MouseEntered()
|
|
||||||
{
|
|
||||||
if (TooltipContainer == null) return;
|
|
||||||
tooltipContainer.Value.SetTooltip(TooltipTemplate,
|
|
||||||
new WidgetArgs() {{ "button", this }});
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void MouseExited()
|
|
||||||
{
|
|
||||||
if (TooltipContainer == null) return;
|
|
||||||
tooltipContainer.Value.RemoveTooltip();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -44,7 +44,7 @@ Container@INGAME_ROOT:
|
|||||||
TooltipContainer@TOOLTIP_CONTAINER:
|
TooltipContainer@TOOLTIP_CONTAINER:
|
||||||
Container@OBSERVER_WIDGETS:
|
Container@OBSERVER_WIDGETS:
|
||||||
Children:
|
Children:
|
||||||
ToggleButton@OPTIONS_BUTTON:
|
Button@OPTIONS_BUTTON:
|
||||||
Key:escape
|
Key:escape
|
||||||
X:WINDOW_RIGHT-202
|
X:WINDOW_RIGHT-202
|
||||||
Y:5
|
Y:5
|
||||||
@@ -98,7 +98,7 @@ Container@PLAYER_WIDGETS:
|
|||||||
Height:240
|
Height:240
|
||||||
Background:panel-black
|
Background:panel-black
|
||||||
Children:
|
Children:
|
||||||
ToggleButton@OPTIONS_BUTTON:
|
Button@OPTIONS_BUTTON:
|
||||||
Key:escape
|
Key:escape
|
||||||
X:42
|
X:42
|
||||||
Y:0-24
|
Y:0-24
|
||||||
@@ -113,7 +113,7 @@ Container@PLAYER_WIDGETS:
|
|||||||
Y:5
|
Y:5
|
||||||
ImageCollection:order-icons
|
ImageCollection:order-icons
|
||||||
ImageName:options
|
ImageName:options
|
||||||
ToggleButton@SELL_BUTTON:
|
Button@SELL_BUTTON:
|
||||||
X:82
|
X:82
|
||||||
Y:0-24
|
Y:0-24
|
||||||
Width:30
|
Width:30
|
||||||
@@ -126,7 +126,7 @@ Container@PLAYER_WIDGETS:
|
|||||||
X:7
|
X:7
|
||||||
Y:5
|
Y:5
|
||||||
ImageCollection:order-icons
|
ImageCollection:order-icons
|
||||||
ToggleButton@REPAIR_BUTTON:
|
Button@REPAIR_BUTTON:
|
||||||
X:122
|
X:122
|
||||||
Y:0-24
|
Y:0-24
|
||||||
Width:30
|
Width:30
|
||||||
|
|||||||
Reference in New Issue
Block a user