Add lobby support for configuring starting units.
This commit is contained in:
@@ -38,6 +38,7 @@ namespace OpenRA
|
|||||||
public string Author;
|
public string Author;
|
||||||
public string Tileset;
|
public string Tileset;
|
||||||
public string[] Difficulties;
|
public string[] Difficulties;
|
||||||
|
public bool AllowStartUnitConfig = true;
|
||||||
|
|
||||||
[FieldLoader.Ignore] public Lazy<Dictionary<string, ActorReference>> Actors;
|
[FieldLoader.Ignore] public Lazy<Dictionary<string, ActorReference>> Actors;
|
||||||
|
|
||||||
|
|||||||
@@ -399,6 +399,32 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
server.SyncLobbyInfo();
|
server.SyncLobbyInfo();
|
||||||
return true;
|
return true;
|
||||||
}},
|
}},
|
||||||
|
{ "startingunits",
|
||||||
|
s =>
|
||||||
|
{
|
||||||
|
if (!client.IsAdmin)
|
||||||
|
{
|
||||||
|
server.SendOrderTo(conn, "Message", "Only the host can set that option");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!server.Map.AllowStartUnitConfig)
|
||||||
|
{
|
||||||
|
server.SendOrderTo(conn, "Message", "Map has disabled start unit configuration");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var startUnits = Rules.Info["world"].Traits.WithInterface<MPStartUnitsInfo>();
|
||||||
|
if (!startUnits.Any(msu => msu.Class == s))
|
||||||
|
{
|
||||||
|
server.SendOrderTo(conn, "Message", "Unknown unit class: {0}".F(s));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
server.lobbyInfo.GlobalSettings.StartingUnitsClass = s;
|
||||||
|
server.SyncLobbyInfo();
|
||||||
|
return true;
|
||||||
|
}},
|
||||||
{ "kick",
|
{ "kick",
|
||||||
s =>
|
s =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -318,8 +318,46 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
difficulty.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem);
|
difficulty.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem);
|
||||||
};
|
};
|
||||||
|
|
||||||
var difficultyDesc = optionsBin.GetOrNull<LabelWidget>("DIFFICULTY_DESC");
|
optionsBin.Get<LabelWidget>("DIFFICULTY_DESC").IsVisible = difficulty.IsVisible;
|
||||||
difficultyDesc.IsVisible = difficulty.IsVisible;
|
}
|
||||||
|
|
||||||
|
var startingUnits = optionsBin.GetOrNull<DropDownButtonWidget>("STARTINGUNITS_DROPDOWNBUTTON");
|
||||||
|
if (startingUnits != null)
|
||||||
|
{
|
||||||
|
var classNames = new Dictionary<string,string>()
|
||||||
|
{
|
||||||
|
{"none", "MCV Only"},
|
||||||
|
{"default", "Light Support"},
|
||||||
|
{"heavy", "Heavy Support"},
|
||||||
|
};
|
||||||
|
|
||||||
|
Func<string, string> className = c => classNames.ContainsKey(c) ? classNames[c] : c;
|
||||||
|
var classes = Rules.Info["world"].Traits.WithInterface<MPStartUnitsInfo>()
|
||||||
|
.Select(a => a.Class).Distinct();
|
||||||
|
|
||||||
|
startingUnits.IsDisabled = configurationDisabled;
|
||||||
|
startingUnits.IsVisible = () => Map.AllowStartUnitConfig;
|
||||||
|
startingUnits.GetText = () => className(orderManager.LobbyInfo.GlobalSettings.StartingUnitsClass);
|
||||||
|
startingUnits.OnMouseDown = _ =>
|
||||||
|
{
|
||||||
|
var options = classes.Select(c => new DropDownOption
|
||||||
|
{
|
||||||
|
Title = className(c),
|
||||||
|
IsSelected = () => orderManager.LobbyInfo.GlobalSettings.StartingUnitsClass == c,
|
||||||
|
OnClick = () => orderManager.IssueOrder(Order.Command("startingunits {0}".F(c)))
|
||||||
|
});
|
||||||
|
|
||||||
|
Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
||||||
|
{
|
||||||
|
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
|
||||||
|
item.Get<LabelWidget>("LABEL").GetText = () => option.Title;
|
||||||
|
return item;
|
||||||
|
};
|
||||||
|
|
||||||
|
startingUnits.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem);
|
||||||
|
};
|
||||||
|
|
||||||
|
optionsBin.Get<LabelWidget>("STARTINGUNITS_DESC").IsVisible = startingUnits.IsVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
var disconnectButton = lobby.Get<ButtonWidget>("DISCONNECT_BUTTON");
|
var disconnectButton = lobby.Get<ButtonWidget>("DISCONNECT_BUTTON");
|
||||||
|
|||||||
Reference in New Issue
Block a user