Added a MouseAttachmentWidget to render the Direction arrows in SelectDirectionalTarget
This commit is contained in:
@@ -13,7 +13,9 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Widgets;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
@@ -36,6 +38,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
bool activated;
|
||||
bool dragStarted;
|
||||
Arrow currentArrow;
|
||||
MouseAttachmentWidget mouseAttachment;
|
||||
|
||||
public SelectDirectionalTarget(World world, string order, SupportPowerManager manager, string cursor,
|
||||
string directionArrowAnimation, string directionArrowPalette)
|
||||
@@ -47,6 +50,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
this.directionArrowPalette = directionArrowPalette;
|
||||
|
||||
directionArrows = LoadArrows(directionArrowAnimation, world, arrows.Length);
|
||||
mouseAttachment = Ui.Root.Get<MouseAttachmentWidget>("MOUSE_ATTATCHMENT");
|
||||
}
|
||||
|
||||
IEnumerable<Order> IOrderGenerator.Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
@@ -82,6 +86,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
dragDirection = -MaxDragThreshold * float2.FromAngle((float)(angle * (Math.PI / 180)));
|
||||
|
||||
currentArrow = GetArrow(angle);
|
||||
|
||||
mouseAttachment.SetAttachment(targetLocation, currentArrow.Sprite, directionArrowPalette);
|
||||
dragStarted = true;
|
||||
}
|
||||
|
||||
@@ -111,19 +117,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
IEnumerable<IRenderable> IOrderGenerator.Render(WorldRenderer wr, World world) { yield break; }
|
||||
|
||||
IEnumerable<IRenderable> IOrderGenerator.RenderAboveShroud(WorldRenderer wr, World world)
|
||||
{
|
||||
if (!activated || !IsOutsideDragZone)
|
||||
yield break;
|
||||
|
||||
var worldPx = wr.Viewport.ViewToWorldPx(targetLocation);
|
||||
var worldPos = wr.ProjectedPosition(worldPx);
|
||||
|
||||
var scale = (Game.Cursor is SoftwareCursor && CursorProvider.CursorViewportZoomed ? 2 : 1) / wr.Viewport.Zoom;
|
||||
|
||||
var directionPalette = wr.Palette(directionArrowPalette);
|
||||
yield return new SpriteRenderable(currentArrow.Sprite, worldPos, WVec.Zero, -511, directionPalette, scale, true);
|
||||
}
|
||||
IEnumerable<IRenderable> IOrderGenerator.RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
||||
|
||||
string IOrderGenerator.GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return cursor; }
|
||||
|
||||
@@ -132,8 +126,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
void IOrderGenerator.Deactivate()
|
||||
{
|
||||
if (activated)
|
||||
{
|
||||
mouseAttachment.Reset();
|
||||
Game.Cursor.Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
// Starting at (0, -1) and rotating in CCW
|
||||
static double AngleOf(float2 delta)
|
||||
|
||||
57
OpenRA.Mods.Common/Widgets/MouseAttachmentWidget.cs
Normal file
57
OpenRA.Mods.Common/Widgets/MouseAttachmentWidget.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2019 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
public class MouseAttachmentWidget : Widget
|
||||
{
|
||||
public bool ClickThrough = true;
|
||||
|
||||
Sprite sprite;
|
||||
readonly WorldRenderer worldRenderer;
|
||||
string palette;
|
||||
int2 location;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public MouseAttachmentWidget(WorldRenderer worldRenderer)
|
||||
{
|
||||
this.worldRenderer = worldRenderer;
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
if (sprite != null && palette != null)
|
||||
{
|
||||
var scale = Game.Cursor is SoftwareCursor && CursorProvider.CursorViewportZoomed ? 2 : 1;
|
||||
var directionPalette = worldRenderer.Palette(palette);
|
||||
WidgetUtils.DrawSHPCentered(sprite, ChildOrigin, directionPalette, scale);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAttachment(int2 location, Sprite sprite, string palette)
|
||||
{
|
||||
this.sprite = sprite;
|
||||
this.location = location;
|
||||
this.palette = palette;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
sprite = null;
|
||||
palette = null;
|
||||
}
|
||||
|
||||
public override int2 ChildOrigin { get { return location; } }
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,7 @@ Container@INGAME_ROOT:
|
||||
Container@PLAYER_ROOT:
|
||||
Container@MENU_ROOT:
|
||||
TooltipContainer@TOOLTIP_CONTAINER:
|
||||
MouseAttachment@MOUSE_ATTATCHMENT:
|
||||
|
||||
Container@PERF_WIDGETS:
|
||||
Logic: PerfDebugLogic
|
||||
|
||||
@@ -60,3 +60,4 @@ Container@INGAME_ROOT:
|
||||
Container@PERF_ROOT:
|
||||
Container@MENU_ROOT:
|
||||
TooltipContainer@TOOLTIP_CONTAINER:
|
||||
MouseAttachment@MOUSE_ATTATCHMENT:
|
||||
|
||||
Reference in New Issue
Block a user