using Editor.MapDoc;
using NativeMapDoc;
using System;
namespace Editor.MapEditor;
///
/// Current selection set for the active map
///
///
/// Currently this only supports selections.
/// There are selections of vertices, edges, faces too that would likely change this API
///
public static class Selection
{
///
/// Called when the selection in Hammer is changed
///
public static event Action OnChanged;
///
/// The current selection mode e.g Meshes or Objects
///
public static SelectMode SelectMode
{
get
{
if ( !NativeSelection.IsValid ) return default;
return NativeSelection.GetMode();
}
set
{
if ( !NativeSelection.IsValid ) return;
NativeSelection.SetMode( value, SelectionConversionMethod_t.SELECTION_CONVERT_STANDARD );
}
}
///
/// The position of the selection's pivot
///
public static Vector3 PivotPosition
{
get
{
if ( !NativeSelection.IsValid ) return default;
return NativeSelection.ActiveSelectionSet().GetPivotPosition();
}
set
{
if ( !NativeSelection.IsValid ) return;
NativeSelection.ActiveSelectionSet().SetPivot( value );
}
}
///
/// All the map nodes in the current selection set
///
public static IEnumerable All
{
get
{
if ( !NativeSelection.IsValid )
yield break;
var count = NativeSelection.ActiveSelectionSet().Count();
for ( int i = 0; i < count; i++ )
{
var node = NativeSelection.ActiveSelectionSet().GetSelectedObject( i );
yield return node;
}
}
}
///
/// Add the map node to the current set
///
public static void Add( MapNode node )
{
NativeSelection.ActiveSelectionSet().SelectObject( node, SelectionOperation_t.SELECT_OP_ADD );
}
///
/// Clear the current set, making the map node the only selected node
///
public static void Set( MapNode node )
{
NativeSelection.ActiveSelectionSet().SelectObject( node, SelectionOperation_t.SELECT_OP_SET );
}
///
/// Remove this map node from the current set if it exists
///
public static void Remove( MapNode node )
{
NativeSelection.ActiveSelectionSet().SelectObject( node, SelectionOperation_t.SELECT_OP_REMOVE );
}
///
/// Clear everything from the current selection set
///
public static void Clear()
{
NativeSelection.ActiveSelectionSet().RemoveAll();
}
///
/// Add all to the current selection
///
public static void SelectAll()
{
NativeSelection.ActiveSelectionSet().SelectAll();
}
///
/// Invert the current selection
///
public static void InvertSelection()
{
NativeSelection.ActiveSelectionSet().InvertSelection();
}
internal static CSelection NativeSelection
{
get
{
if ( !Hammer.ActiveMap.IsValid() ) return default;
return Hammer.ActiveMap.native.GetSelection();
}
}
internal static void OnSelectionChanged()
{
OnChanged?.Invoke();
EditorEvent.Run( "hammer.selection.changed" );
}
}
public enum SelectMode
{
///
/// Select groups, ungrouped entities, and ungrouped solids
///
Groups = 0,
///
/// Select entities and solids not in entities
///
Objects,
///
/// Select point entities, solids in entities, solids
///
Meshes,
///
/// Select vertices
///
Verticies,
///
/// Select edges
///
Edges,
///
/// Select faces
///
Faces,
///
/// Select nav mesh components
///
Nav,
///
/// Select the grid tiles
///
Tiles
}