|
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
|
|
prepareFontAssetBatch,
|
|
|
|
|
prepareSpriteAssetBatch,
|
|
|
|
|
} from '../../features/ui-editor/importAdapter';
|
|
|
|
|
import { applyMergeResult } from '../../features/ui-editor/merge';
|
|
|
|
|
import {
|
|
|
|
|
findStateNodePageContext,
|
|
|
|
|
pageRectSize,
|
|
|
|
@@ -27,7 +26,6 @@ import { collectUiNodeIds } from '../../features/ui-editor/treeUtils';
|
|
|
|
|
import type { ChildrenDisplayMode } from '../../features/ui-editor/types/ChildrenDisplayMode';
|
|
|
|
|
import type { Component } from '../../features/ui-editor/types/Component';
|
|
|
|
|
import type { FontAssetId } from '../../features/ui-editor/types/FontAssetId';
|
|
|
|
|
import type { MergeDTO } from '../../features/ui-editor/types/MergeDTO';
|
|
|
|
|
import type { Node as UiNode } from '../../features/ui-editor/types/Node';
|
|
|
|
|
import type { NodeId } from '../../features/ui-editor/types/NodeId';
|
|
|
|
|
import type { RecognitionDTO } from '../../features/ui-editor/types/RecognitionDTO';
|
|
|
|
@@ -230,18 +228,12 @@ export function useUiEditorSession(
|
|
|
|
|
const [pendingRemoval, setPendingRemoval] =
|
|
|
|
|
useState<PendingResourceRemoval | null>(null);
|
|
|
|
|
const recognitionOperation = useUiEditorOperation();
|
|
|
|
|
const mergeOperation = useUiEditorOperation();
|
|
|
|
|
const separationOperation = useUiEditorOperation();
|
|
|
|
|
const isRecognizing = recognitionOperation.running;
|
|
|
|
|
const recognitionStatus = recognitionOperation.status;
|
|
|
|
|
const beginRecognition = recognitionOperation.begin;
|
|
|
|
|
const finishRecognition = recognitionOperation.finish;
|
|
|
|
|
const setRecognitionStatus = recognitionOperation.setStatus;
|
|
|
|
|
const isMerging = mergeOperation.running;
|
|
|
|
|
const mergeStatus = mergeOperation.status;
|
|
|
|
|
const beginMerge = mergeOperation.begin;
|
|
|
|
|
const finishMerge = mergeOperation.finish;
|
|
|
|
|
const setMergeStatus = mergeOperation.setStatus;
|
|
|
|
|
const isSeparating = separationOperation.running;
|
|
|
|
|
const separationStatus = separationOperation.status;
|
|
|
|
|
const beginSeparation = separationOperation.begin;
|
|
|
|
@@ -382,7 +374,7 @@ export function useUiEditorSession(
|
|
|
|
|
const activeImage = activeImageId ? images[activeImageId] : null;
|
|
|
|
|
const selectedSprite = selectedSpriteId ? sprites[selectedSpriteId] : null;
|
|
|
|
|
const selectedFont = selectedFontId ? fonts[selectedFontId] : null;
|
|
|
|
|
const isAiRunning = isRecognizing || isMerging || isSeparating;
|
|
|
|
|
const isAiRunning = isRecognizing || isSeparating;
|
|
|
|
|
const isWorkflowBusy =
|
|
|
|
|
isAiRunning || isSaving || isGenerating || isLoading || editor.isLocked;
|
|
|
|
|
const stateSignature = JSON.stringify(editor.state);
|
|
|
|
@@ -974,33 +966,6 @@ export function useUiEditorSession(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function mergeUi() {
|
|
|
|
|
// TODO: This experimental operation is intentionally outside the formal workflow.
|
|
|
|
|
if (isMerging || isWorkflowBusy) return;
|
|
|
|
|
setMergeStatus(null);
|
|
|
|
|
beginMerge();
|
|
|
|
|
try {
|
|
|
|
|
await editor.runWithStateLocked(async (snapshot) => {
|
|
|
|
|
const result = await invoke<MergeDTO>('merge_ui', { state: snapshot });
|
|
|
|
|
const nextState = applyMergeResult(snapshot, result);
|
|
|
|
|
const mergedTrees = nextState.ui_trees;
|
|
|
|
|
nextState.ui_trees = [];
|
|
|
|
|
for (const tree of mergedTrees) {
|
|
|
|
|
nextState.ui_trees.push(
|
|
|
|
|
createTree(nextState, tree.src_ui_design, tree.root),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
editor.replaceState(nextState);
|
|
|
|
|
setSelectedNodeId(null);
|
|
|
|
|
setMergeStatus('已生成合并后的单棵界面树。');
|
|
|
|
|
});
|
|
|
|
|
} catch (cause) {
|
|
|
|
|
setMergeStatus(cause instanceof Error ? cause.message : String(cause));
|
|
|
|
|
} finally {
|
|
|
|
|
finishMerge();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function runSeparationWorkflow() {
|
|
|
|
|
if (!resourceId || isWorkflowBusy) return;
|
|
|
|
|
beginSeparation();
|
|
|
|
@@ -1494,14 +1459,11 @@ export function useUiEditorSession(
|
|
|
|
|
selectedNodeId,
|
|
|
|
|
focusRequest,
|
|
|
|
|
operations: {
|
|
|
|
|
isMerging,
|
|
|
|
|
isRecognizing,
|
|
|
|
|
mergeStatus,
|
|
|
|
|
recognitionStatus,
|
|
|
|
|
},
|
|
|
|
|
checkPrerequisites,
|
|
|
|
|
separateUi,
|
|
|
|
|
mergeUi,
|
|
|
|
|
recognizeUi,
|
|
|
|
|
openImporter: setImportKind,
|
|
|
|
|
selectDesignImage,
|
|
|
|
|