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 OnDoubleClick = () => {};
|
||||||
public Action<KeyInput> OnKeyPress = _ => {};
|
public Action<KeyInput> OnKeyPress = _ => {};
|
||||||
|
|
||||||
readonly Ruleset rules;
|
readonly Ruleset modRules;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public ButtonWidget(Ruleset rules)
|
public ButtonWidget(Ruleset modRules)
|
||||||
{
|
{
|
||||||
this.rules = rules;
|
this.modRules = modRules;
|
||||||
|
|
||||||
GetText = () => { return Text; };
|
GetText = () => { return Text; };
|
||||||
GetColor = () => TextColor;
|
GetColor = () => TextColor;
|
||||||
@@ -77,7 +77,7 @@ namespace OpenRA.Widgets
|
|||||||
protected ButtonWidget(ButtonWidget other)
|
protected ButtonWidget(ButtonWidget other)
|
||||||
: base(other)
|
: base(other)
|
||||||
{
|
{
|
||||||
this.rules = other.rules;
|
this.modRules = other.modRules;
|
||||||
|
|
||||||
Text = other.Text;
|
Text = other.Text;
|
||||||
Font = other.Font;
|
Font = other.Font;
|
||||||
@@ -122,10 +122,10 @@ namespace OpenRA.Widgets
|
|||||||
if (!IsDisabled())
|
if (!IsDisabled())
|
||||||
{
|
{
|
||||||
OnKeyPress(e);
|
OnKeyPress(e);
|
||||||
Sound.PlayNotification(rules, null, "Sounds", "ClickSound", null);
|
Sound.PlayNotification(modRules, null, "Sounds", "ClickSound", null);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Sound.PlayNotification(rules, null, "Sounds", "ClickDisabledSound", null);
|
Sound.PlayNotification(modRules, null, "Sounds", "ClickDisabledSound", null);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -162,12 +162,12 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
OnMouseDown(mi);
|
OnMouseDown(mi);
|
||||||
Depressed = true;
|
Depressed = true;
|
||||||
Sound.PlayNotification(rules, null, "Sounds", "ClickSound", null);
|
Sound.PlayNotification(modRules, null, "Sounds", "ClickSound", null);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
YieldMouseFocus(mi);
|
YieldMouseFocus(mi);
|
||||||
Sound.PlayNotification(rules, null, "Sounds", "ClickDisabledSound", null);
|
Sound.PlayNotification(modRules, null, "Sounds", "ClickDisabledSound", null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mi.Event == MouseInputEvent.Move && HasMouseFocus)
|
else if (mi.Event == MouseInputEvent.Move && HasMouseFocus)
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ namespace OpenRA.Widgets
|
|||||||
public bool HasPressedState = ChromeMetrics.Get<bool>("CheckboxPressedState");
|
public bool HasPressedState = ChromeMetrics.Get<bool>("CheckboxPressedState");
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public CheckboxWidget(Ruleset rules)
|
public CheckboxWidget(Ruleset modRules)
|
||||||
: base(rules)
|
: base(modRules)
|
||||||
{
|
{
|
||||||
GetCheckType = () => CheckType;
|
GetCheckType = () => CheckType;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ namespace OpenRA.Widgets
|
|||||||
MaskWidget fullscreenMask;
|
MaskWidget fullscreenMask;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public DropDownButtonWidget(Ruleset rules)
|
public DropDownButtonWidget(Ruleset modRules)
|
||||||
: base(rules) { }
|
: base(modRules) { }
|
||||||
|
|
||||||
protected DropDownButtonWidget(DropDownButtonWidget widget) : base(widget) { }
|
protected DropDownButtonWidget(DropDownButtonWidget widget) : base(widget) { }
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ namespace OpenRA.Widgets
|
|||||||
public string BaseName = "scrollitem";
|
public string BaseName = "scrollitem";
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public ScrollItemWidget(Ruleset rules)
|
public ScrollItemWidget(Ruleset modRules)
|
||||||
: base(rules)
|
: base(modRules)
|
||||||
{
|
{
|
||||||
IsVisible = () => false;
|
IsVisible = () => false;
|
||||||
VisualHeight = 0;
|
VisualHeight = 0;
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ namespace OpenRA
|
|||||||
if (child.Key != "Children")
|
if (child.Key != "Children")
|
||||||
FieldLoader.LoadField(widget, child.Key, child.Value.Value);
|
FieldLoader.LoadField(widget, child.Key, child.Value.Value);
|
||||||
|
|
||||||
if (!args.ContainsKey("rules"))
|
if (!args.ContainsKey("modRules"))
|
||||||
args = new WidgetArgs(args) { { "rules", modData.DefaultRules } };
|
args = new WidgetArgs(args) { { "modRules", modData.DefaultRules } };
|
||||||
widget.Initialize(args);
|
widget.Initialize(args);
|
||||||
|
|
||||||
foreach (var child in node.Value.Nodes)
|
foreach (var child in node.Value.Nodes)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
public class CncInstallMusicLogic
|
public class CncInstallMusicLogic
|
||||||
{
|
{
|
||||||
[ObjectCreator.UseCtor]
|
[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");
|
var installButton = widget.GetOrNull<ButtonWidget>("INSTALL_BUTTON");
|
||||||
if (installButton != null)
|
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, "scores.mix"));
|
||||||
GlobalFileSystem.Mount(Path.Combine(path, "transit.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;
|
var musicPlayerLogic = (MusicPlayerLogic)installButton.Parent.LogicObject;
|
||||||
musicPlayerLogic.BuildMusicTable();
|
musicPlayerLogic.BuildMusicTable();
|
||||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
{ "filesToCopy", new[] { "SCORES.MIX" } },
|
{ "filesToCopy", new[] { "SCORES.MIX" } },
|
||||||
{ "filesToExtract", new[] { "transit.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;
|
public readonly string ProductionGroup;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public ProductionTypeButtonWidget(Ruleset rules)
|
public ProductionTypeButtonWidget(Ruleset modRules)
|
||||||
: base(rules) { }
|
: base(modRules) { }
|
||||||
|
|
||||||
protected ProductionTypeButtonWidget(ProductionTypeButtonWidget other)
|
protected ProductionTypeButtonWidget(ProductionTypeButtonWidget other)
|
||||||
: base(other)
|
: base(other)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
readonly Action onExit;
|
readonly Action onExit;
|
||||||
readonly OrderManager orderManager;
|
readonly OrderManager orderManager;
|
||||||
readonly bool skirmishMode;
|
readonly bool skirmishMode;
|
||||||
readonly World world;
|
readonly Ruleset modRules;
|
||||||
|
|
||||||
enum PanelType { Players, Options, Kick, ForceStart }
|
enum PanelType { Players, Options, Kick, ForceStart }
|
||||||
PanelType panel = PanelType.Players;
|
PanelType panel = PanelType.Players;
|
||||||
@@ -91,15 +91,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
internal LobbyLogic(Widget widget, World world, WorldRenderer worldRenderer, OrderManager orderManager,
|
internal LobbyLogic(Widget widget, WorldRenderer worldRenderer, OrderManager orderManager,
|
||||||
Action onExit, Action onStart, bool skirmishMode)
|
Action onExit, Action onStart, bool skirmishMode, Ruleset modRules)
|
||||||
{
|
{
|
||||||
lobby = widget;
|
lobby = widget;
|
||||||
this.orderManager = orderManager;
|
this.orderManager = orderManager;
|
||||||
this.onStart = onStart;
|
this.onStart = onStart;
|
||||||
this.onExit = onExit;
|
this.onExit = onExit;
|
||||||
this.skirmishMode = skirmishMode;
|
this.skirmishMode = skirmishMode;
|
||||||
this.world = world;
|
this.modRules = modRules;
|
||||||
|
|
||||||
Game.LobbyInfoChanged += UpdateCurrentMap;
|
Game.LobbyInfoChanged += UpdateCurrentMap;
|
||||||
Game.LobbyInfoChanged += UpdatePlayerList;
|
Game.LobbyInfoChanged += UpdatePlayerList;
|
||||||
@@ -134,7 +134,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
colorPreview = lobby.Get<ColorPreviewManagerWidget>("COLOR_MANAGER");
|
colorPreview = lobby.Get<ColorPreviewManagerWidget>("COLOR_MANAGER");
|
||||||
colorPreview.Color = Game.Settings.Player.Color;
|
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)
|
.Where(c => c.Selectable)
|
||||||
.ToDictionary(a => a.Race, a => a.Name);
|
.ToDictionary(a => a.Race, a => a.Name);
|
||||||
countryNames.Add("random", "Any");
|
countryNames.Add("random", "Any");
|
||||||
@@ -172,7 +172,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
slotsButton.IsDisabled = () => configurationDisabled() || panel != PanelType.Players ||
|
slotsButton.IsDisabled = () => configurationDisabled() || panel != PanelType.Players ||
|
||||||
!orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots || !s.LockTeam);
|
!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 = _ =>
|
slotsButton.OnMouseDown = _ =>
|
||||||
{
|
{
|
||||||
var options = new Dictionary<string, IEnumerable<DropDownOption>>();
|
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;
|
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();
|
.Select(a => a.Class).Distinct();
|
||||||
|
|
||||||
startingUnits.IsDisabled = () => Map.Status != MapStatus.Available || !Map.Map.Options.ConfigurableStartingUnits || configurationDisabled();
|
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.GetText = () => Map.Status != MapStatus.Available || Map.Map.Options.StartingCash.HasValue ? "Not Available" : "${0}".F(orderManager.LobbyInfo.GlobalSettings.StartingCash);
|
||||||
startingCash.OnMouseDown = _ =>
|
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),
|
Title = "${0}".F(c),
|
||||||
IsSelected = () => orderManager.LobbyInfo.GlobalSettings.StartingCash == c,
|
IsSelected = () => orderManager.LobbyInfo.GlobalSettings.StartingCash == c,
|
||||||
@@ -501,7 +501,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
Game.LobbyInfoChanged += WidgetUtils.Once(() =>
|
Game.LobbyInfoChanged += WidgetUtils.Once(() =>
|
||||||
{
|
{
|
||||||
var slot = orderManager.LobbyInfo.FirstEmptyBotSlot();
|
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);
|
var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
|
||||||
if (slot != null && bot != null)
|
if (slot != null && bot != null)
|
||||||
orderManager.IssueOrder(Order.Command("slot_bot {0} {1} {2}".F(slot, botController.Index, bot)));
|
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)
|
if (scrolledToBottom)
|
||||||
chatPanel.ScrollToBottom();
|
chatPanel.ScrollToBottom();
|
||||||
|
|
||||||
Sound.PlayNotification(world.Map.Rules, null, "Sounds", "ChatLine", null);
|
Sound.PlayNotification(modRules, null, "Sounds", "ChatLine", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateCurrentMap()
|
void UpdateCurrentMap()
|
||||||
@@ -561,7 +561,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
orderManager.IssueOrder(Order.Command("state {0}".F(Session.ClientState.NotReady)));
|
orderManager.IssueOrder(Order.Command("state {0}".F(Session.ClientState.NotReady)));
|
||||||
|
|
||||||
// Restore default starting cash if the last map set it to something invalid
|
// 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))
|
if (!Map.Map.Options.StartingCash.HasValue && !pri.SelectableCash.Contains(orderManager.LobbyInfo.GlobalSettings.StartingCash))
|
||||||
orderManager.IssueOrder(Order.Command("startingcash {0}".F(pri.DefaultCash)));
|
orderManager.IssueOrder(Order.Command("startingcash {0}".F(pri.DefaultCash)));
|
||||||
}
|
}
|
||||||
@@ -590,7 +590,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
template = emptySlotTemplate.Clone();
|
template = emptySlotTemplate.Clone();
|
||||||
|
|
||||||
if (Game.IsHost)
|
if (Game.IsHost)
|
||||||
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, world.Map.Rules);
|
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, modRules);
|
||||||
else
|
else
|
||||||
LobbyUtils.SetupSlotWidget(template, slot, client);
|
LobbyUtils.SetupSlotWidget(template, slot, client);
|
||||||
|
|
||||||
@@ -609,7 +609,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
LobbyUtils.SetupClientWidget(template, slot, client, orderManager, client.Bot == null);
|
LobbyUtils.SetupClientWidget(template, slot, client, orderManager, client.Bot == null);
|
||||||
|
|
||||||
if (client.Bot != null)
|
if (client.Bot != null)
|
||||||
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, world.Map.Rules);
|
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, modRules);
|
||||||
else
|
else
|
||||||
LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager);
|
LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user