Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
Olympe::NodeSearchPanel Class Reference

Singleton fuzzy-search panel for adding nodes to the graph. More...

#include <NodeSearchPanel.h>

Public Member Functions

void OpenSearch (float posX, float posY)
 Opens the search panel at the given graph-space position.
 
void CloseSearch ()
 Closes the search panel and clears the query.
 
bool IsOpen () const
 Returns true if the panel is currently visible.
 
void UpdateQuery (const std::string &query)
 Recomputes the result list for the given query string.
 
const std::vector< NodeSearchResult > & GetResults () const
 Returns the current result list sorted by relevance (best first).
 
void ConfirmSelection (int index)
 Fires the OnNodeAdd callback for the result at index and closes the panel.
 
int GetSelectedIndex () const
 Returns the index of the currently highlighted result (-1 = none).
 
void SelectPrevious ()
 Moves the selection up by one step (wraps around).
 
void SelectNext ()
 Moves the selection down by one step (wraps around).
 
void SetNodeAddCallback (std::function< void(const std::string &, float, float)> callback)
 Registers the callback that fires when the user confirms a node.
 
float GetSpawnX () const
 Returns the X coordinate where the new node should be spawned.
 
float GetSpawnY () const
 Returns the Y coordinate where the new node should be spawned.
 

Static Public Member Functions

static NodeSearchPanelGet ()
 Returns the single shared instance.
 

Private Member Functions

 NodeSearchPanel ()
 
void InitNodeCatalogue ()
 

Static Private Member Functions

static float ComputeScore (const std::string &query, const std::string &candidate)
 Compute a [0..1] relevance score; returns 0 if there is no match.
 

Private Attributes

bool m_IsOpen
 
float m_SpawnPosX
 
float m_SpawnPosY
 
std::vector< NodeSearchResultm_Catalogue
 Full unfiltered catalogue.
 
std::vector< NodeSearchResultm_Results
 Current filtered/sorted results.
 
int m_SelectedIndex
 
std::function< void(const std::string &, float, float)> m_OnNodeAdd
 

Detailed Description

Singleton fuzzy-search panel for adding nodes to the graph.

Typical usage:

sp.SetNodeAddCallback([](const std::string& type, float x, float y) {
graph.AddNode(type, x, y);
});
// On Space key:
sp.OpenSearch(mouseX, mouseY);
// Each frame the panel is open:
sp.UpdateQuery(currentSearchText);
for (const auto& r : sp.GetResults())
// ... render result ...
// On Enter / double-click:
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
void ConfirmSelection(int index)
Fires the OnNodeAdd callback for the result at index and closes the panel.
const std::vector< NodeSearchResult > & GetResults() const
Returns the current result list sorted by relevance (best first).
static NodeSearchPanel & Get()
Returns the single shared instance.

Definition at line 71 of file NodeSearchPanel.h.

Constructor & Destructor Documentation

◆ NodeSearchPanel()

Olympe::NodeSearchPanel::NodeSearchPanel ( )
private

Definition at line 43 of file NodeSearchPanel.cpp.

References InitNodeCatalogue().

+ Here is the call graph for this function:

Member Function Documentation

◆ CloseSearch()

void Olympe::NodeSearchPanel::CloseSearch ( )

Closes the search panel and clears the query.

Definition at line 117 of file NodeSearchPanel.cpp.

References m_IsOpen, m_Results, and m_SelectedIndex.

Referenced by ConfirmSelection().

+ Here is the caller graph for this function:

◆ ComputeScore()

float Olympe::NodeSearchPanel::ComputeScore ( const std::string &  query,
const std::string &  candidate 
)
staticprivate

Compute a [0..1] relevance score; returns 0 if there is no match.

Definition at line 133 of file NodeSearchPanel.cpp.

References GetComponentTypeID_Static().

Referenced by UpdateQuery().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ConfirmSelection()

void Olympe::NodeSearchPanel::ConfirmSelection ( int  index)

Fires the OnNodeAdd callback for the result at index and closes the panel.

No-op if index is out of range.

Definition at line 221 of file NodeSearchPanel.cpp.

References CloseSearch(), GetComponentTypeID_Static(), m_OnNodeAdd, m_Results, m_SpawnPosX, and m_SpawnPosY.

+ Here is the call graph for this function:

◆ Get()

NodeSearchPanel & Olympe::NodeSearchPanel::Get ( )
static

Returns the single shared instance.

Definition at line 37 of file NodeSearchPanel.cpp.

◆ GetResults()

const std::vector< NodeSearchResult > & Olympe::NodeSearchPanel::GetResults ( ) const

Returns the current result list sorted by relevance (best first).

Definition at line 212 of file NodeSearchPanel.cpp.

References m_Results.

◆ GetSelectedIndex()

int Olympe::NodeSearchPanel::GetSelectedIndex ( ) const

Returns the index of the currently highlighted result (-1 = none).

Definition at line 233 of file NodeSearchPanel.cpp.

References m_SelectedIndex.

◆ GetSpawnX()

float Olympe::NodeSearchPanel::GetSpawnX ( ) const

Returns the X coordinate where the new node should be spawned.

Definition at line 268 of file NodeSearchPanel.cpp.

References m_SpawnPosX.

◆ GetSpawnY()

float Olympe::NodeSearchPanel::GetSpawnY ( ) const

Returns the Y coordinate where the new node should be spawned.

Definition at line 269 of file NodeSearchPanel.cpp.

References m_SpawnPosY.

◆ InitNodeCatalogue()

void Olympe::NodeSearchPanel::InitNodeCatalogue ( )
private

Definition at line 56 of file NodeSearchPanel.cpp.

References GetComponentTypeID_Static(), m_Catalogue, Olympe::NodeSearchResult::nodeType, and SYSTEM_LOG.

Referenced by NodeSearchPanel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsOpen()

bool Olympe::NodeSearchPanel::IsOpen ( ) const

Returns true if the panel is currently visible.

Definition at line 124 of file NodeSearchPanel.cpp.

References m_IsOpen.

◆ OpenSearch()

void Olympe::NodeSearchPanel::OpenSearch ( float  posX,
float  posY 
)

Opens the search panel at the given graph-space position.

Parameters
posXSpawn X for the new node (graph space).
posYSpawn Y for the new node (graph space).

Definition at line 105 of file NodeSearchPanel.cpp.

References m_IsOpen, m_Results, m_SelectedIndex, m_SpawnPosX, m_SpawnPosY, and UpdateQuery().

+ Here is the call graph for this function:

◆ SelectNext()

void Olympe::NodeSearchPanel::SelectNext ( )

Moves the selection down by one step (wraps around).

Definition at line 246 of file NodeSearchPanel.cpp.

References GetComponentTypeID_Static(), m_Results, and m_SelectedIndex.

+ Here is the call graph for this function:

◆ SelectPrevious()

void Olympe::NodeSearchPanel::SelectPrevious ( )

Moves the selection up by one step (wraps around).

Definition at line 238 of file NodeSearchPanel.cpp.

References GetComponentTypeID_Static(), m_Results, and m_SelectedIndex.

+ Here is the call graph for this function:

◆ SetNodeAddCallback()

void Olympe::NodeSearchPanel::SetNodeAddCallback ( std::function< void(const std::string &, float, float)>  callback)

Registers the callback that fires when the user confirms a node.

Parameters
callbackSignature: void(nodeType, spawnX, spawnY)

Definition at line 258 of file NodeSearchPanel.cpp.

References GetComponentTypeID_Static(), and m_OnNodeAdd.

+ Here is the call graph for this function:

◆ UpdateQuery()

void Olympe::NodeSearchPanel::UpdateQuery ( const std::string &  query)

Recomputes the result list for the given query string.

Call this every frame (or whenever the query changes).

Definition at line 176 of file NodeSearchPanel.cpp.

References ComputeScore(), GetComponentTypeID_Static(), m_Catalogue, m_Results, m_SelectedIndex, and Olympe::NodeSearchResult::relevanceScore.

Referenced by OpenSearch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_Catalogue

std::vector<NodeSearchResult> Olympe::NodeSearchPanel::m_Catalogue
private

Full unfiltered catalogue.

Definition at line 172 of file NodeSearchPanel.h.

Referenced by InitNodeCatalogue(), and UpdateQuery().

◆ m_IsOpen

bool Olympe::NodeSearchPanel::m_IsOpen
private

Definition at line 169 of file NodeSearchPanel.h.

Referenced by CloseSearch(), IsOpen(), and OpenSearch().

◆ m_OnNodeAdd

std::function<void(const std::string&, float, float)> Olympe::NodeSearchPanel::m_OnNodeAdd
private

Definition at line 175 of file NodeSearchPanel.h.

Referenced by ConfirmSelection(), and SetNodeAddCallback().

◆ m_Results

std::vector<NodeSearchResult> Olympe::NodeSearchPanel::m_Results
private

Current filtered/sorted results.

Definition at line 173 of file NodeSearchPanel.h.

Referenced by CloseSearch(), ConfirmSelection(), GetResults(), OpenSearch(), SelectNext(), SelectPrevious(), and UpdateQuery().

◆ m_SelectedIndex

int Olympe::NodeSearchPanel::m_SelectedIndex
private

◆ m_SpawnPosX

float Olympe::NodeSearchPanel::m_SpawnPosX
private

Definition at line 170 of file NodeSearchPanel.h.

Referenced by ConfirmSelection(), GetSpawnX(), and OpenSearch().

◆ m_SpawnPosY

float Olympe::NodeSearchPanel::m_SpawnPosY
private

Definition at line 171 of file NodeSearchPanel.h.

Referenced by ConfirmSelection(), GetSpawnY(), and OpenSearch().


The documentation for this class was generated from the following files: