Fix a lot of broken menu stuff in MCP

This commit is contained in:
2026-03-20 14:56:40 -04:00
parent acc5bafe34
commit 0ac9a01859
7 changed files with 142 additions and 167 deletions

View File

@@ -3,136 +3,101 @@
#include "BlueprintActionDatabase.h"
#include "BlueprintNodeSpawner.h"
#include "EdGraphSchema_K2.h"
#include "WingUtils.h"
#include "Kismet2/BlueprintEditorUtils.h"
FString FWingGraphActions::GetFullName(const FEdGraphSchemaAction& Action)
FWingGraphAction::FWingGraphAction(TSharedPtr<FEdGraphSchemaAction> &iAction, UEdGraph *iGraph)
{
FString Category = Action.GetCategory().ToString();
FString MenuName = Action.GetMenuDescription().ToString();
return Category + TEXT("|") + MenuName;
Action = iAction;
Graph = iGraph;
FString Category = Action->GetCategory().ToString();
FString MenuName = Action->GetMenuDescription().ToString();
Name = WingUtils::StandardizeMenuItem(Category + TEXT("|") + MenuName);
Keywords = Action->GetKeywords().ToString();
}
FString FWingGraphActions::GetFullName(const UBlueprintNodeSpawner* Spawner)
FWingGraphAction::FWingGraphAction(UBlueprintNodeSpawner *iSpawner, UEdGraph *iGraph)
{
Spawner = iSpawner;
Graph = iGraph;
const FBlueprintActionUiSpec& UiSpec = Spawner->PrimeDefaultUiSpec();
FString Category = UiSpec.Category.ToString();
FString MenuName = UiSpec.MenuName.ToString();
return Category + TEXT("|") + MenuName;
Name = WingUtils::StandardizeMenuItem(Category + TEXT("|") + MenuName);
Keywords = Spawner->PrimeDefaultUiSpec().Keywords.ToString();
}
bool FWingGraphActions::IsMatch(const FEdGraphSchemaAction& Action, const FString &QueryLower, bool Exact)
UEdGraphNode* FWingGraphAction::Execute(const FVector2D &Location) const
{
FString FullName = GetFullName(Action).ToLower();
if (FullName.Len() < 3) return false;
if (FullName == QueryLower) return true;
if (Exact) return false;
if (FullName.Contains(QueryLower)) return true;
FString Keywords = Action.GetKeywords().ToString();
if (Keywords.ToLower().Contains(QueryLower)) return true;
return false;
}
bool FWingGraphActions::IsMatch(const UBlueprintNodeSpawner* Spawner, const FString &QueryLower, bool Exact)
{
FString FullName = GetFullName(Spawner).ToLower();
if (FullName.Len() < 3) return false;
if (FullName == QueryLower) return true;
if (Exact) return false;
if (FullName.Contains(QueryLower)) return true;
FString Keywords = Spawner->PrimeDefaultUiSpec().Keywords.ToString();
if (Keywords.ToLower().Contains(QueryLower)) return true;
return false;
}
UEdGraphNode* FWingGraphActions::Execute(FEdGraphSchemaAction& Action, int32 X, int32 Y)
{
FVector2D Location(X, Y);
UEdGraphNode* NewNode = Action.PerformAction(Graph, nullptr, Location, /*bSelectNewNode=*/false);
return NewNode;
}
UEdGraphNode* FWingGraphActions::Execute(UBlueprintNodeSpawner* Spawner, int32 X, int32 Y)
{
FVector2D Location(X, Y);
IBlueprintNodeBinder::FBindingSet Bindings;
return Spawner->Invoke(Graph, Bindings, Location);
}
void FWingGraphActions::CollectActions(UEdGraph* GraphP, const FString& Query, int32 MaxResults, bool ExactMatch)
{
Graph = GraphP;
FString QueryLower = Query.ToLower();
FGraphContextMenuBuilder ContextMenuBuilder(Graph);
Graph->GetSchema()->GetGraphContextActions(ContextMenuBuilder);
for (int32 i = 0; i < ContextMenuBuilder.GetNumActions(); i++)
if (Spawner)
{
if ((MaxResults > 0) && (Actions.Num() >= MaxResults)) break;
TSharedPtr<FEdGraphSchemaAction> Action = ContextMenuBuilder.GetSchemaAction(i);
if (IsMatch(*Action, QueryLower, ExactMatch)) Actions.Add(Action);
return Spawner->Invoke(Graph, IBlueprintNodeBinder::FBindingSet(), Location);
}
else
{
return Action->PerformAction(Graph, nullptr, Location, /*bSelectNewNode=*/false);
}
}
void FWingGraphActions::CollectSpawners(UEdGraph* GraphP, const FString& Query, int32 MaxResults, bool ExactMatch)
TArray<FWingGraphAction*> FWingGraphActions::Search(const FString &Query, int32 MaxResults, bool Exact)
{
Graph = GraphP;
FString QueryLower = Query.ToLower();
FString ExtQuery = FString::Printf(TEXT("*%s*"), *Query);
TArray<FWingGraphAction*> Results;
for (FWingGraphAction &Result : Actions)
{
if (Results.Num() == MaxResults) break;
if (Exact)
{
if (Result.Name.Equals(Query, ESearchCase::IgnoreCase))
Results.Emplace(&Result);
}
else
{
if (Result.Name.MatchesWildcard(ExtQuery, ESearchCase::IgnoreCase) ||
Result.Keywords.MatchesWildcard(ExtQuery, ESearchCase::IgnoreCase))
Results.Emplace(&Result);
}
}
return Results;
}
void FWingGraphActions::CollectActions()
{
FGraphContextMenuBuilder ContextMenuBuilder(Graph);
Graph->GetSchema()->GetGraphContextActions(ContextMenuBuilder);
for (int32 i = 0; i < ContextMenuBuilder.GetNumActions(); i++)
{
Actions.Emplace(ContextMenuBuilder.GetSchemaAction(i), Graph);
}
}
void FWingGraphActions::CollectSpawners()
{
for (const auto& Pair : FBlueprintActionDatabase::Get().GetAllActions())
{
for (UBlueprintNodeSpawner* Spawner : Pair.Value)
{
if ((MaxResults > 0) && (Spawners.Num() >= MaxResults)) break;
if (!Spawner) continue;
// Filter by graph compatibility if a graph was provided
if (Spawner->NodeClass)
{
UEdGraphNode* NodeCDO = CastChecked<UEdGraphNode>(Spawner->NodeClass->ClassDefaultObject);
if (!NodeCDO->IsCompatibleWithGraph(Graph))
if (NodeCDO->IsCompatibleWithGraph(Graph))
{
continue;
Actions.Emplace(Spawner, Graph);
}
}
if (IsMatch(Spawner, QueryLower, ExactMatch)) Spawners.Add(Spawner);
}
}
}
FString FWingGraphActions::GetFullName(int N)
{
if (N < Actions.Num())
{
return GetFullName(*Actions[N]);
}
else
{
return GetFullName(Spawners[N - Actions.Num()]);
}
}
UEdGraphNode* FWingGraphActions::Execute(int32 N, int32 PosX, int32 PosY)
{
if (N < Actions.Num())
{
return Execute(*Actions[N], PosX, PosY);
}
else
{
return Execute(Spawners[N - Actions.Num()], PosX, PosY);
}
}
FWingGraphActions::FWingGraphActions(UEdGraph *Graph, const FString& Query, int32 MaxResults, bool ExactMatch)
FWingGraphActions::FWingGraphActions(UEdGraph *iGraph)
{
Graph = iGraph;
if (Cast<UEdGraphSchema_K2>(Graph->GetSchema()))
{
CollectSpawners(Graph, Query, MaxResults, ExactMatch);
CollectSpawners();
}
else
{
CollectActions(Graph, Query, MaxResults, ExactMatch);
CollectActions();
}
}

View File

@@ -18,32 +18,13 @@
FText WingToolMenu::MakeBetterLabel(const UEdGraphPin *Pin, const FText &EntryLabel)
{
FString Sanitized = EntryLabel.ToString();
int32 Dst = 0;
bool Upper = true;
for (int32 Src = 0; Src < Sanitized.Len(); Src++)
{
TCHAR c = Sanitized[Src];
if (FChar::IsAlnum(c))
{
if (Upper) c = FChar::ToUpper(c);
Sanitized[Dst++] = c;
Upper = false;
}
else
{
Upper = true;
if ((c <= 0x20)||(c == 0x7F)) continue;
if (c == ':') c = '-';
Sanitized[Dst++] = c;
}
}
Sanitized.LeftInline(Dst);
FString Standardized = WingUtils::StandardizeMenuItem(EntryLabel.ToString());
if (Pin)
{
Sanitized = FString::Printf(TEXT("Pin:%s:%s"), *WingUtils::FormatName(Pin), *Sanitized);
Standardized = FString::Printf(TEXT("Pin %s %s"),
*WingUtils::FormatName(Pin), *Standardized);
}
return FText::FromString(Sanitized);
return FText::FromString(Standardized);
}
// ============================================================

View File

@@ -87,6 +87,32 @@ FString WingUtils::SanitizeName(FName Name)
return SanitizeName(Name.ToString());
}
FString WingUtils::StandardizeMenuItem(const FString &Item)
{
FString Sanitized = Item;
int32 Dst = 0;
bool Upper = true;
for (int32 Src = 0; Src < Sanitized.Len(); Src++)
{
TCHAR c = Sanitized[Src];
if (FChar::IsAlnum(c))
{
if (Upper) c = FChar::ToUpper(c);
Sanitized[Dst++] = c;
Upper = false;
}
else
{
Upper = true;
if ((c <= 0x20)||(c == 0x7F)) continue;
if (c == ':') c = L'';
Sanitized[Dst++] = c;
}
}
Sanitized.LeftInline(Dst);
return Sanitized;
}
// ============================================================
// Name Lookup
// ============================================================