@@ -136,6 +136,12 @@ namespace OpenRA.Traits
|
||||
bool IsOwnerRowVisible { get; }
|
||||
}
|
||||
|
||||
public interface IProvideTooltipInfo
|
||||
{
|
||||
bool IsTooltipVisible(Player forPlayer);
|
||||
string TooltipText { get; }
|
||||
}
|
||||
|
||||
public interface IDisabledTrait { bool IsTraitDisabled { get; } }
|
||||
public interface IDisable { bool Disabled { get; } }
|
||||
public interface IExplodeModifier { bool ShouldExplode(Actor self); }
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
public WorldTooltipType TooltipType { get; private set; }
|
||||
public IToolTip ActorTooltip { get; private set; }
|
||||
public IEnumerable<IProvideTooltipInfo> ActorTooltipExtra { get; private set; }
|
||||
public FrozenActor FrozenActorTooltip { get; private set; }
|
||||
|
||||
public int EdgeScrollThreshold = 15;
|
||||
@@ -92,6 +93,7 @@ namespace OpenRA.Widgets
|
||||
public void UpdateMouseover()
|
||||
{
|
||||
TooltipType = WorldTooltipType.None;
|
||||
ActorTooltipExtra = null;
|
||||
var cell = worldRenderer.Viewport.ViewToWorld(Viewport.LastMousePos);
|
||||
if (!world.Map.Contains(cell))
|
||||
return;
|
||||
@@ -109,6 +111,7 @@ namespace OpenRA.Widgets
|
||||
if (underCursor != null)
|
||||
{
|
||||
ActorTooltip = underCursor.TraitsImplementing<IToolTip>().First();
|
||||
ActorTooltipExtra = underCursor.TraitsImplementing<IProvideTooltipInfo>();
|
||||
TooltipType = WorldTooltipType.Actor;
|
||||
return;
|
||||
}
|
||||
@@ -120,6 +123,8 @@ namespace OpenRA.Widgets
|
||||
if (frozen != null)
|
||||
{
|
||||
FrozenActorTooltip = frozen;
|
||||
if (frozen.Actor != null)
|
||||
ActorTooltipExtra = frozen.Actor.TraitsImplementing<IProvideTooltipInfo>();
|
||||
TooltipType = WorldTooltipType.FrozenActor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,10 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -20,13 +22,20 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public readonly int RefundPercent = 50;
|
||||
public readonly string[] SellSounds = { };
|
||||
|
||||
public object Create(ActorInitializer init) { return new Sellable(this); }
|
||||
public object Create(ActorInitializer init) { return new Sellable(init.Self, this); }
|
||||
}
|
||||
|
||||
public class Sellable : UpgradableTrait<SellableInfo>, IResolveOrder
|
||||
public class Sellable : UpgradableTrait<SellableInfo>, IResolveOrder, IProvideTooltipInfo
|
||||
{
|
||||
public Sellable(SellableInfo info)
|
||||
: base(info) { }
|
||||
readonly Actor self;
|
||||
readonly Lazy<Health> health;
|
||||
|
||||
public Sellable(Actor self, SellableInfo info)
|
||||
: base(info)
|
||||
{
|
||||
this.self = self;
|
||||
health = Exts.Lazy(() => self.TraitOrDefault<Health>());
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
@@ -57,5 +66,27 @@ namespace OpenRA.Mods.Common.Traits
|
||||
else
|
||||
self.QueueActivity(false, new Sell());
|
||||
}
|
||||
|
||||
public bool IsTooltipVisible(Player forPlayer)
|
||||
{
|
||||
if (self.World.OrderGenerator is SellOrderGenerator)
|
||||
return forPlayer == self.Owner;
|
||||
return false;
|
||||
}
|
||||
|
||||
public string TooltipText
|
||||
{
|
||||
get
|
||||
{
|
||||
var sellValue = self.GetSellValue() * Info.RefundPercent / 100;
|
||||
if (health.Value != null)
|
||||
{
|
||||
sellValue *= health.Value.HP;
|
||||
sellValue /= health.Value.MaxHP;
|
||||
}
|
||||
|
||||
return "Refund: " + sellValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
@@ -24,6 +25,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var label = widget.Get<LabelWidget>("LABEL");
|
||||
var flag = widget.Get<ImageWidget>("FLAG");
|
||||
var owner = widget.Get<LabelWidget>("OWNER");
|
||||
var extras = widget.Get<LabelWidget>("EXTRA");
|
||||
|
||||
var font = Game.Renderer.Fonts[label.Font];
|
||||
var ownerFont = Game.Renderer.Fonts[owner.Font];
|
||||
@@ -33,15 +35,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var flagRace = "";
|
||||
var ownerName = "";
|
||||
var ownerColor = Color.White;
|
||||
var extraText = "";
|
||||
|
||||
var singleHeight = widget.Get("SINGLE_HEIGHT").Bounds.Height;
|
||||
var doubleHeight = widget.Get("DOUBLE_HEIGHT").Bounds.Height;
|
||||
var extraHeightOnDouble = extras.Bounds.Y;
|
||||
var extraHeightOnSingle = extraHeightOnDouble - (doubleHeight - singleHeight);
|
||||
|
||||
tooltipContainer.BeforeRender = () =>
|
||||
{
|
||||
if (viewport == null || viewport.TooltipType == WorldTooltipType.None)
|
||||
return;
|
||||
|
||||
var index = 0;
|
||||
extraText = "";
|
||||
showOwner = false;
|
||||
|
||||
Player o = null;
|
||||
@@ -71,7 +78,22 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
}
|
||||
|
||||
var textWidth = font.Measure(labelText).X;
|
||||
if (viewport.ActorTooltipExtra != null)
|
||||
{
|
||||
foreach (var info in viewport.ActorTooltipExtra)
|
||||
{
|
||||
if (info.IsTooltipVisible(world.LocalPlayer))
|
||||
{
|
||||
if (index != 0)
|
||||
extraText += "\n";
|
||||
extraText += info.TooltipText;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var textWidth = Math.Max(font.Measure(labelText).X, font.Measure(extraText).X);
|
||||
|
||||
if (textWidth != cachedWidth)
|
||||
{
|
||||
label.Bounds.Width = textWidth;
|
||||
@@ -86,9 +108,19 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
widget.Bounds.Height = doubleHeight;
|
||||
widget.Bounds.Width = Math.Max(widget.Bounds.Width,
|
||||
owner.Bounds.X + ownerFont.Measure(ownerName).X + label.Bounds.X);
|
||||
index++;
|
||||
}
|
||||
else
|
||||
widget.Bounds.Height = singleHeight;
|
||||
|
||||
if (extraText != "")
|
||||
{
|
||||
widget.Bounds.Height += font.Measure(extraText).Y + extras.Bounds.Height;
|
||||
if (showOwner)
|
||||
extras.Bounds.Y = extraHeightOnDouble;
|
||||
else
|
||||
extras.Bounds.Y = extraHeightOnSingle;
|
||||
}
|
||||
};
|
||||
|
||||
label.GetText = () => labelText;
|
||||
@@ -98,6 +130,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
owner.IsVisible = () => showOwner;
|
||||
owner.GetText = () => ownerName;
|
||||
owner.GetColor = () => ownerColor;
|
||||
extras.GetText = () => extraText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,11 @@ Background@WORLD_TOOLTIP:
|
||||
Y: 19
|
||||
Height: 23
|
||||
Font: Bold
|
||||
Label@EXTRA:
|
||||
X: 5
|
||||
Y: 45
|
||||
Height: 4
|
||||
Font: Bold
|
||||
|
||||
Background@PRODUCTION_TOOLTIP:
|
||||
Logic: ProductionTooltipLogic
|
||||
|
||||
@@ -49,6 +49,11 @@ Background@WORLD_TOOLTIP:
|
||||
Y: 25
|
||||
Height: 23
|
||||
Font: Bold
|
||||
Label@EXTRA:
|
||||
X: 7
|
||||
Y: 55
|
||||
Height: 4
|
||||
Font: Bold
|
||||
|
||||
Background@SPAWN_TOOLTIP:
|
||||
Logic: SpawnSelectorTooltipLogic
|
||||
|
||||
@@ -49,6 +49,11 @@ Background@WORLD_TOOLTIP:
|
||||
Y: 22
|
||||
Height: 23
|
||||
Font: Bold
|
||||
Label@EXTRA:
|
||||
X: 7
|
||||
Y: 48
|
||||
Height: 4
|
||||
Font: Bold
|
||||
|
||||
Background@SPAWN_TOOLTIP:
|
||||
Logic: SpawnSelectorTooltipLogic
|
||||
|
||||
Reference in New Issue
Block a user