Better distinction between Widgets using the mod's DefaultRules or the map's Rules
This commit is contained in:
@@ -55,12 +55,12 @@ namespace OpenRA.Widgets
|
||||
public Action OnDoubleClick = () => {};
|
||||
public Action<KeyInput> 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)
|
||||
|
||||
@@ -25,8 +25,8 @@ namespace OpenRA.Widgets
|
||||
public bool HasPressedState = ChromeMetrics.Get<bool>("CheckboxPressedState");
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public CheckboxWidget(Ruleset rules)
|
||||
: base(rules)
|
||||
public CheckboxWidget(Ruleset modRules)
|
||||
: base(modRules)
|
||||
{
|
||||
GetCheckType = () => CheckType;
|
||||
}
|
||||
|
||||
@@ -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) { }
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<ButtonWidget>("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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<ColorPreviewManagerWidget>("COLOR_MANAGER");
|
||||
colorPreview.Color = Game.Settings.Player.Color;
|
||||
|
||||
countryNames = world.Map.Rules.Actors["world"].Traits.WithInterface<CountryInfo>()
|
||||
countryNames = modRules.Actors["world"].Traits.WithInterface<CountryInfo>()
|
||||
.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<IBotInfo>().Select(t => t.Name);
|
||||
var botNames = modRules.Actors["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name);
|
||||
slotsButton.OnMouseDown = _ =>
|
||||
{
|
||||
var options = new Dictionary<string, IEnumerable<DropDownOption>>();
|
||||
@@ -377,7 +377,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
};
|
||||
|
||||
Func<string, string> className = c => classNames.ContainsKey(c) ? classNames[c] : c;
|
||||
var classes = world.Map.Rules.Actors["world"].Traits.WithInterface<MPStartUnitsInfo>()
|
||||
var classes = modRules.Actors["world"].Traits.WithInterface<MPStartUnitsInfo>()
|
||||
.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<PlayerResourcesInfo>().SelectableCash.Select(c => new DropDownOption
|
||||
var options = modRules.Actors["player"].Traits.Get<PlayerResourcesInfo>().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<IBotInfo>().Select(t => t.Name).FirstOrDefault();
|
||||
var bot = modRules.Actors["player"].Traits.WithInterface<IBotInfo>().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<PlayerResourcesInfo>();
|
||||
var pri = modRules.Actors["player"].Traits.Get<PlayerResourcesInfo>();
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user