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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | import React, { FC, useCallback, useState } from "react"; import { actorPrefabSelectors } from "store/features/entities/entitiesState"; import { DropdownButton } from "ui/buttons/DropdownButton"; import { EditableText } from "ui/form/EditableText"; import { FormContainer, FormHeader, FormRow } from "ui/form/layout/FormLayout"; import { MenuDivider, MenuItem } from "ui/menu/Menu"; import entitiesActions from "store/features/entities/entitiesActions"; import editorActions from "store/features/editor/editorActions"; import clipboardActions from "store/features/clipboard/clipboardActions"; import { ActorPrefabNormalized } from "shared/lib/entities/entitiesTypes"; import { Sidebar, SidebarColumn, SidebarColumns } from "ui/sidebars/Sidebar"; import { WorldEditor } from "./WorldEditor"; import { NoteField } from "ui/form/NoteField"; import { actorName } from "shared/lib/entities/entitiesHelpers"; import l10n from "shared/lib/lang/l10n"; import { useAppDispatch, useAppSelector } from "store/hooks"; import CachedScroll from "ui/util/CachedScroll"; import { ActorPrefabEditorProperties } from "./prefab/ActorPrefabEditorProperties"; import { ActorPrefabEditorScripts } from "./prefab/ActorPrefabEditorScripts"; import { FlexGrow } from "ui/spacing/Spacing"; import { SplitPaneHeader } from "ui/splitpane/SplitPaneHeader"; import styled from "styled-components"; import { ActorPrefabUsesList } from "./prefab/ActorPrefabUsesList"; import { CheckIcon, BlankIcon } from "ui/icons/Icons"; interface ActorPrefabEditorProps { id: string; } const FlexWrapper = styled.div` display: flex; flex-direction: column; height: 100%; `; const UsesCollapsedWrapper = styled.div` position: sticky; bottom: -1px; left: 0; right: 17px; border-top: 1px solid ${(props) => props.theme.colors.input.border}; `; export const ActorPrefabEditor: FC<ActorPrefabEditorProps> = ({ id }) => { const actorPrefabIds = useAppSelector(actorPrefabSelectors.selectIds); const prefab = useAppSelector((state) => actorPrefabSelectors.selectById(state, id) ); const index = React.useMemo( () => actorPrefabIds.indexOf(id), [actorPrefabIds, id] ); const [notesOpen, setNotesOpen] = useState<boolean>(!!prefab?.notes); const lockScriptEditor = useAppSelector( (state) => state.editor.lockScriptEditor ); const lastScriptTab = useAppSelector((state) => state.editor.lastScriptTab); const showUses = useAppSelector((state) => state.editor.showScriptUses); const dispatch = useAppDispatch(); const onChangeActorPrefabProp = useCallback( <K extends keyof ActorPrefabNormalized>( key: K, value: ActorPrefabNormalized[K] ) => { dispatch( entitiesActions.editActorPrefab({ actorPrefabId: id, changes: { [key]: value, }, }) ); }, [dispatch, id] ); const onChangeName = useCallback( (e: React.ChangeEvent<HTMLInputElement>) => onChangeActorPrefabProp("name", e.currentTarget.value), [onChangeActorPrefabProp] ); const onChangeNotes = useCallback( (e: React.ChangeEvent<HTMLTextAreaElement>) => onChangeActorPrefabProp("notes", e.currentTarget.value), [onChangeActorPrefabProp] ); const selectSidebar = () => { dispatch(editorActions.selectSidebar()); }; const onRemove = () => { Iif (prefab) { dispatch(entitiesActions.removeActorPrefab({ actorPrefabId: prefab.id })); } }; const onFetchClipboard = useCallback(() => { dispatch(clipboardActions.fetchClipboard()); }, [dispatch]); const onAddNotes = () => { setNotesOpen(true); }; const setShowUses = useCallback( (value: boolean) => { dispatch(editorActions.setShowScriptUses(value)); }, [dispatch] ); Iif (!prefab) { return <WorldEditor />; } const showNotes = prefab.notes || notesOpen; const scrollKey = `${prefab.id}_${lastScriptTab}`; return ( <Sidebar onClick={selectSidebar}> <CachedScroll key={scrollKey} cacheKey={scrollKey}> <FlexWrapper> {!lockScriptEditor && ( <FormContainer> <FormHeader variant="prefab"> <EditableText name="name" placeholder={actorName(prefab, index)} value={prefab.name || ""} onChange={onChangeName} /> <DropdownButton size="small" variant="transparent" menuDirection="right" onMouseDown={onFetchClipboard} > {!showNotes && !showUses && ( <MenuItem onClick={onAddNotes} icon={<BlankIcon />}> {l10n("FIELD_ADD_NOTES")} </MenuItem> )} {!showUses && <MenuDivider key="div-view-mode" />} <MenuItem key="view-editor" onClick={() => setShowUses(false)} icon={!showUses ? <CheckIcon /> : <BlankIcon />} > {l10n("MENU_EDIT_PREFAB")} </MenuItem> <MenuItem key="view-uses" onClick={() => setShowUses(true)} icon={showUses ? <CheckIcon /> : <BlankIcon />} > {l10n("FIELD_VIEW_PREFAB_USES")} </MenuItem> <MenuDivider /> <MenuItem onClick={onRemove} icon={<BlankIcon />}> {l10n("MENU_DELETE_PREFAB")} </MenuItem> </DropdownButton> </FormHeader> </FormContainer> )} {showUses ? ( <ActorPrefabUsesList id={id} onClose={() => setShowUses(false)} /> ) : ( <> {!lockScriptEditor && ( <SidebarColumns> {showNotes && ( <SidebarColumn> {showNotes && ( <FormContainer> <FormRow> <NoteField value={prefab.notes || ""} onChange={onChangeNotes} /> </FormRow> </FormContainer> )} </SidebarColumn> )} <ActorPrefabEditorProperties prefab={prefab} /> </SidebarColumns> )} <ActorPrefabEditorScripts prefab={prefab} /> </> )} {!showUses && ( <> <FlexGrow /> <UsesCollapsedWrapper> <SplitPaneHeader collapsed={true} onToggle={() => setShowUses(true)} borderBottom={false} > {l10n("SIDEBAR_PREFAB_USES")} </SplitPaneHeader> </UsesCollapsedWrapper> </> )} </FlexWrapper> </CachedScroll> </Sidebar> ); }; |