Use standard button tooltip for faction descriptions.

This commit is contained in:
Paul Chote
2017-06-24 12:14:54 +01:00
committed by reaperrr
parent 3996aadcb6
commit 714b24329c
10 changed files with 14 additions and 120 deletions

View File

@@ -590,7 +590,6 @@
<Compile Include="Widgets\Logic\ButtonTooltipLogic.cs" />
<Compile Include="Widgets\Logic\ColorPickerLogic.cs" />
<Compile Include="Widgets\Logic\ConnectionLogic.cs" />
<Compile Include="Widgets\Logic\FactionTooltipLogic.cs" />
<Compile Include="Widgets\Logic\CreditsLogic.cs" />
<Compile Include="Widgets\Logic\DisconnectWatcherLogic.cs" />
<Compile Include="Widgets\Logic\Ingame\AddFactionSuffixLogic.cs" />

View File

@@ -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;
}
}
}
}

View File

@@ -118,7 +118,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var flag = item.Get<ImageWidget>("FLAG");
flag.GetImageCollection = () => "flags";
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;
};
@@ -408,8 +414,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var dropdown = parent.Get<DropDownButtonWidget>("FACTION");
dropdown.IsDisabled = () => s.LockFaction || orderManager.LocalClient.IsReady;
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);
}

View File

@@ -50,7 +50,6 @@ ScrollPanel@FACTION_DROPDOWN_TEMPLATE:
Y: 0
Visible: false
TooltipContainer: TOOLTIP_CONTAINER
TooltipTemplate: FACTION_DESCRIPTION_TOOLTIP
Children:
Image@FLAG:
X: 4

View File

@@ -116,7 +116,6 @@ Container@LOBBY_PLAYER_BIN:
Font: Regular
IgnoreChildMouseOver: true
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
Children:
Image@FACTIONFLAG:

View File

@@ -245,22 +245,3 @@ Background@INGAME_CLIENT_TOOLTIP:
Height: 10
Font: TinyBold
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

View File

@@ -112,7 +112,6 @@ Container@LOBBY_PLAYER_BIN:
Height: 25
IgnoreChildMouseOver: true
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
Children:
Image@FACTIONFLAG:
@@ -412,7 +411,6 @@ ScrollPanel@FACTION_DROPDOWN_TEMPLATE:
Y: 0
Visible: false
TooltipContainer: TOOLTIP_CONTAINER
TooltipTemplate: FACTION_DESCRIPTION_TOOLTIP
Children:
Image@FLAG:
X: 5

View File

@@ -254,22 +254,3 @@ Background@SUPPORT_POWER_TOOLTIP:
Y: 22
Font: TinyBold
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

View File

@@ -112,7 +112,6 @@ Container@LOBBY_PLAYER_BIN:
Height: 25
IgnoreChildMouseOver: true
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
Children:
Image@FACTIONFLAG:
@@ -412,7 +411,6 @@ ScrollPanel@FACTION_DROPDOWN_TEMPLATE:
Y: 0
Visible: false
TooltipContainer: TOOLTIP_CONTAINER
TooltipTemplate: FACTION_DESCRIPTION_TOOLTIP
Children:
Image@FLAG:
X: 2

View File

@@ -230,22 +230,3 @@ Background@SUPPORT_POWER_TOOLTIP:
Y: 28
Font: TinyBold
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