/*:
 * @plugindesc Adds a Font selector to the Options Window that allows the Player to choose a Font for the game.
 * @author SumRndmDde
 *
 * @param Option Name
 * @desc The name used by the Font option.
 * @default Text Font
 *
 * @param Position
 * @desc The position of the option in the Options Window.
 * Choices are: Top, Middle, Bottom
 * @default Middle
 *
 * @param == Default Font ==
 * @default
 *
 * @param Default Font Name
 * @desc The name that appears in the Options Window for the default Font.
 * @default Default
 *
 * @param == Font 1 ==
 * @default
 * 
 * @param Font 1 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 1.
 * @default
 *
 * @param Font 1 Name
 * @desc The name that appears in the Options Window for Font 1.
 * @default
 *
 * @param Font 1 Switch
 * @desc The Switch ID that must be ON for Font 1 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 2 ==
 * @default
 * 
 * @param Font 2 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 2.
 * @default
 *
 * @param Font 2 Name
 * @desc The name that appears in the Options Window for Font 2.
 * @default
 *
 * @param Font 2 Switch
 * @desc The Switch ID that must be ON for Font 2 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 3 ==
 * @default
 * 
 * @param Font 3 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 3.
 * @default
 *
 * @param Font 3 Name
 * @desc The name that appears in the Options Window for Font 3.
 * @default
 *
 * @param Font 3 Switch
 * @desc The Switch ID that must be ON for Font 3 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 4 ==
 * @default
 * 
 * @param Font 4 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 4.
 * @default
 *
 * @param Font 4 Name
 * @desc The name that appears in the Options Window for Font 4.
 * @default
 *
 * @param Font 4 Switch
 * @desc The Switch ID that must be ON for Font 4 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 5 ==
 * @default
 * 
 * @param Font 5 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 5.
 * @default
 *
 * @param Font 5 Name
 * @desc The name that appears in the Options Window for Font 5.
 * @default
 *
 * @param Font 5 Switch
 * @desc The Switch ID that must be ON for Font 5 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 6 ==
 * @default
 * 
 * @param Font 6 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 6.
 * @default
 *
 * @param Font 6 Name
 * @desc The name that appears in the Options Window for Font 6.
 * @default
 *
 * @param Font 6 Switch
 * @desc The Switch ID that must be ON for Font 6 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 7 ==
 * @default
 * 
 * @param Font 7 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 7.
 * @default
 *
 * @param Font 7 Name
 * @desc The name that appears in the Options Window for Font 7.
 * @default
 *
 * @param Font 7 Switch
 * @desc The Switch ID that must be ON for Font 7 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 8 ==
 * @default
 * 
 * @param Font 8 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 8.
 * @default
 *
 * @param Font 8 Name
 * @desc The name that appears in the Options Window for Font 8.
 * @default
 *
 * @param Font 8 Switch
 * @desc The Switch ID that must be ON for Font 8 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 9 ==
 * @default
 * 
 * @param Font 9 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 9.
 * @default
 *
 * @param Font 9 Name
 * @desc The name that appears in the Options Window for Font 9.
 * @default
 *
 * @param Font 9 Switch
 * @desc The Switch ID that must be ON for Font 9 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 10 ==
 * @default
 * 
 * @param Font 10 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 10.
 * @default
 *
 * @param Font 10 Name
 * @desc The name that appears in the Options Window for Font 10.
 * @default
 *
 * @param Font 10 Switch
 * @desc The Switch ID that must be ON for Font 10 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 11 ==
 * @default
 * 
 * @param Font 11 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 11.
 * @default
 *
 * @param Font 11 Name
 * @desc The name that appears in the Options Window for Font 11.
 * @default
 *
 * @param Font 11 Switch
 * @desc The Switch ID that must be ON for Font 11 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 12 ==
 * @default
 * 
 * @param Font 12 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 12.
 * @default
 *
 * @param Font 12 Name
 * @desc The name that appears in the Options Window for Font 12.
 * @default
 *
 * @param Font 12 Switch
 * @desc The Switch ID that must be ON for Font 12 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 13 ==
 * @default
 * 
 * @param Font 13 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 13.
 * @default
 *
 * @param Font 13 Name
 * @desc The name that appears in the Options Window for Font 13.
 * @default
 *
 * @param Font 13 Switch
 * @desc The Switch ID that must be ON for Font 13 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 14 ==
 * @default
 * 
 * @param Font 14 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 14.
 * @default
 *
 * @param Font 14 Name
 * @desc The name that appears in the Options Window for Font 14.
 * @default
 *
 * @param Font 14 Switch
 * @desc The Switch ID that must be ON for Font 14 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 15 ==
 * @default
 * 
 * @param Font 15 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 15.
 * @default
 *
 * @param Font 15 Name
 * @desc The name that appears in the Options Window for Font 15.
 * @default
 *
 * @param Font 15 Switch
 * @desc The Switch ID that must be ON for Font 15 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 16 ==
 * @default
 * 
 * @param Font 16 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 16.
 * @default
 *
 * @param Font 16 Name
 * @desc The name that appears in the Options Window for Font 16.
 * @default
 *
 * @param Font 16 Switch
 * @desc The Switch ID that must be ON for Font 16 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 17 ==
 * @default
 * 
 * @param Font 17 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 17.
 * @default
 *
 * @param Font 17 Name
 * @desc The name that appears in the Options Window for Font 17.
 * @default
 *
 * @param Font 17 Switch
 * @desc The Switch ID that must be ON for Font 17 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 18 ==
 * @default
 * 
 * @param Font 18 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 18.
 * @default
 *
 * @param Font 18 Name
 * @desc The name that appears in the Options Window for Font 18.
 * @default
 *
 * @param Font 18 Switch
 * @desc The Switch ID that must be ON for Font 18 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 19 ==
 * @default
 * 
 * @param Font 19 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 19.
 * @default
 *
 * @param Font 19 Name
 * @desc The name that appears in the Options Window for Font 19.
 * @default
 *
 * @param Font 19 Switch
 * @desc The Switch ID that must be ON for Font 19 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 20 ==
 * @default
 * 
 * @param Font 20 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 20.
 * @default
 *
 * @param Font 20 Name
 * @desc The name that appears in the Options Window for Font 20.
 * @default
 *
 * @param Font 20 Switch
 * @desc The Switch ID that must be ON for Font 20 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 21 ==
 * @default
 * 
 * @param Font 21 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 21.
 * @default
 *
 * @param Font 21 Name
 * @desc The name that appears in the Options Window for Font 21.
 * @default
 *
 * @param Font 21 Switch
 * @desc The Switch ID that must be ON for Font 21 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 22 ==
 * @default
 * 
 * @param Font 22 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 22.
 * @default
 *
 * @param Font 22 Name
 * @desc The name that appears in the Options Window for Font 22.
 * @default
 *
 * @param Font 22 Switch
 * @desc The Switch ID that must be ON for Font 22 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 23 ==
 * @default
 * 
 * @param Font 23 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 23.
 * @default
 *
 * @param Font 23 Name
 * @desc The name that appears in the Options Window for Font 23.
 * @default
 *
 * @param Font 23 Switch
 * @desc The Switch ID that must be ON for Font 23 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 24 ==
 * @default
 * 
 * @param Font 24 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 24.
 * @default
 *
 * @param Font 24 Name
 * @desc The name that appears in the Options Window for Font 24.
 * @default
 *
 * @param Font 24 Switch
 * @desc The Switch ID that must be ON for Font 24 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 25 ==
 * @default
 * 
 * @param Font 25 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 25.
 * @default
 *
 * @param Font 25 Name
 * @desc The name that appears in the Options Window for Font 25.
 * @default
 *
 * @param Font 25 Switch
 * @desc The Switch ID that must be ON for Font 25 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 26 ==
 * @default
 * 
 * @param Font 26 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 26.
 * @default
 *
 * @param Font 26 Name
 * @desc The name that appears in the Options Window for Font 26.
 * @default
 *
 * @param Font 26 Switch
 * @desc The Switch ID that must be ON for Font 26 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 27 ==
 * @default
 * 
 * @param Font 27 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 27.
 * @default
 *
 * @param Font 27 Name
 * @desc The name that appears in the Options Window for Font 27.
 * @default
 *
 * @param Font 27 Switch
 * @desc The Switch ID that must be ON for Font 27 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 28 ==
 * @default
 * 
 * @param Font 28 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 28.
 * @default
 *
 * @param Font 28 Name
 * @desc The name that appears in the Options Window for Font 28.
 * @default
 *
 * @param Font 28 Switch
 * @desc The Switch ID that must be ON for Font 28 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 29 ==
 * @default
 * 
 * @param Font 29 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 29.
 * @default
 *
 * @param Font 29 Name
 * @desc The name that appears in the Options Window for Font 29.
 * @default
 *
 * @param Font 29 Switch
 * @desc The Switch ID that must be ON for Font 29 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 30 ==
 * @default
 * 
 * @param Font 30 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 30.
 * @default
 *
 * @param Font 30 Name
 * @desc The name that appears in the Options Window for Font 30.
 * @default
 *
 * @param Font 30 Switch
 * @desc The Switch ID that must be ON for Font 30 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 31 ==
 * @default
 * 
 * @param Font 31 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 31.
 * @default
 *
 * @param Font 31 Name
 * @desc The name that appears in the Options Window for Font 31.
 * @default
 *
 * @param Font 31 Switch
 * @desc The Switch ID that must be ON for Font 31 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 32 ==
 * @default
 * 
 * @param Font 32 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 32.
 * @default
 *
 * @param Font 32 Name
 * @desc The name that appears in the Options Window for Font 32.
 * @default
 *
 * @param Font 32 Switch
 * @desc The Switch ID that must be ON for Font 32 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 33 ==
 * @default
 * 
 * @param Font 33 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 33.
 * @default
 *
 * @param Font 33 Name
 * @desc The name that appears in the Options Window for Font 33.
 * @default
 *
 * @param Font 33 Switch
 * @desc The Switch ID that must be ON for Font 33 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 34 ==
 * @default
 * 
 * @param Font 34 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 34.
 * @default
 *
 * @param Font 34 Name
 * @desc The name that appears in the Options Window for Font 34.
 * @default
 *
 * @param Font 34 Switch
 * @desc The Switch ID that must be ON for Font 34 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 35 ==
 * @default
 * 
 * @param Font 35 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 35.
 * @default
 *
 * @param Font 35 Name
 * @desc The name that appears in the Options Window for Font 35.
 * @default
 *
 * @param Font 35 Switch
 * @desc The Switch ID that must be ON for Font 35 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 36 ==
 * @default
 * 
 * @param Font 36 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 36.
 * @default
 *
 * @param Font 36 Name
 * @desc The name that appears in the Options Window for Font 36.
 * @default
 *
 * @param Font 36 Switch
 * @desc The Switch ID that must be ON for Font 36 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 37 ==
 * @default
 * 
 * @param Font 37 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 37.
 * @default
 *
 * @param Font 37 Name
 * @desc The name that appears in the Options Window for Font 37.
 * @default
 *
 * @param Font 37 Switch
 * @desc The Switch ID that must be ON for Font 37 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 38 ==
 * @default
 * 
 * @param Font 38 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 38.
 * @default
 *
 * @param Font 38 Name
 * @desc The name that appears in the Options Window for Font 38.
 * @default
 *
 * @param Font 38 Switch
 * @desc The Switch ID that must be ON for Font 38 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 39 ==
 * @default
 * 
 * @param Font 39 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 39.
 * @default
 *
 * @param Font 39 Name
 * @desc The name that appears in the Options Window for Font 39.
 * @default
 *
 * @param Font 39 Switch
 * @desc The Switch ID that must be ON for Font 39 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 40 ==
 * @default
 * 
 * @param Font 40 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 40.
 * @default
 *
 * @param Font 40 Name
 * @desc The name that appears in the Options Window for Font 40.
 * @default
 *
 * @param Font 40 Switch
 * @desc The Switch ID that must be ON for Font 40 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 41 ==
 * @default
 * 
 * @param Font 41 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 41.
 * @default
 *
 * @param Font 41 Name
 * @desc The name that appears in the Options Window for Font 41.
 * @default
 *
 * @param Font 41 Switch
 * @desc The Switch ID that must be ON for Font 41 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 42 ==
 * @default
 * 
 * @param Font 42 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 42.
 * @default
 *
 * @param Font 42 Name
 * @desc The name that appears in the Options Window for Font 42.
 * @default
 *
 * @param Font 42 Switch
 * @desc The Switch ID that must be ON for Font 42 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 43 ==
 * @default
 * 
 * @param Font 43 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 43.
 * @default
 *
 * @param Font 43 Name
 * @desc The name that appears in the Options Window for Font 43.
 * @default
 *
 * @param Font 43 Switch
 * @desc The Switch ID that must be ON for Font 43 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 44 ==
 * @default
 * 
 * @param Font 44 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 44.
 * @default
 *
 * @param Font 44 Name
 * @desc The name that appears in the Options Window for Font 44.
 * @default
 *
 * @param Font 44 Switch
 * @desc The Switch ID that must be ON for Font 44 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 45 ==
 * @default
 * 
 * @param Font 45 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 45.
 * @default
 *
 * @param Font 45 Name
 * @desc The name that appears in the Options Window for Font 45.
 * @default
 *
 * @param Font 45 Switch
 * @desc The Switch ID that must be ON for Font 45 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 46 ==
 * @default
 * 
 * @param Font 46 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 46.
 * @default
 *
 * @param Font 46 Name
 * @desc The name that appears in the Options Window for Font 46.
 * @default
 *
 * @param Font 46 Switch
 * @desc The Switch ID that must be ON for Font 46 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 47 ==
 * @default
 * 
 * @param Font 47 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 47.
 * @default
 *
 * @param Font 47 Name
 * @desc The name that appears in the Options Window for Font 47.
 * @default
 *
 * @param Font 47 Switch
 * @desc The Switch ID that must be ON for Font 47 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 48 ==
 * @default
 * 
 * @param Font 48 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 48.
 * @default
 *
 * @param Font 48 Name
 * @desc The name that appears in the Options Window for Font 48.
 * @default
 *
 * @param Font 48 Switch
 * @desc The Switch ID that must be ON for Font 48 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 49 ==
 * @default
 * 
 * @param Font 49 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 49.
 * @default
 *
 * @param Font 49 Name
 * @desc The name that appears in the Options Window for Font 49.
 * @default
 *
 * @param Font 49 Switch
 * @desc The Switch ID that must be ON for Font 49 to be accessable. Leave blank to always allow.
 * @default
 *
 * @param == Font 50 ==
 * @default
 * 
 * @param Font 50 File
 * @desc Input the file name of the Font in /fonts/ that will be Font 50.
 * @default
 *
 * @param Font 50 Name
 * @desc The name that appears in the Options Window for Font 50.
 * @default
 *
 * @param Font 50 Switch
 * @desc The Switch ID that must be ON for Font 50 to be accessable. Leave blank to always allow.
 * @default
 *
 * @help
 *
 * Font Option
 * Version 1.01
 * SumRndmDde
 *
 *
 * This Plugin adds a Font selector to the Options Window that allows 
 * the Player to choose a Font for the game.
 *
 *
 * ==============================================================================
 *  How to Set up the Images
 * ==============================================================================
 *
 * First place all of the Font files you wish to use in:
 *
 * /fonts/
 *
 * The default font file (mplus-1m-regular.ttf) should remain within the folder!
 *
 *
 * ==============================================================================
 *  How to Set up the Options
 * ==============================================================================
 *
 * Next, in order to set up the order and the names for the Fonts in the 
 * Options Menu, you must use the Parameters.
 *
 * It is manadatory that one Font at least the default font should exist!
 * Using the "Default Font Name" Parameter, you can give that font a specific
 * name when selected in the Options Menu.
 *
 *
 * Next, you can set up the choices by filling out the "Font" sections.
 * 
 * Using "Font # File", input the name of a Font file (including extension) from 
 * the fonts folder!
 *
 * Next, use "Font # Name", set the name of that Font that will be displayed
 * in the Options Menu. This will also be the name of the font that can be 
 * accessed using other plugins, so similarly, this can be used to preload
 * fonts.
 *
 *
 * Once you have filled out both Parameters for one "Font" section,
 * it will be available in the Options Menu in game.
 *
 *
 * ==============================================================================
 *  Switches
 * ==============================================================================
 *
 * If you wish for a Font option to only be available once a Switch is turned
 * ON, input the Switch's ID within the "Font # Switch" Parameter.
 *
 * Once done, that Switch must be turned ON for that Font to appear!
 *
 * Use this to create unlockable or purchasable fonts!
 *
 *
 * ==============================================================================
 *  End of Help File
 * ==============================================================================
 * 
 * Welcome to the bottom of the Help file.
 *
 *
 * Thanks for reading!
 * If you have questions, or if you enjoyed this Plugin, please check
 * out my YouTube channel!
 *
 * https://www.youtube.com/c/SumRndmDde
 *
 *
 * Until next time,
 *   ~ SumRndmDde
 *
 */

var SRD = SRD || {};
SRD.FontOption = SRD.FontOption || {};

var Imported = Imported || {};
Imported["SumRndmDde Font Option"] = 1.01;

(function(_) {

"use strict";

//-----------------------------------------------------------------------------
// SRD.FontOption
//-----------------------------------------------------------------------------

const params = PluginManager.parameters('SRD_FontOption');

_.name = String(params['Option Name']);
_.position = String(params['Position']).trim().toLowerCase();

_.defaultName = String(params['Default Font Name']);

_.index = 0;
_.lowest = 0;
_.fonts = [""];
_.names = [_.defaultName];
_.switches = [0];
for(var i = 1; i <= 50; i++) {
	var file = String(params['Font ' + i + ' File']);
	var name = String(params['Font ' + i + ' Name']);
	var swit = parseInt(params['Font ' + i + ' Switch']);
	if(file.trim().length > 0 && name.trim().length > 0) {
		_.fonts[i] = file;
		_.names[i] = name;
		Graphics.loadFont(name, 'fonts/' + file);
	}
	if(swit) _.switches[i] = swit;
}

_.fixIndex = function() {
	while((_.switches[_.index] && _.switches[_.index] != 0) && (!$gameSwitches || !$gameSwitches.value(_.switches[_.index]))) {
		_.index++;
		if(_.index > _.fonts.length - 1) _.index = 0;
	}
};

_.changeIndex = function(value) {
	_.index = Number(value).clamp(_.lowest, _.fonts.length - 1);
	while((_.switches[_.index] && _.switches[_.index] != 0) && (!$gameSwitches || !$gameSwitches.value(_.switches[_.index]))) {
		_.index++;
		if(_.index > _.fonts.length - 1) _.index = 0;
	}
};

_.refreshAllWindows = function() {
	const scene = SceneManager._scene;
	if(scene && scene._windowLayer) {
		const layer = scene._windowLayer;
		if(!layer.children) return;
		layer.children.forEach(function(win) {
			win.resetFontSettings();
			if(win.refresh) win.refresh();
		})
	}
};

//-----------------------------------------------------------------------------
// ConfigManager
//-----------------------------------------------------------------------------

Object.defineProperty(ConfigManager, 'fontStyle', {
	get: function() {
		_.fixIndex();
		return _.index;
	},
	set: function(value) {
		_.changeIndex(value);
		_.refreshAllWindows();
	},
	configurable: true
});

_.ConfigManager_makeData = ConfigManager.makeData;
ConfigManager.makeData = function() {
	var config = _.ConfigManager_makeData.call(this);
	config.fontStyle = this.fontStyle;
	return config;
};

_.ConfigManager_applyData = ConfigManager.applyData;
ConfigManager.applyData = function(config) {
	_.ConfigManager_applyData.call(this, config);
	this.fontStyle = this.readFontStyle(config, 'fontStyle');
};

ConfigManager.readFontStyle = function(config, name) {
	var value = config[name];
	if (value !== undefined) {
		return value;
	} else {
		return _.lowest;
	}
};

//-----------------------------------------------------------------------------
// Window_Base
//-----------------------------------------------------------------------------

_.Window_Base_resetFontSettings = Window_Base.prototype.resetFontSettings;
Window_Base.prototype.resetFontSettings = function() {
	_.Window_Base_resetFontSettings.apply(this, arguments);
	this.loadOptionsFont();
};

Window_Base.prototype.loadOptionsFont = function() {
	if(_.fonts[_.index]) {
		this.contents.fontFace = _.names[_.index];
	}
};

//-----------------------------------------------------------------------------
// Window_Options
//-----------------------------------------------------------------------------

_.Window_Options_addGeneralOptions = Window_Options.prototype.addGeneralOptions;
Window_Options.prototype.addGeneralOptions = function() {
	_.Window_Options_addGeneralOptions.call(this);
	if(_.position === 'middle') {
		this.addCommand(_.name, 'fontStyle');
	}
};

_.Window_Options_makeCommandList = Window_Options.prototype.makeCommandList;
Window_Options.prototype.makeCommandList = function() {
	if(_.position === 'top') {
		this.addCommand(_.name, 'fontStyle');
	}
	_.Window_Options_makeCommandList.call(this);
};

_.Window_Options_addVolumeOptions = Window_Options.prototype.addVolumeOptions;
Window_Options.prototype.addVolumeOptions = function() {
	_.Window_Options_addVolumeOptions.call(this);
	if(_.position === 'bottom') {
		this.addCommand(_.name, 'fontStyle');
	}
};

_.Window_Options_statusText = Window_Options.prototype.statusText;
Window_Options.prototype.statusText = function(index) {
	var symbol = this.commandSymbol(index);
	var value = this.getConfigValue(symbol);
	if(this.isFontSymbol(symbol)) {
		return this.fontStyleStatusText(value);
	}
	return _.Window_Options_statusText.call(this, index);
};

Window_Options.prototype.isFontSymbol = function(symbol) {
	return symbol === 'fontStyle';
};

Window_Options.prototype.fontStyleStatusText = function(value) {
	return _.names[value];
};

_.Window_Options_processOk = Window_Options.prototype.processOk;
Window_Options.prototype.processOk = function() {
	var index = this.index();
	var symbol = this.commandSymbol(index);
	var value = this.getConfigValue(symbol);
	_.Window_Options_processOk.call(this);
	if(this.isFontSymbol(symbol)) {
		value += 1;
		if(value >= _.fonts.length) value = _.lowest;
		this.changeValue(symbol, value);
	}
};

_.Window_Options_cursorRight = Window_Options.prototype.cursorRight;
Window_Options.prototype.cursorRight = function(wrap) {
	var index = this.index();
	var symbol = this.commandSymbol(index);
	var value = this.getConfigValue(symbol);
	_.Window_Options_cursorRight.call(this, wrap);
	if(this.isFontSymbol(symbol)) {
		value += 1;
		this.changeValue(symbol, value);
	}
};

_.Window_Options_cursorLeft = Window_Options.prototype.cursorLeft;
Window_Options.prototype.cursorLeft = function(wrap) {
	var index = this.index();
	var symbol = this.commandSymbol(index);
	var value = this.getConfigValue(symbol);
	_.Window_Options_cursorLeft.call(this, wrap);
	if(this.isFontSymbol(symbol)) {
		value -= 1;
		this.changeValue(symbol, value);
	}
};

})(SRD.FontOption);