remove plenty of redundant junk

This commit is contained in:
Chris Forbes
2010-07-14 19:00:03 +12:00
parent 17bf4610f1
commit fed33fdb00
32 changed files with 1184 additions and 1178 deletions

View File

@@ -67,7 +67,7 @@ namespace OpenRA.FileFormats
}
Preview = Lazy.New(
() => { return new Bitmap(Package.GetContent("preview.png")); }
() => new Bitmap(Package.GetContent("preview.png"))
);
Uid = Package.GetContent("map.uid").ReadAllText();

View File

@@ -18,11 +18,11 @@
*/
#endregion
using System.IO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
namespace OpenRA

View File

@@ -1,10 +1,29 @@
using System;
using System.Collections.Generic;
#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.Linq;
using System.Text;
using System.Net;
using OpenRA.FileFormats;
using System.Text;
using System.Threading;
using OpenRA.FileFormats;
namespace OpenRA.Server
{

View File

@@ -1,4 +1,3 @@
using System.Drawing;
#region Copyright & License Information
/*
* 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(Widget other)
protected BackgroundWidget(BackgroundWidget other)
: base(other)
{
Background = (other as BackgroundWidget).Background;
Background = other.Background;
}
public override Widget Clone() { return new BackgroundWidget(this); }

View File

@@ -18,15 +18,14 @@
*/
#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.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Orders;
using OpenRA.Traits;
namespace OpenRA.Widgets
{
@@ -53,14 +52,6 @@ namespace OpenRA.Widgets
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()
{
base.Initialize();

View File

@@ -18,8 +18,8 @@
*/
#endregion
using System.Drawing;
using System;
using System.Drawing;
namespace OpenRA.Widgets
{
@@ -37,16 +37,16 @@ namespace OpenRA.Widgets
GetText = () => { return Text; };
}
public ButtonWidget(Widget widget)
:base(widget)
protected ButtonWidget(ButtonWidget widget)
: base(widget)
{
Text = (widget as ButtonWidget).Text;
Depressed = (widget as ButtonWidget).Depressed;
VisualHeight = (widget as ButtonWidget).VisualHeight;
GetText = (widget as ButtonWidget).GetText;
Text = widget.Text;
Depressed = widget.Depressed;
VisualHeight = widget.VisualHeight;
GetText = widget.GetText;
}
public override bool LoseFocus (MouseInput mi)
public override bool LoseFocus(MouseInput mi)
{
Depressed = false;
return base.LoseFocus(mi);
@@ -67,7 +67,7 @@ namespace OpenRA.Widgets
if (mi.Event == MouseInputEvent.Down)
Depressed = true;
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;
}
@@ -76,19 +76,16 @@ namespace OpenRA.Widgets
{
var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont;
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();
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,
font.Measure(text).Y / 2) + stateOffset, Color.White);
}
public override Widget Clone()
{
return new ButtonWidget(this);
}
public override Widget Clone() { return new ButtonWidget(this); }
}
}

View File

@@ -18,12 +18,9 @@
*/
#endregion
using OpenRA.FileFormats;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System;
namespace OpenRA.Widgets
{
@@ -35,10 +32,10 @@ namespace OpenRA.Widgets
public List<ChatLine> recentLines = new List<ChatLine>();
public ChatDisplayWidget()
: base() {}
: base() { }
public ChatDisplayWidget(Widget widget)
:base(widget) {}
protected ChatDisplayWidget(Widget widget)
: base(widget) { }
public override void DrawInner(World world)
{
@@ -74,11 +71,13 @@ namespace OpenRA.Widgets
while (recentLines.Count > logLength) recentLines.RemoveAt(0);
}
public override Widget Clone()
{
return new ChatDisplayWidget(this);
}
public override Widget Clone() { return new ChatDisplayWidget(this); }
}
class ChatLine { public Color Color = Color.White; public string Owner, Text; public bool wrapped = false; }
class ChatLine
{
public Color Color = Color.White;
public string Owner, Text;
public bool wrapped = false;
}
}

View File

@@ -56,15 +56,16 @@ namespace OpenRA.Widgets
Game.chrome.lineRenderer.Flush();
}
}
public override bool HandleInput(MouseInput mi) { return true; }
public CheckboxWidget() : base() { }
public CheckboxWidget(Widget other)
protected CheckboxWidget(CheckboxWidget other)
: base(other)
{
Text = (other as CheckboxWidget).Text;
Checked = (other as CheckboxWidget).Checked;
Text = other.Text;
Checked = other.Checked;
}
public override Widget Clone() { return new CheckboxWidget(this); }

View File

@@ -33,10 +33,10 @@ namespace OpenRA.Widgets
GetColor = () => Color.White;
}
public ColorBlockWidget(Widget widget)
:base(widget)
protected ColorBlockWidget(ColorBlockWidget widget)
: base(widget)
{
GetColor = (widget as ColorBlockWidget).GetColor;
GetColor = widget.GetColor;
}
public override Widget Clone()
@@ -47,7 +47,8 @@ namespace OpenRA.Widgets
public override void DrawInner(World world)
{
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,
pos.Y + Game.viewport.Location.Y, Bounds.Width, Bounds.Height);
Game.chrome.lineRenderer.FillRect(paletteRect, GetColor());
}
}

View File

@@ -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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Widgets.Delegates

View File

@@ -17,9 +17,6 @@
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using OpenRA.FileFormats;
using OpenRA.Support;
namespace OpenRA.Widgets.Delegates
{

View File

@@ -18,7 +18,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
@@ -30,7 +29,7 @@ namespace OpenRA.Widgets.Delegates
{
Widget Players, LocalPlayerTemplate, RemotePlayerTemplate;
Dictionary<string,string> CountryNames;
Dictionary<string, string> CountryNames;
string MapUid;
MapStub Map;
@@ -46,9 +45,9 @@ namespace OpenRA.Widgets.Delegates
RemotePlayerTemplate = Players.GetWidget("TEMPLATE_REMOTE");
var map = lobby.GetWidget<MapPreviewWidget>("LOBBY_MAP_PREVIEW");
map.Map = () => {return Map;};
map.OnSpawnClick = sp =>
var mapPreview = lobby.GetWidget<MapPreviewWidget>("LOBBY_MAP_PREVIEW");
mapPreview.Map = () => Map;
mapPreview.OnSpawnClick = sp =>
{
if (Game.LocalClient.State == Session.ClientState.Ready) return;
var owned = Game.LobbyInfo.Clients.Any(c => c.SpawnPoint == sp);
@@ -56,18 +55,18 @@ namespace OpenRA.Widgets.Delegates
Game.IssueOrder(Order.Command("spawn {0}".F(sp)));
};
map.SpawnColors = () =>
mapPreview.SpawnColors = () =>
{
var spawns = Map.SpawnPoints;
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++)
{
var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i);
if (client == null)
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;
};
@@ -76,7 +75,8 @@ namespace OpenRA.Widgets.Delegates
CountryNames.Add("random", "Random");
var mapButton = lobby.GetWidget("CHANGEMAP_BUTTON");
mapButton.OnMouseUp = mi => {
mapButton.OnMouseUp = mi =>
{
r.GetWidget("MAP_CHOOSER").SpecialOneArg(MapUid);
r.OpenWindow("MAP_CHOOSER");
return true;
@@ -85,7 +85,8 @@ namespace OpenRA.Widgets.Delegates
mapButton.IsVisible = () => mapButton.Visible && Game.IsHost;
var disconnectButton = lobby.GetWidget("DISCONNECT_BUTTON");
disconnectButton.OnMouseUp = mi => {
disconnectButton.OnMouseUp = mi =>
{
Game.Disconnect();
return true;
};
@@ -102,7 +103,7 @@ namespace OpenRA.Widgets.Delegates
};
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;
var chatLabel = lobby.GetWidget<LabelWidget>("LABEL_CHATTYPE");
@@ -112,8 +113,8 @@ namespace OpenRA.Widgets.Delegates
if (chatTextField.Text.Length == 0)
return true;
var order = (teamChat) ? Order.TeamChat( chatTextField.Text ) : Order.Chat( chatTextField.Text );
Game.IssueOrder( order );
var order = (teamChat) ? Order.TeamChat(chatTextField.Text) : Order.Chat(chatTextField.Text);
Game.IssueOrder(order);
chatTextField.Text = "";
return true;
};
@@ -131,7 +132,7 @@ namespace OpenRA.Widgets.Delegates
{
if (MapUid == Game.LobbyInfo.GlobalSettings.Map) return;
MapUid = Game.LobbyInfo.GlobalSettings.Map;
Map = Game.AvailableMaps[ MapUid ];
Map = Game.AvailableMaps[MapUid];
}
void UpdatePlayerList()
@@ -141,12 +142,12 @@ namespace OpenRA.Widgets.Delegates
Players.Children.Clear();
int offset = 0;
foreach(var client in Game.LobbyInfo.Clients)
foreach (var client in Game.LobbyInfo.Clients)
{
var c = client;
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();
var name = template.GetWidget<TextFieldWidget>("NAME");
@@ -161,7 +162,7 @@ namespace OpenRA.Widgets.Delegates
if (name.Text == c.Name)
return true;
Game.IssueOrder(Order.Command( "name "+name.Text ));
Game.IssueOrder(Order.Command("name " + name.Text));
Game.Settings.PlayerName = name.Text;
Game.Settings.Save();
return true;
@@ -274,7 +275,7 @@ namespace OpenRA.Widgets.Delegates
{
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(
Order.Command("team " + newIndex));

View File

@@ -17,8 +17,9 @@
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using OpenRA.FileFormats;
namespace OpenRA.Widgets.Delegates
{
public class MainMenuButtonsDelegate : IWidgetDelegate
@@ -27,7 +28,7 @@ namespace OpenRA.Widgets.Delegates
{
// Main menu is the default window
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");

View File

@@ -18,8 +18,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
@@ -36,19 +34,21 @@ namespace OpenRA.Widgets.Delegates
bg.SpecialOneArg = (map) => RefreshMapList(map);
var ml = bg.GetWidget<ListBoxWidget>("MAP_LIST");
bg.GetWidget<MapPreviewWidget>("MAPCHOOSER_MAP_PREVIEW").Map = () => {return Map;};
bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => {return Map.Title;};
bg.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => {return "{0}x{1}".F(Map.Width, Map.Height);};
bg.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => {return Rules.TileSets[Map.Tileset].Name;};
bg.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => {return Map.PlayerCount.ToString();};
bg.GetWidget<MapPreviewWidget>("MAPCHOOSER_MAP_PREVIEW").Map = () => Map;
bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => Map.Title;
bg.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => "{0}x{1}".F(Map.Width, Map.Height);
bg.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => Rules.TileSets[Map.Tileset].Name;
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();
return true;
};
bg.GetWidget("BUTTON_CANCEL").OnMouseUp = mi => {
bg.GetWidget("BUTTON_CANCEL").OnMouseUp = mi =>
{
r.CloseWindow();
return true;
};
@@ -63,9 +63,9 @@ namespace OpenRA.Widgets.Delegates
var template = itemTemplate.Clone() as LabelWidget;
template.Id = "MAP_{0}".F(map.Uid);
template.GetText = () => " "+map.Title;
template.GetText = () => " " + map.Title;
template.GetBackground = () => ((Map == map) ? "dialog2" : null);
template.OnMouseDown = mi => {Map = map; return true;};
template.OnMouseDown = mi => { Map = map; return true; };
template.Parent = ml;
template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
@@ -82,7 +82,7 @@ namespace OpenRA.Widgets.Delegates
// Set the default selected map
var uid = uidobj as string;
if (uid != null)
Map = Game.AvailableMaps[ uid ];
Map = Game.AvailableMaps[uid];
else
Map = Game.AvailableMaps.FirstOrDefault().Value;
}

View File

@@ -17,7 +17,7 @@
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
namespace OpenRA.Widgets.Delegates
{
public class MusicPlayerDelegate : IWidgetDelegate
@@ -27,7 +27,8 @@ namespace OpenRA.Widgets.Delegates
var bg = Chrome.rootWidget.GetWidget("MUSIC_BG");
bg.Visible = Game.Settings.MusicPlayer;
bg.GetWidget("BUTTON_PLAY").OnMouseUp = mi => {
bg.GetWidget("BUTTON_PLAY").OnMouseUp = mi =>
{
if (Sound.MusicStopped)
Sound.PlayMusic(GetSong());
Sound.MusicStopped = false;
@@ -36,19 +37,25 @@ namespace OpenRA.Widgets.Delegates
bg.GetWidget("BUTTON_PAUSE").Visible = true;
return true;
};
bg.GetWidget("BUTTON_PAUSE").OnMouseUp = mi => {
bg.GetWidget("BUTTON_PAUSE").OnMouseUp = mi =>
{
Sound.MusicPaused = true;
bg.GetWidget("BUTTON_PAUSE").Visible = false;
bg.GetWidget("BUTTON_PLAY").Visible = true;
return true;
};
bg.GetWidget("BUTTON_STOP").OnMouseUp = mi => {
bg.GetWidget("BUTTON_STOP").OnMouseUp = mi =>
{
Sound.MusicStopped = true;
bg.GetWidget("BUTTON_PAUSE").Visible = false;
bg.GetWidget("BUTTON_PLAY").Visible = true;
return true;
};
bg.GetWidget("BUTTON_NEXT").OnMouseUp = mi => {
bg.GetWidget("BUTTON_NEXT").OnMouseUp = mi =>
{
Sound.PlayMusic(GetNextSong());
Sound.MusicStopped = false;
Sound.MusicPaused = false;
@@ -56,7 +63,9 @@ namespace OpenRA.Widgets.Delegates
bg.GetWidget("BUTTON_PAUSE").Visible = true;
return true;
};
bg.GetWidget("BUTTON_PREV").OnMouseUp = mi => {
bg.GetWidget("BUTTON_PREV").OnMouseUp = mi =>
{
Sound.PlayMusic(GetPrevSong());
Sound.MusicStopped = false;
Sound.MusicPaused = false;
@@ -71,11 +80,13 @@ namespace OpenRA.Widgets.Delegates
if (!Rules.Music.ContainsKey("allmusic")) return null;
return Rules.Music["allmusic"].Pool.GetNext();
}
string GetPrevSong()
{
if (!Rules.Music.ContainsKey("allmusic")) return null;
return Rules.Music["allmusic"].Pool.GetPrev();
}
string GetSong()
{
if (!Rules.Music.ContainsKey("allmusic")) return null;

View File

@@ -17,8 +17,7 @@
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using OpenRA.FileFormats;
using OpenRA.Support;
namespace OpenRA.Widgets.Delegates
@@ -29,19 +28,17 @@ namespace OpenRA.Widgets.Delegates
{
var r = Chrome.rootWidget;
var perfRoot = r.GetWidget("PERF_BG");
perfRoot.IsVisible = () => {return (perfRoot.Visible && Game.Settings.PerfDebug);};
perfRoot.IsVisible = () => perfRoot.Visible && Game.Settings.PerfDebug;
// Perf text
var perfText = perfRoot.GetWidget<LabelWidget>("TEXT");
perfText.GetText = () => {
return "Render {0} ({5}={2:F1} ms)\nTick {4} ({3:F1} ms)".F(
perfText.GetText = () => "Render {0} ({5}={2:F1} ms)\nTick {4} ({3:F1} ms)".F(
Game.RenderFrame,
Game.orderManager.FrameNumber,
PerfHistory.items["render"].LastValue,
PerfHistory.items["tick_time"].LastValue,
Game.LocalTick,
PerfHistory.items["batches"].LastValue);
};
}
}
}

View File

@@ -21,9 +21,8 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Server;
using OpenRA.FileFormats;
using System;
using OpenRA.Server;
namespace OpenRA.Widgets.Delegates
{
@@ -63,7 +62,7 @@ namespace OpenRA.Widgets.Delegates
preview.IsVisible = () => CurrentMap() != null;
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_PLAYERS").GetText = () =>
{
@@ -71,7 +70,7 @@ namespace OpenRA.Widgets.Delegates
return "";
string ret = currentServer.Players.ToString();
if (CurrentMap() != null)
ret += "/"+CurrentMap().PlayerCount.ToString();
ret += "/" + CurrentMap().PlayerCount.ToString();
return ret;
};
@@ -137,7 +136,8 @@ namespace OpenRA.Widgets.Delegates
};
// Direct Connect
dc.GetWidget("JOIN_BUTTON").OnMouseUp = mi => {
dc.GetWidget("JOIN_BUTTON").OnMouseUp = mi =>
{
var address = dc.GetWidget<TextFieldWidget>("SERVER_ADDRESS").Text;
var cpts = address.Split(':').ToArray();
@@ -152,7 +152,8 @@ namespace OpenRA.Widgets.Delegates
return true;
};
dc.GetWidget("CANCEL_BUTTON").OnMouseUp = mi => {
dc.GetWidget("CANCEL_BUTTON").OnMouseUp = mi =>
{
r.CloseWindow();
return r.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp(mi);
};
@@ -160,7 +161,8 @@ namespace OpenRA.Widgets.Delegates
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)
@@ -190,15 +192,15 @@ namespace OpenRA.Widgets.Delegates
int offset = ServerTemplate.Bounds.Y;
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;
template.Id = "JOIN_GAME_{0}".F(i);
template.GetText = () => " {0} ({1})".F( /* /8 = hack */
game.Name,
game.Address);
template.GetBackground = () => ((currentServer == game) ? "dialog2" : null);
template.OnMouseDown = mi => {currentServer = game; return true;};
template.GetBackground = () => (currentServer == game) ? "dialog2" : null;
template.OnMouseDown = mi => { currentServer = game; return true; };
template.Parent = sl;
template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);

View File

@@ -11,32 +11,31 @@ namespace OpenRA.Widgets
public Func<string> GetImageName;
public Func<string> GetImageCollection;
public ImageWidget ()
public ImageWidget()
: base()
{
GetImageName = () => { return ImageName; };
GetImageCollection = () => { return ImageCollection; };
}
public ImageWidget(Widget other)
protected ImageWidget(ImageWidget other)
: base(other)
{
ImageName = (other as ImageWidget).ImageName;
GetImageName = (other as ImageWidget).GetImageName;
ImageCollection = (other as ImageWidget).ImageCollection;
GetImageCollection = (other as ImageWidget).GetImageCollection;
ImageName = other.ImageName;
GetImageName = other.GetImageName;
ImageCollection = other.ImageCollection;
GetImageCollection = other.GetImageCollection;
}
public override Widget Clone()
{
return new ImageWidget(this);
}
public override Widget Clone() { return new ImageWidget(this); }
public override void DrawInner(World world)
{
var name = GetImageName();
var collection = GetImageCollection();
WidgetUtils.DrawRGBA(ChromeProvider.GetImage(Game.chrome.renderer, collection, name), RenderOrigin);
WidgetUtils.DrawRGBA(
ChromeProvider.GetImage(Game.chrome.renderer, collection, name),
RenderOrigin);
}
}
}

View File

@@ -18,19 +18,14 @@
*/
#endregion
using System.Drawing;
using System;
using System.Drawing;
namespace OpenRA.Widgets
{
class LabelWidget : Widget
{
public enum TextAlign
{
Left,
Center,
Right
}
public enum TextAlign { Left, Center, Right }
public string Text = null;
public string Background = null;
@@ -46,14 +41,14 @@ namespace OpenRA.Widgets
GetBackground = () => { return Background; };
}
public LabelWidget(Widget other)
protected LabelWidget(LabelWidget other)
: base(other)
{
Text = (other as LabelWidget).Text;
Align = (other as LabelWidget).Align;
Bold = (other as LabelWidget).Bold;
GetText = (other as LabelWidget).GetText;
GetBackground = (other as LabelWidget).GetBackground;
Text = other.Text;
Align = other.Align;
Bold = other.Bold;
GetText = other.GetText;
GetBackground = other.GetBackground;
}
public override void DrawInner(World world)
@@ -80,9 +75,6 @@ namespace OpenRA.Widgets
font.DrawText(text, position, Color.White);
}
public override Widget Clone()
{
return new LabelWidget(this);
}
public override Widget Clone() { return new LabelWidget(this); }
}
}

View File

@@ -1,4 +1,3 @@
using System.Drawing;
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
@@ -19,6 +18,8 @@ using System.Drawing;
*/
#endregion
using System.Drawing;
namespace OpenRA.Widgets
{
class ListBoxWidget : Widget
@@ -39,17 +40,17 @@ namespace OpenRA.Widgets
Rectangle scrollbarRect;
public ListBoxWidget() : base() {}
public ListBoxWidget(Widget other)
protected ListBoxWidget(ListBoxWidget other)
: base(other)
{
Background = (other as ListBoxWidget).Background;
upButtonRect = (other as ListBoxWidget).upButtonRect;
downButtonRect = (other as ListBoxWidget).downButtonRect;
scrollbarRect = (other as ListBoxWidget).scrollbarRect;
backgroundRect = (other as ListBoxWidget).backgroundRect;
Background = other.Background;
upButtonRect = other.upButtonRect;
downButtonRect = other.downButtonRect;
scrollbarRect = other.scrollbarRect;
backgroundRect = other.backgroundRect;
UpPressed = (other as ListBoxWidget).UpPressed;
DownPressed = (other as ListBoxWidget).DownPressed;
UpPressed = other.UpPressed;
DownPressed = other.DownPressed;
}
public override void DrawInner(World world) {}
@@ -61,27 +62,26 @@ namespace OpenRA.Widgets
backgroundRect = new Rectangle(RenderBounds.X, RenderBounds.Y, RenderBounds.Width - ScrollbarWidth, RenderBounds.Height);
upButtonRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y, 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 downButtonBg = (DownPressed) ? "dialog3" : "dialog2";
string scrolbarBg = "dialog3";
string scrollbarButton = "dialog2";
string scrollbarBg = "dialog3";
WidgetUtils.DrawPanel(Background, backgroundRect);
WidgetUtils.DrawPanel(upButtonBg, upButtonRect);
WidgetUtils.DrawPanel(downButtonBg, downButtonRect);
WidgetUtils.DrawPanel(scrolbarBg, scrollbarRect);
WidgetUtils.DrawPanel(scrollbarBg, scrollbarRect);
Game.chrome.renderer.Device.EnableScissor(backgroundRect.X, backgroundRect.Y + HeaderHeight, backgroundRect.Width, backgroundRect.Height - HeaderHeight);
foreach (var child in Children)
child.Draw(world);
child.Draw(world);
Game.chrome.renderer.RgbaSpriteRenderer.Flush();
Game.chrome.renderer.Device.DisableScissor();
}
public override int2 ChildOrigin { get { return RenderOrigin + new int2(0, (int)ListOffset); } }
public override void Tick (World world)

View File

@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRA.Graphics;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
namespace OpenRA.Widgets
{
@@ -15,24 +14,25 @@ namespace OpenRA.Widgets
bool mapPreviewDirty = true;
MapStub lastMap;
public Func<MapStub> Map = () => {return null;};
public Func<MapStub> Map = () => null;
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(Widget other)
protected MapPreviewWidget(MapPreviewWidget other)
: base(other)
{
lastMap = (other as MapPreviewWidget).lastMap;
Map = (other as MapPreviewWidget).Map;
OnSpawnClick = (other as MapPreviewWidget).OnSpawnClick;
SpawnColors = (other as MapPreviewWidget).SpawnColors;
lastMap = other.lastMap;
Map = other.Map;
OnSpawnClick = other.OnSpawnClick;
SpawnColors = other.SpawnColors;
}
static Sprite UnownedSpawn = null;
static Sprite OwnedSpawn = null;
const int closeEnough = 50;
public override bool HandleInput(MouseInput mi)
{
var map = Map();

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Widgets
void AddButton(Rectangle r, Action<MouseInput> b) { buttons.Add(Pair.New(r, b)); }
public MoneyBinWidget() : base() { }
public MoneyBinWidget(Widget other) : base(other) { }
protected MoneyBinWidget(Widget other) : base(other) { }
public override Widget Clone() { return new MoneyBinWidget(this); }

View File

@@ -17,8 +17,8 @@
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Support;
@@ -28,18 +28,14 @@ namespace OpenRA.Widgets
{
public PerfGraphWidget() : base() { }
public PerfGraphWidget(Widget other) : base(other) { }
public override Widget Clone() { return new PerfGraphWidget(this); }
public override void DrawInner(World world)
{
var rect = RenderBounds;
float2 origin = Game.viewport.Location + new float2(rect.Right,rect.Bottom);
float2 basis = new float2(-rect.Width/100,-rect.Height/100);
float2 origin = Game.viewport.Location + new float2(rect.Right, rect.Bottom);
float2 basis = new float2(-rect.Width / 100, -rect.Height / 100);
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);
Game.chrome.lineRenderer.DrawLine(origin + new float2(100, 0) * basis, origin + new float2(100, 100) * basis, Color.White, Color.White);
foreach (var item in PerfHistory.items.Values)
{
@@ -48,7 +44,7 @@ namespace OpenRA.Widgets
{
Game.chrome.lineRenderer.DrawLine(
origin + new float2(n, (float)a) * basis,
origin + new float2(n+1, (float)b) * basis,
origin + new float2(n + 1, (float)b) * basis,
item.c, item.c);
++n;
return b;

View File

@@ -28,10 +28,6 @@ namespace OpenRA.Widgets
{
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; }
// todo: all this shit needs to move, probably to Player.

View File

@@ -25,7 +25,6 @@ using OpenRA.Traits;
namespace OpenRA.Widgets
{
public class PowerBinWidget : Widget
{
// Power bar
@@ -35,8 +34,6 @@ namespace OpenRA.Widgets
float? lastPowerDrainedPos;
string powerCollection;
public override Widget Clone() { throw new NotImplementedException("Why are you Cloning PowerBin?"); }
public override void DrawInner(World world)
{
powerCollection = "power-" + world.LocalPlayer.Country.Race;

View File

@@ -76,8 +76,6 @@ namespace OpenRA.Widgets
return true;
}
public override Widget Clone() { throw new NotImplementedException("Why are you Cloning RadarBin?"); }
public override void DrawInner(World world)
{
radarCollection = "radar-" + world.LocalPlayer.Country.Race;
@@ -143,7 +141,7 @@ namespace OpenRA.Widgets
radarMinimapHeight = float2.Lerp(0, 192, (radarAnimationFrame - radarSlideAnimationLength) * 1.0f / radarActivateAnimationLength);
// Animation is complete
if (radarAnimationFrame == (hasRadar ? radarSlideAnimationLength+radarActivateAnimationLength : 0))
if (radarAnimationFrame == (hasRadar ? radarSlideAnimationLength + radarActivateAnimationLength : 0))
radarAnimating = false;
}
}

View File

@@ -14,22 +14,23 @@ namespace OpenRA.Widgets
int2 lastMouseLocation;
bool isMoving = false;
public SliderWidget () : base()
public SliderWidget()
: base()
{
GetOffset = () => Offset;
OnChange = x => Offset = x;
}
public SliderWidget(Widget other)
public SliderWidget(SliderWidget other)
: base(other)
{
OnChange = (other as SliderWidget).OnChange;
GetOffset = (other as SliderWidget).GetOffset;
Offset = (other as SliderWidget).Offset;
Ticks = (other as SliderWidget).Ticks;
TrackHeight = (other as SliderWidget).TrackHeight;
lastMouseLocation = (other as SliderWidget).lastMouseLocation;
isMoving = (other as SliderWidget).isMoving;
OnChange = other.OnChange;
GetOffset = other.GetOffset;
Offset = other.Offset;
Ticks = other.Ticks;
TrackHeight = other.TrackHeight;
lastMouseLocation = other.lastMouseLocation;
isMoving = other.isMoving;
}
public override bool HandleInput(MouseInput mi)
@@ -43,17 +44,17 @@ namespace OpenRA.Widgets
switch (mi.Event)
{
case MouseInputEvent.Up:
{
{
if (Focused)
{
isMoving = false;
base.LoseFocus(mi);
}
}
break;
}
break;
case MouseInputEvent.Down:
{
{
if (thumbRect.Contains(mi.Location.ToPoint()))
{
isMoving = true;
@@ -65,9 +66,9 @@ namespace OpenRA.Widgets
// Offset slightly the direction we want to move so we don't get stuck on a tick
var delta = 0.001;
var targetTick = (float)((mi.Location.X > thumbRect.Right) ? Math.Ceiling((pos+delta)*(Ticks-1))
: Math.Floor((pos-delta)*(Ticks-1)));
OnChange(targetTick/(Ticks-1));
var targetTick = (float)((mi.Location.X > thumbRect.Right) ? Math.Ceiling((pos + delta) * (Ticks - 1))
: Math.Floor((pos - delta) * (Ticks - 1)));
OnChange(targetTick / (Ticks - 1));
if (thumbRect.Contains(mi.Location.ToPoint()))
{
@@ -79,8 +80,8 @@ namespace OpenRA.Widgets
else // No ticks; move to the mouse position
{
var thumb = thumbRect;
var center = thumb.X + thumb.Width/2;
var newOffset = OffsetBy((mi.Location.X - center)*1f/(RenderBounds.Width-thumb.Width));
var center = thumb.X + thumb.Width / 2;
var newOffset = OffsetBy((mi.Location.X - center) * 1f / (RenderBounds.Width - thumb.Width));
if (newOffset != GetOffset())
{
OnChange(newOffset);
@@ -93,25 +94,25 @@ namespace OpenRA.Widgets
return true;
}
}
}
break;
}
break;
case MouseInputEvent.Move:
{
if ((mi.Location.X != lastMouseLocation.X) && isMoving)
{
var newOffset = OffsetBy((mi.Location.X - lastMouseLocation.X)*1f/(RenderBounds.Width-thumbRect.Width));
if (newOffset != Offset)
if ((mi.Location.X != lastMouseLocation.X) && isMoving)
{
lastMouseLocation = mi.Location;
OnChange(newOffset);
var newOffset = OffsetBy((mi.Location.X - lastMouseLocation.X) * 1f / (RenderBounds.Width - thumbRect.Width));
if (newOffset != Offset)
{
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)
@@ -125,26 +126,30 @@ namespace OpenRA.Widgets
public override Widget Clone() { return new SliderWidget(this); }
Rectangle thumbRect
{ get {
var width = RenderBounds.Height;
var height = RenderBounds.Height;
var origin = (int)((RenderBounds.X + width/2) + GetOffset()*(RenderBounds.Width - width) - width/2f);
return new Rectangle(origin, RenderBounds.Y, width, height);
} }
{
get
{
var width = RenderBounds.Height;
var height = RenderBounds.Height;
var origin = (int)((RenderBounds.X + width / 2) + GetOffset() * (RenderBounds.Width - width) - width / 2f);
return new Rectangle(origin, RenderBounds.Y, width, height);
}
}
public override void DrawInner(World world) {
public override void DrawInner(World world)
{
if (!IsVisible())
return;
var trackWidth = RenderBounds.Width - thumbRect.Width;
var trackOrigin = RenderBounds.X + thumbRect.Width/2;
var trackRect = new Rectangle(trackOrigin-1, RenderBounds.Y + (RenderBounds.Height - TrackHeight)/2, trackWidth+2, TrackHeight);
var trackOrigin = RenderBounds.X + thumbRect.Width / 2;
var trackRect = new Rectangle(trackOrigin - 1, RenderBounds.Y + (RenderBounds.Height - TrackHeight) / 2, trackWidth + 2, TrackHeight);
// Tickmarks (hacked until we have real art)
for (int i = 0; i < Ticks; i++)
{
var tickRect = new Rectangle(trackOrigin -1 + (int)(i*trackWidth*1f/(Ticks-1)),
RenderBounds.Y + RenderBounds.Height/2, 2, RenderBounds.Height/2);
var tickRect = new Rectangle(trackOrigin - 1 + (int)(i * trackWidth * 1f / (Ticks - 1)),
RenderBounds.Y + RenderBounds.Height / 2, 2, RenderBounds.Height / 2);
WidgetUtils.DrawPanel("dialog2", tickRect);
}
// Track

View File

@@ -18,14 +18,14 @@
*/
#endregion
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using OpenRA;
using OpenRA.Traits;
using OpenRA.Graphics;
using OpenRA.FileFormats;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Widgets
{
class SpecialPowerBinWidget : Widget
@@ -37,16 +37,6 @@ namespace OpenRA.Widgets
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()
{
base.Initialize();

View File

@@ -18,8 +18,8 @@
*/
#endregion
using System.Drawing;
using System;
using System.Drawing;
namespace OpenRA.Widgets
{
@@ -29,22 +29,22 @@ namespace OpenRA.Widgets
public int MaxLength = 0;
public bool Bold = false;
public int VisualHeight = 1;
public Func<bool> OnEnterKey = () => {return false;};
public Func<bool> OnTabKey = () => {return false;};
public Action OnLoseFocus = () => {};
public Func<bool> OnEnterKey = () => false;
public Func<bool> OnTabKey = () => false;
public Action OnLoseFocus = () => { };
public TextFieldWidget()
: base()
{
}
public TextFieldWidget(Widget widget)
:base(widget)
protected TextFieldWidget(TextFieldWidget widget)
: base(widget)
{
Text = (widget as TextFieldWidget).Text;
MaxLength = (widget as TextFieldWidget).MaxLength;
Bold = (widget as TextFieldWidget).Bold;
VisualHeight = (widget as TextFieldWidget).VisualHeight;
Text = widget.Text;
MaxLength = widget.MaxLength;
Bold = widget.Bold;
VisualHeight = widget.VisualHeight;
}
public override bool LoseFocus(MouseInput mi)
@@ -60,7 +60,7 @@ namespace OpenRA.Widgets
return false;
// Lose focus if they click outside the box; return false so the next widget can grab this event
if (mi.Event == MouseInputEvent.Down && !RenderBounds.Contains(mi.Location.X,mi.Location.Y) && LoseFocus(mi))
if (mi.Event == MouseInputEvent.Down && !RenderBounds.Contains(mi.Location.X, mi.Location.Y) && LoseFocus(mi))
return false;
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
@@ -124,32 +124,29 @@ namespace OpenRA.Widgets
var pos = RenderOrigin;
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
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
if (textSize.X > Bounds.Width - 2*margin)
if (textSize.X > Bounds.Width - 2 * margin)
{
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);
if (textSize.X > Bounds.Width - 2*margin)
if (textSize.X > Bounds.Width - 2 * margin)
{
Game.chrome.renderer.RgbaSpriteRenderer.Flush();
Game.chrome.renderer.Device.DisableScissor();
}
}
public override Widget Clone()
{
return new TextFieldWidget(this);
}
public override Widget Clone() { return new TextFieldWidget(this); }
}
}

View File

@@ -22,8 +22,8 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using OpenRA.FileFormats;
using OpenRA.Widgets.Delegates;
namespace OpenRA.Widgets
{
@@ -49,10 +49,10 @@ namespace OpenRA.Widgets
// Common Funcs that most widgets will want
public Action<object> SpecialOneArg = (arg) => {};
public Func<MouseInput,bool> OnMouseDown = mi => {return false;};
public Func<MouseInput,bool> OnMouseUp = mi => {return false;};
public Func<MouseInput,bool> OnMouseMove = mi => {return false;};
public Func<System.Windows.Forms.KeyPressEventArgs, Modifiers,bool> OnKeyPress = (e,modifiers) => {return false;};
public Func<MouseInput, bool> OnMouseDown = mi => false;
public Func<MouseInput, bool> OnMouseUp = mi => false;
public Func<MouseInput, bool> OnMouseMove = mi => false;
public Func<KeyPressEventArgs, Modifiers, bool> OnKeyPress = (e, modifiers) => false;
public Func<bool> IsVisible;
@@ -83,32 +83,37 @@ namespace OpenRA.Widgets
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
{
get {
get
{
var offset = (Parent == null) ? int2.Zero : Parent.ChildOrigin;
return new int2(Bounds.X, Bounds.Y) + offset;
}
}
public virtual int2 ChildOrigin { get { return RenderOrigin; } }
public virtual Rectangle RenderBounds { get { return new Rectangle(RenderOrigin.X, RenderOrigin.Y, Bounds.Width, Bounds.Height); } }
public virtual void Initialize()
{
// Parse the YAML equations to find the widget bounds
Rectangle parentBounds = (Parent == null)
? new Rectangle(0,0,Game.viewport.Width,Game.viewport.Height)
var parentBounds = (Parent == null)
? new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height)
: Parent.Bounds;
Dictionary<string, int> substitutions = new Dictionary<string, int>();
substitutions.Add("WINDOW_RIGHT", Game.viewport.Width);
substitutions.Add("WINDOW_BOTTOM", Game.viewport.Height);
substitutions.Add("PARENT_RIGHT", parentBounds.Width);
substitutions.Add("PARENT_LEFT", parentBounds.Left);
substitutions.Add("PARENT_TOP", parentBounds.Top);
substitutions.Add("PARENT_BOTTOM", parentBounds.Height);
var substitutions = new Dictionary<string, int>();
substitutions.Add("WINDOW_RIGHT", Game.viewport.Width);
substitutions.Add("WINDOW_BOTTOM", Game.viewport.Height);
substitutions.Add("PARENT_RIGHT", parentBounds.Width);
substitutions.Add("PARENT_LEFT", parentBounds.Left);
substitutions.Add("PARENT_TOP", parentBounds.Top);
substitutions.Add("PARENT_BOTTOM", parentBounds.Height);
int width = Evaluator.Evaluate(Width, substitutions);
int height = Evaluator.Evaluate(Height, substitutions);
@@ -116,14 +121,14 @@ namespace OpenRA.Widgets
substitutions.Add("HEIGHT", height);
Bounds = new Rectangle(Evaluator.Evaluate(X, substitutions),
Evaluator.Evaluate(Y, substitutions),
width,
height);
Evaluator.Evaluate(Y, substitutions),
width,
height);
// Non-static func definitions
if (Delegate != null && !Delegates.Contains(Delegate))
Delegates.Add(Delegate);
Delegates.Add(Delegate);
foreach (var child in Children)
child.Initialize();

View File

@@ -18,7 +18,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.FileFormats;
using OpenRA.Widgets;

View File

@@ -18,12 +18,11 @@
*/
#endregion
using System;
using System.Drawing;
using System.Linq;
using OpenRA.Traits;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Widgets
{
@@ -33,10 +32,6 @@ namespace OpenRA.Widgets
public WorldTooltipWidget() : base() { }
public WorldTooltipWidget(Widget other) : base(other) { }
public override Widget Clone() { return new WorldTooltipWidget(this); }
public override void DrawInner(World world)
{
if (Game.chrome.ticksSinceLastMove < worldTooltipDelay || world == null || world.LocalPlayer == null)
@@ -80,7 +75,9 @@ namespace OpenRA.Widgets
renderer.RegularFont.DrawText(text3,
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();