116 lines
3.4 KiB
C++
116 lines
3.4 KiB
C++
|
|
#include "EditorContext.h"
|
||
|
|
|
||
|
|
#include <algorithm>
|
||
|
|
#include <utility>
|
||
|
|
|
||
|
|
namespace XCEngine::UI::Editor::App {
|
||
|
|
|
||
|
|
namespace {
|
||
|
|
|
||
|
|
constexpr std::size_t kMaxConsoleEntries = 256u;
|
||
|
|
|
||
|
|
std::string ResolveViewportStatusMessage(
|
||
|
|
const UIEditorShellInteractionResult& result) {
|
||
|
|
if (result.viewportInputFrame.captureStarted) {
|
||
|
|
return "Viewport capture started.";
|
||
|
|
}
|
||
|
|
if (result.viewportInputFrame.captureEnded) {
|
||
|
|
return "Viewport capture ended.";
|
||
|
|
}
|
||
|
|
if (result.viewportInputFrame.focusGained) {
|
||
|
|
return "Viewport focused.";
|
||
|
|
}
|
||
|
|
if (result.viewportInputFrame.focusLost) {
|
||
|
|
return "Viewport focus lost.";
|
||
|
|
}
|
||
|
|
if (result.viewportInputFrame.pointerPressedInside) {
|
||
|
|
return "Viewport pointer down.";
|
||
|
|
}
|
||
|
|
if (result.viewportInputFrame.pointerReleasedInside) {
|
||
|
|
return "Viewport pointer up.";
|
||
|
|
}
|
||
|
|
if (result.viewportInputFrame.pointerMoved) {
|
||
|
|
return "Viewport pointer move.";
|
||
|
|
}
|
||
|
|
if (result.viewportInputFrame.wheelDelta != 0.0f) {
|
||
|
|
return "Viewport wheel.";
|
||
|
|
}
|
||
|
|
|
||
|
|
return {};
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace
|
||
|
|
|
||
|
|
void EditorContext::SetReadyStatus() {
|
||
|
|
SetStatus("Ready", "Old editor shell baseline loaded.");
|
||
|
|
}
|
||
|
|
|
||
|
|
void EditorContext::SetStatus(
|
||
|
|
std::string status,
|
||
|
|
std::string message) {
|
||
|
|
if (m_lastStatus != status || m_lastMessage != message) {
|
||
|
|
AppendConsoleEntry(status, message);
|
||
|
|
}
|
||
|
|
m_lastStatus = std::move(status);
|
||
|
|
m_lastMessage = std::move(message);
|
||
|
|
}
|
||
|
|
|
||
|
|
void EditorContext::UpdateStatusFromShellResult(
|
||
|
|
const UIEditorWorkspaceController& workspaceController,
|
||
|
|
const UIEditorShellInteractionResult& result) {
|
||
|
|
(void)workspaceController;
|
||
|
|
|
||
|
|
if (result.commandDispatched) {
|
||
|
|
SetStatus(
|
||
|
|
std::string(GetUIEditorCommandDispatchStatusName(result.commandDispatchResult.status)),
|
||
|
|
result.commandDispatchResult.message.empty()
|
||
|
|
? result.commandDispatchResult.displayName
|
||
|
|
: result.commandDispatchResult.message);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (result.workspaceResult.dockHostResult.layoutChanged) {
|
||
|
|
SetStatus("Layout", result.workspaceResult.dockHostResult.layoutResult.message);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (result.workspaceResult.dockHostResult.commandExecuted) {
|
||
|
|
SetStatus("Workspace", result.workspaceResult.dockHostResult.commandResult.message);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!result.viewportPanelId.empty()) {
|
||
|
|
std::string message = ResolveViewportStatusMessage(result);
|
||
|
|
if (!message.empty()) {
|
||
|
|
SetStatus(result.viewportPanelId, std::move(message));
|
||
|
|
}
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!result.menuMutation.changed) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!result.itemId.empty() && !result.menuMutation.openedPopupId.empty()) {
|
||
|
|
SetStatus("Menu", result.itemId + " opened child popup.");
|
||
|
|
} else if (!result.menuId.empty() && !result.menuMutation.openedPopupId.empty()) {
|
||
|
|
SetStatus("Menu", result.menuId + " opened.");
|
||
|
|
} else {
|
||
|
|
SetStatus("Menu", "Popup chain dismissed.");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void EditorContext::AppendConsoleEntry(
|
||
|
|
std::string channel,
|
||
|
|
std::string message) {
|
||
|
|
EditorConsoleEntry entry = {};
|
||
|
|
entry.channel = std::move(channel);
|
||
|
|
entry.message = std::move(message);
|
||
|
|
m_session.consoleEntries.push_back(std::move(entry));
|
||
|
|
if (m_session.consoleEntries.size() > kMaxConsoleEntries) {
|
||
|
|
m_session.consoleEntries.erase(m_session.consoleEntries.begin());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace XCEngine::UI::Editor::App
|