-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoveConnectionsFragment.cs
More file actions
83 lines (70 loc) · 2.3 KB
/
MoveConnectionsFragment.cs
File metadata and controls
83 lines (70 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using Timberborn.Automation;
using Timberborn.BaseComponentSystem;
using Timberborn.EntityPanelSystem;
using Timberborn.TooltipSystem;
using UnityEngine.UIElements;
using Timberborn.CoreUI;
using Timberborn.Localization;
namespace Calloatti.MoveConnections
{
internal class MoveConnectionsFragment : IEntityPanelFragment
{
private readonly MoveConnectionsTool _moveConnectionsTool;
private readonly ITooltipRegistrar _tooltipRegistrar;
private readonly ILoc _loc;
private VisualElement _root;
private Automator _automator;
public MoveConnectionsFragment(MoveConnectionsTool moveConnectionsTool, ITooltipRegistrar tooltipRegistrar, ILoc loc)
{
_moveConnectionsTool = moveConnectionsTool;
_tooltipRegistrar = tooltipRegistrar;
_loc = loc;
}
public VisualElement InitializeFragment()
{
// We don't need a wrapper here because the header containers in EntityPanel.uxml use Row layout by default.
Button moveButton = new Button(OnButtonClicked);
// Apply the exact classes used by the Duplicate Settings button to make it fit seamlessly into the header.
moveButton.AddToClassList("entity-panel__button");
moveButton.AddToClassList("entity-panel__button--green");
// Add the icon visual element
VisualElement icon = new VisualElement();
icon.AddToClassList("entity-panel__button");
// Reuse the game's native copy-settings icon
icon.AddToClassList("duplicate-settings__icon");
moveButton.Add(icon);
_root = moveButton;
// Register the tooltip
_tooltipRegistrar.Register(_root, _loc.T("Calloatti.AutoTools.MoveConnections.Tooltip"));
_root.ToggleDisplayStyle(false);
return _root;
}
public void ShowFragment(BaseComponent entity)
{
_automator = entity.GetComponent<Automator>();
}
public void ClearFragment()
{
_automator = null;
_root.ToggleDisplayStyle(false);
}
public void UpdateFragment()
{
if (_automator != null && _automator.IsTransmitter)
{
_root.ToggleDisplayStyle(true);
}
else
{
_root.ToggleDisplayStyle(false);
}
}
private void OnButtonClicked()
{
if (_automator != null)
{
_moveConnectionsTool.SwitchTo(_automator);
}
}
}
}