StyleCop clean Cnc DLL

This commit is contained in:
Matthias Mailänder
2013-08-03 18:14:54 +02:00
parent bcce9ea7f0
commit d278bc84d1
24 changed files with 315 additions and 307 deletions

View File

@@ -26,12 +26,11 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
var hotkeyLabel = "({0})".F(button.Key.ToUpperInvariant());
hotkey.GetText = () => hotkeyLabel;
hotkey.Bounds.X = labelWidth + 2*label.Bounds.X;
hotkey.Bounds.X = labelWidth + 2 * label.Bounds.X;
var panelWidth = hotkey.Bounds.X + label.Bounds.X
+ Game.Renderer.Fonts[label.Font].Measure(hotkeyLabel).X;
widget.Bounds.Width = panelWidth;
}
}
}
}

View File

@@ -24,6 +24,17 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
Widget ingameRoot;
World world;
static void BindOrderButton<T>(World world, Widget parent, string button, string icon)
where T : IOrderGenerator, new()
{
var w = parent.Get<ButtonWidget>(button);
w.OnClick = () => world.ToggleInputMode<T>();
w.IsHighlighted = () => world.OrderGenerator is T;
w.Get<ImageWidget>("ICON").GetImageName =
() => world.OrderGenerator is T ? icon + "-active" : icon;
}
void AddChatLine(Color c, string from, string text)
{
ingameRoot.Get<ChatDisplayWidget>("CHAT_DISPLAY").AddLine(c, from, text);
@@ -114,7 +125,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
.Any(a => a.Actor.Owner == world.LocalPlayer && a.Trait.IsActive);
if (radarEnabled != cachedRadarEnabled)
Sound.PlayNotification(null, "Sounds", (radarEnabled ? "RadarUp" : "RadarDown"), null);
Sound.PlayNotification(null, "Sounds", radarEnabled ? "RadarUp" : "RadarDown", null);
cachedRadarEnabled = radarEnabled;
// Switch to observer mode after win/loss
@@ -152,16 +163,5 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
return Color.LimeGreen;
};
}
static void BindOrderButton<T>(World world, Widget parent, string button, string icon)
where T : IOrderGenerator, new()
{
var w = parent.Get<ButtonWidget>(button);
w.OnClick = () => world.ToggleInputMode<T>();
w.IsHighlighted = () => world.OrderGenerator is T;
w.Get<ImageWidget>("ICON").GetImageName =
() => world.OrderGenerator is T ? icon+"-active" : icon;
}
}
}

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
});
};
Action doNothing = () => {};
Action doNothing = () => { };
menu.Get<ButtonWidget>("QUIT_BUTTON").OnClick = () =>
CncWidgetUtils.PromptConfirmAction("Abort Mission", "Leave this game and return to the menu?", onQuit, doNothing);
@@ -92,35 +92,35 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
// Menu panels - ordered from lowest to highest priority
var panelParent = Game.OpenWindow(world, "INGAME_MENU_PANEL");
PanelType Panel = PanelType.Objectives;
PanelType panelType = PanelType.Objectives;
var visibleButtons = 0;
// Debug / Cheats panel
var debugButton = panelParent.Get<ButtonWidget>("DEBUG_BUTTON");
debugButton.OnClick = () => Panel = PanelType.Debug;
debugButton.IsHighlighted = () => Panel == PanelType.Debug;
debugButton.OnClick = () => panelType = PanelType.Debug;
debugButton.IsHighlighted = () => panelType == PanelType.Debug;
if (world.LocalPlayer != null && world.LobbyInfo.GlobalSettings.AllowCheats)
{
Panel = PanelType.Debug;
panelType = PanelType.Debug;
visibleButtons++;
var debugPanel = Game.LoadWidget(world, "CHEATS_PANEL", panelParent, new WidgetArgs(){{"onExit", doNothing}});
debugPanel.IsVisible = () => Panel == PanelType.Debug;
var debugPanel = Game.LoadWidget(world, "CHEATS_PANEL", panelParent, new WidgetArgs() { { "onExit", doNothing } });
debugPanel.IsVisible = () => panelType == PanelType.Debug;
debugButton.IsVisible = () => visibleButtons > 1;
}
// Mission objectives
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
var objectivesButton = panelParent.Get<ButtonWidget>("OBJECTIVES_BUTTON");
objectivesButton.OnClick = () => Panel = PanelType.Objectives;
objectivesButton.IsHighlighted = () => Panel == PanelType.Objectives;
objectivesButton.OnClick = () => panelType = PanelType.Objectives;
objectivesButton.IsHighlighted = () => panelType == PanelType.Objectives;
if (iop != null && iop.ObjectivesPanel != null)
{
Panel = PanelType.Objectives;
panelType = PanelType.Objectives;
visibleButtons++;
var objectivesPanel = Game.LoadWidget(world, iop.ObjectivesPanel, panelParent, new WidgetArgs());
objectivesPanel.IsVisible = () => Panel == PanelType.Objectives;
objectivesPanel.IsVisible = () => panelType == PanelType.Objectives;
objectivesButton.IsVisible = () => visibleButtons > 1;
}
}

View File

@@ -54,9 +54,9 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
public static bool IsValidDisk(string diskRoot)
{
var files = new string[][] {
new [] { diskRoot, "CONQUER.MIX" },
new [] { diskRoot, "DESERT.MIX" },
new [] { diskRoot, "INSTALL", "SETUP.Z" },
new[] { diskRoot, "CONQUER.MIX" },
new[] { diskRoot, "DESERT.MIX" },
new[] { diskRoot, "INSTALL", "SETUP.Z" },
};
return files.All(f => File.Exists(f.Aggregate(Path.Combine)));
@@ -89,7 +89,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
var installTotal = filesToExtract.Count() + filesToExtract.Count();
var onProgress = (Action<string>)(s => Game.RunAfterTick(() =>
{
progressBar.Percentage = installCounter*100/installTotal;
progressBar.Percentage = installCounter * 100 / installTotal;
installCounter++;
statusLabel.GetText = () => s;
@@ -97,12 +97,12 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
var onError = (Action<string>)(s => Game.RunAfterTick(() =>
{
statusLabel.GetText = () => "Error: "+s;
statusLabel.GetText = () => "Error: " + s;
backButton.IsDisabled = () => false;
retryButton.IsDisabled = () => false;
}));
new Thread( _ =>
new Thread(_ =>
{
try
{

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
public class CncInstallLogic
{
[ObjectCreator.UseCtor]
public CncInstallLogic(Widget widget, Dictionary<string,string> installData, Action continueLoading)
public CncInstallLogic(Widget widget, Dictionary<string, string> installData, Action continueLoading)
{
var panel = widget.Get("INSTALL_PANEL");
var args = new WidgetArgs()
@@ -43,8 +43,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
{
Ui.OpenWindow("MODS_PANEL", new WidgetArgs()
{
{ "onExit", () => {} },
// Close this panel
{ "onExit", () => { } },
{ "onSwitch", Ui.CloseWindow },
});
};

View File

@@ -16,9 +16,9 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
{
public class CncMenuLogic
{
enum MenuType { Main, Multiplayer, Settings, None }
enum MenuType { Main, Multiplayer, Settings, None }
MenuType Menu = MenuType.Main;
MenuType menuType = MenuType.Main;
Widget rootMenu;
[ObjectCreator.UseCtor]
@@ -32,85 +32,85 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
// Menu buttons
var mainMenu = widget.Get("MAIN_MENU");
mainMenu.IsVisible = () => Menu == MenuType.Main;
mainMenu.IsVisible = () => menuType == MenuType.Main;
mainMenu.Get<ButtonWidget>("SOLO_BUTTON").OnClick = StartSkirmishGame;
mainMenu.Get<ButtonWidget>("MULTIPLAYER_BUTTON").OnClick = () => Menu = MenuType.Multiplayer;
mainMenu.Get<ButtonWidget>("MULTIPLAYER_BUTTON").OnClick = () => menuType = MenuType.Multiplayer;
mainMenu.Get<ButtonWidget>("MODS_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
menuType = MenuType.None;
Ui.OpenWindow("MODS_PANEL", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Main },
{ "onExit", () => menuType = MenuType.Main },
{ "onSwitch", RemoveShellmapUI }
});
};
mainMenu.Get<ButtonWidget>("SETTINGS_BUTTON").OnClick = () => Menu = MenuType.Settings;
mainMenu.Get<ButtonWidget>("SETTINGS_BUTTON").OnClick = () => menuType = MenuType.Settings;
mainMenu.Get<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit;
// Multiplayer menu
var multiplayerMenu = widget.Get("MULTIPLAYER_MENU");
multiplayerMenu.IsVisible = () => Menu == MenuType.Multiplayer;
multiplayerMenu.IsVisible = () => menuType == MenuType.Multiplayer;
multiplayerMenu.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => Menu = MenuType.Main;
multiplayerMenu.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => menuType = MenuType.Main;
multiplayerMenu.Get<ButtonWidget>("JOIN_BUTTON").OnClick = () => OpenGamePanel("SERVERBROWSER_PANEL");
multiplayerMenu.Get<ButtonWidget>("CREATE_BUTTON").OnClick = () => OpenGamePanel("CREATESERVER_PANEL");
multiplayerMenu.Get<ButtonWidget>("DIRECTCONNECT_BUTTON").OnClick = () => OpenGamePanel("DIRECTCONNECT_PANEL");
// Settings menu
var settingsMenu = widget.Get("SETTINGS_MENU");
settingsMenu.IsVisible = () => Menu == MenuType.Settings;
settingsMenu.IsVisible = () => menuType == MenuType.Settings;
settingsMenu.Get<ButtonWidget>("REPLAYS_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
menuType = MenuType.None;
Ui.OpenWindow("REPLAYBROWSER_PANEL", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Settings },
{ "onExit", () => menuType = MenuType.Settings },
{ "onStart", RemoveShellmapUI }
});
};
settingsMenu.Get<ButtonWidget>("MUSIC_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
menuType = MenuType.None;
Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Settings },
{ "onExit", () => menuType = MenuType.Settings },
});
};
settingsMenu.Get<ButtonWidget>("CREDITS_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
menuType = MenuType.None;
Ui.OpenWindow("CREDITS_PANEL", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Settings },
{ "onExit", () => menuType = MenuType.Settings },
});
};
settingsMenu.Get<ButtonWidget>("SETTINGS_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
menuType = MenuType.None;
Game.OpenWindow("SETTINGS_PANEL", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Settings },
{ "onExit", () => menuType = MenuType.Settings },
});
};
settingsMenu.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => Menu = MenuType.Main;
settingsMenu.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => menuType = MenuType.Main;
rootMenu.Get<ImageWidget>("RECBLOCK").IsVisible = () => world.FrameNumber / 25 % 2 == 0;
}
void OpenGamePanel(string id)
{
Menu = MenuType.None;
menuType = MenuType.None;
Ui.OpenWindow(id, new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Multiplayer },
{ "onExit", () => menuType = MenuType.Multiplayer },
{ "openLobby", () => OpenLobbyPanel(MenuType.Multiplayer, false) }
});
}
@@ -122,10 +122,10 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
void OpenLobbyPanel(MenuType menu, bool addBots)
{
Menu = MenuType.None;
menuType = MenuType.None;
Game.OpenWindow("SERVER_LOBBY", new WidgetArgs()
{
{ "onExit", () => { Game.Disconnect(); Menu = menu; } },
{ "onExit", () => { Game.Disconnect(); menuType = menu; } },
{ "onStart", RemoveShellmapUI },
{ "addBots", addBots }
});
@@ -138,7 +138,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
ConnectionLogic.Connect(IPAddress.Loopback.ToString(),
Game.CreateLocalServer(map),
() => OpenLobbyPanel(MenuType.Main, true),
() => { Game.CloseServer(); Menu = MenuType.Main; });
() => { Game.CloseServer(); menuType = MenuType.Main; });
}
}
}

View File

@@ -16,9 +16,9 @@ using OpenRA.FileFormats;
using OpenRA.FileFormats.Graphics;
using OpenRA.GameRules;
using OpenRA.Mods.RA;
using OpenRA.Mods.RA.Widgets;
using OpenRA.Mods.RA.Widgets.Logic;
using OpenRA.Widgets;
using OpenRA.Mods.RA.Widgets;
namespace OpenRA.Mods.Cnc.Widgets.Logic
{
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
enum PanelType { General, Input }
SoundDevice soundDevice;
PanelType Settings = PanelType.General;
PanelType settingsPanel = PanelType.General;
ColorPreviewManagerWidget colorPreview;
World world;
@@ -39,11 +39,11 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
// General pane
var generalButton = panel.Get<ButtonWidget>("GENERAL_BUTTON");
generalButton.OnClick = () => Settings = PanelType.General;
generalButton.IsHighlighted = () => Settings == PanelType.General;
generalButton.OnClick = () => settingsPanel = PanelType.General;
generalButton.IsHighlighted = () => settingsPanel == PanelType.General;
var generalPane = panel.Get("GENERAL_CONTROLS");
generalPane.IsVisible = () => Settings == PanelType.General;
generalPane.IsVisible = () => settingsPanel == PanelType.General;
var gameSettings = Game.Settings.Game;
var playerSettings = Game.Settings.Player;
@@ -102,7 +102,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
// Audio
var soundSlider = generalPane.Get<SliderWidget>("SOUND_SLIDER");
soundSlider.OnChange += x => { soundSettings.SoundVolume = x; Sound.SoundVolume = x;};
soundSlider.OnChange += x => { soundSettings.SoundVolume = x; Sound.SoundVolume = x; };
soundSlider.Value = soundSettings.SoundVolume;
var musicSlider = generalPane.Get<SliderWidget>("MUSIC_SLIDER");
@@ -122,11 +122,11 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
// Input pane
var inputPane = panel.Get("INPUT_CONTROLS");
inputPane.IsVisible = () => Settings == PanelType.Input;
inputPane.IsVisible = () => settingsPanel == PanelType.Input;
var inputButton = panel.Get<ButtonWidget>("INPUT_BUTTON");
inputButton.OnClick = () => Settings = PanelType.Input;
inputButton.IsHighlighted = () => Settings == PanelType.Input;
inputButton.OnClick = () => settingsPanel = PanelType.Input;
inputButton.IsHighlighted = () => settingsPanel == PanelType.Input;
var classicMouseCheckbox = inputPane.Get<CheckboxWidget>("CLASSICORDERS_CHECKBOX");
classicMouseCheckbox.IsChecked = () => gameSettings.UseClassicMouseStyle;
@@ -154,7 +154,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
int x, y;
int.TryParse(windowWidth.Text, out x);
int.TryParse(windowHeight.Text, out y);
graphicsSettings.WindowedSize = new int2(x,y);
graphicsSettings.WindowedSize = new int2(x, y);
soundSettings.Device = soundDevice.Device;
soundSettings.Engine = soundDevice.Engine;
Game.Settings.Save();
@@ -163,6 +163,28 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
};
}
static bool ShowMouseScrollDropdown(DropDownButtonWidget dropdown, GameSettings s)
{
var options = new Dictionary<string, MouseScrollType>()
{
{ "Disabled", MouseScrollType.Disabled },
{ "Standard", MouseScrollType.Standard },
{ "Inverted", MouseScrollType.Inverted },
};
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
{
var item = ScrollItemWidget.Setup(itemTemplate,
() => s.MouseScroll == options[o],
() => s.MouseScroll = options[o]);
item.Get<LabelWidget>("LABEL").GetText = () => o;
return item;
};
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, setupItem);
return true;
}
bool ShowColorPicker(DropDownButtonWidget color, PlayerSettings s)
{
Action<HSLColor> onChange = c => colorPreview.Color = c;
@@ -183,28 +205,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
return true;
}
static bool ShowMouseScrollDropdown(DropDownButtonWidget dropdown, GameSettings s)
{
var options = new Dictionary<string, MouseScrollType>()
{
{ "Disabled", MouseScrollType.Disabled },
{ "Standard", MouseScrollType.Standard },
{ "Inverted", MouseScrollType.Inverted },
};
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
{
var item = ScrollItemWidget.Setup(itemTemplate,
() => s.MouseScroll == options[o],
() => s.MouseScroll = options[o]);
item.Get<LabelWidget>("LABEL").GetText = () => o;
return item;
};
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, setupItem);
return true;
}
bool ShowAudioDeviceDropdown(DropDownButtonWidget dropdown, SoundSettings s, SoundDevice[] devices)
{
var i = 0;

View File

@@ -10,8 +10,8 @@
using System;
using System.Drawing;
using OpenRA.Mods.RA.Orders;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Orders;
using OpenRA.Traits;
using OpenRA.Widgets;
@@ -42,8 +42,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
var chromeName = button.ProductionGroup.ToLowerInvariant();
var icon = button.Get<ImageWidget>("ICON");
icon.GetImageName = () => button.IsDisabled() ? chromeName+"-disabled" :
tabs.Groups[button.ProductionGroup].Alert ? chromeName+"-alert" : chromeName;
icon.GetImageName = () => button.IsDisabled() ? chromeName + "-disabled" :
tabs.Groups[button.ProductionGroup].Alert ? chromeName + "-alert" : chromeName;
}
[ObjectCreator.UseCtor]

View File

@@ -23,8 +23,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
[ObjectCreator.UseCtor]
public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, ProductionPaletteWidget palette)
{
var pm = palette.world.LocalPlayer.PlayerActor.Trait<PowerManager>();
var pr = palette.world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
var pm = palette.World.LocalPlayer.PlayerActor.Trait<PowerManager>();
var pr = palette.World.LocalPlayer.PlayerActor.Trait<PlayerResources>();
widget.IsVisible = () => palette.TooltipActor != null;
var nameLabel = widget.Get<LabelWidget>("NAME");
@@ -75,20 +75,20 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
var descString = tooltip.Description.Replace("\\n", "\n");
descLabel.GetText = () => descString;
var leftWidth = new [] {font.Measure(tooltip.Name).X, requiresFont.Measure(requiresString).X, descFont.Measure(descString).X}.Aggregate(Math.Max);
var rightWidth = new [] {font.Measure(powerString).X, font.Measure(timeString).X, font.Measure(costString).X}.Aggregate(Math.Max);
timeLabel.Bounds.X = powerLabel.Bounds.X = costLabel.Bounds.X = leftWidth + 2*nameLabel.Bounds.X;
widget.Bounds.Width = leftWidth + rightWidth + 3*nameLabel.Bounds.X;
var leftWidth = new[] { font.Measure(tooltip.Name).X, requiresFont.Measure(requiresString).X, descFont.Measure(descString).X }.Aggregate(Math.Max);
var rightWidth = new[] { font.Measure(powerString).X, font.Measure(timeString).X, font.Measure(costString).X }.Aggregate(Math.Max);
timeLabel.Bounds.X = powerLabel.Bounds.X = costLabel.Bounds.X = leftWidth + 2 * nameLabel.Bounds.X;
widget.Bounds.Width = leftWidth + rightWidth + 3 * nameLabel.Bounds.X;
var leftHeight = font.Measure(tooltip.Name).Y + requiresFont.Measure(requiresString).Y + descFont.Measure(descString).Y;
var rightHeight = font.Measure(powerString).Y + font.Measure(timeString).Y + font.Measure(costString).Y;
widget.Bounds.Height = Math.Max(leftHeight, rightHeight)*3/2 + 3*nameLabel.Bounds.Y;
widget.Bounds.Height = Math.Max(leftHeight, rightHeight) * 3 / 2 + 3 * nameLabel.Bounds.Y;
lastActor = actor;
};
}
static string ActorName( string a )
static string ActorName(string a)
{
ActorInfo ai;
Rules.Info.TryGetValue(a.ToLowerInvariant(), out ai);
@@ -98,5 +98,4 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
return a;
}
}
}
}

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
return; // no instances actually exist (race with destroy)
time = "{0} / {1}".F(WidgetUtils.FormatTime(sp.RemainingTime),
WidgetUtils.FormatTime(sp.Info.ChargeTime*25));
WidgetUtils.FormatTime(sp.Info.ChargeTime * 25));
if (sp == lastPower)
return;
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
var timeWidth = timeFont.Measure(time).X;
var topWidth = nameFont.Measure(name).X + timeWidth + timeOffset;
var descSize = descFont.Measure(desc);
widget.Bounds.Width = 2*nameLabel.Bounds.X + Math.Max(topWidth, descSize.X);
widget.Bounds.Width = 2 * nameLabel.Bounds.X + Math.Max(topWidth, descSize.X);
widget.Bounds.Height = baseHeight + descSize.Y;
timeLabel.Bounds.X = widget.Bounds.Width - nameLabel.Bounds.X - timeWidth;
lastPower = sp;
@@ -64,5 +64,4 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
descLabel.GetText = () => desc;
}
}
}
}