Add support for mission difficulties

This commit is contained in:
Scott_NZ
2012-12-09 21:22:19 +13:00
parent dda4e2c33a
commit bfb07e9948
9 changed files with 65 additions and 0 deletions

View File

@@ -37,6 +37,7 @@ namespace OpenRA
public string Description; public string Description;
public string Author; public string Author;
public string Tileset; public string Tileset;
public string[] Difficulties;
[FieldLoader.Ignore] public Lazy<Dictionary<string, ActorReference>> Actors; [FieldLoader.Ignore] public Lazy<Dictionary<string, ActorReference>> Actors;
@@ -178,6 +179,7 @@ namespace OpenRA
"Description", "Description",
"Author", "Author",
"Tileset", "Tileset",
"Difficulties",
"MapSize", "MapSize",
"Bounds", "Bounds",
"UseAsShellmap", "UseAsShellmap",

View File

@@ -78,6 +78,7 @@ namespace OpenRA.Network
public bool LockTeams = true; // don't allow team changes after game start. public bool LockTeams = true; // don't allow team changes after game start.
public bool AllowCheats = false; public bool AllowCheats = false;
public bool Dedicated; public bool Dedicated;
public string Difficulty;
} }
public Session(string[] mods) public Session(string[] mods)

View File

@@ -317,6 +317,25 @@ namespace OpenRA.Mods.RA.Server
server.SyncLobbyInfo(); server.SyncLobbyInfo();
return true; 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", { "kick",
s => s =>
{ {

View File

@@ -156,6 +156,27 @@ namespace OpenRA.Mods.RA.Widgets.Logic
allowCheats.OnClick = () => orderManager.IssueOrder(Order.Command( allowCheats.OnClick = () => orderManager.IssueOrder(Order.Command(
"allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats))); "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"); var startGameButton = lobby.Get<ButtonWidget>("START_GAME_BUTTON");
startGameButton.IsVisible = () => Game.IsHost; startGameButton.IsVisible = () => Game.IsHost;
startGameButton.IsDisabled = () => gameStarting; startGameButton.IsDisabled = () => gameStarting;
@@ -249,6 +270,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var title = Ui.Root.Get<LabelWidget>("TITLE"); var title = Ui.Root.Get<LabelWidget>("TITLE");
title.Text = orderManager.LobbyInfo.GlobalSettings.ServerName; title.Text = orderManager.LobbyInfo.GlobalSettings.ServerName;
orderManager.LobbyInfo.GlobalSettings.Difficulty = Map.Difficulties != null && Map.Difficulties.Any() ? Map.Difficulties.First() : null;
} }
void UpdatePlayerList() void UpdatePlayerList()
@@ -444,5 +467,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
orderManager.IssueOrder(Order.Command("ready")); orderManager.IssueOrder(Order.Command("ready"));
} }
class DifficultyDropDownOption
{
public string Title;
public Func<bool> IsSelected;
public Action OnClick;
}
} }
} }

Binary file not shown.

View File

@@ -426,6 +426,13 @@ Background@SERVER_LOBBY:
Height:25 Height:25
Text:Disconnect Text:Disconnect
Font:Bold 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: Checkbox@ALLOWCHEATS_CHECKBOX:
X: PARENT_RIGHT-154 X: PARENT_RIGHT-154
Y: PARENT_BOTTOM-229 Y: PARENT_BOTTOM-229

View File

@@ -20,6 +20,8 @@ UseAsShellmap: False
Type: Campaign Type: Campaign
Difficulties: Normal
Players: Players:
PlayerReference@Neutral: PlayerReference@Neutral:
Name: Neutral Name: Neutral

View File

@@ -20,6 +20,8 @@ UseAsShellmap: False
Type: Campaign Type: Campaign
Difficulties: Normal
Players: Players:
PlayerReference@Neutral: PlayerReference@Neutral:
Name: Neutral Name: Neutral

View File

@@ -20,6 +20,8 @@ UseAsShellmap: False
Type: Campaign Type: Campaign
Difficulties: Normal
Players: Players:
PlayerReference@Neutral: PlayerReference@Neutral:
Name: Neutral Name: Neutral