11import { GlobalContext } from "./context" ;
2+ import { TooltipManager } from "./graphics/renderables/tooltip_manager" ;
23import { deselectElement } from "./types/viewportManager" ;
3- import { Colors } from "./utils" ;
4+ import { Colors } from "./utils/utils " ;
45
56export class ConfigModal {
67 private ctx : GlobalContext ;
@@ -11,6 +12,9 @@ export class ConfigModal {
1112 private colorPicker : HTMLInputElement | null ;
1213 private selectedColor : number ; // Stores the actual selected color as a number
1314 private tempColor : number ; // Temporary color for selection
15+ private enableTooltipsSwitch : HTMLInputElement | null ;
16+ private enableTooltips : boolean ;
17+ private tempEnableTooltips : boolean ;
1418
1519 constructor ( ctx : GlobalContext ) {
1620 this . ctx = ctx ;
@@ -21,6 +25,8 @@ export class ConfigModal {
2125 this . colorPicker = null ;
2226 this . selectedColor = Colors . Violet ; // Default saved color
2327 this . tempColor = this . selectedColor ; // Temporary color for selection
28+ this . enableTooltips = true ; // Default saved value
29+ this . tempEnableTooltips = this . enableTooltips ; // Temporary value for selection
2430
2531 this . createModal ( ) ;
2632 this . setupEventListeners ( ) ;
@@ -71,28 +77,11 @@ export class ConfigModal {
7177 <input type="color" id="colorPicker">
7278 </li>
7379 <li class="setting-item">
74- <label for="autoConnections">Auto Connections</label>
75- <input type="checkbox" id="autoConnections" class="switch-input">
76- </li>
77- <li class="setting-item">
78- <label for="autoConnections">Config_1</label>
79- <input type="checkbox" id="Config_1" class="switch-input">
80- </li>
81- <li class="setting-item">
82- <label for="autoConnections">Config_2</label>
83- <input type="checkbox" id="Config_2" class="switch-input">
84- </li>
85- <li class="setting-item">
86- <label for="autoConnections">Config_3</label>
87- <input type="checkbox" id="Config_3" class="switch-input">
88- </li>
89- <li class="setting-item">
90- <label for="autoConnections">Config_4</label>
91- <input type="checkbox" id="Config_4" class="switch-input">
92- </li>
93- <li class="setting-item">
94- <label for="autoConnections">Config_5</label>
95- <input type="checkbox" id="Config_5" class="switch-input">
80+ <label for="enableTooltips">Enable Tooltips</label>
81+ <label class="switch">
82+ <input type="checkbox" id="enableTooltips" class="switch-input" checked>
83+ <span class="switch-slider"></span>
84+ </label>
9685 </li>
9786 </ul>
9887 </div>
@@ -119,6 +108,9 @@ export class ConfigModal {
119108 this . colorPicker = document . getElementById (
120109 "colorPicker" ,
121110 ) as HTMLInputElement ;
111+ this . enableTooltipsSwitch = document . getElementById (
112+ "enableTooltips" ,
113+ ) as HTMLInputElement ;
122114 }
123115
124116 private setupEventListeners ( ) {
@@ -127,7 +119,8 @@ export class ConfigModal {
127119 ! this . modalContent ||
128120 ! this . closeBtn ||
129121 ! this . saveSettingsButton ||
130- ! this . colorPicker
122+ ! this . colorPicker ||
123+ ! this . enableTooltipsSwitch
131124 ) {
132125 console . error ( "Some modal elements were not found." ) ;
133126 return ;
@@ -153,6 +146,12 @@ export class ConfigModal {
153146 this . tempColor = this . hexToNumber ( this . colorPicker . value ) ;
154147 }
155148 } ;
149+
150+ this . enableTooltipsSwitch . onchange = ( ) => {
151+ const isEnabled = this . enableTooltipsSwitch ?. checked || false ;
152+ this . tempEnableTooltips = isEnabled ; // Update the local variable only
153+ console . log ( "Tooltips setting changed (not saved yet):" , isEnabled ) ;
154+ } ;
156155 }
157156
158157 private setUpShortCuts ( ) {
@@ -187,6 +186,12 @@ export class ConfigModal {
187186 this . colorPicker . value = this . toHex ( this . selectedColor ) ;
188187 }
189188
189+ // Update tooltips setting to the saved value
190+ if ( this . enableTooltipsSwitch ) {
191+ this . tempEnableTooltips = this . enableTooltips ;
192+ this . enableTooltipsSwitch . checked = this . tempEnableTooltips ; // Reflect the saved value in the UI
193+ }
194+
190195 this . modalOverlay . style . display = "flex" ; // Make it visible first
191196 setTimeout ( ( ) => {
192197 this . modalOverlay ?. classList . add ( "show" ) ;
@@ -212,6 +217,12 @@ export class ConfigModal {
212217 }
213218 } , 300 ) ;
214219 }
220+
221+ // Reset tooltips setting to the saved value
222+ if ( this . enableTooltipsSwitch ) {
223+ this . tempEnableTooltips = this . enableTooltips ; // Reset temp value
224+ this . enableTooltipsSwitch . checked = this . enableTooltips ; // Reflect saved value in UI
225+ }
215226 }
216227
217228 private saveSettings ( ) {
@@ -221,7 +232,19 @@ export class ConfigModal {
221232 this . ctx . change_select_color ( this . selectedColor ) ;
222233 }
223234
224- console . log ( "Settings saved. Applied color:" , this . selectedColor ) ;
235+ // Save the tooltips setting
236+ if ( this . enableTooltipsSwitch ) {
237+ this . enableTooltips = this . tempEnableTooltips ; // Save the temporary value
238+ this . ctx . change_enable_tooltips ( this . enableTooltips ) ; // Update the GlobalContext
239+ TooltipManager . getInstance ( ) . updateTooltipsState ( ) ; // Update tooltips state in the app
240+ }
241+
242+ console . log (
243+ "Settings saved. Applied color:" ,
244+ this . selectedColor ,
245+ "Tooltips enabled:" ,
246+ this . enableTooltips ,
247+ ) ;
225248 }
226249
227250 // Convert a number (0xRRGGBB) to a hex string ("#RRGGBB")
0 commit comments