Start implementing new tooltip bits. Test tooltips added for buttons and production palette.
This commit is contained in:
@@ -69,7 +69,9 @@ namespace OpenRA.Widgets
|
||||
|
||||
public static bool DoHandleInput(MouseInput mi)
|
||||
{
|
||||
if (mi.Event == MouseInputEvent.Move)
|
||||
var wasMouseOver = MouseOverWidget;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Move)
|
||||
MouseOverWidget = null;
|
||||
|
||||
bool handled = false;
|
||||
@@ -85,6 +87,15 @@ namespace OpenRA.Widgets
|
||||
Viewport.TicksSinceLastMove = 0;
|
||||
}
|
||||
|
||||
if (wasMouseOver != MouseOverWidget)
|
||||
{
|
||||
if (wasMouseOver != null)
|
||||
wasMouseOver.MouseExited();
|
||||
|
||||
if (MouseOverWidget != null)
|
||||
MouseOverWidget.MouseEntered();
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
@@ -268,6 +279,8 @@ namespace OpenRA.Widgets
|
||||
return EventBounds.Contains(pos) ? GetCursor(pos) : null;
|
||||
}
|
||||
|
||||
public virtual void MouseEntered() {}
|
||||
public virtual void MouseExited() {}
|
||||
public virtual bool HandleMouseInput(MouseInput mi) { return false; }
|
||||
public bool HandleMouseInputOuter(MouseInput mi)
|
||||
{
|
||||
|
||||
@@ -96,6 +96,10 @@
|
||||
<Compile Include="Widgets\ProductionPaletteWidget.cs" />
|
||||
<Compile Include="ProductionQueueFromSelection.cs" />
|
||||
<Compile Include="Widgets\SupportPowersWidget.cs" />
|
||||
<Compile Include="Widgets\Logic\ProductionTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\TooltipContainerWidget.cs" />
|
||||
<Compile Include="Widgets\TooltipButtonWidget.cs" />
|
||||
<Compile Include="Widgets\Logic\ButtonTooltipLogic.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
27
OpenRA.Mods.Cnc/Widgets/Logic/ButtonTooltipLogic.cs
Normal file
27
OpenRA.Mods.Cnc/Widgets/Logic/ButtonTooltipLogic.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
#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.Support;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
public class ButtonTooltipLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public ButtonTooltipLogic([ObjectCreator.Param] Widget widget,
|
||||
[ObjectCreator.Param] TooltipButtonWidget button)
|
||||
{
|
||||
widget.GetWidget<LabelWidget>("LABEL").GetText = () => button.TooltipText;
|
||||
widget.GetWidget<LabelWidget>("HOTKEY").GetText = () => button.Key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
27
OpenRA.Mods.Cnc/Widgets/Logic/ProductionTooltipLogic.cs
Normal file
27
OpenRA.Mods.Cnc/Widgets/Logic/ProductionTooltipLogic.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
#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.Support;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
public class ProductionTooltipLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public ProductionTooltipLogic([ObjectCreator.Param] Widget widget,
|
||||
[ObjectCreator.Param] ProductionPaletteWidget palette)
|
||||
{
|
||||
widget.IsVisible = () => palette.TooltipActor != null;
|
||||
widget.GetWidget<LabelWidget>("NAME").GetText = () => palette.TooltipActor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,11 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
{
|
||||
public readonly int Columns = 3;
|
||||
public readonly string TabClick = "button.aud";
|
||||
public readonly string TooltipContainer;
|
||||
public readonly string TooltipTemplate;
|
||||
public string TooltipActor { get; private set; }
|
||||
|
||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||
ProductionQueue currentQueue;
|
||||
public ProductionQueue CurrentQueue
|
||||
{
|
||||
@@ -62,7 +66,9 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
{
|
||||
this.world = world;
|
||||
this.worldRenderer = worldRenderer;
|
||||
|
||||
tooltipContainer = new Lazy<TooltipContainerWidget>(() =>
|
||||
Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
|
||||
|
||||
cantBuild = new Animation("clock");
|
||||
cantBuild.PlayFetchIndex("idle", () => 0);
|
||||
clock = new Animation("clock");
|
||||
@@ -83,12 +89,36 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
if (CurrentQueue != null)
|
||||
RefreshIcons();
|
||||
}
|
||||
|
||||
|
||||
public override void MouseEntered()
|
||||
{
|
||||
if (TooltipContainer == null)
|
||||
return;
|
||||
|
||||
var panel = Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "palette", this }});
|
||||
tooltipContainer.Value.SetTooltip(panel);
|
||||
}
|
||||
|
||||
public override void MouseExited()
|
||||
{
|
||||
if (TooltipContainer == null) return;
|
||||
tooltipContainer.Value.RemoveTooltip();
|
||||
}
|
||||
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
if (mi.Event == MouseInputEvent.Move)
|
||||
{
|
||||
var hover = Icons.Where(i => i.Key.Contains(mi.Location))
|
||||
.Select(i => i.Value).FirstOrDefault();
|
||||
|
||||
TooltipActor = hover != null ? hover.Name : null;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mi.Event != MouseInputEvent.Down)
|
||||
return false;
|
||||
|
||||
|
||||
var clicked = Icons.Where(i => i.Key.Contains(mi.Location))
|
||||
.Select(i => i.Value).FirstOrDefault();
|
||||
|
||||
|
||||
55
OpenRA.Mods.Cnc/Widgets/TooltipButtonWidget.cs
Normal file
55
OpenRA.Mods.Cnc/Widgets/TooltipButtonWidget.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
#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.FileFormats;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets
|
||||
{
|
||||
public class TooltipButtonWidget : ButtonWidget
|
||||
{
|
||||
public readonly string TooltipTemplate;
|
||||
public readonly string TooltipText;
|
||||
public readonly string TooltipContainer;
|
||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||
|
||||
public TooltipButtonWidget()
|
||||
: base()
|
||||
{
|
||||
tooltipContainer = new Lazy<TooltipContainerWidget>(() =>
|
||||
Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
|
||||
}
|
||||
|
||||
protected TooltipButtonWidget(TooltipButtonWidget other)
|
||||
: base(other)
|
||||
{
|
||||
TooltipTemplate = other.TooltipTemplate;
|
||||
TooltipText = other.TooltipText;
|
||||
TooltipContainer = other.TooltipContainer;
|
||||
tooltipContainer = new Lazy<TooltipContainerWidget>(() =>
|
||||
Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
|
||||
}
|
||||
|
||||
public override void MouseEntered()
|
||||
{
|
||||
if (TooltipContainer == null)
|
||||
return;
|
||||
|
||||
var panel = Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "button", this }});
|
||||
tooltipContainer.Value.SetTooltip(panel);
|
||||
}
|
||||
|
||||
public override void MouseExited()
|
||||
{
|
||||
if (TooltipContainer == null) return;
|
||||
tooltipContainer.Value.RemoveTooltip();
|
||||
}
|
||||
}
|
||||
}
|
||||
64
OpenRA.Mods.Cnc/Widgets/TooltipContainerWidget.cs
Executable file
64
OpenRA.Mods.Cnc/Widgets/TooltipContainerWidget.cs
Executable file
@@ -0,0 +1,64 @@
|
||||
#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.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA;
|
||||
using OpenRA.Widgets;
|
||||
using System;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets
|
||||
{
|
||||
class TooltipContainerWidget : Widget
|
||||
{
|
||||
public int2 CursorOffset = new int2(20, 0);
|
||||
public int TooltipDelay = 10;
|
||||
Widget tooltip;
|
||||
|
||||
public TooltipContainerWidget()
|
||||
{
|
||||
IsVisible = () => Viewport.TicksSinceLastMove >= TooltipDelay;
|
||||
}
|
||||
|
||||
public void SetTooltip(Widget tooltip)
|
||||
{
|
||||
this.tooltip = tooltip;
|
||||
RemoveChildren();
|
||||
AddChild(tooltip);
|
||||
}
|
||||
|
||||
public void RemoveTooltip()
|
||||
{
|
||||
RemoveChildren();
|
||||
}
|
||||
|
||||
public override Rectangle GetEventBounds() { return Rectangle.Empty; }
|
||||
public override int2 ChildOrigin
|
||||
{
|
||||
get
|
||||
{
|
||||
var pos = Viewport.LastMousePos + CursorOffset;
|
||||
if (tooltip != null)
|
||||
{
|
||||
if (pos.X + tooltip.Bounds.Right > Game.viewport.Width)
|
||||
pos.X -= 2*CursorOffset.X + tooltip.Bounds.Right;
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
|
||||
public override string GetCursor(int2 pos) { return null; }
|
||||
public override Widget Clone() { throw new NotImplementedException(); }
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ Container@INGAME_ROOT:
|
||||
Width:140
|
||||
Height:35
|
||||
Text:Cheats
|
||||
WorldTooltip:
|
||||
ChatDisplay@CHAT_DISPLAY:
|
||||
Id:CHAT_DISPLAY
|
||||
X:250
|
||||
@@ -180,40 +179,55 @@ Container@INGAME_ROOT:
|
||||
Width:170
|
||||
Height:30
|
||||
Children:
|
||||
Button@BUILDING:
|
||||
TooltipButton@BUILDING:
|
||||
Id:BUILDING
|
||||
Width:30
|
||||
Height:30
|
||||
Text: B
|
||||
Key: y
|
||||
Button@DEFENSE:
|
||||
TooltipText: Buildings
|
||||
TooltipContainer: TOOLTIP_CONTAINER
|
||||
TooltipTemplate: BUTTON_TOOLTIP
|
||||
TooltipButton@DEFENSE:
|
||||
Id:DEFENSE
|
||||
X:35
|
||||
Width:30
|
||||
Height:30
|
||||
Text: D
|
||||
Key: u
|
||||
Button@INFANTRY:
|
||||
TooltipText: Defense
|
||||
TooltipContainer: TOOLTIP_CONTAINER
|
||||
TooltipTemplate: BUTTON_TOOLTIP
|
||||
TooltipButton@INFANTRY:
|
||||
Id:INFANTRY
|
||||
X:70
|
||||
Width:30
|
||||
Height:30
|
||||
Text: I
|
||||
Key: i
|
||||
Button@VEHICLE:
|
||||
TooltipText: Infantry
|
||||
TooltipContainer: TOOLTIP_CONTAINER
|
||||
TooltipTemplate: BUTTON_TOOLTIP
|
||||
TooltipButton@VEHICLE:
|
||||
Id:VEHICLE
|
||||
X:105
|
||||
Width:30
|
||||
Height:30
|
||||
Text: V
|
||||
Key: o
|
||||
Button@AIRCRAFT:
|
||||
TooltipText: Vehicles
|
||||
TooltipContainer: TOOLTIP_CONTAINER
|
||||
TooltipTemplate: BUTTON_TOOLTIP
|
||||
TooltipButton@AIRCRAFT:
|
||||
Id:AIRCRAFT
|
||||
X:140
|
||||
Width:30
|
||||
Height:30
|
||||
Text: H
|
||||
Key: p
|
||||
TooltipText: Aircraft
|
||||
TooltipContainer: TOOLTIP_CONTAINER
|
||||
TooltipTemplate: BUTTON_TOOLTIP
|
||||
ProductionTabs:
|
||||
Id:PRODUCTION_TABS
|
||||
PaletteWidget:PRODUCTION_PALETTE
|
||||
@@ -226,6 +240,11 @@ Container@INGAME_ROOT:
|
||||
X:WINDOW_RIGHT - 204
|
||||
Y:287
|
||||
TabClick: button.aud
|
||||
TooltipContainer: TOOLTIP_CONTAINER
|
||||
TooltipTemplate: PRODUCTION_TOOLTIP
|
||||
TooltipContainer:
|
||||
Id:TOOLTIP_CONTAINER
|
||||
|
||||
Background@FMVPLAYER:
|
||||
Id:FMVPLAYER
|
||||
Width:WINDOW_RIGHT
|
||||
|
||||
36
mods/cnc/chrome/tooltips.yaml
Normal file
36
mods/cnc/chrome/tooltips.yaml
Normal file
@@ -0,0 +1,36 @@
|
||||
Background@PRODUCTION_TOOLTIP:
|
||||
Id:PRODUCTION_TOOLTIP
|
||||
Logic:ProductionTooltipLogic
|
||||
Background:panel-black
|
||||
Width:100
|
||||
Height:30
|
||||
Children:
|
||||
Label@NAME:
|
||||
Id:NAME
|
||||
X:5
|
||||
Y:5
|
||||
Width:PARENT_RIGHT-10
|
||||
Height:PARENT_BOTTOM-10
|
||||
Font:Bold
|
||||
Background@BUTTON_TOOLTIP:
|
||||
Id:BUTTON_TOOLTIP
|
||||
Logic:ButtonTooltipLogic
|
||||
Background:panel-black
|
||||
Width:100
|
||||
Height:30
|
||||
Children:
|
||||
Label@LABEL:
|
||||
Id:LABEL
|
||||
X:5
|
||||
Y:5
|
||||
Width:PARENT_RIGHT-10
|
||||
Height:PARENT_BOTTOM-10
|
||||
Font:Bold
|
||||
Label@HOTKEY:
|
||||
Id:HOTKEY
|
||||
X:PARENT_RIGHT-15
|
||||
Y:5
|
||||
Color:255,255,0
|
||||
Width:PARENT_RIGHT-10
|
||||
Height:PARENT_BOTTOM-10
|
||||
Font:Bold
|
||||
@@ -80,6 +80,7 @@ ChromeLayout:
|
||||
mods/cnc/chrome/cheats.yaml
|
||||
mods/cnc/chrome/dropdowns.yaml
|
||||
mods/cnc/chrome/objectives.yaml
|
||||
mods/cnc/chrome/tooltips.yaml
|
||||
|
||||
Weapons:
|
||||
mods/cnc/weapons.yaml
|
||||
|
||||
Reference in New Issue
Block a user