From 49ec533481aba078871389a7b54bc2a489fd459f Mon Sep 17 00:00:00 2001 From: Pavlos Touboulidis Date: Sun, 11 May 2014 01:26:11 +0300 Subject: [PATCH] Better distinction between Widgets using the mod's DefaultRules or the map's Rules --- OpenRA.Game/Widgets/ButtonWidget.cs | 16 ++++++------ OpenRA.Game/Widgets/CheckboxWidget.cs | 4 +-- OpenRA.Game/Widgets/DropDownButtonWidget.cs | 4 +-- OpenRA.Game/Widgets/ScrollItemWidget.cs | 4 +-- OpenRA.Game/Widgets/WidgetLoader.cs | 4 +-- .../Widgets/Logic/CncInstallMusicLogic.cs | 6 ++--- .../Widgets/ProductionTypeButtonWidget.cs | 4 +-- OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs | 26 +++++++++---------- 8 files changed, 34 insertions(+), 34 deletions(-) diff --git a/OpenRA.Game/Widgets/ButtonWidget.cs b/OpenRA.Game/Widgets/ButtonWidget.cs index e6641726cb..0f63ece79f 100644 --- a/OpenRA.Game/Widgets/ButtonWidget.cs +++ b/OpenRA.Game/Widgets/ButtonWidget.cs @@ -55,12 +55,12 @@ namespace OpenRA.Widgets public Action OnDoubleClick = () => {}; public Action OnKeyPress = _ => {}; - readonly Ruleset rules; + readonly Ruleset modRules; [ObjectCreator.UseCtor] - public ButtonWidget(Ruleset rules) + public ButtonWidget(Ruleset modRules) { - this.rules = rules; + this.modRules = modRules; GetText = () => { return Text; }; GetColor = () => TextColor; @@ -77,7 +77,7 @@ namespace OpenRA.Widgets protected ButtonWidget(ButtonWidget other) : base(other) { - this.rules = other.rules; + this.modRules = other.modRules; Text = other.Text; Font = other.Font; @@ -122,10 +122,10 @@ namespace OpenRA.Widgets if (!IsDisabled()) { OnKeyPress(e); - Sound.PlayNotification(rules, null, "Sounds", "ClickSound", null); + Sound.PlayNotification(modRules, null, "Sounds", "ClickSound", null); } else - Sound.PlayNotification(rules, null, "Sounds", "ClickDisabledSound", null); + Sound.PlayNotification(modRules, null, "Sounds", "ClickDisabledSound", null); return true; } @@ -162,12 +162,12 @@ namespace OpenRA.Widgets { OnMouseDown(mi); Depressed = true; - Sound.PlayNotification(rules, null, "Sounds", "ClickSound", null); + Sound.PlayNotification(modRules, null, "Sounds", "ClickSound", null); } else { YieldMouseFocus(mi); - Sound.PlayNotification(rules, null, "Sounds", "ClickDisabledSound", null); + Sound.PlayNotification(modRules, null, "Sounds", "ClickDisabledSound", null); } } else if (mi.Event == MouseInputEvent.Move && HasMouseFocus) diff --git a/OpenRA.Game/Widgets/CheckboxWidget.cs b/OpenRA.Game/Widgets/CheckboxWidget.cs index e1d4981fd0..bf19e76821 100644 --- a/OpenRA.Game/Widgets/CheckboxWidget.cs +++ b/OpenRA.Game/Widgets/CheckboxWidget.cs @@ -25,8 +25,8 @@ namespace OpenRA.Widgets public bool HasPressedState = ChromeMetrics.Get("CheckboxPressedState"); [ObjectCreator.UseCtor] - public CheckboxWidget(Ruleset rules) - : base(rules) + public CheckboxWidget(Ruleset modRules) + : base(modRules) { GetCheckType = () => CheckType; } diff --git a/OpenRA.Game/Widgets/DropDownButtonWidget.cs b/OpenRA.Game/Widgets/DropDownButtonWidget.cs index c161cf1303..a3d5460d84 100644 --- a/OpenRA.Game/Widgets/DropDownButtonWidget.cs +++ b/OpenRA.Game/Widgets/DropDownButtonWidget.cs @@ -22,8 +22,8 @@ namespace OpenRA.Widgets MaskWidget fullscreenMask; [ObjectCreator.UseCtor] - public DropDownButtonWidget(Ruleset rules) - : base(rules) { } + public DropDownButtonWidget(Ruleset modRules) + : base(modRules) { } protected DropDownButtonWidget(DropDownButtonWidget widget) : base(widget) { } diff --git a/OpenRA.Game/Widgets/ScrollItemWidget.cs b/OpenRA.Game/Widgets/ScrollItemWidget.cs index 10348ba663..b1528617d5 100644 --- a/OpenRA.Game/Widgets/ScrollItemWidget.cs +++ b/OpenRA.Game/Widgets/ScrollItemWidget.cs @@ -20,8 +20,8 @@ namespace OpenRA.Widgets public string BaseName = "scrollitem"; [ObjectCreator.UseCtor] - public ScrollItemWidget(Ruleset rules) - : base(rules) + public ScrollItemWidget(Ruleset modRules) + : base(modRules) { IsVisible = () => false; VisualHeight = 0; diff --git a/OpenRA.Game/Widgets/WidgetLoader.cs b/OpenRA.Game/Widgets/WidgetLoader.cs index 26257b0c6e..ed753fb5ba 100644 --- a/OpenRA.Game/Widgets/WidgetLoader.cs +++ b/OpenRA.Game/Widgets/WidgetLoader.cs @@ -58,8 +58,8 @@ namespace OpenRA if (child.Key != "Children") FieldLoader.LoadField(widget, child.Key, child.Value.Value); - if (!args.ContainsKey("rules")) - args = new WidgetArgs(args) { { "rules", modData.DefaultRules } }; + if (!args.ContainsKey("modRules")) + args = new WidgetArgs(args) { { "modRules", modData.DefaultRules } }; widget.Initialize(args); foreach (var child in node.Value.Nodes) diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncInstallMusicLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncInstallMusicLogic.cs index 89c454ee5a..35bff5fc70 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncInstallMusicLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncInstallMusicLogic.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic public class CncInstallMusicLogic { [ObjectCreator.UseCtor] - public CncInstallMusicLogic(Widget widget, Ruleset rules, Action onExit) + public CncInstallMusicLogic(Widget widget, Ruleset modRules, Action onExit) { var installButton = widget.GetOrNull("INSTALL_BUTTON"); if (installButton != null) @@ -33,7 +33,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic GlobalFileSystem.Mount(Path.Combine(path, "scores.mix")); GlobalFileSystem.Mount(Path.Combine(path, "transit.mix")); - rules.Music.Do(m => m.Value.Reload()); + modRules.Music.Do(m => m.Value.Reload()); var musicPlayerLogic = (MusicPlayerLogic)installButton.Parent.LogicObject; musicPlayerLogic.BuildMusicTable(); @@ -50,7 +50,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic { "filesToCopy", new[] { "SCORES.MIX" } }, { "filesToExtract", new[] { "transit.mix" } }, }); - installButton.IsVisible = () => rules.InstalledMusic.ToArray().Length < 3; // HACK around music being split between transit.mix and scores.mix + installButton.IsVisible = () => modRules.InstalledMusic.ToArray().Length < 3; // HACK around music being split between transit.mix and scores.mix } } } diff --git a/OpenRA.Mods.Cnc/Widgets/ProductionTypeButtonWidget.cs b/OpenRA.Mods.Cnc/Widgets/ProductionTypeButtonWidget.cs index eeb164b111..7debdef2ab 100644 --- a/OpenRA.Mods.Cnc/Widgets/ProductionTypeButtonWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/ProductionTypeButtonWidget.cs @@ -19,8 +19,8 @@ namespace OpenRA.Mods.Cnc.Widgets public readonly string ProductionGroup; [ObjectCreator.UseCtor] - public ProductionTypeButtonWidget(Ruleset rules) - : base(rules) { } + public ProductionTypeButtonWidget(Ruleset modRules) + : base(modRules) { } protected ProductionTypeButtonWidget(ProductionTypeButtonWidget other) : base(other) diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index fda25e1f93..aa17d24a48 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic readonly Action onExit; readonly OrderManager orderManager; readonly bool skirmishMode; - readonly World world; + readonly Ruleset modRules; enum PanelType { Players, Options, Kick, ForceStart } PanelType panel = PanelType.Players; @@ -91,15 +91,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic } [ObjectCreator.UseCtor] - internal LobbyLogic(Widget widget, World world, WorldRenderer worldRenderer, OrderManager orderManager, - Action onExit, Action onStart, bool skirmishMode) + internal LobbyLogic(Widget widget, WorldRenderer worldRenderer, OrderManager orderManager, + Action onExit, Action onStart, bool skirmishMode, Ruleset modRules) { lobby = widget; this.orderManager = orderManager; this.onStart = onStart; this.onExit = onExit; this.skirmishMode = skirmishMode; - this.world = world; + this.modRules = modRules; Game.LobbyInfoChanged += UpdateCurrentMap; Game.LobbyInfoChanged += UpdatePlayerList; @@ -134,7 +134,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic colorPreview = lobby.Get("COLOR_MANAGER"); colorPreview.Color = Game.Settings.Player.Color; - countryNames = world.Map.Rules.Actors["world"].Traits.WithInterface() + countryNames = modRules.Actors["world"].Traits.WithInterface() .Where(c => c.Selectable) .ToDictionary(a => a.Race, a => a.Name); countryNames.Add("random", "Any"); @@ -172,7 +172,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic slotsButton.IsDisabled = () => configurationDisabled() || panel != PanelType.Players || !orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots || !s.LockTeam); - var botNames = world.Map.Rules.Actors["player"].Traits.WithInterface().Select(t => t.Name); + var botNames = modRules.Actors["player"].Traits.WithInterface().Select(t => t.Name); slotsButton.OnMouseDown = _ => { var options = new Dictionary>(); @@ -377,7 +377,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic }; Func className = c => classNames.ContainsKey(c) ? classNames[c] : c; - var classes = world.Map.Rules.Actors["world"].Traits.WithInterface() + var classes = modRules.Actors["world"].Traits.WithInterface() .Select(a => a.Class).Distinct(); startingUnits.IsDisabled = () => Map.Status != MapStatus.Available || !Map.Map.Options.ConfigurableStartingUnits || configurationDisabled(); @@ -411,7 +411,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic startingCash.GetText = () => Map.Status != MapStatus.Available || Map.Map.Options.StartingCash.HasValue ? "Not Available" : "${0}".F(orderManager.LobbyInfo.GlobalSettings.StartingCash); startingCash.OnMouseDown = _ => { - var options = world.Map.Rules.Actors["player"].Traits.Get().SelectableCash.Select(c => new DropDownOption + var options = modRules.Actors["player"].Traits.Get().SelectableCash.Select(c => new DropDownOption { Title = "${0}".F(c), IsSelected = () => orderManager.LobbyInfo.GlobalSettings.StartingCash == c, @@ -501,7 +501,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic Game.LobbyInfoChanged += WidgetUtils.Once(() => { var slot = orderManager.LobbyInfo.FirstEmptyBotSlot(); - var bot = world.Map.Rules.Actors["player"].Traits.WithInterface().Select(t => t.Name).FirstOrDefault(); + var bot = modRules.Actors["player"].Traits.WithInterface().Select(t => t.Name).FirstOrDefault(); var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin); if (slot != null && bot != null) orderManager.IssueOrder(Order.Command("slot_bot {0} {1} {2}".F(slot, botController.Index, bot))); @@ -544,7 +544,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic if (scrolledToBottom) chatPanel.ScrollToBottom(); - Sound.PlayNotification(world.Map.Rules, null, "Sounds", "ChatLine", null); + Sound.PlayNotification(modRules, null, "Sounds", "ChatLine", null); } void UpdateCurrentMap() @@ -561,7 +561,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic orderManager.IssueOrder(Order.Command("state {0}".F(Session.ClientState.NotReady))); // Restore default starting cash if the last map set it to something invalid - var pri = world.Map.Rules.Actors["player"].Traits.Get(); + var pri = modRules.Actors["player"].Traits.Get(); if (!Map.Map.Options.StartingCash.HasValue && !pri.SelectableCash.Contains(orderManager.LobbyInfo.GlobalSettings.StartingCash)) orderManager.IssueOrder(Order.Command("startingcash {0}".F(pri.DefaultCash))); } @@ -590,7 +590,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic template = emptySlotTemplate.Clone(); if (Game.IsHost) - LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, world.Map.Rules); + LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, modRules); else LobbyUtils.SetupSlotWidget(template, slot, client); @@ -609,7 +609,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic LobbyUtils.SetupClientWidget(template, slot, client, orderManager, client.Bot == null); if (client.Bot != null) - LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, world.Map.Rules); + LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, modRules); else LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager);