11import { debugLog } from './sleek-chat-debug.js' ;
22import './settings.js' ;
33import { RecentMessageDisplay } from './recent-message-display.js' ;
4- import { updateDragAndDropState } from './drag-pos.js' ;
5- import { getDragPosition , setDragPosition } from './drag-pos.js' ;
64
75function parseDiceRanges ( ) {
86 const ranges = { } ;
@@ -30,6 +28,34 @@ function parseDiceRanges() {
3028 return ranges ;
3129}
3230
31+ export function applyChatBaseContainerOpacity ( ) {
32+ const chatBaseContainer = document . querySelector ( '.chat-base-container' ) ;
33+ const sleekChatOpacity = game . settings . get ( "sleek-chat" , "sleekChatOpacity" ) ;
34+
35+ if ( chatBaseContainer ) {
36+ // Set initial opacity to the setting value
37+ chatBaseContainer . style . opacity = sleekChatOpacity ;
38+
39+ // Add hover event listeners
40+ chatBaseContainer . addEventListener ( 'mouseenter' , ( ) => {
41+ chatBaseContainer . style . opacity = '1.0' ;
42+ debugLog ( "Chat base container opacity set to 1.0 on hover" ) ;
43+ } ) ;
44+
45+ chatBaseContainer . addEventListener ( 'mouseleave' , ( ) => {
46+ // Start fade out timer
47+ setTimeout ( ( ) => {
48+ chatBaseContainer . style . opacity = sleekChatOpacity ;
49+ debugLog ( `Chat base container opacity reset to ${ sleekChatOpacity } after mouse leave` ) ;
50+ } , game . settings . get ( "sleek-chat" , "messageFadeOutTime" ) * 1000 ) ;
51+ } ) ;
52+
53+ debugLog ( "Chat base container opacity events set up" ) ;
54+ } else {
55+ debugLog ( "Chat base container not found" ) ;
56+ }
57+ }
58+
3359function getResultClass ( result , ranges ) {
3460 if ( result >= ranges [ 0 ] . min && result <= ranges [ 0 ] . max ) {
3561 return 'fumble' ;
@@ -59,17 +85,6 @@ export function applySeeOnlyChat(seeOnlyChat) {
5985Hooks . once ( "ready" , ( ) => {
6086 const seeOnlyChat = game . settings . get ( "sleek-chat" , "seeOnlyChat" ) ;
6187 applySeeOnlyChat ( seeOnlyChat ) ;
62-
63- // Set the initial position of the sleek chat container
64- const sleekChatContainer = document . querySelector ( '.sleek-chat-container' ) ;
65- if ( sleekChatContainer ) {
66- const savedPosition = getDragPosition ( 'sleek-chat' ) ;
67- sleekChatContainer . style . left = savedPosition . left ;
68- sleekChatContainer . style . top = savedPosition . top ;
69- }
70-
71- // Initialize drag and drop
72- updateDragAndDropState ( game . settings . get ( "sleek-chat" , "enableDragAndDrop" ) ) ;
7388} ) ;
7489
7590// Function to apply navigation button hiding based on settings
@@ -126,6 +141,7 @@ export function applyNavButtonHiding() {
126141 // Observe changes in the sidebar state
127142 const observer = new MutationObserver ( ( ) => {
128143 updateButtonVisibility ( ) ;
144+ cleanupSleekChat ( ) ;
129145 } ) ;
130146
131147 observer . observe ( document . getElementById ( 'sidebar' ) , { attributes : true , attributeFilter : [ 'class' ] } ) ;
@@ -290,9 +306,10 @@ Hooks.on("renderChatLog", async (app, html, data) => {
290306 const recentMessageContainer = document . querySelector ( '.recent-message-container' ) ;
291307 const navButtonsContainer = document . querySelector ( '.nav-buttons-container' ) ;
292308 const sleekChatContainer = document . querySelector ( '.sleek-chat-container' ) ;
293-
309+ const chatBaseContainer = document . querySelector ( '.chat-base-container' ) ;
310+
294311 debugLog ( "Sidebar is collapsed:" , isCollapsed ) ;
295-
312+
296313 if ( toolbar ) {
297314 toolbar . style . display = isCollapsed ? 'flex' : 'none' ;
298315 debugLog ( "Toolbar visibility set to:" , isCollapsed ? 'flex' : 'none' ) ;
@@ -308,6 +325,9 @@ Hooks.on("renderChatLog", async (app, html, data) => {
308325 if ( sleekChatContainer ) {
309326 sleekChatContainer . style . display = isCollapsed ? 'block' : 'none' ;
310327 }
328+ if ( chatBaseContainer && isCollapsed ) {
329+ applyChatBaseContainerOpacity ( ) ;
330+ }
311331 } ;
312332
313333 updateVisibility ( ) ;
@@ -486,13 +506,12 @@ Hooks.on('ready', () => {
486506 $ ( '.sleek-chat' ) . css ( 'opacity' , sleekChatOpacity ) ;
487507 debugLog ( "Sleek Chat Opacity set to:" , sleekChatOpacity ) ;
488508
509+ applyChatBaseContainerOpacity ( ) ;
510+
489511 // Apply the dice color filter on startup
490512 const diceColorFilter = game . settings . get ( "sleek-chat" , "diceColorFilter" ) ;
491513 applyDiceColorFilter ( diceColorFilter ) ;
492514
493- // Initialize drag and drop
494- updateDragAndDropState ( game . settings . get ( "sleek-chat" , "enableDragAndDrop" ) ) ;
495-
496515 const hideAdvDisadv = game . settings . get ( "sleek-chat" , "hideAdvDisadv" ) ;
497516 if ( hideAdvDisadv ) {
498517 $ ( '#advantage-toggle' ) . hide ( ) ;
@@ -518,6 +537,16 @@ Hooks.on('ready', () => {
518537
519538} ) ;
520539
540+ function cleanupSleekChat ( ) {
541+ const existingContainers = document . querySelectorAll ( '.sleek-chat-container' ) ;
542+ if ( existingContainers . length > 1 ) {
543+ // Remove all but the most recently created container
544+ for ( let i = 0 ; i < existingContainers . length - 1 ; i ++ ) {
545+ existingContainers [ i ] . remove ( ) ;
546+ }
547+ }
548+ }
549+
521550// Function to apply dice color filter based on settings
522551export function applyDiceColorFilter ( color ) {
523552 let filter ;
0 commit comments