EditorContext class

EditorContext — owns the editor's state: the scene being edited, selection, undo, play sessions, and the panels. Its frame runs on Encoder before each render.

Public types

struct UnsavedDocument
enum class SelectMode: uint8_t { Replace, Add, Toggle, Remove }

Constructors, destructors, conversion operators

EditorContext()
~EditorContext()

Public functions

void Initialize(TrinyxEngine* engine, LogicThreadBase* logic)
void BuildFrame()
void LoadScene(const std::string& path, bool bReset = true)
void OpenConstructEditor(const char* typeName, const char* filePath = nullptr)
void OpenEntityEditor(const char* typeName, const char* filePath = nullptr)
void OpenPrefabEditor(const std::string& filePath)
void OpenWidgetDesigner(const std::string& filePath)
Open (or bring to the front) a widget asset in the widget designer.
auto GetDesigner() -> WidgetDesigner&
void ShowImportDialog()
Ask for a glTF / GLB file and import it (the Content Browser's Import).
void HandleDroppedFile(const std::string& path)
Handle a file dropped onto the window (called from EditorRenderer on render thread).
void SpawnPrefab(const std::string& prefabPath)
Spawn a prefab into the current scene. Called from content browser drag-drop or double-click.
auto SpawnPrefabEntities(const std::string& prefabPath) -> std::vector<EntityHandle>
Spawn a prefab's entities and return them, with no undo step.
void DeleteSelectedEntity()
Delete the currently selected entity (deferred via Spawn handshake).
void StartPIELocal()
PIE local mode: single solo world, replaces primary window with game viewport.
void StartPIE()
PIE networked mode: server + client worlds in floating viewports.
void StopPIE()
Stop whichever PIE mode is active.
auto IsPIEActive() const -> bool
auto PlayWorlds() -> std::vector<std::pair<WorldBase*, std::string>>
The play session's worlds, and what each is: "Solo", "Authority", "Owner 1". Encoder thread.
template<typename T, typename... Args>
auto AddPanel(Args && ... args) -> T*
Register a panel. EditorContext takes ownership.
void PushCommand(std::unique_ptr<UndoCommand> cmd, const char* name)
void BeginInteraction(const char* name)
void Undo()
void Redo()
auto CanUndo() const -> bool
auto CanRedo() const -> bool
auto GetState() -> EditorState&
auto GetShell() -> EditorShell&
The editor's window in GG-UI: title bar, menus, the dock (EditorShell.h).
void Do(std::function<void(EditorContext&)> work)
auto Changes() const -> const GGUI::GGRevision&
Moves after each Do: a panel that shows editor state watches it.
void AskOpenScene()
Scene file commands. The ones that ask open a dialog.
void SaveScene()
void AskSaveSceneAs()
void AskSavePrefab()
void SaveAll()
Save the scene and every open document (prefab, widget asset) that has changes.
auto UnsavedDocuments(bool bDocuments) const -> std::vector<UnsavedDocument>
The scene, if unsaved, and with bDocuments every open document that is.
void AfterUnsaved(bool bDocuments, std::function<void()> then)
void AnswerUnsaved(int choice, std::vector<uint64_t> keys)
The shell's question was answered: 0 save keys and go on, 1 go on without saving, 2 stay.
void AnswerRecovery(bool bRestore)
void FrameSelection()
Commands on the selected entities.
void DuplicateSelection()
copies in the same places, selected
void DropSelectionToFloor()
each down until it rests on what is below it
void SelectEntities(const std::vector<EntityHandle>& entities, SelectMode mode)
Change the entity selection. The last one named becomes the one panels show.

Public variables

bool bPIEStopRequested

Function documentation

void EditorContext::BuildFrame()

The editor's frame: posted work, the scene view, panels, play sessions. Encoder, before the frame is recorded.

void EditorContext::LoadScene(const std::string& path, bool bReset = true)

Load a scene file: reset registry, spawn entities, update editor state. If bReset is false, skips ResetRegistry (used for initial load into an empty world).

void EditorContext::OpenConstructEditor(const char* typeName, const char* filePath = nullptr)

Open the Construct editor and create/focus a tab for the given type name. filePath is the absolute path to the header — when provided the doc is parsed from disk.

void EditorContext::OpenEntityEditor(const char* typeName, const char* filePath = nullptr)

Open the Entity editor and create/focus a tab for the given type name. filePath is the absolute path to the header — when provided the doc is parsed from disk.

void EditorContext::OpenPrefabEditor(const std::string& filePath)

Open the Prefab editor and create/focus a tab for the given .tnxprefab file. Switches to the Asset workspace automatically.

void EditorContext::PushCommand(std::unique_ptr<UndoCommand> cmd, const char* name)

Record an already-applied edit. Joins the open transaction (an interaction or an explicit scope); otherwise it becomes its own transaction named name.

void EditorContext::BeginInteraction(const char* name)

Open a transaction for a widget or gizmo interaction. It stays open while an edit or a gizmo drag goes on, and closes at the end of the first frame where neither does, so a whole drag or typed entry is one undo step. No-op if an interaction is already open.

void EditorContext::Do(std::function<void(EditorContext&)> work)

For handlers in editor panels, which run in the UI update where the editor and the engine aren't theirs to change: work runs on Encoder before the next frame, then Changes() moves so the panels that watch it show the result. Any thread. ui.Button("Editor.Scene.Save", [editor] { editor->Do([](EditorContext& editor) { editor.SaveScene(); }); });

void EditorContext::AfterUnsaved(bool bDocuments, std::function<void()> then)

Run then once nothing unsaved is in its way: at once if nothing is, otherwise after the user has saved it or let it go (the shell asks); not at all if they cancel. bDocuments: open prefabs and widget assets count too, as when leaving the editor.

void EditorContext::AnswerRecovery(bool bRestore)

The answer to the recovery offer at start: restore what the last session left unsaved, or let it go.

void EditorContext::FrameSelection()

Commands on the selected entities.

the editor camera backs off until they fill the view