-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
225 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/core/render/canvas2d/entityRenderer/EntityDetailsButtonRenderer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { MouseLocation } from "../../../MouseLocation"; | ||
import { NumberFunctions } from "../../../algorithm/numberFunctions"; | ||
import { Vector } from "../../../dataStruct/Vector"; | ||
import { Camera } from "../../../stage/Camera"; | ||
import { Entity } from "../../../stageObject/StageObject"; | ||
import { StageStyleManager } from "../../../stageStyle/StageStyleManager"; | ||
import { RenderUtils } from "../RenderUtils"; | ||
import { Renderer } from "../renderer"; | ||
/** | ||
* 仅仅渲染一个节点右上角的按钮 | ||
*/ | ||
export function EntityDetailsButtonRenderer(entity: Entity) { | ||
if (!entity.details) { | ||
return; | ||
} | ||
// RenderUtils.renderRect( | ||
// entity.detailsButtonRectangle().transformWorld2View(), | ||
// StageStyleManager.currentStyle.DetailsDebugTextColor, | ||
// StageStyleManager.currentStyle.DetailsDebugTextColor, | ||
// 2 * Camera.currentScale, | ||
// Renderer.NODE_ROUNDED_RADIUS * Camera.currentScale, | ||
// ); | ||
let isMouseHovering = false; | ||
// 鼠标悬浮在按钮上提示文字 | ||
if ( | ||
entity | ||
.detailsButtonRectangle() | ||
.isPointIn(Renderer.transformView2World(MouseLocation.vector())) | ||
) { | ||
isMouseHovering = true; | ||
if (!entity.isEditingDetails) | ||
// 鼠标悬浮在这上面 | ||
RenderUtils.renderText( | ||
"点击展开或关闭节点注释详情", | ||
Renderer.transformWorld2View( | ||
entity.detailsButtonRectangle().topCenter.subtract(new Vector(0, 12)), | ||
), | ||
12 * Camera.currentScale, | ||
StageStyleManager.currentStyle.DetailsDebugTextColor, | ||
); | ||
} | ||
RenderUtils.renderText( | ||
entity.isEditingDetails ? "✏️" : "📃", | ||
Renderer.transformWorld2View(entity.detailsButtonRectangle().leftTop), | ||
isMouseHovering ? getFontSizeByTime() : 20 * Camera.currentScale, | ||
); | ||
} | ||
|
||
function getFontSizeByTime() { | ||
const r = NumberFunctions.sinNumberByTime(19, 21, 0.25); | ||
return r * Camera.currentScale; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React from "react"; | ||
import Button from "../components/ui/Button"; | ||
import Input from "../components/ui/Input"; | ||
import { editTextNodeHookGlobal } from "../core/controller/concrete/utilsControl"; | ||
import { Controller } from "../core/controller/Controller"; | ||
import { Entity } from "../core/stageObject/StageObject"; | ||
import { cn } from "../utils/cn"; | ||
import IconButton from "../components/ui/IconButton"; | ||
import { ArrowLeftFromLine, ArrowRightFromLine } from "lucide-react"; | ||
|
||
export default function DetailsEditSidePanel() { | ||
const [inputCurrentDetails, setInputCurrentDetails] = React.useState(""); | ||
const [isNodeTextEditing, setIsNodeTextEditing] = React.useState(false); | ||
const [clickedNode, setClickedNode] = React.useState<Entity>(); | ||
const setInputCurrentDetailsHandler = (value: string) => { | ||
setInputCurrentDetails(value); | ||
}; | ||
const handleConfirmDetailsEdit = () => { | ||
setIsNodeTextEditing(false); | ||
if (clickedNode) { | ||
editTextNodeHookGlobal.hookFunctionEnd(clickedNode); | ||
} else { | ||
console.warn("没有点击节点"); | ||
} | ||
}; | ||
const handleCancelDetailsEdit = () => { | ||
setIsNodeTextEditing(false); | ||
Controller.isCameraLocked = false; | ||
if (clickedNode) { | ||
clickedNode.isEditingDetails = false; | ||
} | ||
}; | ||
editTextNodeHookGlobal.hookFunctionStart = (entity: Entity) => { | ||
setInputCurrentDetails(entity.details); | ||
setClickedNode(entity); | ||
setIsNodeTextEditing(true); | ||
}; | ||
editTextNodeHookGlobal.hookFunctionEnd = (entity: Entity) => { | ||
entity.changeDetails(inputCurrentDetails); | ||
Controller.isCameraLocked = false; | ||
entity.isEditingDetails = false; | ||
}; | ||
|
||
const [isFullScreen, setIsFullScreen] = React.useState(false); | ||
// 将整个面板侧向伸展成全屏或缩小到原来的尺寸 | ||
const switchPanelSize = () => { | ||
setIsFullScreen(!isFullScreen); | ||
}; | ||
return ( | ||
<> | ||
{ | ||
<div | ||
className={cn( | ||
"fixed top-0 z-50 flex h-full flex-col transition-all", | ||
isFullScreen ? "right-0 w-full" : "-right-96 w-96", | ||
isNodeTextEditing && "right-0", | ||
)} | ||
> | ||
{/* 顶部空白 */} | ||
<div className="h-16" /> | ||
<div className="flex gap-2"> | ||
<IconButton onClick={switchPanelSize}> | ||
{isFullScreen ? <ArrowRightFromLine /> : <ArrowLeftFromLine />} | ||
</IconButton> | ||
<Button className="flex-1">编辑模式</Button> | ||
<Button onClick={handleConfirmDetailsEdit}>确认修改</Button> | ||
{/* 取消,关闭 */} | ||
<Button onClick={handleCancelDetailsEdit}>取消修改</Button> | ||
</div> | ||
<Input | ||
multiline | ||
onChange={setInputCurrentDetailsHandler} | ||
value={inputCurrentDetails} | ||
className="my-2 flex-1" | ||
enableFocusOpacity={false} | ||
/> | ||
{/* 底部空白 */} | ||
<div className="h-8" /> | ||
</div> | ||
} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters