首页 > 解决方案 > 如何使用路径字符串正确填充/导航此树结构?

问题描述

更新:

事实证明我不必要地使事情复杂化。出于上下文菜单的目的,您实际上只需要一个任意树(带有Parent,FirstChildNextSibling)。为上下文菜单可视化树的最佳方式就像任何其他树一样,但水平分支而不是垂直分支。从来没有真正需要能够在 4 个不同的方向(、、和)上行走树Up,因为Down您需要的所有信息都已经存在,并且(所有这些都相当容易确定您是否已经有一个列表路径字符串)。 该线程可以安全地关闭。LeftRightParentFirstChildNextSibling


我没有使用 XPath 或任何与 web 或 DOM 相关的库,但我想利用 XPath 样式的方法来填充上下文菜单小部件的内容:

struct ContextMenuNode
{
    ContextMenuNode* Left; // Parent Menu
    ContextMenuNode* Right; // Sub Menu
    ContextMenuNode* Up; // Previous Sibling
    ContextMenuNode* Down; // Next Sibling
    FString Path; // An XPath-like string
    FString Caption; // Display text of this menu item
}

我想做的是这样的:

// Defined in a class declaration:
TArray<ContextMenuNode*> MenuNodes;

// ...

/* This should create 2 unique nodes ("/File" doesn't exist yet within MenuNodes),
establish Left & Right relationships between them, and
return the newly created "/File/Open" node,
adding both nodes into MenuNodes
*/
auto openFileNode = AddNode("/File/Open");

/* Much like the previous line, this should
create 1 unique node (since "/File" should already exist from the previous call),
Left should be "/File", Up should be "/File/Open".
But also, we need to update THOSE nodes in relation to this node now...
Both "/File/Open" and "/File/Save" are Up/Down siblings with the same Left ("/File")
*/
auto saveFileNode = AddNode("/File/Save");

这是如何实现的,或者是否有更好的方法来解决这个问题?

对不熟悉 UE4 的人有用的链接:

标签: c++algorithmxpathtreeunreal-engine4

解决方案


推荐阅读