Files
tbd-station-14/Content.Client/UserInterface/Controls/FancyTree/TreeLine.cs
Leon Friedrich 22d72f56b5 Guidebook Revival (#13320)
* Fix some bugs in stations and do a little cleanup.

* Begin backporting the guidebook.

* wow that's a lot of work.

* More work, gives the monkey some more interactions.

* disco monkye.

* monky

* jobs entry.

* more writing.

* disco

* im being harassed

* fix spacing.

* i hate writing.

* Update Resources/Prototypes/Entities/Mobs/NPCs/animals.yml

Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>

* builds again

* a

* pilfer changes from AL

* fix and remove unused code

* pilfer actual guide changes from AL

* localization

* more error logs & safety checks

* replace controls button with command

* add test

* todos

* pidgin parsing

* remove old parser

* Move files and change tree sorting

* add localization and public methods.

* Add help component/verb

* rename ITag to IDocumentTag

* Fix yml and tweak tooltips

* autoclose tooltip

* Split container

* Fancier-tree

* Hover color

* txt to xml

* oops

* Curse you hidden merge conflicts

* Rename parsing manager

* Stricter arg parsing

tag args must now be of the form key="value"

* Change default args

* Moar tests

* nullable enable

* Even fancier tree

* extremely fancy trees

* better indent icons

* stricter xml and subheadings

* tweak embed margin

* Fix parsing bugs

* quick fixes.

* spain.

* ogh

* hn bmvdsyc

Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
2023-01-16 02:42:22 -06:00

62 lines
2.2 KiB
C#

using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Shared.Utility;
namespace Content.Client.UserInterface.Controls.FancyTree;
/// <summary>
/// This is a basic control that draws the lines connecting parents & children in a tree.
/// </summary>
/// <remarks>
/// Ideally this would just be a draw method in <see cref="TreeItem"/>, but sadly the draw override gets called BEFORE children are drawn.
/// </remarks>
public sealed class TreeLine : Control
{
protected override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
// This is basically just a shitty hack to call Draw() after children get drawn.
if (Parent is not TreeItem parent)
return;
if (!parent.Expanded || !parent.Tree.DrawLines || parent.Body.ChildCount == 0)
return;
var width = Math.Max(1, (int) (parent.Tree.LineWidth * UIScale));
var w1 = width / 2;
var w2 = width - w1;
var global = parent.GlobalPixelPosition;
var iconPos = parent.Icon.GlobalPixelPosition - global;
var iconSize = parent.Icon.PixelSize;
var x = iconPos.X + iconSize.X / 2;
DebugTools.Assert(parent.Icon.Visible);
var buttonPos = parent.Button.GlobalPixelPosition - global;
var buttonSize = parent.Button.PixelSize;
var y1 = buttonPos.Y + buttonSize.Y;
var lastItem = (TreeItem) parent.Body.GetChild(parent.Body.ChildCount - 1);
var childPos = lastItem.Button.GlobalPixelPosition - global;
var y2 = childPos.Y + lastItem.Button.PixelSize.Y / 2;
// Vertical line
var rect = new UIBox2i((x - w1, y1), (x + w2, y2));
handle.DrawRect(rect, parent.Tree.LineColor);
// Horizontal lines
var dx = Math.Max(1, (int) (FancyTree.Indentation * UIScale / 2));
foreach (var child in parent.Body.Children)
{
var item = (TreeItem) child;
var pos = item.Button.GlobalPixelPosition - global;
var y = pos.Y + item.Button.PixelSize.Y / 2;
rect = new UIBox2i((x - w1, y - w1), (x + dx, y + w2));
handle.DrawRect(rect, parent.Tree.LineColor);
}
}
}