| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | import LayerConfig from "./ThemeConfig/LayerConfig" | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  | import { UIEventSource } from "../Logic/UIEventSource" | 
					
						
							| 
									
										
										
										
											2023-04-07 03:54:11 +02:00
										 |  |  | import UserRelatedState from "../Logic/State/UserRelatedState" | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  | import { Utils } from "../Utils" | 
					
						
							| 
									
										
										
										
											2024-01-11 04:00:56 +01:00
										 |  |  | import Zoomcontrol from "../UI/Zoomcontrol" | 
					
						
							| 
									
										
										
										
											2024-08-29 02:46:51 +02:00
										 |  |  | import { LocalStorageSource } from "../Logic/Web/LocalStorageSource" | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-29 02:46:51 +02:00
										 |  |  | export type PageType = (typeof MenuState.pageNames)[number] | 
					
						
							| 
									
										
										
										
											2023-05-17 13:21:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Indicates if a menu is open, and if so, which tab is selected; | 
					
						
							|  |  |  |  * Some tabs allow to highlight an element. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Some convenience methods are provided for this as well | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export class MenuState { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-18 15:44:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-29 02:46:51 +02:00
										 |  |  |     public static readonly pageNames = [ | 
					
						
							|  |  |  |         "copyright", "copyright_icons", "community_index", "hotkeys", | 
					
						
							|  |  |  |         "privacy", "filter", "background", "about_theme", "download", "favourites", | 
					
						
							| 
									
										
										
										
											2024-08-31 15:36:52 +02:00
										 |  |  |         "usersettings", "share", "menu" | 
					
						
							| 
									
										
										
										
											2024-08-29 02:46:51 +02:00
										 |  |  |     ] as const | 
					
						
							| 
									
										
										
										
											2024-06-27 03:39:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-31 15:41:43 +02:00
										 |  |  |     public readonly menuIsOpened  | 
					
						
							| 
									
										
										
										
											2024-08-29 02:46:51 +02:00
										 |  |  |     public readonly pageStates: Record<PageType, UIEventSource<boolean>> | 
					
						
							| 
									
										
										
										
											2023-06-07 02:42:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |     public readonly highlightedLayerInFilters: UIEventSource<string> = new UIEventSource<string>( | 
					
						
							|  |  |  |         undefined | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2023-04-07 02:13:57 +02:00
										 |  |  |     public highlightedUserSetting: UIEventSource<string> = new UIEventSource<string>(undefined) | 
					
						
							| 
									
										
										
										
											2023-06-07 02:42:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-29 02:46:51 +02:00
										 |  |  |     constructor(shouldShowWelcomeMessage: boolean, themeid: string) { | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  |         // Note: this class is _not_ responsible to update the Hash, @see ThemeViewStateHashActor for this
 | 
					
						
							| 
									
										
										
										
											2024-08-29 02:46:51 +02:00
										 |  |  |         const states = {} | 
					
						
							|  |  |  |         for (const pageName of MenuState.pageNames) { | 
					
						
							|  |  |  |             const toggle = new UIEventSource(false) | 
					
						
							|  |  |  |             states[pageName] = toggle | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-29 02:46:51 +02:00
										 |  |  |             toggle.addCallback(enabled => { | 
					
						
							|  |  |  |                 if (enabled) { | 
					
						
							|  |  |  |                     this.menuIsOpened.set(false) | 
					
						
							| 
									
										
										
										
											2024-01-11 04:00:56 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-08-29 02:46:51 +02:00
										 |  |  |         this.pageStates = <Record<PageType, UIEventSource<boolean>>>states | 
					
						
							| 
									
										
										
										
											2024-08-31 15:41:43 +02:00
										 |  |  | this.menuOsOpened = this.pageStates.menu | 
					
						
							| 
									
										
										
										
											2024-08-29 02:46:51 +02:00
										 |  |  |         const visitedBefore = LocalStorageSource.GetParsed<boolean>( | 
					
						
							|  |  |  |             themeid + "thememenuisopened", false | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         if (!visitedBefore.data && shouldShowWelcomeMessage) { | 
					
						
							|  |  |  |             this.pageStates.about_theme.set(true) | 
					
						
							|  |  |  |             visitedBefore.set(true) | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-01-11 04:00:56 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private resetZoomIfAllClosed() { | 
					
						
							|  |  |  |         if (this.isSomethingOpen()) { | 
					
						
							|  |  |  |             return | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         Zoomcontrol.resetzoom() | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-06-07 02:42:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |     public openFilterView(highlightLayer?: LayerConfig | string) { | 
					
						
							| 
									
										
										
										
											2024-08-29 02:46:51 +02:00
										 |  |  |         this.pageStates.filter.setData(true) | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |         if (highlightLayer) { | 
					
						
							|  |  |  |             if (typeof highlightLayer !== "string") { | 
					
						
							|  |  |  |                 highlightLayer = highlightLayer.id | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             this.highlightedLayerInFilters.setData(highlightLayer) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-07 02:13:57 +02:00
										 |  |  |     public openUsersettings(highlightTagRendering?: string) { | 
					
						
							| 
									
										
										
										
											2023-04-07 03:54:11 +02:00
										 |  |  |         if ( | 
					
						
							|  |  |  |             highlightTagRendering !== undefined && | 
					
						
							|  |  |  |             !UserRelatedState.availableUserSettingsIds.some((tr) => tr === highlightTagRendering) | 
					
						
							|  |  |  |         ) { | 
					
						
							|  |  |  |             console.error( | 
					
						
							|  |  |  |                 "No tagRendering with id '" + highlightTagRendering + "'; maybe you meant:", | 
					
						
							|  |  |  |                 Utils.sortedByLevenshteinDistance( | 
					
						
							|  |  |  |                     highlightTagRendering, | 
					
						
							|  |  |  |                     UserRelatedState.availableUserSettingsIds, | 
					
						
							|  |  |  |                     (x) => x | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-04-07 02:13:57 +02:00
										 |  |  |         this.highlightedUserSetting.setData(highlightTagRendering) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-11 04:00:56 +01:00
										 |  |  |     public isSomethingOpen(): boolean { | 
					
						
							| 
									
										
										
										
											2024-08-29 02:46:51 +02:00
										 |  |  |         return Object.values(this.pageStates).some((t) => t.data) | 
					
						
							| 
									
										
										
										
											2024-01-11 04:00:56 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-07 02:42:49 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Close all floatOvers. | 
					
						
							|  |  |  |      * Returns 'true' if at least one menu was opened | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public closeAll(): boolean { | 
					
						
							| 
									
										
										
										
											2024-08-29 02:46:51 +02:00
										 |  |  |         for (const key in this.pageStates) { | 
					
						
							|  |  |  |             const toggle = this.pageStates[key] | 
					
						
							|  |  |  |             const wasOpen = toggle.data | 
					
						
							|  |  |  |             toggle.setData(false) | 
					
						
							|  |  |  |             if (wasOpen) { | 
					
						
							|  |  |  |                 return true | 
					
						
							| 
									
										
										
										
											2023-12-20 02:50:08 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-08-29 02:46:51 +02:00
										 |  |  |         if (this.menuIsOpened.data) { | 
					
						
							|  |  |  |             this.menuIsOpened.set(false) | 
					
						
							|  |  |  |             return true | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-08-29 02:46:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | } |