Display Strategies - Grim-/Talented GitHub Wiki
Display strategies determine how nodes are positioned within the talent tree's visual layout. Each strategy implements different algorithms for node placement and can be defined through XML.
You would define which displayStratgey
to use in the <Talented.UpgradeTreeDef>
, for the moment only Horizontal, Vertical and FixedPosition are considered stable.
Display strategies handle the mathematical positioning of nodes in the tree. To implement a strategy, it must conform to the ITreeDisplayStrategy
interface and provide a parameterless constructor. Strategies can be defined and configured through XML configuration files.
The system includes several pre-built layout strategies:
The Vertical Strategy arranges nodes in a top-to-bottom or bottom-to-top layout. It centers start nodes at the bottom/top, maintains consistent vertical spacing between levels, and effectively handles branching paths. This strategy supports multiple start nodes and provides controls for padding and margins.
Additional built-in options include:
- Horizontal Strategy
- Radial Tree Strategy
public class MyCustomStrategy : ITreeDisplayStrategy
{
public Dictionary<UpgradeTreeNodeDef, Rect> PositionNodes(
List<UpgradeTreeNodeDef> nodes,
Rect availableSpace,
float nodeSize,
float spacing)
{
var positions = new Dictionary<UpgradeTreeNodeDef, Rect>();
// Your positioning logic here
return positions;
}
public void DrawToolBar(Rect toolbarRect)
{
// Optional toolbar drawing logic
}
}
### XML Definition
<Talented.TreeDisplayStrategyDef>
<defName>MyCustomLayout</defName>
<label>Custom Layout Strategy</label>
<description>A custom node layout strategy</description>
<strategyClass>MyMod.MyCustomStrategy</strategyClass>
</Talented.TreeDisplayStrategyDef>
<Talented.UpgradeTreeDef>
<defName>MyTree</defName>
<displayStrategy>MyCustomLayout</displayStrategy>
<!-- other tree properties -->
</Talented.UpgradeTreeDef>
public interface ITreeDisplayStrategy
{
Dictionary<UpgradeTreeNodeDef, Rect> PositionNodes(
List<UpgradeTreeNodeDef> nodes, // All nodes in the tree
Rect availableSpace, // Total space available
float nodeSize, // Size of each node
float spacing // Minimum spacing between nodes
);
void DrawToolBar(Rect toolbarRect); // Optional toolbar
}