Add support for mission difficulties
This commit is contained in:
@@ -37,6 +37,7 @@ namespace OpenRA
|
||||
public string Description;
|
||||
public string Author;
|
||||
public string Tileset;
|
||||
public string[] Difficulties;
|
||||
|
||||
[FieldLoader.Ignore] public Lazy<Dictionary<string, ActorReference>> Actors;
|
||||
|
||||
@@ -178,6 +179,7 @@ namespace OpenRA
|
||||
"Description",
|
||||
"Author",
|
||||
"Tileset",
|
||||
"Difficulties",
|
||||
"MapSize",
|
||||
"Bounds",
|
||||
"UseAsShellmap",
|
||||
|
||||
@@ -78,6 +78,7 @@ namespace OpenRA.Network
|
||||
public bool LockTeams = true; // don't allow team changes after game start.
|
||||
public bool AllowCheats = false;
|
||||
public bool Dedicated;
|
||||
public string Difficulty;
|
||||
}
|
||||
|
||||
public Session(string[] mods)
|
||||
|
||||
@@ -317,6 +317,25 @@ namespace OpenRA.Mods.RA.Server
|
||||
server.SyncLobbyInfo();
|
||||
return true;
|
||||
}},
|
||||
{ "difficulty",
|
||||
s =>
|
||||
{
|
||||
if (!client.IsAdmin)
|
||||
{
|
||||
server.SendChatTo(conn, "Only the host can set that option");
|
||||
return true;
|
||||
}
|
||||
if ((server.Map.Difficulties == null && s != null) || (server.Map.Difficulties != null && !server.Map.Difficulties.Contains(s)))
|
||||
{
|
||||
server.SendChatTo(conn, "Unsupported difficulty selected: {0}".F(s));
|
||||
server.SendChatTo(conn, "Supported difficulties: {0}".F(server.Map.Difficulties.JoinWith(",")));
|
||||
return true;
|
||||
}
|
||||
|
||||
server.lobbyInfo.GlobalSettings.Difficulty = s;
|
||||
server.SyncLobbyInfo();
|
||||
return true;
|
||||
}},
|
||||
{ "kick",
|
||||
s =>
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -426,6 +426,13 @@ Background@SERVER_LOBBY:
|
||||
Height:25
|
||||
Text:Disconnect
|
||||
Font:Bold
|
||||
DropDownButton@DIFFICULTY_DROPDOWNBUTTON:
|
||||
X:PARENT_RIGHT-154
|
||||
Y:PARENT_BOTTOM-219+25
|
||||
Width:120
|
||||
Height:25
|
||||
Font:Bold
|
||||
Visible:false
|
||||
Checkbox@ALLOWCHEATS_CHECKBOX:
|
||||
X: PARENT_RIGHT-154
|
||||
Y: PARENT_BOTTOM-229
|
||||
|
||||
@@ -20,6 +20,8 @@ UseAsShellmap: False
|
||||
|
||||
Type: Campaign
|
||||
|
||||
Difficulties: Normal
|
||||
|
||||
Players:
|
||||
PlayerReference@Neutral:
|
||||
Name: Neutral
|
||||
|
||||
@@ -20,6 +20,8 @@ UseAsShellmap: False
|
||||
|
||||
Type: Campaign
|
||||
|
||||
Difficulties: Normal
|
||||
|
||||
Players:
|
||||
PlayerReference@Neutral:
|
||||
Name: Neutral
|
||||
|
||||
@@ -20,6 +20,8 @@ UseAsShellmap: False
|
||||
|
||||
Type: Campaign
|
||||
|
||||
Difficulties: Normal
|
||||
|
||||
Players:
|
||||
PlayerReference@Neutral:
|
||||
Name: Neutral
|
||||
|
||||
Reference in New Issue
Block a user