Overhaul the lobby faction dropdown for ra
This commit is contained in:
@@ -19,9 +19,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
var label = widget.Get<LabelWidget>("LABEL");
|
||||
var font = Game.Renderer.Fonts[label.Font];
|
||||
var labelWidth = font.Measure(button.TooltipText).X;
|
||||
var text = button.GetTooltipText();
|
||||
var labelWidth = font.Measure(text).X;
|
||||
|
||||
label.GetText = () => button.TooltipText;
|
||||
label.GetText = () => text;
|
||||
label.Bounds.Width = labelWidth;
|
||||
widget.Bounds.Width = 2 * label.Bounds.X + labelWidth;
|
||||
|
||||
|
||||
52
OpenRA.Mods.Common/Widgets/Logic/CountryTooltipLogic.cs
Normal file
52
OpenRA.Mods.Common/Widgets/Logic/CountryTooltipLogic.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
#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;
|
||||
using System.Linq;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
public class CountryTooltipLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public CountryTooltipLogic(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user