1- export class PolyglotFontSettings extends FormApplication {
2- /**
3- * Default Options for this FormApplication
4- */
5- static get defaultOptions ( ) {
1+ const { ApplicationV2, HandlebarsApplicationMixin } = foundry . applications . api ;
2+
3+ export class PolyglotFontSettings extends HandlebarsApplicationMixin ( ApplicationV2 ) {
4+ static get classes ( ) {
65 const classes = [ "sheet" , "polyglot" , "polyglot-font-settings" ] ;
7- if ( game . system . id === "wfrp4e" ) {
6+ if ( game . system ? .id === "wfrp4e" ) {
87 classes . push ( game . system . id ) ;
98 }
10- return foundry . utils . mergeObject ( super . defaultOptions , {
11- id : "polyglot-font-form" ,
12- title : "Polyglot Font Settings" ,
13- template : "./modules/polyglot/templates/FontSettings.hbs" ,
14- classes,
9+ return classes ;
10+ }
11+
12+ static DEFAULT_OPTIONS = {
13+ id : "polyglot-font-form" ,
14+ classes : this . classes ,
15+ actions : {
16+ reset : PolyglotFontSettings . reset
17+ } ,
18+ form : {
19+ handler : PolyglotFontSettings . #onSubmit,
20+ closeOnSubmit : true ,
21+ } ,
22+ position : {
1523 width : 780 ,
1624 height : 680 ,
17- closeOnSubmit : true ,
18- resizable : true ,
19- } ) ;
25+ } ,
26+ tag : "form" , // The default is "div"
27+ window : {
28+ icon : "fas fa-font" , // You can now add an icon to the header
29+ title : "Font Settings" ,
30+ contentClasses : [ "standard-form" ] ,
31+ }
32+ } ;
33+
34+ get title ( ) {
35+ return `Polyglot: ${ game . i18n . localize ( this . options . window . title ) } ` ;
2036 }
2137
22- getData ( ) {
38+ static PARTS = {
39+ form : {
40+ template : "./modules/polyglot/templates/FontSettings.hbs"
41+ } ,
42+ footer : {
43+ template : "templates/generic/form-footer.hbs" ,
44+ } ,
45+ } ;
46+
47+ _prepareContext ( ) {
2348 const fonts = game . settings . get ( "polyglot" , "Alphabets" ) ;
2449 this . fonts = { } ;
2550
@@ -35,19 +60,27 @@ export class PolyglotFontSettings extends FormApplication {
3560
3661 return {
3762 fonts : this . fonts ,
63+ buttons : [
64+ { type : "submit" , icon : "fa-solid fa-save" , label : "SETTINGS.Save" } ,
65+ { type : "reset" , action : "reset" , icon : "fa-solid fa-undo" , label : "SETTINGS.Reset" } ,
66+ ]
3867 } ;
3968 }
4069
41- async activateListeners ( html ) {
42- super . activateListeners ( html ) ;
70+ _onRender ( context , options ) {
71+ super . _onRender ( context , options ) ;
4372
4473 const changeFontSize = async ( event ) => {
74+ event . preventDefault ( ) ;
4575 if ( ! event . target . hasFocus ) return ;
4676 let size = event . target . value ;
4777 if ( event . type !== "change" ) {
48- size -= event . originalEvent . deltaY / 10 ;
78+ const multiplier = event . deltaY / Math . abs ( event . deltaY ) ; // 1 or -1
79+ const step = Number ( event . target . step ) || 10 ;
80+ size = Math . floor ( size - ( multiplier * step ) ) ;
4981 }
5082 if ( size < 50 ) return ;
83+ event . target . value = size ;
5184 const parent = event . target . parentElement ;
5285 const font = parent . previousElementSibling . textContent ;
5386 parent . nextElementSibling . nextElementSibling . nextElementSibling . style . fontSize = `${ size } %` ;
@@ -64,31 +97,30 @@ export class PolyglotFontSettings extends FormApplication {
6497 this . fonts [ font ] . logographical = event . target . checked ;
6598 } ;
6699
67- html . find ( ".alphabeticOnly" ) . on ( "change" , changeFontAlphabetic ) ;
68- html . find ( ".logographical" ) . on ( "change" , changeFontLogographical ) ;
100+ this . element . querySelectorAll ( ".alphabeticOnly" ) . forEach ( ( el ) => el . addEventListener ( "change" , changeFontAlphabetic ) ) ;
101+ this . element . querySelectorAll ( ".logographical" ) . forEach ( ( el ) => el . addEventListener ( "change" , changeFontLogographical ) ) ;
69102
70- html . find ( ".selectatr" ) . on ( "focus" , ( event ) => {
103+ this . element . querySelectorAll ( ".selectatr" ) . forEach ( ( el ) => el . addEventListener ( "focus" , ( event ) => {
71104 event . target . hasFocus = true ;
72- } ) ;
73- html . find ( ".selectatr" ) . on ( "blur" , ( event ) => {
105+ } ) ) ;
106+ this . element . querySelectorAll ( ".selectatr" ) . forEach ( ( el ) => el . addEventListener ( "blur" , ( event ) => {
74107 event . target . hasFocus = false ;
75- } ) ;
76- html . find ( ".selectatr" ) . on ( "change" , changeFontSize ) ;
77- html . find ( ".selectatr" ) . on ( "wheel" , changeFontSize ) ;
78- html . find ( "button" ) . on ( "click" , async ( event ) => {
79- if ( event . currentTarget ?. dataset ?. action === "reset" ) {
80- const defaultAlphabets = new game . polyglot . languageProvider . constructor ( ) . fonts ;
81- game . polyglot . languageProvider . fonts = defaultAlphabets ;
82- await game . settings . set ( "polyglot" , "Alphabets" , game . polyglot . languageProvider . fonts ) ;
83- const defaultCustomFontSizes = game . settings . settings . get ( "polyglot.CustomFontSizes" ) . default ;
84- await game . settings . set ( "polyglot" , "CustomFontSizes" , defaultCustomFontSizes ) ;
85- this . close ( ) ;
86- SettingsConfig . reloadConfirm ( { world : true } ) ;
87- }
88- } ) ;
108+ } ) ) ;
109+ this . element . querySelectorAll ( ".selectatr" ) . forEach ( ( el ) => el . addEventListener ( "change" , changeFontSize ) ) ;
110+ this . element . querySelectorAll ( ".selectatr" ) . forEach ( ( el ) => el . addEventListener ( "wheel" , changeFontSize ) ) ;
111+ }
112+
113+ static async reset ( ) {
114+ const defaultAlphabets = new game . polyglot . languageProvider . constructor ( ) . fonts ;
115+ game . polyglot . languageProvider . fonts = defaultAlphabets ;
116+ await game . settings . set ( "polyglot" , "Alphabets" , game . polyglot . languageProvider . fonts ) ;
117+ const defaultCustomFontSizes = game . settings . settings . get ( "polyglot.CustomFontSizes" ) . default ;
118+ await game . settings . set ( "polyglot" , "CustomFontSizes" , defaultCustomFontSizes ) ;
119+ this . close ( ) ;
120+ SettingsConfig . reloadConfirm ( { world : true } ) ;
89121 }
90122
91- async _updateObject ( ) {
123+ static async #onSubmit ( ) {
92124 const customFontSizes = { } ;
93125 for ( const [ key , font ] of Object . entries ( this . fonts ) ) {
94126 customFontSizes [ key ] = font . size ;
0 commit comments