checkpoint: commit current workspace state

This commit is contained in:
2026-04-25 16:11:01 +08:00
parent 6d43fe5a7d
commit 6002d86a7e
449 changed files with 11303 additions and 100602 deletions

View File

@@ -1,7 +1,8 @@
#include "InspectorPanel.h"
#include "Composition/EditorContext.h"
#include "State/EditorColorPickerToolState.h"
#include "Windowing/Utility/EditorUtilityWindowResultState.h"
#include "Windowing/Utility/EditorUtilityWindowRequestSink.h"
#include <XCEditor/Collections/UIEditorScrollView.h>
#include <XCEditor/Fields/UIEditorFieldStyle.h>
#include <XCEditor/Foundation/UIEditorPanelInputFilter.h>
@@ -14,6 +15,7 @@
#include <algorithm>
#include <cmath>
#include <utility>
namespace XCEngine::UI::Editor::App {
@@ -239,7 +241,6 @@ void InspectorPanel::ResetInteractionState() {
m_scrollVerticalOffset = 0.0f;
m_interactionState = {};
m_gridFrame = {};
m_lastAppliedColorPickerRevision = 0u;
ResetAddComponentButtonState();
}
@@ -554,32 +555,66 @@ void InspectorPanel::RefreshPresentation(
}
}
bool InspectorPanel::ApplyColorPickerToolValue(EditorContext& context) {
EditorColorPickerToolState& toolState = context.GetColorPickerToolState();
if (m_sceneRuntime == nullptr ||
!toolState.active ||
toolState.revision == m_lastAppliedColorPickerRevision ||
!IsEditorColorPickerToolTarget(
toolState,
bool InspectorPanel::ApplyColorPickerToolValue(
EditorContext& context,
EditorUtilityWindowResultState& utilityWindowResultState) {
const EditorUtilityWindowColorPickerResult& result =
utilityWindowResultState.colorPickerResult;
if (!result.active ||
!IsEditorUtilityWindowColorPickerResultTarget(
utilityWindowResultState,
m_subjectKey,
toolState.inspectorTarget.fieldId)) {
result.targetFieldId)) {
return false;
}
Widgets::UIEditorPropertyGridField* field =
FindMutableField(toolState.inspectorTarget.fieldId);
const bool applied = TryApplyColorPickerResult(
context,
result.targetSubjectKey,
result.targetFieldId,
result.color);
ClearEditorUtilityWindowColorPickerResult(utilityWindowResultState);
return applied;
}
bool InspectorPanel::TryApplyColorPickerValue(
std::string_view targetSubjectKey,
std::string_view targetFieldId,
const UIColor& color) {
if (m_sceneRuntime == nullptr) {
return false;
}
EditorContext* context = m_currentContext;
if (context == nullptr) {
return false;
}
return TryApplyColorPickerResult(
*context,
targetSubjectKey,
targetFieldId,
color);
}
bool InspectorPanel::TryApplyColorPickerResult(
EditorContext& context,
std::string_view targetSubjectKey,
std::string_view targetFieldId,
const UIColor& color) {
if (m_sceneRuntime == nullptr || targetSubjectKey != m_subjectKey) {
return false;
}
Widgets::UIEditorPropertyGridField* field = FindMutableField(targetFieldId);
if (field == nullptr || field->kind != Widgets::UIEditorPropertyGridFieldKind::Color) {
return false;
}
if (AreColorsEqual(field->colorValue.value, toolState.color)) {
m_lastAppliedColorPickerRevision = toolState.revision;
if (AreColorsEqual(field->colorValue.value, color)) {
return false;
}
field->colorValue.value = toolState.color;
field->colorValue.value = color;
const bool applied = ApplyChangedField(field->fieldId);
m_lastAppliedColorPickerRevision = toolState.revision;
if (!applied) {
ForceResyncPresentation(context);
return false;
@@ -590,7 +625,8 @@ bool InspectorPanel::ApplyColorPickerToolValue(EditorContext& context) {
}
void InspectorPanel::RequestColorPicker(
EditorContext& context,
EditorUtilityWindowResultState& utilityWindowResultState,
EditorUtilityWindowRequestSink& utilityRequestSink,
std::string_view fieldId) {
const Widgets::UIEditorPropertyGridField* field = FindField(fieldId);
if (field == nullptr ||
@@ -599,13 +635,15 @@ void InspectorPanel::RequestColorPicker(
return;
}
OpenEditorColorPickerToolForInspectorField(
context.GetColorPickerToolState(),
m_subjectKey,
field->fieldId,
field->colorValue.value,
field->colorValue.showAlpha);
context.RequestOpenUtilityWindow(EditorUtilityWindowKind::ColorPicker);
EditorUtilityWindowSession session = {};
session.type = EditorUtilityWindowType::ColorPicker;
session.payload = EditorUtilityWindowColorPickerPayload{
.targetSubjectKey = m_subjectKey,
.targetFieldId = field->fieldId,
.initialColor = field->colorValue.value,
.showAlpha = field->colorValue.showAlpha,
};
utilityRequestSink.Request(std::move(session));
}
void InspectorPanel::ResetAddComponentButtonState() {
@@ -615,6 +653,7 @@ void InspectorPanel::ResetAddComponentButtonState() {
void InspectorPanel::UpdateAddComponentButton(
EditorContext& context,
EditorUtilityWindowRequestSink& utilityRequestSink,
const std::vector<UIInputEvent>& inputEvents) {
if (!ShouldShowAddComponentButton()) {
ResetAddComponentButtonState();
@@ -655,7 +694,13 @@ void InspectorPanel::UpdateAddComponentButton(
if (m_addComponentButtonPressed &&
ContainsPoint(buttonRect, event.position)) {
context.RequestOpenUtilityWindow(EditorUtilityWindowKind::AddComponent);
EditorUtilityWindowSession session = {};
session.type = EditorUtilityWindowType::AddComponent;
session.payload = EditorUtilityWindowAddComponentPayload{
.targetItemId = context.GetSceneRuntime().GetSelectedItemId(),
.targetDisplayName = context.GetSceneRuntime().GetSelectedDisplayName(),
};
utilityRequestSink.Request(std::move(session));
}
m_addComponentButtonHovered = ContainsPoint(buttonRect, event.position);
@@ -724,6 +769,8 @@ bool InspectorPanel::ApplyChangedField(std::string_view fieldId) {
void InspectorPanel::Update(
EditorContext& context,
EditorUtilityWindowResultState& utilityWindowResultState,
EditorUtilityWindowRequestSink& utilityRequestSink,
const UIEditorHostedPanelDispatchEntry& dispatchEntry,
const std::vector<UIInputEvent>& inputEvents) {
if (!dispatchEntry.mounted) {
@@ -734,6 +781,7 @@ void InspectorPanel::Update(
m_visible = true;
m_bounds = dispatchEntry.bounds;
m_sceneRuntime = &context.GetSceneRuntime();
m_currentContext = &context;
m_textMeasurer = context.GetShellServices().textMeasurer;
m_subject = BuildInspectorSubject(context.GetSession(), context.GetSceneRuntime());
@@ -745,7 +793,7 @@ void InspectorPanel::Update(
}
RefreshPresentation(context, subjectChanged);
ApplyColorPickerToolValue(context);
ApplyColorPickerToolValue(context, utilityWindowResultState);
const std::vector<UIInputEvent> filteredEvents =
BuildUIEditorPanelInputEvents(
@@ -814,7 +862,10 @@ void InspectorPanel::Update(
m_gridFrame.result = interactionFrame.result;
if (interactionFrame.result.pickerRequested &&
!interactionFrame.result.requestedFieldId.empty()) {
RequestColorPicker(context, interactionFrame.result.requestedFieldId);
RequestColorPicker(
utilityWindowResultState,
utilityRequestSink,
interactionFrame.result.requestedFieldId);
}
if (interactionFrame.result.fieldValueChanged &&
@@ -828,7 +879,7 @@ void InspectorPanel::Update(
}
RebuildScrollableLayout();
UpdateAddComponentButton(context, filteredEvents);
UpdateAddComponentButton(context, utilityRequestSink, filteredEvents);
}
void InspectorPanel::Append(UIDrawList& drawList) const {
@@ -996,3 +1047,16 @@ UIEditorHostCommandDispatchResult InspectorPanel::DispatchEditCommand(
}
} // namespace XCEngine::UI::Editor::App