57 lines
1.3 KiB
C#
57 lines
1.3 KiB
C#
|
|
|
||
|
|
using System.Diagnostics;
|
||
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System;
|
||
|
|
using Godot;
|
||
|
|
|
||
|
|
|
||
|
|
using Rokojori.Extensions;
|
||
|
|
namespace Rokojori
|
||
|
|
{
|
||
|
|
[Tool]
|
||
|
|
[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/Selector.svg")]
|
||
|
|
public partial class SelectManager:Node
|
||
|
|
{
|
||
|
|
[Export]
|
||
|
|
public Node root;
|
||
|
|
|
||
|
|
Dictionary<Selector,Node> _singleSelections = new Dictionary<Selector, Node>();
|
||
|
|
Dictionary<Selector,List<Node>> _listSelections = new Dictionary<Selector, List<Node>>();
|
||
|
|
|
||
|
|
public Node GetSelectionRoot()
|
||
|
|
{
|
||
|
|
return root == null ? GetTree().Root : root;
|
||
|
|
}
|
||
|
|
|
||
|
|
public Node Select( Selector selector )
|
||
|
|
{
|
||
|
|
if ( selector == null )
|
||
|
|
{
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
if ( ! _singleSelections.ContainsKey( selector ) )
|
||
|
|
{
|
||
|
|
_singleSelections[ selector ] = GetSelectionRoot().Select( selector );
|
||
|
|
}
|
||
|
|
|
||
|
|
return _singleSelections[ selector ];
|
||
|
|
}
|
||
|
|
|
||
|
|
public List<Node> SelectAll( Selector selector )
|
||
|
|
{
|
||
|
|
if ( selector == null )
|
||
|
|
{
|
||
|
|
return new List<Node>();
|
||
|
|
}
|
||
|
|
|
||
|
|
if ( ! _singleSelections.ContainsKey( selector ) )
|
||
|
|
{
|
||
|
|
_listSelections[ selector ] = GetSelectionRoot().SelectAll( selector );
|
||
|
|
}
|
||
|
|
|
||
|
|
return _listSelections[ selector ];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|