Add button highlighting/glow effect, to be used for the objective button when the objectives update
This commit is contained in:
@@ -23,8 +23,10 @@ namespace OpenRA.Widgets
|
||||
public int VisualHeight = ChromeMetrics.Get<int>("ButtonDepth");
|
||||
public string Font = ChromeMetrics.Get<string>("ButtonFont");
|
||||
public bool Disabled = false;
|
||||
public bool Highlighted = false;
|
||||
public Func<string> GetText;
|
||||
public Func<bool> IsDisabled;
|
||||
public Func<bool> IsHighlighted;
|
||||
public Action<MouseInput> OnMouseDown = _ => {};
|
||||
public Action<MouseInput> OnMouseUp = _ => {};
|
||||
|
||||
@@ -39,6 +41,7 @@ namespace OpenRA.Widgets
|
||||
OnMouseUp = _ => OnClick();
|
||||
OnKeyPress = _ => OnClick();
|
||||
IsDisabled = () => Disabled;
|
||||
IsHighlighted = () => Highlighted;
|
||||
}
|
||||
|
||||
protected ButtonWidget(ButtonWidget widget)
|
||||
@@ -52,6 +55,8 @@ namespace OpenRA.Widgets
|
||||
OnMouseDown = widget.OnMouseDown;
|
||||
Disabled = widget.Disabled;
|
||||
IsDisabled = widget.IsDisabled;
|
||||
Highlighted = widget.Highlighted;
|
||||
IsHighlighted = widget.IsHighlighted;
|
||||
|
||||
OnMouseUp = mi => OnClick();
|
||||
OnKeyPress = _ => OnClick();
|
||||
@@ -124,13 +129,14 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
var rb = RenderBounds;
|
||||
var disabled = IsDisabled();
|
||||
var highlighted = IsHighlighted();
|
||||
|
||||
var font = Game.Renderer.Fonts[Font];
|
||||
var text = GetText();
|
||||
var s = font.Measure(text);
|
||||
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
|
||||
|
||||
DrawBackground(rb, disabled, Depressed, Ui.MouseOverWidget == this);
|
||||
DrawBackground(rb, disabled, Depressed, Ui.MouseOverWidget == this, highlighted);
|
||||
font.DrawText(text, new int2(rb.X + (UsableWidth - s.X)/ 2, rb.Y + (Bounds.Height - s.Y) / 2) + stateOffset,
|
||||
disabled ? Color.Gray : Color.White);
|
||||
}
|
||||
@@ -138,17 +144,19 @@ namespace OpenRA.Widgets
|
||||
public override Widget Clone() { return new ButtonWidget(this); }
|
||||
public virtual int UsableWidth { get { return Bounds.Width; } }
|
||||
|
||||
public virtual void DrawBackground(Rectangle rect, bool disabled, bool pressed, bool hover)
|
||||
public virtual void DrawBackground(Rectangle rect, bool disabled, bool pressed, bool hover, bool highlighted)
|
||||
{
|
||||
ButtonWidget.DrawBackground("button", rect, disabled, pressed, hover);
|
||||
ButtonWidget.DrawBackground("button", rect, disabled, pressed, hover, highlighted);
|
||||
}
|
||||
|
||||
public static void DrawBackground(string baseName, Rectangle rect, bool disabled, bool pressed, bool hover)
|
||||
public static void DrawBackground(string baseName, Rectangle rect, bool disabled, bool pressed, bool hover, bool highlighted)
|
||||
{
|
||||
var state = disabled ? "-disabled" :
|
||||
pressed ? "-pressed" :
|
||||
hover ? "-hover" :
|
||||
"";
|
||||
if (highlighted)
|
||||
state += "-highlighted";
|
||||
|
||||
WidgetUtils.DrawPanel(baseName + state, rect);
|
||||
}
|
||||
|
||||
@@ -79,11 +79,11 @@ namespace OpenRA.Widgets
|
||||
var thumbHover = Ui.MouseOverWidget == this && thumbRect.Contains(Viewport.LastMousePos);
|
||||
WidgetUtils.DrawPanel(Background, backgroundRect);
|
||||
WidgetUtils.DrawPanel("scrollpanel-bg", scrollbarRect);
|
||||
ButtonWidget.DrawBackground("button", upButtonRect, upDisabled, UpPressed, upHover);
|
||||
ButtonWidget.DrawBackground("button", downButtonRect, downDisabled, DownPressed, downHover);
|
||||
ButtonWidget.DrawBackground("button", upButtonRect, upDisabled, UpPressed, upHover, false);
|
||||
ButtonWidget.DrawBackground("button", downButtonRect, downDisabled, DownPressed, downHover, false);
|
||||
|
||||
if (thumbHeight > 0)
|
||||
ButtonWidget.DrawBackground("scrollthumb", thumbRect, false, Focused && thumbHover, thumbHover);
|
||||
ButtonWidget.DrawBackground("scrollthumb", thumbRect, false, Focused && thumbHover, thumbHover, false);
|
||||
|
||||
var upOffset = !UpPressed || upDisabled ? 4 : 4 + ButtonDepth;
|
||||
var downOffset = !DownPressed || downDisabled ? 4 : 4 + ButtonDepth;
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
// Thumb
|
||||
var thumbHover = Ui.MouseOverWidget == this && tr.Contains(Viewport.LastMousePos);
|
||||
ButtonWidget.DrawBackground("scrollthumb", tr, IsDisabled(), isMoving, thumbHover);
|
||||
ButtonWidget.DrawBackground("scrollthumb", tr, IsDisabled(), isMoving, thumbHover, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,8 +138,8 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
var rightHover = Ui.MouseOverWidget == this && rightButtonRect.Contains(Viewport.LastMousePos);
|
||||
|
||||
WidgetUtils.DrawPanel("panel-black", rb);
|
||||
ButtonWidget.DrawBackground("button", leftButtonRect, leftDisabled, leftPressed, leftHover);
|
||||
ButtonWidget.DrawBackground("button", rightButtonRect, rightDisabled, rightPressed, rightHover);
|
||||
ButtonWidget.DrawBackground("button", leftButtonRect, leftDisabled, leftPressed, leftHover, false);
|
||||
ButtonWidget.DrawBackground("button", rightButtonRect, rightDisabled, rightPressed, rightHover, false);
|
||||
|
||||
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", leftPressed || leftDisabled ? "left_pressed" : "left_arrow"),
|
||||
new float2(leftButtonRect.Left + 2, leftButtonRect.Top + 2));
|
||||
@@ -157,7 +157,7 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
var rect = new Rectangle(origin.X + ContentWidth, origin.Y, TabWidth, rb.Height);
|
||||
var hover = !leftHover && !rightHover && Ui.MouseOverWidget == this && rect.Contains(Viewport.LastMousePos);
|
||||
var baseName = tab.Queue == CurrentQueue ? "button-toggled" : "button";
|
||||
ButtonWidget.DrawBackground(baseName, rect, false, false, hover);
|
||||
ButtonWidget.DrawBackground(baseName, rect, false, false, hover, false);
|
||||
ContentWidth += TabWidth - 1;
|
||||
|
||||
int2 textSize = font.Measure(tab.Name);
|
||||
|
||||
@@ -53,10 +53,10 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
tooltipContainer.Value.RemoveTooltip();
|
||||
}
|
||||
|
||||
public override void DrawBackground(Rectangle rect, bool disabled, bool pressed, bool hover)
|
||||
public override void DrawBackground(Rectangle rect, bool disabled, bool pressed, bool hover, bool highlighted)
|
||||
{
|
||||
var baseName = IsToggled() ? "button-toggled" : "button";
|
||||
ButtonWidget.DrawBackground(baseName, rect, disabled, pressed, hover);
|
||||
ButtonWidget.DrawBackground(baseName, rect, disabled, pressed, hover, highlighted);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,10 +45,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
var objectivesButton = gameRoot.Get<ButtonWidget>("OBJECTIVES_BUTTON");
|
||||
var objectivesWidget = Game.LoadWidget(world, iop.ObjectivesPanel, Ui.Root, new WidgetArgs());
|
||||
objectivesWidget.Visible = false;
|
||||
objectivesButton.OnClick = () =>
|
||||
{
|
||||
objectivesWidget.Visible = !objectivesWidget.Visible;
|
||||
};
|
||||
objectivesButton.OnClick += () => objectivesWidget.Visible = !objectivesWidget.Visible;
|
||||
objectivesButton.IsVisible = () => world.LocalPlayer != null;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Missions;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
@@ -23,18 +22,26 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
Widget secondaryPanel;
|
||||
Widget primaryTemplate;
|
||||
Widget secondaryTemplate;
|
||||
ButtonWidget objectivesButton;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public MissionObjectivesLogic(World world, Widget widget)
|
||||
{
|
||||
var gameRoot = Ui.Root.Get("INGAME_ROOT");
|
||||
primaryPanel = widget.Get("PRIMARY_OBJECTIVES");
|
||||
secondaryPanel = widget.Get("SECONDARY_OBJECTIVES");
|
||||
primaryTemplate = primaryPanel.Get("PRIMARY_OBJECTIVE_TEMPLATE");
|
||||
secondaryTemplate = secondaryPanel.Get("SECONDARY_OBJECTIVE_TEMPLATE");
|
||||
|
||||
objectives = world.WorldActor.TraitsImplementing<IHasObjectives>().First();
|
||||
Game.ConnectionStateChanged += RemoveHandlers;
|
||||
|
||||
objectivesButton = gameRoot.Get<ButtonWidget>("OBJECTIVES_BUTTON");
|
||||
objectivesButton.IsHighlighted = () => Game.LocalTick % 60 <= 30 && objectivesButton.Highlighted;
|
||||
objectivesButton.OnClick += () => objectivesButton.Highlighted = false;
|
||||
|
||||
objectives.ObjectivesUpdated += UpdateObjectives;
|
||||
UpdateObjectives();
|
||||
Game.ConnectionStateChanged += RemoveHandlers;
|
||||
}
|
||||
|
||||
public void RemoveHandlers(OrderManager orderManager)
|
||||
@@ -48,6 +55,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
public void UpdateObjectives()
|
||||
{
|
||||
objectivesButton.Highlighted = true;
|
||||
primaryPanel.RemoveChildren();
|
||||
secondaryPanel.RemoveChildren();
|
||||
foreach (var o in objectives.Objectives.Where(o => o.Status != ObjectiveStatus.Inactive))
|
||||
|
||||
@@ -249,6 +249,17 @@ button: dialog.png
|
||||
corner-bl: 512,82,1,1
|
||||
corner-br: 594,82,1,1
|
||||
|
||||
button-highlighted: dialog.png
|
||||
background: 513,145,126,126
|
||||
border-r: 639,145,1,126
|
||||
border-l: 512,145,1,126
|
||||
border-b: 513,271,126,1
|
||||
border-t: 513,144,126,1
|
||||
corner-tl: 512,144,1,1
|
||||
corner-tr: 594,144,1,1
|
||||
corner-bl: 512,271,1,1
|
||||
corner-br: 594,271,1,1
|
||||
|
||||
# A copy of dialog2
|
||||
button-hover: dialog.png
|
||||
background: 513,1,126,126
|
||||
@@ -261,6 +272,17 @@ button-hover: dialog.png
|
||||
corner-bl: 512,82,1,1
|
||||
corner-br: 594,82,1,1
|
||||
|
||||
button-hover-highlighted: dialog.png
|
||||
background: 513,145,126,126
|
||||
border-r: 639,145,1,126
|
||||
border-l: 512,145,1,126
|
||||
border-b: 513,271,126,1
|
||||
border-t: 513,144,126,1
|
||||
corner-tl: 512,144,1,1
|
||||
corner-tr: 594,144,1,1
|
||||
corner-bl: 512,271,1,1
|
||||
corner-br: 594,271,1,1
|
||||
|
||||
# A copy of dialog2
|
||||
button-disabled: dialog.png
|
||||
background: 513,1,126,126
|
||||
@@ -273,6 +295,17 @@ button-disabled: dialog.png
|
||||
corner-bl: 512,82,1,1
|
||||
corner-br: 594,82,1,1
|
||||
|
||||
button-disabled-highlighted: dialog.png
|
||||
background: 513,145,126,126
|
||||
border-r: 639,145,1,126
|
||||
border-l: 512,145,1,126
|
||||
border-b: 513,271,126,1
|
||||
border-t: 513,144,126,1
|
||||
corner-tl: 512,144,1,1
|
||||
corner-tr: 594,144,1,1
|
||||
corner-bl: 512,271,1,1
|
||||
corner-br: 594,271,1,1
|
||||
|
||||
# A copy of dialog3
|
||||
button-pressed: dialog.png
|
||||
background: 641,1,126,126
|
||||
@@ -284,7 +317,18 @@ button-pressed: dialog.png
|
||||
corner-tr: 722,0,1,1
|
||||
corner-bl: 640,82,1,1
|
||||
corner-br: 722,82,1,1
|
||||
|
||||
|
||||
button-pressed-highlighted: dialog.png
|
||||
background: 641,145,126,126
|
||||
border-r: 767,145,1,126
|
||||
border-l: 640,145,1,126
|
||||
border-b: 641,271,126,1
|
||||
border-t: 641,144,126,1
|
||||
corner-tl: 640,144,1,1
|
||||
corner-tr: 722,144,1,1
|
||||
corner-bl: 640,271,1,1
|
||||
corner-br: 722,271,1,1
|
||||
|
||||
scrollthumb: dialog.png
|
||||
background: 513,1,126,126
|
||||
border-r: 639,1,1,126
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Reference in New Issue
Block a user