Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | import React, { FC, useMemo } from "react"; import { actorSelectors, sceneSelectors, } from "store/features/entities/entitiesState"; import editorActions from "store/features/editor/editorActions"; import { FlatList } from "ui/lists/FlatList"; import { EntityListItem } from "ui/lists/EntityListItem"; import useDimensions from "react-cool-dimensions"; import styled from "styled-components"; import { SplitPaneHeader } from "ui/splitpane/SplitPaneHeader"; import l10n from "shared/lib/lang/l10n"; import { useAppDispatch, useAppSelector } from "store/hooks"; import { Button } from "ui/buttons/Button"; import { actorName, sceneName } from "shared/lib/entities/entitiesHelpers"; import { ActorNormalized, SceneNormalized, } from "shared/lib/entities/entitiesTypes"; interface ActorPrefabUsesListProps { id: string; onClose?: () => void; } const UsesWrapper = styled.div` position: absolute; top: 38px; left: 0; bottom: 0; right: 0; width: 100%; `; const UseMessage = styled.div` padding: 5px 10px; font-size: 11px; `; export type ActorPrefabUse = { id: string; name: string; } & ( | { type: "scene"; sceneId: string; scene: SceneNormalized; sceneIndex: number; } | { type: "actor"; actor: ActorNormalized; actorIndex: number; sceneId: string; scene: SceneNormalized; sceneIndex: number; } ); export const ActorPrefabUsesList: FC<ActorPrefabUsesListProps> = ({ id, onClose, }) => { const { observe, height } = useDimensions(); const scenes = useAppSelector(sceneSelectors.selectAll); const actorsLookup = useAppSelector(actorSelectors.selectEntities); // const [prefabUses, setPrefabUses] = useState<ActorPrefabUse[]>([]); const prefabUses: ActorPrefabUse[] = useMemo(() => { const uses: ActorPrefabUse[] = []; for (let sceneIndex = 0; sceneIndex < scenes.length; sceneIndex++) { const scene = scenes[sceneIndex]; const sceneUses: ActorPrefabUse[] = []; for (let actorIndex = 0; actorIndex < scene.actors.length; actorIndex++) { const actorId = scene.actors[actorIndex]; const actor = actorsLookup[actorId]; Iif (actor?.prefabId === id) { const numChanges = Object.keys(actor.prefabScriptOverrides).length; sceneUses.push({ type: "actor", id: actor.id, name: numChanges === 0 ? actorName(actor, actorIndex) : `${actorName(actor, actorIndex)} (+${l10n( numChanges === 1 ? "FIELD_N_CHANGE" : "FIELD_N_CHANGES", { n: numChanges } )})`, actor, actorIndex, sceneId: scene.id, scene, sceneIndex: 0, }); } } Iif (sceneUses.length > 0) { uses.push({ type: "scene", id: scene.id, name: sceneName(scene, sceneIndex), sceneId: scene.id, scene, sceneIndex, }); uses.push(...sceneUses); } } return uses; }, [actorsLookup, id, scenes]); const dispatch = useAppDispatch(); const setSelectedId = (id: string, item: ActorPrefabUse) => { dispatch(editorActions.selectActor({ actorId: id, sceneId: item.sceneId })); dispatch(editorActions.setFocusSceneId(item.sceneId)); }; return ( <UsesWrapper ref={observe}> <SplitPaneHeader collapsed={false} onToggle={onClose} buttons={ <Button variant="transparent" size="small" onClick={onClose}> {l10n("MENU_EDIT_PREFAB")} </Button> } > {l10n("SIDEBAR_PREFAB_USES")} </SplitPaneHeader> {prefabUses.length > 0 ? ( <FlatList items={prefabUses} height={height - 30} setSelectedId={setSelectedId} children={({ item }) => { Iif (item.type === "scene") { return <EntityListItem item={item} type={item.type} />; } return <EntityListItem item={item} type={"actor"} nestLevel={1} />; }} /> ) : ( <UseMessage>{l10n("FIELD_PREFAB_NOT_USED")}</UseMessage> )} </UsesWrapper> ); }; |