Advertisement
Guest User

Minimap

a guest
Nov 24th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // SilvMinimap.js
  3. // Version: 1.01
  4. // Requires plugin: SilvKeys (place this one below it)
  5. //=============================================================================
  6. /*:
  7.  * @plugindesc v1.01 Minimap. <SilvMinimap>
  8.  * @author Silver
  9.  *
  10.  * @param Map Style
  11.  * @desc Is the minimap scaled to fit? Or does it zoom and scroll? Autofit/Scroll
  12.  * @default Scroll
  13.  *
  14.  * @param Global Map Zoom
  15.  * @desc Only applies if MapStyle is set to: Scroll. Determines the default zoom level for all maps. A value of 1 means 1:1.
  16.  * @default 0.25
  17.  *
  18.  * @param -- Positioning & Size --
  19.  *
  20.  * @param X
  21.  * @desc x-location of minimap window. If window-alignment is set to Right, this will act as an offset value instead
  22.  * @default -2
  23.  *
  24.  * @param Y
  25.  * @desc y-location of minimap window. If window-alignment is set to Top, this will act as an offset value instead
  26.  * @default 2
  27.  *
  28.  * @param Horizontal Alignment
  29.  * @desc Left/Right
  30.  * @default Right
  31.  *
  32.  * @param Vertical Alignment
  33.  * @desc Top/Bottom
  34.  * @default Bottom
  35.  *
  36.  * @param Width
  37.  * @desc width of the minimap
  38.  * @default 320
  39.  *
  40.  * @param Height
  41.  * @desc height of the minimap
  42.  * @default 320
  43.  *
  44.  * @param Border Width
  45.  * @desc Border width of the minimap
  46.  * @default 12
  47.  *
  48.  * @param Border Height
  49.  * @desc Border height of the minimap
  50.  * @default 12
  51.  *
  52.  * @param -- Menu --
  53.  *
  54.  * @param Menu Player Description
  55.  * @desc The description of the player marker in the menu. Spaces are allowed.
  56.  * @default You
  57.  *
  58.  * @param Menu Zoom
  59.  * @desc Map Zoomlevel for the menu
  60.  * @default 0.3. A value of 1 means 1:1
  61.  *
  62.  * @param Menu Left Window Width
  63.  * @desc Width of the left window
  64.  * @default 240
  65.  *
  66.  * @param Menu Topright Window Height
  67.  * @desc Height of the topright window
  68.  * @default 510
  69.  *
  70.  * @param Menu Event Render Size
  71.  * @desc How big the events are that are drawn onto the menu map
  72.  * @default 24
  73.  *
  74.  * @param Menu Player Icon Size
  75.  * @desc How big the player is drawn onto the menu map
  76.  * @default 64
  77.  *
  78.  * @param Menu Min Manual Zoom
  79.  * @desc How far the player can zoom out
  80.  * @default 0.20
  81.  *
  82.  * @param Menu Max Manual Zoom
  83.  * @desc How far the player can zoom in
  84.  * @default 10.0
  85.  *
  86.  * @param Menu Zoomin Key
  87.  * @desc Key for zooming in. 33 = pageup
  88.  * @default pageup
  89.  *
  90.  * @param Menu Zoomout Key
  91.  * @desc Key for zooming out. 34 = pagedown
  92.  * @default pagedown
  93.  *
  94.  * @param Menu Reset Zoom Key
  95.  * @desc Key for resetting the zoom. 36 = home
  96.  * @default home
  97.  *
  98.  * @param Menu Reset Scroll Key
  99.  * @desc Key to reset the mapscroll
  100.  * @default end
  101.  *
  102.  * @param -- The rest --
  103.  *
  104.  * @param Allow Teleportation
  105.  * @desc By default, allow teleportation to events/poi's that support it? true/falee
  106.  * @default true
  107.  *
  108.  * @param Standard Padding
  109.  * @desc Standard Window Padding. Best to leave at 0
  110.  * @default 0
  111.  *
  112.  * @param Window Skin
  113.  * @desc Name of the window skin to use for this window
  114.  * @default Window_Minimap
  115.  *
  116.  * @param Player Icon Width
  117.  * @desc Standard Window Padding
  118.  * @default 16
  119.  *
  120.  * @param Player Icon Height
  121.  * @desc Standard Window Padding
  122.  * @default 16
  123.  *
  124.  * @param Draw Player Icon
  125.  * @desc Draw player on the map? true/false
  126.  * @default true
  127.  *
  128.  * @param Player Blink Delay
  129.  * @desc Blinks the player icon (in frames). Set to 0 to disable. Does nothing if "Draw Player Icon" is set to false
  130.  * @default 0
  131.  *
  132.  * @param Fill Color
  133.  * @desc Color to fill the background of the minimap with for 'odd aspect ratios'. Use 0 0 0 0 to disable. R G B A.
  134.  * @default 0 0 0 255
  135.  *
  136.  * @param Maintain Aspect Ratio
  137.  * @desc Maintains minimap aspect ratio if set to true. true/false
  138.  * @default true
  139.  *
  140.  * @param Fadeout Speed
  141.  * @desc How fast the minimap fades out
  142.  * @default 3
  143.  *
  144.  * @param Global Required Item
  145.  * @desc Item ID of the item that the player must have in their INVENTORY for any map to be displayed. Requires map to be reloaded if item is acquired or call the plugin command "Minimap Refresh" (w/o quotes). A value of 0 disables this
  146.  * @default 0
  147.  *
  148.  * @param Event Render Size
  149.  * @desc How big the events are that are drawn onto the minimap
  150.  * @default 16
  151.  *
  152.  * @param Auto Clear POI
  153.  * @desc Automatically clear POI's between map transfers? true/false
  154.  * @default false
  155.  *
  156.  * @param Render Minimap Overlay
  157.  * @desc If enabled, add the image: /img/Minimap/Overlay.png and it will be drawn on top of the minimap. true/false
  158.  * @default true
  159.  *
  160.  * @param -- Manual Scrolling --
  161.  *
  162.  * @param Allow Manual Scrolling
  163.  * @desc true/false
  164.  * @default true
  165.  *
  166.  * @param Manual Scrollspeed
  167.  * @desc How fast the map is scrolled
  168.  * @default 24
  169.  *
  170.  * @param Manual Scroll Key Up
  171.  * @desc Key for scrolling the map upwards. Default: u  http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
  172.  * @default u
  173.  *
  174.  * @param Manual Scroll Key Right
  175.  * @desc Key for scrolling the map upwards. Default: k
  176.  * @default k
  177.  *
  178.  * @param Manual Scroll Key Down
  179.  * @desc Key for scrolling the map upwards. Default: j
  180.  * @default j
  181.  *
  182.  * @param Manual Scroll Key Left
  183.  * @desc Key for scrolling the map upwards. Default: h
  184.  * @default h
  185.  *
  186.  * @param -- Advanced & Debug --
  187.  *
  188.  * @param Player Sprite Sourceframe Width
  189.  * @desc Width of the playersprite sourceframe
  190.  * @default 48
  191.  *
  192.  * @param Player Sprite Sourceframe Height
  193.  * @desc Heigth of the playersprite sourceframe
  194.  * @default 48
  195.  *
  196.  * @param Frame Skip
  197.  * @desc Skips some minimap calculations&rendering if set to value > 0 to safe performance. The value equals the amount of frames skipped.
  198.  * @default 0
  199.  *
  200.  * @param Mapshot Filename Length
  201.  * @desc Length of the mapshot filenames. A value of 3 would equal to: 001.png, 002.png, 016.png, etc. And a value of 2 would equal: 01.png, etc. A value of 0 disables it
  202.  * @default 3
  203.  *
  204.  * @param Debug Mode
  205.  * @desc Prints extra info if set to true. true/false
  206.  * @default false
  207.  *
  208.  * @param Render Debug Grid
  209.  * @desc Draws a debug grid. Requires "/img/Minimap/DebugGrid.png" which is 48x48 in size. Drains a lot of performance!
  210.  * @default false
  211.  *
  212.  * @param Debug Grid Image
  213.  * @desc Name of the debug-grid image
  214.  * @default DebugGrid01
  215.  *
  216.  * @help
  217.  * 1. Make a mapshot of your map. You may use http://forums.rpgmakerweb.com/index.php?/topic/49711-orange-mapshot/
  218.  * 2. Install this script: http://pastebin.com/FF6jh3S0 and make sure to put it above the minimap script.
  219.  * 3. Copy the files to:
  220.  * 4. /img/minimap/Overlay.png
  221.  * 5. /img/minimap/DebugGrid01.png
  222.  * 6. /img/system/Window_Minimap.png
  223.  * 7. Place your mapshots in the /img/minimap/ directory and rename them 001.png, 002.png etc. (matching the id of your map)
  224.  *
  225.  * To show the menu make a script call and place this in it (you can place this in a common event):
  226.  * Silv.Minimap.Window.pushMapScene();
  227.  *
  228.  *--------------------------------------
  229.  * Map notetags (case sensitive!)
  230.  *--------------------------------------
  231.  * <mm_req_itm:item_id1 item_id2 etc>
  232.  * Example: <mm_req_itm:1, 2, 3>
  233.  *
  234.  * <mm_frameskip:value>
  235.  * Example: <mm_frameskip:1>
  236.  * Note: overrides the global frameskip parameter for this map
  237.  *
  238.  * <mm_mapzoom:value>
  239.  * Example: <mm_mapzoom:0.15>
  240.  * Note: overrides the global mapzoom parameter for this map
  241.  *
  242.  * <mm_allowmanualscroll:value>
  243.  * Example: <mm_allowmanualscroll:false>
  244.  * Allowed values: true/false
  245.  * Note: overrides the global "Allow Manual Scrolling" parameter for this map
  246.  *
  247.  * <mm_menuzoom:value>
  248.  * Example: <mm_menuzoom:0.75>
  249.  * Note: overrides the global "Menu Zoom" parameter for this map
  250.  *
  251.  * <mm_size:x y>
  252.  * Example: <mm_size:128 128>
  253.  * Note: overrides the global "Width" and "Height" parameters for this map
  254.  *
  255.  * Allow/disallow teleportation.
  256.  * <mm_tp_allow:value>
  257.  * Example: <mm_tp_allow:false>
  258.  * Note: overrides the global "Allow Teleportation" parameter for this map
  259.  *
  260.  *--------------------------------------
  261.  * Event notetags (not case sensitive)
  262.  *--------------------------------------
  263.  * mm_show
  264.  *
  265.  *--------------------------------------
  266.  * Plugin Commands (not case-sensitive)
  267.  *--------------------------------------
  268.  * Minimap Hide
  269.  * Minimap Show
  270.  * Minimap FadeOut
  271.  * Minimap FadeReset
  272.  * Minimap Refresh
  273.  * Minimap RefreshEvents
  274.  * Minimap IncreaseScroll <x> <y>
  275.  * Minimap SetScroll <x> <y>
  276.  * Minimap DeletePOI <poi_id>
  277.  *
  278.  * Minimap POIDesc <description>
  279.  * Example: Minimap POIDesc An Awesome City!
  280.  *
  281.  * Minimap POI_TP <poi_id x_offset y_offset direction fadeType>
  282.  * Example: Minimap POI_TP 1 1 0 0 0
  283.  * Note that teleporting with both offsets set to 0, will teleport the player straight into the center of the poi.
  284.  *
  285.  * Adding POI's (advanced plugin command!):
  286.  * Minimap AddPOI unique_poi_id, name, real_x, real_y, bitmap folder, bitmap filename, s_x, s_y, s_w, s_h, draw_w, draw_h
  287.  * Example that draws Actor1_3 on tile 10,10:
  288.  * Minimap AddPOI 1 A_Friend 10 10 img/enemies/ Actor1_3 0 0 254 225 64 64
  289.  * Note:
  290.  * - The real_x & real_y are in maptiles and not in coordinates. 0,0 is in the upper left corner.
  291.  * - name-value replaces underscores _  with spaces.
  292.  *
  293.  
  294.  *
  295.  *--------------------------------------
  296.  * Comment-tags (case sentitive!)
  297.  *--------------------------------------
  298.  * To show an event on the minimap:
  299.  * <mm_show>
  300.  *
  301.  * To add a description to an event (for the minimap-scene)
  302.  * <mm_desc>
  303.  *
  304.  * To add teleport to the event:
  305.  * <mm_tp:offset_x offset_y direction fadeType>
  306.  * Example: <mm_tp:1 0 2 0>
  307.  * Notes:
  308.  *        - Offset is the offset in tiles with the event-location itself being 0 0
  309.  *        - Possible direction values: 2 (down), 4 (left), 6 (right), 8 (up). Or use a value of 0 to maintain the current player-facing-direction
  310.  *        - Possible fadeType values: 0 (black), 1 (white), 2 (none)
  311.  *
  312.  *
  313.  * Note to other scripters: You can access the variable that contains the window through this: "Silv.Minimap.Window" w/o the quotes.
  314.  *
  315.  *
  316.  *--------------------------------------
  317.  * Version History:
  318.  *--------------------------------------
  319.  * v.1.01 (24 November 2015) [Updated Parameters]
  320.  *   - Fixed the player-blip becoming invisible when walking on grass. Because of this I had to add 2 more advanced parameters.
  321.  *   - Fixed: The minimap no longer automatically shows itself again when it was manually hidden after opening a menu.
  322.  *   - Updated the version number to 1.01 (it was still 0.91) in the plugin description.
  323.  *   - Cleaned up some more out-commented code.
  324.  *   - Fixed: minimap can now hide again when it contains POI's.
  325.  *   - Fixed a bug that would not 'dispose' the minimap-window when getting rid of a minimap within a scene because the Scene_Map still had a references in it's children to the map. This also increases performance.
  326.  *
  327.  * v1.00 (23 November 2015)
  328.  *   - First release.
  329.  *
  330.  * v0.90-0.92 (November 2015)
  331.  *   - First alpha release.
  332.  *
  333.  */
  334.  
  335. // Get Plugin #Parameters
  336. var Silv = Silv || {};
  337. Silv.Plugins = Silv.Plugins || {};
  338. Silv.Plugins.Minimap = 1.01;
  339. if (!('Keys' in Silv.Plugins) || Silv.Plugins.Keys < 1.00) { throw 'ERROR: Silvers Minimap requires Silvers KeyMapper v1.00 or higher. It must be placed above the minimap script.'; }
  340. Silv.Parameters = $plugins.filter(function(p) { return p.description.contains('<SilvMinimap>'); })[0].parameters;
  341. Silv.Minimap = Silv.Minimap || {};
  342. Silv.Minimap.Menu = Silv.Minimap.Menu || {};
  343. // Non-parameters
  344. Silv.Minimap.Window = null;
  345. Silv.Minimap.POI = {};
  346. Silv.Minimap.Events = new Array(); // Is an array of objects [{ Game_Event, Sprite_Character }]. USe .event and .sprite to retrieve the values.
  347. Silv.Minimap.ScreenIsFading = false;
  348. Silv.Minimap.Menu.Bmp = null;
  349. Silv.Minimap.Menu.Markers = new Array();
  350. Silv.Minimap.WasLoadedFromSave = false;
  351. Silv.Minimap.LastMapID = -1; // To detect when a different map is loaded. Because loading the menu-scene for example will reload the entire map again and also recreate the minimap, but we don't want to erase the POI's and such then.
  352. Silv.Minimap.TP_Dest = null;
  353. Silv.Minimap.CreateFunctionIsLocked = false;
  354. // Minimap Style and Zoom
  355. Silv.Minimap.MapStyle = Silv.Parameters['Map Style'].toLowerCase();
  356. Silv.Minimap.GlobalMapZoom = parseFloat(Silv.Parameters['Global Map Zoom']);
  357. // Positioning & Size
  358. Silv.Minimap.Window_X = parseInt(Silv.Parameters['X']);
  359. Silv.Minimap.Window_Y = parseInt(Silv.Parameters['Y']);
  360. Silv.Minimap.WindowWidth = parseInt(Silv.Parameters['Width']);
  361. Silv.Minimap.WindowHeight = parseInt(Silv.Parameters['Height']);
  362. Silv.Minimap.BorderWidth = parseInt(Silv.Parameters['Border Width']);
  363. Silv.Minimap.BorderHeight = parseInt(Silv.Parameters['Border Height']);
  364. Silv.Minimap.WindowHorizontalAlignment = Silv.Parameters['Horizontal Alignment'].toLowerCase();
  365. Silv.Minimap.WindowVerticalAlignment = Silv.Parameters['Vertical Alignment'].toLowerCase();
  366. // Menu
  367. Silv.Minimap.Menu.PlayerDesc = Silv.Parameters['Menu Player Description'];
  368. Silv.Minimap.Menu.Zoom = parseFloat(Silv.Parameters['Menu Zoom']);
  369. Silv.Minimap.Menu.WindowWidth_Left = parseInt(Silv.Parameters['Menu Left Window Width']);
  370. Silv.Minimap.Menu.WindowHeight_MapSection = parseInt(Silv.Parameters['Menu Topright Window Height']);
  371. Silv.Minimap.Menu.EventRenderSize = parseInt(Silv.Parameters['Menu Event Render Size']);
  372. Silv.Minimap.Menu.PlayerIconSize = parseInt(Silv.Parameters['Menu Player Icon Size']);
  373. Silv.Minimap.Menu.ManualZoom_Min = parseFloat(Silv.Parameters['Menu Min Manual Zoom']);
  374. Silv.Minimap.Menu.ManualZoom_Max = parseFloat(Silv.Parameters['Menu Max Manual Zoom']);
  375. Silv.Minimap.Menu.ManualZoomKey_In = Silv.Keys.fromStringParam(Silv.Parameters['Menu Zoomin Key']);
  376. Silv.Minimap.Menu.ManualZoomKey_Out = Silv.Keys.fromStringParam(Silv.Parameters['Menu Zoomout Key']);
  377. Silv.Minimap.Menu.ManualZoomKey_Reset = Silv.Keys.fromStringParam(Silv.Parameters['Menu Reset Zoom Key']);
  378. Silv.Minimap.Menu.ManualScrollKey_Reset = Silv.Keys.fromStringParam(Silv.Parameters['Menu Reset Scroll Key']);
  379. // The Rest
  380. Silv.Minimap.AllowTeleportation = Silv.Parameters['Allow Teleportation'].toLowerCase() == 'true';
  381. Silv.Minimap.StandardPadding = parseInt(Silv.Parameters['Standard Padding']);
  382. Silv.Minimap.WindowSkin = Silv.Parameters['Window Skin'];
  383. Silv.Minimap.PlayerIconWidth = parseInt(Silv.Parameters['Player Icon Width']);
  384. Silv.Minimap.PlayerIconHeight = parseInt(Silv.Parameters['Player Icon Height']);
  385. Silv.Minimap.DrawPlayerIcon = Silv.Parameters['Draw Player Icon'].toLowerCase() == 'true';
  386. Silv.Minimap.PlayerBlinks = parseInt(Silv.Parameters['Player Blink Delay']) > 0;
  387. Silv.Minimap.PlayerBlinkDelay = parseInt(Silv.Parameters['Player Blink Delay']);
  388. Silv.Minimap.MapBGFillColor = Silv.Parameters['Fill Color'].split(' ');
  389. Silv.Minimap.MaintainAspectRatio = Silv.Parameters['Maintain Aspect Ratio'].toLowerCase() == 'true';
  390. Silv.Minimap.FadeoutSpeed = parseInt(Silv.Parameters['Fadeout Speed']);
  391. Silv.Minimap.GlobalRequiredItem = parseInt(Silv.Parameters['Global Required Item']);
  392. Silv.Minimap.EventRenderSize = parseInt(Silv.Parameters['Event Render Size']);
  393. Silv.Minimap.AutoClearPOI = Silv.Parameters['Auto Clear POI'].toLowerCase() == 'true';
  394. Silv.Minimap.DrawOverlay = Silv.Parameters['Render Minimap Overlay'].toLowerCase() == 'true';
  395. // Manual Scrolling
  396. Silv.Minimap.AllowManualScrolling = Silv.Parameters['Allow Manual Scrolling'].toLowerCase() == 'true';
  397. Silv.Minimap.ManualScrollspeed = parseFloat(Silv.Parameters['Manual Scrollspeed']);
  398. Silv.Minimap.ManualScrollKeyUp = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Up']);
  399. Silv.Minimap.ManualScrollKeyRight = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Right']);
  400. Silv.Minimap.ManualScrollKeyDown = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Down']);
  401. Silv.Minimap.ManualScrollKeyLeft = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Left']);
  402. // Advanced & Debug
  403. Silv.Minimap.PlayerSpriteSrcFrame_Width = parseInt(Silv.Parameters['Player Sprite Sourceframe Width']);
  404. Silv.Minimap.PlayerSpriteSrcFrame_Height = parseInt(Silv.Parameters['Player Sprite Sourceframe Height']);
  405. Silv.Minimap.FrameSkip = parseInt(Silv.Parameters['Frame Skip']);
  406. Silv.Minimap.MapFilenameLength = parseInt(Silv.Parameters['Mapshot Filename Length']);
  407. Silv.Minimap.DebugMode = Silv.Parameters['Debug Mode'].toLowerCase() == 'true';
  408. Silv.Minimap.DrawDebugGrid = Silv.Parameters['Render Debug Grid'].toLowerCase() == 'true';
  409. Silv.Minimap.DebugGridImage = Silv.Parameters['Debug Grid Image'];
  410. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  411. (function()
  412. {
  413. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  414. // Utilities & Misc
  415. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  416. // Example: lpad('2', '0') // result: '002'
  417. function lpad_mapname(word, padStr)
  418. {
  419.     word = String(word);
  420.     while (word.length < Silv.Minimap.MapFilenameLength) word = padStr + word;
  421.     return word;
  422. }
  423.  
  424. function minimapFolderPath()
  425. {
  426.     var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, "/img/minimap/");
  427.     if (path.match(/^\/([A-Z]\:)/)) { path = path.slice(1); }
  428.     path = decodeURIComponent(path);
  429.     return path;
  430. }
  431.  
  432. // filename example: '002.png'
  433. function minimapImageExists(filename)
  434. {
  435.     var filename = minimapFolderPath() + filename;
  436.     var fs = require('fs');
  437.     return fs.existsSync(filename);
  438. }
  439.  
  440. function dataMapGetEventByID(ev_id)
  441. {
  442.     for(var i=1; i< $dataMap.events.length; i++)
  443.     {
  444.         if ($dataMap.events[i].id == ev_id) { return $dataMap.events[i]; }
  445.     }
  446.     return null;
  447. }
  448.  
  449. ImageManager.loadMinimap = function(filename, hue)
  450. {
  451.     return this.loadBitmap('img/minimap/', filename, hue, false);
  452. };
  453.  
  454. // Do not just show the minimap on top of a faded-out screen.
  455. var alias_silv_mm_updateFadeOut = Game_Screen.prototype.updateFadeOut;
  456. Game_Screen.prototype.updateFadeOut = function() {
  457.     alias_silv_mm_updateFadeOut.call(this);
  458.    
  459.     if (this._brightness < 255) // (this._fadeOutDuration > 0)
  460.     {
  461.         Silv.Minimap.ScreenIsFading = true;
  462.         Silv.Minimap.Window.opacity = this._brightness;
  463.         Silv.Minimap.Window.contents.paintOpacity  = this._brightness;
  464.     }
  465.     else
  466.     {
  467.         Silv.Minimap.ScreenIsFading = false;
  468.     }
  469. };
  470.  
  471. //------------------------------------------------------------------------------------------------------------------------------------
  472. // Store a reference to the player graphic.
  473. //------------------------------------------------------------------------------------------------------------------------------------
  474. var alias_silv_mm_createCharacters = Spriteset_Map.prototype.createCharacters;
  475. Spriteset_Map.prototype.createCharacters = function()
  476. {
  477.     alias_silv_mm_createCharacters.call(this);
  478.    
  479.     for (var i = this._characterSprites.length - 1; i >= 0; i--)
  480.     {
  481.         if (this._characterSprites[i]._character == $gamePlayer)
  482.         {
  483.             Spriteset_Map.prototype.playerSprite = this._characterSprites[i];
  484.             break;
  485.         }  
  486.     }
  487. };
  488. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  489. // Automatically create a event-Notetag from event-comments on the active page
  490. // Example usage: console.log($gameMap.event(1).event.silvNote);
  491. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  492. var alias_silv_mm_Game_Event_setupPage = Game_Event.prototype.setupPage;
  493. Game_Event.prototype.setupPage = function()
  494. {
  495.     alias_silv_mm_Game_Event_setupPage.call(this);
  496.     this.silvCreateNote();
  497. };
  498.  
  499. Game_Event.prototype.silvCreateNote = function()
  500. {
  501.     this.silvNote = '';
  502.     if (typeof this.page() === 'undefined') { return; }
  503.    
  504.     var list = this.list();
  505.     str = null;
  506.     for (var commandProperty in list)
  507.     {
  508.         if (list.hasOwnProperty(commandProperty))
  509.         {
  510.             var command = list[commandProperty];
  511.             var commandCode = command.code;
  512.             if (commandCode == 108) // 108: new comment-item, always the first line.
  513.             {
  514.                 if (str != null) { this.silvNote += str; }
  515.                 str = command.parameters[0];
  516.             }
  517.             else if (commandCode == 408) // 408: comment-line, but not the first one.
  518.             {
  519.                 this.silvNote += command.parameters[0];
  520.             }
  521.             else if (str) // It's not a comment-code, so add the previous str (if any) to the note.
  522.             {
  523.                 this.silvNote += str;
  524.                 str = null;
  525.             }
  526.         }
  527.     }
  528.     if (this.silvNote != '') {this.extractSilvMetadata()};
  529. };
  530.  
  531. // <mm_tp:1> will result in: '1'
  532. // <mm_tp:1> will result in: ['1', '0'];
  533. Game_Event.prototype.extractSilvMetadata = function() {
  534.     var re = /<([^<>:]+)(:?)([^>]*)>/g;
  535.     this.meta = {};
  536.     for (;;)
  537.     {
  538.         var match = re.exec(this.silvNote);
  539.         if (match)
  540.         {
  541.             if (match[2] === ':')
  542.             {
  543.                 var value = match[3];
  544.                 if (match[3].indexOf(' ') >= 0) { value = match[3].split(' '); }
  545.                
  546.                 this[match[1]] = value;
  547.             }
  548.             else
  549.             {
  550.                 this[match[1]] = true;
  551.             }
  552.         }
  553.         else
  554.         {
  555.             break;
  556.         }
  557.     }
  558. };
  559. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  560. // Minimap Window
  561. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  562. function Window_Minimap() { this.initialize.apply(this, arguments); }
  563. // Inherit from base window
  564. Window_Minimap.prototype = Object.create(Window_Base.prototype);
  565. // Set Constructor
  566. Window_Minimap.prototype.constructor = Window_Minimap;
  567.  
  568. Window_Minimap.prototype.loadWindowskin = function() { this.windowskin = ImageManager.loadSystem(Silv.Minimap.WindowSkin); }
  569. Window_Minimap.prototype.standardPadding = function() { return Silv.Minimap.StandardPadding; }
  570. //Window_Minimap.prototype.standardFontSize = function() { return Silv.Minimap.FontSize; }
  571.  
  572. var mapBmp;
  573. var drawAreaWidth;
  574. var drawAreaHeight;
  575. var mapWidth
  576. var mapHeight;
  577. var playerBlinkCnt;
  578. var playerBlink_IsVisible;
  579. var frameSkip;
  580. var frameSkipCnt;
  581. var mapAspRatInfo;
  582. var mapZoom;
  583. var mapZoomInverse;
  584. var isManualScrolling;
  585. var allowManualScroll;
  586. var mapScroll;
  587. var lastPlayerLoc;
  588. var isFirstProcessedUpdate;
  589. var debugGridBmp;
  590. var overlayBmp;
  591. var menuZoom;
  592. var allowTeleportation;
  593. var playerFrame;
  594. var playerInfo;
  595.  
  596. // #Initialization
  597. Window_Minimap.prototype.initialize = function(x, y, width, height)
  598. {
  599.     if ('mm_size' in $dataMap.meta)
  600.     {
  601.         var newSize = $dataMap.meta.mm_size.split(' ');
  602.         width = parseInt(newSize[0]);
  603.         heigth = parseInt(newSize[1]);
  604.     }
  605.    
  606.     Window_Base.prototype.initialize.call(this, x, y, width, height);
  607.     this._helpWindow = null;
  608.     this._handlers = {};
  609.     this._touching = false;
  610.     this.deactivate();
  611.    
  612.     this.isFadingOut = false;
  613.     this.isFadedOut = false;
  614.     this.mapBmp = ImageManager.loadMinimap(lpad_mapname($gameMap._mapId, '0'));
  615.     this.overlayBmp = ImageManager.loadMinimap('Overlay');
  616.     this.drawAreaWidth = this.contents.width - Silv.Minimap.BorderWidth * 2;
  617.     this.drawAreaHeight = this.contents.height - Silv.Minimap.BorderHeight * 2;
  618.     this.mapWidth = parseFloat($gameMap.width());
  619.     this.mapHeight = parseFloat($gameMap.height());
  620.     this.setAspectRatio();
  621.     this.playerBlinkCnt = Silv.Minimap.PlayerBlinkDelay;
  622.     this.playerBlink_IsVisible = true;
  623.     this.frameSkip = Silv.Minimap.FrameSkip;
  624.     this.frameSkipCnt = 0;
  625.    
  626.     this.mapZoom = Silv.Minimap.GlobalMapZoom;
  627.     if ('mm_mapzoom' in $dataMap.meta) { this.mapZoom = parseFloat($dataMap.meta.mm_mapzoom); }
  628.     this.mapZoomInverse = 1 / this.mapZoom;
  629.     this.isFirstProcessedUpdate = true;
  630.    
  631.     this.isManualScrolling = false;
  632.     this.allowManualScroll = Silv.Minimap.AllowManualScrolling;
  633.     if ('mm_allowmanualscroll' in $dataMap.meta) { this.allowManualScroll = $dataMap.meta.mm_allowmanualscroll == 'true'; }
  634.     this.mapScroll = {x: 0, y: 0, adjustment_x: 0, adjustment_y: 0};
  635.     this.lastPlayerLoc = {x: $gamePlayer._realX, y: $gamePlayer._realY};
  636.     this.menuZoom = Silv.Minimap.Menu.Zoom;
  637.     if ('mm_menuzoom' in $dataMap.meta) { this.menuZoom = $dataMap.meta.mm_menuzoom == 'true'; }
  638.     this.allowTeleportation = Silv.Minimap.AllowTeleportation;
  639.     if ('mm_tp_allow' in $dataMap.meta) { this.allowTeleportation = $dataMap.meta.mm_tp_allow == 'true'; }
  640.     this.playerFrame = {x:0, y:0, width:Silv.Minimap.PlayerSpriteSrcFrame_Width, height:Silv.Minimap.PlayerSpriteSrcFrame_Height};
  641.    
  642.     this.loadEvents(); 
  643.     this.debugGridBmp = ImageManager.loadMinimap(Silv.Minimap.DebugGridImage);
  644.        
  645.     // The update must be called AFTER all the initialization code.
  646.     this.update();
  647. };
  648.  
  649. Window_Minimap.prototype.clamp = function(value, min, max)
  650. {
  651.     return Math.min(Math.max(value, min), max);
  652. };
  653.    
  654. // This function requires this.mapBmp to be fully initialized.
  655. // #Aspect #Ratio #AspectRatio
  656. Window_Minimap.prototype.setAspectRatio = function()
  657. {
  658.     // this.mapAspRatInfo.scaleDelta_x is the difference in size between the mapwidth (in pixels, NOT in tiles) and the minimap (render)width.
  659.     this.mapAspRatInfo = { w: 0.0, h: 0.0, offset_x: 0.0, offset_y: 0.0, scaleDelta_x: 0.0, scaleDelta_y: 0.0 }
  660.     var w = $gameMap.width();
  661.     var h = $gameMap.height();
  662.    
  663.     // Map Aspect Ratio
  664.     if (!Silv.Minimap.MaintainAspectRatio || (w == h))
  665.     {
  666.         this.mapAspRatInfo.w = 1.0;
  667.         this.mapAspRatInfo.h = 1.0;
  668.     }
  669.     else if (w > h)
  670.     {
  671.         this.mapAspRatInfo.w = 1.0;
  672.         this.mapAspRatInfo.h = h / parseFloat(w);
  673.     }
  674.     else // if (h > w)
  675.     {
  676.         this.mapAspRatInfo.w = w / parseFloat(h);
  677.         this.mapAspRatInfo.h = 1.0;
  678.     }
  679.    
  680.     this.mapAspRatInfo.scaleDelta_x = this.drawAreaWidth / parseFloat($gameMap.width() * $gameMap.tileWidth());
  681.     this.mapAspRatInfo.scaleDelta_y = this.drawAreaHeight / parseFloat($gameMap.height() * $gameMap.tileHeight());
  682. };
  683.  
  684. // #Events
  685. Window_Minimap.prototype.loadEvents = function()
  686. {
  687.     Silv.Minimap.Events = new Array();
  688.     for (ev_idx = 1; ev_idx < $dataMap.events.length; ev_idx++) // Note: start at 1. Because the first one is always null.
  689.     {
  690.         if ($dataMap.events[ev_idx] != null)
  691.         {
  692.             var ev = $gameMap.event(ev_idx);
  693.            
  694.             // Check Event Note
  695.             if ($dataMap.events[ev_idx].note != '' || ('mm_show' in ev))
  696.             {
  697.                 var cmds = $dataMap.events[ev_idx].note.toLowerCase().split(' ');
  698.                 if ((cmds.indexOf('mm_show') > -1) ||  ('mm_show' in ev))
  699.                 {
  700.                     var new_ev = {event: ev, sprite: this.getEventCharacterSprite(ev.eventId())};
  701.                     Silv.Minimap.Events.push(new_ev); // Add event to the array so we can render it on the minimap
  702.                 }
  703.             }
  704.         }
  705.     }
  706.     if (Silv.Minimap.DebugMode) { console.log('Loaded Events:'); console.log(Silv.Minimap.Events); }
  707. };
  708.  
  709. Window_Minimap.prototype.getEventCharacterSprite = function(ev_id)
  710. {
  711.     for (var i=0; i < SceneManager._scene._spriteset._characterSprites.length; i++)
  712.     {
  713.         var eventSprite = SceneManager._scene._spriteset._characterSprites[i];
  714.         if (eventSprite._character.eventId() == ev_id)
  715.         {
  716.             return eventSprite;
  717.         }
  718.     }
  719.     throw 'getEventCharacterSprite() did not find a match for ev_id: ' + ev_id;
  720. };
  721.    
  722. // #update
  723. Window_Minimap.prototype.update = function()
  724. {
  725.     if (!this.skipFrame() && this.mapBmp.isReady())
  726.     {
  727.         Window_Base.prototype.update.call(this);
  728.         this.updateFadeOut();
  729.         this.updateInput();
  730.         if (Silv.Minimap.PlayerBlinks) { this.updatePlayerBlink(); }
  731.         this.updateMapScroll(this.isFirstProcessedUpdate);
  732.         this.playerInfo = this.getPlayerBitmap();
  733.         this.drawMinimap();
  734.         this.lastPlayerLoc.x  = $gamePlayer._realX;
  735.         this.lastPlayerLoc.y  = $gamePlayer._realY;
  736.         this.isFirstProcessedUpdate = false;
  737.        
  738.         // Teleport
  739.         if (Silv.Minimap.TP_Dest != null)
  740.         {
  741.             this.teleport(Silv.Minimap.TP_Dest);
  742.             Silv.Minimap.TP_Dest = null;
  743.         }
  744.     }
  745. };
  746.  
  747. Window_Minimap.prototype.getPlayerBitmap = function()
  748. {
  749.     var playerSpr = Spriteset_Map.prototype.playerSprite;
  750.     // Player is not in bush, so return the regular player-graphic
  751.     if (playerSpr._bushDepth == 0 || playerSpr._lowerBody == null) { return {bmp:playerSpr._bitmap, src:playerSpr._frame} };
  752.  
  753.     // Create Bush graphic (which is divided into 2 graphics by the RM-code..)
  754.     var playerBmp = new Bitmap(Silv.Minimap.PlayerSpriteSrcFrame_Width, Silv.Minimap.PlayerSpriteSrcFrame_Height);
  755.     playerBmp.blt(Spriteset_Map.prototype.playerSprite._lowerBody._bitmap, Spriteset_Map.prototype.playerSprite._lowerBody._frame.x, Spriteset_Map.prototype.playerSprite._lowerBody._frame.y, Spriteset_Map.prototype.playerSprite._lowerBody._frame.width, Spriteset_Map.prototype.playerSprite._lowerBody._frame.height,
  756.                   0, Silv.Minimap.PlayerSpriteSrcFrame_Height - playerSpr._bushDepth, Silv.Minimap.PlayerIconSize, Silv.Minimap.PlayerIconSize);
  757.     playerBmp.blt(Spriteset_Map.prototype.playerSprite._upperBody._bitmap, Spriteset_Map.prototype.playerSprite._upperBody._frame.x, Spriteset_Map.prototype.playerSprite._upperBody._frame.y, Spriteset_Map.prototype.playerSprite._upperBody._frame.width, Spriteset_Map.prototype.playerSprite._upperBody._frame.height,
  758.                   0, 0, Silv.Minimap.PlayerIconSize, Silv.Minimap.PlayerIconSize);
  759.    
  760.     return {bmp:playerBmp, src:this.playerFrame};
  761. };
  762.  
  763. Window_Minimap.prototype.updateInput = function()
  764. {
  765.     if (Input.isPressed(Silv.Minimap.ManualScrollKeyUp))    { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x, Silv.Minimap.Window.mapScroll.y - Silv.Minimap.ManualScrollspeed); }
  766.     if (Input.isPressed(Silv.Minimap.ManualScrollKeyRight)) { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x + Silv.Minimap.ManualScrollspeed, Silv.Minimap.Window.mapScroll.y); }
  767.     if (Input.isPressed(Silv.Minimap.ManualScrollKeyDown))  { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x, Silv.Minimap.Window.mapScroll.y + Silv.Minimap.ManualScrollspeed); }
  768.     if (Input.isPressed(Silv.Minimap.ManualScrollKeyLeft))  { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x - Silv.Minimap.ManualScrollspeed, Silv.Minimap.Window.mapScroll.y); }
  769. };
  770.  
  771. Window_Minimap.prototype.teleport = function(tp_info)
  772. {
  773.     var direction = $gamePlayer._direction;
  774.     if (tp_info[2] != 0) { direction = parseInt(tp_info[2]); }
  775.  
  776.     $gamePlayer.reserveTransfer($gameMap._mapId, tp_info[0], tp_info[1], direction, parseInt(tp_info[3]));
  777. };
  778.  
  779. Window_Minimap.prototype.playerLocChanged = function()
  780. {
  781.     return this.lastPlayerLoc.x != $gamePlayer._realX || this.lastPlayerLoc.y != $gamePlayer._realY;
  782. };
  783.  
  784. // #Scroll
  785. Window_Minimap.prototype.updateMapScroll = function(force)
  786. {
  787.     if (this.playerLocChanged() || force) // Only update mapscroll if the player changed location. This way manual-scrolling is made possible.
  788.     {  
  789.         this.isManualScrolling = false;
  790.         this.setMapScroll($gamePlayer._realX * $gameMap.tileWidth() - (this.drawAreaWidth / 2 * this.mapZoomInverse), $gamePlayer._realY * $gameMap.tileHeight() - (this.drawAreaHeight / 2 * this.mapZoomInverse));
  791.     }
  792. };
  793.  
  794. Window_Minimap.prototype.setMapScroll = function(scroll_x, scroll_y)
  795. {
  796.     var old_x = this.mapScroll.x = scroll_x;
  797.     var source_w = this.drawAreaWidth * this.mapZoomInverse;
  798.     this.mapScroll.x = this.clamp(this.mapScroll.x, 0, this.mapBmp.width - source_w);
  799.     this.mapScroll.adjustment_x = old_x - this.mapScroll.x; // clamp difference
  800.    
  801.     var old_y = this.mapScroll.y = scroll_y;
  802.     var source_h = this.drawAreaHeight * this.mapZoomInverse;
  803.     this.mapScroll.y = this.clamp(this.mapScroll.y, 0, this.mapBmp.height - source_h);
  804.     this.mapScroll.adjustment_y = old_y - this.mapScroll.y; // clamp difference
  805. };
  806.  
  807. Window_Minimap.prototype.manualScroll = function(scroll_x, scroll_y)
  808. {
  809.     this.setMapScroll(scroll_x, scroll_y);
  810.     this.isManualScrolling = true;
  811. };
  812.  
  813. // Skips frame (returns true) if frameSkipCnt > frameSkip
  814. Window_Minimap.prototype.skipFrame = function()
  815. {
  816.     if (this.frameSkip == 0) { return false; } // process frame
  817.    
  818.     this.frameSkipCnt++;
  819.     if (this.frameSkipCnt < this.frameSkip)
  820.     {
  821.         return true; // skip frame
  822.     }
  823.     else
  824.     {
  825.         this.frameSkipCnt = 0;
  826.         return false; // process frame
  827.     }
  828. };
  829.  
  830. Window_Minimap.prototype.updatePlayerBlink = function()
  831. {
  832.     this.playerBlinkCnt--;
  833.     if (this.playerBlinkCnt <= 0)      
  834.     {  
  835.         this.playerBlinkCnt = Silv.Minimap.PlayerBlinkDelay;
  836.         this.playerBlink_IsVisible = !this.playerBlink_IsVisible;
  837.     }
  838. };
  839.  
  840. //----------------------------------------------------------------------------------------------------
  841. // Window Fading
  842. //----------------------------------------------------------------------------------------------------
  843. Window_Minimap.prototype.updateFadeOut = function()
  844. {
  845.     if (this.isFadedOut || Silv.Minimap.ScreenIsFading) { return; } // Do nothing if the minimap is already completely faded out or if the screen itself is being faded in/out.
  846.     if (this.isFadingOut) { this.fadeOut(); }
  847. };
  848.  
  849. Window_Minimap.prototype.fadeOut = function()
  850. {
  851.     this.opacity = this.contentsOpacity -= Silv.Minimap.FadeoutSpeed;
  852.     this.isFadedOut = (this.opacity <= 0);
  853. };
  854.  
  855. Window_Minimap.prototype.resetFade = function()
  856. {
  857.     this.isFadingOut = false;
  858.     this.fadeOutCnt = 0;
  859.     this.opacity = this.contentsOpacity  = 255;
  860.     this.isFadedOut = false;
  861. };
  862.  
  863. Window_Minimap.prototype.fadeOutInstantly = function()
  864. {
  865.     this.opacity = this.contentsOpacity = 0;
  866.     this.isFadedOut = true;
  867. };
  868.  
  869. //----------------------------------------------------------------------------------------------------
  870. // #Menu
  871. //----------------------------------------------------------------------------------------------------
  872. Window_Minimap.prototype.pushMapScene = function()
  873. {
  874.     this.createMenuBmp();
  875.     this.createMenuMarkers();
  876.     SceneManager.push(Scene_MiniMap);
  877. };
  878. //----------------------------------------------------------------------------------------------------
  879. // Create Menu Bitmap
  880. //----------------------------------------------------------------------------------------------------
  881. Window_Minimap.prototype.createMenuBmp = function()
  882. {
  883.     Silv.Minimap.Menu.Bmp = new Bitmap(this.mapBmp.width * this.menuZoom, this.mapBmp.height * this.menuZoom);
  884.    
  885.     this.tileInfo = {
  886.             w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.menuZoom,
  887.             h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.menuZoom
  888.         };
  889.    
  890.     // Draw Map
  891.     Silv.Minimap.Menu.Bmp.blt(this.mapBmp, 0, 0, this.mapBmp.width, this.mapBmp.height, 0, 0, Silv.Minimap.Menu.Bmp.width, Silv.Minimap.Menu.Bmp.height);
  892.    
  893.     // Draw Debug Grid
  894.     if (Silv.Minimap.DrawDebugGrid)
  895.     {
  896.         for (var i=0; i < $gameMap.width(); i++)
  897.         {
  898.             for (j=0; j < $gameMap.height(); j++)
  899.             {
  900.                 var debugTileLoc = this.translateLocationMenu(i, j, this.tileInfo.w * this.menuZoom, this.tileInfo.h * this.menuZoom);
  901.                 Silv.Minimap.Menu.Bmp.blt(this.debugGridBmp, 0, 0, this.tileInfo.w, this.tileInfo.h, debugTileLoc.x, debugTileLoc.y, this.tileInfo.w * this.menuZoom, this.tileInfo.h * this.menuZoom);
  902.             }
  903.         }
  904.     }
  905.    
  906.     // Draw POI's
  907.     for (var i = 0; i < this.getAllPOI().length; i++)
  908.     {
  909.         var poi = this.getPOIByIdx(i);
  910.         var poiLoc = this.translateLocationMenu(poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  911.         Silv.Minimap.Menu.Bmp.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
  912.                                   poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
  913.     }
  914.    
  915.     // Draw Events
  916.     for (var i=0; i < Silv.Minimap.Events.length; i++)
  917.     {
  918.         var ev = Silv.Minimap.Events[i].event;
  919.         var ev_sprite = Silv.Minimap.Events[i].sprite;
  920.         var evMapLoc = this.translateLocationMenu(ev._realX, ev._realY, Silv.Minimap.Menu.EventRenderSize, Silv.Minimap.Menu.EventRenderSize);
  921.         Silv.Minimap.Menu.Bmp.blt(ev_sprite._bitmap, ev_sprite._frame.x, ev_sprite._frame.y, ev_sprite._frame.width, ev_sprite._frame.height, evMapLoc.x, evMapLoc.y, Silv.Minimap.Menu.EventRenderSize, Silv.Minimap.Menu.EventRenderSize);
  922.     }
  923.    
  924.     // Draw Player
  925.     var playerMapLoc = this.translateLocationMenu($gamePlayer._realX, $gamePlayer._realY, Silv.Minimap.Menu.PlayerIconSize, Silv.Minimap.Menu.PlayerIconSize);
  926.     Silv.Minimap.Menu.Bmp.blt(this.playerInfo.bmp, this.playerInfo.src.x, this.playerInfo.src.y, this.playerInfo.src.width, this.playerInfo.src.height,
  927.                               playerMapLoc.x, playerMapLoc.y, Silv.Minimap.Menu.PlayerIconSize, Silv.Minimap.Menu.PlayerIconSize);
  928. };
  929. //----------------------------------------------------------------------------------------------------
  930. // Menu Create #Markers
  931. //----------------------------------------------------------------------------------------------------
  932. Window_Minimap.prototype.createMenuMarkers = function()
  933. {
  934.     Silv.Minimap.Menu.Markers = new Array();
  935.    
  936.     // Player
  937.     var playerMapLoc = this.translateLocationMenu($gamePlayer._realX, $gamePlayer._realY, Silv.Minimap.Menu.PlayerIconSize, Silv.Minimap.Menu.PlayerIconSize);
  938.     Silv.Minimap.Menu.Markers.push({text:'Player', map_x:playerMapLoc.x, map_y:playerMapLoc.y, w:Silv.Minimap.Menu.PlayerIconSize, h:Silv.Minimap.Menu.PlayerIconSize, desc:Silv.Minimap.Menu.PlayerDesc, tp:null});
  939.    
  940.     // POI's
  941.     for (var i = 0; i < this.getAllPOI().length; i++)
  942.     {
  943.         var poi = this.getPOIByIdx(i);
  944.         var poiLoc = this.translateLocationMenu(poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  945.        
  946.         var tp = poi.tp.slice(0); // slice(0) clones it
  947.         if (this.allowTeleportation && (poi.tp != null))
  948.         {
  949.             tp[0] = parseInt(tp[0]) + parseInt(poi.real_x);
  950.             tp[1] = parseInt(tp[1]) + parseInt(poi.real_y);
  951.         }
  952.        
  953.         Silv.Minimap.Menu.Markers.push({text:poi.name, map_x:poiLoc.x, map_y:poiLoc.y, w:poi.destSize.w, h:poi.destSize.h, desc:poi.desc, tp:tp});
  954.     }
  955.    
  956.     // Events
  957.     for (var i=0; i < Silv.Minimap.Events.length; i++)
  958.     {
  959.         var ev = Silv.Minimap.Events[i].event;
  960.         var evMapLoc = this.translateLocationMenu(ev._realX, ev._realY, Silv.Minimap.Menu.EventRenderSize, Silv.Minimap.Menu.EventRenderSize);
  961.        
  962.         var desc = '';
  963.         if ('mm_desc' in ev) { desc = ev.mm_desc.join(' '); }
  964.        
  965.         var tp = null;
  966.         if (this.allowTeleportation && ('mm_tp' in ev))
  967.         {
  968.             tp = ev.mm_tp.slice(0); // slice(0) clones it
  969.             tp[0] = parseInt(tp[0]) + parseInt(ev._x);
  970.             tp[1] = parseInt(tp[1]) + parseInt(ev._y);
  971.         }
  972.        
  973.         Silv.Minimap.Menu.Markers.push({text:dataMapGetEventByID(ev._eventId).name, map_x:evMapLoc.x, map_y:evMapLoc.y, w:Silv.Minimap.Menu.EventRenderSize, h:Silv.Minimap.Menu.EventRenderSize, desc:desc, tp:tp});
  974.     }
  975. };
  976. //----------------------------------------------------------------------------------------------------
  977. // #Rendering #Drawing
  978. //----------------------------------------------------------------------------------------------------
  979. Window_Minimap.prototype.drawMinimap = function()
  980. {
  981.     this.contents.clear();
  982.    
  983.     // BG fill colour, if applicable
  984.     this.contents.fillRect(Silv.Minimap.BorderWidth, Silv.Minimap.BorderHeight, this.drawAreaWidth, this.drawAreaHeight, Silv.Minimap.MapBGFillColor);
  985.    
  986.     switch(Silv.Minimap.MapStyle)
  987.     {
  988.         case 'autofit':
  989.             this.drawstyleAutofit();
  990.             break;
  991.         case 'scroll':
  992.             this.drawstyleScroll();
  993.             break; 
  994.         default:
  995.             throw 'Window_Minimap.prototype.drawMinimap invalid switch value: ' + Silv.Minimap.MapStyle;
  996.     }
  997. };
  998.  
  999. Window_Minimap.prototype.drawstyleAutofit = function()
  1000. {
  1001.     var destination_w = this.drawAreaWidth  * this.mapAspRatInfo.w;
  1002.     var destination_h = this.drawAreaHeight * this.mapAspRatInfo.h;
  1003.    
  1004.     // Calculate the aspect ratio offsets
  1005.     this.mapAspRatInfo.offset_x = 0.0; // to center the map
  1006.     this.mapAspRatInfo.offset_y = 0.0; // to center the map
  1007.     if (this.mapAspRatInfo.w < 1.0) { this.mapAspRatInfo.offset_x = (this.drawAreaWidth  - destination_w) / 2.0; }
  1008.     if (this.mapAspRatInfo.h < 1.0) { this.mapAspRatInfo.offset_y = (this.drawAreaHeight - destination_h) / 2.0; }
  1009.    
  1010.     // This variable saves on calculations further down the road during this update
  1011.     // w = width, hw=  half width, zhw = zoomed half width
  1012.     this.tileInfo = {
  1013.             w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.mapAspRatInfo.w,
  1014.             h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.mapAspRatInfo.h
  1015.         };
  1016.    
  1017.     // Draw Map
  1018.     this.contents.blt(this.mapBmp, 0, 0, this.mapBmp.width, this.mapBmp.height, Silv.Minimap.BorderWidth + this.mapAspRatInfo.offset_x, Silv.Minimap.BorderHeight + this.mapAspRatInfo.offset_y, destination_w, destination_h);
  1019.  
  1020.     // Debug Grid (if applicable)
  1021.     if (Silv.Minimap.DrawDebugGrid)
  1022.     {
  1023.         for (var i=0; i < $gameMap.width(); i++)
  1024.         {
  1025.             for (j=0; j < $gameMap.height(); j++)
  1026.             {
  1027.                 var debugTileLoc = this.translateLocationAutofit(i, j, this.tileInfo.w * this.mapAspRatInfo.w, this.tileInfo.h * this.mapAspRatInfo.h);
  1028.                 this.contents.blt(this.debugGridBmp, 0, 0, this.tileInfo.w, this.tileInfo.h, debugTileLoc.x, debugTileLoc.y, this.tileInfo.w * this.mapAspRatInfo.w, this.tileInfo.h * this.mapAspRatInfo.h);
  1029.             }
  1030.         }
  1031.     }
  1032.    
  1033.     // Draw POI's
  1034.     for (var i = 0; i < this.getAllPOI().length; i++)
  1035.     {
  1036.         var poi = this.getPOIByIdx(i);
  1037.         var poiLoc = this.translateLocationAutofit(poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  1038.         this.contents.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
  1039.                           poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
  1040.     }
  1041.    
  1042.     // Draw Events
  1043.     for (var i=0; i < Silv.Minimap.Events.length; i++)
  1044.     {
  1045.         var ev = Silv.Minimap.Events[i].event;
  1046.         var ev_sprite = Silv.Minimap.Events[i].sprite;
  1047.         var evMapLoc = this.translateLocationAutofit(ev._realX, ev._realY, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
  1048.         this.contents.blt(ev_sprite._bitmap, ev_sprite._frame.x, ev_sprite._frame.y, ev_sprite._frame.width, ev_sprite._frame.height, evMapLoc.x, evMapLoc.y, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
  1049.     }
  1050.    
  1051.     // Draw Player
  1052.     if (Silv.Minimap.DrawPlayerIcon && this.playerBlink_IsVisible)
  1053.     {
  1054.         var playerMapLoc = this.translateLocationAutofit($gamePlayer._realX, $gamePlayer._realY, Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
  1055.         this.contents.blt(this.playerInfo.bmp, this.playerInfo.src.x, this.playerInfo.src.y, this.playerInfo.src.width, this.playerInfo.src.height,
  1056.                           playerMapLoc.x, playerMapLoc.y, Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
  1057.     }
  1058.    
  1059.     // Overlay (if applicable)
  1060.     if(Silv.Minimap.DrawOverlay) { this.drawOverlay(); }
  1061. };
  1062.  
  1063. Window_Minimap.prototype.drawstyleScroll = function()
  1064. {
  1065.     // The minimap is so large it would require a source-map that is bigger. Because of this the entire map fits onto the minimap anyway so might as well switch to autofit instead of displaying a black image
  1066.     if (this.mapScroll.x < 0 || this.drawAreaWidth  * this.mapZoomInverse > this.mapBmp.width ||
  1067.         this.mapScroll.y < 0 || this.drawAreaHeight * this.mapZoomInverse > this.mapBmp.height)
  1068.         {
  1069.             this.drawstyleAutofit();
  1070.             return;
  1071.         }
  1072.    
  1073.     // This variable saves on calculations further down the road during this update
  1074.     // w = width, hw=  half width, zhw = zoomed half width
  1075.     this.tileInfo = {
  1076.             w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.mapZoom,
  1077.             h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.mapZoom
  1078.         };
  1079.    
  1080.     // Draw Map
  1081.     var map_src_rect = { x:0.0, y:0.0, w:0.0, h:0.0};
  1082.     map_src_rect.x = this.mapScroll.x;
  1083.     map_src_rect.y = this.mapScroll.y;
  1084.     map_src_rect.w = this.drawAreaWidth * this.mapZoomInverse;
  1085.     map_src_rect.h = this.drawAreaHeight * this.mapZoomInverse;
  1086.    
  1087.     this.contents.blt(this.mapBmp, this.mapScroll.x, this.mapScroll.y, this.drawAreaWidth * this.mapZoomInverse, this.drawAreaHeight * this.mapZoomInverse, Silv.Minimap.BorderWidth, Silv.Minimap.BorderHeight, this.drawAreaWidth, this.drawAreaHeight);
  1088.    
  1089.     // Debug Grid (if applicable)
  1090.     if (Silv.Minimap.DrawDebugGrid)
  1091.     {
  1092.         for (var i=0; i < $gameMap.width(); i++)
  1093.         {
  1094.             for (j=0; j < $gameMap.height(); j++)
  1095.             {
  1096.                 var debugTileLoc = this.translateLocationScroll(i, j, this.tileInfo.w * this.mapZoom, this.tileInfo.h * this.mapZoom);
  1097.                 this.contents.blt(this.debugGridBmp, 0, 0, this.tileInfo.w, this.tileInfo.h, debugTileLoc.x, debugTileLoc.y, this.tileInfo.w * this.mapZoom, this.tileInfo.h * this.mapZoom);
  1098.             }
  1099.         }
  1100.     }
  1101.    
  1102.     // Draw POI's
  1103.     for (var i = 0; i < this.getAllPOI().length; i++)
  1104.     {
  1105.         var poi = this.getPOIByIdx(i);
  1106.         var poiLoc = this.translateLocationScroll(poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  1107.         this.contents.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
  1108.                           poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
  1109.     }
  1110.  
  1111.     // Draw Events
  1112.     for (var i=0; i < Silv.Minimap.Events.length; i++)
  1113.     {
  1114.         var ev = Silv.Minimap.Events[i].event;
  1115.         var ev_sprite = Silv.Minimap.Events[i].sprite;
  1116.         var evMapLoc = this.translateLocationScroll(ev._realX, ev._realY, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
  1117.         this.contents.blt(ev_sprite._bitmap, ev_sprite._frame.x, ev_sprite._frame.y, ev_sprite._frame.width, ev_sprite._frame.height, evMapLoc.x, evMapLoc.y, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
  1118.     }
  1119.    
  1120.     // Draw Player
  1121.     if (Silv.Minimap.DrawPlayerIcon && this.playerBlink_IsVisible)
  1122.     {
  1123.         var playerLoc = this.translateLocationScroll($gamePlayer._realX, $gamePlayer._realY, Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
  1124.         this.contents.blt(this.playerInfo.bmp, this.playerInfo.src.x, this.playerInfo.src.y, this.playerInfo.src.width, this.playerInfo.src.height,
  1125.                           playerLoc.x, playerLoc.y, Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
  1126.     }
  1127.     // Overlay (if applicable)
  1128.     if(Silv.Minimap.DrawOverlay) { this.drawOverlay(); }
  1129. };
  1130.  
  1131. Window_Minimap.prototype.drawOverlay = function()
  1132. {
  1133.     this.contents.blt(this.overlayBmp, 0, 0, this.overlayBmp.width, this.overlayBmp.height, 0, 0, this.width, this.height);
  1134. };
  1135.  
  1136. // #Translate
  1137. // returns {x, y}
  1138. Window_Minimap.prototype.translateLocationScroll = function(obj_real_x, obj_real_y, obj_w, obj_h)
  1139. {
  1140.     var obj_x = (obj_real_x * this.tileInfo.w + this.tileInfo.hw) * this.mapZoom - this.mapScroll.x * this.mapZoom - obj_w / 2.0 + Silv.Minimap.BorderWidth;
  1141.     var obj_y = (obj_real_y * this.tileInfo.h + this.tileInfo.hh) * this.mapZoom - this.mapScroll.y * this.mapZoom - obj_h / 2.0 + Silv.Minimap.BorderHeight;
  1142.     return {x: obj_x, y: obj_y};
  1143. };
  1144.  
  1145. // returns {x, y}
  1146. Window_Minimap.prototype.translateLocationAutofit = function(obj_real_x, obj_real_y, obj_w, obj_h)
  1147. {
  1148.     var obj_x = (obj_real_x * this.tileInfo.w + this.tileInfo.hw) * this.mapAspRatInfo.scaleDelta_x * this.mapAspRatInfo.w - obj_w / 2.0 + this.mapAspRatInfo.offset_x + Silv.Minimap.BorderWidth;
  1149.     var obj_y = (obj_real_y * this.tileInfo.h + this.tileInfo.hh) * this.mapAspRatInfo.scaleDelta_y * this.mapAspRatInfo.h - obj_h / 2.0 + this.mapAspRatInfo.offset_y + Silv.Minimap.BorderHeight;
  1150.     return {x: obj_x, y: obj_y};
  1151. };
  1152.  
  1153. // returns {x, y}
  1154. Window_Minimap.prototype.translateLocationMenu = function(obj_real_x, obj_real_y, obj_w, obj_h)
  1155. {
  1156.     var obj_x = (obj_real_x * this.tileInfo.w + this.tileInfo.hw) * this.menuZoom - obj_w / 2.0;
  1157.     var obj_y = (obj_real_y * this.tileInfo.h + this.tileInfo.hh) * this.menuZoom - obj_h / 2.0;
  1158.     return {x: obj_x, y: obj_y};
  1159. };
  1160. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1161. // #POI
  1162. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1163. function MM_POI() { this.initialize.apply(this, arguments); }
  1164. // Set Constructor
  1165. MM_POI.prototype.constructor = MM_POI;
  1166.  
  1167. // Initialization
  1168. // real_x & real_y are in tiles
  1169. MM_POI.prototype.initialize = function(poi_id, name, desc, real_x, real_y, folderPath, filename, source_x, source_y, source_w, source_h, draw_w, draw_h)
  1170. {
  1171.   this.id = poi_id;
  1172.   this.name = name;
  1173.   this.desc = desc;
  1174.   this.real_x = real_x;
  1175.   this.real_y = real_y;
  1176.   this.folderPath = folderPath; // Required for saving&loading
  1177.   this.filename = filename; // Required for saving&loading
  1178.   this.bmp = ImageManager.loadBitmap(folderPath, filename, 0, false);
  1179.   this.src = { x:source_x, y:source_y, w:source_w, h:source_h };
  1180.   this.destSize = { w:draw_w, h:draw_h };
  1181.   this.tp = null;
  1182. };
  1183.  
  1184. // Note: Does not include the Bitmap
  1185. MM_POI.prototype.makeSaveContents = function()
  1186. {
  1187.     return  { id:this.id, name:this.name, desc:this.desc, real_x:this.real_x, real_y:this.real_y, src:this.src, destSize:this.destSize, folderPath:this.folderPath, filename:this.filename, tp:this.tp };
  1188. };
  1189.  
  1190. // Retrieves all the POI's for the current active $gameMap
  1191. Window_Minimap.prototype.getAllPOI = function()
  1192. {
  1193.     return Silv.Minimap.POI[$gameMap._mapId];
  1194. };
  1195.  
  1196. // Retrieves the specified POI by index for the current active $gameMap. Note this is NOT by POI id, this is by index.
  1197. Window_Minimap.prototype.getPOIByIdx = function(index)
  1198. {
  1199.     return Silv.Minimap.POI[$gameMap._mapId][index];
  1200. };
  1201.  
  1202. Window_Minimap.prototype.getPOIByID = function(id)
  1203. {
  1204.     for (var i=0; i<Silv.Minimap.POI[$gameMap._mapId].length; i++)
  1205.     {
  1206.         if (Silv.Minimap.POI[$gameMap._mapId][i].id == id) { return Silv.Minimap.POI[$gameMap._mapId][i]; }
  1207.     }
  1208.     throw 'getPOIByID(' + id + ') not found.';
  1209. };
  1210. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1211. // #Create the Minimap window
  1212. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1213. var alias_silver_mm_createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
  1214. Scene_Map.prototype.createDisplayObjects = function()
  1215. {
  1216.     alias_silver_mm_createDisplayObjects.call(this);
  1217.     var didMapChange = $gameMap._mapId != Silv.Minimap.LastMapID;
  1218.     if (didMapChange)
  1219.     {
  1220.         if (Silv.Minimap.WasLoadedFromSave)
  1221.         {
  1222.             Silv.Minimap.WasLoadedFromSave = false;
  1223.         }
  1224.         else
  1225.         {
  1226.             if (Silv.Minimap.AutoClearPOI) { Silv.Minimap.POI[$gameMap._mapId] = new Array(); }
  1227.         }
  1228.     }
  1229.    
  1230.     // Create empty POI array if it's not defined yet for this map
  1231.     if (typeof Silv.Minimap.POI[$gameMap._mapId] === 'undefined') {Silv.Minimap.POI[$gameMap._mapId] = new Array() };
  1232.  
  1233.     this.attemptToCreateMinimap(didMapChange);
  1234.     Silv.Minimap.LastMapID = $gameMap._mapId;
  1235. };
  1236.  
  1237. Scene_Map.prototype.attemptToCreateMinimap = function(didMapChange)
  1238. {
  1239.     var minimapWasCreated = false;
  1240.     var mapname = lpad_mapname($gameMap._mapId, '0') + '.png';
  1241.    
  1242.     var windowWasHidden = false;
  1243.     if (Silv.Minimap.Window != null) { windowWasHidden = Silv.Minimap.Window.visible; }
  1244.  
  1245.     if (minimapImageExists(mapname))
  1246.     {
  1247.         if (this.MinimapHasRequiredItems())
  1248.         {
  1249.             this.removeWindow(Silv.Minimap.Window); // Required because the Scene_Map still holds a reference to the old minimap, effectively creating 2 or more minimaps if this method creates another one now...
  1250.             this.createMinimapWindow();
  1251.             minimapWasCreated = true;
  1252.             if (windowWasHidden && !didMapChange) { Silv.Minimap.Window.hide(); } // This is to prevent the minimap from showing itself again after opening a menu or when recreating the minimap while staying on the same map.
  1253.         }
  1254.     }
  1255.     else
  1256.     {
  1257.         if (Silv.Minimap.DebugMode) { console.log('No minimap \'' + mapname + '\' found for map with map-id: ' + $gameMap._mapId + '.'); }
  1258.     }
  1259.    
  1260.     // 'Dispose'   
  1261.     // This is required for values like "Silv.Minimap.Window.visible" to get 'reset' properly. Otherwise they keep the values from an old map which can lead to nasty bugs.
  1262.     if (!minimapWasCreated) { Silv.Minimap.Window = null; }
  1263. };
  1264.  
  1265. // Omg why does RPG Maker not have this method by default...
  1266. Scene_Base.prototype.removeWindow = function(window)
  1267. {
  1268.     var index = this.children.indexOf(window);
  1269.     if (index > -1) { this.children.splice(index, 1); }
  1270. }
  1271.  
  1272. Scene_Map.prototype.createMinimapWindow = function()
  1273. {
  1274.     x = 0;
  1275.     if (Silv.Minimap.WindowHorizontalAlignment == 'right') { x = Graphics.width - Silv.Minimap.WindowWidth; }
  1276.     y = 0;
  1277.     if (Silv.Minimap.WindowVerticalAlignment == 'bottom') { y = Graphics.height - Silv.Minimap.WindowHeight; }
  1278.    
  1279.     Silv.Minimap.Window = new Window_Minimap(x + Silv.Minimap.Window_X, y + Silv.Minimap.Window_Y, Silv.Minimap.WindowWidth, Silv.Minimap.WindowHeight);
  1280.     Silv.Minimap.Window.resetFade();
  1281.    
  1282.     // override frameskip (map-specific frameskip)
  1283.     if ('mm_frameskip' in $dataMap.meta)
  1284.     {
  1285.         Silv.Minimap.Window.frameSkip = parseInt($dataMap.meta.mm_frameskip);
  1286.         if (Silv.Minimap.DebugMode) { console.log('Global frameskip: ' + Silv.Minimap.FrameSkip + ' was overriden by the map-specific frameskip of: ' + $dataMap.meta.mm_frameskip + '.'); }
  1287.     }
  1288.    
  1289.     this.addChildAt(Silv.Minimap.Window, 1);
  1290. };
  1291.  
  1292. Scene_Map.prototype.MinimapHasRequiredItems = function()
  1293. {
  1294.     // Check global item
  1295.     if (Silv.Minimap.GlobalRequiredItem > 0)
  1296.     {
  1297.         if (!$gameParty.hasItem($dataItems[Silv.Minimap.GlobalRequiredItem], false))
  1298.         {
  1299.             if (Silv.Minimap.DebugMode) { console.log('Minimap was found but party does not possess the required global item: ' + $dataItems[Silv.Minimap.GlobalRequiredItem].name); }
  1300.             return false;
  1301.         }
  1302.     }
  1303.    
  1304.     // Check map-specific items
  1305.     if ('mm_req_itm' in $dataMap.meta)
  1306.     {
  1307.         var req_item_ids = $dataMap.meta.mm_req_itm.split(' ').filter(Boolean); // .filter(Boolean) removes empty strings from array
  1308.         for (var i = 0; i < req_item_ids.length; i++)
  1309.         {
  1310.             if (!$gameParty.hasItem($dataItems[req_item_ids[i]], false))
  1311.             {
  1312.                 if (Silv.Minimap.DebugMode) { console.log('Minimap was found but party does not possess the required map-specific item: ' + $dataItems[req_item_ids[i]].name); }
  1313.                 return false;
  1314.             }
  1315.         }
  1316.     }
  1317.    
  1318.     return true;
  1319. };
  1320. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1321. // Saving & Loading #Save #Saving #Loading
  1322. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1323. var alias_silv_mm_makeSaveContents = DataManager.makeSaveContents;
  1324. DataManager.makeSaveContents = function()
  1325. {
  1326.     contents = alias_silv_mm_makeSaveContents.call(this);
  1327.    
  1328.     contents.minimap = {};
  1329.     contents.minimap.poi = {};
  1330.    
  1331.     // POI
  1332.     for (var mapID in Silv.Minimap.POI)
  1333.     {
  1334.         if (Silv.Minimap.POI.hasOwnProperty(mapID))
  1335.         {
  1336.             if(Silv.Minimap.POI[mapID].length > 0) { contents.minimap.poi[mapID] = new Array(); }
  1337.             for(var poi_idx=0; poi_idx<Silv.Minimap.POI[mapID].length; poi_idx++)
  1338.             {
  1339.                 contents.minimap.poi[mapID].push(Silv.Minimap.Window.getPOIByIdx(poi_idx).makeSaveContents());
  1340.             }
  1341.         }
  1342.     }
  1343.     return contents;
  1344. };
  1345.  
  1346. var alias_silv_mm_extractSaveContents = DataManager.extractSaveContents;
  1347. DataManager.extractSaveContents = function(contents)
  1348. {
  1349.     alias_silv_mm_extractSaveContents.call(this, contents);
  1350.     Silv.Minimap.POI = {};
  1351.    
  1352.    
  1353.     // POI
  1354.     for (var mapID in contents.minimap.poi)
  1355.     {
  1356.         if (contents.minimap.poi.hasOwnProperty(mapID))
  1357.         {
  1358.             if(contents.minimap.poi[mapID].length > 0) { Silv.Minimap.POI[mapID] = new Array(); }
  1359.             for(var poi_idx=0; poi_idx<contents.minimap.poi[mapID].length; poi_idx++)
  1360.             {
  1361.                 var poi = contents.minimap.poi[mapID][poi_idx];
  1362.                 var newPOI = new MM_POI(poi.id, poi.name, poi.desc, poi.real_x, poi.real_y, poi.folderPath, poi.filename, poi.src.x, poi.src.y, poi.src.w, poi.src.h, poi.destSize.w, poi.destSize.h);
  1363.                 newPOI.tp = poi.tp;
  1364.                 Silv.Minimap.POI[mapID].push(newPOI);
  1365.             }
  1366.         }
  1367.     }
  1368.    
  1369.     // Prevent the minimap from autoclearing it's POI's (if AutoClearPOI is enabled) when loading a savegame
  1370.     Silv.Minimap.WasLoadedFromSave = true;
  1371. };
  1372. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1373. // #Plugin Command
  1374. // Note: The items are separated by spaces. The command is the first word and any following words are args. args is an array.
  1375. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1376. var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  1377. Game_Interpreter.prototype.pluginCommand = function(command, args)
  1378. {
  1379.     _Game_Interpreter_pluginCommand.call(this, command, args);
  1380.     if (command.toLowerCase() == 'minimap') { PluginCommand(command, args); }
  1381. };
  1382.  
  1383. function PluginCommand(cmd, args)
  1384. {
  1385.     switch(args[0].toLowerCase())
  1386.     {
  1387.         case 'hide':
  1388.             Silv.Minimap.Window.hide();
  1389.             break;
  1390.         case 'show':
  1391.             Silv.Minimap.Window.show();
  1392.             break;
  1393.         case 'fadeout':
  1394.             Silv.Minimap.Window.isFadingOut = true;
  1395.             break;
  1396.         case 'fadereset':
  1397.             Silv.Minimap.Window.resetFade();
  1398.             break;
  1399.         case 'refresh':
  1400.             SceneManager._scene.attemptToCreateMinimap(false);
  1401.             break;
  1402.         case 'addpoi': // addpoi id, name, desc, real_x, real_y, bitmap folder, bitmap filename, s_x, s_y, s_w, s_h, draw_w, draw_h
  1403.             Silv.Minimap.POI[$gameMap._mapId].push(new MM_POI(args[1], args[2].replace('_', ' '), '', parseFloat(args[3]), parseFloat(args[4]), args[5], args[6], parseInt(args[7]), parseInt(args[8]), parseInt(args[9]), parseInt(args[10]), parseInt(args[11]), parseInt(args[12])));
  1404.             SceneManager._scene.attemptToCreateMinimap(false);
  1405.             break;
  1406.         case 'deletepoi':
  1407.             Silv.Minimap.POI[$gameMap._mapId] = Silv.Minimap.POI[$gameMap._mapId].filter(function(poi) { return poi.id != args[1]; });
  1408.             break;
  1409.         case 'poidesc':
  1410.               Silv.Minimap.Window.getPOIByID(parseInt(args[1])).desc = args.join(' ').substr(2 + args[0].length + args[1].length);
  1411.             break;
  1412.         case 'poi_tp': // POI_TP <poi_id x_offset, y_offset, direction, fadeType>
  1413.               Silv.Minimap.Window.getPOIByID(parseInt(args[1])).tp = [parseInt(args[2]), parseInt(args[3]), parseInt(args[4]), parseInt(args[5])]
  1414.             break;
  1415.         case 'refreshevents':
  1416.             Silv.Minimap.Window.loadEvents();
  1417.             break;
  1418.         case 'increasescroll':
  1419.             Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x + parseFloat(args[1]), Silv.Minimap.Window.mapScroll.y + parseFloat(args[2]));
  1420.             break;
  1421.         case 'setscroll':
  1422.             Silv.Minimap.Window.manualScroll(parseFloat(args[1]), parseFloat(args[2]));
  1423.             break;
  1424.         default:
  1425.             throw 'Minimap, unknown Plugin Command: ' + args[0];
  1426.     }
  1427. }
  1428. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1429. })();
  1430. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1431. // Map Menu #Scene
  1432. // Note: Must be placed outside of the })();
  1433. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1434. function Scene_MiniMap() { this.initialize.apply(this, arguments); }
  1435.  
  1436. Scene_MiniMap.prototype = Object.create(Scene_MenuBase.prototype);
  1437. Scene_MiniMap.prototype.constructor = Scene_MiniMap;
  1438.  
  1439. Scene_MiniMap.prototype.initialize = function()
  1440. {
  1441.     Scene_MenuBase.prototype.initialize.call(this);
  1442. };
  1443.  
  1444. Scene_MiniMap.prototype.create = function()
  1445. {
  1446.     Scene_MenuBase.prototype.create.call(this);
  1447.     this.createLeftWindow();
  1448.     this.createMapSectionWindow();
  1449.     this.createMapHelpWindow();
  1450.     this.refreshHelpWindow();
  1451. };
  1452.  
  1453. Scene_MiniMap.prototype.createLeftWindow = function()
  1454. {
  1455.     this._window_left = new Window_MinimapMenuLeft(0, 0);
  1456.     this._window_left.setHandler('ok',     this.onRangeOk.bind(this));
  1457.     this._window_left.setHandler('cancel', this.popScene.bind(this));
  1458.     this._window_left.setHandler('index_changed', this.index_changed.bind(this));
  1459.     this.addWindow(this._window_left);
  1460. };
  1461.  
  1462. Scene_MiniMap.prototype.createMapSectionWindow = function()
  1463. {
  1464.     var wx = this._window_left.width;
  1465.     var ww = Graphics.boxWidth - wx;
  1466.     this._mapSectionWindow = new Window_MapSection(wx, 0, ww);
  1467.     this._mapSectionWindow.setHandler('cancel', this.onEditCancel.bind(this));
  1468.     this._window_left.setMapWindow(this._mapSectionWindow);
  1469.     this.addWindow(this._mapSectionWindow);
  1470. };
  1471.  
  1472. Scene_MiniMap.prototype.createMapHelpWindow = function()
  1473. {
  1474.     var wx = this._mapSectionWindow.x;
  1475.     var wy = this._mapSectionWindow.height;
  1476.     var ww = this._mapSectionWindow.width;
  1477.     var wh = Graphics.boxHeight - wy;
  1478.     this._mapHelpWindow = new Window_Base(wx, wy, ww, wh);
  1479.     this.addWindow(this._mapHelpWindow);
  1480. };
  1481.  
  1482. Scene_MiniMap.prototype.index_changed = function()
  1483. {
  1484.     this.refreshHelpWindow();
  1485. };
  1486.  
  1487. Scene_MiniMap.prototype.onRangeOk = function()
  1488. {
  1489.     this._mapSectionWindow.activate();
  1490.     this._mapSectionWindow.select(0);
  1491.     this.refreshHelpWindow();
  1492. };
  1493.  
  1494. Scene_MiniMap.prototype.onEditCancel = function()
  1495. {
  1496.     this._window_left.activate();
  1497.     this._mapSectionWindow.deselect();
  1498.     this.refreshHelpWindow();
  1499. };
  1500.  
  1501. Scene_MiniMap.prototype.refreshHelpWindow = function()
  1502. {
  1503.     this._mapHelpWindow.contents.clear();
  1504.     this._mapHelpWindow.drawTextEx(this.helpText(), 4, 0);
  1505. };
  1506.  
  1507. Scene_MiniMap.prototype.helpText = function()
  1508. {
  1509.     var marker = this._window_left.marker();
  1510.     var tp_text = '';
  1511.     if (marker.tp != null) { tp_text = '\nTeleports you to: ' + marker.tp[0] + ',' + marker.tp[1]; }
  1512.     return this._window_left.marker().desc + tp_text;
  1513. };
  1514. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1515. // Left Window #leftwindow
  1516. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1517. function Window_MinimapMenuLeft() { this.initialize.apply(this, arguments); }
  1518.  
  1519. Window_MinimapMenuLeft.prototype = Object.create(Window_Selectable.prototype);
  1520. Window_MinimapMenuLeft.prototype.constructor = Window_MinimapMenuLeft;
  1521.  
  1522. Window_MinimapMenuLeft.lastTopRow = 0;
  1523. Window_MinimapMenuLeft.lastIndex  = 0;
  1524.  
  1525. Window_MinimapMenuLeft.prototype.initialize = function(x, y)
  1526. {
  1527.     var width = this.windowWidth();
  1528.     var height = this.windowHeight();
  1529.     Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  1530.     this.refresh();
  1531.     this.setTopRow(Window_MinimapMenuLeft.lastTopRow);
  1532.     this.select(Window_MinimapMenuLeft.lastIndex);
  1533.     this.activate();
  1534. };
  1535.  
  1536. Window_MinimapMenuLeft.prototype.windowWidth = function()
  1537. {
  1538.     return Silv.Minimap.Menu.WindowWidth_Left;
  1539. };
  1540.  
  1541. Window_MinimapMenuLeft.prototype.windowHeight = function()
  1542. {
  1543.     return Graphics.boxHeight;
  1544. };
  1545.  
  1546. Window_MinimapMenuLeft.prototype.maxItems = function()
  1547. {
  1548.     return Silv.Minimap.Menu.Markers.length;
  1549. };
  1550.  
  1551. Window_MinimapMenuLeft.prototype.update = function()
  1552. {
  1553.     Window_Selectable.prototype.update.call(this);
  1554.     if (this._mapWindow) { this._mapWindow.setMarker(this.marker()); }
  1555.     if (this.index() != Window_MinimapMenuLeft.lastIndex)
  1556.     {
  1557.         Window_MinimapMenuLeft.lastIndex = this.index();
  1558.         this.callHandler('index_changed');
  1559.     }
  1560.    
  1561.     if (Input.isTriggered('ok'))
  1562.     {
  1563.         var marker = this.marker();
  1564.         if(marker.tp != null)
  1565.         {
  1566.             // Add the teleport location to the minimap and dequeue this scene to return to the previous scene
  1567.             SoundManager.playOk();
  1568.             Silv.Minimap.TP_Dest = marker.tp;
  1569.             SceneManager.pop();
  1570.         }
  1571.     }
  1572. };
  1573.  
  1574. Window_MinimapMenuLeft.prototype.marker = function()
  1575. {
  1576.     return Silv.Minimap.Menu.Markers[this.index()];
  1577. };
  1578.  
  1579. Window_MinimapMenuLeft.prototype.refresh = function()
  1580. {
  1581.     this.createContents();
  1582.     this.drawAllItems();
  1583. };
  1584.  
  1585. Window_MinimapMenuLeft.prototype.drawItem = function(index)
  1586. {
  1587.     var rect = this.itemRectForText(index);
  1588.     var text = Silv.Minimap.Menu.Markers[index].text;
  1589.     this.drawText(text, rect.x, rect.y, rect.width);
  1590. };
  1591.  
  1592. Window_MinimapMenuLeft.prototype.isCancelTriggered = function()
  1593. {
  1594.     return (Window_Selectable.prototype.isCancelTriggered());
  1595. };
  1596.  
  1597. Window_MinimapMenuLeft.prototype.processCancel = function()
  1598. {
  1599.     Window_Selectable.prototype.processCancel.call(this);
  1600.     Window_MinimapMenuLeft.lastTopRow = this.topRow();
  1601.     Window_MinimapMenuLeft.lastIndex = this.index();
  1602. };
  1603.  
  1604. Window_MinimapMenuLeft.prototype.setMapWindow = function(mapWindow)
  1605. {
  1606.     this._mapWindow = mapWindow;
  1607.     this.update();
  1608. };
  1609. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1610. // Map Section Window
  1611. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1612. function Window_MapSection() { this.initialize.apply(this, arguments); }
  1613.  
  1614. Window_MapSection.prototype = Object.create(Window_Selectable.prototype);
  1615. Window_MapSection.prototype.constructor = Window_MapSection;
  1616.  
  1617. Window_MapSection.prototype.initialize = function(x, y, width)
  1618. {
  1619.     var height = Silv.Minimap.Menu.WindowHeight_MapSection;
  1620.     Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  1621.     this._marker = 1;
  1622.     this.mapScroll = {x:0, y:0};
  1623.     this.mapZoom = 1.0;
  1624.     this.centerLoc = {x:width / 2.0, y: height / 2.0};
  1625.     this.refresh();
  1626. };
  1627.  
  1628. // Hide the cursor
  1629. Window_MapSection.prototype.updateCursor = function()
  1630. {
  1631.     this.setCursorRect(0,0,0,0);
  1632. }
  1633.  
  1634. Window_MapSection.prototype.maxItems = function() { return 0; };
  1635.  
  1636. Window_MapSection.prototype.refresh = function()
  1637. {
  1638.     this.contents.clear();
  1639.     this.drawMap();
  1640. };
  1641.  
  1642. // Prevent anything from being drawn in the base-class
  1643. Window_MapSection.prototype.drawAllItems = function(){};
  1644.  
  1645. Window_MapSection.prototype.drawMap = function()
  1646. {
  1647.     this.contents.blt(Silv.Minimap.Menu.Bmp, 0, 0, Silv.Minimap.Menu.Bmp.width, Silv.Minimap.Menu.Bmp.height, this.mapScroll.x, this.mapScroll.y, Silv.Minimap.Menu.Bmp.width * this.mapZoom, Silv.Minimap.Menu.Bmp.height * this.mapZoom);
  1648. };
  1649.  
  1650. Window_MapSection.prototype.centerOnMarker = function(marker)
  1651. {
  1652.     this.mapScroll.x = this.centerLoc.x - marker.map_x - marker.w / 2.0;
  1653.     this.mapScroll.y = this.centerLoc.y - marker.map_y - marker.h / 2.0;
  1654.     this.refresh();
  1655. }
  1656.  
  1657. Window_MapSection.prototype.setMarker = function(marker)
  1658. {
  1659.     if (this._marker !== marker) {
  1660.         this._marker = marker;
  1661.         this.centerOnMarker(marker)
  1662.     }
  1663. };
  1664.  
  1665. Window_MapSection.prototype.update = function()
  1666. {
  1667.     Window_Selectable.prototype.update.call(this);
  1668.     if (this.active) {
  1669.         if (Input.isPressed('up')) { this.mapScroll.y += 10; this.refresh(); }
  1670.         if (Input.isPressed('right')) { this.mapScroll.x -= 10; this.refresh(); }
  1671.         if (Input.isPressed('down')) { this.mapScroll.y -= 10; this.refresh(); }
  1672.         if (Input.isPressed('left')) { this.mapScroll.x += 10; this.refresh(); }
  1673.         if (Input.isPressed(Silv.Minimap.Menu.ManualScrollKey_Reset)) { this.mapScroll.x = 0; this.mapScroll.y = 0; this.refresh(); }
  1674.        
  1675.         if (Input.isPressed(Silv.Minimap.Menu.ManualZoomKey_In))
  1676.         {
  1677.             this.mapZoom += 0.05;
  1678.             if (this.mapZoom > Silv.Minimap.Menu.ManualZoom_Max) { this.mapZoom = Silv.Minimap.Menu.ManualZoom_Max; }
  1679.             this.refresh();
  1680.         }
  1681.         if (Input.isPressed(Silv.Minimap.Menu.ManualZoomKey_Out))
  1682.         {
  1683.             this.mapZoom -= 0.05;
  1684.             if (this.mapZoom < Silv.Minimap.Menu.ManualZoom_Min) { this.mapZoom = Silv.Minimap.Menu.ManualZoom_Min; }
  1685.             this.refresh();
  1686.         }
  1687.         if  (Input.isPressed(Silv.Minimap.Menu.ManualZoomKey_Reset)) { this.mapZoom = 1.0; this.refresh(); }
  1688.     }
  1689. };
  1690. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1691. // This is the end of this awesome script! Why did you even read this line ;)
  1692. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement