@@ -2,6 +2,7 @@ import _ from 'es-toolkit/compat'
22import { computed , onMounted , watch } from 'vue'
33
44import { useNodePricing } from '@/composables/node/useNodePricing'
5+ import { usePriceBadge } from '@/composables/node/usePriceBadge'
56import { useComputedWithWidgetWatch } from '@/composables/node/useWatchWidget'
67import { BadgePosition , LGraphBadge } from '@/lib/litegraph/src/litegraph'
78import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
@@ -12,7 +13,6 @@ import type { ComfyNodeDefImpl } from '@/stores/nodeDefStore'
1213import { useNodeDefStore } from '@/stores/nodeDefStore'
1314import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore'
1415import { NodeBadgeMode } from '@/types/nodeSource'
15- import { adjustColor } from '@/utils/colorUtil'
1616
1717/**
1818 * Add LGraphBadge to LGraphNode based on settings.
@@ -27,6 +27,7 @@ export const useNodeBadge = () => {
2727 const settingStore = useSettingStore ( )
2828 const extensionStore = useExtensionStore ( )
2929 const colorPaletteStore = useColorPaletteStore ( )
30+ const priceBadge = usePriceBadge ( )
3031
3132 const nodeSourceBadgeMode = computed (
3233 ( ) =>
@@ -118,29 +119,7 @@ export const useNodeBadge = () => {
118119 let creditsBadge
119120 const createBadge = ( ) => {
120121 const price = nodePricing . getNodeDisplayPrice ( node )
121-
122- const isLightTheme =
123- colorPaletteStore . completedActivePalette . light_theme
124- return new LGraphBadge ( {
125- text : price ,
126- iconOptions : {
127- unicode : '\ue96b' ,
128- fontFamily : 'PrimeIcons' ,
129- color : isLightTheme
130- ? adjustColor ( '#FABC25' , { lightness : 0.5 } )
131- : '#FABC25' ,
132- bgColor : isLightTheme
133- ? adjustColor ( '#654020' , { lightness : 0.5 } )
134- : '#654020' ,
135- fontSize : 8
136- } ,
137- fgColor :
138- colorPaletteStore . completedActivePalette . colors . litegraph_base
139- . BADGE_FG_COLOR ,
140- bgColor : isLightTheme
141- ? adjustColor ( '#8D6932' , { lightness : 0.5 } )
142- : '#8D6932'
143- } )
122+ return priceBadge . getCreditsBadge ( price )
144123 }
145124
146125 if ( hasDynamicPricing ) {
@@ -162,6 +141,23 @@ export const useNodeBadge = () => {
162141
163142 node . badges . push ( ( ) => creditsBadge . value )
164143 }
144+ } ,
145+ init ( ) {
146+ app . canvas . canvas . addEventListener < 'litegraph:set-graph' > (
147+ 'litegraph:set-graph' ,
148+ ( ) => {
149+ for ( const node of app . canvas . graph ?. nodes ?? [ ] )
150+ priceBadge . updateSubgraphCredits ( node )
151+ }
152+ )
153+ app . canvas . canvas . addEventListener < 'subgraph-converted' > (
154+ 'subgraph-converted' ,
155+ ( e ) => priceBadge . updateSubgraphCredits ( e . detail . subgraphNode )
156+ )
157+ } ,
158+ afterConfigureGraph ( ) {
159+ for ( const node of app . canvas . graph ?. nodes ?? [ ] )
160+ priceBadge . updateSubgraphCredits ( node )
165161 }
166162 } )
167163 } )
0 commit comments