remove plenty of redundant junk
This commit is contained in:
@@ -64,10 +64,10 @@ namespace OpenRA.FileFormats
|
|||||||
{
|
{
|
||||||
string[] loc = wp.Value.Value.Split(',');
|
string[] loc = wp.Value.Value.Split(',');
|
||||||
Waypoints.Add(wp.Key, new int2(int.Parse(loc[0]), int.Parse(loc[1])));
|
Waypoints.Add(wp.Key, new int2(int.Parse(loc[0]), int.Parse(loc[1])));
|
||||||
}
|
}
|
||||||
|
|
||||||
Preview = Lazy.New(
|
Preview = Lazy.New(
|
||||||
() => { return new Bitmap(Package.GetContent("preview.png")); }
|
() => new Bitmap(Package.GetContent("preview.png"))
|
||||||
);
|
);
|
||||||
|
|
||||||
Uid = Package.GetContent("map.uid").ReadAllText();
|
Uid = Package.GetContent("map.uid").ReadAllText();
|
||||||
|
|||||||
@@ -18,11 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.IO;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
|
|||||||
@@ -1,10 +1,29 @@
|
|||||||
using System;
|
#region Copyright & License Information
|
||||||
using System.Collections.Generic;
|
/*
|
||||||
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
|
* This file is part of OpenRA.
|
||||||
|
*
|
||||||
|
* OpenRA is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* OpenRA is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using OpenRA.FileFormats;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
namespace OpenRA.Server
|
namespace OpenRA.Server
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
using System.Drawing;
|
|
||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
@@ -32,10 +31,10 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
public BackgroundWidget() : base() { }
|
public BackgroundWidget() : base() { }
|
||||||
|
|
||||||
public BackgroundWidget(Widget other)
|
protected BackgroundWidget(BackgroundWidget other)
|
||||||
: base(other)
|
: base(other)
|
||||||
{
|
{
|
||||||
Background = (other as BackgroundWidget).Background;
|
Background = other.Background;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Widget Clone() { return new BackgroundWidget(this); }
|
public override Widget Clone() { return new BackgroundWidget(this); }
|
||||||
|
|||||||
@@ -18,15 +18,14 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using OpenRA;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
using OpenRA.Graphics;
|
|
||||||
using OpenRA.FileFormats;
|
|
||||||
using OpenRA.Orders;
|
|
||||||
using System;
|
using System;
|
||||||
|
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
|
namespace OpenRA.Widgets
|
||||||
{
|
{
|
||||||
@@ -52,14 +51,6 @@ namespace OpenRA.Widgets
|
|||||||
List<string> visibleTabs = new List<string>();
|
List<string> visibleTabs = new List<string>();
|
||||||
|
|
||||||
public BuildPaletteWidget() : base() { }
|
public BuildPaletteWidget() : base() { }
|
||||||
|
|
||||||
public BuildPaletteWidget(Widget other)
|
|
||||||
: base(other)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException("Why are you Cloning BuildPalette?");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Widget Clone() { return new BuildPaletteWidget(this); }
|
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,8 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Drawing;
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
namespace OpenRA.Widgets
|
namespace OpenRA.Widgets
|
||||||
{
|
{
|
||||||
@@ -30,45 +30,45 @@ namespace OpenRA.Widgets
|
|||||||
public bool Depressed = false;
|
public bool Depressed = false;
|
||||||
public int VisualHeight = 1;
|
public int VisualHeight = 1;
|
||||||
public Func<string> GetText;
|
public Func<string> GetText;
|
||||||
|
|
||||||
public ButtonWidget()
|
public ButtonWidget()
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
GetText = () => { return Text; };
|
GetText = () => { return Text; };
|
||||||
}
|
}
|
||||||
|
|
||||||
public ButtonWidget(Widget widget)
|
protected ButtonWidget(ButtonWidget widget)
|
||||||
:base(widget)
|
: base(widget)
|
||||||
{
|
{
|
||||||
Text = (widget as ButtonWidget).Text;
|
Text = widget.Text;
|
||||||
Depressed = (widget as ButtonWidget).Depressed;
|
Depressed = widget.Depressed;
|
||||||
VisualHeight = (widget as ButtonWidget).VisualHeight;
|
VisualHeight = widget.VisualHeight;
|
||||||
GetText = (widget as ButtonWidget).GetText;
|
GetText = widget.GetText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool LoseFocus (MouseInput mi)
|
public override bool LoseFocus(MouseInput mi)
|
||||||
{
|
{
|
||||||
Depressed = false;
|
Depressed = false;
|
||||||
return base.LoseFocus(mi);
|
return base.LoseFocus(mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi)
|
public override bool HandleInput(MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Only fire the onMouseUp order if we successfully lost focus, and were pressed
|
// Only fire the onMouseUp order if we successfully lost focus, and were pressed
|
||||||
if (Focused && mi.Event == MouseInputEvent.Up)
|
if (Focused && mi.Event == MouseInputEvent.Up)
|
||||||
{
|
{
|
||||||
var wasPressed = Depressed;
|
var wasPressed = Depressed;
|
||||||
return (LoseFocus(mi) && wasPressed);
|
return (LoseFocus(mi) && wasPressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mi.Event == MouseInputEvent.Down)
|
if (mi.Event == MouseInputEvent.Down)
|
||||||
Depressed = true;
|
Depressed = true;
|
||||||
else if (mi.Event == MouseInputEvent.Move && Focused)
|
else if (mi.Event == MouseInputEvent.Move && Focused)
|
||||||
Depressed = RenderBounds.Contains(mi.Location.X,mi.Location.Y);
|
Depressed = RenderBounds.Contains(mi.Location.X, mi.Location.Y);
|
||||||
|
|
||||||
return Depressed;
|
return Depressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,19 +76,16 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont;
|
var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont;
|
||||||
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
|
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
|
||||||
WidgetUtils.DrawPanel(Depressed ? "dialog3" : "dialog2", RenderBounds );
|
WidgetUtils.DrawPanel(Depressed ? "dialog3" : "dialog2", RenderBounds);
|
||||||
|
|
||||||
var text = GetText();
|
var text = GetText();
|
||||||
font.DrawText(text,
|
font.DrawText(text,
|
||||||
new int2( RenderOrigin.X + Bounds.Width / 2, RenderOrigin.Y + Bounds.Height / 2)
|
new int2(RenderOrigin.X + Bounds.Width / 2, RenderOrigin.Y + Bounds.Height / 2)
|
||||||
- new int2(font.Measure(text).X / 2,
|
- new int2(font.Measure(text).X / 2,
|
||||||
font.Measure(text).Y / 2) + stateOffset, Color.White);
|
font.Measure(text).Y / 2) + stateOffset, Color.White);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Widget Clone()
|
public override Widget Clone() { return new ButtonWidget(this); }
|
||||||
{
|
|
||||||
return new ButtonWidget(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,69 +16,68 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using OpenRA.FileFormats;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System;
|
namespace OpenRA.Widgets
|
||||||
|
{
|
||||||
namespace OpenRA.Widgets
|
class ChatDisplayWidget : Widget
|
||||||
{
|
{
|
||||||
class ChatDisplayWidget : Widget
|
const int logLength = 10;
|
||||||
{
|
public string Notification = "";
|
||||||
const int logLength = 10;
|
|
||||||
public string Notification = "";
|
public List<ChatLine> recentLines = new List<ChatLine>();
|
||||||
|
|
||||||
public List<ChatLine> recentLines = new List<ChatLine>();
|
public ChatDisplayWidget()
|
||||||
|
: base() { }
|
||||||
public ChatDisplayWidget()
|
|
||||||
: base() {}
|
protected ChatDisplayWidget(Widget widget)
|
||||||
|
: base(widget) { }
|
||||||
public ChatDisplayWidget(Widget widget)
|
|
||||||
:base(widget) {}
|
public override void DrawInner(World world)
|
||||||
|
{
|
||||||
public override void DrawInner(World world)
|
var pos = RenderOrigin;
|
||||||
{
|
var chatLogArea = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
|
||||||
var pos = RenderOrigin;
|
var chatpos = new int2(chatLogArea.X + 10, chatLogArea.Bottom - 6);
|
||||||
var chatLogArea = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
|
WidgetUtils.DrawPanel("dialog3", chatLogArea);
|
||||||
var chatpos = new int2(chatLogArea.X + 10, chatLogArea.Bottom - 6);
|
|
||||||
WidgetUtils.DrawPanel("dialog3", chatLogArea);
|
var renderer = Game.chrome.renderer;
|
||||||
|
var font = renderer.RegularFont;
|
||||||
var renderer = Game.chrome.renderer;
|
|
||||||
var font = renderer.RegularFont;
|
renderer.Device.EnableScissor(chatLogArea.Left, chatLogArea.Top, chatLogArea.Width, chatLogArea.Height);
|
||||||
|
foreach (var line in recentLines.AsEnumerable().Reverse())
|
||||||
renderer.Device.EnableScissor(chatLogArea.Left, chatLogArea.Top, chatLogArea.Width, chatLogArea.Height);
|
{
|
||||||
foreach (var line in recentLines.AsEnumerable().Reverse())
|
chatpos.Y -= 20;
|
||||||
{
|
var owner = line.Owner + ":";
|
||||||
chatpos.Y -= 20;
|
var inset = font.Measure(owner).X + 10;
|
||||||
var owner = line.Owner + ":";
|
font.DrawText(owner, chatpos, line.Color);
|
||||||
var inset = font.Measure(owner).X + 10;
|
font.DrawText(line.Text, chatpos + new int2(inset, 0), Color.White);
|
||||||
font.DrawText(owner, chatpos, line.Color);
|
}
|
||||||
font.DrawText(line.Text, chatpos + new int2(inset, 0), Color.White);
|
|
||||||
}
|
renderer.RgbaSpriteRenderer.Flush();
|
||||||
|
renderer.Device.DisableScissor();
|
||||||
renderer.RgbaSpriteRenderer.Flush();
|
}
|
||||||
renderer.Device.DisableScissor();
|
|
||||||
}
|
public void AddLine(Color c, string from, string text)
|
||||||
|
{
|
||||||
public void AddLine(Color c, string from, string text)
|
recentLines.Add(new ChatLine { Color = c, Owner = from, Text = text });
|
||||||
{
|
|
||||||
recentLines.Add(new ChatLine { Color = c, Owner = from, Text = text });
|
if (Notification != null)
|
||||||
|
Sound.Play(Notification);
|
||||||
if (Notification != null)
|
|
||||||
Sound.Play(Notification);
|
while (recentLines.Count > logLength) recentLines.RemoveAt(0);
|
||||||
|
}
|
||||||
while (recentLines.Count > logLength) recentLines.RemoveAt(0);
|
|
||||||
}
|
public override Widget Clone() { return new ChatDisplayWidget(this); }
|
||||||
|
}
|
||||||
public override Widget Clone()
|
|
||||||
{
|
class ChatLine
|
||||||
return new ChatDisplayWidget(this);
|
{
|
||||||
}
|
public Color Color = Color.White;
|
||||||
}
|
public string Owner, Text;
|
||||||
class ChatLine { public Color Color = Color.White; public string Owner, Text; public bool wrapped = false; }
|
public bool wrapped = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -56,15 +56,16 @@ namespace OpenRA.Widgets
|
|||||||
Game.chrome.lineRenderer.Flush();
|
Game.chrome.lineRenderer.Flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi) { return true; }
|
public override bool HandleInput(MouseInput mi) { return true; }
|
||||||
|
|
||||||
public CheckboxWidget() : base() { }
|
public CheckboxWidget() : base() { }
|
||||||
|
|
||||||
public CheckboxWidget(Widget other)
|
protected CheckboxWidget(CheckboxWidget other)
|
||||||
: base(other)
|
: base(other)
|
||||||
{
|
{
|
||||||
Text = (other as CheckboxWidget).Text;
|
Text = other.Text;
|
||||||
Checked = (other as CheckboxWidget).Checked;
|
Checked = other.Checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Widget Clone() { return new CheckboxWidget(this); }
|
public override Widget Clone() { return new CheckboxWidget(this); }
|
||||||
|
|||||||
@@ -19,36 +19,37 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
||||||
namespace OpenRA.Widgets
|
namespace OpenRA.Widgets
|
||||||
{
|
{
|
||||||
class ColorBlockWidget : Widget
|
class ColorBlockWidget : Widget
|
||||||
{
|
{
|
||||||
public Func<Color> GetColor;
|
public Func<Color> GetColor;
|
||||||
|
|
||||||
public ColorBlockWidget()
|
public ColorBlockWidget()
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
GetColor = () => Color.White;
|
GetColor = () => Color.White;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColorBlockWidget(Widget widget)
|
protected ColorBlockWidget(ColorBlockWidget widget)
|
||||||
:base(widget)
|
: base(widget)
|
||||||
{
|
{
|
||||||
GetColor = (widget as ColorBlockWidget).GetColor;
|
GetColor = widget.GetColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Widget Clone()
|
public override Widget Clone()
|
||||||
{
|
{
|
||||||
return new ColorBlockWidget(this);
|
return new ColorBlockWidget(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawInner(World world)
|
public override void DrawInner(World world)
|
||||||
{
|
{
|
||||||
var pos = RenderOrigin;
|
var pos = RenderOrigin;
|
||||||
var paletteRect = new RectangleF(pos.X + Game.viewport.Location.X, pos.Y + Game.viewport.Location.Y, Bounds.Width, Bounds.Height);
|
var paletteRect = new RectangleF(pos.X + Game.viewport.Location.X,
|
||||||
Game.chrome.lineRenderer.FillRect(paletteRect, GetColor());
|
pos.Y + Game.viewport.Location.Y, Bounds.Width, Bounds.Height);
|
||||||
}
|
Game.chrome.lineRenderer.FillRect(paletteRect, GetColor());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,27 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
|
* This file is part of OpenRA.
|
||||||
|
*
|
||||||
|
* OpenRA is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* OpenRA is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Widgets.Delegates
|
namespace OpenRA.Widgets.Delegates
|
||||||
|
|||||||
@@ -16,11 +16,8 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
using System;
|
|
||||||
using OpenRA.FileFormats;
|
|
||||||
using OpenRA.Support;
|
|
||||||
|
|
||||||
namespace OpenRA.Widgets.Delegates
|
namespace OpenRA.Widgets.Delegates
|
||||||
{
|
{
|
||||||
public class IngameChromeDelegate : IWidgetDelegate
|
public class IngameChromeDelegate : IWidgetDelegate
|
||||||
|
|||||||
@@ -18,76 +18,77 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
namespace OpenRA.Widgets.Delegates
|
namespace OpenRA.Widgets.Delegates
|
||||||
{
|
{
|
||||||
public class LobbyDelegate : IWidgetDelegate
|
public class LobbyDelegate : IWidgetDelegate
|
||||||
{
|
{
|
||||||
Widget Players, LocalPlayerTemplate, RemotePlayerTemplate;
|
Widget Players, LocalPlayerTemplate, RemotePlayerTemplate;
|
||||||
|
|
||||||
Dictionary<string,string> CountryNames;
|
Dictionary<string, string> CountryNames;
|
||||||
|
|
||||||
string MapUid;
|
string MapUid;
|
||||||
MapStub Map;
|
MapStub Map;
|
||||||
public LobbyDelegate()
|
public LobbyDelegate()
|
||||||
{
|
{
|
||||||
Game.LobbyInfoChanged += UpdateCurrentMap;
|
Game.LobbyInfoChanged += UpdateCurrentMap;
|
||||||
UpdateCurrentMap();
|
UpdateCurrentMap();
|
||||||
|
|
||||||
var r = Chrome.rootWidget;
|
var r = Chrome.rootWidget;
|
||||||
var lobby = r.GetWidget("SERVER_LOBBY");
|
var lobby = r.GetWidget("SERVER_LOBBY");
|
||||||
Players = Chrome.rootWidget.GetWidget("SERVER_LOBBY").GetWidget("PLAYERS");
|
Players = Chrome.rootWidget.GetWidget("SERVER_LOBBY").GetWidget("PLAYERS");
|
||||||
LocalPlayerTemplate = Players.GetWidget("TEMPLATE_LOCAL");
|
LocalPlayerTemplate = Players.GetWidget("TEMPLATE_LOCAL");
|
||||||
RemotePlayerTemplate = Players.GetWidget("TEMPLATE_REMOTE");
|
RemotePlayerTemplate = Players.GetWidget("TEMPLATE_REMOTE");
|
||||||
|
|
||||||
|
|
||||||
var map = lobby.GetWidget<MapPreviewWidget>("LOBBY_MAP_PREVIEW");
|
var mapPreview = lobby.GetWidget<MapPreviewWidget>("LOBBY_MAP_PREVIEW");
|
||||||
map.Map = () => {return Map;};
|
mapPreview.Map = () => Map;
|
||||||
map.OnSpawnClick = sp =>
|
mapPreview.OnSpawnClick = sp =>
|
||||||
{
|
{
|
||||||
if (Game.LocalClient.State == Session.ClientState.Ready) return;
|
if (Game.LocalClient.State == Session.ClientState.Ready) return;
|
||||||
var owned = Game.LobbyInfo.Clients.Any(c => c.SpawnPoint == sp);
|
var owned = Game.LobbyInfo.Clients.Any(c => c.SpawnPoint == sp);
|
||||||
if (sp == 0 || !owned)
|
if (sp == 0 || !owned)
|
||||||
Game.IssueOrder(Order.Command("spawn {0}".F(sp)));
|
Game.IssueOrder(Order.Command("spawn {0}".F(sp)));
|
||||||
};
|
};
|
||||||
|
|
||||||
map.SpawnColors = () =>
|
mapPreview.SpawnColors = () =>
|
||||||
{
|
{
|
||||||
var spawns = Map.SpawnPoints;
|
var spawns = Map.SpawnPoints;
|
||||||
var playerColors = Game.world.PlayerColors();
|
var playerColors = Game.world.PlayerColors();
|
||||||
var sc = new Dictionary<int2,Color>();
|
var sc = new Dictionary<int2, Color>();
|
||||||
|
|
||||||
for (int i = 1; i <= spawns.Count(); i++)
|
for (int i = 1; i <= spawns.Count(); i++)
|
||||||
{
|
{
|
||||||
var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i);
|
var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i);
|
||||||
if (client == null)
|
if (client == null)
|
||||||
continue;
|
continue;
|
||||||
sc.Add(spawns.ElementAt(i-1),playerColors[client.PaletteIndex % playerColors.Count()].Color);
|
sc.Add(spawns.ElementAt(i - 1), playerColors[client.PaletteIndex % playerColors.Count()].Color);
|
||||||
}
|
}
|
||||||
return sc;
|
return sc;
|
||||||
};
|
};
|
||||||
|
|
||||||
CountryNames = Rules.Info["world"].Traits.WithInterface<OpenRA.Traits.CountryInfo>().ToDictionary(a => a.Race, a => a.Name);
|
CountryNames = Rules.Info["world"].Traits.WithInterface<OpenRA.Traits.CountryInfo>().ToDictionary(a => a.Race, a => a.Name);
|
||||||
CountryNames.Add("random", "Random");
|
CountryNames.Add("random", "Random");
|
||||||
|
|
||||||
var mapButton = lobby.GetWidget("CHANGEMAP_BUTTON");
|
var mapButton = lobby.GetWidget("CHANGEMAP_BUTTON");
|
||||||
mapButton.OnMouseUp = mi => {
|
mapButton.OnMouseUp = mi =>
|
||||||
r.GetWidget("MAP_CHOOSER").SpecialOneArg(MapUid);
|
{
|
||||||
r.OpenWindow("MAP_CHOOSER");
|
r.GetWidget("MAP_CHOOSER").SpecialOneArg(MapUid);
|
||||||
return true;
|
r.OpenWindow("MAP_CHOOSER");
|
||||||
};
|
return true;
|
||||||
|
};
|
||||||
mapButton.IsVisible = () => mapButton.Visible && Game.IsHost;
|
|
||||||
|
mapButton.IsVisible = () => mapButton.Visible && Game.IsHost;
|
||||||
var disconnectButton = lobby.GetWidget("DISCONNECT_BUTTON");
|
|
||||||
disconnectButton.OnMouseUp = mi => {
|
var disconnectButton = lobby.GetWidget("DISCONNECT_BUTTON");
|
||||||
Game.Disconnect();
|
disconnectButton.OnMouseUp = mi =>
|
||||||
return true;
|
{
|
||||||
|
Game.Disconnect();
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
var lockTeamsCheckbox = lobby.GetWidget<CheckboxWidget>("LOCKTEAMS_CHECKBOX");
|
var lockTeamsCheckbox = lobby.GetWidget<CheckboxWidget>("LOCKTEAMS_CHECKBOX");
|
||||||
@@ -99,186 +100,186 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
Game.IssueOrder(Order.Command(
|
Game.IssueOrder(Order.Command(
|
||||||
"lockteams {0}".F(!Game.LobbyInfo.GlobalSettings.LockTeams)));
|
"lockteams {0}".F(!Game.LobbyInfo.GlobalSettings.LockTeams)));
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
Game.LobbyInfoChanged += UpdatePlayerList;
|
Game.LobbyInfoChanged += UpdatePlayerList;
|
||||||
Game.AddChatLine += (c,n,s) => lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").AddLine(c,n,s);
|
Game.AddChatLine += (c, n, s) => lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").AddLine(c, n, s);
|
||||||
|
|
||||||
bool teamChat = false;
|
bool teamChat = false;
|
||||||
var chatLabel = lobby.GetWidget<LabelWidget>("LABEL_CHATTYPE");
|
var chatLabel = lobby.GetWidget<LabelWidget>("LABEL_CHATTYPE");
|
||||||
var chatTextField = lobby.GetWidget<TextFieldWidget>("CHAT_TEXTFIELD");
|
var chatTextField = lobby.GetWidget<TextFieldWidget>("CHAT_TEXTFIELD");
|
||||||
chatTextField.OnEnterKey = () =>
|
chatTextField.OnEnterKey = () =>
|
||||||
{
|
{
|
||||||
if (chatTextField.Text.Length == 0)
|
if (chatTextField.Text.Length == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
var order = (teamChat) ? Order.TeamChat( chatTextField.Text ) : Order.Chat( chatTextField.Text );
|
var order = (teamChat) ? Order.TeamChat(chatTextField.Text) : Order.Chat(chatTextField.Text);
|
||||||
Game.IssueOrder( order );
|
Game.IssueOrder(order);
|
||||||
chatTextField.Text = "";
|
chatTextField.Text = "";
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
chatTextField.OnTabKey = () =>
|
chatTextField.OnTabKey = () =>
|
||||||
{
|
{
|
||||||
teamChat ^= true;
|
teamChat ^= true;
|
||||||
chatLabel.Text = (teamChat) ? "Team:" : "Chat:";
|
chatLabel.Text = (teamChat) ? "Team:" : "Chat:";
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateCurrentMap()
|
void UpdateCurrentMap()
|
||||||
{
|
{
|
||||||
if (MapUid == Game.LobbyInfo.GlobalSettings.Map) return;
|
if (MapUid == Game.LobbyInfo.GlobalSettings.Map) return;
|
||||||
MapUid = Game.LobbyInfo.GlobalSettings.Map;
|
MapUid = Game.LobbyInfo.GlobalSettings.Map;
|
||||||
Map = Game.AvailableMaps[ MapUid ];
|
Map = Game.AvailableMaps[MapUid];
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdatePlayerList()
|
void UpdatePlayerList()
|
||||||
{
|
{
|
||||||
// This causes problems for people who are in the process of editing their names (the widgets vanish from beneath them)
|
// This causes problems for people who are in the process of editing their names (the widgets vanish from beneath them)
|
||||||
// Todo: handle this nicer
|
// Todo: handle this nicer
|
||||||
Players.Children.Clear();
|
Players.Children.Clear();
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
foreach(var client in Game.LobbyInfo.Clients)
|
foreach (var client in Game.LobbyInfo.Clients)
|
||||||
{
|
{
|
||||||
var c = client;
|
var c = client;
|
||||||
Widget template;
|
Widget template;
|
||||||
|
|
||||||
if(client.Index == Game.LocalClient.Index && c.State != Session.ClientState.Ready)
|
if (client.Index == Game.LocalClient.Index && c.State != Session.ClientState.Ready)
|
||||||
{
|
{
|
||||||
template = LocalPlayerTemplate.Clone();
|
template = LocalPlayerTemplate.Clone();
|
||||||
var name = template.GetWidget<TextFieldWidget>("NAME");
|
var name = template.GetWidget<TextFieldWidget>("NAME");
|
||||||
name.Text = c.Name;
|
name.Text = c.Name;
|
||||||
name.OnEnterKey = () =>
|
name.OnEnterKey = () =>
|
||||||
{
|
{
|
||||||
name.Text = name.Text.Trim();
|
name.Text = name.Text.Trim();
|
||||||
if (name.Text.Length == 0)
|
if (name.Text.Length == 0)
|
||||||
name.Text = c.Name;
|
name.Text = c.Name;
|
||||||
|
|
||||||
name.LoseFocus();
|
name.LoseFocus();
|
||||||
if (name.Text == c.Name)
|
if (name.Text == c.Name)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Game.IssueOrder(Order.Command( "name "+name.Text ));
|
Game.IssueOrder(Order.Command("name " + name.Text));
|
||||||
Game.Settings.PlayerName = name.Text;
|
Game.Settings.PlayerName = name.Text;
|
||||||
Game.Settings.Save();
|
Game.Settings.Save();
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
name.OnLoseFocus = () => name.OnEnterKey();
|
name.OnLoseFocus = () => name.OnEnterKey();
|
||||||
|
|
||||||
var color = template.GetWidget<ButtonWidget>("COLOR");
|
var color = template.GetWidget<ButtonWidget>("COLOR");
|
||||||
color.OnMouseUp = CyclePalette;
|
color.OnMouseUp = CyclePalette;
|
||||||
|
|
||||||
var colorBlock = color.GetWidget<ColorBlockWidget>("COLORBLOCK");
|
var colorBlock = color.GetWidget<ColorBlockWidget>("COLORBLOCK");
|
||||||
colorBlock.GetColor = () => Game.world.PlayerColors()[c.PaletteIndex % Game.world.PlayerColors().Count].Color;
|
colorBlock.GetColor = () => Game.world.PlayerColors()[c.PaletteIndex % Game.world.PlayerColors().Count].Color;
|
||||||
|
|
||||||
var faction = template.GetWidget<ButtonWidget>("FACTION");
|
var faction = template.GetWidget<ButtonWidget>("FACTION");
|
||||||
faction.OnMouseUp = CycleRace;
|
faction.OnMouseUp = CycleRace;
|
||||||
var factionname = faction.GetWidget<LabelWidget>("FACTIONNAME");
|
var factionname = faction.GetWidget<LabelWidget>("FACTIONNAME");
|
||||||
factionname.GetText = () => CountryNames[c.Country];
|
factionname.GetText = () => CountryNames[c.Country];
|
||||||
var factionflag = faction.GetWidget<ImageWidget>("FACTIONFLAG");
|
var factionflag = faction.GetWidget<ImageWidget>("FACTIONFLAG");
|
||||||
factionflag.GetImageName = () => c.Country;
|
factionflag.GetImageName = () => c.Country;
|
||||||
factionflag.GetImageCollection = () => "flags";
|
factionflag.GetImageCollection = () => "flags";
|
||||||
|
|
||||||
var team = template.GetWidget<ButtonWidget>("TEAM");
|
var team = template.GetWidget<ButtonWidget>("TEAM");
|
||||||
team.OnMouseUp = CycleTeam;
|
team.OnMouseUp = CycleTeam;
|
||||||
team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
|
team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
|
||||||
|
|
||||||
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
||||||
status.Checked = () => c.State == Session.ClientState.Ready;
|
status.Checked = () => c.State == Session.ClientState.Ready;
|
||||||
status.OnMouseDown = CycleReady;
|
status.OnMouseDown = CycleReady;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
template = RemotePlayerTemplate.Clone();
|
template = RemotePlayerTemplate.Clone();
|
||||||
template.GetWidget<LabelWidget>("NAME").GetText = () => c.Name;
|
template.GetWidget<LabelWidget>("NAME").GetText = () => c.Name;
|
||||||
var color = template.GetWidget<ColorBlockWidget>("COLOR");
|
var color = template.GetWidget<ColorBlockWidget>("COLOR");
|
||||||
color.GetColor = () => Game.world.PlayerColors()[c.PaletteIndex % Game.world.PlayerColors().Count].Color;
|
color.GetColor = () => Game.world.PlayerColors()[c.PaletteIndex % Game.world.PlayerColors().Count].Color;
|
||||||
|
|
||||||
var faction = template.GetWidget<LabelWidget>("FACTION");
|
var faction = template.GetWidget<LabelWidget>("FACTION");
|
||||||
var factionname = faction.GetWidget<LabelWidget>("FACTIONNAME");
|
var factionname = faction.GetWidget<LabelWidget>("FACTIONNAME");
|
||||||
factionname.GetText = () => CountryNames[c.Country];
|
factionname.GetText = () => CountryNames[c.Country];
|
||||||
var factionflag = faction.GetWidget<ImageWidget>("FACTIONFLAG");
|
var factionflag = faction.GetWidget<ImageWidget>("FACTIONFLAG");
|
||||||
factionflag.GetImageName = () => c.Country;
|
factionflag.GetImageName = () => c.Country;
|
||||||
factionflag.GetImageCollection = () => "flags";
|
factionflag.GetImageCollection = () => "flags";
|
||||||
|
|
||||||
var team = template.GetWidget<LabelWidget>("TEAM");
|
var team = template.GetWidget<LabelWidget>("TEAM");
|
||||||
team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
|
team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
|
||||||
|
|
||||||
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
||||||
status.Checked = () => c.State == Session.ClientState.Ready;
|
status.Checked = () => c.State == Session.ClientState.Ready;
|
||||||
if (client.Index == Game.LocalClient.Index) status.OnMouseDown = CycleReady;
|
if (client.Index == Game.LocalClient.Index) status.OnMouseDown = CycleReady;
|
||||||
}
|
}
|
||||||
|
|
||||||
template.Id = "PLAYER_{0}".F(c.Index);
|
template.Id = "PLAYER_{0}".F(c.Index);
|
||||||
template.Parent = Players;
|
template.Parent = Players;
|
||||||
|
|
||||||
template.Bounds = new Rectangle(0, offset, template.Bounds.Width, template.Bounds.Height);
|
template.Bounds = new Rectangle(0, offset, template.Bounds.Width, template.Bounds.Height);
|
||||||
template.IsVisible = () => true;
|
template.IsVisible = () => true;
|
||||||
Players.AddChild(template);
|
Players.AddChild(template);
|
||||||
|
|
||||||
offset += template.Bounds.Height;
|
offset += template.Bounds.Height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PaletteAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.PaletteIndex != index) && Game.world.PlayerColors()[index % Game.world.PlayerColors().Count].Playable; }
|
bool PaletteAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.PaletteIndex != index) && Game.world.PlayerColors()[index % Game.world.PlayerColors().Count].Playable; }
|
||||||
bool SpawnPointAvailable(int index) { return (index == 0) || Game.LobbyInfo.Clients.All(c => c.SpawnPoint != index); }
|
bool SpawnPointAvailable(int index) { return (index == 0) || Game.LobbyInfo.Clients.All(c => c.SpawnPoint != index); }
|
||||||
|
|
||||||
bool CyclePalette(MouseInput mi)
|
bool CyclePalette(MouseInput mi)
|
||||||
{
|
{
|
||||||
var d = (mi.Button == MouseButton.Left) ? +1 : Game.world.PlayerColors().Count() - 1;
|
var d = (mi.Button == MouseButton.Left) ? +1 : Game.world.PlayerColors().Count() - 1;
|
||||||
|
|
||||||
var newIndex = ((int)Game.LocalClient.PaletteIndex + d) % Game.world.PlayerColors().Count();
|
var newIndex = ((int)Game.LocalClient.PaletteIndex + d) % Game.world.PlayerColors().Count();
|
||||||
|
|
||||||
while (!PaletteAvailable(newIndex) && newIndex != (int)Game.LocalClient.PaletteIndex)
|
while (!PaletteAvailable(newIndex) && newIndex != (int)Game.LocalClient.PaletteIndex)
|
||||||
newIndex = (newIndex + d) % Game.world.PlayerColors().Count();
|
newIndex = (newIndex + d) % Game.world.PlayerColors().Count();
|
||||||
|
|
||||||
Game.IssueOrder(
|
Game.IssueOrder(
|
||||||
Order.Command("pal " + newIndex));
|
Order.Command("pal " + newIndex));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CycleRace(MouseInput mi)
|
bool CycleRace(MouseInput mi)
|
||||||
{
|
{
|
||||||
var countries = CountryNames.Select(a => a.Key);
|
var countries = CountryNames.Select(a => a.Key);
|
||||||
|
|
||||||
if (mi.Button == MouseButton.Right)
|
if (mi.Button == MouseButton.Right)
|
||||||
countries = countries.Reverse();
|
countries = countries.Reverse();
|
||||||
|
|
||||||
var nextCountry = countries
|
var nextCountry = countries
|
||||||
.SkipWhile(c => c != Game.LocalClient.Country)
|
.SkipWhile(c => c != Game.LocalClient.Country)
|
||||||
.Skip(1)
|
.Skip(1)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
if (nextCountry == null)
|
if (nextCountry == null)
|
||||||
nextCountry = countries.First();
|
nextCountry = countries.First();
|
||||||
|
|
||||||
Game.IssueOrder(Order.Command("race " + nextCountry));
|
Game.IssueOrder(Order.Command("race " + nextCountry));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CycleReady(MouseInput mi)
|
bool CycleReady(MouseInput mi)
|
||||||
{
|
{
|
||||||
//HACK: Can't set this as part of the fuction as LocalClient/State not initalised yet
|
//HACK: Can't set this as part of the fuction as LocalClient/State not initalised yet
|
||||||
Chrome.rootWidget.GetWidget("SERVER_LOBBY").GetWidget<ButtonWidget>("CHANGEMAP_BUTTON").Visible
|
Chrome.rootWidget.GetWidget("SERVER_LOBBY").GetWidget<ButtonWidget>("CHANGEMAP_BUTTON").Visible
|
||||||
= (Game.IsHost && Game.LocalClient.State == Session.ClientState.Ready);
|
= (Game.IsHost && Game.LocalClient.State == Session.ClientState.Ready);
|
||||||
Game.IssueOrder(Order.Command("ready"));
|
Game.IssueOrder(Order.Command("ready"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CycleTeam(MouseInput mi)
|
bool CycleTeam(MouseInput mi)
|
||||||
{
|
{
|
||||||
var d = (mi.Button == MouseButton.Left) ? +1 : Game.world.Map.PlayerCount;
|
var d = (mi.Button == MouseButton.Left) ? +1 : Game.world.Map.PlayerCount;
|
||||||
|
|
||||||
var newIndex = (Game.LocalClient.Team + d) % (Game.world.Map.PlayerCount+1);
|
var newIndex = (Game.LocalClient.Team + d) % (Game.world.Map.PlayerCount + 1);
|
||||||
|
|
||||||
Game.IssueOrder(
|
Game.IssueOrder(
|
||||||
Order.Command("team " + newIndex));
|
Order.Command("team " + newIndex));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,9 @@
|
|||||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
using System;
|
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
namespace OpenRA.Widgets.Delegates
|
namespace OpenRA.Widgets.Delegates
|
||||||
{
|
{
|
||||||
public class MainMenuButtonsDelegate : IWidgetDelegate
|
public class MainMenuButtonsDelegate : IWidgetDelegate
|
||||||
@@ -27,10 +28,10 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
{
|
{
|
||||||
// Main menu is the default window
|
// Main menu is the default window
|
||||||
Widget.WindowList.Push("MAINMENU_BG");
|
Widget.WindowList.Push("MAINMENU_BG");
|
||||||
Chrome.rootWidget.GetWidget("MAINMENU_BUTTON_QUIT").OnMouseUp = mi => {Game.Exit(); return true;};
|
Chrome.rootWidget.GetWidget("MAINMENU_BUTTON_QUIT").OnMouseUp = mi => { Game.Exit(); return true; };
|
||||||
|
|
||||||
var version = Chrome.rootWidget.GetWidget("MAINMENU_BG").GetWidget<LabelWidget>("VERSION_STRING");
|
var version = Chrome.rootWidget.GetWidget("MAINMENU_BG").GetWidget<LabelWidget>("VERSION_STRING");
|
||||||
|
|
||||||
if (FileSystem.Exists("VERSION"))
|
if (FileSystem.Exists("VERSION"))
|
||||||
{
|
{
|
||||||
var s = FileSystem.Open("VERSION");
|
var s = FileSystem.Open("VERSION");
|
||||||
|
|||||||
@@ -16,75 +16,75 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
namespace OpenRA.Widgets.Delegates
|
namespace OpenRA.Widgets.Delegates
|
||||||
{
|
{
|
||||||
public class MapChooserDelegate : IWidgetDelegate
|
public class MapChooserDelegate : IWidgetDelegate
|
||||||
{
|
{
|
||||||
MapStub Map = null;
|
MapStub Map = null;
|
||||||
public MapChooserDelegate()
|
public MapChooserDelegate()
|
||||||
{
|
{
|
||||||
var r = Chrome.rootWidget;
|
var r = Chrome.rootWidget;
|
||||||
var bg = r.GetWidget("MAP_CHOOSER");
|
var bg = r.GetWidget("MAP_CHOOSER");
|
||||||
bg.SpecialOneArg = (map) => RefreshMapList(map);
|
bg.SpecialOneArg = (map) => RefreshMapList(map);
|
||||||
var ml = bg.GetWidget<ListBoxWidget>("MAP_LIST");
|
var ml = bg.GetWidget<ListBoxWidget>("MAP_LIST");
|
||||||
|
|
||||||
bg.GetWidget<MapPreviewWidget>("MAPCHOOSER_MAP_PREVIEW").Map = () => {return Map;};
|
bg.GetWidget<MapPreviewWidget>("MAPCHOOSER_MAP_PREVIEW").Map = () => Map;
|
||||||
bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => {return Map.Title;};
|
bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => Map.Title;
|
||||||
bg.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => {return "{0}x{1}".F(Map.Width, Map.Height);};
|
bg.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => "{0}x{1}".F(Map.Width, Map.Height);
|
||||||
bg.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => {return Rules.TileSets[Map.Tileset].Name;};
|
bg.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => Rules.TileSets[Map.Tileset].Name;
|
||||||
bg.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => {return Map.PlayerCount.ToString();};
|
bg.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => Map.PlayerCount.ToString();
|
||||||
|
|
||||||
bg.GetWidget("BUTTON_OK").OnMouseUp = mi => {
|
bg.GetWidget("BUTTON_OK").OnMouseUp = mi =>
|
||||||
Game.IssueOrder(Order.Command("map " + Map.Uid));
|
{
|
||||||
r.CloseWindow();
|
Game.IssueOrder(Order.Command("map " + Map.Uid));
|
||||||
return true;
|
r.CloseWindow();
|
||||||
};
|
return true;
|
||||||
|
};
|
||||||
bg.GetWidget("BUTTON_CANCEL").OnMouseUp = mi => {
|
|
||||||
r.CloseWindow();
|
bg.GetWidget("BUTTON_CANCEL").OnMouseUp = mi =>
|
||||||
return true;
|
{
|
||||||
};
|
r.CloseWindow();
|
||||||
|
return true;
|
||||||
var itemTemplate = ml.GetWidget<LabelWidget>("MAP_TEMPLATE");
|
};
|
||||||
int offset = itemTemplate.Bounds.Y;
|
|
||||||
foreach (var kv in Game.AvailableMaps)
|
var itemTemplate = ml.GetWidget<LabelWidget>("MAP_TEMPLATE");
|
||||||
{
|
int offset = itemTemplate.Bounds.Y;
|
||||||
var map = kv.Value;
|
foreach (var kv in Game.AvailableMaps)
|
||||||
if (!map.Selectable)
|
{
|
||||||
continue;
|
var map = kv.Value;
|
||||||
|
if (!map.Selectable)
|
||||||
var template = itemTemplate.Clone() as LabelWidget;
|
continue;
|
||||||
template.Id = "MAP_{0}".F(map.Uid);
|
|
||||||
template.GetText = () => " "+map.Title;
|
var template = itemTemplate.Clone() as LabelWidget;
|
||||||
template.GetBackground = () => ((Map == map) ? "dialog2" : null);
|
template.Id = "MAP_{0}".F(map.Uid);
|
||||||
template.OnMouseDown = mi => {Map = map; return true;};
|
template.GetText = () => " " + map.Title;
|
||||||
template.Parent = ml;
|
template.GetBackground = () => ((Map == map) ? "dialog2" : null);
|
||||||
|
template.OnMouseDown = mi => { Map = map; return true; };
|
||||||
template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
|
template.Parent = ml;
|
||||||
template.IsVisible = () => true;
|
|
||||||
ml.AddChild(template);
|
template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
|
||||||
|
template.IsVisible = () => true;
|
||||||
offset += template.Bounds.Height;
|
ml.AddChild(template);
|
||||||
ml.ContentHeight += template.Bounds.Height;
|
|
||||||
}
|
offset += template.Bounds.Height;
|
||||||
}
|
ml.ContentHeight += template.Bounds.Height;
|
||||||
|
}
|
||||||
public void RefreshMapList(object uidobj)
|
}
|
||||||
{
|
|
||||||
// Set the default selected map
|
public void RefreshMapList(object uidobj)
|
||||||
var uid = uidobj as string;
|
{
|
||||||
if (uid != null)
|
// Set the default selected map
|
||||||
Map = Game.AvailableMaps[ uid ];
|
var uid = uidobj as string;
|
||||||
else
|
if (uid != null)
|
||||||
Map = Game.AvailableMaps.FirstOrDefault().Value;
|
Map = Game.AvailableMaps[uid];
|
||||||
}
|
else
|
||||||
}
|
Map = Game.AvailableMaps.FirstOrDefault().Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,69 +17,80 @@
|
|||||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
using System;
|
|
||||||
namespace OpenRA.Widgets.Delegates
|
namespace OpenRA.Widgets.Delegates
|
||||||
{
|
{
|
||||||
public class MusicPlayerDelegate : IWidgetDelegate
|
public class MusicPlayerDelegate : IWidgetDelegate
|
||||||
{
|
{
|
||||||
public MusicPlayerDelegate()
|
public MusicPlayerDelegate()
|
||||||
{
|
{
|
||||||
var bg = Chrome.rootWidget.GetWidget("MUSIC_BG");
|
var bg = Chrome.rootWidget.GetWidget("MUSIC_BG");
|
||||||
bg.Visible = Game.Settings.MusicPlayer;
|
bg.Visible = Game.Settings.MusicPlayer;
|
||||||
|
|
||||||
bg.GetWidget("BUTTON_PLAY").OnMouseUp = mi => {
|
bg.GetWidget("BUTTON_PLAY").OnMouseUp = mi =>
|
||||||
if (Sound.MusicStopped)
|
{
|
||||||
Sound.PlayMusic(GetSong());
|
if (Sound.MusicStopped)
|
||||||
Sound.MusicStopped = false;
|
Sound.PlayMusic(GetSong());
|
||||||
Sound.MusicPaused = false;
|
Sound.MusicStopped = false;
|
||||||
bg.GetWidget("BUTTON_PLAY").Visible = false;
|
Sound.MusicPaused = false;
|
||||||
bg.GetWidget("BUTTON_PAUSE").Visible = true;
|
bg.GetWidget("BUTTON_PLAY").Visible = false;
|
||||||
return true;
|
bg.GetWidget("BUTTON_PAUSE").Visible = true;
|
||||||
};
|
return true;
|
||||||
bg.GetWidget("BUTTON_PAUSE").OnMouseUp = mi => {
|
};
|
||||||
Sound.MusicPaused = true;
|
|
||||||
bg.GetWidget("BUTTON_PAUSE").Visible = false;
|
bg.GetWidget("BUTTON_PAUSE").OnMouseUp = mi =>
|
||||||
bg.GetWidget("BUTTON_PLAY").Visible = true;
|
{
|
||||||
return true;
|
Sound.MusicPaused = true;
|
||||||
};
|
bg.GetWidget("BUTTON_PAUSE").Visible = false;
|
||||||
bg.GetWidget("BUTTON_STOP").OnMouseUp = mi => {
|
bg.GetWidget("BUTTON_PLAY").Visible = true;
|
||||||
Sound.MusicStopped = true;
|
return true;
|
||||||
bg.GetWidget("BUTTON_PAUSE").Visible = false;
|
};
|
||||||
bg.GetWidget("BUTTON_PLAY").Visible = true;
|
|
||||||
return true;
|
bg.GetWidget("BUTTON_STOP").OnMouseUp = mi =>
|
||||||
};
|
{
|
||||||
bg.GetWidget("BUTTON_NEXT").OnMouseUp = mi => {
|
Sound.MusicStopped = true;
|
||||||
Sound.PlayMusic(GetNextSong());
|
bg.GetWidget("BUTTON_PAUSE").Visible = false;
|
||||||
Sound.MusicStopped = false;
|
bg.GetWidget("BUTTON_PLAY").Visible = true;
|
||||||
Sound.MusicPaused = false;
|
return true;
|
||||||
bg.GetWidget("BUTTON_PLAY").Visible = false;
|
};
|
||||||
bg.GetWidget("BUTTON_PAUSE").Visible = true;
|
|
||||||
return true;
|
bg.GetWidget("BUTTON_NEXT").OnMouseUp = mi =>
|
||||||
};
|
{
|
||||||
bg.GetWidget("BUTTON_PREV").OnMouseUp = mi => {
|
Sound.PlayMusic(GetNextSong());
|
||||||
Sound.PlayMusic(GetPrevSong());
|
Sound.MusicStopped = false;
|
||||||
Sound.MusicStopped = false;
|
Sound.MusicPaused = false;
|
||||||
Sound.MusicPaused = false;
|
bg.GetWidget("BUTTON_PLAY").Visible = false;
|
||||||
bg.GetWidget("BUTTON_PLAY").Visible = false;
|
bg.GetWidget("BUTTON_PAUSE").Visible = true;
|
||||||
bg.GetWidget("BUTTON_PAUSE").Visible = true;
|
return true;
|
||||||
return true;
|
};
|
||||||
};
|
|
||||||
}
|
bg.GetWidget("BUTTON_PREV").OnMouseUp = mi =>
|
||||||
|
{
|
||||||
string GetNextSong()
|
Sound.PlayMusic(GetPrevSong());
|
||||||
{
|
Sound.MusicStopped = false;
|
||||||
if (!Rules.Music.ContainsKey("allmusic")) return null;
|
Sound.MusicPaused = false;
|
||||||
return Rules.Music["allmusic"].Pool.GetNext();
|
bg.GetWidget("BUTTON_PLAY").Visible = false;
|
||||||
}
|
bg.GetWidget("BUTTON_PAUSE").Visible = true;
|
||||||
string GetPrevSong()
|
return true;
|
||||||
{
|
};
|
||||||
if (!Rules.Music.ContainsKey("allmusic")) return null;
|
}
|
||||||
return Rules.Music["allmusic"].Pool.GetPrev();
|
|
||||||
}
|
string GetNextSong()
|
||||||
string GetSong()
|
{
|
||||||
{
|
if (!Rules.Music.ContainsKey("allmusic")) return null;
|
||||||
if (!Rules.Music.ContainsKey("allmusic")) return null;
|
return Rules.Music["allmusic"].Pool.GetNext();
|
||||||
return Rules.Music["allmusic"].Pool.GetCurrent();
|
}
|
||||||
}
|
|
||||||
|
string GetPrevSong()
|
||||||
|
{
|
||||||
|
if (!Rules.Music.ContainsKey("allmusic")) return null;
|
||||||
|
return Rules.Music["allmusic"].Pool.GetPrev();
|
||||||
|
}
|
||||||
|
|
||||||
|
string GetSong()
|
||||||
|
{
|
||||||
|
if (!Rules.Music.ContainsKey("allmusic")) return null;
|
||||||
|
return Rules.Music["allmusic"].Pool.GetCurrent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,31 +17,28 @@
|
|||||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
using System;
|
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.Support;
|
||||||
using OpenRA.Support;
|
|
||||||
|
namespace OpenRA.Widgets.Delegates
|
||||||
namespace OpenRA.Widgets.Delegates
|
{
|
||||||
{
|
public class PerfDebugDelegate : IWidgetDelegate
|
||||||
public class PerfDebugDelegate : IWidgetDelegate
|
{
|
||||||
{
|
public PerfDebugDelegate()
|
||||||
public PerfDebugDelegate()
|
{
|
||||||
{
|
var r = Chrome.rootWidget;
|
||||||
var r = Chrome.rootWidget;
|
var perfRoot = r.GetWidget("PERF_BG");
|
||||||
var perfRoot = r.GetWidget("PERF_BG");
|
perfRoot.IsVisible = () => perfRoot.Visible && Game.Settings.PerfDebug;
|
||||||
perfRoot.IsVisible = () => {return (perfRoot.Visible && Game.Settings.PerfDebug);};
|
|
||||||
|
// Perf text
|
||||||
// Perf text
|
var perfText = perfRoot.GetWidget<LabelWidget>("TEXT");
|
||||||
var perfText = perfRoot.GetWidget<LabelWidget>("TEXT");
|
perfText.GetText = () => "Render {0} ({5}={2:F1} ms)\nTick {4} ({3:F1} ms)".F(
|
||||||
perfText.GetText = () => {
|
Game.RenderFrame,
|
||||||
return "Render {0} ({5}={2:F1} ms)\nTick {4} ({3:F1} ms)".F(
|
Game.orderManager.FrameNumber,
|
||||||
Game.RenderFrame,
|
PerfHistory.items["render"].LastValue,
|
||||||
Game.orderManager.FrameNumber,
|
PerfHistory.items["tick_time"].LastValue,
|
||||||
PerfHistory.items["render"].LastValue,
|
Game.LocalTick,
|
||||||
PerfHistory.items["tick_time"].LastValue,
|
PerfHistory.items["batches"].LastValue);
|
||||||
Game.LocalTick,
|
}
|
||||||
PerfHistory.items["batches"].LastValue);
|
}
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Server;
|
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
using System;
|
using OpenRA.Server;
|
||||||
|
|
||||||
namespace OpenRA.Widgets.Delegates
|
namespace OpenRA.Widgets.Delegates
|
||||||
{
|
{
|
||||||
@@ -36,10 +35,10 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
|
|
||||||
public ServerBrowserDelegate()
|
public ServerBrowserDelegate()
|
||||||
{
|
{
|
||||||
var r = Chrome.rootWidget;
|
var r = Chrome.rootWidget;
|
||||||
var bg = r.GetWidget("JOINSERVER_BG");
|
var bg = r.GetWidget("JOINSERVER_BG");
|
||||||
var dc = r.GetWidget("DIRECTCONNECT_BG");
|
var dc = r.GetWidget("DIRECTCONNECT_BG");
|
||||||
|
|
||||||
MasterServerQuery.OnComplete += games => RefreshServerList(games);
|
MasterServerQuery.OnComplete += games => RefreshServerList(games);
|
||||||
|
|
||||||
r.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp = mi =>
|
r.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp = mi =>
|
||||||
@@ -56,14 +55,14 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
bg.GetWidget("SERVER_INFO").IsVisible = () => currentServer != null;
|
bg.GetWidget("SERVER_INFO").IsVisible = () => currentServer != null;
|
||||||
var preview = bg.GetWidget<MapPreviewWidget>("MAP_PREVIEW");
|
var preview = bg.GetWidget<MapPreviewWidget>("MAP_PREVIEW");
|
||||||
preview.Map = () => CurrentMap();
|
preview.Map = () => CurrentMap();
|
||||||
preview.IsVisible = () => CurrentMap() != null;
|
preview.IsVisible = () => CurrentMap() != null;
|
||||||
|
|
||||||
bg.GetWidget<LabelWidget>("SERVER_IP").GetText = () => currentServer.Address;
|
bg.GetWidget<LabelWidget>("SERVER_IP").GetText = () => currentServer.Address;
|
||||||
bg.GetWidget<LabelWidget>("SERVER_MODS").GetText = () => string.Join( ",", currentServer.Mods );
|
bg.GetWidget<LabelWidget>("SERVER_MODS").GetText = () => string.Join(",", currentServer.Mods);
|
||||||
bg.GetWidget<LabelWidget>("MAP_TITLE").GetText = () => (CurrentMap() != null) ? CurrentMap().Title : "Unknown";
|
bg.GetWidget<LabelWidget>("MAP_TITLE").GetText = () => (CurrentMap() != null) ? CurrentMap().Title : "Unknown";
|
||||||
bg.GetWidget<LabelWidget>("MAP_PLAYERS").GetText = () =>
|
bg.GetWidget<LabelWidget>("MAP_PLAYERS").GetText = () =>
|
||||||
{
|
{
|
||||||
@@ -71,11 +70,11 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
return "";
|
return "";
|
||||||
string ret = currentServer.Players.ToString();
|
string ret = currentServer.Players.ToString();
|
||||||
if (CurrentMap() != null)
|
if (CurrentMap() != null)
|
||||||
ret += "/"+CurrentMap().PlayerCount.ToString();
|
ret += "/" + CurrentMap().PlayerCount.ToString();
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var sl = bg.GetWidget<ListBoxWidget>("SERVER_LIST");
|
var sl = bg.GetWidget<ListBoxWidget>("SERVER_LIST");
|
||||||
ServerTemplate = sl.GetWidget<LabelWidget>("SERVER_TEMPLATE");
|
ServerTemplate = sl.GetWidget<LabelWidget>("SERVER_TEMPLATE");
|
||||||
|
|
||||||
@@ -101,20 +100,20 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
bg.GetWidget("DIRECTCONNECT_BUTTON").OnMouseUp = mi =>
|
bg.GetWidget("DIRECTCONNECT_BUTTON").OnMouseUp = mi =>
|
||||||
{
|
{
|
||||||
r.CloseWindow();
|
r.CloseWindow();
|
||||||
|
|
||||||
dc.GetWidget<TextFieldWidget>("SERVER_ADDRESS").Text = Game.Settings.LastServer;
|
dc.GetWidget<TextFieldWidget>("SERVER_ADDRESS").Text = Game.Settings.LastServer;
|
||||||
r.OpenWindow("DIRECTCONNECT_BG");
|
r.OpenWindow("DIRECTCONNECT_BG");
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
bg.GetWidget("JOIN_BUTTON").OnMouseUp = mi =>
|
bg.GetWidget("JOIN_BUTTON").OnMouseUp = mi =>
|
||||||
{
|
{
|
||||||
if (currentServer == null)
|
if (currentServer == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Todo: Add an error dialog explaining why we aren't letting them join
|
// Todo: Add an error dialog explaining why we aren't letting them join
|
||||||
// Or even better, reject them server side and display the error in the connection failed dialog.
|
// Or even better, reject them server side and display the error in the connection failed dialog.
|
||||||
|
|
||||||
// Don't bother joining a server with different mods... its only going to crash
|
// Don't bother joining a server with different mods... its only going to crash
|
||||||
if (currentServer.Mods.SymmetricDifference(Game.LobbyInfo.GlobalSettings.Mods).Any())
|
if (currentServer.Mods.SymmetricDifference(Game.LobbyInfo.GlobalSettings.Mods).Any())
|
||||||
{
|
{
|
||||||
@@ -122,56 +121,59 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
System.Console.WriteLine("FIX THIS BUG YOU NOOB!");
|
System.Console.WriteLine("FIX THIS BUG YOU NOOB!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent user joining a full server
|
// Prevent user joining a full server
|
||||||
if (CurrentMap() != null && currentServer.Players >= CurrentMap().PlayerCount)
|
if (CurrentMap() != null && currentServer.Players >= CurrentMap().PlayerCount)
|
||||||
{
|
{
|
||||||
System.Console.WriteLine("Server is full; not connecting");
|
System.Console.WriteLine("Server is full; not connecting");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
r.CloseWindow();
|
r.CloseWindow();
|
||||||
Game.JoinServer(currentServer.Address.Split(':')[0], int.Parse(currentServer.Address.Split(':')[1]));
|
Game.JoinServer(currentServer.Address.Split(':')[0], int.Parse(currentServer.Address.Split(':')[1]));
|
||||||
Game.SetGameId(currentServer.Id);
|
Game.SetGameId(currentServer.Id);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Direct Connect
|
// Direct Connect
|
||||||
dc.GetWidget("JOIN_BUTTON").OnMouseUp = mi => {
|
dc.GetWidget("JOIN_BUTTON").OnMouseUp = mi =>
|
||||||
|
{
|
||||||
|
|
||||||
var address = dc.GetWidget<TextFieldWidget>("SERVER_ADDRESS").Text;
|
var address = dc.GetWidget<TextFieldWidget>("SERVER_ADDRESS").Text;
|
||||||
var cpts = address.Split(':').ToArray();
|
var cpts = address.Split(':').ToArray();
|
||||||
if (cpts.Length != 2)
|
if (cpts.Length != 2)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Game.Settings.LastServer = address;
|
Game.Settings.LastServer = address;
|
||||||
Game.Settings.Save();
|
Game.Settings.Save();
|
||||||
|
|
||||||
r.CloseWindow();
|
r.CloseWindow();
|
||||||
Game.JoinServer(cpts[0], int.Parse(cpts[1]));
|
Game.JoinServer(cpts[0], int.Parse(cpts[1]));
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
dc.GetWidget("CANCEL_BUTTON").OnMouseUp = mi => {
|
dc.GetWidget("CANCEL_BUTTON").OnMouseUp = mi =>
|
||||||
|
{
|
||||||
r.CloseWindow();
|
r.CloseWindow();
|
||||||
return r.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp(mi);
|
return r.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp(mi);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
MapStub CurrentMap()
|
MapStub CurrentMap()
|
||||||
{
|
{
|
||||||
return (currentServer == null || !Game.AvailableMaps.ContainsKey(currentServer.Map)) ? null : Game.AvailableMaps[currentServer.Map];
|
return (currentServer == null || !Game.AvailableMaps.ContainsKey(currentServer.Map))
|
||||||
|
? null : Game.AvailableMaps[currentServer.Map];
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefreshServerList(IEnumerable<GameServer> games)
|
void RefreshServerList(IEnumerable<GameServer> games)
|
||||||
{
|
{
|
||||||
var r = Chrome.rootWidget;
|
var r = Chrome.rootWidget;
|
||||||
var bg = r.GetWidget("JOINSERVER_BG");
|
var bg = r.GetWidget("JOINSERVER_BG");
|
||||||
var sl = bg.GetWidget<ListBoxWidget>("SERVER_LIST");
|
var sl = bg.GetWidget<ListBoxWidget>("SERVER_LIST");
|
||||||
|
|
||||||
sl.Children.Clear();
|
sl.Children.Clear();
|
||||||
currentServer = null;
|
currentServer = null;
|
||||||
|
|
||||||
if (games == null)
|
if (games == null)
|
||||||
{
|
{
|
||||||
r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true;
|
r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true;
|
||||||
@@ -187,26 +189,26 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
}
|
}
|
||||||
|
|
||||||
r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = false;
|
r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = false;
|
||||||
|
|
||||||
int offset = ServerTemplate.Bounds.Y;
|
int offset = ServerTemplate.Bounds.Y;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (var game in games.Where( g => g.State == 1 )) /* only "waiting for players" */
|
foreach (var game in games.Where(g => g.State == 1)) /* only "waiting for players" */
|
||||||
{
|
{
|
||||||
var template = ServerTemplate.Clone() as LabelWidget;
|
var template = ServerTemplate.Clone() as LabelWidget;
|
||||||
template.Id = "JOIN_GAME_{0}".F(i);
|
template.Id = "JOIN_GAME_{0}".F(i);
|
||||||
template.GetText = () => " {0} ({1})".F( /* /8 = hack */
|
template.GetText = () => " {0} ({1})".F( /* /8 = hack */
|
||||||
game.Name,
|
game.Name,
|
||||||
game.Address);
|
game.Address);
|
||||||
template.GetBackground = () => ((currentServer == game) ? "dialog2" : null);
|
template.GetBackground = () => (currentServer == game) ? "dialog2" : null;
|
||||||
template.OnMouseDown = mi => {currentServer = game; return true;};
|
template.OnMouseDown = mi => { currentServer = game; return true; };
|
||||||
template.Parent = sl;
|
template.Parent = sl;
|
||||||
|
|
||||||
template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
|
template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
|
||||||
template.IsVisible = () => true;
|
template.IsVisible = () => true;
|
||||||
sl.AddChild(template);
|
sl.AddChild(template);
|
||||||
|
|
||||||
if (i == 0) currentServer = game;
|
if (i == 0) currentServer = game;
|
||||||
|
|
||||||
offset += template.Bounds.Height;
|
offset += template.Bounds.Height;
|
||||||
sl.ContentHeight += template.Bounds.Height;
|
sl.ContentHeight += template.Bounds.Height;
|
||||||
i++;
|
i++;
|
||||||
|
|||||||
@@ -3,40 +3,39 @@ using System;
|
|||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
|
||||||
namespace OpenRA.Widgets
|
namespace OpenRA.Widgets
|
||||||
{
|
{
|
||||||
public class ImageWidget : Widget
|
public class ImageWidget : Widget
|
||||||
{
|
{
|
||||||
public string ImageCollection = "";
|
public string ImageCollection = "";
|
||||||
public string ImageName = "";
|
public string ImageName = "";
|
||||||
public Func<string> GetImageName;
|
public Func<string> GetImageName;
|
||||||
public Func<string> GetImageCollection;
|
public Func<string> GetImageCollection;
|
||||||
|
|
||||||
public ImageWidget ()
|
public ImageWidget()
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
GetImageName = () => { return ImageName; };
|
GetImageName = () => { return ImageName; };
|
||||||
GetImageCollection = () => { return ImageCollection; };
|
GetImageCollection = () => { return ImageCollection; };
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageWidget(Widget other)
|
protected ImageWidget(ImageWidget other)
|
||||||
: base(other)
|
: base(other)
|
||||||
{
|
{
|
||||||
ImageName = (other as ImageWidget).ImageName;
|
ImageName = other.ImageName;
|
||||||
GetImageName = (other as ImageWidget).GetImageName;
|
GetImageName = other.GetImageName;
|
||||||
ImageCollection = (other as ImageWidget).ImageCollection;
|
ImageCollection = other.ImageCollection;
|
||||||
GetImageCollection = (other as ImageWidget).GetImageCollection;
|
GetImageCollection = other.GetImageCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Widget Clone()
|
public override Widget Clone() { return new ImageWidget(this); }
|
||||||
{
|
|
||||||
return new ImageWidget(this);
|
public override void DrawInner(World world)
|
||||||
}
|
{
|
||||||
|
var name = GetImageName();
|
||||||
public override void DrawInner(World world)
|
var collection = GetImageCollection();
|
||||||
{
|
WidgetUtils.DrawRGBA(
|
||||||
var name = GetImageName();
|
ChromeProvider.GetImage(Game.chrome.renderer, collection, name),
|
||||||
var collection = GetImageCollection();
|
RenderOrigin);
|
||||||
WidgetUtils.DrawRGBA(ChromeProvider.GetImage(Game.chrome.renderer, collection, name), RenderOrigin);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,19 +18,14 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Drawing;
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
namespace OpenRA.Widgets
|
namespace OpenRA.Widgets
|
||||||
{
|
{
|
||||||
class LabelWidget : Widget
|
class LabelWidget : Widget
|
||||||
{
|
{
|
||||||
public enum TextAlign
|
public enum TextAlign { Left, Center, Right }
|
||||||
{
|
|
||||||
Left,
|
|
||||||
Center,
|
|
||||||
Right
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Text = null;
|
public string Text = null;
|
||||||
public string Background = null;
|
public string Background = null;
|
||||||
@@ -46,14 +41,14 @@ namespace OpenRA.Widgets
|
|||||||
GetBackground = () => { return Background; };
|
GetBackground = () => { return Background; };
|
||||||
}
|
}
|
||||||
|
|
||||||
public LabelWidget(Widget other)
|
protected LabelWidget(LabelWidget other)
|
||||||
: base(other)
|
: base(other)
|
||||||
{
|
{
|
||||||
Text = (other as LabelWidget).Text;
|
Text = other.Text;
|
||||||
Align = (other as LabelWidget).Align;
|
Align = other.Align;
|
||||||
Bold = (other as LabelWidget).Bold;
|
Bold = other.Bold;
|
||||||
GetText = (other as LabelWidget).GetText;
|
GetText = other.GetText;
|
||||||
GetBackground = (other as LabelWidget).GetBackground;
|
GetBackground = other.GetBackground;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawInner(World world)
|
public override void DrawInner(World world)
|
||||||
@@ -79,10 +74,7 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
font.DrawText(text, position, Color.White);
|
font.DrawText(text, position, Color.White);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Widget Clone()
|
public override Widget Clone() { return new LabelWidget(this); }
|
||||||
{
|
|
||||||
return new LabelWidget(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
using System.Drawing;
|
|
||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
@@ -18,6 +17,8 @@ using System.Drawing;
|
|||||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
namespace OpenRA.Widgets
|
namespace OpenRA.Widgets
|
||||||
{
|
{
|
||||||
@@ -38,50 +39,49 @@ namespace OpenRA.Widgets
|
|||||||
Rectangle backgroundRect;
|
Rectangle backgroundRect;
|
||||||
Rectangle scrollbarRect;
|
Rectangle scrollbarRect;
|
||||||
|
|
||||||
public ListBoxWidget() : base() {}
|
public ListBoxWidget() : base() {}
|
||||||
public ListBoxWidget(Widget other)
|
protected ListBoxWidget(ListBoxWidget other)
|
||||||
: base(other)
|
: base(other)
|
||||||
{
|
{
|
||||||
Background = (other as ListBoxWidget).Background;
|
Background = other.Background;
|
||||||
upButtonRect = (other as ListBoxWidget).upButtonRect;
|
upButtonRect = other.upButtonRect;
|
||||||
downButtonRect = (other as ListBoxWidget).downButtonRect;
|
downButtonRect = other.downButtonRect;
|
||||||
scrollbarRect = (other as ListBoxWidget).scrollbarRect;
|
scrollbarRect = other.scrollbarRect;
|
||||||
backgroundRect = (other as ListBoxWidget).backgroundRect;
|
backgroundRect = other.backgroundRect;
|
||||||
|
|
||||||
UpPressed = (other as ListBoxWidget).UpPressed;
|
UpPressed = other.UpPressed;
|
||||||
DownPressed = (other as ListBoxWidget).DownPressed;
|
DownPressed = other.DownPressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawInner(World world) {}
|
public override void DrawInner(World world) {}
|
||||||
public override void Draw(World world)
|
public override void Draw(World world)
|
||||||
{
|
{
|
||||||
if (!IsVisible())
|
if (!IsVisible())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
backgroundRect = new Rectangle(RenderBounds.X, RenderBounds.Y, RenderBounds.Width - ScrollbarWidth, RenderBounds.Height);
|
backgroundRect = new Rectangle(RenderBounds.X, RenderBounds.Y, RenderBounds.Width - ScrollbarWidth, RenderBounds.Height);
|
||||||
upButtonRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y, ScrollbarWidth, ScrollbarWidth);
|
upButtonRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y, ScrollbarWidth, ScrollbarWidth);
|
||||||
downButtonRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Bottom - ScrollbarWidth, ScrollbarWidth, ScrollbarWidth);
|
downButtonRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Bottom - ScrollbarWidth, ScrollbarWidth, ScrollbarWidth);
|
||||||
scrollbarRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y + ScrollbarWidth, ScrollbarWidth, RenderBounds.Height - 2*ScrollbarWidth);
|
scrollbarRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y + ScrollbarWidth, ScrollbarWidth, RenderBounds.Height - 2 * ScrollbarWidth);
|
||||||
|
|
||||||
string upButtonBg = (UpPressed) ? "dialog3" : "dialog2";
|
string upButtonBg = (UpPressed) ? "dialog3" : "dialog2";
|
||||||
string downButtonBg = (DownPressed) ? "dialog3" : "dialog2";
|
string downButtonBg = (DownPressed) ? "dialog3" : "dialog2";
|
||||||
string scrolbarBg = "dialog3";
|
string scrollbarBg = "dialog3";
|
||||||
string scrollbarButton = "dialog2";
|
|
||||||
|
WidgetUtils.DrawPanel(Background, backgroundRect);
|
||||||
WidgetUtils.DrawPanel(Background, backgroundRect);
|
WidgetUtils.DrawPanel(upButtonBg, upButtonRect);
|
||||||
WidgetUtils.DrawPanel(upButtonBg, upButtonRect);
|
WidgetUtils.DrawPanel(downButtonBg, downButtonRect);
|
||||||
WidgetUtils.DrawPanel(downButtonBg, downButtonRect);
|
WidgetUtils.DrawPanel(scrollbarBg, scrollbarRect);
|
||||||
WidgetUtils.DrawPanel(scrolbarBg, scrollbarRect);
|
|
||||||
|
Game.chrome.renderer.Device.EnableScissor(backgroundRect.X, backgroundRect.Y + HeaderHeight, backgroundRect.Width, backgroundRect.Height - HeaderHeight);
|
||||||
|
|
||||||
Game.chrome.renderer.Device.EnableScissor(backgroundRect.X, backgroundRect.Y + HeaderHeight, backgroundRect.Width, backgroundRect.Height - HeaderHeight);
|
foreach (var child in Children)
|
||||||
|
child.Draw(world);
|
||||||
foreach (var child in Children)
|
|
||||||
child.Draw(world);
|
Game.chrome.renderer.RgbaSpriteRenderer.Flush();
|
||||||
|
Game.chrome.renderer.Device.DisableScissor();
|
||||||
Game.chrome.renderer.RgbaSpriteRenderer.Flush();
|
|
||||||
Game.chrome.renderer.Device.DisableScissor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int2 ChildOrigin { get { return RenderOrigin + new int2(0, (int)ListOffset); } }
|
public override int2 ChildOrigin { get { return RenderOrigin + new int2(0, (int)ListOffset); } }
|
||||||
|
|
||||||
public override void Tick (World world)
|
public override void Tick (World world)
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using OpenRA.Graphics;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
|
||||||
namespace OpenRA.Widgets
|
namespace OpenRA.Widgets
|
||||||
{
|
{
|
||||||
@@ -14,25 +13,26 @@ namespace OpenRA.Widgets
|
|||||||
Sprite mapChooserSprite;
|
Sprite mapChooserSprite;
|
||||||
bool mapPreviewDirty = true;
|
bool mapPreviewDirty = true;
|
||||||
MapStub lastMap;
|
MapStub lastMap;
|
||||||
|
|
||||||
public Func<MapStub> Map = () => {return null;};
|
public Func<MapStub> Map = () => null;
|
||||||
public Action<int> OnSpawnClick = spawn => {};
|
public Action<int> OnSpawnClick = spawn => {};
|
||||||
public Func<Dictionary<int2,Color>> SpawnColors = () => {return new Dictionary<int2, Color>(); };
|
public Func<Dictionary<int2, Color>> SpawnColors = () => new Dictionary<int2, Color>();
|
||||||
|
|
||||||
public MapPreviewWidget() : base() { }
|
public MapPreviewWidget() : base() { }
|
||||||
|
|
||||||
public MapPreviewWidget(Widget other)
|
protected MapPreviewWidget(MapPreviewWidget other)
|
||||||
: base(other)
|
: base(other)
|
||||||
{
|
{
|
||||||
lastMap = (other as MapPreviewWidget).lastMap;
|
lastMap = other.lastMap;
|
||||||
Map = (other as MapPreviewWidget).Map;
|
Map = other.Map;
|
||||||
OnSpawnClick = (other as MapPreviewWidget).OnSpawnClick;
|
OnSpawnClick = other.OnSpawnClick;
|
||||||
SpawnColors = (other as MapPreviewWidget).SpawnColors;
|
SpawnColors = other.SpawnColors;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Sprite UnownedSpawn = null;
|
static Sprite UnownedSpawn = null;
|
||||||
static Sprite OwnedSpawn = null;
|
static Sprite OwnedSpawn = null;
|
||||||
const int closeEnough = 50;
|
const int closeEnough = 50;
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi)
|
public override bool HandleInput(MouseInput mi)
|
||||||
{
|
{
|
||||||
var map = Map();
|
var map = Map();
|
||||||
|
|||||||
@@ -36,12 +36,12 @@ namespace OpenRA.Widgets
|
|||||||
/* legacy crap!!! */
|
/* legacy crap!!! */
|
||||||
List<Pair<Rectangle, Action<MouseInput>>> buttons = new List<Pair<Rectangle, Action<MouseInput>>>();
|
List<Pair<Rectangle, Action<MouseInput>>> buttons = new List<Pair<Rectangle, Action<MouseInput>>>();
|
||||||
void AddButton(Rectangle r, Action<MouseInput> b) { buttons.Add(Pair.New(r, b)); }
|
void AddButton(Rectangle r, Action<MouseInput> b) { buttons.Add(Pair.New(r, b)); }
|
||||||
|
|
||||||
public MoneyBinWidget() : base() { }
|
public MoneyBinWidget() : base() { }
|
||||||
public MoneyBinWidget(Widget other) : base(other) { }
|
protected MoneyBinWidget(Widget other) : base(other) { }
|
||||||
|
|
||||||
public override Widget Clone() { return new MoneyBinWidget(this); }
|
public override Widget Clone() { return new MoneyBinWidget(this); }
|
||||||
|
|
||||||
public override void DrawInner(World world)
|
public override void DrawInner(World world)
|
||||||
{
|
{
|
||||||
var playerResources = world.LocalPlayer.PlayerActor.traits.Get<PlayerResources>();
|
var playerResources = world.LocalPlayer.PlayerActor.traits.Get<PlayerResources>();
|
||||||
@@ -54,7 +54,7 @@ namespace OpenRA.Widgets
|
|||||||
new float2(Bounds.Left, 0), "chrome");
|
new float2(Bounds.Left, 0), "chrome");
|
||||||
|
|
||||||
// Cash
|
// Cash
|
||||||
var cashDigits = (SplitOreAndCash ? playerResources.DisplayCash
|
var cashDigits = (SplitOreAndCash ? playerResources.DisplayCash
|
||||||
: (playerResources.DisplayCash + playerResources.DisplayOre)).ToString();
|
: (playerResources.DisplayCash + playerResources.DisplayOre)).ToString();
|
||||||
var x = Bounds.Right - 65;
|
var x = Bounds.Right - 65;
|
||||||
|
|
||||||
@@ -149,6 +149,6 @@ namespace OpenRA.Widgets
|
|||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
using System.Drawing;
|
|
||||||
using System.Collections.Generic;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Support;
|
using OpenRA.Support;
|
||||||
|
|
||||||
@@ -26,36 +26,32 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
class PerfGraphWidget : Widget
|
class PerfGraphWidget : Widget
|
||||||
{
|
{
|
||||||
public PerfGraphWidget() : base() { }
|
public PerfGraphWidget() : base() { }
|
||||||
|
|
||||||
public PerfGraphWidget(Widget other) : base(other) { }
|
public override void DrawInner(World world)
|
||||||
|
{
|
||||||
public override Widget Clone() { return new PerfGraphWidget(this); }
|
var rect = RenderBounds;
|
||||||
|
float2 origin = Game.viewport.Location + new float2(rect.Right, rect.Bottom);
|
||||||
public override void DrawInner(World world)
|
float2 basis = new float2(-rect.Width / 100, -rect.Height / 100);
|
||||||
{
|
|
||||||
var rect = RenderBounds;
|
Game.chrome.lineRenderer.DrawLine(origin, origin + new float2(100, 0) * basis, Color.White, Color.White);
|
||||||
float2 origin = Game.viewport.Location + new float2(rect.Right,rect.Bottom);
|
Game.chrome.lineRenderer.DrawLine(origin + new float2(100, 0) * basis, origin + new float2(100, 100) * basis, Color.White, Color.White);
|
||||||
float2 basis = new float2(-rect.Width/100,-rect.Height/100);
|
|
||||||
|
foreach (var item in PerfHistory.items.Values)
|
||||||
Game.chrome.lineRenderer.DrawLine(origin, origin + new float2(100, 0) * basis, Color.White, Color.White);
|
{
|
||||||
Game.chrome.lineRenderer.DrawLine(origin + new float2(100,0) * basis, origin + new float2(100,100) * basis, Color.White, Color.White);
|
int n = 0;
|
||||||
|
item.Samples().Aggregate((a, b) =>
|
||||||
foreach (var item in PerfHistory.items.Values)
|
{
|
||||||
{
|
Game.chrome.lineRenderer.DrawLine(
|
||||||
int n = 0;
|
origin + new float2(n, (float)a) * basis,
|
||||||
item.Samples().Aggregate((a, b) =>
|
origin + new float2(n + 1, (float)b) * basis,
|
||||||
{
|
item.c, item.c);
|
||||||
Game.chrome.lineRenderer.DrawLine(
|
++n;
|
||||||
origin + new float2(n, (float)a) * basis,
|
return b;
|
||||||
origin + new float2(n+1, (float)b) * basis,
|
});
|
||||||
item.c, item.c);
|
}
|
||||||
++n;
|
|
||||||
return b;
|
Game.chrome.lineRenderer.Flush();
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Game.chrome.lineRenderer.Flush();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,10 +28,6 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
public PostGameWidget() : base() { }
|
public PostGameWidget() : base() { }
|
||||||
|
|
||||||
public PostGameWidget(Widget other) : base(other) { }
|
|
||||||
|
|
||||||
public override Widget Clone() { return new PostGameWidget(this); }
|
|
||||||
|
|
||||||
bool AreMutualAllies(Player a, Player b) { return a.Stances[b] == Stance.Ally && b.Stances[a] == Stance.Ally; }
|
bool AreMutualAllies(Player a, Player b) { return a.Stances[b] == Stance.Ally && b.Stances[a] == Stance.Ally; }
|
||||||
|
|
||||||
// todo: all this shit needs to move, probably to Player.
|
// todo: all this shit needs to move, probably to Player.
|
||||||
|
|||||||
@@ -21,80 +21,77 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Widgets
|
namespace OpenRA.Widgets
|
||||||
{
|
{
|
||||||
|
public class PowerBinWidget : Widget
|
||||||
public class PowerBinWidget : Widget
|
{
|
||||||
{
|
// Power bar
|
||||||
// Power bar
|
static float2 powerOrigin = new float2(42, 205); // Relative to radarOrigin
|
||||||
static float2 powerOrigin = new float2(42, 205); // Relative to radarOrigin
|
static Size powerSize = new Size(138, 5);
|
||||||
static Size powerSize = new Size(138, 5);
|
float? lastPowerProvidedPos;
|
||||||
float? lastPowerProvidedPos;
|
float? lastPowerDrainedPos;
|
||||||
float? lastPowerDrainedPos;
|
string powerCollection;
|
||||||
string powerCollection;
|
|
||||||
|
public override void DrawInner(World world)
|
||||||
public override Widget Clone() { throw new NotImplementedException("Why are you Cloning PowerBin?"); }
|
{
|
||||||
|
powerCollection = "power-" + world.LocalPlayer.Country.Race;
|
||||||
public override void DrawInner(World world)
|
|
||||||
{
|
var resources = world.LocalPlayer.PlayerActor.traits.Get<PlayerResources>();
|
||||||
powerCollection = "power-" + world.LocalPlayer.Country.Race;
|
|
||||||
|
// Nothing to draw
|
||||||
var resources = world.LocalPlayer.PlayerActor.traits.Get<PlayerResources>();
|
if (resources.PowerProvided == 0
|
||||||
|
&& resources.PowerDrained == 0)
|
||||||
// Nothing to draw
|
return;
|
||||||
if (resources.PowerProvided == 0
|
|
||||||
&& resources.PowerDrained == 0)
|
var renderer = Game.chrome.renderer;
|
||||||
return;
|
var lineRenderer = Game.chrome.lineRenderer;
|
||||||
|
var rgbaRenderer = renderer.RgbaSpriteRenderer;
|
||||||
var renderer = Game.chrome.renderer;
|
|
||||||
var lineRenderer = Game.chrome.lineRenderer;
|
// Draw bar horizontally
|
||||||
var rgbaRenderer = renderer.RgbaSpriteRenderer;
|
var barStart = powerOrigin + RadarBinWidget.radarOrigin;
|
||||||
|
var barEnd = barStart + new float2(powerSize.Width, 0);
|
||||||
// Draw bar horizontally
|
|
||||||
var barStart = powerOrigin + RadarBinWidget.radarOrigin;
|
float powerScaleBy = 100;
|
||||||
var barEnd = barStart + new float2(powerSize.Width, 0);
|
var maxPower = Math.Max(resources.PowerProvided, resources.PowerDrained);
|
||||||
|
while (maxPower >= powerScaleBy) powerScaleBy *= 2;
|
||||||
float powerScaleBy = 100;
|
|
||||||
var maxPower = Math.Max(resources.PowerProvided, resources.PowerDrained);
|
// Current power supply
|
||||||
while (maxPower >= powerScaleBy) powerScaleBy *= 2;
|
var powerLevelTemp = barStart.X + (barEnd.X - barStart.X) * (resources.PowerProvided / powerScaleBy);
|
||||||
|
lastPowerProvidedPos = float2.Lerp(lastPowerProvidedPos.GetValueOrDefault(powerLevelTemp), powerLevelTemp, .3f);
|
||||||
// Current power supply
|
float2 powerLevel = new float2(lastPowerProvidedPos.Value, barStart.Y);
|
||||||
var powerLevelTemp = barStart.X + (barEnd.X - barStart.X) * (resources.PowerProvided / powerScaleBy);
|
|
||||||
lastPowerProvidedPos = float2.Lerp(lastPowerProvidedPos.GetValueOrDefault(powerLevelTemp), powerLevelTemp, .3f);
|
var color = Color.LimeGreen;
|
||||||
float2 powerLevel = new float2(lastPowerProvidedPos.Value, barStart.Y);
|
if (resources.GetPowerState() == PowerState.Low)
|
||||||
|
color = Color.Orange;
|
||||||
var color = Color.LimeGreen;
|
if (resources.GetPowerState() == PowerState.Critical)
|
||||||
if (resources.GetPowerState() == PowerState.Low)
|
color = Color.Red;
|
||||||
color = Color.Orange;
|
|
||||||
if (resources.GetPowerState() == PowerState.Critical)
|
var colorDark = Graphics.Util.Lerp(0.25f, color, Color.Black);
|
||||||
color = Color.Red;
|
for (int i = 0; i < powerSize.Height; i++)
|
||||||
|
{
|
||||||
var colorDark = Graphics.Util.Lerp(0.25f, color, Color.Black);
|
color = (i - 1 < powerSize.Height / 2) ? color : colorDark;
|
||||||
for (int i = 0; i < powerSize.Height; i++)
|
float2 leftOffset = new float2(0, i);
|
||||||
{
|
float2 rightOffset = new float2(0, i);
|
||||||
color = (i - 1 < powerSize.Height / 2) ? color : colorDark;
|
// Indent corners
|
||||||
float2 leftOffset = new float2(0, i);
|
if ((i == 0 || i == powerSize.Height - 1) && powerLevel.X - barStart.X > 1)
|
||||||
float2 rightOffset = new float2(0, i);
|
{
|
||||||
// Indent corners
|
leftOffset.X += 1;
|
||||||
if ((i == 0 || i == powerSize.Height - 1) && powerLevel.X - barStart.X > 1)
|
rightOffset.X -= 1;
|
||||||
{
|
}
|
||||||
leftOffset.X += 1;
|
lineRenderer.DrawLine(Game.viewport.Location + barStart + leftOffset, Game.viewport.Location + powerLevel + rightOffset, color, color);
|
||||||
rightOffset.X -= 1;
|
}
|
||||||
}
|
lineRenderer.Flush();
|
||||||
lineRenderer.DrawLine(Game.viewport.Location + barStart + leftOffset, Game.viewport.Location + powerLevel + rightOffset, color, color);
|
|
||||||
}
|
// Power usage indicator
|
||||||
lineRenderer.Flush();
|
var indicator = ChromeProvider.GetImage(renderer, powerCollection, "power-indicator");
|
||||||
|
var powerDrainedTemp = barStart.X + (barEnd.X - barStart.X) * (resources.PowerDrained / powerScaleBy);
|
||||||
// Power usage indicator
|
lastPowerDrainedPos = float2.Lerp(lastPowerDrainedPos.GetValueOrDefault(powerDrainedTemp), powerDrainedTemp, .3f);
|
||||||
var indicator = ChromeProvider.GetImage(renderer, powerCollection, "power-indicator");
|
float2 powerDrainLevel = new float2(lastPowerDrainedPos.Value - indicator.size.X / 2, barStart.Y - 1);
|
||||||
var powerDrainedTemp = barStart.X + (barEnd.X - barStart.X) * (resources.PowerDrained / powerScaleBy);
|
|
||||||
lastPowerDrainedPos = float2.Lerp(lastPowerDrainedPos.GetValueOrDefault(powerDrainedTemp), powerDrainedTemp, .3f);
|
rgbaRenderer.DrawSprite(indicator, powerDrainLevel, "chrome");
|
||||||
float2 powerDrainLevel = new float2(lastPowerDrainedPos.Value - indicator.size.X / 2, barStart.Y - 1);
|
rgbaRenderer.Flush();
|
||||||
|
}
|
||||||
rgbaRenderer.DrawSprite(indicator, powerDrainLevel, "chrome");
|
}
|
||||||
rgbaRenderer.Flush();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,10 +44,10 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
if (!hasRadar || radarAnimating) return false; // we're not set up for this.
|
if (!hasRadar || radarAnimating) return false; // we're not set up for this.
|
||||||
|
|
||||||
var mapRect = new RectangleF(radarOrigin.X + 9, radarOrigin.Y + (192 - radarMinimapHeight) / 2,
|
var mapRect = new RectangleF(radarOrigin.X + 9, radarOrigin.Y + (192 - radarMinimapHeight) / 2,
|
||||||
192, radarMinimapHeight);
|
192, radarMinimapHeight);
|
||||||
|
|
||||||
if (!mapRect.Contains(mi.Location.ToPointF()))
|
if (!mapRect.Contains(mi.Location.ToPointF()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var loc = Game.world.Minimap.MinimapPixelToCell(mapRect, mi.Location);
|
var loc = Game.world.Minimap.MinimapPixelToCell(mapRect, mi.Location);
|
||||||
@@ -59,10 +59,10 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
// fake a mousedown/mouseup here
|
// fake a mousedown/mouseup here
|
||||||
|
|
||||||
var fakemi = new MouseInput
|
var fakemi = new MouseInput
|
||||||
{
|
{
|
||||||
Event = MouseInputEvent.Down,
|
Event = MouseInputEvent.Down,
|
||||||
Button = MouseButton.Right,
|
Button = MouseButton.Right,
|
||||||
Modifiers = mi.Modifiers,
|
Modifiers = mi.Modifiers,
|
||||||
Location = (loc * Game.CellSize - Game.viewport.Location).ToInt2()
|
Location = (loc * Game.CellSize - Game.viewport.Location).ToInt2()
|
||||||
};
|
};
|
||||||
@@ -75,8 +75,6 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Widget Clone() { throw new NotImplementedException("Why are you Cloning RadarBin?"); }
|
|
||||||
|
|
||||||
public override void DrawInner(World world)
|
public override void DrawInner(World world)
|
||||||
{
|
{
|
||||||
@@ -143,7 +141,7 @@ namespace OpenRA.Widgets
|
|||||||
radarMinimapHeight = float2.Lerp(0, 192, (radarAnimationFrame - radarSlideAnimationLength) * 1.0f / radarActivateAnimationLength);
|
radarMinimapHeight = float2.Lerp(0, 192, (radarAnimationFrame - radarSlideAnimationLength) * 1.0f / radarActivateAnimationLength);
|
||||||
|
|
||||||
// Animation is complete
|
// Animation is complete
|
||||||
if (radarAnimationFrame == (hasRadar ? radarSlideAnimationLength+radarActivateAnimationLength : 0))
|
if (radarAnimationFrame == (hasRadar ? radarSlideAnimationLength + radarActivateAnimationLength : 0))
|
||||||
radarAnimating = false;
|
radarAnimating = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,158 +1,163 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
||||||
namespace OpenRA.Widgets
|
namespace OpenRA.Widgets
|
||||||
{
|
{
|
||||||
public class SliderWidget : Widget
|
public class SliderWidget : Widget
|
||||||
{
|
{
|
||||||
public event Action<float> OnChange;
|
public event Action<float> OnChange;
|
||||||
public Func<float> GetOffset;
|
public Func<float> GetOffset;
|
||||||
public float Offset = 0;
|
public float Offset = 0;
|
||||||
public int Ticks = 0;
|
public int Ticks = 0;
|
||||||
public int TrackHeight = 5;
|
public int TrackHeight = 5;
|
||||||
|
|
||||||
int2 lastMouseLocation;
|
int2 lastMouseLocation;
|
||||||
bool isMoving = false;
|
bool isMoving = false;
|
||||||
|
|
||||||
public SliderWidget () : base()
|
public SliderWidget()
|
||||||
{
|
: base()
|
||||||
GetOffset = () => Offset;
|
{
|
||||||
OnChange = x => Offset = x;
|
GetOffset = () => Offset;
|
||||||
}
|
OnChange = x => Offset = x;
|
||||||
|
}
|
||||||
public SliderWidget(Widget other)
|
|
||||||
: base(other)
|
public SliderWidget(SliderWidget other)
|
||||||
{
|
: base(other)
|
||||||
OnChange = (other as SliderWidget).OnChange;
|
{
|
||||||
GetOffset = (other as SliderWidget).GetOffset;
|
OnChange = other.OnChange;
|
||||||
Offset = (other as SliderWidget).Offset;
|
GetOffset = other.GetOffset;
|
||||||
Ticks = (other as SliderWidget).Ticks;
|
Offset = other.Offset;
|
||||||
TrackHeight = (other as SliderWidget).TrackHeight;
|
Ticks = other.Ticks;
|
||||||
lastMouseLocation = (other as SliderWidget).lastMouseLocation;
|
TrackHeight = other.TrackHeight;
|
||||||
isMoving = (other as SliderWidget).isMoving;
|
lastMouseLocation = other.lastMouseLocation;
|
||||||
}
|
isMoving = other.isMoving;
|
||||||
|
}
|
||||||
public override bool HandleInput(MouseInput mi)
|
|
||||||
{
|
public override bool HandleInput(MouseInput mi)
|
||||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
{
|
||||||
return false;
|
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||||
|
return false;
|
||||||
if (!Focused)
|
|
||||||
return false;
|
if (!Focused)
|
||||||
|
return false;
|
||||||
switch (mi.Event)
|
|
||||||
{
|
switch (mi.Event)
|
||||||
case MouseInputEvent.Up:
|
{
|
||||||
{
|
case MouseInputEvent.Up:
|
||||||
if (Focused)
|
{
|
||||||
{
|
if (Focused)
|
||||||
isMoving = false;
|
{
|
||||||
base.LoseFocus(mi);
|
isMoving = false;
|
||||||
}
|
base.LoseFocus(mi);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
case MouseInputEvent.Down:
|
|
||||||
{
|
case MouseInputEvent.Down:
|
||||||
if (thumbRect.Contains(mi.Location.ToPoint()))
|
{
|
||||||
{
|
if (thumbRect.Contains(mi.Location.ToPoint()))
|
||||||
isMoving = true;
|
{
|
||||||
lastMouseLocation = mi.Location;
|
isMoving = true;
|
||||||
}
|
lastMouseLocation = mi.Location;
|
||||||
else if (Ticks != 0)
|
}
|
||||||
{
|
else if (Ticks != 0)
|
||||||
var pos = GetOffset();
|
{
|
||||||
|
var pos = GetOffset();
|
||||||
// Offset slightly the direction we want to move so we don't get stuck on a tick
|
|
||||||
var delta = 0.001;
|
// Offset slightly the direction we want to move so we don't get stuck on a tick
|
||||||
var targetTick = (float)((mi.Location.X > thumbRect.Right) ? Math.Ceiling((pos+delta)*(Ticks-1))
|
var delta = 0.001;
|
||||||
: Math.Floor((pos-delta)*(Ticks-1)));
|
var targetTick = (float)((mi.Location.X > thumbRect.Right) ? Math.Ceiling((pos + delta) * (Ticks - 1))
|
||||||
OnChange(targetTick/(Ticks-1));
|
: Math.Floor((pos - delta) * (Ticks - 1)));
|
||||||
|
OnChange(targetTick / (Ticks - 1));
|
||||||
if (thumbRect.Contains(mi.Location.ToPoint()))
|
|
||||||
{
|
if (thumbRect.Contains(mi.Location.ToPoint()))
|
||||||
isMoving = true;
|
{
|
||||||
lastMouseLocation = mi.Location;
|
isMoving = true;
|
||||||
}
|
lastMouseLocation = mi.Location;
|
||||||
return true;
|
}
|
||||||
}
|
return true;
|
||||||
else // No ticks; move to the mouse position
|
}
|
||||||
{
|
else // No ticks; move to the mouse position
|
||||||
var thumb = thumbRect;
|
{
|
||||||
var center = thumb.X + thumb.Width/2;
|
var thumb = thumbRect;
|
||||||
var newOffset = OffsetBy((mi.Location.X - center)*1f/(RenderBounds.Width-thumb.Width));
|
var center = thumb.X + thumb.Width / 2;
|
||||||
if (newOffset != GetOffset())
|
var newOffset = OffsetBy((mi.Location.X - center) * 1f / (RenderBounds.Width - thumb.Width));
|
||||||
{
|
if (newOffset != GetOffset())
|
||||||
OnChange(newOffset);
|
{
|
||||||
|
OnChange(newOffset);
|
||||||
if (thumbRect.Contains(mi.Location.ToPoint()))
|
|
||||||
{
|
if (thumbRect.Contains(mi.Location.ToPoint()))
|
||||||
isMoving = true;
|
{
|
||||||
lastMouseLocation = mi.Location;
|
isMoving = true;
|
||||||
}
|
lastMouseLocation = mi.Location;
|
||||||
return true;
|
}
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
case MouseInputEvent.Move:
|
|
||||||
{
|
case MouseInputEvent.Move:
|
||||||
if ((mi.Location.X != lastMouseLocation.X) && isMoving)
|
{
|
||||||
{
|
if ((mi.Location.X != lastMouseLocation.X) && isMoving)
|
||||||
var newOffset = OffsetBy((mi.Location.X - lastMouseLocation.X)*1f/(RenderBounds.Width-thumbRect.Width));
|
{
|
||||||
if (newOffset != Offset)
|
var newOffset = OffsetBy((mi.Location.X - lastMouseLocation.X) * 1f / (RenderBounds.Width - thumbRect.Width));
|
||||||
{
|
if (newOffset != Offset)
|
||||||
lastMouseLocation = mi.Location;
|
{
|
||||||
OnChange(newOffset);
|
lastMouseLocation = mi.Location;
|
||||||
}
|
OnChange(newOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
return thumbRect.Contains(mi.Location.X,mi.Location.Y);
|
|
||||||
}
|
return thumbRect.Contains(mi.Location.X, mi.Location.Y);
|
||||||
|
}
|
||||||
float OffsetBy(float amount)
|
|
||||||
{
|
float OffsetBy(float amount)
|
||||||
var centerPos = GetOffset() + amount;
|
{
|
||||||
if (centerPos < 0) centerPos = 0;
|
var centerPos = GetOffset() + amount;
|
||||||
if (centerPos > 1) centerPos = 1;
|
if (centerPos < 0) centerPos = 0;
|
||||||
return centerPos;
|
if (centerPos > 1) centerPos = 1;
|
||||||
}
|
return centerPos;
|
||||||
|
}
|
||||||
public override Widget Clone() { return new SliderWidget(this); }
|
|
||||||
|
public override Widget Clone() { return new SliderWidget(this); }
|
||||||
Rectangle thumbRect
|
|
||||||
{ get {
|
Rectangle thumbRect
|
||||||
var width = RenderBounds.Height;
|
{
|
||||||
var height = RenderBounds.Height;
|
get
|
||||||
var origin = (int)((RenderBounds.X + width/2) + GetOffset()*(RenderBounds.Width - width) - width/2f);
|
{
|
||||||
return new Rectangle(origin, RenderBounds.Y, width, height);
|
var width = RenderBounds.Height;
|
||||||
} }
|
var height = RenderBounds.Height;
|
||||||
|
var origin = (int)((RenderBounds.X + width / 2) + GetOffset() * (RenderBounds.Width - width) - width / 2f);
|
||||||
public override void DrawInner(World world) {
|
return new Rectangle(origin, RenderBounds.Y, width, height);
|
||||||
if (!IsVisible())
|
}
|
||||||
return;
|
}
|
||||||
|
|
||||||
var trackWidth = RenderBounds.Width - thumbRect.Width;
|
public override void DrawInner(World world)
|
||||||
var trackOrigin = RenderBounds.X + thumbRect.Width/2;
|
{
|
||||||
var trackRect = new Rectangle(trackOrigin-1, RenderBounds.Y + (RenderBounds.Height - TrackHeight)/2, trackWidth+2, TrackHeight);
|
if (!IsVisible())
|
||||||
|
return;
|
||||||
// Tickmarks (hacked until we have real art)
|
|
||||||
for (int i = 0; i < Ticks; i++)
|
var trackWidth = RenderBounds.Width - thumbRect.Width;
|
||||||
{
|
var trackOrigin = RenderBounds.X + thumbRect.Width / 2;
|
||||||
var tickRect = new Rectangle(trackOrigin -1 + (int)(i*trackWidth*1f/(Ticks-1)),
|
var trackRect = new Rectangle(trackOrigin - 1, RenderBounds.Y + (RenderBounds.Height - TrackHeight) / 2, trackWidth + 2, TrackHeight);
|
||||||
RenderBounds.Y + RenderBounds.Height/2, 2, RenderBounds.Height/2);
|
|
||||||
WidgetUtils.DrawPanel("dialog2", tickRect);
|
// Tickmarks (hacked until we have real art)
|
||||||
}
|
for (int i = 0; i < Ticks; i++)
|
||||||
// Track
|
{
|
||||||
WidgetUtils.DrawPanel("dialog3", trackRect);
|
var tickRect = new Rectangle(trackOrigin - 1 + (int)(i * trackWidth * 1f / (Ticks - 1)),
|
||||||
|
RenderBounds.Y + RenderBounds.Height / 2, 2, RenderBounds.Height / 2);
|
||||||
// Thumb
|
WidgetUtils.DrawPanel("dialog2", tickRect);
|
||||||
WidgetUtils.DrawPanel("dialog2", thumbRect);
|
}
|
||||||
}
|
// Track
|
||||||
}
|
WidgetUtils.DrawPanel("dialog3", trackRect);
|
||||||
|
|
||||||
|
// Thumb
|
||||||
|
WidgetUtils.DrawPanel("dialog2", thumbRect);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,16 +16,16 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Drawing;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Drawing;
|
||||||
using OpenRA;
|
using System.Linq;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
using OpenRA.Graphics;
|
|
||||||
using OpenRA.FileFormats;
|
|
||||||
using System;
|
|
||||||
namespace OpenRA.Widgets
|
namespace OpenRA.Widgets
|
||||||
{
|
{
|
||||||
class SpecialPowerBinWidget : Widget
|
class SpecialPowerBinWidget : Widget
|
||||||
@@ -36,16 +36,6 @@ namespace OpenRA.Widgets
|
|||||||
readonly List<Pair<Rectangle, Action<MouseInput>>> buttons = new List<Pair<Rectangle,Action<MouseInput>>>();
|
readonly List<Pair<Rectangle, Action<MouseInput>>> buttons = new List<Pair<Rectangle,Action<MouseInput>>>();
|
||||||
|
|
||||||
public SpecialPowerBinWidget() : base() { }
|
public SpecialPowerBinWidget() : base() { }
|
||||||
|
|
||||||
public SpecialPowerBinWidget(Widget other)
|
|
||||||
: base(other)
|
|
||||||
{
|
|
||||||
ready = (other as SpecialPowerBinWidget).ready;
|
|
||||||
clock = (other as SpecialPowerBinWidget).clock;
|
|
||||||
buttons = (other as SpecialPowerBinWidget).buttons;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Widget Clone() { return new SpecialPowerBinWidget(this); }
|
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,140 +16,137 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Drawing;
|
using System;
|
||||||
using System;
|
using System.Drawing;
|
||||||
|
|
||||||
namespace OpenRA.Widgets
|
namespace OpenRA.Widgets
|
||||||
{
|
{
|
||||||
class TextFieldWidget : Widget
|
class TextFieldWidget : Widget
|
||||||
{
|
{
|
||||||
public string Text = "";
|
public string Text = "";
|
||||||
public int MaxLength = 0;
|
public int MaxLength = 0;
|
||||||
public bool Bold = false;
|
public bool Bold = false;
|
||||||
public int VisualHeight = 1;
|
public int VisualHeight = 1;
|
||||||
public Func<bool> OnEnterKey = () => {return false;};
|
public Func<bool> OnEnterKey = () => false;
|
||||||
public Func<bool> OnTabKey = () => {return false;};
|
public Func<bool> OnTabKey = () => false;
|
||||||
public Action OnLoseFocus = () => {};
|
public Action OnLoseFocus = () => { };
|
||||||
|
|
||||||
public TextFieldWidget()
|
public TextFieldWidget()
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextFieldWidget(Widget widget)
|
protected TextFieldWidget(TextFieldWidget widget)
|
||||||
:base(widget)
|
: base(widget)
|
||||||
{
|
{
|
||||||
Text = (widget as TextFieldWidget).Text;
|
Text = widget.Text;
|
||||||
MaxLength = (widget as TextFieldWidget).MaxLength;
|
MaxLength = widget.MaxLength;
|
||||||
Bold = (widget as TextFieldWidget).Bold;
|
Bold = widget.Bold;
|
||||||
VisualHeight = (widget as TextFieldWidget).VisualHeight;
|
VisualHeight = widget.VisualHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool LoseFocus(MouseInput mi)
|
public override bool LoseFocus(MouseInput mi)
|
||||||
{
|
{
|
||||||
OnLoseFocus();
|
OnLoseFocus();
|
||||||
var lose = base.LoseFocus(mi);
|
var lose = base.LoseFocus(mi);
|
||||||
return lose;
|
return lose;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi)
|
public override bool HandleInput(MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Event == MouseInputEvent.Move)
|
if (mi.Event == MouseInputEvent.Move)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Lose focus if they click outside the box; return false so the next widget can grab this event
|
// 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.X,mi.Location.Y) && LoseFocus(mi))
|
if (mi.Event == MouseInputEvent.Down && !RenderBounds.Contains(mi.Location.X, mi.Location.Y) && LoseFocus(mi))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
blinkCycle = 10;
|
blinkCycle = 10;
|
||||||
showCursor = true;
|
showCursor = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleKeyPress(System.Windows.Forms.KeyPressEventArgs e, Modifiers modifiers)
|
public override bool HandleKeyPress(System.Windows.Forms.KeyPressEventArgs e, Modifiers modifiers)
|
||||||
{
|
{
|
||||||
// Only take input if we are focused
|
// Only take input if we are focused
|
||||||
if (!Focused)
|
if (!Focused)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (e.KeyChar == '\r' && OnEnterKey())
|
if (e.KeyChar == '\r' && OnEnterKey())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (e.KeyChar == '\t' && OnTabKey())
|
if (e.KeyChar == '\t' && OnTabKey())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
TypeChar(e.KeyChar);
|
TypeChar(e.KeyChar);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TypeChar(char c)
|
public void TypeChar(char c)
|
||||||
{
|
{
|
||||||
if (c == '\b' || c == 0x7f)
|
if (c == '\b' || c == 0x7f)
|
||||||
{
|
{
|
||||||
if (Text.Length > 0)
|
if (Text.Length > 0)
|
||||||
Text = Text.Remove(Text.Length - 1);
|
Text = Text.Remove(Text.Length - 1);
|
||||||
}
|
}
|
||||||
else if (!char.IsControl(c))
|
else if (!char.IsControl(c))
|
||||||
{
|
{
|
||||||
if (MaxLength > 0 && Text.Length >= MaxLength)
|
if (MaxLength > 0 && Text.Length >= MaxLength)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Text += c;
|
Text += c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int blinkCycle = 10;
|
int blinkCycle = 10;
|
||||||
bool showCursor = true;
|
bool showCursor = true;
|
||||||
public override void Tick(World world)
|
public override void Tick(World world)
|
||||||
{
|
{
|
||||||
if (--blinkCycle <= 0)
|
if (--blinkCycle <= 0)
|
||||||
{
|
{
|
||||||
blinkCycle = 20;
|
blinkCycle = 20;
|
||||||
showCursor ^= true;
|
showCursor ^= true;
|
||||||
}
|
}
|
||||||
base.Tick(world);
|
base.Tick(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawInner(World world)
|
public override void DrawInner(World world)
|
||||||
{
|
{
|
||||||
int margin = 5;
|
int margin = 5;
|
||||||
var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont;
|
var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont;
|
||||||
var cursor = (showCursor && Focused) ? "|" : "";
|
var cursor = (showCursor && Focused) ? "|" : "";
|
||||||
var textSize = font.Measure(Text + "|");
|
var textSize = font.Measure(Text + "|");
|
||||||
var pos = RenderOrigin;
|
var pos = RenderOrigin;
|
||||||
|
|
||||||
WidgetUtils.DrawPanel("dialog3",
|
WidgetUtils.DrawPanel("dialog3",
|
||||||
new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height ) );
|
new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height));
|
||||||
|
|
||||||
// Inset text by the margin and center vertically
|
// Inset text by the margin and center vertically
|
||||||
var textPos = pos + new int2( margin, (Bounds.Height - textSize.Y)/2 - VisualHeight);
|
var textPos = pos + new int2(margin, (Bounds.Height - textSize.Y) / 2 - VisualHeight);
|
||||||
|
|
||||||
// Right align when editing and scissor when the text overflows
|
// Right align when editing and scissor when the text overflows
|
||||||
if (textSize.X > Bounds.Width - 2*margin)
|
if (textSize.X > Bounds.Width - 2 * margin)
|
||||||
{
|
{
|
||||||
if (Focused)
|
if (Focused)
|
||||||
textPos += new int2(Bounds.Width - 2*margin - textSize.X,0);
|
textPos += new int2(Bounds.Width - 2 * margin - textSize.X, 0);
|
||||||
|
|
||||||
Game.chrome.renderer.Device.EnableScissor(pos.X + margin, pos.Y, Bounds.Width - 2*margin, Bounds.Bottom);
|
Game.chrome.renderer.Device.EnableScissor(pos.X + margin, pos.Y, Bounds.Width - 2 * margin, Bounds.Bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
font.DrawText(Text + cursor, textPos, Color.White);
|
font.DrawText(Text + cursor, textPos, Color.White);
|
||||||
|
|
||||||
if (textSize.X > Bounds.Width - 2*margin)
|
if (textSize.X > Bounds.Width - 2 * margin)
|
||||||
{
|
{
|
||||||
Game.chrome.renderer.RgbaSpriteRenderer.Flush();
|
Game.chrome.renderer.RgbaSpriteRenderer.Flush();
|
||||||
Game.chrome.renderer.Device.DisableScissor();
|
Game.chrome.renderer.Device.DisableScissor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Widget Clone()
|
public override Widget Clone() { return new TextFieldWidget(this); }
|
||||||
{
|
}
|
||||||
return new TextFieldWidget(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -22,8 +22,8 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Windows.Forms;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Widgets.Delegates;
|
|
||||||
|
|
||||||
namespace OpenRA.Widgets
|
namespace OpenRA.Widgets
|
||||||
{
|
{
|
||||||
@@ -49,10 +49,10 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
// Common Funcs that most widgets will want
|
// Common Funcs that most widgets will want
|
||||||
public Action<object> SpecialOneArg = (arg) => {};
|
public Action<object> SpecialOneArg = (arg) => {};
|
||||||
public Func<MouseInput,bool> OnMouseDown = mi => {return false;};
|
public Func<MouseInput, bool> OnMouseDown = mi => false;
|
||||||
public Func<MouseInput,bool> OnMouseUp = mi => {return false;};
|
public Func<MouseInput, bool> OnMouseUp = mi => false;
|
||||||
public Func<MouseInput,bool> OnMouseMove = mi => {return false;};
|
public Func<MouseInput, bool> OnMouseMove = mi => false;
|
||||||
public Func<System.Windows.Forms.KeyPressEventArgs, Modifiers,bool> OnKeyPress = (e,modifiers) => {return false;};
|
public Func<KeyPressEventArgs, Modifiers, bool> OnKeyPress = (e, modifiers) => false;
|
||||||
|
|
||||||
public Func<bool> IsVisible;
|
public Func<bool> IsVisible;
|
||||||
|
|
||||||
@@ -82,49 +82,54 @@ namespace OpenRA.Widgets
|
|||||||
foreach(var child in widget.Children)
|
foreach(var child in widget.Children)
|
||||||
AddChild(child.Clone());
|
AddChild(child.Clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Widget Clone();
|
public virtual Widget Clone()
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Widget type `{0}` is not cloneable.".F(GetType().Name));
|
||||||
|
}
|
||||||
|
|
||||||
public virtual int2 RenderOrigin
|
public virtual int2 RenderOrigin
|
||||||
{
|
{
|
||||||
get {
|
get
|
||||||
|
{
|
||||||
var offset = (Parent == null) ? int2.Zero : Parent.ChildOrigin;
|
var offset = (Parent == null) ? int2.Zero : Parent.ChildOrigin;
|
||||||
return new int2(Bounds.X, Bounds.Y) + offset;
|
return new int2(Bounds.X, Bounds.Y) + offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual int2 ChildOrigin { get { return RenderOrigin; } }
|
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 Rectangle RenderBounds { get { return new Rectangle(RenderOrigin.X, RenderOrigin.Y, Bounds.Width, Bounds.Height); } }
|
||||||
|
|
||||||
public virtual void Initialize()
|
public virtual void Initialize()
|
||||||
{
|
{
|
||||||
// Parse the YAML equations to find the widget bounds
|
// Parse the YAML equations to find the widget bounds
|
||||||
Rectangle parentBounds = (Parent == null)
|
var parentBounds = (Parent == null)
|
||||||
? new Rectangle(0,0,Game.viewport.Width,Game.viewport.Height)
|
? new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height)
|
||||||
: Parent.Bounds;
|
: Parent.Bounds;
|
||||||
|
|
||||||
Dictionary<string, int> substitutions = new Dictionary<string, int>();
|
var substitutions = new Dictionary<string, int>();
|
||||||
substitutions.Add("WINDOW_RIGHT", Game.viewport.Width);
|
substitutions.Add("WINDOW_RIGHT", Game.viewport.Width);
|
||||||
substitutions.Add("WINDOW_BOTTOM", Game.viewport.Height);
|
substitutions.Add("WINDOW_BOTTOM", Game.viewport.Height);
|
||||||
substitutions.Add("PARENT_RIGHT", parentBounds.Width);
|
substitutions.Add("PARENT_RIGHT", parentBounds.Width);
|
||||||
substitutions.Add("PARENT_LEFT", parentBounds.Left);
|
substitutions.Add("PARENT_LEFT", parentBounds.Left);
|
||||||
substitutions.Add("PARENT_TOP", parentBounds.Top);
|
substitutions.Add("PARENT_TOP", parentBounds.Top);
|
||||||
substitutions.Add("PARENT_BOTTOM", parentBounds.Height);
|
substitutions.Add("PARENT_BOTTOM", parentBounds.Height);
|
||||||
int width = Evaluator.Evaluate(Width, substitutions);
|
int width = Evaluator.Evaluate(Width, substitutions);
|
||||||
int height = Evaluator.Evaluate(Height, substitutions);
|
int height = Evaluator.Evaluate(Height, substitutions);
|
||||||
|
|
||||||
substitutions.Add("WIDTH", width);
|
substitutions.Add("WIDTH", width);
|
||||||
substitutions.Add("HEIGHT", height);
|
substitutions.Add("HEIGHT", height);
|
||||||
|
|
||||||
Bounds = new Rectangle(Evaluator.Evaluate(X, substitutions),
|
Bounds = new Rectangle(Evaluator.Evaluate(X, substitutions),
|
||||||
Evaluator.Evaluate(Y, substitutions),
|
Evaluator.Evaluate(Y, substitutions),
|
||||||
width,
|
width,
|
||||||
height);
|
height);
|
||||||
|
|
||||||
// Non-static func definitions
|
// Non-static func definitions
|
||||||
|
|
||||||
if (Delegate != null && !Delegates.Contains(Delegate))
|
if (Delegate != null && !Delegates.Contains(Delegate))
|
||||||
Delegates.Add(Delegate);
|
Delegates.Add(Delegate);
|
||||||
|
|
||||||
foreach (var child in Children)
|
foreach (var child in Children)
|
||||||
child.Initialize();
|
child.Initialize();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|||||||
@@ -18,12 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Traits;
|
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Widgets
|
namespace OpenRA.Widgets
|
||||||
{
|
{
|
||||||
@@ -32,10 +31,6 @@ namespace OpenRA.Widgets
|
|||||||
const int worldTooltipDelay = 10; /* ticks */
|
const int worldTooltipDelay = 10; /* ticks */
|
||||||
|
|
||||||
public WorldTooltipWidget() : base() { }
|
public WorldTooltipWidget() : base() { }
|
||||||
|
|
||||||
public WorldTooltipWidget(Widget other) : base(other) { }
|
|
||||||
|
|
||||||
public override Widget Clone() { return new WorldTooltipWidget(this); }
|
|
||||||
|
|
||||||
public override void DrawInner(World world)
|
public override void DrawInner(World world)
|
||||||
{
|
{
|
||||||
@@ -80,7 +75,9 @@ namespace OpenRA.Widgets
|
|||||||
renderer.RegularFont.DrawText(text3,
|
renderer.RegularFont.DrawText(text3,
|
||||||
new float2(Game.chrome.lastMousePos.X + 65 + sz2.X, Game.chrome.lastMousePos.Y + 50), Color.White);
|
new float2(Game.chrome.lastMousePos.X + 65 + sz2.X, Game.chrome.lastMousePos.Y + 50), Color.White);
|
||||||
|
|
||||||
WidgetUtils.DrawRGBA(ChromeProvider.GetImage(Game.chrome.renderer, "flags", actor.Owner.Country.Race), new float2(Game.chrome.lastMousePos.X + 30, Game.chrome.lastMousePos.Y + 50));
|
WidgetUtils.DrawRGBA(
|
||||||
|
ChromeProvider.GetImage(Game.chrome.renderer, "flags", actor.Owner.Country.Race),
|
||||||
|
new float2(Game.chrome.lastMousePos.X + 30, Game.chrome.lastMousePos.Y + 50));
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.RgbaSpriteRenderer.Flush();
|
renderer.RgbaSpriteRenderer.Flush();
|
||||||
|
|||||||
Reference in New Issue
Block a user