Merge pull request #6217 from Mailaender/starting-units-classname

Fixed lobby start unit notifications not showing class names
This commit is contained in:
Paul Chote
2014-08-19 10:15:12 +12:00
14 changed files with 111 additions and 46 deletions

View File

@@ -15,10 +15,19 @@ namespace OpenRA.Mods.RA
[Desc("Used by SpawnMPUnits. Attach these to the world actor. You can have multiple variants by adding @suffixes.")]
public class MPStartUnitsInfo : TraitInfo<MPStartUnits>
{
[Desc("Internal class ID.")]
public readonly string Class = "none";
[Desc("Exposed via the UI to the player.")]
public readonly string ClassName = "Unlabeled";
[Desc("Only available when selecting this faction.", "Leave empty for no restrictions.")]
public readonly string[] Races = { };
[Desc("The mobile construction vehicle.")]
public readonly string BaseActor = null;
[Desc("A group of units ready to defend or scout.")]
public readonly string[] SupportActors = { };
[Desc("Inner radius for spawning support actors")]

View File

@@ -561,6 +561,7 @@
<Compile Include="Player\GlobalUpgradeManager.cs" />
<Compile Include="GainsStatUpgrades.cs" />
<Compile Include="Player\Extensions.cs" />
<Compile Include="ServerTraits\LobbySettingsNotification.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">

View File

@@ -552,9 +552,13 @@ namespace OpenRA.Mods.RA.Server
return true;
}
var startUnitsInfo = server.Map.Rules.Actors["world"].Traits.WithInterface<MPStartUnitsInfo>();
var selectedClass = startUnitsInfo.Where(u => u.Class == s).Select(u => u.ClassName).FirstOrDefault();
var className = selectedClass != null ? selectedClass : s;
server.LobbyInfo.GlobalSettings.StartingUnitsClass = s;
server.SyncLobbyGlobalSettings();
server.SendMessage("{0} changed Starting Units to {1}.".F(client.Name, s));
server.SendMessage("{0} changed Starting Units to {1}.".F(client.Name, className));
return true;
}},

View File

@@ -0,0 +1,60 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Linq;
using OpenRA.Network;
using OpenRA.Server;
namespace OpenRA.Mods.RA.Server
{
public class LobbySettingsNotification : ServerTrait, IClientJoined
{
public void ClientJoined(OpenRA.Server.Server server, Connection conn)
{
if (server.LobbyInfo.ClientWithIndex(conn.PlayerIndex).IsAdmin)
return;
var defaults = new Session.Global();
FieldLoader.Load(defaults, Game.modData.Manifest.LobbyDefaults);
if (server.LobbyInfo.GlobalSettings.FragileAlliances != defaults.FragileAlliances)
server.SendOrderTo(conn, "Message", "Diplomacy Changes: {0}".F(server.LobbyInfo.GlobalSettings.FragileAlliances));
if (server.LobbyInfo.GlobalSettings.AllowCheats != defaults.AllowCheats)
server.SendOrderTo(conn, "Message", "Allow Cheats: {0}".F(server.LobbyInfo.GlobalSettings.AllowCheats));
if (server.LobbyInfo.GlobalSettings.Shroud != defaults.Shroud)
server.SendOrderTo(conn, "Message", "Shroud: {0}".F(server.LobbyInfo.GlobalSettings.Shroud));
if (server.LobbyInfo.GlobalSettings.Fog != defaults.Fog)
server.SendOrderTo(conn, "Message", "Fog of war: {0}".F(server.LobbyInfo.GlobalSettings.Fog));
if (server.LobbyInfo.GlobalSettings.Crates != defaults.Crates)
server.SendOrderTo(conn, "Message", "Crates Appear: {0}".F(server.LobbyInfo.GlobalSettings.Crates));
if (server.LobbyInfo.GlobalSettings.AllyBuildRadius != defaults.AllyBuildRadius)
server.SendOrderTo(conn, "Message", "Build off Ally ConYards: {0}".F(server.LobbyInfo.GlobalSettings.AllyBuildRadius));
if (server.LobbyInfo.GlobalSettings.StartingUnitsClass != defaults.StartingUnitsClass)
{
var startUnitsInfo = server.Map.Rules.Actors["world"].Traits.WithInterface<MPStartUnitsInfo>();
var selectedClass = startUnitsInfo.Where(u => u.Class == server.LobbyInfo.GlobalSettings.StartingUnitsClass).Select(u => u.ClassName).FirstOrDefault();
var className = selectedClass != null ? selectedClass : server.LobbyInfo.GlobalSettings.StartingUnitsClass;
server.SendOrderTo(conn, "Message", "Starting Units: {0}".F(className));
}
if (server.LobbyInfo.GlobalSettings.StartingCash != defaults.StartingCash)
server.SendOrderTo(conn, "Message", "Starting Cash: ${0}".F(server.LobbyInfo.GlobalSettings.StartingCash));
if (server.LobbyInfo.GlobalSettings.TechLevel != defaults.TechLevel)
server.SendOrderTo(conn, "Message", "Tech Level: {0}".F(server.LobbyInfo.GlobalSettings.TechLevel));
}
}
}

View File

@@ -371,17 +371,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var startingUnits = optionsBin.GetOrNull<DropDownButtonWidget>("STARTINGUNITS_DROPDOWNBUTTON");
if (startingUnits != null)
{
var classNames = new Dictionary<string, string>()
var startUnitsInfo = modRules.Actors["world"].Traits.WithInterface<MPStartUnitsInfo>();
var classes = startUnitsInfo.Select(a => a.Class).Distinct();
Func<string, string> className = c =>
{
{ "none", "MCV Only" },
{ "light", "Light Support" },
{ "heavy", "Heavy Support" },
var selectedClass = startUnitsInfo.Where(s => s.Class == c).Select(u => u.ClassName).FirstOrDefault();
return selectedClass != null ? selectedClass : c;
};
Func<string, string> className = c => classNames.ContainsKey(c) ? classNames[c] : c;
var classes = modRules.Actors["world"].Traits.WithInterface<MPStartUnitsInfo>()
.Select(a => a.Class).Distinct();
startingUnits.IsDisabled = () => Map.Status != MapStatus.Available || !Map.Map.Options.ConfigurableStartingUnits || configurationDisabled();
startingUnits.GetText = () => Map.Status != MapStatus.Available || !Map.Map.Options.ConfigurableStartingUnits ? "Not Available" : className(orderManager.LobbyInfo.GlobalSettings.StartingUnitsClass);
startingUnits.OnMouseDown = _ =>