Advertisement
Kakakadafi

YEP_SaveCore

Jun 29th, 2016
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Yanfly Engine Plugins - Save Core
  3. // YEP_SaveCore.js
  4. //=============================================================================
  5.  
  6. var Imported = Imported || {};
  7. Imported.YEP_SaveCore = true;
  8.  
  9. var Yanfly = Yanfly || {};
  10. Yanfly.Save = Yanfly.Save || {};
  11.  
  12. //=============================================================================
  13.  /*:
  14.  * @plugindesc v1.02 Alter the save menu for a more aesthetic layout
  15.  * and take control over the file system's rules.
  16.  * @author Yanfly Engine Plugins
  17.  *
  18.  * @param ---General---
  19.  * @default
  20.  *
  21.  * @param Max Files
  22.  * @desc The maximum number of files for your game.
  23.  * Default: 20
  24.  * @default 24
  25.  *
  26.  * @param Saved Icon
  27.  * @desc Icon ID used for a file slot with a save.
  28.  * @default 231
  29.  *
  30.  * @param Empty Icon
  31.  * @desc Icon ID used for an empty file slot.
  32.  * @default 230
  33.  *
  34.  * @param Return After Saving
  35.  * @desc Return to the previous scene after saving?
  36.  * NO - false     YES - true     Default: true
  37.  * @default false
  38.  *
  39.  * @param Auto New Index
  40.  * @desc For new games, automatically decide the save slot?
  41.  * NO - false     YES - true     Default: true
  42.  * @default true
  43.  *
  44.  * @param ---Action Window---
  45.  * @default
  46.  *
  47.  * @param Load Command
  48.  * @desc Text for the load command in the action window.
  49.  * @default Load
  50.  *
  51.  * @param Save Command
  52.  * @desc Text for the save command in the action window.
  53.  * @default Save
  54.  *
  55.  * @param Delete Command
  56.  * @desc Text for the delete command in the action window.
  57.  * @default Delete
  58.  *
  59.  * @param ---Help Window---
  60.  * @default
  61.  *
  62.  * @param Select Help
  63.  * @desc Help text displayed when selecting a slot.
  64.  * @default Please select a file slot.
  65.  *
  66.  * @param Load Help
  67.  * @desc Help text displayed when selecting load option.
  68.  * @default Loads the data from the saved game.
  69.  *
  70.  * @param Save Help
  71.  * @desc Help text displayed when selecting save option.
  72.  * @default Saves the current progress in your game.
  73.  *
  74.  * @param Delete Help
  75.  * @desc Help text displayed when selecting delete option.
  76.  * @default Deletes all data from this save file.
  77.  *
  78.  * @param ---Delete---
  79.  * @default
  80.  *
  81.  * @param Delete Filename
  82.  * @desc Used for the delete sound from the /audio/se/ folder.
  83.  * Do NOT include the file extension.
  84.  * @default Damage2
  85.  *
  86.  * @param Delete Volume
  87.  * @desc Volume used for the delete sound.
  88.  * @default 100
  89.  *
  90.  * @param Delete Pitch
  91.  * @desc Pitch used for the delete sound.
  92.  * @default 150
  93.  *
  94.  * @param Delete Pan
  95.  * @desc Pan used for the delete sound.
  96.  * @default 0
  97.  *
  98.  * @param ---Info Window---
  99.  * @default
  100.  *
  101.  * @param Show Game Title
  102.  * @desc Display the game title in the save file?
  103.  * NO - false     YES - true
  104.  * @default true
  105.  *
  106.  * @param Invalid Game Text
  107.  * @desc Text used when the save is for a different game.
  108.  * @default This save is for a different game.
  109.  *
  110.  * @param Empty Game Text
  111.  * @desc Text used when the save is empty.
  112.  * @default Empty
  113.  *
  114.  * @param Party Display
  115.  * @desc The display type used for the party.
  116.  * 0 - None; 1 - Characters; 2 - Faces; 3 - SV Actors
  117.  * @default 2
  118.  *
  119.  * @param Party Y Position
  120.  * @desc This is the base Y position for the party display.
  121.  * Formulas can be used.
  122.  * @default this.lineHeight() + Window_Base._faceHeight
  123.  *
  124.  * @param Show Actor Names
  125.  * @desc Display the names of the actors?
  126.  * NO - false     YES - true
  127.  * @default true
  128.  *
  129.  * @param Name Font Size
  130.  * @desc Font size used for names if names are displayed.
  131.  * Default: 28
  132.  * @default 20
  133.  *
  134.  * @param Show Actor Level
  135.  * @desc Display the levels of the actors?
  136.  * NO - false     YES - true
  137.  * @default true
  138.  *
  139.  * @param Level Font Size
  140.  * @desc Font size used for levels if levels are displayed.
  141.  * Default: 28
  142.  * @default 20
  143.  *
  144.  * @param Level Format
  145.  * @desc The text format used to display levels.
  146.  * %1 - Lv (Abbr)   %2 - Lv (Full)     %3 - Value
  147.  * @default \c[16]%1 \c[0]%3
  148.  *
  149.  * @param Data Font Size
  150.  * @desc Font size used for displaying data.
  151.  * Default: 28
  152.  * @default 20
  153.  *
  154.  * @param Data Column 1
  155.  * @desc The data to be displayed in data column 1. Refer to help
  156.  * file for data entries. Separate each entry with commas.
  157.  * @default empty, playtime, save count, gold count
  158.  *
  159.  * @param Data Column 2
  160.  * @desc The data to be displayed in data column 2. Refer to help
  161.  * file for data entries. Separate each entry with commas.
  162.  * @default location, variable 1, variable 2, variable 3
  163.  *
  164.  * @param Data Column 3
  165.  * @desc The data to be displayed in data column 2. Refer to help
  166.  * file for data entries. Separate each entry with commas.
  167.  * @default empty, variable 4, variable 5, variable 6
  168.  *
  169.  * @param Data Column 4
  170.  * @desc The data to be displayed in data column 2. Refer to help
  171.  * file for data entries. Separate each entry with commas.
  172.  * @default
  173.  *
  174.  * @param ---Vocabulary---
  175.  * @default
  176.  *
  177.  * @param Map Location
  178.  * @desc Text used to categorize 'Map Location'.
  179.  * Leave empty to not use this category and center the data.
  180.  * @default
  181.  *
  182.  * @param Playtime
  183.  * @desc Text used to categorize 'Playtime'.
  184.  * Leave empty to not use this category and center the data.
  185.  * @default Playtime:
  186.  *
  187.  * @param Save Count
  188.  * @desc Text used to categorize 'Save Count'.
  189.  * Leave empty to not use this category and center the data.
  190.  * @default Total Saves:
  191.  *
  192.  * @param Gold Count
  193.  * @desc Text used to categorize 'Gold Count'.
  194.  * Leave empty to not use this category and center the data.
  195.  * @default %1:
  196.  *
  197.  * @param ---Technical---
  198.  * @default
  199.  *
  200.  * @param Save Mode
  201.  * @desc How the save system should work for your game:
  202.  * local     web     auto
  203.  * @default auto
  204.  *
  205.  * @param Local Config
  206.  * @desc Filename for config when working with local saves.
  207.  * Default: config.rpgsave
  208.  * @default config.rpgsave
  209.  *
  210.  * @param Local Global
  211.  * @desc Filename for global when working with local saves.
  212.  * Default: global.rpgsave
  213.  * @default global.rpgsave
  214.  *
  215.  * @param Local Save
  216.  * @desc Filename for game saves when working with local saves.
  217.  * %1 - File Slot. Default: config.rpgsave
  218.  * @default file%1.rpgsave
  219.  *
  220.  * @param Web Config
  221.  * @desc Filename for config when working with web saves.
  222.  * %1 - Game Name. Default: RPG Config
  223.  * @default RPG %1 Config
  224.  *
  225.  * @param Web Global
  226.  * @desc Filename for global when working with web saves.
  227.  * %1 - Game Name. Default: RPG Global
  228.  * @default RPG %1 Global
  229.  *
  230.  * @param Web Save
  231.  * @desc Filename for game saves when working with web saves.
  232.  * %1 - Game Name. %2 - File Slot. Default: RPG File%1
  233.  * @default RPG %1 File%2
  234.  *
  235.  * @param ---Confirmation---
  236.  * @default
  237.  *
  238.  * @param Load Confirmation
  239.  * @desc Show the load confirmation window when loading a
  240.  * save file? NO - false     YES - true
  241.  * @default true
  242.  *
  243.  * @param Load Text
  244.  * @desc Text displayed when loading a save file.
  245.  * @default Do you wish to load this save file?
  246.  *
  247.  * @param Save Confirmation
  248.  * @desc Show the save confirmation window when overwriting a
  249.  * save file? NO - false     YES - true
  250.  * @default true
  251.  *
  252.  * @param Save Text
  253.  * @desc Text displayed when overwriting a save file.
  254.  * @default Do you wish to overwrite this save file?
  255.  *
  256.  * @param Delete Confirmation
  257.  * @desc Show the save confirmation window when deleting a
  258.  * save file? NO - false     YES - true
  259.  * @default true
  260.  *
  261.  * @param Delete Text
  262.  * @desc Text displayed when deleting a save file.
  263.  * @default Do you wish to delete this save file?
  264.  *
  265.  * @param Confirm Yes
  266.  * @desc Text used for the 'Yes' confirm command
  267.  * @default Yes
  268.  *
  269.  * @param Confirm No
  270.  * @desc Text used for the 'No' confirm command
  271.  * @default No
  272.  *
  273.  * @help
  274.  * ============================================================================
  275.  * Introduction
  276.  * ============================================================================
  277.  *
  278.  * This plugin provides a new save interface for the player. Along with a new
  279.  * interface, the player can also load and delete saves straight from the menu
  280.  * itself. This will in turn make the save command from the Main Menu always
  281.  * available, but the save option within the new save menu will be enabled
  282.  * depending on whether or not it is allowed or disallowed. From the interface,
  283.  * the player is given more information regarding the save file including the
  284.  * the location the player saved at, the amount of gold available, and any
  285.  * variables that you want to show the player as well.
  286.  *
  287.  * ============================================================================
  288.  * Instructions - Data Columns
  289.  * ============================================================================
  290.  *
  291.  * For those who wish to show additional data in the save menu for each save
  292.  * file, you can add various data categories within the 'Data Columns' inside
  293.  * the plugin parameters. Separate each category with a comma (,). You can use
  294.  * the following entries for data categories:
  295.  *
  296.  * Data Column Categories:
  297.  *
  298.  *   Empty
  299.  *   - Leaves an empty box in the category location. This won't even show the
  300.  *   dark rectangle in the category slot.
  301.  *
  302.  *   Null
  303.  *   - Won't draw any text, but it will draw the dark rectangle in the
  304.  *   category slot.
  305.  *
  306.  *   Location
  307.  *   - Draws the current map location of the save file.
  308.  *
  309.  *   Playtime
  310.  *   - Draws the playtime spent for the save file.
  311.  *
  312.  *   Save Count
  313.  *   - Draws the number of times saved in that playthrough.
  314.  *
  315.  *   Gold Count
  316.  *   - Draws the current gold count of the safe file.
  317.  *
  318.  *   Variable x
  319.  *   - Draws the name of the variable and value of the variable. You can use
  320.  *   text codes in the variable name. Any text between << and >> will be not
  321.  *   be shown when drawn. If the variable name is empty, the value will be
  322.  *   centered.
  323.  *
  324.  *   text: stuff
  325.  *   left text: stuff
  326.  *   center text: stuff
  327.  *   right text: stuff
  328.  *   - This will draw 'stuff' (Replace it with your own text) as text by itself
  329.  *   with no data attached. Use 'left', 'center', or 'right' to decide the text
  330.  *   alignment. If no alignment is used, it will default to 'left' alignment.
  331.  *   You can use text codes within the drawn text.
  332.  *
  333.  * ============================================================================
  334.  * Technical - Save Modes
  335.  * ============================================================================
  336.  *
  337.  * For developers who are planning to publish their RPG Maker MV games on the
  338.  * web, you may want to look into the 'Technical' parameters. Here, you can
  339.  * force the game into thinking the game is running on 'local' or 'web' mode.
  340.  * By default, you'll want it on 'auto' but the forced modes are for testing
  341.  * purposes. Despite being for testing purposes, if you wish for your game to
  342.  * adjust saves as per 'web' mode, you can keep it that way even if your game
  343.  * is to be local-only. Games on the web, however, cannot use 'local' mode and
  344.  * will automatically default to 'web' mode.
  345.  *
  346.  * ============================================================================
  347.  * Technical - Save Files
  348.  * ============================================================================
  349.  *
  350.  * The 'Local Config', 'Local Global', and 'Local Save' can have their filename
  351.  * format changed to your liking. Personally, I don't recommend messing with
  352.  * this unless you know what you're doing.
  353.  *
  354.  * ---
  355.  *
  356.  * However, if you are making a web-based (mobile included), I strongly suggest
  357.  * you look into the 'Web Config', 'Web Global', and 'Web Save' parameters. By
  358.  * default, RPG Maker MV defaults all of the saves to RPG FileX. All web-based
  359.  * RPG Maker MV games would then use the same configuration, same global save
  360.  * file, and all RPG Maker MV games played by an individual would share the
  361.  * same save slots. This can be very problematic.
  362.  *
  363.  * This plugin's default settings will solve this sharing issue by making the
  364.  * web save named accordingly to your game's name provided that you keep the
  365.  * current plugin settings as is or adjust it accordingly. Now, your game will
  366.  * have its own individual identity, use its own configuration, global, and
  367.  * save files without clashing with any other RPG Maker MV games players may
  368.  * have played.
  369.  *
  370.  * ============================================================================
  371.  * Changelog
  372.  * ============================================================================
  373.  *
  374.  * Version 1.02:
  375.  * - Fixed a bug that caused the actor's default name to appear in the save
  376.  * screen instead of the actor's current name (if it was changed.)
  377.  *
  378.  * Version 1.01:
  379.  * - Added a wait time update for save info data to load when moving across the
  380.  * various save files.
  381.  *
  382.  * Version 1.00:
  383.  * - Finished Plugin!
  384.  */
  385. //=============================================================================
  386.  
  387. if (!Utils.RPGMAKER_VERSION) {
  388.   var errortext = '\nYou do not have RPG Maker MV version 1.1.0\n';
  389.      errortext += 'or higher applied to your project. The update\n';
  390.      errortext += 'is absolutely needed for YEP_SaveCore\n';
  391.      errortext += 'to run. Your game will not start until you\n';
  392.      errortext += 'have updated your project\'s files to at\n';
  393.      errortext += 'least version 1.1.0 or higher or if you choose\n';
  394.      errortext += 'to not use the YEP_SaveCore plugin.'
  395.      errortext += '\n\n'
  396.      errortext += 'Find the latest version at http://forums.rpgmakerweb.com/';
  397.      errortext += '\n\n'
  398.      errortext += 'If you do have MV version 1.1.0 or higher\n';
  399.      errortext += 'and you are still getting this message, it is\n';
  400.      errortext += 'because this project\'s rpg_core.js, rpg_managers.js,\n';
  401.      errortext += 'rpg_objects.js, rpg_scenes.js, rpg_sprites.js, and\n';
  402.      errortext += 'rpg_windows.js aren\'t updated. Create a new project\n';
  403.      errortext += 'or go to the NewData folder in your RPG Maker MV root\n';
  404.      errortext += 'folder. Copy the new js files (except plugins.js so it\n';
  405.      errortext += 'won\'t overwrite your Plugin Manager Parameters) to\n';
  406.      errortext += 'your current project!';
  407.   SceneManager.run = function(sceneClass) {
  408.     require('nw.gui').Window.get().showDevTools();
  409.     throw new Error(errortext);
  410.   };
  411. };
  412.  
  413. //=============================================================================
  414. // Parameter Variables
  415. //=============================================================================
  416.  
  417. Yanfly.Parameters = PluginManager.parameters('YEP_SaveCore');
  418. Yanfly.Param = Yanfly.Param || {};
  419.  
  420. Yanfly.Param.SaveMaxFiles = Number(Yanfly.Parameters['Max Files']);
  421. Yanfly.Param.SaveIconSaved = Number(Yanfly.Parameters['Saved Icon']);
  422. Yanfly.Param.SaveIconEmpty = Number(Yanfly.Parameters['Empty Icon']);
  423. Yanfly.Param.SavePop = eval(String(Yanfly.Parameters['Return After Saving']));
  424. Yanfly.Param.SaveAutoIndex = eval(String(Yanfly.Parameters['Auto New Index']));
  425.  
  426. Yanfly.Param.SaveCmdLoad = String(Yanfly.Parameters['Load Command']);
  427. Yanfly.Param.SaveCmdSave = String(Yanfly.Parameters['Save Command']);
  428. Yanfly.Param.SaveCmdDelete = String(Yanfly.Parameters['Delete Command']);
  429.  
  430. Yanfly.Param.SaveHelpSelect = String(Yanfly.Parameters['Select Help']);
  431. Yanfly.Param.SaveLoadSelect = String(Yanfly.Parameters['Load Help']);
  432. Yanfly.Param.SaveSaveSelect = String(Yanfly.Parameters['Save Help']);
  433. Yanfly.Param.SaveDeleteSelect = String(Yanfly.Parameters['Delete Help']);
  434.  
  435. Yanfly.Param.SaveDeleteSound = {
  436.   name:   String(Yanfly.Parameters['Delete Filename']),
  437.   volume: Number(Yanfly.Parameters['Delete Volume']),
  438.   pitch:  Number(Yanfly.Parameters['Delete Pitch']),
  439.   pan:    Number(Yanfly.Parameters['Delete Pan'])
  440. };
  441.  
  442. Yanfly.Param.SaveInfoTitle = String(Yanfly.Parameters['Show Game Title']);
  443. Yanfly.Param.SaveInfoTitle = eval(Yanfly.Param.SaveInfoTitle);
  444. Yanfly.Param.SaveInfoInvalid = String(Yanfly.Parameters['Invalid Game Text']);
  445. Yanfly.Param.SaveInfoEmpty = String(Yanfly.Parameters['Empty Game Text']);
  446. Yanfly.Param.SaveInfoPartyType = Number(Yanfly.Parameters['Party Display']);
  447. Yanfly.Param.SaveInfoPartyType = Yanfly.Param.SaveInfoPartyType.clamp(0, 3);
  448. Yanfly.Param.SaveInfoPartyY = String(Yanfly.Parameters['Party Y Position']);
  449. Yanfly.Param.SaveInfoActorName = String(Yanfly.Parameters['Show Actor Names']);
  450. Yanfly.Param.SaveInfoActorName = eval(Yanfly.Param.SaveInfoActorName);
  451. Yanfly.Param.SaveInfoActorNameSz = Number(Yanfly.Parameters['Name Font Size']);
  452. Yanfly.Param.SaveInfoActorLv = String(Yanfly.Parameters['Show Actor Level']);
  453. Yanfly.Param.SaveInfoActorLv = eval(Yanfly.Param.SaveInfoActorLv);
  454. Yanfly.Param.SaveInfoActorLvSz = Number(Yanfly.Parameters['Level Font Size']);
  455. Yanfly.Param.SaveInfoActorLvFmt = String(Yanfly.Parameters['Level Format']);
  456. Yanfly.Param.SaveInfoDataSz = Number(Yanfly.Parameters['Data Font Size']);
  457. Yanfly.Param.SaveInfoDataCol1 = String(Yanfly.Parameters['Data Column 1']);
  458. Yanfly.Param.SaveInfoDataCol1 = Yanfly.Param.SaveInfoDataCol1.split(',');
  459. Yanfly.Param.SaveInfoDataCol2 = String(Yanfly.Parameters['Data Column 2']);
  460. Yanfly.Param.SaveInfoDataCol2 = Yanfly.Param.SaveInfoDataCol2.split(',');
  461. Yanfly.Param.SaveInfoDataCol3 = String(Yanfly.Parameters['Data Column 3']);
  462. Yanfly.Param.SaveInfoDataCol3 = Yanfly.Param.SaveInfoDataCol3.split(',');
  463. Yanfly.Param.SaveInfoDataCol4 = String(Yanfly.Parameters['Data Column 4']);
  464. Yanfly.Param.SaveInfoDataCol4 = Yanfly.Param.SaveInfoDataCol4.split(',');
  465.  
  466. Yanfly.trimSaveDataColumns = function(array) {
  467.   var length = array.length;
  468.   for (var i = 0; i < length; ++i) {
  469.     array[i] = array[i].trim();
  470.   }
  471.   if (length === 1 && array[0] === '') array.splice(0);
  472. };
  473.  
  474. Yanfly.trimSaveDataColumns(Yanfly.Param.SaveInfoDataCol1);
  475. Yanfly.trimSaveDataColumns(Yanfly.Param.SaveInfoDataCol2);
  476. Yanfly.trimSaveDataColumns(Yanfly.Param.SaveInfoDataCol3);
  477. Yanfly.trimSaveDataColumns(Yanfly.Param.SaveInfoDataCol4);
  478.  
  479. Yanfly.Param.SaveVocabLocation = String(Yanfly.Parameters['Map Location']);
  480. Yanfly.Param.SaveVocabPlaytime = String(Yanfly.Parameters['Playtime']);
  481. Yanfly.Param.SaveVocabSaveCount = String(Yanfly.Parameters['Save Count']);
  482. Yanfly.Param.SaveVocabGoldCount = String(Yanfly.Parameters['Gold Count']);
  483.  
  484. Yanfly.Param.SaveTechSaveMode = String(Yanfly.Parameters['Save Mode']).trim();
  485. Yanfly.Param.SaveTechSaveMode = Yanfly.Param.SaveTechSaveMode.toLowerCase();
  486. Yanfly.Param.SaveTechLocalConfig = String(Yanfly.Parameters['Local Config']);
  487. Yanfly.Param.SaveTechLocalGlobal = String(Yanfly.Parameters['Local Global']);
  488. Yanfly.Param.SaveTechLocalSave = String(Yanfly.Parameters['Local Save']);
  489. Yanfly.Param.SaveTechWebConfig = String(Yanfly.Parameters['Web Config']);
  490. Yanfly.Param.SaveTechWebGlobal = String(Yanfly.Parameters['Web Global']);
  491. Yanfly.Param.SaveTechWebSave = String(Yanfly.Parameters['Web Config']);
  492.  
  493. Yanfly.Param.SaveConfirmLoad = String(Yanfly.Parameters['Load Confirmation']);
  494. Yanfly.Param.SaveConfirmLoad = eval(Yanfly.Param.SaveConfirmLoad);
  495. Yanfly.Param.SaveConfirmLoadTx = String(Yanfly.Parameters['Load Text']);
  496. Yanfly.Param.SaveConfirmSave = String(Yanfly.Parameters['Save Confirmation']);
  497. Yanfly.Param.SaveConfirmSave = eval(Yanfly.Param.SaveConfirmSave);
  498. Yanfly.Param.SaveConfirmSaveTx = String(Yanfly.Parameters['Save Text']);
  499. Yanfly.Param.SaveConfirmDel = String(Yanfly.Parameters['Delete Confirmation']);
  500. Yanfly.Param.SaveConfirmDel = eval(Yanfly.Param.SaveConfirmDel);
  501. Yanfly.Param.SaveConfirmDelTx = String(Yanfly.Parameters['Delete Text']);
  502. Yanfly.Param.SaveConfirmYes = String(Yanfly.Parameters['Confirm Yes']);
  503. Yanfly.Param.SaveConfirmNo = String(Yanfly.Parameters['Confirm No']);
  504.  
  505. //=============================================================================
  506. // DataManager
  507. //=============================================================================
  508.  
  509. DataManager.maxSavefiles = function() {
  510.     return Yanfly.Param.SaveMaxFiles;
  511. };
  512.  
  513. Yanfly.Save.DataManager_selectSavefileForNewGame =
  514.     DataManager.selectSavefileForNewGame;
  515. DataManager.selectSavefileForNewGame = function() {
  516.     Yanfly.Save.DataManager_selectSavefileForNewGame.call(this);
  517.     if (Yanfly.Param.SaveAutoIndex) return;
  518.     this._lastAccessedId = 1;
  519. };
  520.  
  521. //=============================================================================
  522. // StorageManager
  523. //=============================================================================
  524.  
  525. Yanfly.Save.StorageManager_isLocalMode = StorageManager.isLocalMode;
  526. StorageManager.isLocalMode = function() {
  527.   if (Yanfly.Param.SaveTechSaveMode === 'local') {
  528.     if (!Utils.isNwjs()) return false;
  529.     return true;
  530.   } else if (Yanfly.Param.SaveTechSaveMode === 'web') {
  531.     return false;
  532.   } else {
  533.     return Yanfly.Save.StorageManager_isLocalMode.call(this);
  534.   }
  535. };
  536.  
  537. StorageManager.localFilePath = function(savefileId) {
  538.   var name;
  539.   if (savefileId < 0) {
  540.     name = Yanfly.Param.SaveTechLocalConfig;
  541.   } else if (savefileId === 0) {
  542.     name = Yanfly.Param.SaveTechLocalGlobal;
  543.   } else {
  544.     name = Yanfly.Param.SaveTechLocalSave.format(savefileId);
  545.   }
  546.   return this.localFileDirectoryPath() + name;
  547. };
  548.  
  549. Yanfly.Save.StorageManager_webStorageKey = StorageManager.webStorageKey;
  550. StorageManager.webStorageKey = function(savefileId) {
  551.   if (!$dataSystem) return Yanfly.Save.StorageManager_webStorageKey.call(this);
  552.   var title = $dataSystem.gameTitle;
  553.   this.loadConfig();
  554.   if (savefileId < 0) {
  555.     return Yanfly.Param.SaveTechWebConfig.format(title);
  556.   } else if (savefileId === 0) {
  557.     return Yanfly.Param.SaveTechWebGlobal.format(title);
  558.   } else {
  559.     return Yanfly.Param.SaveTechWebSave.format(savefileId);
  560.   }
  561. };
  562.  
  563. StorageManager.loadConfig = function() {
  564.   if (this._configLoaded) return;
  565.   this._configLoaded = true;
  566.   ConfigManager.load();
  567. };
  568.  
  569. //=============================================================================
  570. // BattleManager
  571. //=============================================================================
  572.  
  573. Yanfly.Save.BattleManager_setBattleTest = BattleManager.setBattleTest;
  574. BattleManager.setBattleTest = function(battleTest) {
  575.     Yanfly.Save.BattleManager_setBattleTest.call(this, battleTest);
  576.     if (battleTest) StorageManager.loadConfig();
  577. };
  578.  
  579. //=============================================================================
  580. // Window_Base
  581. //=============================================================================
  582.  
  583. Window_Base.prototype.drawSvActor = function(actor, x, y) {
  584.     var filename = actor.battlerName();
  585.     var bitmap = ImageManager.loadSvActor(filename);
  586.     var pw = bitmap.width / 9;
  587.     var ph = bitmap.height / 6;
  588.     var sx = 0;
  589.     var sy = 0;
  590.     this.contents.blt(bitmap, sx, sy, pw, ph, x - pw / 2, y - ph);
  591. };
  592.  
  593. Window_Base.prototype.textWidthEx = function(text) {
  594.     return this.drawTextEx(text, 0, this.contents.height);
  595. };
  596.  
  597. //=============================================================================
  598. // Window_MenuCommand
  599. //=============================================================================
  600.  
  601. Window_MenuCommand.prototype.isSaveEnabled = function() {
  602.     if (DataManager.isEventTest()) return false;
  603.     return true;
  604. };
  605.  
  606. //=============================================================================
  607. // Window_SavefileList
  608. //=============================================================================
  609.  
  610. Window_SavefileList.prototype.itemHeight = function() {
  611.     return this.lineHeight();
  612. };
  613.  
  614. Window_SavefileList.prototype.numVisibleRows = function() {
  615.     return 1;
  616. };
  617.  
  618. Window_SavefileList.prototype.maxCols = function() {
  619.     return 2;
  620. };
  621.  
  622. Window_SavefileList.prototype.cursorDown = function(wrap) {
  623. };
  624.  
  625. Window_SavefileList.prototype.cursorUp = function(wrap) {
  626. };
  627.  
  628. Window_Selectable.prototype.cursorPagedown = function() {
  629. };
  630.  
  631. Window_Selectable.prototype.cursorPageup = function() {
  632. };
  633.  
  634. Window_Selectable.prototype.updateArrows = function() {
  635.     var topRow = this.topRow();
  636.     var maxTopRow = this.maxTopRow();
  637.     this.downArrowVisible = false;
  638.     this.upArrowVisible = false;
  639. };
  640.  
  641. Window_SavefileList.prototype.windowHeight = function() {
  642.     return this.fittingHeight(Math.min(this.numVisibleRows(), 12));
  643. };
  644.  
  645. Window_SavefileList.prototype.changeWindowHeight = function() {
  646.     this.height = this.windowHeight();
  647. };
  648.  
  649. Window_SavefileList.prototype.drawItem = function(index) {
  650.     var id = index + 1;
  651.     var valid = DataManager.isThisGameFile(id);
  652.     var rect = this.itemRect(index);
  653.     this.resetTextColor();
  654.     //if (this._mode === 'load') this.changePaintOpacity(valid);
  655.     this.changePaintOpacity(valid);
  656.     var icon = valid ? Yanfly.Param.SaveIconSaved : Yanfly.Param.SaveIconEmpty;
  657.     this.drawIcon(icon, rect.x + 2, rect.y + 2);
  658.     this.drawFileId(id, rect.x + Window_Base._iconWidth + 4, rect.y);
  659. };
  660.  
  661. Window_SavefileList.prototype.playOkSound = function() {
  662.     Window_Selectable.prototype.playOkSound.call(this);
  663. };
  664.  
  665. //=============================================================================
  666. // Window_SaveAction
  667. //=============================================================================
  668.  
  669. function Window_SaveAction() {
  670.     this.initialize.apply(this, arguments);
  671. }
  672.  
  673. Window_SaveAction.prototype = Object.create(Window_HorzCommand.prototype);
  674. Window_SaveAction.prototype.constructor = Window_SaveAction;
  675.  
  676. Window_SaveAction.prototype.initialize = function(x, y, mode) {
  677.     this._width = Graphics.boxWidth;
  678.     this._currentFile = 0;
  679.     this._mode = mode;
  680.     Window_HorzCommand.prototype.initialize.call(this, x, y);
  681.     this.deactivate();
  682.     this.deselect();
  683. };
  684.  
  685. Window_SaveAction.prototype.windowWidth = function() {
  686.     return this._width;
  687. };
  688.  
  689. Window_SaveAction.prototype.maxCols = function() {
  690.     return 3;
  691. };
  692.  
  693. Window_SaveAction.prototype.savefileId = function() {
  694.     return SceneManager._scene._listWindow.index() + 1;
  695. };
  696.  
  697. Window_SaveAction.prototype.makeCommandList = function() {
  698.     var id = this.savefileId();
  699.     var enabled = DataManager.isThisGameFile(id);
  700.     var valid = DataManager.loadSavefileInfo(id);
  701.     this.addCommand(this.getCommandName('load'), 'load', valid);
  702.     this.addCommand(this.getCommandName('save'), 'save', this.isSaveEnabled());
  703.     this.addCommand(this.getCommandName('delete'), 'delete', enabled);
  704. };
  705.  
  706. Window_SaveAction.prototype.getCommandName = function(type) {
  707.     if (type === 'load') {
  708.       return Yanfly.Param.SaveCmdLoad;
  709.     } else if (type === 'save') {
  710.       return Yanfly.Param.SaveCmdSave;
  711.     } else {
  712.       return Yanfly.Param.SaveCmdDelete;
  713.     }
  714. };
  715.  
  716. Window_SaveAction.prototype.isSaveEnabled = function() {
  717.     if (this._mode !== 'save') return false;
  718.     return $gameSystem.isSaveEnabled();
  719. };
  720.  
  721. Window_SaveAction.prototype.update = function() {
  722.     Window_HorzCommand.prototype.update.call(this);
  723.     if (this.savefileId() !== this._currentFile) this.updateIndex();
  724. };
  725.  
  726. Window_SaveAction.prototype.updateIndex = function() {
  727.     this._currentFile = this.savefileId();
  728.     this.refresh();
  729. };
  730.  
  731. Window_SaveAction.prototype.playOkSound = function() {
  732. };
  733.  
  734. Window_SaveAction.prototype.updateHelp = function() {
  735.     var text = '';
  736.     if (this.currentSymbol() === 'load') {
  737.       text = Yanfly.Param.SaveLoadSelect;
  738.     } else if (this.currentSymbol() === 'save') {
  739.       text = Yanfly.Param.SaveSaveSelect;
  740.     } else if (this.currentSymbol() === 'delete') {
  741.       text = Yanfly.Param.SaveDeleteSelect;
  742.     }
  743.     this._helpWindow.setText(text);
  744. };
  745.  
  746. //=============================================================================
  747. // Window_SaveInfo
  748. //=============================================================================
  749.  
  750. function Window_SaveInfo() {
  751.     this.initialize.apply(this, arguments);
  752. }
  753.  
  754. Window_SaveInfo.prototype = Object.create(Window_Base.prototype);
  755. Window_SaveInfo.prototype.constructor = Window_SaveInfo;
  756.  
  757. Window_SaveInfo.prototype.initialize = function(x, y, width, height, mode) {
  758.   this._currentFile = 0;
  759.   this._waitTime = 0;
  760.   this._mode = mode;
  761.   Window_Base.prototype.initialize.call(this, x, y, width, height);
  762. };
  763.  
  764. Window_SaveInfo.prototype.resetFontSettings = function() {
  765.   Window_Base.prototype.resetFontSettings.call(this);
  766.   if (this._drawLevel) this.contents.fontSize = Yanfly.Param.SaveInfoActorLvSz;
  767.   if (this._drawData) this.contents.fontSize = Yanfly.Param.SaveInfoDataSz;
  768. };
  769.  
  770. Window_SaveInfo.prototype.savefileId = function() {
  771.   return SceneManager._scene._listWindow.index() + 1;
  772. };
  773.  
  774. Window_SaveInfo.prototype.drawDarkRect = function(dx, dy, dw, dh) {
  775.   var color = this.gaugeBackColor();
  776.   this.changePaintOpacity(false);
  777.   this.contents.fillRect(dx + 1, dy + 1, dw - 2, dh - 2, color);
  778.   this.changePaintOpacity(true);
  779. };
  780.  
  781. Window_SaveInfo.prototype.update = function() {
  782.   Window_Base.prototype.update.call(this);
  783.   if (this.savefileId() !== this._currentFile) this.updateIndex();
  784.   if (this._waitTime > 0) this.updateTimer();
  785. };
  786.  
  787. Window_SaveInfo.prototype.systemColorEx = function() {
  788.     if (Imported.YEP_CoreEngine) {
  789.       return '\\c[' + Yanfly.Param.ColorSystem + ']';
  790.     } else {
  791.       return '\\c[16]';
  792.     }
  793. };
  794.  
  795. Window_SaveInfo.prototype.updateIndex = function() {
  796.   var id = this.savefileId();
  797.   this._currentFile = id;
  798.   this._waitTime = 30;
  799.   this.contents.clear();
  800. };
  801.  
  802. Window_SaveInfo.prototype.updateTimer = function() {
  803.   this._waitTime -= 1;
  804.   if (this._waitTime > 0) return;
  805.   var id = this.savefileId();
  806.   this._valid = DataManager.isThisGameFile(id);
  807.   this._info = DataManager.loadSavefileInfo(id);
  808.   this.refresh();
  809. };
  810.  
  811. Window_SaveInfo.prototype.refresh = function() {
  812.   this.contents.clear();
  813.   this.resetFontSettings();
  814.   var dy = 0;
  815.   dy = this.drawGameTitle(dy);
  816.   if (!this._valid) return this.drawInvalidText(dy);
  817.   this._saveContents = StorageManager.load(this.savefileId());
  818.   this.drawContents(dy);
  819. };
  820.  
  821. Window_SaveInfo.prototype.drawGameTitle = function(dy) {
  822.   if (!Yanfly.Param.SaveInfoTitle) return dy;
  823.   if (!this._info) return dy;
  824.   if (!this._info.title) return dy;
  825.   this.resetFontSettings();
  826.   var text = this._info.title;
  827.   this.drawText(text, 0, dy, this.contents.width, 'center');
  828.   return dy + this.lineHeight();
  829. };
  830.  
  831. Window_SaveInfo.prototype.drawInvalidText = function(dy) {
  832.   this.drawDarkRect(0, dy, this.contents.width, this.contents.height - dy);
  833.   dy = (this.contents.height - dy - this.lineHeight()) / 2;
  834.   if (this._info) {
  835.     var text = Yanfly.Param.SaveInfoInvalid;
  836.   } else {
  837.     var text = Yanfly.Param.SaveInfoEmpty;
  838.   }
  839.   this.changeTextColor(this.systemColor());
  840.   this.drawText(text, 0, dy, this.contents.width, 'center');
  841. };
  842.  
  843. Window_SaveInfo.prototype.drawContents = function(dy) {
  844.   if (!this._saveContents) {
  845.     return setTimeout(this.drawContents.bind(this, dy), 50);
  846.   }
  847.   this._saveContents = JsonEx.parse(this._saveContents);
  848.   dy = this.drawPartyGraphics(dy);
  849.   dy = this.drawPartyNames(dy);
  850.   dy = this.drawPartyLevels(dy);
  851.   this.drawColumnData(dy);
  852. };
  853.  
  854. Window_SaveInfo.prototype.drawPartyGraphics = function(dy) {
  855.   if (Yanfly.Param.SaveInfoPartyType === 0) return dy;
  856.   dy = eval(Yanfly.Param.SaveInfoPartyY);
  857.   var length = this._saveContents.party.maxBattleMembers();
  858.   var dw = this.contents.width / length;;
  859.   dw = Math.floor(dw);
  860.   var dx = Math.floor(dw / 2);
  861.   for (var i = 0; i < length; ++i) {
  862.     var actorId = this._saveContents.party._actors[i];
  863.     var member = this._saveContents.actors._data[actorId];
  864.     if (member) {
  865.       if (Yanfly.Param.SaveInfoPartyType === 1) {
  866.         var name = member.characterName();
  867.         var index = member.characterIndex();
  868.         this.drawCharacter(name, index, dx, dy);
  869.       } else if (Yanfly.Param.SaveInfoPartyType === 2) {
  870.         var fh = Window_Base._faceHeight;
  871.         var fw = Window_Base._faceWidth;
  872.         var fx = dx - Math.floor(Math.min(fh, dw) / 2);
  873.         var dif = Math.floor(Math.max(0, dw - fw) / 2);
  874.         var name = member.faceName();
  875.         var index = member.faceIndex();
  876.         this.drawFace(name, index, fx - dif, dy - fh, dw, fh);
  877.       } else if (Yanfly.Param.SaveInfoPartyType === 3) {
  878.         this.drawSvActor(member, dx, dy);
  879.       }
  880.     }
  881.     dx += dw;
  882.   }
  883.   return dy;
  884. };
  885.  
  886. Window_SaveInfo.prototype.drawCharacter = function(name, index, x, y) {
  887.     var bitmap = ImageManager.loadCharacter(name);
  888.     if (bitmap.width <= 0) {
  889.       return setTimeout(this.drawCharacter.bind(this, name, index, x, y), 50);
  890.     }
  891.     Window_Base.prototype.drawCharacter.call(this, name, index, x, y);
  892. };
  893.  
  894. Window_SaveInfo.prototype.drawFace = function(name, index, x, y, w, h) {
  895.     var bitmap = ImageManager.loadFace(name);
  896.     if (bitmap.width <= 0) {
  897.       return setTimeout(this.drawFace.bind(this, name, index, x, y, w, h), 50);
  898.     }
  899.     Window_Base.prototype.drawFace.call(this, name, index, x, y, w, h);
  900. };
  901.  
  902. Window_SaveInfo.prototype.drawSvActor = function(actor, x, y) {
  903.     var filename = actor.battlerName();
  904.     var bitmap = ImageManager.loadSvActor(filename);
  905.     if (bitmap.width <= 0) {
  906.       return setTimeout(this.drawSvActor.bind(this, actor, x, y), 50);
  907.     }
  908.     Window_Base.prototype.drawSvActor.call(this, actor, x, y);
  909. };
  910.  
  911. Window_SaveInfo.prototype.drawPartyNames = function(dy) {
  912.   if (!Yanfly.Param.SaveInfoActorName) return dy;
  913.   this.resetFontSettings();
  914.   this.contents.fontSize = Yanfly.Param.SaveInfoActorNameSz;
  915.   var length = this._saveContents.party.maxBattleMembers();
  916.   var dw = this.contents.width / length;;
  917.   dw = Math.floor(dw);
  918.   var dx = 0;
  919.   for (var i = 0; i < length; ++i) {
  920.     var actorId = this._saveContents.party._actors[i];
  921.     var member = this._saveContents.actors._data[actorId];
  922.     if (member) {
  923.       var name = member._name;
  924.       this.drawText(name, dx, dy, dw, 'center');
  925.     }
  926.     dx += dw
  927.   }
  928.   return dy += this.lineHeight();
  929. };
  930.  
  931. Window_SaveInfo.prototype.drawPartyLevels = function(dy) {
  932.   if (!Yanfly.Param.SaveInfoActorLv) return dy;
  933.   this._drawLevel = true;
  934.   var length = this._saveContents.party.maxBattleMembers();
  935.   var dw = this.contents.width / length;;
  936.   dw = Math.floor(dw);
  937.   var dx = 0;
  938.   var fmt = Yanfly.Param.SaveInfoActorLvFmt;
  939.   for (var i = 0; i < length; ++i) {
  940.     var actorId = this._saveContents.party._actors[i];
  941.     var member = this._saveContents.actors._data[actorId];
  942.     if (member) {
  943.       var lv = Yanfly.Util.toGroup(member.level);
  944.       var text = fmt.format(TextManager.levelA, TextManager.level, lv);
  945.       var tw = this.textWidthEx(text);
  946.       var dif = Math.floor(Math.max(0, dw - tw) / 2);
  947.       this.drawTextEx(text, dx + dif, dy);
  948.     }
  949.     dx += dw
  950.   }
  951.   this._drawLevel = false;
  952.   return dy += this.lineHeight();
  953. };
  954.  
  955. Window_SaveInfo.prototype.drawColumnData = function(dy) {
  956.     var totalColumns = 0;
  957.     var drawnArrays = [];
  958.     if (Yanfly.Param.SaveInfoDataCol1.length > 0) {
  959.       totalColumns += 1;
  960.       drawnArrays.push(Yanfly.Param.SaveInfoDataCol1);
  961.     }
  962.     if (Yanfly.Param.SaveInfoDataCol2.length > 0) {
  963.       totalColumns += 1;
  964.       drawnArrays.push(Yanfly.Param.SaveInfoDataCol2);
  965.     }
  966.     if (Yanfly.Param.SaveInfoDataCol3.length > 0) {
  967.       totalColumns += 1;
  968.       drawnArrays.push(Yanfly.Param.SaveInfoDataCol3);
  969.     }
  970.     if (Yanfly.Param.SaveInfoDataCol4.length > 0) {
  971.       totalColumns += 1;
  972.       drawnArrays.push(Yanfly.Param.SaveInfoDataCol4);
  973.     }
  974.     if (totalColumns <= 0) return;
  975.     var dw = Math.floor(this.contents.width / totalColumns);
  976.     var dif = totalColumns > 1 ? this.textPadding() : 0;
  977.     for (var i = 0; i < totalColumns; ++i) {
  978.       var column = drawnArrays[i];
  979.       var dx = i * dw;
  980.       this.drawColumn(column, dx, dy, dw - dif);
  981.     }
  982. };
  983.  
  984. Window_SaveInfo.prototype.drawColumn = function(column, dx, dy, dw) {
  985.     var length = column.length;
  986.     var tp = this.textPadding();
  987.     for (var i = 0; i < length; ++i) {
  988.       this.resetFontSettings();
  989.       this.contents.fontSize = Yanfly.Param.SaveInfoDataSz;
  990.       var data = column[i];
  991.       if (data.toUpperCase().trim() !== 'EMPTY') {
  992.         this.drawDarkRect(dx, dy, dw, this.lineHeight());
  993.         this.drawData(data, dx + tp, dy, dw - tp * 2);
  994.       }
  995.       dy += this.lineHeight();
  996.     }
  997. };
  998.  
  999. Window_SaveInfo.prototype.drawData = function(data, dx, dy, dw) {
  1000.   if (data.toUpperCase().trim() === 'NULL') {
  1001.     return;
  1002.   } else if (data.toUpperCase().trim() === 'LOCATION') {
  1003.     this.drawLocation(dx, dy, dw);
  1004.   } else if (data.toUpperCase().trim() === 'PLAYTIME') {
  1005.     this.drawPlaytime(dx, dy, dw);
  1006.   } else if (data.toUpperCase().trim() === 'SAVE COUNT') {
  1007.     this.drawSaveCount(dx, dy, dw);
  1008.   } else if (data.toUpperCase().trim() === 'GOLD COUNT') {
  1009.     this.drawGoldCount(dx, dy, dw);
  1010.   } else if (data.match(/VARIABLE[ ](\d+)/i)) {
  1011.     this.drawVariable(parseInt(RegExp.$1), dx, dy, dw);
  1012.   } else if (data.match(/(.*)[ ]TEXT:(.*)/i)) {
  1013.     this.drawDataText(String(RegExp.$1), String(RegExp.$2), dx, dy, dw);
  1014.   } else if (data.match(/TEXT:(.*)/i)) {
  1015.     this.drawDataText('left', String(RegExp.$1), dx, dy, dw);
  1016.   }
  1017. };
  1018.  
  1019. Window_SaveInfo.prototype.drawLocation = function(dx, dy, dw) {
  1020.     var id = this._saveContents.map._mapId;
  1021.     var text = $dataMapInfos[id].name;
  1022.     if (Yanfly.Param.SaveVocabLocation.length > 0) {
  1023.       this.changeTextColor(this.systemColor());
  1024.       this.drawText(Yanfly.Param.SaveVocabLocation, dx, dy, dw, 'left');
  1025.       this.changeTextColor(this.normalColor());
  1026.       this.drawText(text, dx, dy, dw, 'right');
  1027.     } else {
  1028.       this.drawText(text, dx, dy, dw, 'center');
  1029.     }
  1030. };
  1031.  
  1032. Window_SaveInfo.prototype.drawPlaytime = function(dx, dy, dw) {
  1033.     if (!this._info.playtime) return;
  1034.     var text = this._info.playtime;
  1035.     if (Yanfly.Param.SaveVocabPlaytime.length > 0) {
  1036.       this.changeTextColor(this.systemColor());
  1037.       this.drawText(Yanfly.Param.SaveVocabPlaytime, dx, dy, dw, 'left');
  1038.       this.changeTextColor(this.normalColor());
  1039.       this.drawText(text, dx, dy, dw, 'right');
  1040.     } else {
  1041.       this.drawText(text, dx, dy, dw, 'center');
  1042.     }
  1043. };
  1044.  
  1045. Window_SaveInfo.prototype.drawSaveCount = function(dx, dy, dw) {
  1046.     var text = Yanfly.Util.toGroup(this._saveContents.system._saveCount);
  1047.     if (Yanfly.Param.SaveVocabSaveCount.length > 0) {
  1048.       this.changeTextColor(this.systemColor());
  1049.       this.drawText(Yanfly.Param.SaveVocabSaveCount, dx, dy, dw, 'left');
  1050.       this.changeTextColor(this.normalColor());
  1051.       this.drawText(text, dx, dy, dw, 'right');
  1052.     } else {
  1053.       this.drawText(text, dx, dy, dw, 'center');
  1054.     }
  1055. };
  1056.  
  1057. Window_SaveInfo.prototype.drawGoldCount = function(dx, dy, dw) {
  1058.     var text = Yanfly.Util.toGroup(this._saveContents.party._gold);
  1059.     if (Yanfly.Param.SaveVocabGoldCount.length > 0) {
  1060.       this.changeTextColor(this.systemColor());
  1061.       var fmt = Yanfly.Param.SaveVocabGoldCount;
  1062.       this.drawText(fmt.format(TextManager.currencyUnit), dx, dy, dw, 'left');
  1063.       this.changeTextColor(this.normalColor());
  1064.      
  1065.       this.drawText(text, dx, dy, dw, 'right');
  1066.     } else {
  1067.       var fmt = '\\c[0]%1' + this.systemColorEx() + '%2';
  1068.       var ftext = fmt.format(text, TextManager.currencyUnit);
  1069.       this._drawData = true;
  1070.       var fw = this.textWidthEx(ftext);
  1071.       dx += Math.max(0, Math.floor((dw - fw) / 2));
  1072.       this.drawTextEx(ftext, dx, dy);
  1073.       this._drawData = false;
  1074.     }
  1075. };
  1076.  
  1077. Window_SaveInfo.prototype.drawVariable = function(id, dx, dy, dw) {
  1078.     var varName = $dataSystem.variables[id];
  1079.     varName = varName.replace(/<<(.*?)>>/i, '');
  1080.     var text = Yanfly.Util.toGroup(this._saveContents.variables.value(id));
  1081.     var diff = Math.max(0, (this.standardFontSize() -
  1082.       this.contents.fontSize) / 2);
  1083.     if (varName.length > 0) {
  1084.       this._drawData = true;
  1085.       this.changeTextColor(this.systemColor());
  1086.       dy += diff;
  1087.       this.drawTextEx(this.systemColorEx() + varName, dx, dy, dw, 'left');
  1088.       dy -= diff;
  1089.       this.changeTextColor(this.normalColor());
  1090.       this._drawData = false;
  1091.       this.drawText(text, dx, dy, dw, 'right');
  1092.     } else {
  1093.       this.drawText(text, dx, dy, dw, 'center');
  1094.     }
  1095. };
  1096.  
  1097. Window_SaveInfo.prototype.drawDataText = function(align, text, dx, dy, dw) {
  1098.     this._drawData = true;
  1099.     dy += Math.max(0, (this.standardFontSize() - this.contents.fontSize) / 2);
  1100.     var align = align.toLowerCase().trim();
  1101.     var text = text.trim();
  1102.     if (align === 'left') {
  1103.       this.drawTextEx(text, dx, dy);
  1104.     } else if (align === 'right') {
  1105.       var tw = this.textWidthEx(text);
  1106.       this.drawTextEx(text, dx + dw - tw, dy);
  1107.     } else {
  1108.       var tw = this.textWidthEx(text);
  1109.       this.drawTextEx(text, dx + (dw - tw) / 2, dy);
  1110.     }
  1111.     this._drawData = false;
  1112. };
  1113.  
  1114. //=============================================================================
  1115. // Window_SaveConfirm
  1116. //=============================================================================
  1117.  
  1118. function Window_SaveConfirm() {
  1119.     this.initialize.apply(this, arguments);
  1120. }
  1121.  
  1122. Window_SaveConfirm.prototype = Object.create(Window_Command.prototype);
  1123. Window_SaveConfirm.prototype.constructor = Window_SaveConfirm;
  1124.  
  1125. Window_SaveConfirm.prototype.initialize = function() {
  1126.     Window_Command.prototype.initialize.call(this, 0, 0);
  1127.     this.openness = 0;
  1128. };
  1129.  
  1130. Window_SaveConfirm.prototype.makeCommandList = function() {
  1131.     this.addCommand(Yanfly.Param.SaveConfirmYes, 'confirm');
  1132.     this.addCommand(Yanfly.Param.SaveConfirmNo, 'cancel');
  1133. };
  1134.  
  1135. Window_SaveConfirm.prototype.setData = function(text) {
  1136.     this._text = text;
  1137.     var ww = this.textWidthEx(this._text) + this.standardPadding() * 2;
  1138.     ww += this.textPadding() * 2;
  1139.     this.width = ww;
  1140.     this.refresh();
  1141.     this.x = (Graphics.boxWidth - this.width) / 2;
  1142.     this.y = (Graphics.boxHeight - this.height) / 2;
  1143.     this.drawTextEx(this._text, this.textPadding(), 0);
  1144. };
  1145.  
  1146. Window_SaveConfirm.prototype.itemTextAlign = function() {
  1147.     return 'center';
  1148. };
  1149.  
  1150. Window_SaveConfirm.prototype.windowHeight = function() {
  1151.     return this.fittingHeight(3);
  1152. };
  1153.  
  1154. Window_SaveConfirm.prototype.itemRect = function(index) {
  1155.     var rect = Window_Selectable.prototype.itemRect.call(this, index);
  1156.     rect.y += this.lineHeight();
  1157.     return rect;
  1158. };
  1159.  
  1160. //=============================================================================
  1161. // Scene_File
  1162. //=============================================================================
  1163.  
  1164. Scene_File.prototype.terminate = function() {
  1165.     Scene_MenuBase.prototype.terminate.call(this);
  1166.     if (this._loadSuccess) $gameSystem.onAfterLoad();
  1167. };
  1168.  
  1169. Scene_Load.prototype.terminate = function() {
  1170.     Scene_File.prototype.terminate.call(this);
  1171. };
  1172.  
  1173. Scene_File.prototype.create = function() {
  1174.     Scene_MenuBase.prototype.create.call(this);
  1175.     DataManager.loadAllSavefileImages();
  1176.     this.createHelpWindow();
  1177.     this.createListWindow();
  1178.     this.createActionWindow();
  1179.     this.createInfoWindow();
  1180.     this.createConfirmWindow();
  1181. };
  1182.  
  1183. Scene_File.prototype.createHelpWindow = function() {
  1184.     this._helpWindow = new Window_Help(2);
  1185.     this._helpWindow.setText(Yanfly.Param.SaveHelpSelect);
  1186.     this.addWindow(this._helpWindow);
  1187. };
  1188.  
  1189. Scene_File.prototype.createListWindow = function() {
  1190.     var x = 0;
  1191.     var y = this._helpWindow.height;
  1192.     var width = Graphics.boxWidth;
  1193.     var height = Graphics.boxHeight - y;
  1194.     this._listWindow = new Window_SavefileList(x, y, width, height);
  1195.     this.addWindow(this._listWindow);
  1196.     this._listWindow.changeWindowHeight();
  1197.     this._listWindow.setHandler('ok',     this.onSavefileOk.bind(this));
  1198.     this._listWindow.setHandler('cancel', this.popScene.bind(this));
  1199.     this._listWindow.select(this.firstSavefileIndex());
  1200.     this._listWindow.setTopRow(this.firstSavefileIndex() - 2);
  1201.     this._listWindow.setMode(this.mode());
  1202.     this._listWindow.refresh();
  1203.    
  1204. };
  1205.  
  1206. Scene_File.prototype.createActionWindow = function() {
  1207.     var x = this._listWindow.x;
  1208.     var y = this._listWindow.y + this._listWindow.height;
  1209.     this._actionWindow = new Window_SaveAction(x, y, this.mode());
  1210.     this.addWindow(this._actionWindow);
  1211.     this._actionWindow.setHelpWindow(this._helpWindow);
  1212.     this._actionWindow.setHandler('load', this.onActionLoad.bind(this));
  1213.     this._actionWindow.setHandler('save', this.onActionSave.bind(this));
  1214.     this._actionWindow.setHandler('delete', this.onActionDelete.bind(this));
  1215.     this._actionWindow.setHandler('cancel', this.onActionCancel.bind(this));
  1216. };
  1217.  
  1218. Scene_File.prototype.createInfoWindow = function() {
  1219.     var x = this._actionWindow.x;
  1220.     var y = this._actionWindow.y + this._actionWindow.height;
  1221.     var width = Graphics.boxWidth;
  1222.     var height = Graphics.boxHeight - y;
  1223.     this._infoWindow = new Window_SaveInfo(x, y, width, height, this.mode());
  1224.     this.addWindow(this._infoWindow);
  1225. };
  1226.  
  1227. Scene_File.prototype.createConfirmWindow = function() {
  1228.     this._confirmWindow = new Window_SaveConfirm();
  1229.     var win = this._confirmWindow;
  1230.     win.setHandler('confirm', this.onConfirmOk.bind(this));
  1231.     win.setHandler('cancel',  this.onConfirmCancel.bind(this));
  1232.     this.addWindow(this._confirmWindow);
  1233. };
  1234.  
  1235. Scene_File.prototype.onSavefileOk = function() {
  1236.     this._actionWindow.activate();
  1237.     if (this.mode() === 'load') {
  1238.       this._actionWindow.select(0);
  1239.     } else if (this.mode() === 'save') {
  1240.       this._actionWindow.select(1);
  1241.     }
  1242. };
  1243.  
  1244. Scene_Save.prototype.onSavefileOk = function() {
  1245.     Scene_File.prototype.onSavefileOk.call(this);
  1246. };
  1247.  
  1248. Scene_Load.prototype.onSavefileOk = function() {
  1249.     Scene_File.prototype.onSavefileOk.call(this);
  1250. };
  1251.  
  1252. Scene_File.prototype.onActionLoad = function() {
  1253.     if (Yanfly.Param.SaveConfirmLoad) {
  1254.       this.startConfirmWindow(Yanfly.Param.SaveConfirmLoadTx);
  1255.     } else {
  1256.       this.performActionLoad();
  1257.     }
  1258. };
  1259.  
  1260. Scene_File.prototype.performActionLoad = function() {
  1261.     if (DataManager.loadGame(this.savefileId())) {
  1262.         this.onLoadSuccess();
  1263.     } else {
  1264.         this.onLoadFailure();
  1265.     }
  1266. };
  1267.  
  1268. Scene_File.prototype.onLoadSuccess = function() {
  1269.     SoundManager.playLoad();
  1270.     this.fadeOutAll();
  1271.     this.reloadMapIfUpdated();
  1272.     SceneManager.goto(Scene_Map);
  1273.     this._loadSuccess = true;
  1274. };
  1275.  
  1276. Scene_Load.prototype.onLoadSuccess = function() {
  1277.     Scene_File.prototype.onLoadSuccess.call(this);
  1278. };
  1279.  
  1280. Scene_File.prototype.onLoadFailure = function() {
  1281.     SoundManager.playBuzzer();
  1282.     this.onActionCancel();
  1283. };
  1284.  
  1285. Scene_Load.prototype.onLoadFailure = function() {
  1286.     Scene_File.prototype.onLoadFailure.call(this);
  1287. };
  1288.  
  1289. Scene_File.prototype.reloadMapIfUpdated = function() {
  1290.   if ($gameSystem.versionId() === $dataSystem.versionId) return;
  1291.   $gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
  1292.   $gamePlayer.requestMapReload();
  1293. };
  1294.  
  1295. Scene_File.prototype.onActionSave = function() {
  1296.   var id = this.savefileId();
  1297.   if (Yanfly.Param.SaveConfirmSave && StorageManager.exists(id)) {
  1298.     this.startConfirmWindow(Yanfly.Param.SaveConfirmSaveTx);
  1299.   } else {
  1300.     this.performActionSave();
  1301.   }
  1302. };
  1303.  
  1304. Scene_File.prototype.performActionSave = function() {
  1305.     $gameSystem.onBeforeSave();
  1306.     if (DataManager.saveGame(this.savefileId())) {
  1307.       this.onSaveSuccess();
  1308.     } else {
  1309.       this.onSaveFailure();
  1310.     }
  1311. };
  1312.  
  1313. Scene_File.prototype.onSaveSuccess = function() {
  1314.     SoundManager.playSave();
  1315.     StorageManager.cleanBackup(this.savefileId());
  1316.     if (Yanfly.Param.SavePop) {
  1317.       this.popScene();
  1318.     } else {
  1319.       this._listWindow.refresh();
  1320.       this._actionWindow._currentFile = this.savefileId() - 1;
  1321.       this._infoWindow._currentFile = this.savefileId() - 1;
  1322.       this.onActionCancel();
  1323.     }
  1324. };
  1325.  
  1326. Scene_Save.prototype.onSaveSuccess = function() {
  1327.     Scene_File.prototype.onSaveSuccess.call(this);
  1328. };
  1329.  
  1330. Scene_File.prototype.onSaveFailure = function() {
  1331.     SoundManager.playBuzzer();
  1332.     this.onActionCancel();
  1333. };
  1334.  
  1335. Scene_Save.prototype.onSaveFailure = function() {
  1336.     Scene_File.prototype.onSaveFailure.call(this);
  1337. };
  1338.  
  1339. Scene_File.prototype.onActionDelete = function() {
  1340.     if (Yanfly.Param.SaveConfirmDel) {
  1341.       this.startConfirmWindow(Yanfly.Param.SaveConfirmDelTx);
  1342.     } else {
  1343.       this.performActionDelete();
  1344.     }
  1345. };
  1346.  
  1347. Scene_File.prototype.performActionDelete = function() {
  1348.     AudioManager.playSe(Yanfly.Param.SaveDeleteSound);
  1349.     StorageManager.remove(this.savefileId());
  1350.     this.onActionCancel();
  1351.     this._listWindow.refresh();
  1352.     this._actionWindow._currentFile = this.savefileId() - 1;
  1353.     this._infoWindow._currentFile = this.savefileId() - 1;
  1354. };
  1355.  
  1356. Scene_File.prototype.onActionCancel = function() {
  1357.     this._actionWindow.deselect();
  1358.     this._listWindow.activate();
  1359.     this._helpWindow.setText(Yanfly.Param.SaveHelpSelect);
  1360. };
  1361.  
  1362. Scene_File.prototype.startConfirmWindow = function(text) {
  1363.     SoundManager.playOk();
  1364.     this._confirmWindow.setData(text);
  1365.     this._confirmWindow.open();
  1366.     this._confirmWindow.activate();
  1367.     this._confirmWindow.select(0);
  1368. };
  1369.  
  1370. Scene_File.prototype.onConfirmOk = function() {
  1371.     this._confirmWindow.deactivate();
  1372.     this._confirmWindow.close();
  1373.     if (this._actionWindow.currentSymbol() === 'load') {
  1374.       setTimeout(this.performActionLoad.bind(this), 200);
  1375.     } else if (this._actionWindow.currentSymbol() === 'save') {
  1376.       setTimeout(this.performActionSave.bind(this), 200);
  1377.     } else if (this._actionWindow.currentSymbol() === 'delete') {
  1378.       setTimeout(this.performActionDelete.bind(this), 200);
  1379.     } else {
  1380.       this.onConfirmCancel();
  1381.     }
  1382. };
  1383.  
  1384. Scene_File.prototype.onConfirmCancel = function() {
  1385.     var index = this._actionWindow.index();
  1386.     this._confirmWindow.deactivate();
  1387.     this._confirmWindow.close();
  1388.     this.onSavefileOk();
  1389.     this._actionWindow.select(index);
  1390. };
  1391.  
  1392. //=============================================================================
  1393. // Utilities
  1394. //=============================================================================
  1395.  
  1396. Yanfly.Util = Yanfly.Util || {};
  1397.  
  1398. if (!Yanfly.Util.toGroup) {
  1399.     Yanfly.Util.toGroup = function(inVal) {
  1400.         return inVal;
  1401.     }
  1402. };
  1403.  
  1404. //=============================================================================
  1405. // End of File
  1406. //=============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement