Add support for mission difficulties
This commit is contained in:
@@ -156,6 +156,27 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
allowCheats.OnClick = () => orderManager.IssueOrder(Order.Command(
|
||||
"allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats)));
|
||||
|
||||
var difficulty = lobby.Get<DropDownButtonWidget>("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 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<DifficultyDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
||||
{
|
||||
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => option.Title;
|
||||
return item;
|
||||
};
|
||||
difficulty.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem);
|
||||
};
|
||||
|
||||
var startGameButton = lobby.Get<ButtonWidget>("START_GAME_BUTTON");
|
||||
startGameButton.IsVisible = () => Game.IsHost;
|
||||
startGameButton.IsDisabled = () => gameStarting;
|
||||
@@ -249,6 +270,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
var title = Ui.Root.Get<LabelWidget>("TITLE");
|
||||
title.Text = orderManager.LobbyInfo.GlobalSettings.ServerName;
|
||||
|
||||
orderManager.LobbyInfo.GlobalSettings.Difficulty = Map.Difficulties != null && Map.Difficulties.Any() ? Map.Difficulties.First() : null;
|
||||
}
|
||||
|
||||
void UpdatePlayerList()
|
||||
@@ -444,5 +467,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
orderManager.IssueOrder(Order.Command("ready"));
|
||||
}
|
||||
|
||||
class DifficultyDropDownOption
|
||||
{
|
||||
public string Title;
|
||||
public Func<bool> IsSelected;
|
||||
public Action OnClick;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user