@@ -3,6 +3,10 @@ import Button from "../components/Button";
33import { Dialog } from "../components/dialog" ;
44import { Color } from "../core/dataStruct/Color" ;
55import { ColorManager } from "../core/service/feedbackService/ColorManager" ;
6+ import { StageManager } from "../core/stage/stageManager/StageManager" ;
7+ import { TextNode } from "../core/stage/stageObject/entity/TextNode" ;
8+ import { Section } from "../core/stage/stageObject/entity/Section" ;
9+ import { LineEdge } from "../core/stage/stageObject/association/LineEdge" ;
610
711/**
812 * 自定义颜色设置面板
@@ -19,15 +23,29 @@ export default function ColorManagerPanel() {
1923 const [ currentColorList , setCurrentColorList ] = useState < Color [ ] > ( [ ] ) ;
2024
2125 return (
22- < div className = "h-96 w-96 bg-neutral-700 p-4" >
26+ < div className = "bg-panel-bg h-96 w-96 p-4" >
2327 < div >
24- < p > 当前颜色 :</ p >
28+ < p > 我的颜色库 :</ p >
2529 { /* <ColorDotElement color={Color.Red} /> */ }
2630 < div className = "flex flex-wrap items-center justify-center" >
2731 { currentColorList . map ( ( color ) => (
28- < ColorDotElement key = { color . toString ( ) } color = { color } />
32+ < ColorDotElement
33+ key = { color . toString ( ) }
34+ color = { color }
35+ onclick = { ( ) => {
36+ console . log ( color ) ;
37+ const rgbSharpString = color . toHexString ( ) ;
38+ if ( rgbSharpString . length === 9 ) {
39+ // 去掉透明度
40+ setPreAddColor ( rgbSharpString . slice ( 0 , 7 ) ) ;
41+ }
42+ } }
43+ />
2944 ) ) }
3045 </ div >
46+ { currentColorList . length !== 0 && (
47+ < div className = "text-panel-details-text text-center text-xs" > 提示:点击颜色可以复制颜色值到待添加颜色</ div >
48+ ) }
3149 </ div >
3250 < div >
3351 < p > 添加颜色:</ p >
@@ -60,25 +78,56 @@ export default function ColorManagerPanel() {
6078 >
6179 确认添加
6280 </ Button >
81+ < Button
82+ onClick = { ( ) => {
83+ StageManager . getSelectedStageObjects ( ) . forEach ( ( stageObject ) => {
84+ if ( stageObject instanceof TextNode ) {
85+ ColorManager . addUserEntityFillColor ( stageObject . color ) ;
86+ } else if ( stageObject instanceof Section ) {
87+ ColorManager . addUserEntityFillColor ( stageObject . color ) ;
88+ } else if ( stageObject instanceof LineEdge ) {
89+ ColorManager . addUserEntityFillColor ( stageObject . color ) ;
90+ }
91+ } ) ;
92+ } }
93+ >
94+ 将选中的节点颜色添加到库
95+ </ Button >
96+ < Button
97+ onClick = { ( ) => {
98+ ColorManager . organizeUserEntityFillColors ( ) ;
99+ } }
100+ >
101+ 一键整理颜色库
102+ </ Button >
63103 </ div >
64104 </ div >
65105 ) ;
66106}
67- function ColorDotElement ( { color } : { color : Color } ) {
107+
108+ function ColorDotElement ( { color, onclick } : { color : Color ; onclick : ( e : any ) => void } ) {
68109 const r = color . r ;
69110 const g = color . g ;
70111 const b = color . b ;
71112 const a = color . a ;
72113 return (
73- < div className = "relative m-1 h-8 w-8 rounded-full" style = { { backgroundColor : `rgba(${ r } , ${ g } , ${ b } , ${ a } )` } } >
74- < Button
75- className = "absolute -right-2 -top-2 h-2 w-2 rounded-full text-xs"
76- onClick = { ( ) => {
77- ColorManager . removeUserEntityFillColor ( color ) ;
78- } }
114+ < div className = "my-1" >
115+ < div
116+ className = "relative mx-1 h-8 min-w-8 rounded-full hover:cursor-pointer"
117+ style = { { backgroundColor : `rgba(${ r } , ${ g } , ${ b } , ${ a } )` } }
118+ onClick = { onclick }
79119 >
80- x
81- </ Button >
120+ < Button
121+ className = "absolute -right-2 -top-2 h-2 w-2 rounded-full text-xs"
122+ onClick = { ( ) => {
123+ ColorManager . removeUserEntityFillColor ( color ) ;
124+ } }
125+ tooltip = "删除"
126+ >
127+ x
128+ </ Button >
129+ </ div >
130+ < span className = "mx-0.5 cursor-text select-all rounded bg-black px-1 text-xs text-neutral-300" > { `${ r } , ${ g } , ${ b } ` } </ span >
82131 </ div >
83132 ) ;
84133}
0 commit comments