Remove static Game.ModData references from widget logic.

This commit is contained in:
Paul Chote
2016-02-17 02:39:13 +00:00
parent ff2aabda9b
commit 84b470017f
20 changed files with 78 additions and 67 deletions

View File

@@ -49,6 +49,9 @@ namespace OpenRA
if (!args.ContainsKey("modRules")) if (!args.ContainsKey("modRules"))
args = new WidgetArgs(args) { { "modRules", modData.DefaultRules } }; args = new WidgetArgs(args) { { "modRules", modData.DefaultRules } };
if (!args.ContainsKey("modData"))
args = new WidgetArgs(args) { { "modData", modData } };
var widget = NewWidget(node.Key, args); var widget = NewWidget(node.Key, args);
if (parent != null) if (parent != null)

View File

@@ -18,8 +18,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
public class CncMainMenuLogic : MainMenuLogic public class CncMainMenuLogic : MainMenuLogic
{ {
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public CncMainMenuLogic(Widget widget, World world) public CncMainMenuLogic(Widget widget, World world, ModData modData)
: base(widget, world) : base(widget, world, modData)
{ {
var shellmapDecorations = widget.Get("SHELLMAP_DECORATIONS"); var shellmapDecorations = widget.Get("SHELLMAP_DECORATIONS");
shellmapDecorations.IsVisible = () => menuType != MenuType.None && Game.Settings.Game.ShowShellmap; shellmapDecorations.IsVisible = () => menuType != MenuType.None && Game.Settings.Game.ShowShellmap;

View File

@@ -48,11 +48,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
int currentFrame; int currentFrame;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public AssetBrowserLogic(Widget widget, Action onExit, World world, Dictionary<string, MiniYaml> logicArgs) public AssetBrowserLogic(Widget widget, Action onExit, ModData modData, World world, Dictionary<string, MiniYaml> logicArgs)
{ {
this.world = world; this.world = world;
modData = Game.ModData; this.modData = modData;
panel = widget; panel = widget;
var ticker = panel.GetOrNull<LogicTickerWidget>("ANIMATION_TICKER"); var ticker = panel.GetOrNull<LogicTickerWidget>("ANIMATION_TICKER");

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public class ColorPickerLogic : ChromeLogic public class ColorPickerLogic : ChromeLogic
{ {
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public ColorPickerLogic(Widget widget, World world, HSLColor initialColor, Action<HSLColor> onChange, WorldRenderer worldRenderer) public ColorPickerLogic(Widget widget, ModData modData, World world, HSLColor initialColor, Action<HSLColor> onChange, WorldRenderer worldRenderer)
{ {
string actorType; string actorType;
if (!ChromeMetrics.TryGet("ColorPickerActorType", out actorType)) if (!ChromeMetrics.TryGet("ColorPickerActorType", out actorType))
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}; };
// Set the initial state // Set the initial state
var validator = Game.ModData.Manifest.Get<ColorValidator>(); var validator = modData.Manifest.Get<ColorValidator>();
mixer.SetPaletteRange(validator.HsvSaturationRange[0], validator.HsvSaturationRange[1], validator.HsvValueRange[0], validator.HsvValueRange[1]); mixer.SetPaletteRange(validator.HsvSaturationRange[0], validator.HsvSaturationRange[1], validator.HsvValueRange[0], validator.HsvValueRange[1]);
mixer.Set(initialColor); mixer.Set(initialColor);

View File

@@ -18,10 +18,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public class CreditsLogic : ChromeLogic public class CreditsLogic : ChromeLogic
{ {
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public CreditsLogic(Widget widget, Action onExit) public CreditsLogic(Widget widget, ModData modData, Action onExit)
{ {
var panel = widget.Get("CREDITS_PANEL"); var panel = widget.Get("CREDITS_PANEL");
var modData = Game.ModData;
panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () =>
{ {

View File

@@ -29,9 +29,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
} }
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public SaveMapLogic(Widget widget, Action<string> onSave, Action onExit, Map map, List<MiniYamlNode> playerDefinitions, List<MiniYamlNode> actorDefinitions) public SaveMapLogic(Widget widget, ModData modData, Action<string> onSave, Action onExit,
Map map, List<MiniYamlNode> playerDefinitions, List<MiniYamlNode> actorDefinitions)
{ {
var modData = Game.ModData;
var title = widget.Get<TextFieldWidget>("TITLE"); var title = widget.Get<TextFieldWidget>("TITLE");
title.Text = map.Title; title.Text = map.Title;

View File

@@ -16,10 +16,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
class GameInfoBriefingLogic : ChromeLogic class GameInfoBriefingLogic : ChromeLogic
{ {
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public GameInfoBriefingLogic(Widget widget, World world) public GameInfoBriefingLogic(Widget widget, ModData modData, World world)
{ {
var previewWidget = widget.Get<MapPreviewWidget>("MAP_PREVIEW"); var previewWidget = widget.Get<MapPreviewWidget>("MAP_PREVIEW");
previewWidget.Preview = () => Game.ModData.MapCache[world.Map.Uid]; previewWidget.Preview = () => modData.MapCache[world.Map.Uid];
var mapDescriptionPanel = widget.Get<ScrollPanelWidget>("MAP_DESCRIPTION_PANEL"); var mapDescriptionPanel = widget.Get<ScrollPanelWidget>("MAP_DESCRIPTION_PANEL");
var mapDescription = widget.Get<LabelWidget>("MAP_DESCRIPTION"); var mapDescription = widget.Get<LabelWidget>("MAP_DESCRIPTION");

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Widget menu; Widget menu;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public IngameMenuLogic(Widget widget, World world, Action onExit, WorldRenderer worldRenderer, IngameInfoPanel activePanel) public IngameMenuLogic(Widget widget, ModData modData, World world, Action onExit, WorldRenderer worldRenderer, IngameInfoPanel activePanel)
{ {
var leaving = false; var leaving = false;
menu = widget.Get("INGAME_MENU"); menu = widget.Get("INGAME_MENU");
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (mpe != null) if (mpe != null)
mpe.Fade(mpe.Info.MenuEffect); mpe.Fade(mpe.Info.MenuEffect);
menu.Get<LabelWidget>("VERSION_LABEL").Text = Game.ModData.Manifest.Mod.Version; menu.Get<LabelWidget>("VERSION_LABEL").Text = modData.Manifest.Mod.Version;
var hideMenu = false; var hideMenu = false;
menu.Get("MENU_BUTTONS").IsVisible = () => !hideMenu; menu.Get("MENU_BUTTONS").IsVisible = () => !hideMenu;

View File

@@ -20,6 +20,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
public class InstallFromCDLogic : ChromeLogic public class InstallFromCDLogic : ChromeLogic
{ {
readonly ModData modData;
readonly string modId; readonly string modId;
readonly Widget panel; readonly Widget panel;
readonly ProgressBarWidget progressBar; readonly ProgressBarWidget progressBar;
@@ -30,8 +31,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly ContentInstaller installData; readonly ContentInstaller installData;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public InstallFromCDLogic(Widget widget, Action afterInstall, string modId) public InstallFromCDLogic(Widget widget, ModData modData, Action afterInstall, string modId)
{ {
this.modData = modData;
this.modId = modId; this.modId = modId;
installData = ModMetadata.AllMods[modId].Content; installData = ModMetadata.AllMods[modId].Content;
this.afterInstall = afterInstall; this.afterInstall = afterInstall;
@@ -92,11 +94,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
insertDiskContainer.IsVisible = () => false; insertDiskContainer.IsVisible = () => false;
installingContainer.IsVisible = () => true; installingContainer.IsVisible = () => true;
progressBar.Percentage = 0; progressBar.Percentage = 0;
var modData = Game.ModData;
new Thread(() => new Thread(() =>
{ {
using (var cabExtractor = new InstallShieldCABExtractor(Game.ModData.ModFiles, source)) using (var cabExtractor = new InstallShieldCABExtractor(modData.ModFiles, source))
{ {
var denom = installData.InstallShieldCABFileIds.Count; var denom = installData.InstallShieldCABFileIds.Count;
var extractFiles = installData.ExtractFilesFromCD; var extractFiles = installData.ExtractFilesFromCD;
@@ -152,7 +153,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
retryButton.IsDisabled = () => true; retryButton.IsDisabled = () => true;
insertDiskContainer.IsVisible = () => false; insertDiskContainer.IsVisible = () => false;
installingContainer.IsVisible = () => true; installingContainer.IsVisible = () => true;
var modData = Game.ModData;
var dest = Platform.ResolvePath("^", "Content", modId); var dest = Platform.ResolvePath("^", "Content", modId);
var copyFiles = installData.CopyFilesFromCD; var copyFiles = installData.CopyFilesFromCD;

View File

@@ -30,6 +30,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public MapPreview MapPreview { get; private set; } public MapPreview MapPreview { get; private set; }
public Map Map { get; private set; } public Map Map { get; private set; }
readonly ModData modData;
readonly Action onStart; readonly Action onStart;
readonly Action onExit; readonly Action onExit;
readonly OrderManager orderManager; readonly OrderManager orderManager;
@@ -110,11 +111,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
} }
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
internal LobbyLogic(Widget widget, WorldRenderer worldRenderer, OrderManager orderManager, internal LobbyLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, OrderManager orderManager,
Action onExit, Action onStart, bool skirmishMode, Ruleset modRules) Action onExit, Action onStart, bool skirmishMode, Ruleset modRules)
{ {
MapPreview = MapCache.UnknownMap; MapPreview = MapCache.UnknownMap;
lobby = widget; lobby = widget;
this.modData = modData;
this.orderManager = orderManager; this.orderManager = orderManager;
this.onStart = onStart; this.onStart = onStart;
this.onExit = onExit; this.onExit = onExit;
@@ -511,7 +513,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var gameSpeed = optionsBin.GetOrNull<DropDownButtonWidget>("GAMESPEED_DROPDOWNBUTTON"); var gameSpeed = optionsBin.GetOrNull<DropDownButtonWidget>("GAMESPEED_DROPDOWNBUTTON");
if (gameSpeed != null) if (gameSpeed != null)
{ {
var speeds = Game.ModData.Manifest.Get<GameSpeeds>().Speeds; var speeds = modData.Manifest.Get<GameSpeeds>().Speeds;
gameSpeed.IsDisabled = configurationDisabled; gameSpeed.IsDisabled = configurationDisabled;
gameSpeed.GetText = () => gameSpeed.GetText = () =>
@@ -738,7 +740,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (MapPreview.Uid == uid) if (MapPreview.Uid == uid)
return; return;
var modData = Game.ModData;
MapPreview = modData.MapCache[uid]; MapPreview = modData.MapCache[uid];
Map = null; Map = null;
if (MapPreview.Status == MapStatus.Available) if (MapPreview.Status == MapStatus.Available)
@@ -768,7 +769,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}).Start(); }).Start();
} }
else if (Game.Settings.Game.AllowDownloading) else if (Game.Settings.Game.AllowDownloading)
Game.ModData.MapCache.QueryRemoteMapDetails(new[] { uid }); modData.MapCache.QueryRemoteMapDetails(new[] { uid });
} }
void UpdatePlayerList() void UpdatePlayerList()

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
int blinkTick; int blinkTick;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
internal LobbyMapPreviewLogic(Widget widget, OrderManager orderManager, LobbyLogic lobby) internal LobbyMapPreviewLogic(Widget widget, ModData modData, OrderManager orderManager, LobbyLogic lobby)
{ {
var available = widget.GetOrNull("MAP_AVAILABLE"); var available = widget.GetOrNull("MAP_AVAILABLE");
if (available != null) if (available != null)
@@ -162,7 +162,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (lobby.MapPreview.Status == MapStatus.DownloadError) if (lobby.MapPreview.Status == MapStatus.DownloadError)
lobby.MapPreview.Install(); lobby.MapPreview.Install();
else if (lobby.MapPreview.Status == MapStatus.Unavailable) else if (lobby.MapPreview.Status == MapStatus.Unavailable)
Game.ModData.MapCache.QueryRemoteMapDetails(new[] { lobby.MapPreview.Uid }); modData.MapCache.QueryRemoteMapDetails(new[] { lobby.MapPreview.Uid });
}; };
retry.GetText = () => lobby.MapPreview.Status == MapStatus.DownloadError ? "Retry Install" : "Retry Search"; retry.GetText = () => lobby.MapPreview.Status == MapStatus.DownloadError ? "Retry Install" : "Retry Search";

View File

@@ -41,10 +41,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
} }
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public MainMenuLogic(Widget widget, World world) public MainMenuLogic(Widget widget, World world, ModData modData)
{ {
rootMenu = widget; rootMenu = widget;
rootMenu.Get<LabelWidget>("VERSION_LABEL").Text = Game.ModData.Manifest.Mod.Version; rootMenu.Get<LabelWidget>("VERSION_LABEL").Text = modData.Manifest.Mod.Version;
// Menu buttons // Menu buttons
var mainMenu = widget.Get("MAIN_MENU"); var mainMenu = widget.Get("MAIN_MENU");
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
// so we can't do this inside the input handler. // so we can't do this inside the input handler.
Game.RunAfterTick(() => Game.RunAfterTick(() =>
{ {
Game.Settings.Game.PreviousMod = Game.ModData.Manifest.Mod.Id; Game.Settings.Game.PreviousMod = modData.Manifest.Mod.Id;
Game.InitializeMod("modchooser", null); Game.InitializeMod("modchooser", null);
}); });
}; };
@@ -103,8 +103,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}); });
}; };
var hasCampaign = Game.ModData.Manifest.Missions.Any(); var hasCampaign = modData.Manifest.Missions.Any();
var hasMissions = Game.ModData.MapCache var hasMissions = modData.MapCache
.Any(p => p.Status == MapStatus.Available && p.Visibility.HasFlag(MapVisibility.MissionSelector)); .Any(p => p.Status == MapStatus.Available && p.Visibility.HasFlag(MapVisibility.MissionSelector));
missionsButton.Disabled = !hasCampaign && !hasMissions; missionsButton.Disabled = !hasCampaign && !hasMissions;
@@ -168,7 +168,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var onSelect = new Action<string>(uid => var onSelect = new Action<string>(uid =>
{ {
RemoveShellmapUI(); RemoveShellmapUI();
LoadMapIntoEditor(Game.ModData.MapCache[uid].Uid); LoadMapIntoEditor(modData.MapCache[uid].Uid);
}); });
var newMapButton = widget.Get<ButtonWidget>("NEW_MAP_BUTTON"); var newMapButton = widget.Get<ButtonWidget>("NEW_MAP_BUTTON");

View File

@@ -23,6 +23,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
readonly Widget widget; readonly Widget widget;
readonly DropDownButtonWidget gameModeDropdown; readonly DropDownButtonWidget gameModeDropdown;
readonly ModData modData;
MapClassification currentTab; MapClassification currentTab;
@@ -38,9 +39,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
string mapFilter; string mapFilter;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
internal MapChooserLogic(Widget widget, string initialMap, MapClassification initialTab, Action onExit, Action<string> onSelect, MapVisibility filter) internal MapChooserLogic(Widget widget, ModData modData, string initialMap,
MapClassification initialTab, Action onExit, Action<string> onSelect, MapVisibility filter)
{ {
this.widget = widget; this.widget = widget;
this.modData = modData;
this.onSelect = onSelect; this.onSelect = onSelect;
var approving = new Action(() => { Ui.CloseWindow(); onSelect(selectedUid); }); var approving = new Action(() => { Ui.CloseWindow(); onSelect(selectedUid); });
@@ -93,7 +96,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
} }
var deleteMapButton = widget.Get<ButtonWidget>("DELETE_MAP_BUTTON"); var deleteMapButton = widget.Get<ButtonWidget>("DELETE_MAP_BUTTON");
deleteMapButton.IsDisabled = () => Game.ModData.MapCache[selectedUid].Class != MapClassification.User; deleteMapButton.IsDisabled = () => modData.MapCache[selectedUid].Class != MapClassification.User;
deleteMapButton.IsVisible = () => currentTab == MapClassification.User; deleteMapButton.IsVisible = () => currentTab == MapClassification.User;
deleteMapButton.OnClick = () => deleteMapButton.OnClick = () =>
{ {
@@ -102,7 +105,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
RefreshMaps(currentTab, filter); RefreshMaps(currentTab, filter);
EnumerateMaps(currentTab, itemTemplate); EnumerateMaps(currentTab, itemTemplate);
if (!tabMaps[currentTab].Any()) if (!tabMaps[currentTab].Any())
SwitchTab(Game.ModData.MapCache[newUid].Class, itemTemplate); SwitchTab(modData.MapCache[newUid].Class, itemTemplate);
}); });
}; };
@@ -114,7 +117,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
RefreshMaps(currentTab, filter); RefreshMaps(currentTab, filter);
EnumerateMaps(currentTab, itemTemplate); EnumerateMaps(currentTab, itemTemplate);
SwitchTab(Game.ModData.MapCache[newUid].Class, itemTemplate); SwitchTab(modData.MapCache[newUid].Class, itemTemplate);
}); });
}; };
@@ -143,7 +146,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void RefreshMaps(MapClassification tab, MapVisibility filter) void RefreshMaps(MapClassification tab, MapVisibility filter)
{ {
tabMaps[tab] = Game.ModData.MapCache.Where(m => m.Status == MapStatus.Available && tabMaps[tab] = modData.MapCache.Where(m => m.Status == MapStatus.Available &&
m.Class == tab && (m.Visibility & filter) != 0).ToArray(); m.Class == tab && (m.Visibility & filter) != 0).ToArray();
} }
@@ -285,7 +288,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
string DeleteMap(string map) string DeleteMap(string map)
{ {
var path = Game.ModData.MapCache[map].Package.Name; var path = modData.MapCache[map].Package.Name;
try try
{ {
if (File.Exists(path)) if (File.Exists(path))
@@ -293,7 +296,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
else if (Directory.Exists(path)) else if (Directory.Exists(path))
Directory.Delete(path, true); Directory.Delete(path, true);
Game.ModData.MapCache[map].Invalidate(); modData.MapCache[map].Invalidate();
if (selectedUid == map) if (selectedUid == map)
selectedUid = WidgetUtils.ChooseInitialMap(tabMaps[currentTab].Select(mp => mp.Uid).FirstOrDefault()); selectedUid = WidgetUtils.ChooseInitialMap(tabMaps[currentTab].Select(mp => mp.Uid).FirstOrDefault());
@@ -311,7 +314,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
ConfirmationDialogs.PromptConfirmAction( ConfirmationDialogs.PromptConfirmAction(
title: "Delete map", title: "Delete map",
text: "Delete the map '{0}'?".F(Game.ModData.MapCache[map].Title), text: "Delete the map '{0}'?".F(modData.MapCache[map].Title),
onConfirm: () => onConfirm: () =>
{ {
var newUid = DeleteMap(map); var newUid = DeleteMap(map);

View File

@@ -53,10 +53,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
string gameSpeed; string gameSpeed;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public MissionBrowserLogic(Widget widget, World world, Action onStart, Action onExit) public MissionBrowserLogic(Widget widget, ModData modData, World world, Action onStart, Action onExit)
{ {
modData = Game.ModData;
mapCache = new Cache<MapPreview, Map>(p => new Map(modData, p.Package)); mapCache = new Cache<MapPreview, Map>(p => new Map(modData, p.Package));
this.modData = modData;
this.onStart = onStart; this.onStart = onStart;
missionList = widget.Get<ScrollPanelWidget>("MISSION_LIST"); missionList = widget.Get<ScrollPanelWidget>("MISSION_LIST");
@@ -230,7 +230,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (gameSpeedButton != null) if (gameSpeedButton != null)
{ {
var speeds = Game.ModData.Manifest.Get<GameSpeeds>().Speeds; var speeds = modData.Manifest.Get<GameSpeeds>().Speeds;
gameSpeed = "default"; gameSpeed = "default";
gameSpeedButton.GetText = () => speeds[gameSpeed].Name; gameSpeedButton.GetText = () => speeds[gameSpeed].Name;

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
int modOffset = 0; int modOffset = 0;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public ModBrowserLogic(Widget widget) public ModBrowserLogic(Widget widget, ModData modData)
{ {
modInstallStatus = new Cache<ModMetadata, bool>(IsModInstalled); modInstallStatus = new Cache<ModMetadata, bool>(IsModInstalled);
modPrerequisitesFulfilled = new Cache<string, bool>(Game.IsModInstalled); modPrerequisitesFulfilled = new Cache<string, bool>(Game.IsModInstalled);
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
modChooserPanel = widget; modChooserPanel = widget;
loadButton = modChooserPanel.Get<ButtonWidget>("LOAD_BUTTON"); loadButton = modChooserPanel.Get<ButtonWidget>("LOAD_BUTTON");
loadButton.OnClick = () => LoadMod(selectedMod); loadButton.OnClick = () => LoadMod(selectedMod);
loadButton.IsDisabled = () => selectedMod.Id == Game.ModData.Manifest.Mod.Id; loadButton.IsDisabled = () => selectedMod.Id == modData.Manifest.Mod.Id;
modChooserPanel.Get<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit; modChooserPanel.Get<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit;

View File

@@ -36,6 +36,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly Color incompatibleGameStartedColor; readonly Color incompatibleGameStartedColor;
readonly Color gameStartedColor; readonly Color gameStartedColor;
readonly Color incompatibleGameColor; readonly Color incompatibleGameColor;
readonly ModData modData;
GameServer currentServer; GameServer currentServer;
MapPreview currentMap; MapPreview currentMap;
@@ -68,8 +69,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
} }
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public MultiplayerLogic(Widget widget, Action onStart, Action onExit, string directConnectHost, int directConnectPort) public MultiplayerLogic(Widget widget, ModData modData, Action onStart, Action onExit, string directConnectHost, int directConnectPort)
{ {
this.modData = modData;
this.onStart = onStart; this.onStart = onStart;
this.onExit = onExit; this.onExit = onExit;
@@ -321,7 +323,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return 0; return 0;
// Games for the current mod+version are sorted first // Games for the current mod+version are sorted first
if (testEntry.ModId == Game.ModData.Manifest.Mod.Id) if (testEntry.ModId == modData.Manifest.Mod.Id)
return 2; return 2;
// Followed by games for different mods that are joinable // Followed by games for different mods that are joinable
@@ -331,7 +333,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void SelectServer(GameServer server) void SelectServer(GameServer server)
{ {
currentServer = server; currentServer = server;
currentMap = server != null ? Game.ModData.MapCache[server.Map] : null; currentMap = server != null ? modData.MapCache[server.Map] : null;
} }
void RefreshServerListInner(IEnumerable<GameServer> games) void RefreshServerListInner(IEnumerable<GameServer> games)
@@ -438,7 +440,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
// Search for any unknown maps // Search for any unknown maps
if (Game.Settings.Game.AllowDownloading) if (Game.Settings.Game.AllowDownloading)
Game.ModData.MapCache.QueryRemoteMapDetails(games.Where(g => !Filtered(g)).Select(g => g.Map)); modData.MapCache.QueryRemoteMapDetails(games.Where(g => !Filtered(g)).Select(g => g.Map));
foreach (var row in rows) foreach (var row in rows)
serverList.AddChild(row); serverList.AddChild(row);

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
MusicInfo currentSong = null; MusicInfo currentSong = null;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public MusicPlayerLogic(Widget widget, Ruleset modRules, World world, Action onExit) public MusicPlayerLogic(Widget widget, ModData modData, Ruleset modRules, World world, Action onExit)
{ {
var panel = widget; var panel = widget;
@@ -107,11 +107,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (installButton != null) if (installButton != null)
{ {
installButton.IsDisabled = () => world.Type != WorldType.Shellmap; installButton.IsDisabled = () => world.Type != WorldType.Shellmap;
var args = new[] { "installMusic={0}".F(Game.ModData.Manifest.Mod.Id) }; var args = new[] { "installMusic={0}".F(modData.Manifest.Mod.Id) };
installButton.OnClick = () => installButton.OnClick = () =>
Game.RunAfterTick(() => Game.InitializeMod("modchooser", new Arguments(args))); Game.RunAfterTick(() => Game.InitializeMod("modchooser", new Arguments(args)));
var installData = Game.ModData.Manifest.Get<ContentInstaller>(); var installData = modData.Manifest.Get<ContentInstaller>();
installButton.IsVisible = () => modRules.InstalledMusic.ToArray().Length <= installData.ShippedSoundtracks; installButton.IsVisible = () => modRules.InstalledMusic.ToArray().Length <= installData.ShippedSoundtracks;
} }

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
volatile bool cancelLoadingReplays; volatile bool cancelLoadingReplays;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public ReplayBrowserLogic(Widget widget, Action onExit, Action onStart) public ReplayBrowserLogic(Widget widget, ModData modData, Action onExit, Action onStart)
{ {
panel = widget; panel = widget;
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
replayList = panel.Get<ScrollPanelWidget>("REPLAY_LIST"); replayList = panel.Get<ScrollPanelWidget>("REPLAY_LIST");
var template = panel.Get<ScrollItemWidget>("REPLAY_TEMPLATE"); var template = panel.Get<ScrollItemWidget>("REPLAY_TEMPLATE");
var mod = Game.ModData.Manifest.Mod; var mod = modData.Manifest.Mod;
var dir = Platform.ResolvePath("^", "Replays", mod.Id, mod.Version); var dir = Platform.ResolvePath("^", "Replays", mod.Id, mod.Version);
if (Directory.Exists(dir)) if (Directory.Exists(dir))

View File

@@ -25,14 +25,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
bool allowPortForward; bool allowPortForward;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public ServerCreationLogic(Widget widget, Action onExit, Action openLobby) public ServerCreationLogic(Widget widget, ModData modData, Action onExit, Action openLobby)
{ {
panel = widget; panel = widget;
onCreate = openLobby; onCreate = openLobby;
this.onExit = onExit; this.onExit = onExit;
var settings = Game.Settings; var settings = Game.Settings;
preview = Game.ModData.MapCache[WidgetUtils.ChooseInitialMap(Game.Settings.Server.Map)]; preview = modData.MapCache[WidgetUtils.ChooseInitialMap(Game.Settings.Server.Map)];
panel.Get<ButtonWidget>("CREATE_BUTTON").OnClick = CreateAndJoin; panel.Get<ButtonWidget>("CREATE_BUTTON").OnClick = CreateAndJoin;
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ "initialMap", preview.Uid }, { "initialMap", preview.Uid },
{ "initialTab", MapClassification.System }, { "initialTab", MapClassification.System },
{ "onExit", () => { } }, { "onExit", () => { } },
{ "onSelect", (Action<string>)(uid => preview = Game.ModData.MapCache[uid]) }, { "onSelect", (Action<string>)(uid => preview = modData.MapCache[uid]) },
{ "filter", MapVisibility.Lobby }, { "filter", MapVisibility.Lobby },
{ "onStart", () => { } } { "onStart", () => { } }
}); });

View File

@@ -21,13 +21,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public class SettingsLogic : ChromeLogic public class SettingsLogic : ChromeLogic
{ {
enum PanelType { Display, Audio, Input, Advanced } enum PanelType { Display, Audio, Input, Advanced }
Dictionary<PanelType, Action> leavePanelActions = new Dictionary<PanelType, Action>();
Dictionary<PanelType, Action> resetPanelActions = new Dictionary<PanelType, Action>();
PanelType settingsPanel = PanelType.Display;
Widget panelContainer, tabContainer;
WorldRenderer worldRenderer;
SoundDevice soundDevice;
static readonly string OriginalSoundDevice; static readonly string OriginalSoundDevice;
static readonly string OriginalSoundEngine; static readonly string OriginalSoundEngine;
@@ -36,6 +29,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
static readonly int2 OriginalGraphicsWindowedSize; static readonly int2 OriginalGraphicsWindowedSize;
static readonly int2 OriginalGraphicsFullscreenSize; static readonly int2 OriginalGraphicsFullscreenSize;
readonly Dictionary<PanelType, Action> leavePanelActions = new Dictionary<PanelType, Action>();
readonly Dictionary<PanelType, Action> resetPanelActions = new Dictionary<PanelType, Action>();
readonly Widget panelContainer, tabContainer;
readonly ModData modData;
readonly WorldRenderer worldRenderer;
SoundDevice soundDevice;
PanelType settingsPanel = PanelType.Display;
static SettingsLogic() static SettingsLogic()
{ {
var original = Game.Settings; var original = Game.Settings;
@@ -48,9 +51,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
} }
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public SettingsLogic(Widget widget, Action onExit, WorldRenderer worldRenderer) public SettingsLogic(Widget widget, Action onExit, ModData modData, WorldRenderer worldRenderer)
{ {
this.worldRenderer = worldRenderer; this.worldRenderer = worldRenderer;
this.modData = modData;
panelContainer = widget.Get("SETTINGS_PANEL"); panelContainer = widget.Get("SETTINGS_PANEL");
tabContainer = widget.Get("TAB_CONTAINER"); tabContainer = widget.Get("TAB_CONTAINER");
@@ -158,7 +162,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
BindCheckboxPref(panel, "PLAYER_STANCE_COLORS_CHECKBOX", gs, "UsePlayerStanceColors"); BindCheckboxPref(panel, "PLAYER_STANCE_COLORS_CHECKBOX", gs, "UsePlayerStanceColors");
var languageDropDownButton = panel.Get<DropDownButtonWidget>("LANGUAGE_DROPDOWNBUTTON"); var languageDropDownButton = panel.Get<DropDownButtonWidget>("LANGUAGE_DROPDOWNBUTTON");
languageDropDownButton.OnMouseDown = _ => ShowLanguageDropdown(languageDropDownButton); languageDropDownButton.OnMouseDown = _ => ShowLanguageDropdown(languageDropDownButton, modData.Languages);
languageDropDownButton.GetText = () => FieldLoader.Translate(ds.Language); languageDropDownButton.GetText = () => FieldLoader.Translate(ds.Language);
var windowModeDropdown = panel.Get<DropDownButtonWidget>("MODE_DROPDOWN"); var windowModeDropdown = panel.Get<DropDownButtonWidget>("MODE_DROPDOWN");
@@ -684,7 +688,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return true; return true;
} }
static bool ShowLanguageDropdown(DropDownButtonWidget dropdown) static bool ShowLanguageDropdown(DropDownButtonWidget dropdown, IEnumerable<string> languages)
{ {
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) => Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
{ {
@@ -696,7 +700,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return item; return item;
}; };
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, Game.ModData.Languages, setupItem); dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, languages, setupItem);
return true; return true;
} }