Use standard button tooltip for faction descriptions.
This commit is contained in:
@@ -590,7 +590,6 @@
|
|||||||
<Compile Include="Widgets\Logic\ButtonTooltipLogic.cs" />
|
<Compile Include="Widgets\Logic\ButtonTooltipLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\ColorPickerLogic.cs" />
|
<Compile Include="Widgets\Logic\ColorPickerLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\ConnectionLogic.cs" />
|
<Compile Include="Widgets\Logic\ConnectionLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\FactionTooltipLogic.cs" />
|
|
||||||
<Compile Include="Widgets\Logic\CreditsLogic.cs" />
|
<Compile Include="Widgets\Logic\CreditsLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\DisconnectWatcherLogic.cs" />
|
<Compile Include="Widgets\Logic\DisconnectWatcherLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\Ingame\AddFactionSuffixLogic.cs" />
|
<Compile Include="Widgets\Logic\Ingame\AddFactionSuffixLogic.cs" />
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
#region Copyright & License Information
|
|
||||||
/*
|
|
||||||
* Copyright 2007-2017 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, either version 3 of
|
|
||||||
* the License, or (at your option) any later version. For more
|
|
||||||
* information, see COPYING.
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using OpenRA.Widgets;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
|
||||||
{
|
|
||||||
public class FactionTooltipLogic : ChromeLogic
|
|
||||||
{
|
|
||||||
[ObjectCreator.UseCtor]
|
|
||||||
public FactionTooltipLogic(Widget widget, ButtonWidget button)
|
|
||||||
{
|
|
||||||
var lines = button.GetTooltipText().Replace("\\n", "\n").Split('\n');
|
|
||||||
|
|
||||||
var header = widget.Get<LabelWidget>("HEADER");
|
|
||||||
var headerLine = lines[0];
|
|
||||||
var headerFont = Game.Renderer.Fonts[header.Font];
|
|
||||||
var headerSize = headerFont.Measure(headerLine);
|
|
||||||
header.Bounds.Width += headerSize.X;
|
|
||||||
header.Bounds.Height += headerSize.Y;
|
|
||||||
header.GetText = () => headerLine;
|
|
||||||
|
|
||||||
if (lines.Length > 1)
|
|
||||||
{
|
|
||||||
var description = widget.Get<LabelWidget>("DESCRIPTION");
|
|
||||||
var descriptionLines = lines.Skip(1).ToArray();
|
|
||||||
var descriptionFont = Game.Renderer.Fonts[description.Font];
|
|
||||||
description.Bounds.Y += header.Bounds.Y + header.Bounds.Height;
|
|
||||||
description.Bounds.Width += descriptionLines.Select(l => descriptionFont.Measure(l).X).Max();
|
|
||||||
description.Bounds.Height += descriptionFont.Measure(descriptionLines.First()).Y * descriptionLines.Length;
|
|
||||||
description.GetText = () => string.Join("\n", descriptionLines);
|
|
||||||
|
|
||||||
widget.Bounds.Width = Math.Max(header.Bounds.X + header.Bounds.Width, description.Bounds.X + description.Bounds.Width);
|
|
||||||
widget.Bounds.Height = description.Bounds.Y + description.Bounds.Height;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
widget.Bounds.Width = header.Bounds.X + header.Bounds.Width;
|
|
||||||
widget.Bounds.Height = header.Bounds.Y + header.Bounds.Height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -118,7 +118,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var flag = item.Get<ImageWidget>("FLAG");
|
var flag = item.Get<ImageWidget>("FLAG");
|
||||||
flag.GetImageCollection = () => "flags";
|
flag.GetImageCollection = () => "flags";
|
||||||
flag.GetImageName = () => factionId;
|
flag.GetImageName = () => factionId;
|
||||||
item.GetTooltipText = () => faction.Description;
|
|
||||||
|
var factionName = faction.Description.SubstringBefore("\\n", StringComparison.Ordinal);
|
||||||
|
var factionDescription = faction.Description.SubstringAfter("\\n", StringComparison.Ordinal);
|
||||||
|
item.GetTooltipText = () => factionName;
|
||||||
|
if (factionDescription != factionName)
|
||||||
|
item.GetTooltipDesc = () => factionDescription;
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -408,8 +414,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var dropdown = parent.Get<DropDownButtonWidget>("FACTION");
|
var dropdown = parent.Get<DropDownButtonWidget>("FACTION");
|
||||||
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 factionDescription = factions[c.Faction].Description;
|
|
||||||
dropdown.GetTooltipText = () => factionDescription;
|
var factionName = factions[c.Faction].Description.SubstringBefore("\\n", StringComparison.Ordinal);
|
||||||
|
var factionDescription = factions[c.Faction].Description.SubstringAfter("\\n", StringComparison.Ordinal);
|
||||||
|
dropdown.GetTooltipText = () => factionName;
|
||||||
|
if (factionDescription != factionName)
|
||||||
|
dropdown.GetTooltipDesc = () => factionDescription;
|
||||||
|
|
||||||
SetupFactionWidget(dropdown, s, c, factions);
|
SetupFactionWidget(dropdown, s, c, factions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ ScrollPanel@FACTION_DROPDOWN_TEMPLATE:
|
|||||||
Y: 0
|
Y: 0
|
||||||
Visible: false
|
Visible: false
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
TooltipTemplate: FACTION_DESCRIPTION_TOOLTIP
|
|
||||||
Children:
|
Children:
|
||||||
Image@FLAG:
|
Image@FLAG:
|
||||||
X: 4
|
X: 4
|
||||||
|
|||||||
@@ -116,7 +116,6 @@ Container@LOBBY_PLAYER_BIN:
|
|||||||
Font: Regular
|
Font: Regular
|
||||||
IgnoreChildMouseOver: true
|
IgnoreChildMouseOver: true
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
TooltipTemplate: FACTION_DESCRIPTION_TOOLTIP
|
|
||||||
PanelRoot: FACTION_DROPDOWN_PANEL_ROOT # ensure that tooltips for the options are on top of the dropdown panel
|
PanelRoot: FACTION_DROPDOWN_PANEL_ROOT # ensure that tooltips for the options are on top of the dropdown panel
|
||||||
Children:
|
Children:
|
||||||
Image@FACTIONFLAG:
|
Image@FACTIONFLAG:
|
||||||
|
|||||||
@@ -245,22 +245,3 @@ Background@INGAME_CLIENT_TOOLTIP:
|
|||||||
Height: 10
|
Height: 10
|
||||||
Font: TinyBold
|
Font: TinyBold
|
||||||
Align: Center
|
Align: Center
|
||||||
|
|
||||||
Background@FACTION_DESCRIPTION_TOOLTIP:
|
|
||||||
Logic: FactionTooltipLogic
|
|
||||||
Background: panel-black
|
|
||||||
Children:
|
|
||||||
Label@HEADER:
|
|
||||||
X: 7
|
|
||||||
Y: 6
|
|
||||||
Width: 8
|
|
||||||
Height: 12
|
|
||||||
Font: Bold
|
|
||||||
VAlign: Top
|
|
||||||
Label@DESCRIPTION:
|
|
||||||
X: 14
|
|
||||||
Y: 0
|
|
||||||
Width: 15
|
|
||||||
Height: 14
|
|
||||||
Font: TinyBold
|
|
||||||
VAlign: Top
|
|
||||||
|
|||||||
@@ -112,7 +112,6 @@ Container@LOBBY_PLAYER_BIN:
|
|||||||
Height: 25
|
Height: 25
|
||||||
IgnoreChildMouseOver: true
|
IgnoreChildMouseOver: true
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
TooltipTemplate: FACTION_DESCRIPTION_TOOLTIP
|
|
||||||
PanelRoot: FACTION_DROPDOWN_PANEL_ROOT # ensure that tooltips for the options are on top of the dropdown panel
|
PanelRoot: FACTION_DROPDOWN_PANEL_ROOT # ensure that tooltips for the options are on top of the dropdown panel
|
||||||
Children:
|
Children:
|
||||||
Image@FACTIONFLAG:
|
Image@FACTIONFLAG:
|
||||||
@@ -412,7 +411,6 @@ ScrollPanel@FACTION_DROPDOWN_TEMPLATE:
|
|||||||
Y: 0
|
Y: 0
|
||||||
Visible: false
|
Visible: false
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
TooltipTemplate: FACTION_DESCRIPTION_TOOLTIP
|
|
||||||
Children:
|
Children:
|
||||||
Image@FLAG:
|
Image@FLAG:
|
||||||
X: 5
|
X: 5
|
||||||
|
|||||||
@@ -254,22 +254,3 @@ Background@SUPPORT_POWER_TOOLTIP:
|
|||||||
Y: 22
|
Y: 22
|
||||||
Font: TinyBold
|
Font: TinyBold
|
||||||
VAlign: Top
|
VAlign: Top
|
||||||
|
|
||||||
Background@FACTION_DESCRIPTION_TOOLTIP:
|
|
||||||
Logic: FactionTooltipLogic
|
|
||||||
Background: dialog4
|
|
||||||
Children:
|
|
||||||
Label@HEADER:
|
|
||||||
X: 7
|
|
||||||
Y: 6
|
|
||||||
Width: 8
|
|
||||||
Height: 12
|
|
||||||
Font: Bold
|
|
||||||
VAlign: Top
|
|
||||||
Label@DESCRIPTION:
|
|
||||||
X: 14
|
|
||||||
Y: 0
|
|
||||||
Width: 15
|
|
||||||
Height: 14
|
|
||||||
Font: TinyBold
|
|
||||||
VAlign: Top
|
|
||||||
|
|||||||
@@ -112,7 +112,6 @@ Container@LOBBY_PLAYER_BIN:
|
|||||||
Height: 25
|
Height: 25
|
||||||
IgnoreChildMouseOver: true
|
IgnoreChildMouseOver: true
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
TooltipTemplate: FACTION_DESCRIPTION_TOOLTIP
|
|
||||||
PanelRoot: FACTION_DROPDOWN_PANEL_ROOT # ensure that tooltips for the options are on top of the dropdown panel
|
PanelRoot: FACTION_DROPDOWN_PANEL_ROOT # ensure that tooltips for the options are on top of the dropdown panel
|
||||||
Children:
|
Children:
|
||||||
Image@FACTIONFLAG:
|
Image@FACTIONFLAG:
|
||||||
@@ -412,7 +411,6 @@ ScrollPanel@FACTION_DROPDOWN_TEMPLATE:
|
|||||||
Y: 0
|
Y: 0
|
||||||
Visible: false
|
Visible: false
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
TooltipTemplate: FACTION_DESCRIPTION_TOOLTIP
|
|
||||||
Children:
|
Children:
|
||||||
Image@FLAG:
|
Image@FLAG:
|
||||||
X: 2
|
X: 2
|
||||||
|
|||||||
@@ -230,22 +230,3 @@ Background@SUPPORT_POWER_TOOLTIP:
|
|||||||
Y: 28
|
Y: 28
|
||||||
Font: TinyBold
|
Font: TinyBold
|
||||||
VAlign: Top
|
VAlign: Top
|
||||||
|
|
||||||
Background@FACTION_DESCRIPTION_TOOLTIP:
|
|
||||||
Logic: FactionTooltipLogic
|
|
||||||
Background: dialog3
|
|
||||||
Children:
|
|
||||||
Label@HEADER:
|
|
||||||
X: 7
|
|
||||||
Y: 7
|
|
||||||
Width: 8
|
|
||||||
Height: 10
|
|
||||||
Font: Bold
|
|
||||||
VAlign: Top
|
|
||||||
Label@DESCRIPTION:
|
|
||||||
X: 14
|
|
||||||
Y: 0
|
|
||||||
Width: 15
|
|
||||||
Height: 14
|
|
||||||
Font: TinyBold
|
|
||||||
VAlign: Top
|
|
||||||
|
|||||||
Reference in New Issue
Block a user