Update copyright header. Normalize line endings to LF.
This commit is contained in:
@@ -1,41 +1,41 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class BackgroundWidget : Widget
|
||||
{
|
||||
public readonly string Background = "dialog";
|
||||
public readonly bool ClickThrough = false;
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
WidgetUtils.DrawPanel(Background, RenderBounds);
|
||||
}
|
||||
|
||||
public BackgroundWidget() : base() { }
|
||||
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
return !ClickThrough;
|
||||
}
|
||||
|
||||
protected BackgroundWidget(BackgroundWidget other)
|
||||
: base(other)
|
||||
{
|
||||
Background = other.Background;
|
||||
ClickThrough = other.ClickThrough;
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new BackgroundWidget(this); }
|
||||
}
|
||||
#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.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class BackgroundWidget : Widget
|
||||
{
|
||||
public readonly string Background = "dialog";
|
||||
public readonly bool ClickThrough = false;
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
WidgetUtils.DrawPanel(Background, RenderBounds);
|
||||
}
|
||||
|
||||
public BackgroundWidget() : base() { }
|
||||
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
return !ClickThrough;
|
||||
}
|
||||
|
||||
protected BackgroundWidget(BackgroundWidget other)
|
||||
: base(other)
|
||||
{
|
||||
Background = other.Background;
|
||||
ClickThrough = other.ClickThrough;
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new BackgroundWidget(this); }
|
||||
}
|
||||
}
|
||||
@@ -1,195 +1,195 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class ButtonWidget : Widget
|
||||
{
|
||||
public string Text = "";
|
||||
public bool Bold = false;
|
||||
public bool Depressed = false;
|
||||
public int VisualHeight = 1;
|
||||
public Func<string> GetText;
|
||||
|
||||
public ButtonWidget()
|
||||
: base()
|
||||
{
|
||||
GetText = () => { return Text; };
|
||||
}
|
||||
|
||||
protected ButtonWidget(ButtonWidget widget)
|
||||
: base(widget)
|
||||
{
|
||||
Text = widget.Text;
|
||||
Depressed = widget.Depressed;
|
||||
VisualHeight = widget.VisualHeight;
|
||||
GetText = widget.GetText;
|
||||
}
|
||||
|
||||
public override bool LoseFocus(MouseInput mi)
|
||||
{
|
||||
Depressed = false;
|
||||
return base.LoseFocus(mi);
|
||||
}
|
||||
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
if (mi.Button != MouseButton.Left)
|
||||
return false;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||
return false;
|
||||
|
||||
// Only fire the onMouseUp order if we successfully lost focus, and were pressed
|
||||
if (Focused && mi.Event == MouseInputEvent.Up)
|
||||
{
|
||||
if (Depressed)
|
||||
OnMouseUp(mi);
|
||||
|
||||
return LoseFocus(mi);
|
||||
}
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down)
|
||||
{
|
||||
// OnMouseDown returns false if the button shouldn't be pressed
|
||||
if (!OnMouseDown(mi))
|
||||
Depressed = true;
|
||||
else
|
||||
LoseFocus(mi);
|
||||
}
|
||||
|
||||
else if (mi.Event == MouseInputEvent.Move && Focused)
|
||||
{
|
||||
Depressed = RenderBounds.Contains(mi.Location.X, mi.Location.Y);
|
||||
|
||||
// All widgets should recieve MouseMove events
|
||||
OnMouseMove(mi);
|
||||
}
|
||||
|
||||
return Depressed;
|
||||
}
|
||||
|
||||
public override int2 ChildOrigin { get { return RenderOrigin +
|
||||
((Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0)); } }
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
|
||||
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
|
||||
WidgetUtils.DrawPanel(Depressed ? "dialog3" : "dialog2", RenderBounds);
|
||||
|
||||
var text = GetText();
|
||||
|
||||
font.DrawText(text,
|
||||
new int2(RenderOrigin.X + UsableWidth / 2, RenderOrigin.Y + Bounds.Height / 2)
|
||||
- new int2(font.Measure(text).X / 2,
|
||||
font.Measure(text).Y / 2) + stateOffset, Color.White);
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new ButtonWidget(this); }
|
||||
public virtual int UsableWidth { get { return Bounds.Width; } }
|
||||
}
|
||||
|
||||
public class DropDownButtonWidget : ButtonWidget
|
||||
{
|
||||
public DropDownButtonWidget()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
protected DropDownButtonWidget(DropDownButtonWidget widget)
|
||||
: base(widget)
|
||||
{
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
base.DrawInner();
|
||||
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
|
||||
|
||||
var image = ChromeProvider.GetImage("scrollbar", "down_arrow");
|
||||
WidgetUtils.DrawRGBA( image,
|
||||
stateOffset + new float2( RenderBounds.Right - RenderBounds.Height + 4,
|
||||
RenderBounds.Top + (RenderBounds.Height - image.bounds.Height) / 2 ));
|
||||
|
||||
WidgetUtils.FillRectWithColor(new Rectangle(stateOffset.X + RenderBounds.Right - RenderBounds.Height,
|
||||
stateOffset.Y + RenderBounds.Top + 3, 1, RenderBounds.Height - 6),
|
||||
Color.White);
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new DropDownButtonWidget(this); }
|
||||
public override int UsableWidth { get { return Bounds.Width - Bounds.Height; } } /* space for button */
|
||||
|
||||
public static void ShowDropPanel(Widget w, Widget panel, IEnumerable<Widget> dismissAfter, Func<bool> onDismiss)
|
||||
{
|
||||
// Mask to prevent any clicks from being sent to other widgets
|
||||
var fullscreenMask = new ContainerWidget();
|
||||
fullscreenMask.Bounds = new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height);
|
||||
Widget.RootWidget.AddChild(fullscreenMask);
|
||||
|
||||
Action HideDropDown = () =>
|
||||
{
|
||||
Widget.RootWidget.RemoveChild(fullscreenMask);
|
||||
Widget.RootWidget.RemoveChild(panel);
|
||||
};
|
||||
|
||||
HideDropDown += () => Game.BeforeGameStart -= HideDropDown;
|
||||
Game.BeforeGameStart += HideDropDown;
|
||||
|
||||
fullscreenMask.OnMouseDown = mi =>
|
||||
{
|
||||
if (onDismiss()) HideDropDown();
|
||||
return true;
|
||||
};
|
||||
fullscreenMask.OnMouseUp = mi => true;
|
||||
|
||||
var oldBounds = panel.Bounds;
|
||||
panel.Bounds = new Rectangle(w.RenderOrigin.X, w.RenderOrigin.Y + w.Bounds.Height, oldBounds.Width, oldBounds.Height);
|
||||
panel.OnMouseUp = mi => true;
|
||||
|
||||
foreach (var ww in dismissAfter)
|
||||
{
|
||||
var origMouseUp = ww.OnMouseUp;
|
||||
ww.OnMouseUp = mi => { var result = origMouseUp(mi); if (onDismiss()) HideDropDown(); return result; };
|
||||
}
|
||||
Widget.RootWidget.AddChild(panel);
|
||||
}
|
||||
|
||||
public static void ShowDropDown<T>(Widget w, IEnumerable<T> ts, Func<T, int, LabelWidget> ft)
|
||||
{
|
||||
var dropDown = new ScrollPanelWidget();
|
||||
dropDown.Bounds = new Rectangle(w.RenderOrigin.X, w.RenderOrigin.Y + w.Bounds.Height, w.Bounds.Width, 100);
|
||||
dropDown.ItemSpacing = 1;
|
||||
|
||||
List<LabelWidget> items = new List<LabelWidget>();
|
||||
List<Widget> dismissAfter = new List<Widget>();
|
||||
foreach (var t in ts)
|
||||
{
|
||||
var ww = ft(t, dropDown.Bounds.Width - dropDown.ScrollbarWidth);
|
||||
dismissAfter.Add(ww);
|
||||
ww.OnMouseMove = mi => items.Do(lw =>
|
||||
{
|
||||
lw.Background = null; ww.Background = "dialog2";
|
||||
});
|
||||
|
||||
dropDown.AddChild(ww);
|
||||
items.Add(ww);
|
||||
}
|
||||
|
||||
dropDown.Bounds.Height = Math.Min(150, dropDown.ContentHeight);
|
||||
ShowDropPanel(w, dropDown, dismissAfter, () => true);
|
||||
}
|
||||
}
|
||||
#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;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class ButtonWidget : Widget
|
||||
{
|
||||
public string Text = "";
|
||||
public bool Bold = false;
|
||||
public bool Depressed = false;
|
||||
public int VisualHeight = 1;
|
||||
public Func<string> GetText;
|
||||
|
||||
public ButtonWidget()
|
||||
: base()
|
||||
{
|
||||
GetText = () => { return Text; };
|
||||
}
|
||||
|
||||
protected ButtonWidget(ButtonWidget widget)
|
||||
: base(widget)
|
||||
{
|
||||
Text = widget.Text;
|
||||
Depressed = widget.Depressed;
|
||||
VisualHeight = widget.VisualHeight;
|
||||
GetText = widget.GetText;
|
||||
}
|
||||
|
||||
public override bool LoseFocus(MouseInput mi)
|
||||
{
|
||||
Depressed = false;
|
||||
return base.LoseFocus(mi);
|
||||
}
|
||||
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
if (mi.Button != MouseButton.Left)
|
||||
return false;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||
return false;
|
||||
|
||||
// Only fire the onMouseUp order if we successfully lost focus, and were pressed
|
||||
if (Focused && mi.Event == MouseInputEvent.Up)
|
||||
{
|
||||
if (Depressed)
|
||||
OnMouseUp(mi);
|
||||
|
||||
return LoseFocus(mi);
|
||||
}
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down)
|
||||
{
|
||||
// OnMouseDown returns false if the button shouldn't be pressed
|
||||
if (!OnMouseDown(mi))
|
||||
Depressed = true;
|
||||
else
|
||||
LoseFocus(mi);
|
||||
}
|
||||
|
||||
else if (mi.Event == MouseInputEvent.Move && Focused)
|
||||
{
|
||||
Depressed = RenderBounds.Contains(mi.Location.X, mi.Location.Y);
|
||||
|
||||
// All widgets should recieve MouseMove events
|
||||
OnMouseMove(mi);
|
||||
}
|
||||
|
||||
return Depressed;
|
||||
}
|
||||
|
||||
public override int2 ChildOrigin { get { return RenderOrigin +
|
||||
((Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0)); } }
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
|
||||
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
|
||||
WidgetUtils.DrawPanel(Depressed ? "dialog3" : "dialog2", RenderBounds);
|
||||
|
||||
var text = GetText();
|
||||
|
||||
font.DrawText(text,
|
||||
new int2(RenderOrigin.X + UsableWidth / 2, RenderOrigin.Y + Bounds.Height / 2)
|
||||
- new int2(font.Measure(text).X / 2,
|
||||
font.Measure(text).Y / 2) + stateOffset, Color.White);
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new ButtonWidget(this); }
|
||||
public virtual int UsableWidth { get { return Bounds.Width; } }
|
||||
}
|
||||
|
||||
public class DropDownButtonWidget : ButtonWidget
|
||||
{
|
||||
public DropDownButtonWidget()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
protected DropDownButtonWidget(DropDownButtonWidget widget)
|
||||
: base(widget)
|
||||
{
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
base.DrawInner();
|
||||
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
|
||||
|
||||
var image = ChromeProvider.GetImage("scrollbar", "down_arrow");
|
||||
WidgetUtils.DrawRGBA( image,
|
||||
stateOffset + new float2( RenderBounds.Right - RenderBounds.Height + 4,
|
||||
RenderBounds.Top + (RenderBounds.Height - image.bounds.Height) / 2 ));
|
||||
|
||||
WidgetUtils.FillRectWithColor(new Rectangle(stateOffset.X + RenderBounds.Right - RenderBounds.Height,
|
||||
stateOffset.Y + RenderBounds.Top + 3, 1, RenderBounds.Height - 6),
|
||||
Color.White);
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new DropDownButtonWidget(this); }
|
||||
public override int UsableWidth { get { return Bounds.Width - Bounds.Height; } } /* space for button */
|
||||
|
||||
public static void ShowDropPanel(Widget w, Widget panel, IEnumerable<Widget> dismissAfter, Func<bool> onDismiss)
|
||||
{
|
||||
// Mask to prevent any clicks from being sent to other widgets
|
||||
var fullscreenMask = new ContainerWidget();
|
||||
fullscreenMask.Bounds = new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height);
|
||||
Widget.RootWidget.AddChild(fullscreenMask);
|
||||
|
||||
Action HideDropDown = () =>
|
||||
{
|
||||
Widget.RootWidget.RemoveChild(fullscreenMask);
|
||||
Widget.RootWidget.RemoveChild(panel);
|
||||
};
|
||||
|
||||
HideDropDown += () => Game.BeforeGameStart -= HideDropDown;
|
||||
Game.BeforeGameStart += HideDropDown;
|
||||
|
||||
fullscreenMask.OnMouseDown = mi =>
|
||||
{
|
||||
if (onDismiss()) HideDropDown();
|
||||
return true;
|
||||
};
|
||||
fullscreenMask.OnMouseUp = mi => true;
|
||||
|
||||
var oldBounds = panel.Bounds;
|
||||
panel.Bounds = new Rectangle(w.RenderOrigin.X, w.RenderOrigin.Y + w.Bounds.Height, oldBounds.Width, oldBounds.Height);
|
||||
panel.OnMouseUp = mi => true;
|
||||
|
||||
foreach (var ww in dismissAfter)
|
||||
{
|
||||
var origMouseUp = ww.OnMouseUp;
|
||||
ww.OnMouseUp = mi => { var result = origMouseUp(mi); if (onDismiss()) HideDropDown(); return result; };
|
||||
}
|
||||
Widget.RootWidget.AddChild(panel);
|
||||
}
|
||||
|
||||
public static void ShowDropDown<T>(Widget w, IEnumerable<T> ts, Func<T, int, LabelWidget> ft)
|
||||
{
|
||||
var dropDown = new ScrollPanelWidget();
|
||||
dropDown.Bounds = new Rectangle(w.RenderOrigin.X, w.RenderOrigin.Y + w.Bounds.Height, w.Bounds.Width, 100);
|
||||
dropDown.ItemSpacing = 1;
|
||||
|
||||
List<LabelWidget> items = new List<LabelWidget>();
|
||||
List<Widget> dismissAfter = new List<Widget>();
|
||||
foreach (var t in ts)
|
||||
{
|
||||
var ww = ft(t, dropDown.Bounds.Width - dropDown.ScrollbarWidth);
|
||||
dismissAfter.Add(ww);
|
||||
ww.OnMouseMove = mi => items.Do(lw =>
|
||||
{
|
||||
lw.Background = null; ww.Background = "dialog2";
|
||||
});
|
||||
|
||||
dropDown.AddChild(ww);
|
||||
items.Add(ww);
|
||||
}
|
||||
|
||||
dropDown.Bounds.Height = Math.Min(150, dropDown.ContentHeight);
|
||||
ShowDropPanel(w, dropDown, dismissAfter, () => true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,106 +1,106 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class ChatDisplayWidget : Widget
|
||||
{
|
||||
public readonly int RemoveTime = 0;
|
||||
public readonly bool UseContrast = false;
|
||||
|
||||
const int logLength = 9;
|
||||
public string Notification = "";
|
||||
public bool DrawBackground = true;
|
||||
int ticksUntilRemove = 0;
|
||||
|
||||
internal List<ChatLine> recentLines = new List<ChatLine>();
|
||||
|
||||
public ChatDisplayWidget()
|
||||
: base() { }
|
||||
|
||||
protected ChatDisplayWidget(Widget widget)
|
||||
: base(widget) { }
|
||||
|
||||
public override Rectangle EventBounds { get { return Rectangle.Empty; } }
|
||||
public override void DrawInner()
|
||||
{
|
||||
var pos = RenderOrigin;
|
||||
var chatLogArea = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
|
||||
var chatpos = new int2(chatLogArea.X + 10, chatLogArea.Bottom - 6);
|
||||
|
||||
if (DrawBackground)
|
||||
WidgetUtils.DrawPanel("dialog3", chatLogArea);
|
||||
|
||||
Game.Renderer.EnableScissor(chatLogArea.Left, chatLogArea.Top, chatLogArea.Width, chatLogArea.Height);
|
||||
foreach (var line in recentLines.AsEnumerable().Reverse())
|
||||
{
|
||||
chatpos.Y -= 20;
|
||||
int inset = 0;
|
||||
|
||||
if (!string.IsNullOrEmpty(line.Owner))
|
||||
{
|
||||
var owner = line.Owner + ":";
|
||||
inset = Game.Renderer.RegularFont.Measure(owner).X + 10;
|
||||
|
||||
Game.Renderer.RegularFont.DrawTextWithContrast(owner, chatpos,
|
||||
line.Color, Color.Black, UseContrast ? 1 : 0);
|
||||
}
|
||||
|
||||
Game.Renderer.RegularFont.DrawTextWithContrast(line.Text, chatpos + new int2(inset, 0),
|
||||
Color.White, Color.Black, UseContrast ? 1 : 0);
|
||||
}
|
||||
|
||||
Game.Renderer.DisableScissor();
|
||||
}
|
||||
|
||||
public void AddLine(Color c, string from, string text)
|
||||
{
|
||||
recentLines.Add(new ChatLine { Color = c, Owner = from, Text = text });
|
||||
ticksUntilRemove = RemoveTime;
|
||||
|
||||
if (Notification != null)
|
||||
Sound.Play(Notification);
|
||||
|
||||
while (recentLines.Count > logLength) recentLines.RemoveAt(0);
|
||||
}
|
||||
|
||||
public void RemoveLine()
|
||||
{
|
||||
if (recentLines.Count > 0) recentLines.RemoveAt(0);
|
||||
}
|
||||
|
||||
public void ClearChat()
|
||||
{
|
||||
recentLines = new List<ChatLine>();
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
if (RemoveTime == 0) return;
|
||||
if (--ticksUntilRemove > 0) return;
|
||||
ticksUntilRemove = RemoveTime;
|
||||
RemoveLine();
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new ChatDisplayWidget(this); }
|
||||
}
|
||||
|
||||
class ChatLine
|
||||
{
|
||||
public Color Color = Color.White;
|
||||
public string Owner, Text;
|
||||
public bool wrapped = false;
|
||||
}
|
||||
#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.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class ChatDisplayWidget : Widget
|
||||
{
|
||||
public readonly int RemoveTime = 0;
|
||||
public readonly bool UseContrast = false;
|
||||
|
||||
const int logLength = 9;
|
||||
public string Notification = "";
|
||||
public bool DrawBackground = true;
|
||||
int ticksUntilRemove = 0;
|
||||
|
||||
internal List<ChatLine> recentLines = new List<ChatLine>();
|
||||
|
||||
public ChatDisplayWidget()
|
||||
: base() { }
|
||||
|
||||
protected ChatDisplayWidget(Widget widget)
|
||||
: base(widget) { }
|
||||
|
||||
public override Rectangle EventBounds { get { return Rectangle.Empty; } }
|
||||
public override void DrawInner()
|
||||
{
|
||||
var pos = RenderOrigin;
|
||||
var chatLogArea = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
|
||||
var chatpos = new int2(chatLogArea.X + 10, chatLogArea.Bottom - 6);
|
||||
|
||||
if (DrawBackground)
|
||||
WidgetUtils.DrawPanel("dialog3", chatLogArea);
|
||||
|
||||
Game.Renderer.EnableScissor(chatLogArea.Left, chatLogArea.Top, chatLogArea.Width, chatLogArea.Height);
|
||||
foreach (var line in recentLines.AsEnumerable().Reverse())
|
||||
{
|
||||
chatpos.Y -= 20;
|
||||
int inset = 0;
|
||||
|
||||
if (!string.IsNullOrEmpty(line.Owner))
|
||||
{
|
||||
var owner = line.Owner + ":";
|
||||
inset = Game.Renderer.RegularFont.Measure(owner).X + 10;
|
||||
|
||||
Game.Renderer.RegularFont.DrawTextWithContrast(owner, chatpos,
|
||||
line.Color, Color.Black, UseContrast ? 1 : 0);
|
||||
}
|
||||
|
||||
Game.Renderer.RegularFont.DrawTextWithContrast(line.Text, chatpos + new int2(inset, 0),
|
||||
Color.White, Color.Black, UseContrast ? 1 : 0);
|
||||
}
|
||||
|
||||
Game.Renderer.DisableScissor();
|
||||
}
|
||||
|
||||
public void AddLine(Color c, string from, string text)
|
||||
{
|
||||
recentLines.Add(new ChatLine { Color = c, Owner = from, Text = text });
|
||||
ticksUntilRemove = RemoveTime;
|
||||
|
||||
if (Notification != null)
|
||||
Sound.Play(Notification);
|
||||
|
||||
while (recentLines.Count > logLength) recentLines.RemoveAt(0);
|
||||
}
|
||||
|
||||
public void RemoveLine()
|
||||
{
|
||||
if (recentLines.Count > 0) recentLines.RemoveAt(0);
|
||||
}
|
||||
|
||||
public void ClearChat()
|
||||
{
|
||||
recentLines = new List<ChatLine>();
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
if (RemoveTime == 0) return;
|
||||
if (--ticksUntilRemove > 0) return;
|
||||
ticksUntilRemove = RemoveTime;
|
||||
RemoveLine();
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new ChatDisplayWidget(this); }
|
||||
}
|
||||
|
||||
class ChatLine
|
||||
{
|
||||
public Color Color = Color.White;
|
||||
public string Owner, Text;
|
||||
public bool wrapped = false;
|
||||
}
|
||||
}
|
||||
@@ -1,115 +1,115 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Network;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
// a dirty hack of a widget, which likes to steal the focus when \r is pressed, and then
|
||||
// refuse to give it up until \r is pressed again.
|
||||
|
||||
// this emulates the previous chat support, with one improvement: shift+enter can toggle the
|
||||
// team/all mode *while* composing, not just on beginning to compose.
|
||||
|
||||
public class ChatEntryWidget : Widget
|
||||
{
|
||||
string content = "";
|
||||
bool composing = false;
|
||||
bool teamChat = false;
|
||||
public readonly bool UseContrast = false;
|
||||
|
||||
readonly OrderManager orderManager;
|
||||
[ObjectCreator.UseCtor]
|
||||
internal ChatEntryWidget( [ObjectCreator.Param] OrderManager orderManager )
|
||||
{
|
||||
this.orderManager = orderManager;
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
if (composing)
|
||||
{
|
||||
var text = teamChat ? "Chat (Team): " : "Chat (All): ";
|
||||
var w = Game.Renderer.BoldFont.Measure(text).X;
|
||||
|
||||
Game.Renderer.BoldFont.DrawTextWithContrast(text, RenderOrigin + new float2(3, 7), Color.White, Color.Black, UseContrast ? 1 : 0);
|
||||
Game.Renderer.RegularFont.DrawTextWithContrast(content, RenderOrigin + new float2(3 + w, 7), Color.White, Color.Black, UseContrast ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
public override Rectangle EventBounds { get { return Rectangle.Empty; } }
|
||||
public override bool LoseFocus(MouseInput mi)
|
||||
{
|
||||
return composing ? false : base.LoseFocus(mi);
|
||||
}
|
||||
|
||||
public override bool HandleKeyPressInner(KeyInput e)
|
||||
{
|
||||
if (e.Event == KeyInputEvent.Up) return false;
|
||||
|
||||
if (e.KeyChar == '\r')
|
||||
{
|
||||
if (composing)
|
||||
{
|
||||
if (e.Modifiers.HasModifier(Modifiers.Shift))
|
||||
{
|
||||
teamChat ^= true;
|
||||
return true;
|
||||
}
|
||||
|
||||
composing = false;
|
||||
if (content != "")
|
||||
orderManager.IssueOrder(teamChat
|
||||
? Order.TeamChat(content)
|
||||
: Order.Chat(content));
|
||||
content = "";
|
||||
|
||||
LoseFocus();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
TakeFocus(new MouseInput());
|
||||
composing = true;
|
||||
if (Game.Settings.Game.TeamChatToggle)
|
||||
{
|
||||
teamChat ^= e.Modifiers.HasModifier(Modifiers.Shift);
|
||||
}
|
||||
else
|
||||
{
|
||||
teamChat = e.Modifiers.HasModifier(Modifiers.Shift);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (composing)
|
||||
{
|
||||
if (e.KeyChar == '\b' || e.KeyChar == 0x7f)
|
||||
{
|
||||
if (content.Length > 0)
|
||||
content = content.Remove(content.Length - 1);
|
||||
return true;
|
||||
}
|
||||
else if (!char.IsControl(e.KeyChar))
|
||||
{
|
||||
content += e.KeyChar;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.HandleKeyPressInner(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
#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.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Network;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
// a dirty hack of a widget, which likes to steal the focus when \r is pressed, and then
|
||||
// refuse to give it up until \r is pressed again.
|
||||
|
||||
// this emulates the previous chat support, with one improvement: shift+enter can toggle the
|
||||
// team/all mode *while* composing, not just on beginning to compose.
|
||||
|
||||
public class ChatEntryWidget : Widget
|
||||
{
|
||||
string content = "";
|
||||
bool composing = false;
|
||||
bool teamChat = false;
|
||||
public readonly bool UseContrast = false;
|
||||
|
||||
readonly OrderManager orderManager;
|
||||
[ObjectCreator.UseCtor]
|
||||
internal ChatEntryWidget( [ObjectCreator.Param] OrderManager orderManager )
|
||||
{
|
||||
this.orderManager = orderManager;
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
if (composing)
|
||||
{
|
||||
var text = teamChat ? "Chat (Team): " : "Chat (All): ";
|
||||
var w = Game.Renderer.BoldFont.Measure(text).X;
|
||||
|
||||
Game.Renderer.BoldFont.DrawTextWithContrast(text, RenderOrigin + new float2(3, 7), Color.White, Color.Black, UseContrast ? 1 : 0);
|
||||
Game.Renderer.RegularFont.DrawTextWithContrast(content, RenderOrigin + new float2(3 + w, 7), Color.White, Color.Black, UseContrast ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
public override Rectangle EventBounds { get { return Rectangle.Empty; } }
|
||||
public override bool LoseFocus(MouseInput mi)
|
||||
{
|
||||
return composing ? false : base.LoseFocus(mi);
|
||||
}
|
||||
|
||||
public override bool HandleKeyPressInner(KeyInput e)
|
||||
{
|
||||
if (e.Event == KeyInputEvent.Up) return false;
|
||||
|
||||
if (e.KeyChar == '\r')
|
||||
{
|
||||
if (composing)
|
||||
{
|
||||
if (e.Modifiers.HasModifier(Modifiers.Shift))
|
||||
{
|
||||
teamChat ^= true;
|
||||
return true;
|
||||
}
|
||||
|
||||
composing = false;
|
||||
if (content != "")
|
||||
orderManager.IssueOrder(teamChat
|
||||
? Order.TeamChat(content)
|
||||
: Order.Chat(content));
|
||||
content = "";
|
||||
|
||||
LoseFocus();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
TakeFocus(new MouseInput());
|
||||
composing = true;
|
||||
if (Game.Settings.Game.TeamChatToggle)
|
||||
{
|
||||
teamChat ^= e.Modifiers.HasModifier(Modifiers.Shift);
|
||||
}
|
||||
else
|
||||
{
|
||||
teamChat = e.Modifiers.HasModifier(Modifiers.Shift);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (composing)
|
||||
{
|
||||
if (e.KeyChar == '\b' || e.KeyChar == 0x7f)
|
||||
{
|
||||
if (content.Length > 0)
|
||||
content = content.Remove(content.Length - 1);
|
||||
return true;
|
||||
}
|
||||
else if (!char.IsControl(e.KeyChar))
|
||||
{
|
||||
content += e.KeyChar;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.HandleKeyPressInner(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,88 +1,88 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using System.Reflection;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class CheckboxWidget : Widget
|
||||
{
|
||||
public string Text = "";
|
||||
public int baseLine = 1;
|
||||
public bool Bold = false;
|
||||
public Func<bool> IsChecked = () => false;
|
||||
public event Action<bool> OnChange = _ => {};
|
||||
|
||||
object boundObject;
|
||||
bool boundReadOnly;
|
||||
FieldInfo boundField;
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
var font = Bold ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
|
||||
var pos = RenderOrigin;
|
||||
var rect = RenderBounds;
|
||||
var check = new Rectangle(rect.Location,
|
||||
new Size(Bounds.Height, Bounds.Height));
|
||||
WidgetUtils.DrawPanel("dialog3", check);
|
||||
|
||||
var textSize = font.Measure(Text);
|
||||
font.DrawText(Text,
|
||||
new float2(rect.Left + rect.Height * 1.5f,
|
||||
pos.Y - baseLine + (Bounds.Height - textSize.Y)/2), Color.White);
|
||||
|
||||
if ((boundObject != null && (bool)boundField.GetValue(boundObject)) || IsChecked())
|
||||
WidgetUtils.DrawRGBA(
|
||||
ChromeProvider.GetImage("checkbox", "checked"),
|
||||
new float2(rect.Left + 2, rect.Top + 2));
|
||||
}
|
||||
|
||||
public void Bind(object obj, string field) { Bind(obj, field, false); }
|
||||
public void BindReadOnly(object obj, string field) { Bind(obj, field, true); }
|
||||
|
||||
void Bind(object obj, string field, bool readOnly)
|
||||
{
|
||||
boundObject = obj;
|
||||
boundReadOnly = readOnly;
|
||||
boundField = obj.GetType().GetField(field);
|
||||
}
|
||||
|
||||
// TODO: CheckboxWidget doesn't support delegate methods for mouse input
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
// Checkboxes require lmb
|
||||
if (mi.Button != MouseButton.Left || mi.Event != MouseInputEvent.Down)
|
||||
return false;
|
||||
|
||||
bool newVal = !IsChecked();
|
||||
if (boundObject != null && !boundReadOnly)
|
||||
{
|
||||
newVal = !(bool)boundField.GetValue(boundObject);
|
||||
boundField.SetValue(boundObject, newVal);
|
||||
}
|
||||
|
||||
OnChange(newVal);
|
||||
return true;
|
||||
}
|
||||
|
||||
public CheckboxWidget() : base() { }
|
||||
|
||||
protected CheckboxWidget(CheckboxWidget other)
|
||||
: base(other)
|
||||
{
|
||||
Text = other.Text;
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new CheckboxWidget(this); }
|
||||
}
|
||||
#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;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using System.Reflection;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class CheckboxWidget : Widget
|
||||
{
|
||||
public string Text = "";
|
||||
public int baseLine = 1;
|
||||
public bool Bold = false;
|
||||
public Func<bool> IsChecked = () => false;
|
||||
public event Action<bool> OnChange = _ => {};
|
||||
|
||||
object boundObject;
|
||||
bool boundReadOnly;
|
||||
FieldInfo boundField;
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
var font = Bold ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
|
||||
var pos = RenderOrigin;
|
||||
var rect = RenderBounds;
|
||||
var check = new Rectangle(rect.Location,
|
||||
new Size(Bounds.Height, Bounds.Height));
|
||||
WidgetUtils.DrawPanel("dialog3", check);
|
||||
|
||||
var textSize = font.Measure(Text);
|
||||
font.DrawText(Text,
|
||||
new float2(rect.Left + rect.Height * 1.5f,
|
||||
pos.Y - baseLine + (Bounds.Height - textSize.Y)/2), Color.White);
|
||||
|
||||
if ((boundObject != null && (bool)boundField.GetValue(boundObject)) || IsChecked())
|
||||
WidgetUtils.DrawRGBA(
|
||||
ChromeProvider.GetImage("checkbox", "checked"),
|
||||
new float2(rect.Left + 2, rect.Top + 2));
|
||||
}
|
||||
|
||||
public void Bind(object obj, string field) { Bind(obj, field, false); }
|
||||
public void BindReadOnly(object obj, string field) { Bind(obj, field, true); }
|
||||
|
||||
void Bind(object obj, string field, bool readOnly)
|
||||
{
|
||||
boundObject = obj;
|
||||
boundReadOnly = readOnly;
|
||||
boundField = obj.GetType().GetField(field);
|
||||
}
|
||||
|
||||
// TODO: CheckboxWidget doesn't support delegate methods for mouse input
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
// Checkboxes require lmb
|
||||
if (mi.Button != MouseButton.Left || mi.Event != MouseInputEvent.Down)
|
||||
return false;
|
||||
|
||||
bool newVal = !IsChecked();
|
||||
if (boundObject != null && !boundReadOnly)
|
||||
{
|
||||
newVal = !(bool)boundField.GetValue(boundObject);
|
||||
boundField.SetValue(boundObject, newVal);
|
||||
}
|
||||
|
||||
OnChange(newVal);
|
||||
return true;
|
||||
}
|
||||
|
||||
public CheckboxWidget() : base() { }
|
||||
|
||||
protected CheckboxWidget(CheckboxWidget other)
|
||||
: base(other)
|
||||
{
|
||||
Text = other.Text;
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new CheckboxWidget(this); }
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,43 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class ColorBlockWidget : Widget
|
||||
{
|
||||
public Func<Color> GetColor;
|
||||
|
||||
public ColorBlockWidget()
|
||||
: base()
|
||||
{
|
||||
GetColor = () => Color.White;
|
||||
}
|
||||
|
||||
protected ColorBlockWidget(ColorBlockWidget widget)
|
||||
: base(widget)
|
||||
{
|
||||
GetColor = widget.GetColor;
|
||||
}
|
||||
|
||||
public override Widget Clone()
|
||||
{
|
||||
return new ColorBlockWidget(this);
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
WidgetUtils.FillRectWithColor(RenderBounds, GetColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
#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;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class ColorBlockWidget : Widget
|
||||
{
|
||||
public Func<Color> GetColor;
|
||||
|
||||
public ColorBlockWidget()
|
||||
: base()
|
||||
{
|
||||
GetColor = () => Color.White;
|
||||
}
|
||||
|
||||
protected ColorBlockWidget(ColorBlockWidget widget)
|
||||
: base(widget)
|
||||
{
|
||||
GetColor = widget.GetColor;
|
||||
}
|
||||
|
||||
public override Widget Clone()
|
||||
{
|
||||
return new ColorBlockWidget(this);
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
WidgetUtils.FillRectWithColor(RenderBounds, GetColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +1,50 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class ImageWidget : Widget
|
||||
{
|
||||
public string ImageCollection = "";
|
||||
public string ImageName = "";
|
||||
public Func<string> GetImageName;
|
||||
public Func<string> GetImageCollection;
|
||||
|
||||
public ImageWidget()
|
||||
: base()
|
||||
{
|
||||
GetImageName = () => ImageName;
|
||||
GetImageCollection = () => ImageCollection;
|
||||
}
|
||||
|
||||
protected ImageWidget(ImageWidget other)
|
||||
: base(other)
|
||||
{
|
||||
ImageName = other.ImageName;
|
||||
GetImageName = other.GetImageName;
|
||||
ImageCollection = other.ImageCollection;
|
||||
GetImageCollection = other.GetImageCollection;
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new ImageWidget(this); }
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
var name = GetImageName();
|
||||
var collection = GetImageCollection();
|
||||
WidgetUtils.DrawRGBA(
|
||||
ChromeProvider.GetImage(collection, name),
|
||||
RenderOrigin);
|
||||
}
|
||||
}
|
||||
}
|
||||
#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;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class ImageWidget : Widget
|
||||
{
|
||||
public string ImageCollection = "";
|
||||
public string ImageName = "";
|
||||
public Func<string> GetImageName;
|
||||
public Func<string> GetImageCollection;
|
||||
|
||||
public ImageWidget()
|
||||
: base()
|
||||
{
|
||||
GetImageName = () => ImageName;
|
||||
GetImageCollection = () => ImageCollection;
|
||||
}
|
||||
|
||||
protected ImageWidget(ImageWidget other)
|
||||
: base(other)
|
||||
{
|
||||
ImageName = other.ImageName;
|
||||
GetImageName = other.GetImageName;
|
||||
ImageCollection = other.ImageCollection;
|
||||
GetImageCollection = other.GetImageCollection;
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new ImageWidget(this); }
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
var name = GetImageName();
|
||||
var collection = GetImageCollection();
|
||||
WidgetUtils.DrawRGBA(
|
||||
ChromeProvider.GetImage(collection, name),
|
||||
RenderOrigin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,132 +1,132 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class LabelWidget : Widget
|
||||
{
|
||||
public enum TextAlign { Left, Center, Right }
|
||||
public enum TextVAlign { Top, Middle, Bottom }
|
||||
|
||||
public string Text = null;
|
||||
public string Background = null;
|
||||
public TextAlign Align = TextAlign.Left;
|
||||
public TextVAlign VAlign = TextVAlign.Middle;
|
||||
public bool Bold = false;
|
||||
public bool WordWrap = false;
|
||||
public Func<string> GetText;
|
||||
public Func<string> GetBackground;
|
||||
|
||||
public LabelWidget()
|
||||
: base()
|
||||
{
|
||||
GetText = () => Text;
|
||||
GetBackground = () => Background;
|
||||
}
|
||||
|
||||
protected LabelWidget(LabelWidget other)
|
||||
: base(other)
|
||||
{
|
||||
Text = other.Text;
|
||||
Align = other.Align;
|
||||
Bold = other.Bold;
|
||||
GetText = other.GetText;
|
||||
GetBackground = other.GetBackground;
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
var bg = GetBackground();
|
||||
|
||||
if (bg != null)
|
||||
WidgetUtils.DrawPanel(bg, RenderBounds );
|
||||
|
||||
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
|
||||
var text = GetText();
|
||||
if (text == null)
|
||||
return;
|
||||
|
||||
int2 textSize = font.Measure(text);
|
||||
int2 position = RenderOrigin;
|
||||
|
||||
if (VAlign == TextVAlign.Middle)
|
||||
position += new int2(0, (Bounds.Height - textSize.Y)/2);
|
||||
|
||||
if (VAlign == TextVAlign.Bottom)
|
||||
position += new int2(0, Bounds.Height - textSize.Y);
|
||||
|
||||
if (Align == TextAlign.Center)
|
||||
position += new int2((Bounds.Width - textSize.X)/2, 0);
|
||||
|
||||
if (Align == TextAlign.Right)
|
||||
position += new int2(Bounds.Width - textSize.X,0);
|
||||
|
||||
if (WordWrap)
|
||||
{
|
||||
if (textSize.X > Bounds.Width)
|
||||
{
|
||||
string[] lines = text.Split('\n');
|
||||
List<string> newLines = new List<string>();
|
||||
int i = 0;
|
||||
string line = lines[i++];
|
||||
while (true)
|
||||
{
|
||||
newLines.Add(line);
|
||||
int2 m = font.Measure(line);
|
||||
int spaceIndex = 0, start = line.Length - 1;
|
||||
|
||||
if (m.X <= Bounds.Width)
|
||||
{
|
||||
if (i < lines.Length - 1)
|
||||
{
|
||||
line = lines[i++];
|
||||
continue;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
while (m.X > Bounds.Width)
|
||||
{
|
||||
if (-1 == (spaceIndex = line.LastIndexOf(' ', start)))
|
||||
break;
|
||||
start = spaceIndex - 1;
|
||||
m = font.Measure(line.Substring(0, spaceIndex));
|
||||
}
|
||||
|
||||
if (spaceIndex != -1)
|
||||
{
|
||||
newLines.RemoveAt(newLines.Count - 1);
|
||||
newLines.Add(line.Substring(0, spaceIndex));
|
||||
line = line.Substring(spaceIndex + 1);
|
||||
}
|
||||
else if (i < lines.Length - 1)
|
||||
{
|
||||
line = lines[i++];
|
||||
continue;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
text = string.Join("\n", newLines.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
font.DrawText(text, position, Color.White);
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new LabelWidget(this); }
|
||||
}
|
||||
#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;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class LabelWidget : Widget
|
||||
{
|
||||
public enum TextAlign { Left, Center, Right }
|
||||
public enum TextVAlign { Top, Middle, Bottom }
|
||||
|
||||
public string Text = null;
|
||||
public string Background = null;
|
||||
public TextAlign Align = TextAlign.Left;
|
||||
public TextVAlign VAlign = TextVAlign.Middle;
|
||||
public bool Bold = false;
|
||||
public bool WordWrap = false;
|
||||
public Func<string> GetText;
|
||||
public Func<string> GetBackground;
|
||||
|
||||
public LabelWidget()
|
||||
: base()
|
||||
{
|
||||
GetText = () => Text;
|
||||
GetBackground = () => Background;
|
||||
}
|
||||
|
||||
protected LabelWidget(LabelWidget other)
|
||||
: base(other)
|
||||
{
|
||||
Text = other.Text;
|
||||
Align = other.Align;
|
||||
Bold = other.Bold;
|
||||
GetText = other.GetText;
|
||||
GetBackground = other.GetBackground;
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
var bg = GetBackground();
|
||||
|
||||
if (bg != null)
|
||||
WidgetUtils.DrawPanel(bg, RenderBounds );
|
||||
|
||||
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
|
||||
var text = GetText();
|
||||
if (text == null)
|
||||
return;
|
||||
|
||||
int2 textSize = font.Measure(text);
|
||||
int2 position = RenderOrigin;
|
||||
|
||||
if (VAlign == TextVAlign.Middle)
|
||||
position += new int2(0, (Bounds.Height - textSize.Y)/2);
|
||||
|
||||
if (VAlign == TextVAlign.Bottom)
|
||||
position += new int2(0, Bounds.Height - textSize.Y);
|
||||
|
||||
if (Align == TextAlign.Center)
|
||||
position += new int2((Bounds.Width - textSize.X)/2, 0);
|
||||
|
||||
if (Align == TextAlign.Right)
|
||||
position += new int2(Bounds.Width - textSize.X,0);
|
||||
|
||||
if (WordWrap)
|
||||
{
|
||||
if (textSize.X > Bounds.Width)
|
||||
{
|
||||
string[] lines = text.Split('\n');
|
||||
List<string> newLines = new List<string>();
|
||||
int i = 0;
|
||||
string line = lines[i++];
|
||||
while (true)
|
||||
{
|
||||
newLines.Add(line);
|
||||
int2 m = font.Measure(line);
|
||||
int spaceIndex = 0, start = line.Length - 1;
|
||||
|
||||
if (m.X <= Bounds.Width)
|
||||
{
|
||||
if (i < lines.Length - 1)
|
||||
{
|
||||
line = lines[i++];
|
||||
continue;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
while (m.X > Bounds.Width)
|
||||
{
|
||||
if (-1 == (spaceIndex = line.LastIndexOf(' ', start)))
|
||||
break;
|
||||
start = spaceIndex - 1;
|
||||
m = font.Measure(line.Substring(0, spaceIndex));
|
||||
}
|
||||
|
||||
if (spaceIndex != -1)
|
||||
{
|
||||
newLines.RemoveAt(newLines.Count - 1);
|
||||
newLines.Add(line.Substring(0, spaceIndex));
|
||||
line = line.Substring(spaceIndex + 1);
|
||||
}
|
||||
else if (i < lines.Length - 1)
|
||||
{
|
||||
line = lines[i++];
|
||||
continue;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
text = string.Join("\n", newLines.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
font.DrawText(text, position, Color.White);
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new LabelWidget(this); }
|
||||
}
|
||||
}
|
||||
@@ -1,101 +1,101 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class MapPreviewWidget : Widget
|
||||
{
|
||||
public Func<Map> Map = () => null;
|
||||
public Func<Dictionary<int2, Color>> SpawnColors = () => new Dictionary<int2, Color>();
|
||||
static Cache<Map,Bitmap> PreviewCache = new Cache<Map, Bitmap>(stub => Minimap.RenderMapPreview( new Map( stub.Path )));
|
||||
|
||||
public MapPreviewWidget() : base() { }
|
||||
protected MapPreviewWidget(MapPreviewWidget other)
|
||||
: base(other)
|
||||
{
|
||||
lastMap = other.lastMap;
|
||||
Map = other.Map;
|
||||
SpawnColors = other.SpawnColors;
|
||||
}
|
||||
public override Widget Clone() { return new MapPreviewWidget(this); }
|
||||
|
||||
public int2 ConvertToPreview(Map map, int2 point)
|
||||
{
|
||||
return new int2(MapRect.X + (int)(PreviewScale*(point.X - map.Bounds.Left)) , MapRect.Y + (int)(PreviewScale*(point.Y - map.Bounds.Top)));
|
||||
}
|
||||
|
||||
Sheet mapChooserSheet;
|
||||
Sprite mapChooserSprite;
|
||||
Map lastMap;
|
||||
Rectangle MapRect;
|
||||
float PreviewScale = 0;
|
||||
static Sprite UnownedSpawn = null;
|
||||
static Sprite OwnedSpawn = null;
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
if (UnownedSpawn == null)
|
||||
UnownedSpawn = ChromeProvider.GetImage("spawnpoints", "unowned");
|
||||
if (OwnedSpawn == null)
|
||||
OwnedSpawn = ChromeProvider.GetImage("spawnpoints", "owned");
|
||||
|
||||
var map = Map();
|
||||
if( map == null ) return;
|
||||
|
||||
if (lastMap != map)
|
||||
{
|
||||
lastMap = map;
|
||||
|
||||
// Update image data
|
||||
var preview = PreviewCache[map];
|
||||
if( mapChooserSheet == null || mapChooserSheet.Size.Width != preview.Width || mapChooserSheet.Size.Height != preview.Height )
|
||||
mapChooserSheet = new Sheet(new Size( preview.Width, preview.Height ) );
|
||||
|
||||
mapChooserSheet.Texture.SetData( preview );
|
||||
mapChooserSprite = new Sprite( mapChooserSheet, new Rectangle( 0, 0, map.Bounds.Width, map.Bounds.Height ), TextureChannel.Alpha );
|
||||
|
||||
// Update map rect
|
||||
PreviewScale = Math.Min(RenderBounds.Width * 1.0f / map.Bounds.Width, RenderBounds.Height * 1.0f / map.Bounds.Height);
|
||||
var size = Math.Max(map.Bounds.Width, map.Bounds.Height);
|
||||
var dw = (int)(PreviewScale * (size - map.Bounds.Width)) / 2;
|
||||
var dh = (int)(PreviewScale * (size - map.Bounds.Height)) / 2;
|
||||
MapRect = new Rectangle(RenderBounds.X + dw, RenderBounds.Y + dh, (int)(map.Bounds.Width * PreviewScale), (int)(map.Bounds.Height * PreviewScale));
|
||||
}
|
||||
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite( mapChooserSprite,
|
||||
new float2(MapRect.Location),
|
||||
new float2( MapRect.Size ) );
|
||||
|
||||
// Overlay spawnpoints
|
||||
var colors = SpawnColors();
|
||||
foreach (var p in map.SpawnPoints)
|
||||
{
|
||||
var pos = ConvertToPreview(map, p);
|
||||
var sprite = UnownedSpawn;
|
||||
var offset = new int2(-UnownedSpawn.bounds.Width/2, -UnownedSpawn.bounds.Height/2);
|
||||
|
||||
if (colors.ContainsKey(p))
|
||||
{
|
||||
sprite = OwnedSpawn;
|
||||
offset = new int2(-OwnedSpawn.bounds.Width/2, -OwnedSpawn.bounds.Height/2);
|
||||
WidgetUtils.FillRectWithColor(new Rectangle(pos.X + offset.X + 2, pos.Y + offset.Y + 2, 12, 12), colors[p]);
|
||||
}
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(sprite, pos + offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#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;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class MapPreviewWidget : Widget
|
||||
{
|
||||
public Func<Map> Map = () => null;
|
||||
public Func<Dictionary<int2, Color>> SpawnColors = () => new Dictionary<int2, Color>();
|
||||
static Cache<Map,Bitmap> PreviewCache = new Cache<Map, Bitmap>(stub => Minimap.RenderMapPreview( new Map( stub.Path )));
|
||||
|
||||
public MapPreviewWidget() : base() { }
|
||||
protected MapPreviewWidget(MapPreviewWidget other)
|
||||
: base(other)
|
||||
{
|
||||
lastMap = other.lastMap;
|
||||
Map = other.Map;
|
||||
SpawnColors = other.SpawnColors;
|
||||
}
|
||||
public override Widget Clone() { return new MapPreviewWidget(this); }
|
||||
|
||||
public int2 ConvertToPreview(Map map, int2 point)
|
||||
{
|
||||
return new int2(MapRect.X + (int)(PreviewScale*(point.X - map.Bounds.Left)) , MapRect.Y + (int)(PreviewScale*(point.Y - map.Bounds.Top)));
|
||||
}
|
||||
|
||||
Sheet mapChooserSheet;
|
||||
Sprite mapChooserSprite;
|
||||
Map lastMap;
|
||||
Rectangle MapRect;
|
||||
float PreviewScale = 0;
|
||||
static Sprite UnownedSpawn = null;
|
||||
static Sprite OwnedSpawn = null;
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
if (UnownedSpawn == null)
|
||||
UnownedSpawn = ChromeProvider.GetImage("spawnpoints", "unowned");
|
||||
if (OwnedSpawn == null)
|
||||
OwnedSpawn = ChromeProvider.GetImage("spawnpoints", "owned");
|
||||
|
||||
var map = Map();
|
||||
if( map == null ) return;
|
||||
|
||||
if (lastMap != map)
|
||||
{
|
||||
lastMap = map;
|
||||
|
||||
// Update image data
|
||||
var preview = PreviewCache[map];
|
||||
if( mapChooserSheet == null || mapChooserSheet.Size.Width != preview.Width || mapChooserSheet.Size.Height != preview.Height )
|
||||
mapChooserSheet = new Sheet(new Size( preview.Width, preview.Height ) );
|
||||
|
||||
mapChooserSheet.Texture.SetData( preview );
|
||||
mapChooserSprite = new Sprite( mapChooserSheet, new Rectangle( 0, 0, map.Bounds.Width, map.Bounds.Height ), TextureChannel.Alpha );
|
||||
|
||||
// Update map rect
|
||||
PreviewScale = Math.Min(RenderBounds.Width * 1.0f / map.Bounds.Width, RenderBounds.Height * 1.0f / map.Bounds.Height);
|
||||
var size = Math.Max(map.Bounds.Width, map.Bounds.Height);
|
||||
var dw = (int)(PreviewScale * (size - map.Bounds.Width)) / 2;
|
||||
var dh = (int)(PreviewScale * (size - map.Bounds.Height)) / 2;
|
||||
MapRect = new Rectangle(RenderBounds.X + dw, RenderBounds.Y + dh, (int)(map.Bounds.Width * PreviewScale), (int)(map.Bounds.Height * PreviewScale));
|
||||
}
|
||||
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite( mapChooserSprite,
|
||||
new float2(MapRect.Location),
|
||||
new float2( MapRect.Size ) );
|
||||
|
||||
// Overlay spawnpoints
|
||||
var colors = SpawnColors();
|
||||
foreach (var p in map.SpawnPoints)
|
||||
{
|
||||
var pos = ConvertToPreview(map, p);
|
||||
var sprite = UnownedSpawn;
|
||||
var offset = new int2(-UnownedSpawn.bounds.Width/2, -UnownedSpawn.bounds.Height/2);
|
||||
|
||||
if (colors.ContainsKey(p))
|
||||
{
|
||||
sprite = OwnedSpawn;
|
||||
offset = new int2(-OwnedSpawn.bounds.Width/2, -OwnedSpawn.bounds.Height/2);
|
||||
WidgetUtils.FillRectWithColor(new Rectangle(pos.X + offset.X + 2, pos.Y + offset.Y + 2, 12, 12), colors[p]);
|
||||
}
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(sprite, pos + offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class PasswordFieldWidget : TextFieldWidget
|
||||
{
|
||||
public PasswordFieldWidget() : base() {}
|
||||
protected PasswordFieldWidget(PasswordFieldWidget widget) : base(widget) {}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
DrawWithString(new string('*', Text.Length));
|
||||
}
|
||||
public override Widget Clone() { return new PasswordFieldWidget(this); }
|
||||
}
|
||||
#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;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class PasswordFieldWidget : TextFieldWidget
|
||||
{
|
||||
public PasswordFieldWidget() : base() {}
|
||||
protected PasswordFieldWidget(PasswordFieldWidget widget) : base(widget) {}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
DrawWithString(new string('*', Text.Length));
|
||||
}
|
||||
public override Widget Clone() { return new PasswordFieldWidget(this); }
|
||||
}
|
||||
}
|
||||
@@ -1,63 +1,63 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Support;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class PerfGraphWidget : Widget
|
||||
{
|
||||
public PerfGraphWidget() : base() { }
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
var rect = RenderBounds;
|
||||
float2 origin = Game.viewport.Location + new float2(rect.Right, rect.Bottom);
|
||||
float2 basis = new float2(-rect.Width / 100, -rect.Height / 100);
|
||||
|
||||
Game.Renderer.LineRenderer.DrawLine(origin, origin + new float2(100, 0) * basis, Color.White, Color.White);
|
||||
Game.Renderer.LineRenderer.DrawLine(origin + new float2(100, 0) * basis, origin + new float2(100, 100) * basis, Color.White, Color.White);
|
||||
|
||||
int k = 0;
|
||||
foreach (var item in PerfHistory.items.Values)
|
||||
{
|
||||
int n = 0;
|
||||
item.Samples().Aggregate((a, b) =>
|
||||
{
|
||||
Game.Renderer.LineRenderer.DrawLine(
|
||||
origin + new float2(n, (float)a) * basis,
|
||||
origin + new float2(n + 1, (float)b) * basis,
|
||||
item.c, item.c);
|
||||
++n;
|
||||
return b;
|
||||
});
|
||||
|
||||
var u = Game.viewport.Location + new float2(rect.Left, rect.Top);
|
||||
|
||||
Game.Renderer.LineRenderer.DrawLine(
|
||||
u + new float2(10, 10 * k + 5),
|
||||
u + new float2(12, 10 * k + 5),
|
||||
item.c, item.c);
|
||||
|
||||
Game.Renderer.LineRenderer.DrawLine(
|
||||
u + new float2(10, 10 * k + 4),
|
||||
u + new float2(12, 10 * k + 4),
|
||||
item.c, item.c);
|
||||
|
||||
Game.Renderer.TinyFont.DrawText(item.Name, new float2(rect.Left, rect.Top) + new float2(18, 10 * k - 3), Color.White);
|
||||
Game.Renderer.Flush();
|
||||
++k;
|
||||
}
|
||||
}
|
||||
}
|
||||
#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.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Support;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class PerfGraphWidget : Widget
|
||||
{
|
||||
public PerfGraphWidget() : base() { }
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
var rect = RenderBounds;
|
||||
float2 origin = Game.viewport.Location + new float2(rect.Right, rect.Bottom);
|
||||
float2 basis = new float2(-rect.Width / 100, -rect.Height / 100);
|
||||
|
||||
Game.Renderer.LineRenderer.DrawLine(origin, origin + new float2(100, 0) * basis, Color.White, Color.White);
|
||||
Game.Renderer.LineRenderer.DrawLine(origin + new float2(100, 0) * basis, origin + new float2(100, 100) * basis, Color.White, Color.White);
|
||||
|
||||
int k = 0;
|
||||
foreach (var item in PerfHistory.items.Values)
|
||||
{
|
||||
int n = 0;
|
||||
item.Samples().Aggregate((a, b) =>
|
||||
{
|
||||
Game.Renderer.LineRenderer.DrawLine(
|
||||
origin + new float2(n, (float)a) * basis,
|
||||
origin + new float2(n + 1, (float)b) * basis,
|
||||
item.c, item.c);
|
||||
++n;
|
||||
return b;
|
||||
});
|
||||
|
||||
var u = Game.viewport.Location + new float2(rect.Left, rect.Top);
|
||||
|
||||
Game.Renderer.LineRenderer.DrawLine(
|
||||
u + new float2(10, 10 * k + 5),
|
||||
u + new float2(12, 10 * k + 5),
|
||||
item.c, item.c);
|
||||
|
||||
Game.Renderer.LineRenderer.DrawLine(
|
||||
u + new float2(10, 10 * k + 4),
|
||||
u + new float2(12, 10 * k + 4),
|
||||
item.c, item.c);
|
||||
|
||||
Game.Renderer.TinyFont.DrawText(item.Name, new float2(rect.Left, rect.Top) + new float2(18, 10 * k - 3), Color.White);
|
||||
Game.Renderer.Flush();
|
||||
++k;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,50 +1,50 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class ProgressBarWidget : Widget
|
||||
{
|
||||
public int Percentage = 0;
|
||||
public bool Indeterminate = false;
|
||||
int indeterminateTick = 0;
|
||||
|
||||
public ProgressBarWidget() : base() {}
|
||||
protected ProgressBarWidget(ProgressBarWidget widget)
|
||||
: base(widget)
|
||||
{
|
||||
Percentage = widget.Percentage;
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
WidgetUtils.DrawPanel("dialog3", RenderBounds);
|
||||
Rectangle barRect = Indeterminate ?
|
||||
new Rectangle(RenderBounds.X + 2 + (int)((RenderBounds.Width - 4)*(-Math.Cos(Math.PI*2*indeterminateTick/100) + 1)*3/8), RenderBounds.Y + 2, (RenderBounds.Width - 4) / 4, RenderBounds.Height - 4) :
|
||||
new Rectangle(RenderBounds.X + 2, RenderBounds.Y + 2, Percentage * (RenderBounds.Width - 4) / 100, RenderBounds.Height - 4);
|
||||
|
||||
if (barRect.Width > 0)
|
||||
WidgetUtils.DrawPanel("dialog2", barRect);
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
if (Indeterminate && indeterminateTick++ >= 100)
|
||||
indeterminateTick = 0;
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new ProgressBarWidget(this); }
|
||||
}
|
||||
#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;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class ProgressBarWidget : Widget
|
||||
{
|
||||
public int Percentage = 0;
|
||||
public bool Indeterminate = false;
|
||||
int indeterminateTick = 0;
|
||||
|
||||
public ProgressBarWidget() : base() {}
|
||||
protected ProgressBarWidget(ProgressBarWidget widget)
|
||||
: base(widget)
|
||||
{
|
||||
Percentage = widget.Percentage;
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
WidgetUtils.DrawPanel("dialog3", RenderBounds);
|
||||
Rectangle barRect = Indeterminate ?
|
||||
new Rectangle(RenderBounds.X + 2 + (int)((RenderBounds.Width - 4)*(-Math.Cos(Math.PI*2*indeterminateTick/100) + 1)*3/8), RenderBounds.Y + 2, (RenderBounds.Width - 4) / 4, RenderBounds.Height - 4) :
|
||||
new Rectangle(RenderBounds.X + 2, RenderBounds.Y + 2, Percentage * (RenderBounds.Width - 4) / 100, RenderBounds.Height - 4);
|
||||
|
||||
if (barRect.Width > 0)
|
||||
WidgetUtils.DrawPanel("dialog2", barRect);
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
if (Indeterminate && indeterminateTick++ >= 100)
|
||||
indeterminateTick = 0;
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new ProgressBarWidget(this); }
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* 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 LICENSE.
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -1,126 +1,126 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class ScrollingTextWidget : Widget
|
||||
{
|
||||
public string Text = "";
|
||||
private string ScrollingText = "";
|
||||
|
||||
public string Background = null;
|
||||
|
||||
public bool Bold = false;
|
||||
|
||||
public int ScrollLength = 200;
|
||||
|
||||
// ticks per single letter scroll
|
||||
public int ScrollRate = 4;
|
||||
|
||||
private string ScrollBuffer = "";
|
||||
|
||||
private int ScrollLocation = 0;
|
||||
private int ScrollTick = 0;
|
||||
|
||||
public Func<string> GetText;
|
||||
public Func<string> GetBackground;
|
||||
|
||||
public ScrollingTextWidget()
|
||||
: base()
|
||||
{
|
||||
GetText = () => Text;
|
||||
GetBackground = () => Background;
|
||||
}
|
||||
|
||||
protected ScrollingTextWidget(ScrollingTextWidget other)
|
||||
: base(other)
|
||||
{
|
||||
Text = other.Text;
|
||||
GetText = other.GetText;
|
||||
Bold = other.Bold;
|
||||
GetBackground = other.GetBackground;
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
if (Text != "")
|
||||
{
|
||||
ScrollingText = Text;
|
||||
Text = "";
|
||||
}
|
||||
UpdateScrollBuffer();
|
||||
}
|
||||
|
||||
public void ResetScroll()
|
||||
{
|
||||
ScrollLocation = 0;
|
||||
ScrollTick = 0;
|
||||
}
|
||||
|
||||
private void UpdateScrollBuffer()
|
||||
{
|
||||
ScrollTick++;
|
||||
|
||||
if (ScrollTick < ScrollRate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ScrollTick = 0;
|
||||
ScrollBuffer = "";
|
||||
|
||||
if (ScrollingText.Substring(ScrollingText.Length - 4, 3) != " ")
|
||||
{
|
||||
ScrollingText += " ";
|
||||
}
|
||||
|
||||
int tempScrollLocation = ScrollLocation;
|
||||
for (int i = 0; i < ScrollLength; ++i)
|
||||
{
|
||||
ScrollBuffer += ScrollingText.Substring(tempScrollLocation, 1);
|
||||
tempScrollLocation = (tempScrollLocation + 1) % ScrollingText.Length;
|
||||
}
|
||||
|
||||
ScrollLocation = (ScrollLocation + 1) % ScrollingText.Length;
|
||||
}
|
||||
|
||||
public void SetText(string newText)
|
||||
{
|
||||
Text = newText.Replace("\n", " ");
|
||||
Text = Text.Replace("\r", "");
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
var bg = GetBackground();
|
||||
|
||||
if (bg != null)
|
||||
WidgetUtils.DrawPanel(bg, RenderBounds);
|
||||
|
||||
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
|
||||
var text = GetText();
|
||||
if (text == null)
|
||||
return;
|
||||
|
||||
int2 textSize = font.Measure(text);
|
||||
int2 position = RenderOrigin + new int2(0, (Bounds.Height - textSize.Y) / 2);
|
||||
|
||||
Game.Renderer.EnableScissor(position.X, position.Y, Bounds.Width, Bounds.Height);
|
||||
font.DrawText(ScrollBuffer, position, Color.White);
|
||||
Game.Renderer.DisableScissor();
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new ScrollingTextWidget(this); }
|
||||
}
|
||||
}
|
||||
#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;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class ScrollingTextWidget : Widget
|
||||
{
|
||||
public string Text = "";
|
||||
private string ScrollingText = "";
|
||||
|
||||
public string Background = null;
|
||||
|
||||
public bool Bold = false;
|
||||
|
||||
public int ScrollLength = 200;
|
||||
|
||||
// ticks per single letter scroll
|
||||
public int ScrollRate = 4;
|
||||
|
||||
private string ScrollBuffer = "";
|
||||
|
||||
private int ScrollLocation = 0;
|
||||
private int ScrollTick = 0;
|
||||
|
||||
public Func<string> GetText;
|
||||
public Func<string> GetBackground;
|
||||
|
||||
public ScrollingTextWidget()
|
||||
: base()
|
||||
{
|
||||
GetText = () => Text;
|
||||
GetBackground = () => Background;
|
||||
}
|
||||
|
||||
protected ScrollingTextWidget(ScrollingTextWidget other)
|
||||
: base(other)
|
||||
{
|
||||
Text = other.Text;
|
||||
GetText = other.GetText;
|
||||
Bold = other.Bold;
|
||||
GetBackground = other.GetBackground;
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
if (Text != "")
|
||||
{
|
||||
ScrollingText = Text;
|
||||
Text = "";
|
||||
}
|
||||
UpdateScrollBuffer();
|
||||
}
|
||||
|
||||
public void ResetScroll()
|
||||
{
|
||||
ScrollLocation = 0;
|
||||
ScrollTick = 0;
|
||||
}
|
||||
|
||||
private void UpdateScrollBuffer()
|
||||
{
|
||||
ScrollTick++;
|
||||
|
||||
if (ScrollTick < ScrollRate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ScrollTick = 0;
|
||||
ScrollBuffer = "";
|
||||
|
||||
if (ScrollingText.Substring(ScrollingText.Length - 4, 3) != " ")
|
||||
{
|
||||
ScrollingText += " ";
|
||||
}
|
||||
|
||||
int tempScrollLocation = ScrollLocation;
|
||||
for (int i = 0; i < ScrollLength; ++i)
|
||||
{
|
||||
ScrollBuffer += ScrollingText.Substring(tempScrollLocation, 1);
|
||||
tempScrollLocation = (tempScrollLocation + 1) % ScrollingText.Length;
|
||||
}
|
||||
|
||||
ScrollLocation = (ScrollLocation + 1) % ScrollingText.Length;
|
||||
}
|
||||
|
||||
public void SetText(string newText)
|
||||
{
|
||||
Text = newText.Replace("\n", " ");
|
||||
Text = Text.Replace("\r", "");
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
var bg = GetBackground();
|
||||
|
||||
if (bg != null)
|
||||
WidgetUtils.DrawPanel(bg, RenderBounds);
|
||||
|
||||
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
|
||||
var text = GetText();
|
||||
if (text == null)
|
||||
return;
|
||||
|
||||
int2 textSize = font.Measure(text);
|
||||
int2 position = RenderOrigin + new int2(0, (Bounds.Height - textSize.Y) / 2);
|
||||
|
||||
Game.Renderer.EnableScissor(position.X, position.Y, Bounds.Width, Bounds.Height);
|
||||
font.DrawText(ScrollBuffer, position, Color.White);
|
||||
Game.Renderer.DisableScissor();
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new ScrollingTextWidget(this); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#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;
|
||||
@@ -22,15 +22,15 @@ namespace OpenRA.Widgets
|
||||
public Func<string> GetImage;
|
||||
public Func<int> GetFrame;
|
||||
public Func<string> GetPalette;
|
||||
|
||||
readonly WorldRenderer worldRenderer;
|
||||
[ObjectCreator.UseCtor]
|
||||
|
||||
readonly WorldRenderer worldRenderer;
|
||||
[ObjectCreator.UseCtor]
|
||||
public ShpImageWidget([ObjectCreator.Param] WorldRenderer worldRenderer)
|
||||
: base()
|
||||
{
|
||||
GetImage = () => { return Image; };
|
||||
GetFrame = () => { return Frame; };
|
||||
GetPalette = () => { return Palette; };
|
||||
GetPalette = () => { return Palette; };
|
||||
this.worldRenderer = worldRenderer;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace OpenRA.Widgets
|
||||
Palette = other.Palette;
|
||||
GetImage = other.GetImage;
|
||||
GetFrame = other.GetFrame;
|
||||
GetPalette = other.GetPalette;
|
||||
GetPalette = other.GetPalette;
|
||||
worldRenderer = other.worldRenderer;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,197 +1,197 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class SliderWidget : Widget
|
||||
{
|
||||
public event Action<float> OnChange;
|
||||
public Func<float> GetOffset;
|
||||
public int Ticks = 0;
|
||||
public int TrackHeight = 5;
|
||||
public float2 Range = new float2(0f, 1f);
|
||||
|
||||
private float Offset = 0;
|
||||
|
||||
int2 lastMouseLocation;
|
||||
bool isMoving = false;
|
||||
|
||||
public SliderWidget()
|
||||
: base()
|
||||
{
|
||||
GetOffset = () =>
|
||||
{
|
||||
var Big = Math.Max(Range.X, Range.Y);
|
||||
var Little = Math.Min(Range.X, Range.Y);
|
||||
var Spread = Big - Little;
|
||||
|
||||
return Spread * Offset + Little;
|
||||
};
|
||||
OnChange = x => Offset = x.Clamp(0f, 1f);
|
||||
}
|
||||
|
||||
public SliderWidget(SliderWidget other)
|
||||
: base(other)
|
||||
{
|
||||
OnChange = other.OnChange;
|
||||
GetOffset = other.GetOffset;
|
||||
Ticks = other.Ticks;
|
||||
Range = other.Range;
|
||||
Offset = GetOffset();
|
||||
TrackHeight = other.TrackHeight;
|
||||
lastMouseLocation = other.lastMouseLocation;
|
||||
isMoving = other.isMoving;
|
||||
}
|
||||
|
||||
public void SetOffset(float newOffset)
|
||||
{
|
||||
var Big = Math.Max(Range.X, Range.Y);
|
||||
var Little = Math.Min(Range.X, Range.Y);
|
||||
var Spread = Big - Little;
|
||||
|
||||
Offset = ((newOffset - Little) / Spread).Clamp(0f, 1f);
|
||||
}
|
||||
|
||||
// TODO: SliderWidget doesn't support delegate methods for mouse input
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
if (mi.Button != MouseButton.Left)
|
||||
return false;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||
return false;
|
||||
|
||||
if (!Focused)
|
||||
return false;
|
||||
|
||||
switch (mi.Event)
|
||||
{
|
||||
case MouseInputEvent.Up:
|
||||
{
|
||||
if (Focused)
|
||||
{
|
||||
isMoving = false;
|
||||
base.LoseFocus(mi);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MouseInputEvent.Down:
|
||||
{
|
||||
if (thumbRect.Contains(mi.Location))
|
||||
{
|
||||
isMoving = true;
|
||||
lastMouseLocation = mi.Location;
|
||||
}
|
||||
else if (Ticks != 0)
|
||||
{
|
||||
var pos = Offset;
|
||||
|
||||
// Offset slightly the direction we want to move so we don't get stuck on a tick
|
||||
var delta = 0.001;
|
||||
var targetTick = (float)((mi.Location.X > thumbRect.Right) ? Math.Ceiling((pos + delta) * (Ticks - 1))
|
||||
: Math.Floor((pos - delta) * (Ticks - 1)));
|
||||
OnChange(targetTick / (Ticks - 1));
|
||||
|
||||
if (thumbRect.Contains(mi.Location))
|
||||
{
|
||||
isMoving = true;
|
||||
lastMouseLocation = mi.Location;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else // No ticks; move to the mouse position
|
||||
{
|
||||
var thumb = thumbRect;
|
||||
var center = thumb.X + thumb.Width / 2;
|
||||
var newOffset = OffsetBy((mi.Location.X - center) * 1f / (RenderBounds.Width - thumb.Width));
|
||||
if (newOffset != Offset)
|
||||
{
|
||||
OnChange(newOffset);
|
||||
|
||||
if (thumbRect.Contains(mi.Location))
|
||||
{
|
||||
isMoving = true;
|
||||
lastMouseLocation = mi.Location;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MouseInputEvent.Move:
|
||||
{
|
||||
if ((mi.Location.X != lastMouseLocation.X) && isMoving)
|
||||
{
|
||||
var newOffset = OffsetBy((mi.Location.X - lastMouseLocation.X) * 1f / (RenderBounds.Width - thumbRect.Width));
|
||||
if (newOffset != Offset)
|
||||
{
|
||||
lastMouseLocation = mi.Location;
|
||||
OnChange(newOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return thumbRect.Contains(mi.Location.X, mi.Location.Y);
|
||||
}
|
||||
|
||||
float OffsetBy(float amount)
|
||||
{
|
||||
var centerPos = Offset + amount;
|
||||
if (centerPos < 0) centerPos = 0;
|
||||
if (centerPos > 1) centerPos = 1;
|
||||
return centerPos;
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new SliderWidget(this); }
|
||||
|
||||
Rectangle thumbRect
|
||||
{
|
||||
get
|
||||
{
|
||||
var width = RenderBounds.Height;
|
||||
var height = RenderBounds.Height;
|
||||
var origin = (int)((RenderBounds.X + width / 2) + Offset * (RenderBounds.Width - width) - width / 2f);
|
||||
return new Rectangle(origin, RenderBounds.Y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
if (!IsVisible())
|
||||
return;
|
||||
|
||||
var trackWidth = RenderBounds.Width - thumbRect.Width;
|
||||
var trackOrigin = RenderBounds.X + thumbRect.Width / 2;
|
||||
var trackRect = new Rectangle(trackOrigin - 1, RenderBounds.Y + (RenderBounds.Height - TrackHeight) / 2, trackWidth + 2, TrackHeight);
|
||||
|
||||
// Tickmarks (hacked until we have real art)
|
||||
for (int i = 0; i < Ticks; i++)
|
||||
{
|
||||
var tickRect = new Rectangle(trackOrigin - 1 + (int)(i * trackWidth * 1f / (Ticks - 1)),
|
||||
RenderBounds.Y + RenderBounds.Height / 2, 2, RenderBounds.Height / 2);
|
||||
WidgetUtils.DrawPanel("dialog2", tickRect);
|
||||
}
|
||||
// Track
|
||||
WidgetUtils.DrawPanel("dialog3", trackRect);
|
||||
|
||||
// Thumb
|
||||
WidgetUtils.DrawPanel("dialog2", thumbRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#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;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class SliderWidget : Widget
|
||||
{
|
||||
public event Action<float> OnChange;
|
||||
public Func<float> GetOffset;
|
||||
public int Ticks = 0;
|
||||
public int TrackHeight = 5;
|
||||
public float2 Range = new float2(0f, 1f);
|
||||
|
||||
private float Offset = 0;
|
||||
|
||||
int2 lastMouseLocation;
|
||||
bool isMoving = false;
|
||||
|
||||
public SliderWidget()
|
||||
: base()
|
||||
{
|
||||
GetOffset = () =>
|
||||
{
|
||||
var Big = Math.Max(Range.X, Range.Y);
|
||||
var Little = Math.Min(Range.X, Range.Y);
|
||||
var Spread = Big - Little;
|
||||
|
||||
return Spread * Offset + Little;
|
||||
};
|
||||
OnChange = x => Offset = x.Clamp(0f, 1f);
|
||||
}
|
||||
|
||||
public SliderWidget(SliderWidget other)
|
||||
: base(other)
|
||||
{
|
||||
OnChange = other.OnChange;
|
||||
GetOffset = other.GetOffset;
|
||||
Ticks = other.Ticks;
|
||||
Range = other.Range;
|
||||
Offset = GetOffset();
|
||||
TrackHeight = other.TrackHeight;
|
||||
lastMouseLocation = other.lastMouseLocation;
|
||||
isMoving = other.isMoving;
|
||||
}
|
||||
|
||||
public void SetOffset(float newOffset)
|
||||
{
|
||||
var Big = Math.Max(Range.X, Range.Y);
|
||||
var Little = Math.Min(Range.X, Range.Y);
|
||||
var Spread = Big - Little;
|
||||
|
||||
Offset = ((newOffset - Little) / Spread).Clamp(0f, 1f);
|
||||
}
|
||||
|
||||
// TODO: SliderWidget doesn't support delegate methods for mouse input
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
if (mi.Button != MouseButton.Left)
|
||||
return false;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||
return false;
|
||||
|
||||
if (!Focused)
|
||||
return false;
|
||||
|
||||
switch (mi.Event)
|
||||
{
|
||||
case MouseInputEvent.Up:
|
||||
{
|
||||
if (Focused)
|
||||
{
|
||||
isMoving = false;
|
||||
base.LoseFocus(mi);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MouseInputEvent.Down:
|
||||
{
|
||||
if (thumbRect.Contains(mi.Location))
|
||||
{
|
||||
isMoving = true;
|
||||
lastMouseLocation = mi.Location;
|
||||
}
|
||||
else if (Ticks != 0)
|
||||
{
|
||||
var pos = Offset;
|
||||
|
||||
// Offset slightly the direction we want to move so we don't get stuck on a tick
|
||||
var delta = 0.001;
|
||||
var targetTick = (float)((mi.Location.X > thumbRect.Right) ? Math.Ceiling((pos + delta) * (Ticks - 1))
|
||||
: Math.Floor((pos - delta) * (Ticks - 1)));
|
||||
OnChange(targetTick / (Ticks - 1));
|
||||
|
||||
if (thumbRect.Contains(mi.Location))
|
||||
{
|
||||
isMoving = true;
|
||||
lastMouseLocation = mi.Location;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else // No ticks; move to the mouse position
|
||||
{
|
||||
var thumb = thumbRect;
|
||||
var center = thumb.X + thumb.Width / 2;
|
||||
var newOffset = OffsetBy((mi.Location.X - center) * 1f / (RenderBounds.Width - thumb.Width));
|
||||
if (newOffset != Offset)
|
||||
{
|
||||
OnChange(newOffset);
|
||||
|
||||
if (thumbRect.Contains(mi.Location))
|
||||
{
|
||||
isMoving = true;
|
||||
lastMouseLocation = mi.Location;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MouseInputEvent.Move:
|
||||
{
|
||||
if ((mi.Location.X != lastMouseLocation.X) && isMoving)
|
||||
{
|
||||
var newOffset = OffsetBy((mi.Location.X - lastMouseLocation.X) * 1f / (RenderBounds.Width - thumbRect.Width));
|
||||
if (newOffset != Offset)
|
||||
{
|
||||
lastMouseLocation = mi.Location;
|
||||
OnChange(newOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return thumbRect.Contains(mi.Location.X, mi.Location.Y);
|
||||
}
|
||||
|
||||
float OffsetBy(float amount)
|
||||
{
|
||||
var centerPos = Offset + amount;
|
||||
if (centerPos < 0) centerPos = 0;
|
||||
if (centerPos > 1) centerPos = 1;
|
||||
return centerPos;
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new SliderWidget(this); }
|
||||
|
||||
Rectangle thumbRect
|
||||
{
|
||||
get
|
||||
{
|
||||
var width = RenderBounds.Height;
|
||||
var height = RenderBounds.Height;
|
||||
var origin = (int)((RenderBounds.X + width / 2) + Offset * (RenderBounds.Width - width) - width / 2f);
|
||||
return new Rectangle(origin, RenderBounds.Y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
if (!IsVisible())
|
||||
return;
|
||||
|
||||
var trackWidth = RenderBounds.Width - thumbRect.Width;
|
||||
var trackOrigin = RenderBounds.X + thumbRect.Width / 2;
|
||||
var trackRect = new Rectangle(trackOrigin - 1, RenderBounds.Y + (RenderBounds.Height - TrackHeight) / 2, trackWidth + 2, TrackHeight);
|
||||
|
||||
// Tickmarks (hacked until we have real art)
|
||||
for (int i = 0; i < Ticks; i++)
|
||||
{
|
||||
var tickRect = new Rectangle(trackOrigin - 1 + (int)(i * trackWidth * 1f / (Ticks - 1)),
|
||||
RenderBounds.Y + RenderBounds.Height / 2, 2, RenderBounds.Height / 2);
|
||||
WidgetUtils.DrawPanel("dialog2", tickRect);
|
||||
}
|
||||
// Track
|
||||
WidgetUtils.DrawPanel("dialog3", trackRect);
|
||||
|
||||
// Thumb
|
||||
WidgetUtils.DrawPanel("dialog2", thumbRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,211 +1,211 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class TextFieldWidget : Widget
|
||||
{
|
||||
public string Text = "";
|
||||
public int MaxLength = 0;
|
||||
public bool Bold = false;
|
||||
public int VisualHeight = 1;
|
||||
public Func<bool> OnEnterKey = () => false;
|
||||
public Func<bool> OnTabKey = () => false;
|
||||
public Action OnLoseFocus = () => { };
|
||||
public int CursorPosition { get; protected set; }
|
||||
|
||||
public TextFieldWidget() : base() {}
|
||||
protected TextFieldWidget(TextFieldWidget widget)
|
||||
: base(widget)
|
||||
{
|
||||
Text = widget.Text;
|
||||
MaxLength = widget.MaxLength;
|
||||
Bold = widget.Bold;
|
||||
VisualHeight = widget.VisualHeight;
|
||||
}
|
||||
|
||||
public override bool LoseFocus(MouseInput mi)
|
||||
{
|
||||
OnLoseFocus();
|
||||
var lose = base.LoseFocus(mi);
|
||||
return lose;
|
||||
}
|
||||
|
||||
// TODO: TextFieldWidgets don't support delegate methods for mouse input
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
if (mi.Event == MouseInputEvent.Move)
|
||||
return false;
|
||||
|
||||
// Lose focus if they click outside the box; return false so the next widget can grab this event
|
||||
if (mi.Event == MouseInputEvent.Down && !RenderBounds.Contains(mi.Location) && LoseFocus(mi))
|
||||
return false;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||
return false;
|
||||
|
||||
blinkCycle = 10;
|
||||
showCursor = true;
|
||||
CursorPosition = ClosestCursorPosition(mi.Location.X);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public int ClosestCursorPosition(int x)
|
||||
{
|
||||
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
|
||||
var textSize = font.Measure(Text);
|
||||
|
||||
var start = RenderOrigin.X + margin;
|
||||
if (textSize.X > Bounds.Width - 2 * margin && Focused)
|
||||
start += Bounds.Width - 2 * margin - textSize.X;
|
||||
|
||||
int minIndex = -1;
|
||||
int minValue = int.MaxValue;
|
||||
for (int i = 0; i <= Text.Length; i++)
|
||||
{
|
||||
var dist = Math.Abs(start + font.Measure(Text.Substring(0,i)).X - x);
|
||||
if (dist > minValue)
|
||||
break;
|
||||
minValue = dist;
|
||||
minIndex = i;
|
||||
}
|
||||
return minIndex;
|
||||
}
|
||||
|
||||
public override bool HandleKeyPressInner(KeyInput e)
|
||||
{
|
||||
if (e.Event == KeyInputEvent.Up) return false;
|
||||
|
||||
// Only take input if we are focused
|
||||
if (!Focused)
|
||||
return false;
|
||||
|
||||
if (e.KeyChar == '\r' && OnEnterKey())
|
||||
return true;
|
||||
|
||||
if (e.KeyChar == '\t' && OnTabKey())
|
||||
return true;
|
||||
|
||||
if (e.KeyName == "left")
|
||||
{
|
||||
if (CursorPosition > 0)
|
||||
CursorPosition--;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (e.KeyName == "right")
|
||||
{
|
||||
if (CursorPosition <= Text.Length-1)
|
||||
CursorPosition++;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (e.KeyName == "delete")
|
||||
{
|
||||
if (Text.Length > 0 && CursorPosition < Text.Length)
|
||||
{
|
||||
Text = Text.Remove(CursorPosition, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
TypeChar(e.KeyChar);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void TypeChar(char c)
|
||||
{
|
||||
// backspace
|
||||
if (c == '\b' || c == 0x7f)
|
||||
{
|
||||
if (Text.Length > 0 && CursorPosition > 0)
|
||||
{
|
||||
Text = Text.Remove(CursorPosition - 1, 1);
|
||||
|
||||
CursorPosition--;
|
||||
}
|
||||
}
|
||||
else if (!char.IsControl(c))
|
||||
{
|
||||
if (MaxLength > 0 && Text.Length >= MaxLength)
|
||||
return;
|
||||
|
||||
Text = Text.Insert(CursorPosition, c.ToString());
|
||||
|
||||
CursorPosition++;
|
||||
}
|
||||
}
|
||||
|
||||
protected int blinkCycle = 10;
|
||||
protected bool showCursor = true;
|
||||
public override void Tick()
|
||||
{
|
||||
if (--blinkCycle <= 0)
|
||||
{
|
||||
blinkCycle = 20;
|
||||
showCursor ^= true;
|
||||
}
|
||||
|
||||
base.Tick();
|
||||
}
|
||||
|
||||
int margin = 5;
|
||||
public virtual void DrawWithString(string text)
|
||||
{
|
||||
if (text == null) text = "";
|
||||
|
||||
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
|
||||
var pos = RenderOrigin;
|
||||
|
||||
if (CursorPosition > text.Length)
|
||||
CursorPosition = text.Length;
|
||||
|
||||
var textSize = font.Measure(text);
|
||||
var cursorPosition = font.Measure(text.Substring(0,CursorPosition));
|
||||
|
||||
WidgetUtils.DrawPanel("dialog3",
|
||||
new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height));
|
||||
|
||||
// Inset text by the margin and center vertically
|
||||
var textPos = pos + new int2(margin, (Bounds.Height - textSize.Y) / 2 - VisualHeight);
|
||||
|
||||
// Right align when editing and scissor when the text overflows
|
||||
if (textSize.X > Bounds.Width - 2 * margin)
|
||||
{
|
||||
if (Focused)
|
||||
textPos += new int2(Bounds.Width - 2 * margin - textSize.X, 0);
|
||||
|
||||
Game.Renderer.EnableScissor(pos.X + margin, pos.Y, Bounds.Width - 2 * margin, Bounds.Bottom);
|
||||
}
|
||||
|
||||
font.DrawText(text, textPos, Color.White);
|
||||
|
||||
if (showCursor && Focused)
|
||||
font.DrawText("|", new float2(textPos.X + cursorPosition.X - 2, textPos.Y), Color.White);
|
||||
|
||||
if (textSize.X > Bounds.Width - 2 * margin)
|
||||
Game.Renderer.DisableScissor();
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
DrawWithString(Text);
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new TextFieldWidget(this); }
|
||||
}
|
||||
#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;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class TextFieldWidget : Widget
|
||||
{
|
||||
public string Text = "";
|
||||
public int MaxLength = 0;
|
||||
public bool Bold = false;
|
||||
public int VisualHeight = 1;
|
||||
public Func<bool> OnEnterKey = () => false;
|
||||
public Func<bool> OnTabKey = () => false;
|
||||
public Action OnLoseFocus = () => { };
|
||||
public int CursorPosition { get; protected set; }
|
||||
|
||||
public TextFieldWidget() : base() {}
|
||||
protected TextFieldWidget(TextFieldWidget widget)
|
||||
: base(widget)
|
||||
{
|
||||
Text = widget.Text;
|
||||
MaxLength = widget.MaxLength;
|
||||
Bold = widget.Bold;
|
||||
VisualHeight = widget.VisualHeight;
|
||||
}
|
||||
|
||||
public override bool LoseFocus(MouseInput mi)
|
||||
{
|
||||
OnLoseFocus();
|
||||
var lose = base.LoseFocus(mi);
|
||||
return lose;
|
||||
}
|
||||
|
||||
// TODO: TextFieldWidgets don't support delegate methods for mouse input
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
if (mi.Event == MouseInputEvent.Move)
|
||||
return false;
|
||||
|
||||
// Lose focus if they click outside the box; return false so the next widget can grab this event
|
||||
if (mi.Event == MouseInputEvent.Down && !RenderBounds.Contains(mi.Location) && LoseFocus(mi))
|
||||
return false;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||
return false;
|
||||
|
||||
blinkCycle = 10;
|
||||
showCursor = true;
|
||||
CursorPosition = ClosestCursorPosition(mi.Location.X);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public int ClosestCursorPosition(int x)
|
||||
{
|
||||
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
|
||||
var textSize = font.Measure(Text);
|
||||
|
||||
var start = RenderOrigin.X + margin;
|
||||
if (textSize.X > Bounds.Width - 2 * margin && Focused)
|
||||
start += Bounds.Width - 2 * margin - textSize.X;
|
||||
|
||||
int minIndex = -1;
|
||||
int minValue = int.MaxValue;
|
||||
for (int i = 0; i <= Text.Length; i++)
|
||||
{
|
||||
var dist = Math.Abs(start + font.Measure(Text.Substring(0,i)).X - x);
|
||||
if (dist > minValue)
|
||||
break;
|
||||
minValue = dist;
|
||||
minIndex = i;
|
||||
}
|
||||
return minIndex;
|
||||
}
|
||||
|
||||
public override bool HandleKeyPressInner(KeyInput e)
|
||||
{
|
||||
if (e.Event == KeyInputEvent.Up) return false;
|
||||
|
||||
// Only take input if we are focused
|
||||
if (!Focused)
|
||||
return false;
|
||||
|
||||
if (e.KeyChar == '\r' && OnEnterKey())
|
||||
return true;
|
||||
|
||||
if (e.KeyChar == '\t' && OnTabKey())
|
||||
return true;
|
||||
|
||||
if (e.KeyName == "left")
|
||||
{
|
||||
if (CursorPosition > 0)
|
||||
CursorPosition--;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (e.KeyName == "right")
|
||||
{
|
||||
if (CursorPosition <= Text.Length-1)
|
||||
CursorPosition++;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (e.KeyName == "delete")
|
||||
{
|
||||
if (Text.Length > 0 && CursorPosition < Text.Length)
|
||||
{
|
||||
Text = Text.Remove(CursorPosition, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
TypeChar(e.KeyChar);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void TypeChar(char c)
|
||||
{
|
||||
// backspace
|
||||
if (c == '\b' || c == 0x7f)
|
||||
{
|
||||
if (Text.Length > 0 && CursorPosition > 0)
|
||||
{
|
||||
Text = Text.Remove(CursorPosition - 1, 1);
|
||||
|
||||
CursorPosition--;
|
||||
}
|
||||
}
|
||||
else if (!char.IsControl(c))
|
||||
{
|
||||
if (MaxLength > 0 && Text.Length >= MaxLength)
|
||||
return;
|
||||
|
||||
Text = Text.Insert(CursorPosition, c.ToString());
|
||||
|
||||
CursorPosition++;
|
||||
}
|
||||
}
|
||||
|
||||
protected int blinkCycle = 10;
|
||||
protected bool showCursor = true;
|
||||
public override void Tick()
|
||||
{
|
||||
if (--blinkCycle <= 0)
|
||||
{
|
||||
blinkCycle = 20;
|
||||
showCursor ^= true;
|
||||
}
|
||||
|
||||
base.Tick();
|
||||
}
|
||||
|
||||
int margin = 5;
|
||||
public virtual void DrawWithString(string text)
|
||||
{
|
||||
if (text == null) text = "";
|
||||
|
||||
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
|
||||
var pos = RenderOrigin;
|
||||
|
||||
if (CursorPosition > text.Length)
|
||||
CursorPosition = text.Length;
|
||||
|
||||
var textSize = font.Measure(text);
|
||||
var cursorPosition = font.Measure(text.Substring(0,CursorPosition));
|
||||
|
||||
WidgetUtils.DrawPanel("dialog3",
|
||||
new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height));
|
||||
|
||||
// Inset text by the margin and center vertically
|
||||
var textPos = pos + new int2(margin, (Bounds.Height - textSize.Y) / 2 - VisualHeight);
|
||||
|
||||
// Right align when editing and scissor when the text overflows
|
||||
if (textSize.X > Bounds.Width - 2 * margin)
|
||||
{
|
||||
if (Focused)
|
||||
textPos += new int2(Bounds.Width - 2 * margin - textSize.X, 0);
|
||||
|
||||
Game.Renderer.EnableScissor(pos.X + margin, pos.Y, Bounds.Width - 2 * margin, Bounds.Bottom);
|
||||
}
|
||||
|
||||
font.DrawText(text, textPos, Color.White);
|
||||
|
||||
if (showCursor && Focused)
|
||||
font.DrawText("|", new float2(textPos.X + cursorPosition.X - 2, textPos.Y), Color.White);
|
||||
|
||||
if (textSize.X > Bounds.Width - 2 * margin)
|
||||
Game.Renderer.DisableScissor();
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
DrawWithString(Text);
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new TextFieldWidget(this); }
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* 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 LICENSE.
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Support;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
@@ -26,10 +26,10 @@ namespace OpenRA.Widgets
|
||||
public override void DrawInner()
|
||||
{
|
||||
var s = WidgetUtils.FormatTime(Game.LocalTick);
|
||||
var size = Game.Renderer.TitleFont.Measure(s);
|
||||
var pos = new float2(RenderBounds.Left - size.X / 2, RenderBounds.Top - 20);
|
||||
|
||||
Game.Renderer.TitleFont.DrawTextWithContrast(s, pos, Color.White, Color.Black, 1);
|
||||
var size = Game.Renderer.TitleFont.Measure(s);
|
||||
var pos = new float2(RenderBounds.Left - size.X / 2, RenderBounds.Top - 20);
|
||||
|
||||
Game.Renderer.TitleFont.DrawTextWithContrast(s, pos, Color.White, Color.Black, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,179 +1,179 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
[Flags]
|
||||
public enum ScrollDirection
|
||||
{
|
||||
None = 0,
|
||||
Up = 1,
|
||||
Left = 2,
|
||||
Down = 4,
|
||||
Right = 8
|
||||
}
|
||||
|
||||
public class ViewportScrollControllerWidget : Widget
|
||||
{
|
||||
public int EdgeScrollThreshold = 15;
|
||||
|
||||
ScrollDirection Keyboard;
|
||||
ScrollDirection Edge;
|
||||
|
||||
public ViewportScrollControllerWidget() : base() { }
|
||||
protected ViewportScrollControllerWidget(ViewportScrollControllerWidget widget) : base(widget) {}
|
||||
public override void DrawInner() {}
|
||||
|
||||
// TODO: ViewportScrollController doesn't support delegate methods for mouse input
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
if (mi.Event == MouseInputEvent.Move &&
|
||||
(mi.Button == MouseButton.Middle || mi.Button == (MouseButton.Left | MouseButton.Right)))
|
||||
{
|
||||
int InverseScroll = Game.Settings.Game.InverseDragScroll ? -1 : 1;
|
||||
Game.viewport.Scroll((Viewport.LastMousePos - mi.Location) * InverseScroll);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string GetCursor(int2 pos)
|
||||
{
|
||||
if (!Game.Settings.Game.ViewportEdgeScroll)
|
||||
return null;
|
||||
|
||||
if (Edge.Includes(ScrollDirection.Up) && Edge.Includes(ScrollDirection.Left)){
|
||||
ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections();
|
||||
if(BlockedDirections.Includes(ScrollDirection.Up) && BlockedDirections.Includes(ScrollDirection.Left))
|
||||
return "scroll-tl-blocked";
|
||||
else
|
||||
return "scroll-tl";
|
||||
}
|
||||
if (Edge.Includes(ScrollDirection.Up) && Edge.Includes(ScrollDirection.Right)){
|
||||
ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections();
|
||||
if (BlockedDirections.Includes(ScrollDirection.Up) && BlockedDirections.Includes(ScrollDirection.Right))
|
||||
return "scroll-tr-blocked";
|
||||
else
|
||||
return "scroll-tr";
|
||||
}
|
||||
if (Edge.Includes(ScrollDirection.Down) && Edge.Includes(ScrollDirection.Left)){
|
||||
ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections();
|
||||
if (BlockedDirections.Includes(ScrollDirection.Down) && BlockedDirections.Includes(ScrollDirection.Left))
|
||||
return "scroll-bl-blocked";
|
||||
else
|
||||
return "scroll-bl";
|
||||
}
|
||||
if (Edge.Includes(ScrollDirection.Down) && Edge.Includes(ScrollDirection.Right)){
|
||||
ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections();
|
||||
if (BlockedDirections.Includes(ScrollDirection.Down) && BlockedDirections.Includes(ScrollDirection.Right))
|
||||
return "scroll-br-blocked";
|
||||
else
|
||||
return "scroll-br";
|
||||
}
|
||||
|
||||
if (Edge.Includes(ScrollDirection.Up))
|
||||
if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Up))
|
||||
return "scroll-t-blocked";
|
||||
else
|
||||
return "scroll-t";
|
||||
if (Edge.Includes(ScrollDirection.Down))
|
||||
if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Down))
|
||||
return "scroll-b-blocked";
|
||||
else
|
||||
return "scroll-b";
|
||||
if (Edge.Includes(ScrollDirection.Left))
|
||||
if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Left))
|
||||
return "scroll-l-blocked";
|
||||
else
|
||||
return "scroll-l";
|
||||
if (Edge.Includes(ScrollDirection.Right))
|
||||
if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Right))
|
||||
return "scroll-r-blocked";
|
||||
else
|
||||
return "scroll-r";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override bool LoseFocus (MouseInput mi)
|
||||
{
|
||||
Keyboard = ScrollDirection.None;
|
||||
return base.LoseFocus(mi);
|
||||
}
|
||||
|
||||
public override bool HandleKeyPressInner(KeyInput e)
|
||||
{
|
||||
switch (e.KeyName)
|
||||
{
|
||||
case "up": Keyboard = Keyboard.Set(ScrollDirection.Up, (e.Event == KeyInputEvent.Down)); return true;
|
||||
case "down": Keyboard = Keyboard.Set(ScrollDirection.Down, (e.Event == KeyInputEvent.Down)); return true;
|
||||
case "left": Keyboard = Keyboard.Set(ScrollDirection.Left, (e.Event == KeyInputEvent.Down)); return true;
|
||||
case "right": Keyboard = Keyboard.Set(ScrollDirection.Right, (e.Event == KeyInputEvent.Down)); return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
Edge = ScrollDirection.None;
|
||||
if (Game.Settings.Game.ViewportEdgeScroll && Game.HasInputFocus)
|
||||
{
|
||||
// Check for edge-scroll
|
||||
if (Viewport.LastMousePos.X < EdgeScrollThreshold)
|
||||
Edge = Edge.Set(ScrollDirection.Left, true);
|
||||
if (Viewport.LastMousePos.Y < EdgeScrollThreshold)
|
||||
Edge = Edge.Set(ScrollDirection.Up, true);
|
||||
if (Viewport.LastMousePos.X >= Game.viewport.Width - EdgeScrollThreshold)
|
||||
Edge = Edge.Set(ScrollDirection.Right, true);
|
||||
if (Viewport.LastMousePos.Y >= Game.viewport.Height - EdgeScrollThreshold)
|
||||
Edge = Edge.Set(ScrollDirection.Down, true);
|
||||
}
|
||||
|
||||
if(Keyboard != ScrollDirection.None || Edge != ScrollDirection.None)
|
||||
{
|
||||
var scroll = new float2(0, 0);
|
||||
|
||||
// Modified to use the ViewportEdgeScrollStep setting - Gecko
|
||||
if (Keyboard.Includes(ScrollDirection.Up) || Edge.Includes(ScrollDirection.Up))
|
||||
scroll += new float2(0, -1);
|
||||
if (Keyboard.Includes(ScrollDirection.Right) || Edge.Includes(ScrollDirection.Right))
|
||||
scroll += new float2(1, 0);
|
||||
if (Keyboard.Includes(ScrollDirection.Down) || Edge.Includes(ScrollDirection.Down))
|
||||
scroll += new float2(0, 1);
|
||||
if (Keyboard.Includes(ScrollDirection.Left) || Edge.Includes(ScrollDirection.Left))
|
||||
scroll += new float2(-1, 0);
|
||||
|
||||
float length = Math.Max(1, scroll.Length);
|
||||
scroll.X = (scroll.X / length) * Game.Settings.Game.ViewportEdgeScrollStep;
|
||||
scroll.Y = (scroll.Y / length) * Game.Settings.Game.ViewportEdgeScrollStep;
|
||||
|
||||
Game.viewport.Scroll(scroll);
|
||||
}
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new ViewportScrollControllerWidget(this); }
|
||||
}
|
||||
|
||||
public static class ViewportExts
|
||||
{
|
||||
public static bool Includes(this ScrollDirection d, ScrollDirection s)
|
||||
{
|
||||
return (d & s) == s;
|
||||
}
|
||||
|
||||
public static ScrollDirection Set(this ScrollDirection d, ScrollDirection s, bool val)
|
||||
{
|
||||
return (d.Includes(s) != val) ? d ^ s : d;
|
||||
}
|
||||
}
|
||||
}
|
||||
#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;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
[Flags]
|
||||
public enum ScrollDirection
|
||||
{
|
||||
None = 0,
|
||||
Up = 1,
|
||||
Left = 2,
|
||||
Down = 4,
|
||||
Right = 8
|
||||
}
|
||||
|
||||
public class ViewportScrollControllerWidget : Widget
|
||||
{
|
||||
public int EdgeScrollThreshold = 15;
|
||||
|
||||
ScrollDirection Keyboard;
|
||||
ScrollDirection Edge;
|
||||
|
||||
public ViewportScrollControllerWidget() : base() { }
|
||||
protected ViewportScrollControllerWidget(ViewportScrollControllerWidget widget) : base(widget) {}
|
||||
public override void DrawInner() {}
|
||||
|
||||
// TODO: ViewportScrollController doesn't support delegate methods for mouse input
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
if (mi.Event == MouseInputEvent.Move &&
|
||||
(mi.Button == MouseButton.Middle || mi.Button == (MouseButton.Left | MouseButton.Right)))
|
||||
{
|
||||
int InverseScroll = Game.Settings.Game.InverseDragScroll ? -1 : 1;
|
||||
Game.viewport.Scroll((Viewport.LastMousePos - mi.Location) * InverseScroll);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string GetCursor(int2 pos)
|
||||
{
|
||||
if (!Game.Settings.Game.ViewportEdgeScroll)
|
||||
return null;
|
||||
|
||||
if (Edge.Includes(ScrollDirection.Up) && Edge.Includes(ScrollDirection.Left)){
|
||||
ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections();
|
||||
if(BlockedDirections.Includes(ScrollDirection.Up) && BlockedDirections.Includes(ScrollDirection.Left))
|
||||
return "scroll-tl-blocked";
|
||||
else
|
||||
return "scroll-tl";
|
||||
}
|
||||
if (Edge.Includes(ScrollDirection.Up) && Edge.Includes(ScrollDirection.Right)){
|
||||
ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections();
|
||||
if (BlockedDirections.Includes(ScrollDirection.Up) && BlockedDirections.Includes(ScrollDirection.Right))
|
||||
return "scroll-tr-blocked";
|
||||
else
|
||||
return "scroll-tr";
|
||||
}
|
||||
if (Edge.Includes(ScrollDirection.Down) && Edge.Includes(ScrollDirection.Left)){
|
||||
ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections();
|
||||
if (BlockedDirections.Includes(ScrollDirection.Down) && BlockedDirections.Includes(ScrollDirection.Left))
|
||||
return "scroll-bl-blocked";
|
||||
else
|
||||
return "scroll-bl";
|
||||
}
|
||||
if (Edge.Includes(ScrollDirection.Down) && Edge.Includes(ScrollDirection.Right)){
|
||||
ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections();
|
||||
if (BlockedDirections.Includes(ScrollDirection.Down) && BlockedDirections.Includes(ScrollDirection.Right))
|
||||
return "scroll-br-blocked";
|
||||
else
|
||||
return "scroll-br";
|
||||
}
|
||||
|
||||
if (Edge.Includes(ScrollDirection.Up))
|
||||
if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Up))
|
||||
return "scroll-t-blocked";
|
||||
else
|
||||
return "scroll-t";
|
||||
if (Edge.Includes(ScrollDirection.Down))
|
||||
if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Down))
|
||||
return "scroll-b-blocked";
|
||||
else
|
||||
return "scroll-b";
|
||||
if (Edge.Includes(ScrollDirection.Left))
|
||||
if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Left))
|
||||
return "scroll-l-blocked";
|
||||
else
|
||||
return "scroll-l";
|
||||
if (Edge.Includes(ScrollDirection.Right))
|
||||
if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Right))
|
||||
return "scroll-r-blocked";
|
||||
else
|
||||
return "scroll-r";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override bool LoseFocus (MouseInput mi)
|
||||
{
|
||||
Keyboard = ScrollDirection.None;
|
||||
return base.LoseFocus(mi);
|
||||
}
|
||||
|
||||
public override bool HandleKeyPressInner(KeyInput e)
|
||||
{
|
||||
switch (e.KeyName)
|
||||
{
|
||||
case "up": Keyboard = Keyboard.Set(ScrollDirection.Up, (e.Event == KeyInputEvent.Down)); return true;
|
||||
case "down": Keyboard = Keyboard.Set(ScrollDirection.Down, (e.Event == KeyInputEvent.Down)); return true;
|
||||
case "left": Keyboard = Keyboard.Set(ScrollDirection.Left, (e.Event == KeyInputEvent.Down)); return true;
|
||||
case "right": Keyboard = Keyboard.Set(ScrollDirection.Right, (e.Event == KeyInputEvent.Down)); return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
Edge = ScrollDirection.None;
|
||||
if (Game.Settings.Game.ViewportEdgeScroll && Game.HasInputFocus)
|
||||
{
|
||||
// Check for edge-scroll
|
||||
if (Viewport.LastMousePos.X < EdgeScrollThreshold)
|
||||
Edge = Edge.Set(ScrollDirection.Left, true);
|
||||
if (Viewport.LastMousePos.Y < EdgeScrollThreshold)
|
||||
Edge = Edge.Set(ScrollDirection.Up, true);
|
||||
if (Viewport.LastMousePos.X >= Game.viewport.Width - EdgeScrollThreshold)
|
||||
Edge = Edge.Set(ScrollDirection.Right, true);
|
||||
if (Viewport.LastMousePos.Y >= Game.viewport.Height - EdgeScrollThreshold)
|
||||
Edge = Edge.Set(ScrollDirection.Down, true);
|
||||
}
|
||||
|
||||
if(Keyboard != ScrollDirection.None || Edge != ScrollDirection.None)
|
||||
{
|
||||
var scroll = new float2(0, 0);
|
||||
|
||||
// Modified to use the ViewportEdgeScrollStep setting - Gecko
|
||||
if (Keyboard.Includes(ScrollDirection.Up) || Edge.Includes(ScrollDirection.Up))
|
||||
scroll += new float2(0, -1);
|
||||
if (Keyboard.Includes(ScrollDirection.Right) || Edge.Includes(ScrollDirection.Right))
|
||||
scroll += new float2(1, 0);
|
||||
if (Keyboard.Includes(ScrollDirection.Down) || Edge.Includes(ScrollDirection.Down))
|
||||
scroll += new float2(0, 1);
|
||||
if (Keyboard.Includes(ScrollDirection.Left) || Edge.Includes(ScrollDirection.Left))
|
||||
scroll += new float2(-1, 0);
|
||||
|
||||
float length = Math.Max(1, scroll.Length);
|
||||
scroll.X = (scroll.X / length) * Game.Settings.Game.ViewportEdgeScrollStep;
|
||||
scroll.Y = (scroll.Y / length) * Game.Settings.Game.ViewportEdgeScrollStep;
|
||||
|
||||
Game.viewport.Scroll(scroll);
|
||||
}
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new ViewportScrollControllerWidget(this); }
|
||||
}
|
||||
|
||||
public static class ViewportExts
|
||||
{
|
||||
public static bool Includes(this ScrollDirection d, ScrollDirection s)
|
||||
{
|
||||
return (d & s) == s;
|
||||
}
|
||||
|
||||
public static ScrollDirection Set(this ScrollDirection d, ScrollDirection s, bool val)
|
||||
{
|
||||
return (d.Includes(s) != val) ? d ^ s : d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* 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 LICENSE.
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class VqaPlayerWidget : Widget
|
||||
|
||||
@@ -1,368 +1,368 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public abstract class Widget
|
||||
{
|
||||
// Info defined in YAML
|
||||
public string Id = null;
|
||||
public string X = "0";
|
||||
public string Y = "0";
|
||||
public string Width = "0";
|
||||
public string Height = "0";
|
||||
public string Delegate = null;
|
||||
public string EventHandler = null;
|
||||
public bool Visible = true;
|
||||
|
||||
public readonly List<Widget> Children = new List<Widget>();
|
||||
|
||||
// Calculated internally
|
||||
public Rectangle Bounds;
|
||||
public Widget Parent = null;
|
||||
|
||||
public static Stack<Widget> WindowList = new Stack<Widget>();
|
||||
|
||||
// Common Funcs that most widgets will want
|
||||
public Func<MouseInput, bool> OnMouseDown = mi => false;
|
||||
public Func<MouseInput, bool> OnMouseUp = mi => false;
|
||||
public Action<MouseInput> OnMouseMove = mi => {};
|
||||
public Func<KeyInput, bool> OnKeyPress = e => false;
|
||||
|
||||
public Func<bool> IsVisible;
|
||||
|
||||
public Widget() { IsVisible = () => Visible; }
|
||||
|
||||
public static Widget RootWidget
|
||||
{
|
||||
get { return rootWidget; }
|
||||
set { rootWidget = value; }
|
||||
}
|
||||
private static Widget rootWidget = new ContainerWidget();
|
||||
|
||||
public Widget(Widget widget)
|
||||
{
|
||||
Id = widget.Id;
|
||||
X = widget.X;
|
||||
Y = widget.Y;
|
||||
Width = widget.Width;
|
||||
Height = widget.Height;
|
||||
Delegate = widget.Delegate;
|
||||
Visible = widget.Visible;
|
||||
|
||||
Bounds = widget.Bounds;
|
||||
Parent = widget.Parent;
|
||||
|
||||
OnMouseDown = widget.OnMouseDown;
|
||||
OnMouseUp = widget.OnMouseUp;
|
||||
OnMouseMove = widget.OnMouseMove;
|
||||
OnKeyPress = widget.OnKeyPress;
|
||||
|
||||
IsVisible = widget.IsVisible;
|
||||
|
||||
foreach(var child in widget.Children)
|
||||
AddChild(child.Clone());
|
||||
}
|
||||
|
||||
public virtual Widget Clone()
|
||||
{
|
||||
throw new InvalidOperationException("Widget type `{0}` is not cloneable.".F(GetType().Name));
|
||||
}
|
||||
|
||||
public virtual int2 RenderOrigin
|
||||
{
|
||||
get
|
||||
{
|
||||
var offset = (Parent == null) ? int2.Zero : Parent.ChildOrigin;
|
||||
return new int2(Bounds.X, Bounds.Y) + offset;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int2 ChildOrigin { get { return RenderOrigin; } }
|
||||
public virtual Rectangle RenderBounds { get { return new Rectangle(RenderOrigin.X, RenderOrigin.Y, Bounds.Width, Bounds.Height); } }
|
||||
|
||||
public virtual void Initialize()
|
||||
{
|
||||
// Parse the YAML equations to find the widget bounds
|
||||
var parentBounds = (Parent == null)
|
||||
? new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height)
|
||||
: Parent.Bounds;
|
||||
|
||||
var substitutions = new Dictionary<string, int>();
|
||||
substitutions.Add("WINDOW_RIGHT", Game.viewport.Width);
|
||||
substitutions.Add("WINDOW_BOTTOM", Game.viewport.Height);
|
||||
substitutions.Add("PARENT_RIGHT", parentBounds.Width);
|
||||
substitutions.Add("PARENT_LEFT", parentBounds.Left);
|
||||
substitutions.Add("PARENT_TOP", parentBounds.Top);
|
||||
substitutions.Add("PARENT_BOTTOM", parentBounds.Height);
|
||||
int width = Evaluator.Evaluate(Width, substitutions);
|
||||
int height = Evaluator.Evaluate(Height, substitutions);
|
||||
|
||||
substitutions.Add("WIDTH", width);
|
||||
substitutions.Add("HEIGHT", height);
|
||||
|
||||
Bounds = new Rectangle(Evaluator.Evaluate(X, substitutions),
|
||||
Evaluator.Evaluate(Y, substitutions),
|
||||
width,
|
||||
height);
|
||||
}
|
||||
|
||||
public void PostInit(Dictionary<string, object> args)
|
||||
{
|
||||
if( Delegate != null )
|
||||
{
|
||||
args["widget"] = this;
|
||||
Game.modData.ObjectCreator.CreateObject<IWidgetDelegate>(Delegate, args);
|
||||
args.Remove("widget");
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Rectangle EventBounds { get { return RenderBounds; } }
|
||||
public virtual Rectangle GetEventBounds()
|
||||
{
|
||||
return Children
|
||||
.Where(c => c.IsVisible())
|
||||
.Select(c => c.GetEventBounds())
|
||||
.Aggregate(EventBounds, Rectangle.Union);
|
||||
}
|
||||
|
||||
public static Widget SelectedWidget;
|
||||
public bool Focused { get { return SelectedWidget == this; } }
|
||||
public virtual bool TakeFocus(MouseInput mi)
|
||||
{
|
||||
if (Focused)
|
||||
return true;
|
||||
|
||||
if (SelectedWidget != null && !SelectedWidget.LoseFocus(mi))
|
||||
return false;
|
||||
SelectedWidget = this;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Remove focus from this widget; return false if you don't want to give it up
|
||||
public virtual bool LoseFocus(MouseInput mi)
|
||||
{
|
||||
// Some widgets may need to override focus depending on mouse click
|
||||
return LoseFocus();
|
||||
}
|
||||
|
||||
public virtual bool LoseFocus()
|
||||
{
|
||||
if (SelectedWidget == this)
|
||||
SelectedWidget = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual string GetCursor(int2 pos) { return "default"; }
|
||||
public string GetCursorOuter(int2 pos)
|
||||
{
|
||||
// Is the cursor on top of us?
|
||||
if (!(IsVisible() && GetEventBounds().Contains(pos)))
|
||||
return null;
|
||||
|
||||
// Do any of our children specify a cursor?
|
||||
foreach (var child in Children.OfType<Widget>().Reverse())
|
||||
{
|
||||
var cc = child.GetCursorOuter(pos);
|
||||
if (cc != null)
|
||||
return cc;
|
||||
}
|
||||
|
||||
return EventBounds.Contains(pos) ? GetCursor(pos) : null;
|
||||
}
|
||||
|
||||
public static bool HandleInput(MouseInput mi)
|
||||
{
|
||||
bool handled = false;
|
||||
if (SelectedWidget != null && SelectedWidget.HandleMouseInputOuter(mi))
|
||||
handled = true;
|
||||
|
||||
if (!handled && RootWidget.HandleMouseInputOuter(mi))
|
||||
handled = true;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Move)
|
||||
{
|
||||
Viewport.LastMousePos = mi.Location;
|
||||
Viewport.TicksSinceLastMove = 0;
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
public bool HandleMouseInputOuter(MouseInput mi)
|
||||
{
|
||||
// Are we able to handle this event?
|
||||
if (!(Focused || (IsVisible() && GetEventBounds().Contains(mi.Location.X,mi.Location.Y))))
|
||||
return false;
|
||||
|
||||
// Send the event to the deepest children first and bubble up if unhandled
|
||||
foreach (var child in Children.OfType<Widget>().Reverse())
|
||||
if (child.HandleMouseInputOuter(mi))
|
||||
return true;
|
||||
|
||||
return HandleMouseInput(mi);
|
||||
}
|
||||
|
||||
// Hack: Don't eat mouse input that others want
|
||||
// TODO: Solve this properly
|
||||
public virtual bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
// Apply any special logic added by delegates; they return true if they caught the input
|
||||
if (mi.Event == MouseInputEvent.Down && OnMouseDown(mi)) return true;
|
||||
if (mi.Event == MouseInputEvent.Up && OnMouseUp(mi)) return true;
|
||||
if (mi.Event == MouseInputEvent.Move)
|
||||
OnMouseMove(mi);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool HandleKeyPressInner(KeyInput e) { return false; }
|
||||
public virtual bool HandleKeyPressOuter(KeyInput e)
|
||||
{
|
||||
if (!IsVisible())
|
||||
return false;
|
||||
|
||||
// Can any of our children handle this?
|
||||
foreach (var child in Children)
|
||||
if (child.HandleKeyPressOuter(e))
|
||||
return true;
|
||||
|
||||
// Do any widgety behavior (enter text etc)
|
||||
var handled = HandleKeyPressInner(e);
|
||||
|
||||
// Apply any special logic added by delegates; they return true if they caught the input
|
||||
if (OnKeyPress(e)) return true;
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
public static bool HandleKeyPress(KeyInput e)
|
||||
{
|
||||
if (SelectedWidget != null)
|
||||
return SelectedWidget.HandleKeyPressOuter(e);
|
||||
|
||||
if (RootWidget.HandleKeyPressOuter(e))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract void DrawInner();
|
||||
|
||||
public virtual void Draw()
|
||||
{
|
||||
if (IsVisible())
|
||||
{
|
||||
DrawInner();
|
||||
foreach (var child in Children)
|
||||
child.Draw();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Tick()
|
||||
{
|
||||
if (IsVisible())
|
||||
foreach (var child in Children)
|
||||
child.Tick();
|
||||
}
|
||||
|
||||
public virtual void AddChild(Widget child)
|
||||
{
|
||||
child.Parent = this;
|
||||
Children.Add( child );
|
||||
}
|
||||
public virtual void RemoveChild(Widget child) { Children.Remove(child); }
|
||||
public virtual void RemoveChildren() { Children.Clear(); }
|
||||
|
||||
public Widget GetWidget(string id)
|
||||
{
|
||||
if (this.Id == id)
|
||||
return this;
|
||||
|
||||
foreach (var child in Children)
|
||||
{
|
||||
var w = child.GetWidget(id);
|
||||
if (w != null)
|
||||
return w;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public T GetWidget<T>(string id) where T : Widget
|
||||
{
|
||||
var widget = GetWidget(id);
|
||||
return (widget != null)? (T) widget : null;
|
||||
}
|
||||
|
||||
public static void CloseWindow()
|
||||
{
|
||||
RootWidget.Children.Remove( WindowList.Pop() );
|
||||
if( WindowList.Count > 0 )
|
||||
rootWidget.Children.Add( WindowList.Peek() );
|
||||
}
|
||||
|
||||
public static Widget OpenWindow( string id )
|
||||
{
|
||||
return OpenWindow( id, new Dictionary<string, object>() );
|
||||
}
|
||||
|
||||
public static Widget OpenWindow(string id, Dictionary<string, object> args )
|
||||
{
|
||||
var window = Game.modData.WidgetLoader.LoadWidget( args, rootWidget, id );
|
||||
if( WindowList.Count > 0 )
|
||||
rootWidget.Children.Remove( WindowList.Peek() );
|
||||
WindowList.Push( window );
|
||||
return window;
|
||||
}
|
||||
|
||||
public static void DoTick()
|
||||
{
|
||||
RootWidget.Tick();
|
||||
}
|
||||
|
||||
public static void DoDraw()
|
||||
{
|
||||
RootWidget.Draw();
|
||||
}
|
||||
}
|
||||
|
||||
public class ContainerWidget : Widget {
|
||||
public Func<string> GetBackground;
|
||||
public string Background = null;
|
||||
|
||||
public ContainerWidget() : base()
|
||||
{
|
||||
GetBackground = () => Background;
|
||||
}
|
||||
|
||||
public ContainerWidget(ContainerWidget other) : base(other)
|
||||
{
|
||||
Background = other.Background;
|
||||
GetBackground = other.GetBackground;
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
var bg = GetBackground();
|
||||
if (bg != null)
|
||||
WidgetUtils.DrawPanel(bg, RenderBounds );
|
||||
}
|
||||
|
||||
public override string GetCursor(int2 pos) { return null; }
|
||||
public override Widget Clone() { return new ContainerWidget(this); }
|
||||
}
|
||||
public interface IWidgetDelegate { }
|
||||
#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;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public abstract class Widget
|
||||
{
|
||||
// Info defined in YAML
|
||||
public string Id = null;
|
||||
public string X = "0";
|
||||
public string Y = "0";
|
||||
public string Width = "0";
|
||||
public string Height = "0";
|
||||
public string Delegate = null;
|
||||
public string EventHandler = null;
|
||||
public bool Visible = true;
|
||||
|
||||
public readonly List<Widget> Children = new List<Widget>();
|
||||
|
||||
// Calculated internally
|
||||
public Rectangle Bounds;
|
||||
public Widget Parent = null;
|
||||
|
||||
public static Stack<Widget> WindowList = new Stack<Widget>();
|
||||
|
||||
// Common Funcs that most widgets will want
|
||||
public Func<MouseInput, bool> OnMouseDown = mi => false;
|
||||
public Func<MouseInput, bool> OnMouseUp = mi => false;
|
||||
public Action<MouseInput> OnMouseMove = mi => {};
|
||||
public Func<KeyInput, bool> OnKeyPress = e => false;
|
||||
|
||||
public Func<bool> IsVisible;
|
||||
|
||||
public Widget() { IsVisible = () => Visible; }
|
||||
|
||||
public static Widget RootWidget
|
||||
{
|
||||
get { return rootWidget; }
|
||||
set { rootWidget = value; }
|
||||
}
|
||||
private static Widget rootWidget = new ContainerWidget();
|
||||
|
||||
public Widget(Widget widget)
|
||||
{
|
||||
Id = widget.Id;
|
||||
X = widget.X;
|
||||
Y = widget.Y;
|
||||
Width = widget.Width;
|
||||
Height = widget.Height;
|
||||
Delegate = widget.Delegate;
|
||||
Visible = widget.Visible;
|
||||
|
||||
Bounds = widget.Bounds;
|
||||
Parent = widget.Parent;
|
||||
|
||||
OnMouseDown = widget.OnMouseDown;
|
||||
OnMouseUp = widget.OnMouseUp;
|
||||
OnMouseMove = widget.OnMouseMove;
|
||||
OnKeyPress = widget.OnKeyPress;
|
||||
|
||||
IsVisible = widget.IsVisible;
|
||||
|
||||
foreach(var child in widget.Children)
|
||||
AddChild(child.Clone());
|
||||
}
|
||||
|
||||
public virtual Widget Clone()
|
||||
{
|
||||
throw new InvalidOperationException("Widget type `{0}` is not cloneable.".F(GetType().Name));
|
||||
}
|
||||
|
||||
public virtual int2 RenderOrigin
|
||||
{
|
||||
get
|
||||
{
|
||||
var offset = (Parent == null) ? int2.Zero : Parent.ChildOrigin;
|
||||
return new int2(Bounds.X, Bounds.Y) + offset;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int2 ChildOrigin { get { return RenderOrigin; } }
|
||||
public virtual Rectangle RenderBounds { get { return new Rectangle(RenderOrigin.X, RenderOrigin.Y, Bounds.Width, Bounds.Height); } }
|
||||
|
||||
public virtual void Initialize()
|
||||
{
|
||||
// Parse the YAML equations to find the widget bounds
|
||||
var parentBounds = (Parent == null)
|
||||
? new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height)
|
||||
: Parent.Bounds;
|
||||
|
||||
var substitutions = new Dictionary<string, int>();
|
||||
substitutions.Add("WINDOW_RIGHT", Game.viewport.Width);
|
||||
substitutions.Add("WINDOW_BOTTOM", Game.viewport.Height);
|
||||
substitutions.Add("PARENT_RIGHT", parentBounds.Width);
|
||||
substitutions.Add("PARENT_LEFT", parentBounds.Left);
|
||||
substitutions.Add("PARENT_TOP", parentBounds.Top);
|
||||
substitutions.Add("PARENT_BOTTOM", parentBounds.Height);
|
||||
int width = Evaluator.Evaluate(Width, substitutions);
|
||||
int height = Evaluator.Evaluate(Height, substitutions);
|
||||
|
||||
substitutions.Add("WIDTH", width);
|
||||
substitutions.Add("HEIGHT", height);
|
||||
|
||||
Bounds = new Rectangle(Evaluator.Evaluate(X, substitutions),
|
||||
Evaluator.Evaluate(Y, substitutions),
|
||||
width,
|
||||
height);
|
||||
}
|
||||
|
||||
public void PostInit(Dictionary<string, object> args)
|
||||
{
|
||||
if( Delegate != null )
|
||||
{
|
||||
args["widget"] = this;
|
||||
Game.modData.ObjectCreator.CreateObject<IWidgetDelegate>(Delegate, args);
|
||||
args.Remove("widget");
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Rectangle EventBounds { get { return RenderBounds; } }
|
||||
public virtual Rectangle GetEventBounds()
|
||||
{
|
||||
return Children
|
||||
.Where(c => c.IsVisible())
|
||||
.Select(c => c.GetEventBounds())
|
||||
.Aggregate(EventBounds, Rectangle.Union);
|
||||
}
|
||||
|
||||
public static Widget SelectedWidget;
|
||||
public bool Focused { get { return SelectedWidget == this; } }
|
||||
public virtual bool TakeFocus(MouseInput mi)
|
||||
{
|
||||
if (Focused)
|
||||
return true;
|
||||
|
||||
if (SelectedWidget != null && !SelectedWidget.LoseFocus(mi))
|
||||
return false;
|
||||
SelectedWidget = this;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Remove focus from this widget; return false if you don't want to give it up
|
||||
public virtual bool LoseFocus(MouseInput mi)
|
||||
{
|
||||
// Some widgets may need to override focus depending on mouse click
|
||||
return LoseFocus();
|
||||
}
|
||||
|
||||
public virtual bool LoseFocus()
|
||||
{
|
||||
if (SelectedWidget == this)
|
||||
SelectedWidget = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual string GetCursor(int2 pos) { return "default"; }
|
||||
public string GetCursorOuter(int2 pos)
|
||||
{
|
||||
// Is the cursor on top of us?
|
||||
if (!(IsVisible() && GetEventBounds().Contains(pos)))
|
||||
return null;
|
||||
|
||||
// Do any of our children specify a cursor?
|
||||
foreach (var child in Children.OfType<Widget>().Reverse())
|
||||
{
|
||||
var cc = child.GetCursorOuter(pos);
|
||||
if (cc != null)
|
||||
return cc;
|
||||
}
|
||||
|
||||
return EventBounds.Contains(pos) ? GetCursor(pos) : null;
|
||||
}
|
||||
|
||||
public static bool HandleInput(MouseInput mi)
|
||||
{
|
||||
bool handled = false;
|
||||
if (SelectedWidget != null && SelectedWidget.HandleMouseInputOuter(mi))
|
||||
handled = true;
|
||||
|
||||
if (!handled && RootWidget.HandleMouseInputOuter(mi))
|
||||
handled = true;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Move)
|
||||
{
|
||||
Viewport.LastMousePos = mi.Location;
|
||||
Viewport.TicksSinceLastMove = 0;
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
public bool HandleMouseInputOuter(MouseInput mi)
|
||||
{
|
||||
// Are we able to handle this event?
|
||||
if (!(Focused || (IsVisible() && GetEventBounds().Contains(mi.Location.X,mi.Location.Y))))
|
||||
return false;
|
||||
|
||||
// Send the event to the deepest children first and bubble up if unhandled
|
||||
foreach (var child in Children.OfType<Widget>().Reverse())
|
||||
if (child.HandleMouseInputOuter(mi))
|
||||
return true;
|
||||
|
||||
return HandleMouseInput(mi);
|
||||
}
|
||||
|
||||
// Hack: Don't eat mouse input that others want
|
||||
// TODO: Solve this properly
|
||||
public virtual bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
// Apply any special logic added by delegates; they return true if they caught the input
|
||||
if (mi.Event == MouseInputEvent.Down && OnMouseDown(mi)) return true;
|
||||
if (mi.Event == MouseInputEvent.Up && OnMouseUp(mi)) return true;
|
||||
if (mi.Event == MouseInputEvent.Move)
|
||||
OnMouseMove(mi);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool HandleKeyPressInner(KeyInput e) { return false; }
|
||||
public virtual bool HandleKeyPressOuter(KeyInput e)
|
||||
{
|
||||
if (!IsVisible())
|
||||
return false;
|
||||
|
||||
// Can any of our children handle this?
|
||||
foreach (var child in Children)
|
||||
if (child.HandleKeyPressOuter(e))
|
||||
return true;
|
||||
|
||||
// Do any widgety behavior (enter text etc)
|
||||
var handled = HandleKeyPressInner(e);
|
||||
|
||||
// Apply any special logic added by delegates; they return true if they caught the input
|
||||
if (OnKeyPress(e)) return true;
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
public static bool HandleKeyPress(KeyInput e)
|
||||
{
|
||||
if (SelectedWidget != null)
|
||||
return SelectedWidget.HandleKeyPressOuter(e);
|
||||
|
||||
if (RootWidget.HandleKeyPressOuter(e))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract void DrawInner();
|
||||
|
||||
public virtual void Draw()
|
||||
{
|
||||
if (IsVisible())
|
||||
{
|
||||
DrawInner();
|
||||
foreach (var child in Children)
|
||||
child.Draw();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Tick()
|
||||
{
|
||||
if (IsVisible())
|
||||
foreach (var child in Children)
|
||||
child.Tick();
|
||||
}
|
||||
|
||||
public virtual void AddChild(Widget child)
|
||||
{
|
||||
child.Parent = this;
|
||||
Children.Add( child );
|
||||
}
|
||||
public virtual void RemoveChild(Widget child) { Children.Remove(child); }
|
||||
public virtual void RemoveChildren() { Children.Clear(); }
|
||||
|
||||
public Widget GetWidget(string id)
|
||||
{
|
||||
if (this.Id == id)
|
||||
return this;
|
||||
|
||||
foreach (var child in Children)
|
||||
{
|
||||
var w = child.GetWidget(id);
|
||||
if (w != null)
|
||||
return w;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public T GetWidget<T>(string id) where T : Widget
|
||||
{
|
||||
var widget = GetWidget(id);
|
||||
return (widget != null)? (T) widget : null;
|
||||
}
|
||||
|
||||
public static void CloseWindow()
|
||||
{
|
||||
RootWidget.Children.Remove( WindowList.Pop() );
|
||||
if( WindowList.Count > 0 )
|
||||
rootWidget.Children.Add( WindowList.Peek() );
|
||||
}
|
||||
|
||||
public static Widget OpenWindow( string id )
|
||||
{
|
||||
return OpenWindow( id, new Dictionary<string, object>() );
|
||||
}
|
||||
|
||||
public static Widget OpenWindow(string id, Dictionary<string, object> args )
|
||||
{
|
||||
var window = Game.modData.WidgetLoader.LoadWidget( args, rootWidget, id );
|
||||
if( WindowList.Count > 0 )
|
||||
rootWidget.Children.Remove( WindowList.Peek() );
|
||||
WindowList.Push( window );
|
||||
return window;
|
||||
}
|
||||
|
||||
public static void DoTick()
|
||||
{
|
||||
RootWidget.Tick();
|
||||
}
|
||||
|
||||
public static void DoDraw()
|
||||
{
|
||||
RootWidget.Draw();
|
||||
}
|
||||
}
|
||||
|
||||
public class ContainerWidget : Widget {
|
||||
public Func<string> GetBackground;
|
||||
public string Background = null;
|
||||
|
||||
public ContainerWidget() : base()
|
||||
{
|
||||
GetBackground = () => Background;
|
||||
}
|
||||
|
||||
public ContainerWidget(ContainerWidget other) : base(other)
|
||||
{
|
||||
Background = other.Background;
|
||||
GetBackground = other.GetBackground;
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
var bg = GetBackground();
|
||||
if (bg != null)
|
||||
WidgetUtils.DrawPanel(bg, RenderBounds );
|
||||
}
|
||||
|
||||
public override string GetCursor(int2 pos) { return null; }
|
||||
public override Widget Clone() { return new ContainerWidget(this); }
|
||||
}
|
||||
public interface IWidgetDelegate { }
|
||||
}
|
||||
@@ -1,62 +1,62 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public class WidgetLoader
|
||||
{
|
||||
Dictionary<string, MiniYamlNode> widgets = new Dictionary<string, MiniYamlNode>();
|
||||
|
||||
public WidgetLoader( ModData modData )
|
||||
{
|
||||
foreach( var file in modData.Manifest.ChromeLayout.Select( a => MiniYaml.FromFile( a ) ) )
|
||||
foreach( var w in file )
|
||||
widgets.Add( w.Key.Substring( w.Key.IndexOf( '@' ) + 1 ), w );
|
||||
}
|
||||
|
||||
public Widget LoadWidget( Dictionary<string, object> args, Widget parent, string w )
|
||||
{
|
||||
return LoadWidget( args, parent, widgets[ w ] );
|
||||
}
|
||||
|
||||
public Widget LoadWidget( Dictionary<string, object> args, Widget parent, MiniYamlNode node)
|
||||
{
|
||||
var widget = NewWidget(node.Key, args);
|
||||
|
||||
if (parent != null)
|
||||
parent.AddChild( widget );
|
||||
|
||||
foreach (var child in node.Value.Nodes)
|
||||
if (child.Key != "Children")
|
||||
FieldLoader.LoadField(widget, child.Key, child.Value.Value);
|
||||
|
||||
widget.Initialize();
|
||||
|
||||
foreach (var child in node.Value.Nodes)
|
||||
if (child.Key == "Children")
|
||||
foreach (var c in child.Value.Nodes)
|
||||
LoadWidget( args, widget, c);
|
||||
|
||||
widget.PostInit( args );
|
||||
return widget;
|
||||
}
|
||||
|
||||
Widget NewWidget(string widgetType, Dictionary<string, object> args)
|
||||
{
|
||||
widgetType = widgetType.Split('@')[0];
|
||||
return Game.modData.ObjectCreator.CreateObject<Widget>(widgetType + "Widget", args);
|
||||
}
|
||||
}
|
||||
#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.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public class WidgetLoader
|
||||
{
|
||||
Dictionary<string, MiniYamlNode> widgets = new Dictionary<string, MiniYamlNode>();
|
||||
|
||||
public WidgetLoader( ModData modData )
|
||||
{
|
||||
foreach( var file in modData.Manifest.ChromeLayout.Select( a => MiniYaml.FromFile( a ) ) )
|
||||
foreach( var w in file )
|
||||
widgets.Add( w.Key.Substring( w.Key.IndexOf( '@' ) + 1 ), w );
|
||||
}
|
||||
|
||||
public Widget LoadWidget( Dictionary<string, object> args, Widget parent, string w )
|
||||
{
|
||||
return LoadWidget( args, parent, widgets[ w ] );
|
||||
}
|
||||
|
||||
public Widget LoadWidget( Dictionary<string, object> args, Widget parent, MiniYamlNode node)
|
||||
{
|
||||
var widget = NewWidget(node.Key, args);
|
||||
|
||||
if (parent != null)
|
||||
parent.AddChild( widget );
|
||||
|
||||
foreach (var child in node.Value.Nodes)
|
||||
if (child.Key != "Children")
|
||||
FieldLoader.LoadField(widget, child.Key, child.Value.Value);
|
||||
|
||||
widget.Initialize();
|
||||
|
||||
foreach (var child in node.Value.Nodes)
|
||||
if (child.Key == "Children")
|
||||
foreach (var c in child.Value.Nodes)
|
||||
LoadWidget( args, widget, c);
|
||||
|
||||
widget.PostInit( args );
|
||||
return widget;
|
||||
}
|
||||
|
||||
Widget NewWidget(string widgetType, Dictionary<string, object> args)
|
||||
{
|
||||
widgetType = widgetType.Split('@')[0];
|
||||
return Game.modData.ObjectCreator.CreateObject<Widget>(widgetType + "Widget", args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,155 +1,155 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public static class WidgetUtils
|
||||
{
|
||||
public static Sprite GetChromeImage(World world, string name)
|
||||
{
|
||||
return ChromeProvider.GetImage("chrome-" + world.LocalPlayer.Country.Race, name);
|
||||
}
|
||||
|
||||
public static void DrawRGBA(Sprite s, float2 pos)
|
||||
{
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(s,pos);
|
||||
}
|
||||
|
||||
public static void DrawSHP(Sprite s, float2 pos, WorldRenderer wr)
|
||||
{
|
||||
Game.Renderer.WorldSpriteRenderer.DrawSprite(s,pos, wr, "chrome");
|
||||
}
|
||||
|
||||
public static void DrawPanel(string collection, Rectangle Bounds)
|
||||
{
|
||||
DrawPanelPartial(collection, Bounds, PanelSides.All);
|
||||
}
|
||||
|
||||
public static void FillRectWithSprite(Rectangle r, Sprite s)
|
||||
{
|
||||
for (var x = r.Left; x < r.Right; x += (int)s.size.X)
|
||||
for (var y = r.Top; y < r.Bottom; y += (int)s.size.Y)
|
||||
{
|
||||
var ss = s;
|
||||
var left = new int2(r.Right - x, r.Bottom - y);
|
||||
if (left.X < (int)s.size.X || left.Y < (int)s.size.Y)
|
||||
{
|
||||
Rectangle rr = new Rectangle(s.bounds.Left,s.bounds.Top,Math.Min(left.X,(int)s.size.X),Math.Min(left.Y,(int)s.size.Y));
|
||||
ss = new Sprite(s.sheet,rr,s.channel);
|
||||
}
|
||||
DrawRGBA(ss, new float2(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
public static void FillRectWithColor(Rectangle r, Color c)
|
||||
{
|
||||
Game.Renderer.LineRenderer.FillRect(new RectangleF(
|
||||
Game.viewport.Location.X + r.X,
|
||||
Game.viewport.Location.Y + r.Y,
|
||||
r.Width, r.Height), c);
|
||||
}
|
||||
|
||||
public static int[] GetBorderSizes(string collection)
|
||||
{
|
||||
var images = new[] { "border-t", "border-b", "border-l", "border-r" };
|
||||
var ss = images.Select(i => ChromeProvider.GetImage("dialog4", i)).ToArray();
|
||||
return new[] { (int)ss[0].size.Y, (int)ss[1].size.Y, (int)ss[2].size.X, (int)ss[3].size.X };
|
||||
}
|
||||
|
||||
static bool HasFlags(this PanelSides a, PanelSides b) { return (a & b) == b; }
|
||||
public static Rectangle InflateBy(this Rectangle rect, int l, int t, int r, int b)
|
||||
{
|
||||
return Rectangle.FromLTRB(rect.Left - l, rect.Top - t,
|
||||
rect.Right + r, rect.Bottom + b);
|
||||
}
|
||||
|
||||
public static void DrawPanelPartial(string collection, Rectangle Bounds, PanelSides ps)
|
||||
{
|
||||
var images = new[] { "border-t", "border-b", "border-l", "border-r", "corner-tl", "corner-tr", "corner-bl", "corner-br", "background" };
|
||||
var ss = images.Select(i => ChromeProvider.GetImage(collection, i)).ToArray();
|
||||
|
||||
// Background
|
||||
FillRectWithSprite(new Rectangle(Bounds.Left + (int)ss[2].size.X,
|
||||
Bounds.Top + (int)ss[0].size.Y,
|
||||
Bounds.Right - (int)ss[3].size.X - Bounds.Left - (int)ss[2].size.X,
|
||||
Bounds.Bottom - (int)ss[1].size.Y - Bounds.Top - (int)ss[0].size.Y),
|
||||
ss[8]);
|
||||
|
||||
// Left border
|
||||
if (ps.HasFlags(PanelSides.Left))
|
||||
FillRectWithSprite(new Rectangle(Bounds.Left,
|
||||
Bounds.Top + (int)ss[0].size.Y,
|
||||
(int)ss[2].size.X,
|
||||
Bounds.Bottom - (int)ss[1].size.Y - Bounds.Top - (int)ss[0].size.Y),
|
||||
ss[2]);
|
||||
|
||||
// Right border
|
||||
if (ps.HasFlags(PanelSides.Right))
|
||||
FillRectWithSprite(new Rectangle(Bounds.Right - (int)ss[3].size.X,
|
||||
Bounds.Top + (int)ss[0].size.Y,
|
||||
(int)ss[2].size.X,
|
||||
Bounds.Bottom - (int)ss[1].size.Y - Bounds.Top - (int)ss[0].size.Y),
|
||||
ss[3]);
|
||||
|
||||
// Top border
|
||||
if (ps.HasFlags(PanelSides.Top))
|
||||
FillRectWithSprite(new Rectangle(Bounds.Left + (int)ss[2].size.X,
|
||||
Bounds.Top,
|
||||
Bounds.Right - (int)ss[3].size.X - Bounds.Left - (int)ss[2].size.X,
|
||||
(int)ss[0].size.Y),
|
||||
ss[0]);
|
||||
|
||||
// Bottom border
|
||||
if (ps.HasFlags(PanelSides.Bottom))
|
||||
FillRectWithSprite(new Rectangle(Bounds.Left + (int)ss[2].size.X,
|
||||
Bounds.Bottom - (int)ss[1].size.Y,
|
||||
Bounds.Right - (int)ss[3].size.X - Bounds.Left - (int)ss[2].size.X,
|
||||
(int)ss[0].size.Y),
|
||||
ss[1]);
|
||||
|
||||
if (ps.HasFlags(PanelSides.Left | PanelSides.Top))
|
||||
DrawRGBA(ss[4], new float2(Bounds.Left, Bounds.Top));
|
||||
if (ps.HasFlags(PanelSides.Right | PanelSides.Top))
|
||||
DrawRGBA(ss[5], new float2(Bounds.Right - ss[5].size.X, Bounds.Top));
|
||||
if (ps.HasFlags(PanelSides.Left | PanelSides.Bottom))
|
||||
DrawRGBA(ss[6], new float2(Bounds.Left, Bounds.Bottom - ss[6].size.Y));
|
||||
if (ps.HasFlags(PanelSides.Right | PanelSides.Bottom))
|
||||
DrawRGBA(ss[7], new float2(Bounds.Right - ss[7].size.X, Bounds.Bottom - ss[7].size.Y));
|
||||
}
|
||||
|
||||
|
||||
public static string FormatTime(int ticks)
|
||||
{
|
||||
var seconds = (int)Math.Ceiling(ticks / 25f);
|
||||
var minutes = seconds / 60;
|
||||
|
||||
if (minutes >= 60)
|
||||
return "{0:D}:{1:D2}:{2:D2}".F(minutes / 60, minutes % 60, seconds % 60);
|
||||
else
|
||||
return "{0:D2}:{1:D2}".F(minutes, seconds % 60);
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum PanelSides
|
||||
{
|
||||
Left = 1,
|
||||
Top = 2,
|
||||
Right = 4,
|
||||
Bottom = 8,
|
||||
|
||||
All = Left | Top | Right | Bottom
|
||||
}
|
||||
}
|
||||
#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;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public static class WidgetUtils
|
||||
{
|
||||
public static Sprite GetChromeImage(World world, string name)
|
||||
{
|
||||
return ChromeProvider.GetImage("chrome-" + world.LocalPlayer.Country.Race, name);
|
||||
}
|
||||
|
||||
public static void DrawRGBA(Sprite s, float2 pos)
|
||||
{
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(s,pos);
|
||||
}
|
||||
|
||||
public static void DrawSHP(Sprite s, float2 pos, WorldRenderer wr)
|
||||
{
|
||||
Game.Renderer.WorldSpriteRenderer.DrawSprite(s,pos, wr, "chrome");
|
||||
}
|
||||
|
||||
public static void DrawPanel(string collection, Rectangle Bounds)
|
||||
{
|
||||
DrawPanelPartial(collection, Bounds, PanelSides.All);
|
||||
}
|
||||
|
||||
public static void FillRectWithSprite(Rectangle r, Sprite s)
|
||||
{
|
||||
for (var x = r.Left; x < r.Right; x += (int)s.size.X)
|
||||
for (var y = r.Top; y < r.Bottom; y += (int)s.size.Y)
|
||||
{
|
||||
var ss = s;
|
||||
var left = new int2(r.Right - x, r.Bottom - y);
|
||||
if (left.X < (int)s.size.X || left.Y < (int)s.size.Y)
|
||||
{
|
||||
Rectangle rr = new Rectangle(s.bounds.Left,s.bounds.Top,Math.Min(left.X,(int)s.size.X),Math.Min(left.Y,(int)s.size.Y));
|
||||
ss = new Sprite(s.sheet,rr,s.channel);
|
||||
}
|
||||
DrawRGBA(ss, new float2(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
public static void FillRectWithColor(Rectangle r, Color c)
|
||||
{
|
||||
Game.Renderer.LineRenderer.FillRect(new RectangleF(
|
||||
Game.viewport.Location.X + r.X,
|
||||
Game.viewport.Location.Y + r.Y,
|
||||
r.Width, r.Height), c);
|
||||
}
|
||||
|
||||
public static int[] GetBorderSizes(string collection)
|
||||
{
|
||||
var images = new[] { "border-t", "border-b", "border-l", "border-r" };
|
||||
var ss = images.Select(i => ChromeProvider.GetImage("dialog4", i)).ToArray();
|
||||
return new[] { (int)ss[0].size.Y, (int)ss[1].size.Y, (int)ss[2].size.X, (int)ss[3].size.X };
|
||||
}
|
||||
|
||||
static bool HasFlags(this PanelSides a, PanelSides b) { return (a & b) == b; }
|
||||
public static Rectangle InflateBy(this Rectangle rect, int l, int t, int r, int b)
|
||||
{
|
||||
return Rectangle.FromLTRB(rect.Left - l, rect.Top - t,
|
||||
rect.Right + r, rect.Bottom + b);
|
||||
}
|
||||
|
||||
public static void DrawPanelPartial(string collection, Rectangle Bounds, PanelSides ps)
|
||||
{
|
||||
var images = new[] { "border-t", "border-b", "border-l", "border-r", "corner-tl", "corner-tr", "corner-bl", "corner-br", "background" };
|
||||
var ss = images.Select(i => ChromeProvider.GetImage(collection, i)).ToArray();
|
||||
|
||||
// Background
|
||||
FillRectWithSprite(new Rectangle(Bounds.Left + (int)ss[2].size.X,
|
||||
Bounds.Top + (int)ss[0].size.Y,
|
||||
Bounds.Right - (int)ss[3].size.X - Bounds.Left - (int)ss[2].size.X,
|
||||
Bounds.Bottom - (int)ss[1].size.Y - Bounds.Top - (int)ss[0].size.Y),
|
||||
ss[8]);
|
||||
|
||||
// Left border
|
||||
if (ps.HasFlags(PanelSides.Left))
|
||||
FillRectWithSprite(new Rectangle(Bounds.Left,
|
||||
Bounds.Top + (int)ss[0].size.Y,
|
||||
(int)ss[2].size.X,
|
||||
Bounds.Bottom - (int)ss[1].size.Y - Bounds.Top - (int)ss[0].size.Y),
|
||||
ss[2]);
|
||||
|
||||
// Right border
|
||||
if (ps.HasFlags(PanelSides.Right))
|
||||
FillRectWithSprite(new Rectangle(Bounds.Right - (int)ss[3].size.X,
|
||||
Bounds.Top + (int)ss[0].size.Y,
|
||||
(int)ss[2].size.X,
|
||||
Bounds.Bottom - (int)ss[1].size.Y - Bounds.Top - (int)ss[0].size.Y),
|
||||
ss[3]);
|
||||
|
||||
// Top border
|
||||
if (ps.HasFlags(PanelSides.Top))
|
||||
FillRectWithSprite(new Rectangle(Bounds.Left + (int)ss[2].size.X,
|
||||
Bounds.Top,
|
||||
Bounds.Right - (int)ss[3].size.X - Bounds.Left - (int)ss[2].size.X,
|
||||
(int)ss[0].size.Y),
|
||||
ss[0]);
|
||||
|
||||
// Bottom border
|
||||
if (ps.HasFlags(PanelSides.Bottom))
|
||||
FillRectWithSprite(new Rectangle(Bounds.Left + (int)ss[2].size.X,
|
||||
Bounds.Bottom - (int)ss[1].size.Y,
|
||||
Bounds.Right - (int)ss[3].size.X - Bounds.Left - (int)ss[2].size.X,
|
||||
(int)ss[0].size.Y),
|
||||
ss[1]);
|
||||
|
||||
if (ps.HasFlags(PanelSides.Left | PanelSides.Top))
|
||||
DrawRGBA(ss[4], new float2(Bounds.Left, Bounds.Top));
|
||||
if (ps.HasFlags(PanelSides.Right | PanelSides.Top))
|
||||
DrawRGBA(ss[5], new float2(Bounds.Right - ss[5].size.X, Bounds.Top));
|
||||
if (ps.HasFlags(PanelSides.Left | PanelSides.Bottom))
|
||||
DrawRGBA(ss[6], new float2(Bounds.Left, Bounds.Bottom - ss[6].size.Y));
|
||||
if (ps.HasFlags(PanelSides.Right | PanelSides.Bottom))
|
||||
DrawRGBA(ss[7], new float2(Bounds.Right - ss[7].size.X, Bounds.Bottom - ss[7].size.Y));
|
||||
}
|
||||
|
||||
|
||||
public static string FormatTime(int ticks)
|
||||
{
|
||||
var seconds = (int)Math.Ceiling(ticks / 25f);
|
||||
var minutes = seconds / 60;
|
||||
|
||||
if (minutes >= 60)
|
||||
return "{0:D}:{1:D2}:{2:D2}".F(minutes / 60, minutes % 60, seconds % 60);
|
||||
else
|
||||
return "{0:D2}:{1:D2}".F(minutes, seconds % 60);
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum PanelSides
|
||||
{
|
||||
Left = 1,
|
||||
Top = 2,
|
||||
Right = 4,
|
||||
Bottom = 8,
|
||||
|
||||
All = Left | Top | Right | Bottom
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* 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 LICENSE.
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Orders;
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Orders;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
@@ -21,12 +21,12 @@ namespace OpenRA.Widgets
|
||||
public class WorldInteractionControllerWidget : Widget
|
||||
{
|
||||
readonly World world;
|
||||
readonly WorldRenderer worldRenderer;
|
||||
[ObjectCreator.UseCtor]
|
||||
public WorldInteractionControllerWidget([ObjectCreator.Param] World world, [ObjectCreator.Param] WorldRenderer worldRenderer)
|
||||
{
|
||||
readonly WorldRenderer worldRenderer;
|
||||
[ObjectCreator.UseCtor]
|
||||
public WorldInteractionControllerWidget([ObjectCreator.Param] World world, [ObjectCreator.Param] WorldRenderer worldRenderer)
|
||||
{
|
||||
this.world = world;
|
||||
this.worldRenderer = worldRenderer;
|
||||
this.worldRenderer = worldRenderer;
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
@@ -95,7 +95,7 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
if (world.OrderGenerator == null) return;
|
||||
|
||||
var orders = world.OrderGenerator.Order(world, xy.ToInt2(), mi).ToArray();
|
||||
var orders = world.OrderGenerator.Order(world, xy.ToInt2(), mi).ToArray();
|
||||
orders.Do( o => world.IssueOrder( o ) );
|
||||
|
||||
// Find an actor with a phrase to say
|
||||
@@ -117,8 +117,8 @@ namespace OpenRA.Widgets
|
||||
|
||||
public override string GetCursor(int2 pos)
|
||||
{
|
||||
return Sync.CheckSyncUnchanged( world, () =>
|
||||
{
|
||||
return Sync.CheckSyncUnchanged( world, () =>
|
||||
{
|
||||
var mi = new MouseInput
|
||||
{
|
||||
Location = pos,
|
||||
@@ -138,13 +138,13 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
world.Selection.DoControlGroup(world, e.KeyName[0] - '0', e.Modifiers);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool handled = false;
|
||||
|
||||
foreach (var t in world.WorldActor.TraitsImplementing<INotifyKeyPress>())
|
||||
handled = (t.KeyPressed(world.WorldActor, e)) ? true : handled;
|
||||
|
||||
}
|
||||
|
||||
bool handled = false;
|
||||
|
||||
foreach (var t in world.WorldActor.TraitsImplementing<INotifyKeyPress>())
|
||||
handled = (t.KeyPressed(world.WorldActor, e)) ? true : handled;
|
||||
|
||||
if (handled) return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user