From eb3685fe67d61e40985e61c17587dc31f1b61222 Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Wed, 9 Jan 2013 21:50:20 +1300 Subject: [PATCH] Fix a lack of difficulty dropdown yaml in other mods (d2k/cnc) causing crashes --- OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs | 37 ++++++++++++---------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index 8684901a28..8319f2d033 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -156,26 +156,29 @@ namespace OpenRA.Mods.RA.Widgets.Logic allowCheats.OnClick = () => orderManager.IssueOrder(Order.Command( "allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats))); - var difficulty = lobby.Get("DIFFICULTY_DROPDOWNBUTTON"); - difficulty.IsVisible = () => Map != null && Map.Difficulties != null && Map.Difficulties.Any(); - difficulty.IsDisabled = () => !Game.IsHost || gameStarting || orderManager.LocalClient == null || orderManager.LocalClient.IsReady; - difficulty.GetText = () => orderManager.LobbyInfo.GlobalSettings.Difficulty; - difficulty.OnMouseDown = _ => + var difficulty = lobby.GetOrNull("DIFFICULTY_DROPDOWNBUTTON"); + if (difficulty != null) { - var options = Map.Difficulties.Select(d => new DifficultyDropDownOption + difficulty.IsVisible = () => Map != null && Map.Difficulties != null && Map.Difficulties.Any(); + difficulty.IsDisabled = () => !Game.IsHost || gameStarting || orderManager.LocalClient == null || orderManager.LocalClient.IsReady; + difficulty.GetText = () => orderManager.LobbyInfo.GlobalSettings.Difficulty; + difficulty.OnMouseDown = _ => { - Title = d, - IsSelected = () => orderManager.LobbyInfo.GlobalSettings.Difficulty == d, - OnClick = () => orderManager.IssueOrder(Order.Command("difficulty {0}".F(d))) - }); - Func setupItem = (option, template) => - { - var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); - item.Get("LABEL").GetText = () => option.Title; - return item; + var options = Map.Difficulties.Select(d => new DifficultyDropDownOption + { + Title = d, + IsSelected = () => orderManager.LobbyInfo.GlobalSettings.Difficulty == d, + OnClick = () => orderManager.IssueOrder(Order.Command("difficulty {0}".F(d))) + }); + Func setupItem = (option, template) => + { + var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); + item.Get("LABEL").GetText = () => option.Title; + return item; + }; + difficulty.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); }; - difficulty.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); - }; + } var startGameButton = lobby.Get("START_GAME_BUTTON"); startGameButton.IsVisible = () => Game.IsHost;