Fix empty lobby faction tooltips.
This commit is contained in:
@@ -104,6 +104,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
dropdown.ShowDropDown("SPAWN_DROPDOWN_TEMPLATE", 150, spawnPoints, setupItem);
|
dropdown.ShowDropDown("SPAWN_DROPDOWN_TEMPLATE", 150, spawnPoints, setupItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Splits a string into two parts on the first instance of a given token.</summary>
|
||||||
|
static Pair<string, string> SplitOnFirstToken(string input, string token = "\\n")
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(input))
|
||||||
|
return Pair.New<string, string>(null, null);
|
||||||
|
|
||||||
|
var split = input.IndexOf(token, StringComparison.Ordinal);
|
||||||
|
var first = split > 0 ? input.Substring(0, split) : input;
|
||||||
|
var second = split > 0 ? input.Substring(split + token.Length) : null;
|
||||||
|
return Pair.New(first, second);
|
||||||
|
}
|
||||||
|
|
||||||
public static void ShowFactionDropDown(DropDownButtonWidget dropdown, Session.Client client,
|
public static void ShowFactionDropDown(DropDownButtonWidget dropdown, Session.Client client,
|
||||||
OrderManager orderManager, Dictionary<string, LobbyFaction> factions)
|
OrderManager orderManager, Dictionary<string, LobbyFaction> factions)
|
||||||
{
|
{
|
||||||
@@ -118,11 +130,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
flag.GetImageCollection = () => "flags";
|
flag.GetImageCollection = () => "flags";
|
||||||
flag.GetImageName = () => factionId;
|
flag.GetImageName = () => factionId;
|
||||||
|
|
||||||
var factionName = faction.Description.SubstringBefore("\\n", StringComparison.Ordinal);
|
var tooltip = SplitOnFirstToken(faction.Description);
|
||||||
var factionDescription = faction.Description.SubstringAfter("\\n", StringComparison.Ordinal);
|
item.GetTooltipText = () => tooltip.First;
|
||||||
item.GetTooltipText = () => factionName;
|
item.GetTooltipDesc = () => tooltip.Second;
|
||||||
if (factionDescription != factionName)
|
|
||||||
item.GetTooltipDesc = () => factionDescription;
|
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
};
|
};
|
||||||
@@ -414,11 +424,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
dropdown.IsDisabled = () => s.LockFaction || orderManager.LocalClient.IsReady;
|
dropdown.IsDisabled = () => s.LockFaction || orderManager.LocalClient.IsReady;
|
||||||
dropdown.OnMouseDown = _ => ShowFactionDropDown(dropdown, c, orderManager, factions);
|
dropdown.OnMouseDown = _ => ShowFactionDropDown(dropdown, c, orderManager, factions);
|
||||||
|
|
||||||
var factionName = factions[c.Faction].Description.SubstringBefore("\\n", StringComparison.Ordinal);
|
var tooltip = SplitOnFirstToken(factions[c.Faction].Description);
|
||||||
var factionDescription = factions[c.Faction].Description.SubstringAfter("\\n", StringComparison.Ordinal);
|
dropdown.GetTooltipText = () => tooltip.First;
|
||||||
dropdown.GetTooltipText = () => factionName;
|
dropdown.GetTooltipDesc = () => tooltip.Second;
|
||||||
if (factionDescription != factionName)
|
|
||||||
dropdown.GetTooltipDesc = () => factionDescription;
|
|
||||||
|
|
||||||
SetupFactionWidget(dropdown, s, c, factions);
|
SetupFactionWidget(dropdown, s, c, factions);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user