Start implementing new tooltip bits. Test tooltips added for buttons and production palette.

This commit is contained in:
Paul Chote
2011-07-04 05:24:44 +12:00
parent 608bdc8fcd
commit 460451c402
10 changed files with 286 additions and 10 deletions

View File

@@ -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">

View 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;
}
}
}

View 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;
}
}
}

View File

@@ -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();

View 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();
}
}
}

View 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(); }
}
}