Advertisement
Guest User

Minimap

a guest
Dec 6th, 2015
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // SilvMinimap.js
  3. // Version: 1.06
  4. // Requires plugin: SilvKeys (place this one below it)
  5. //=============================================================================
  6. /*:
  7.  * @plugindesc v1.06 Minimap. <SilvMinimap>
  8.  * @author Silver
  9.  * @param -- General --
  10.  *
  11.  * @param Map Style
  12.  * @desc Is the minimap scaled to fit? Or does it zoom and scroll? Autofit/Scroll
  13.  * @default Scroll
  14.  *
  15.  * @param Global Map Zoom
  16.  * @desc Only applies if MapStyle is set to: Scroll. Determines the default zoom level for all maps. A value of 1 means 1:1.
  17.  * @default 0.25
  18.  *
  19.  * @param Minimap Opacity
  20.  * @desc 0 = invisible, 255 = fully opaque.
  21.  * @default 255
  22.  *
  23.  * @param -- Positioning & Size --
  24.  *
  25.  * @param X
  26.  * @desc x-location of minimap window. If window-alignment is set to Right, this will act as an offset value instead
  27.  * @default -2
  28.  *
  29.  * @param Y
  30.  * @desc y-location of minimap window. If window-alignment is set to Top, this will act as an offset value instead
  31.  * @default 2
  32.  *
  33.  * @param Horizontal Alignment
  34.  * @desc Left/Right
  35.  * @default Right
  36.  *
  37.  * @param Vertical Alignment
  38.  * @desc Top/Bottom
  39.  * @default Bottom
  40.  *
  41.  * @param Width
  42.  * @desc width of the minimap
  43.  * @default 320
  44.  *
  45.  * @param Height
  46.  * @desc height of the minimap
  47.  * @default 320
  48.  *
  49.  * @param Border Width
  50.  * @desc Border width of the minimap
  51.  * @default 12
  52.  *
  53.  * @param Border Height
  54.  * @desc Border height of the minimap
  55.  * @default 12
  56.  *
  57.  * @param -- Player Blip --
  58.  *
  59.  * @param Render Player Blip
  60.  * @desc Render the player blip in the minimap (=usually the center icon)? true/false
  61.  * @default true
  62.  *
  63.  * @param Player Blip Graphic
  64.  * @desc Name of the image (in /img/minimap/) to use as the blip. or use :player to use the realtime-player-graphic.
  65.  * @default :player
  66.  *
  67.  * @param Player Icon Width
  68.  * @desc Standard Window Padding
  69.  * @default 16
  70.  *
  71.  * @param Player Icon Height
  72.  * @desc Standard Window Padding
  73.  * @default 16
  74.  *
  75.  * @param Player Blink Delay
  76.  * @desc Blinks the player icon (in frames). Set to 0 to disable. Does nothing if "Draw Player Icon" is set to false
  77.  * @default 0
  78.  *
  79.  * @param -- Menu --
  80.  *
  81.  * @param Menu Key
  82.  * @desc The key used to show the map-menu. Use none to disable.
  83.  * @default m
  84.  *
  85.  * @param Menu Player Description
  86.  * @desc The description of the player marker in the menu. Spaces are allowed.
  87.  * @default You
  88.  *
  89.  * @param Menu Zoom
  90.  * @desc Map Zoomlevel for the menu
  91.  * @default 0.3. A value of 1 means 1:1
  92.  *
  93.  * @param Menu Left Window Width
  94.  * @desc Width of the left window
  95.  * @default 240
  96.  *
  97.  * @param Menu Topright Window Height
  98.  * @desc Height of the topright window
  99.  * @default 510
  100.  *
  101.  * @param Menu Event Render Size
  102.  * @desc How big the events are that are drawn onto the menu map
  103.  * @default 24
  104.  *
  105.  * @param Menu Player Icon Size
  106.  * @desc How big the player is drawn onto the menu map
  107.  * @default 64
  108.  *
  109.  * @param Menu Min Manual Zoom
  110.  * @desc How far the player can zoom out
  111.  * @default 0.20
  112.  *
  113.  * @param Menu Max Manual Zoom
  114.  * @desc How far the player can zoom in
  115.  * @default 10.0
  116.  *
  117.  * @param Menu Zoomin Key
  118.  * @desc Key for zooming in. 33 = pageup
  119.  * @default pageup
  120.  *
  121.  * @param Menu Zoomout Key
  122.  * @desc Key for zooming out. 34 = pagedown
  123.  * @default pagedown
  124.  *
  125.  * @param Menu Reset Zoom Key
  126.  * @desc Key for resetting the zoom. 36 = home
  127.  * @default home
  128.  *
  129.  * @param Menu Reset Scroll Key
  130.  * @desc Key to reset the mapscroll
  131.  * @default end
  132.  *
  133.  * @param -- Passability Map --
  134.  *
  135.  * @param Passability Overlay Opacity
  136.  * @desc 0 = invisible, 255 = fully opaque. 0-255
  137.  * @default 128
  138.  *
  139.  * @param Passability Color
  140.  * @desc Color for walkable tiles
  141.  * @default #6B8E23
  142.  *
  143.  * @param Impassability Color
  144.  * @desc Color for unwalkable tiles
  145.  * @default #FF0000
  146.  *
  147.  * @param -- Map Generator --
  148.  *
  149.  * @param Map Gen Tag Colors
  150.  * @desc 0-7, use a ####### value to ignore that terrain-tag. Default: lightgreen, blue, brown, darkgreen, lightbrown
  151.  * @default #6B8E23 #00008B #8B4513 #006400 #F4A460 ####### ####### #######
  152.  *
  153.  * @param Overworld Gen Tag Colors
  154.  * @desc 0-7, use a ####### value to ignore that terrain-tag. Default: lightgreen, blue, brown, darkgreen, lightbrown
  155.  * @default #6B8E23 #00008B #8B4513 #006400 #F4A460 ####### ####### #######
  156.  *
  157.  * @param -- The rest --
  158.  *
  159.  * @param Allow Teleportation
  160.  * @desc By default, allow teleportation to events/poi's that support it? true/false
  161.  * @default true
  162.  *
  163.  * @param Standard Padding
  164.  * @desc Standard Window Padding. Best to leave at 0
  165.  * @default 0
  166.  *
  167.  * @param Window Skin
  168.  * @desc Name of the window skin to use for this window
  169.  * @default Window_Minimap
  170.  *
  171.  * @param Fill Color
  172.  * @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.
  173.  * @default 0 0 0 255
  174.  *
  175.  * @param Maintain Aspect Ratio
  176.  * @desc Maintains minimap aspect ratio if set to true. true/false
  177.  * @default true
  178.  *
  179.  * @param Fadeout Speed
  180.  * @desc How fast the minimap fades out
  181.  * @default 3
  182.  *
  183.  * @param Global Required Item
  184.  * @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
  185.  * @default 0
  186.  *
  187.  * @param Event Render Size
  188.  * @desc How big the events are that are drawn onto the minimap
  189.  * @default 16
  190.  *
  191.  * @param Auto Clear POI
  192.  * @desc Automatically clear POI's between map transfers? true/false
  193.  * @default false
  194.  *
  195.  * @param Render Minimap Overlay
  196.  * @desc If enabled, add the image: /img/Minimap/Overlay.png and it will be drawn on top of the minimap. true/false
  197.  * @default true
  198.  *
  199.  * @param -- Manual Scrolling --
  200.  *
  201.  * @param Allow Manual Scrolling
  202.  * @desc true/false
  203.  * @default true
  204.  *
  205.  * @param Manual Scrollspeed
  206.  * @desc How fast the map is scrolled
  207.  * @default 24
  208.  *
  209.  * @param Manual Scroll Key Up
  210.  * @desc Key for scrolling the map upwards. Default: u  http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
  211.  * @default u
  212.  *
  213.  * @param Manual Scroll Key Right
  214.  * @desc Key for scrolling the map upwards. Default: k
  215.  * @default k
  216.  *
  217.  * @param Manual Scroll Key Down
  218.  * @desc Key for scrolling the map upwards. Default: j
  219.  * @default j
  220.  *
  221.  * @param Manual Scroll Key Left
  222.  * @desc Key for scrolling the map upwards. Default: h
  223.  * @default h
  224.  *
  225.  * @param -- Advanced & Debug --
  226.  *
  227.  * @param Player Sprite Sourceframe Width
  228.  * @desc Width of the playersprite sourceframe
  229.  * @default 48
  230.  *
  231.  * @param Player Sprite Sourceframe Height
  232.  * @desc Heigth of the playersprite sourceframe
  233.  * @default 48
  234.  *
  235.  * @param Frame Skip
  236.  * @desc Skips some minimap calculations&rendering if set to value > 0 to safe performance. The value equals the amount of frames skipped.
  237.  * @default 0
  238.  *
  239.  * @param Mapshot Filename Length
  240.  * @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
  241.  * @default 3
  242.  *
  243.  * @param Debug Mode
  244.  * @desc Prints extra info if set to true. true/false
  245.  * @default false
  246.  *
  247.  * @param Render Debug Grid
  248.  * @desc Draws a debug grid. Requires "/img/Minimap/DebugGrid.png" which is 48x48 in size. Drains a lot of performance!
  249.  * @default false
  250.  *
  251.  * @param Debug Grid Image
  252.  * @desc Name of the debug-grid image
  253.  * @default DebugGrid01
  254.  *
  255.  * @help
  256.  * 1. Make a mapshot of your map. You may use http://forums.rpgmakerweb.com/index.php?/topic/49711-orange-mapshot/
  257.  * 2. Install this script: http://pastebin.com/FF6jh3S0 and make sure to put it above the minimap script.
  258.  * 3. Copy the files to:
  259.  * 4. /img/minimap/Overlay.png
  260.  * 5. /img/minimap/DebugGrid01.png
  261.  * 6. /img/system/Window_Minimap.png
  262.  * 7. Place your mapshots in the /img/minimap/ directory and rename them 001.png, 002.png etc. (matching the id of your map)
  263.  *
  264.  * If you prefer to use automatic generated maps instead, use the map-notetags and you then obviously do not require mapshots of course.
  265.  *
  266.  *--------------------------------------
  267.  * Yanfly's Main Menu Manager Setup (optional)
  268.  *--------------------------------------
  269.  *
  270.  * 1. Download & Install YEP_MainMenuManager.js
  271.  * 2. Configure the parameters as follow:
  272.  * Menu Name: "Map"
  273.  * Menu Symbol: silvMap
  274.  * Menu Show: true
  275.  * Menu Enabled: Silv.Minimap.Menu.Enabled
  276.  * Menu Main Bind: this.commandSilvMap.bind(this)
  277.  *
  278.  *--------------------------------------
  279.  * Map notetags (most are case sensitive!)
  280.  *--------------------------------------
  281.  * <mm_req_itm:item_id1 item_id2 etc>
  282.  * Example: <mm_req_itm:1, 2, 3>
  283.  *
  284.  * <mm_mapstyle:Scroll/Autofit>
  285.  * Examples:
  286.  * <mm_mapstyle:Scroll>
  287.  * <mm_mapstyle:AutoFit>
  288.  *
  289.  * <mm_frameskip:value>
  290.  * Example: <mm_frameskip:1>
  291.  * Note: overrides the global frameskip parameter for this map
  292.  *
  293.  * <mm_mapzoom:value>
  294.  * Example: <mm_mapzoom:0.15>
  295.  * Note: overrides the global mapzoom parameter for this map
  296.  *
  297.  * <mm_allowmanualscroll:value>
  298.  * Example: <mm_allowmanualscroll:false>
  299.  * Allowed values: true/false
  300.  * Note: overrides the global "Allow Manual Scrolling" parameter for this map
  301.  *
  302.  * <mm_menuzoom:value>
  303.  * Example: <mm_menuzoom:0.75>
  304.  * Note: overrides the global "Menu Zoom" parameter for this map
  305.  *
  306.  * <mm_size:x y>
  307.  * Example: <mm_size:128 128>
  308.  * Note: overrides the global "Width" and "Height" parameters for this map
  309.  *
  310.  * Allow/disallow teleportation.
  311.  * <mm_tp_allow:value>
  312.  * Example: <mm_tp_allow:false>
  313.  * Note: overrides the global "Allow Teleportation" parameter for this map
  314.  *
  315.  * Generate a worldmap-minimap if there is no image (does increase load-time, the first time, for the map)
  316.  * <mm_generate_worldmap>
  317.  * <mm_generate_overworld>
  318.  *
  319.  * Geberate regular map
  320.  * <mm_generate_map>
  321.  *
  322.  * Generate and overlay a generated passability-map on top of the minimap
  323.  * <mm_generate_passability_overlay>
  324.  *
  325.  * Change the player-blip
  326.  * <mm_player_blip:value>
  327.  * Example to use the realtime player graphic:
  328.  * <mm_player_blip::player>
  329.  * Example to use a custom blip graphic:
  330.  * <mm_player_blip:myCustomPlayerBlip>
  331.  * Note that in the above example, the game requires the image /img/minimap/myCustomPlayerBlip.png"
  332.  *
  333.  * User another map's mapshot (handy for duplicate maps)
  334.  * <mm_mapshot:map_id>
  335.  * Example: <mm_mapshot:2>
  336.  * Note: leading zero's are optional but not required.
  337.  *
  338.  *--------------------------------------
  339.  * Event notetags (not case sensitive)
  340.  *--------------------------------------
  341.  * mm_show
  342.  *
  343.  *--------------------------------------
  344.  * Plugin Commands (not case-sensitive)
  345.  *--------------------------------------
  346.  * Minimap Hide
  347.  * Minimap Show
  348.  * Minimap FadeOut
  349.  * Minimap FadeReset
  350.  * Minimap Refresh
  351.  * Minimap RefreshEvents
  352.  * Minimap IncreaseScroll <x> <y>
  353.  * Minimap SetScroll <x> <y>
  354.  * Minimap DeletePOI <poi_id>
  355.  * Minimap Generate_Passability_Overlay <true/false>
  356.  * Minimap Gen_Pass_Ov <true/false>
  357.  * Minimap ShowMapMenu
  358.  * Minimap SetPlayerBlip <filename/:player>
  359.  *
  360.  * Minimap SetFollowTarget <type> <value>
  361.  * Minimap setcamera <type> <value>
  362.  * Allowed types: player, event, coordinate
  363.  * Note: the player-type has no value parameter.
  364.  * Examples:
  365.  * Minimap SetFollowTarget player
  366.  * Minimap SetFollowTarget event 1
  367.  * Minimap SetFollowTarget coordinate 10 20
  368.  *
  369.  * Minimap POIDesc <description>
  370.  * Example: Minimap POIDesc An Awesome City!
  371.  *
  372.  * Minimap POI_TP <poi_id x_offset y_offset direction fadeType>
  373.  * Example: Minimap POI_TP 1 1 0 0 0
  374.  * Note that teleporting with both offsets set to 0, will teleport the player straight into the center of the poi.
  375.  *
  376.  * Adding POI's (advanced plugin command!):
  377.  * 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
  378.  * Example that draws Actor1_3 on tile 10,10:
  379.  * Minimap AddPOI 1 A_Friend 10 10 img/enemies/ Actor1_3 0 0 254 225 64 64
  380.  * Note:
  381.  * - The real_x & real_y are in maptiles and not in coordinates. 0,0 is in the upper left corner.
  382.  * - name-value replaces underscores _  with spaces.
  383.  *
  384.  
  385.  *
  386.  *--------------------------------------
  387.  * Event comment-tags (case sentitive!)
  388.  *--------------------------------------
  389.  * To show an event on the minimap:
  390.  * <mm_show>
  391.  *
  392.  * To add a description to an event (for the minimap-scene)
  393.  * <mm_desc>
  394.  *
  395.  * To add teleport to the event:
  396.  * <mm_tp:offset_x offset_y direction fadeType>
  397.  * Example: <mm_tp:1 0 2 0>
  398.  * Notes:
  399.  *        - Offset is the offset in tiles with the event-location itself being 0 0
  400.  *        - Possible direction values: 2 (down), 4 (left), 6 (right), 8 (up). Or use a value of 0 to maintain the current player-facing-direction
  401.  *        - Possible fadeType values: 0 (black), 1 (white), 2 (none)
  402.  *
  403.  *
  404.  * Note to other scripters: You can access the variable that contains the window through this: "Silv.Minimap.Window" w/o the quotes.
  405.  *
  406.  *
  407.  *--------------------------------------
  408.  * Version History:
  409.  *--------------------------------------
  410.  * v.1.06 (06 December 2015)
  411.  *   - This plugin is now compatible with Yanfly's "Main Menu Manager" plugin. It also automatically disables (or even hides if you want) the map-menu-command if
  412.  *     you do not have an active minimap or simply do not possess the required items.
  413.  *   - Added a new mapnotetag: <mm_mapshot:map_id>. This one is used to display a mapshot from a different map in the current map. Handy in case you have duplicate maps
  414.  *     to prevent ending up with duplicate minimap images in your project folder.
  415.  *   - Removed a console.log() that I forgot to remove in 1.05 before release.
  416.  * v.1.05 (30 November 2015)
  417.  *   - I accidentally had some global variables declared above the window-initialization, I made them local now to save memory and to prevent incompatibility issues with other scripts.
  418.  *   - Fixed a crash when fading the scene without an active minimap.
  419.  * v.1.04 (27 November 2015) [Updated Parameters]
  420.  *   - Disabled strict-mode (Either Javascript or RPG Maker seems not to support this fully...).
  421.  *   - Fixed a typo that caused the minimap to not resize in height.
  422.  *   - Grouped the player-blink parameters together and removed the unused "Draw Player Icon" parameter (v.1.03 only removed it partially).
  423.  *   - New feature: focus the minimap-camera onto (moving-)events, coordinates or the player.
  424.  *   - Minor refactoring.
  425.  * v.1.03 (26 November 2015) [Updated Parameters]
  426.  *   - New feature: Use custom player blip.
  427.  *     - 2 new parameters: "Render Player Blip" & "Player Blip Graphic" and new mapnotetag: <mm_player_blip::player> and a new plugin parameter "Minimap setplayerblip <value>".
  428.  *     - Removed parameter "Draw Player Icon".
  429.  *   - Added a parameter to change minimap-opacity.
  430.  *   - Added plugin commands and map-notetags to switch between AutoScroll and Autofit map-modes, <mm_mapstyle:Scroll/Autofit>
  431.  * v.1.02 (25 November 2015) [Updated Parameters]
  432.  *   - Enabled strict mode.
  433.  *   - Added the 'Minimap ShowMapMenu' plugin-command.
  434.  *   - New feature: can now generate overworld-minimaps (w/o requiring mapshots) with the map-notetag: <mm_generate_worldmap> or <mm_generate_overworld> or <mm_generate_map>].
  435.  *   - New feature: generate passability overlay. Also comes with new map-notetag & plugin command. Supports 4-direction-passability.
  436.  *   - New feature: You can now (optional) open the minimap-menu through a keybinding and also close it with that same keybinding (if the left-menu is active).
  437.  *   - Fixed the minimap-visibility again (it was still not properly fixed in v1.01).
  438.  *   - Now requires Silvers Keybinding script 1.01 instead of 1.00.
  439.  *
  440.  * v.1.01 (24 November 2015) [Updated Parameters]
  441.  *   - Fixed the player-blip becoming invisible when walking on grass. Because of this I had to add 2 more advanced parameters.
  442.  *   - Fixed: The minimap no longer automatically shows itself again when it was manually hidden after opening a menu.
  443.  *   - Updated the version number to 1.01 (it was still 0.91) in the plugin description.
  444.  *   - Cleaned up some more out-commented code.
  445.  *   - Fixed: minimap can now hide again when it contains POI's.
  446.  *   - 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.
  447.  *
  448.  * v1.00 (23 November 2015)
  449.  *   - First release.
  450.  *
  451.  * v0.90-0.92 (November 2015)
  452.  *   - First alpha release.
  453.  *
  454.  */
  455. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  456. // Script start
  457. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  458. // Enable strict mode
  459. //'use strict'; // Either Javascript or RPG Maker MV bugs with this... So I disabled it.
  460.  
  461. // Get Plugin #Parameters
  462. var Silv = Silv || {};
  463. Silv.Plugins = Silv.Plugins || {};
  464. Silv.Plugins.Minimap = 1.06;
  465. if (!('Keys' in Silv.Plugins) || Silv.Plugins.Keys < 1.01) { throw 'ERROR: Silvers Minimap requires Silvers KeyMapper v1.00 or higher. It must be placed above the minimap script.'; }
  466. Silv.Parameters = $plugins.filter(function(p) { return p.description.contains('<SilvMinimap>'); })[0].parameters;
  467. Silv.Minimap = Silv.Minimap || {};
  468. Silv.Minimap.Menu = Silv.Minimap.Menu || {};
  469. Silv.Minimap.Generator = Silv.Minimap.Generator || {};
  470. // Non-parameters
  471. Silv.Minimap.Window = null;
  472. Silv.Minimap.POI = {};
  473. Silv.Minimap.Events = []; // Is an array of objects [{ Game_Event, Sprite_Character }]. USe .event and .sprite to retrieve the values.
  474. Silv.Minimap.ScreenIsFading = false;
  475. Silv.Minimap.Menu.Bmp = null;
  476. Silv.Minimap.Menu.Markers = [];
  477. Silv.Minimap.Menu.Enabled = false;
  478. Silv.Minimap.WasLoadedFromSave = false;
  479. 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.
  480. Silv.Minimap.TP_Dest = null;
  481. Silv.Minimap.CreateFunctionIsLocked = false;
  482. Silv.Minimap.Visible = true;
  483. // General
  484. Silv.Minimap.MapStyle = Silv.Parameters['Map Style'].toLowerCase();
  485. Silv.Minimap.GlobalMapZoom = parseFloat(Silv.Parameters['Global Map Zoom']);
  486. Silv.Minimap.Window_Opacity = parseInt(Silv.Parameters['Minimap Opacity']);
  487. // Positioning & Size
  488. Silv.Minimap.Window_X = parseInt(Silv.Parameters['X']);
  489. Silv.Minimap.Window_Y = parseInt(Silv.Parameters['Y']);
  490. Silv.Minimap.WindowWidth = parseInt(Silv.Parameters['Width']);
  491. Silv.Minimap.WindowHeight = parseInt(Silv.Parameters['Height']);
  492. Silv.Minimap.BorderWidth = parseInt(Silv.Parameters['Border Width']);
  493. Silv.Minimap.BorderHeight = parseInt(Silv.Parameters['Border Height']);
  494. Silv.Minimap.WindowHorizontalAlignment = Silv.Parameters['Horizontal Alignment'].toLowerCase();
  495. Silv.Minimap.WindowVerticalAlignment = Silv.Parameters['Vertical Alignment'].toLowerCase();
  496. // Player Blip
  497. Silv.Minimap.PlayerBlipEnabled = Silv.Parameters['Render Player Blip'].toLowerCase() == 'true';
  498. Silv.Minimap.PlayerBlipGraphic = Silv.Parameters['Player Blip Graphic'].toLowerCase();
  499. Silv.Minimap.PlayerIconWidth = parseInt(Silv.Parameters['Player Icon Width']);
  500. Silv.Minimap.PlayerIconHeight = parseInt(Silv.Parameters['Player Icon Height']);
  501. Silv.Minimap.PlayerBlinks = parseInt(Silv.Parameters['Player Blink Delay']) > 0; // note: is not directly a parameter but uses one to calculate the value instead
  502. Silv.Minimap.PlayerBlinkDelay = parseInt(Silv.Parameters['Player Blink Delay']);
  503. // Menu
  504. Silv.Minimap.Menu.MenuKey = Silv.Keys.fromStringParam(Silv.Parameters['Menu Key']);
  505. Silv.Minimap.Menu.PlayerDesc = Silv.Parameters['Menu Player Description'];
  506. Silv.Minimap.Menu.Zoom = parseFloat(Silv.Parameters['Menu Zoom']);
  507. Silv.Minimap.Menu.WindowWidth_Left = parseInt(Silv.Parameters['Menu Left Window Width']);
  508. Silv.Minimap.Menu.WindowHeight_MapSection = parseInt(Silv.Parameters['Menu Topright Window Height']);
  509. Silv.Minimap.Menu.EventRenderSize = parseInt(Silv.Parameters['Menu Event Render Size']);
  510. Silv.Minimap.Menu.PlayerIconSize = parseInt(Silv.Parameters['Menu Player Icon Size']);
  511. Silv.Minimap.Menu.ManualZoom_Min = parseFloat(Silv.Parameters['Menu Min Manual Zoom']);
  512. Silv.Minimap.Menu.ManualZoom_Max = parseFloat(Silv.Parameters['Menu Max Manual Zoom']);
  513. Silv.Minimap.Menu.ManualZoomKey_In = Silv.Keys.fromStringParam(Silv.Parameters['Menu Zoomin Key']);
  514. Silv.Minimap.Menu.ManualZoomKey_Out = Silv.Keys.fromStringParam(Silv.Parameters['Menu Zoomout Key']);
  515. Silv.Minimap.Menu.ManualZoomKey_Reset = Silv.Keys.fromStringParam(Silv.Parameters['Menu Reset Zoom Key']);
  516. Silv.Minimap.Menu.ManualScrollKey_Reset = Silv.Keys.fromStringParam(Silv.Parameters['Menu Reset Scroll Key']);
  517. // Passability Map
  518. Silv.Minimap.PassabilityOverlayOpacity = parseInt(Silv.Parameters['Passability Overlay Opacity']);
  519. Silv.Minimap.PassabilityColor = Silv.Parameters['Passability Color'];
  520. Silv.Minimap.ImpassabilityColor = Silv.Parameters['Impassability Color'];
  521. // Generator
  522. Silv.Minimap.Generator.MapColors = Silv.Parameters['Map Gen Tag Colors'].split(' ');
  523. Silv.Minimap.Generator.OverworldColors = Silv.Parameters['Overworld Gen Tag Colors'].split(' ');
  524. // The Rest
  525. Silv.Minimap.AllowTeleportation = Silv.Parameters['Allow Teleportation'].toLowerCase() == 'true';
  526. Silv.Minimap.StandardPadding = parseInt(Silv.Parameters['Standard Padding']);
  527. Silv.Minimap.WindowSkin = Silv.Parameters['Window Skin'];
  528. Silv.Minimap.MapBGFillColor = Silv.Parameters['Fill Color'].split(' ');
  529. Silv.Minimap.MaintainAspectRatio = Silv.Parameters['Maintain Aspect Ratio'].toLowerCase() == 'true';
  530. Silv.Minimap.FadeoutSpeed = parseInt(Silv.Parameters['Fadeout Speed']);
  531. Silv.Minimap.GlobalRequiredItem = parseInt(Silv.Parameters['Global Required Item']);
  532. Silv.Minimap.EventRenderSize = parseInt(Silv.Parameters['Event Render Size']);
  533. Silv.Minimap.AutoClearPOI = Silv.Parameters['Auto Clear POI'].toLowerCase() == 'true';
  534. Silv.Minimap.DrawOverlay = Silv.Parameters['Render Minimap Overlay'].toLowerCase() == 'true';
  535. // Manual Scrolling
  536. Silv.Minimap.AllowManualScrolling = Silv.Parameters['Allow Manual Scrolling'].toLowerCase() == 'true';
  537. Silv.Minimap.ManualScrollspeed = parseFloat(Silv.Parameters['Manual Scrollspeed']);
  538. Silv.Minimap.ManualScrollKeyUp = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Up']);
  539. Silv.Minimap.ManualScrollKeyRight = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Right']);
  540. Silv.Minimap.ManualScrollKeyDown = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Down']);
  541. Silv.Minimap.ManualScrollKeyLeft = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Left']);
  542. // Advanced & Debug
  543. Silv.Minimap.PlayerSpriteSrcFrame_Width = parseInt(Silv.Parameters['Player Sprite Sourceframe Width']);
  544. Silv.Minimap.PlayerSpriteSrcFrame_Height = parseInt(Silv.Parameters['Player Sprite Sourceframe Height']);
  545. Silv.Minimap.FrameSkip = parseInt(Silv.Parameters['Frame Skip']);
  546. Silv.Minimap.MapFilenameLength = parseInt(Silv.Parameters['Mapshot Filename Length']);
  547. Silv.Minimap.DebugMode = Silv.Parameters['Debug Mode'].toLowerCase() == 'true';
  548. Silv.Minimap.DrawDebugGrid = Silv.Parameters['Render Debug Grid'].toLowerCase() == 'true';
  549. Silv.Minimap.DebugGridImage = Silv.Parameters['Debug Grid Image'];
  550. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  551. (function()
  552. {
  553. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  554. // #Utilities & Misc
  555. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  556. // Example: lpad('2', '0') // result: '002'
  557. function lpad_mapname(word, padStr)
  558. {
  559.     word = String(word);
  560.     while (word.length < Silv.Minimap.MapFilenameLength) word = padStr + word;
  561.     return word;
  562. }
  563.  
  564. function minimapFolderPath()
  565. {
  566.     var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, "/img/minimap/");
  567.     if (path.match(/^\/([A-Z]\:)/)) { path = path.slice(1); }
  568.     path = decodeURIComponent(path);
  569.     return path;
  570. }
  571.  
  572. function getFullMinimapPath(filename)
  573. {
  574.     return minimapFolderPath() + filename;
  575. }
  576.  
  577. // filename example: '002.png'
  578. function minimapImageExists(filename)
  579. {
  580.     var fs = require('fs');
  581.     return fs.existsSync(getFullMinimapPath(filename));
  582. }
  583.  
  584. function dataMapGetEventByID(ev_id)
  585. {
  586.     for(var i=1; i< $dataMap.events.length; i++)
  587.     {
  588.         if ($dataMap.events[i].id == ev_id) { return $dataMap.events[i]; }
  589.     }
  590.     return null;
  591. }
  592.  
  593. ImageManager.loadMinimap = function(filename, hue)
  594. {
  595.     return this.loadBitmap('img/minimap/', filename, hue, false);
  596. };
  597.  
  598. // Do not just show the minimap on top of a faded-out screen.
  599. var alias_silv_mm_updateFadeOut = Game_Screen.prototype.updateFadeOut;
  600. Game_Screen.prototype.updateFadeOut = function() {
  601.     alias_silv_mm_updateFadeOut.call(this);
  602.    
  603.     if (this._brightness < 255) // (this._fadeOutDuration > 0)
  604.     {
  605.         Silv.Minimap.ScreenIsFading = true;
  606.         if (Silv.Minimap.Window !== null)
  607.         {
  608.             Silv.Minimap.Window.opacity = this._brightness;
  609.             Silv.Minimap.Window.contents.paintOpacity  = this._brightness;
  610.         }
  611.     }
  612.     else
  613.     {
  614.         Silv.Minimap.ScreenIsFading = false;
  615.     }
  616. };
  617. //------------------------------------------------------------------------------------------------------------------------------------
  618. // Store a reference to the player graphic.
  619. //------------------------------------------------------------------------------------------------------------------------------------
  620. var alias_silv_mm_createCharacters = Spriteset_Map.prototype.createCharacters;
  621. Spriteset_Map.prototype.createCharacters = function()
  622. {
  623.     alias_silv_mm_createCharacters.call(this);
  624.    
  625.     for (var i = this._characterSprites.length - 1; i >= 0; i--)
  626.     {
  627.         if (this._characterSprites[i]._character == $gamePlayer)
  628.         {
  629.             Spriteset_Map.prototype.playerSprite = this._characterSprites[i];
  630.             break;
  631.         }  
  632.     }
  633. };
  634. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  635. // Automatically create a event-Notetag from event-comments on the active page
  636. // Example usage: console.log($gameMap.event(1).event.silvNote);
  637. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  638. var alias_silv_mm_Game_Event_setupPage = Game_Event.prototype.setupPage;
  639. Game_Event.prototype.setupPage = function()
  640. {
  641.     alias_silv_mm_Game_Event_setupPage.call(this);
  642.     this.silvCreateNote();
  643. };
  644.  
  645. Game_Event.prototype.silvCreateNote = function()
  646. {
  647.     this.silvNote = '';
  648.     if (typeof this.page() === 'undefined') { return; }
  649.    
  650.     var list = this.list();
  651.     var str = null;
  652.     for (var commandProperty in list)
  653.     {
  654.         if (list.hasOwnProperty(commandProperty))
  655.         {
  656.             var command = list[commandProperty];
  657.             var commandCode = command.code;
  658.             if (commandCode == 108) // 108: new comment-item, always the first line.
  659.             {
  660.                 if (str !== null) { this.silvNote += str; }
  661.                 str = command.parameters[0];
  662.             }
  663.             else if (commandCode == 408) // 408: comment-line, but not the first one.
  664.             {
  665.                 this.silvNote += command.parameters[0];
  666.             }
  667.             else if (str) // It's not a comment-code, so add the previous str (if any) to the note.
  668.             {
  669.                 this.silvNote += str;
  670.                 str = null;
  671.             }
  672.         }
  673.     }
  674.     if (this.silvNote !== '') { this.extractSilvMetadata(); }
  675. };
  676.  
  677. // <mm_tp:1> will result in: '1'
  678. // <mm_tp:1> will result in: ['1', '0'];
  679. Game_Event.prototype.extractSilvMetadata = function() {
  680.     var re = /<([^<>:]+)(:?)([^>]*)>/g;
  681.     this.meta = {};
  682.     for (;;)
  683.     {
  684.         var match = re.exec(this.silvNote);
  685.         if (match)
  686.         {
  687.             if (match[2] === ':')
  688.             {
  689.                 var value = match[3];
  690.                 if (match[3].indexOf(' ') >= 0) { value = match[3].split(' '); }
  691.                
  692.                 this[match[1]] = value;
  693.             }
  694.             else
  695.             {
  696.                 this[match[1]] = true;
  697.             }
  698.         }
  699.         else
  700.         {
  701.             break;
  702.         }
  703.     }
  704. };
  705. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  706. // Minimap Window
  707. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  708. function Window_Minimap() { this.initialize.apply(this, arguments); }
  709. // Inherit from base window
  710. Window_Minimap.prototype = Object.create(Window_Base.prototype);
  711. // Set Constructor
  712. Window_Minimap.prototype.constructor = Window_Minimap;
  713.  
  714. Window_Minimap.prototype.loadWindowskin = function() { this.windowskin = ImageManager.loadSystem(Silv.Minimap.WindowSkin); };
  715. Window_Minimap.prototype.standardPadding = function() { return Silv.Minimap.StandardPadding; };
  716. //Window_Minimap.prototype.standardFontSize = function() { return Silv.Minimap.FontSize; }
  717. /* // old accidental global vars
  718. var mapBmp;
  719. var originalMapBmp;
  720.  
  721. var passabilityBmp;
  722. var drawPassabilityOverlay;
  723. var passabilityRequiresRedraw;
  724.  
  725. var drawAreaWidth;
  726. var drawAreaHeight;
  727. var mapWidth;
  728. var mapHeight;
  729. var playerBlinkCnt;
  730. var playerBlink_IsVisible;
  731. var frameSkip;
  732. var frameSkipCnt;
  733. var mapAspRatInfo;
  734. var mapZoom;
  735. var mapZoomInverse;
  736. var isManualScrolling;
  737. var allowManualScroll;
  738. var mapScroll;
  739. var lastPlayerLoc;
  740. var isFirstProcessedUpdate;
  741. var requiresDrawing; // as in AFTER isReady().
  742. var debugGridBmp;
  743. var overlayBmp;
  744. var menuZoom;
  745. var allowTeleportation;
  746. var playerFrame;
  747. var playerInfo;
  748. var minimapType;
  749. var mapStyle;
  750.  
  751. var playerBlipEnabled;
  752. var playerBlipGfx;
  753. var playerBlipBmp;
  754. var usePlayerBlipGfx;
  755.  
  756. var cameraFocusType; // player / event / coordinate
  757. var cameraFocusObject; // null / reference to event / {x:real_x, y:real_y}
  758. */
  759.  
  760. // #Initialization
  761. Window_Minimap.prototype.initialize = function(x, y, width, height, mapName, minimapType)
  762. {
  763.     this.mapName = mapName;
  764.     this.minimapType = minimapType;
  765.     if ('mm_size' in $dataMap.meta)
  766.     {
  767.         var newSize = $dataMap.meta.mm_size.split(' ');
  768.         this.width = parseInt(newSize[0]);
  769.         this.height = parseInt(newSize[1]);
  770.     }
  771.    
  772.     Window_Base.prototype.initialize.call(this, x, y, width, height);
  773.     this._helpWindow = null;
  774.     this._handlers = {};
  775.     this._touching = false;
  776.     this.deactivate();
  777.    
  778.     this.originalMapBmp = null;
  779.     this.passabilityBmp = null;
  780.     this.drawPassabilityOverlay = false;
  781.     this.isFadingOut = false;
  782.     this.isFadedOut = false;
  783.     this.setDrawMapBmp();
  784.     this.overlayBmp = ImageManager.loadMinimap('Overlay');
  785.     this.drawAreaWidth = this.contents.width - Silv.Minimap.BorderWidth * 2;
  786.     this.drawAreaHeight = this.contents.height - Silv.Minimap.BorderHeight * 2;
  787.     this.mapWidth = parseFloat($gameMap.width());
  788.     this.mapHeight = parseFloat($gameMap.height());
  789.     this.setAspectRatio();
  790.     this.playerBlinkCnt = Silv.Minimap.PlayerBlinkDelay;
  791.     this.playerBlink_IsVisible = true;
  792.     this.frameSkip = Silv.Minimap.FrameSkip;
  793.     this.frameSkipCnt = 0;
  794.     Silv.Minimap.Menu.Enabled = true;
  795.    
  796.     if ('mm_mapzoom' in $dataMap.meta) { this.mapZoom = parseFloat($dataMap.meta.mm_mapzoom); }
  797.     else { this.mapZoom = Silv.Minimap.GlobalMapZoom; }
  798.    
  799.     this.mapZoomInverse = 1 / this.mapZoom;
  800.     this.isFirstProcessedUpdate = true;
  801.     this.requiresDrawing = true; // as in AFTER isReady().
  802.    
  803.     this.isManualScrolling = false;
  804.        
  805.     if ('mm_allowmanualscroll' in $dataMap.meta) { this.allowManualScroll = $dataMap.meta.mm_allowmanualscroll.toLowerCase() == 'true'; }
  806.     else { this.allowManualScroll = Silv.Minimap.AllowManualScrolling; }
  807.    
  808.     this.mapScroll = {x: 0, y: 0, adjustment_x: 0, adjustment_y: 0};
  809.     this.lastPlayerLoc = {x: $gamePlayer._realX, y: $gamePlayer._realY};
  810.    
  811.     if ('mm_menuzoom' in $dataMap.meta) { this.menuZoom = $dataMap.meta.mm_menuzoom.toLowerCase() == 'true'; }
  812.     else { this.menuZoom = Silv.Minimap.Menu.Zoom; }
  813.    
  814.     if ('mm_tp_allow' in $dataMap.meta) { this.allowTeleportation = $dataMap.meta.mm_tp_allow.toLowerCase() == 'true'; }
  815.     else { this.allowTeleportation = Silv.Minimap.AllowTeleportation; }
  816.    
  817.     this.playerFrame = {x:0, y:0, width:Silv.Minimap.PlayerSpriteSrcFrame_Width, height:Silv.Minimap.PlayerSpriteSrcFrame_Height};
  818.    
  819.     if ('mm_mapstyle' in $dataMap.meta) { this.mapStyle = $dataMap.meta.mm_mapstyle.toLowerCase(); }
  820.     else { this.mapStyle = Silv.Minimap.MapStyle; }
  821.    
  822.     this.cameraFocusType = 'player'; // player / event / coordinate
  823.     this.cameraFocusObject = null; // null / reference to event / {x:real_x, y:real_y}
  824.    
  825.     this.initPlayerBlip();
  826.    
  827.     this.loadEvents();
  828.     this.debugGridBmp = ImageManager.loadMinimap(Silv.Minimap.DebugGridImage);
  829.        
  830.     // The update must be called AFTER all the initialization code.
  831.     this.update();
  832. };
  833.  
  834. Window_Minimap.prototype.setOpacity = function()
  835. {
  836.     this.opacity = Silv.Minimap.Window_Opacity;
  837. };
  838.  
  839. Window_Minimap.prototype.initPlayerBlip = function()
  840. {
  841.     this.playerBlipEnabled = Silv.Minimap.PlayerBlipEnabled;
  842.     this.playerBlipGfx = Silv.Minimap.PlayerBlipGraphic;
  843.     this.playerBlipBmp = null;
  844.    
  845.     if ('mm_player_blip' in $dataMap.meta) { this.setPlayerBlip($dataMap.meta.mm_player_blip); }
  846.     else { this.setPlayerBlip(Silv.Minimap.PlayerBlipGraphic); }
  847. };
  848.  
  849. Window_Minimap.prototype.setDrawMapBmp = function()
  850. {
  851.     switch (this.minimapType)
  852.     {
  853.         case 'regular':
  854.             if(this.originalMapBmp === null)
  855.             {
  856.                 this.originalMapBmp = ImageManager.loadMinimap(this.mapName);
  857.                 this.mapBmp = ImageManager.loadMinimap(this.mapName);
  858.             }
  859.             else if (this.originalMapBmp.isReady())
  860.             {
  861.                 this.mapBmp = new Bitmap(this.originalMapBmp.width, this.originalMapBmp.height);
  862.                 this.mapBmp.blt(this.originalMapBmp, 0, 0, this.originalMapBmp.width, this.originalMapBmp.height, 0, 0); // Because nobody knows how to clone a bitmap, we do it like this...
  863.                 this.requiresDrawing = false;
  864.             }
  865.             break;
  866.         case 'generate_map':
  867.             this.mapBmp = this.generateMap(Silv.Minimap.Generator.MapColors);
  868.             this.requiresDrawing = false;
  869.             break;
  870.         case 'generate_overworld':
  871.             this.mapBmp = this.generateMap(Silv.Minimap.Generator.OverworldColors);
  872.             this.requiresDrawing = false;
  873.             break;
  874.         default:
  875.             throw 'Window_Minimap.prototype.GetMapBmp has invalid switch-value: ' + this.minimapType;
  876.     }
  877.    
  878.     if (this.drawPassabilityOverlay)
  879.     {
  880.         if (this.originalMapBmp.isReady()) { this.bltPassabilityOverlay(); }
  881.         else { this.passabilityRequiresRedraw = true; }
  882.     }
  883. };
  884. //----------------------------------------------------------------------------------------------------
  885. // #Show & #Hide
  886. //----------------------------------------------------------------------------------------------------
  887. var alias_silv_mm_hide = Window_Minimap.prototype.hide;
  888. Window_Minimap.prototype.hide = function()
  889. {
  890.     alias_silv_mm_hide.call(this);
  891.     Silv.Minimap.Visible = false;
  892. };
  893.  
  894. var alias_silv_mm_show = Window_Minimap.prototype.show;
  895. Window_Minimap.prototype.show = function()
  896. {
  897.     alias_silv_mm_show.call(this);
  898.     Silv.Minimap.Visible = true;
  899. };
  900. //----------------------------------------------------------------------------------------------------
  901. // #Passability #Overlay
  902. //----------------------------------------------------------------------------------------------------
  903. Window_Minimap.prototype.bltPassabilityOverlay = function()
  904. {
  905.     // Generate the bitmap if it wasn't done already
  906.     if (this.passabilityBmp === null) { this.passabilityBmp = this.generatePassabilityBmp(); }
  907.    
  908.     // Blt the overlay on top of the this.mapBmp
  909.     this.mapBmp.blt(this.passabilityBmp, 0, 0, this.passabilityBmp.width, this.passabilityBmp.height, 0, 0);
  910.    
  911.     this.passabilityRequiresRedraw = false;
  912. };
  913.  
  914. Window_Minimap.prototype.setPassabilityOverlay = function(enabled)
  915. {
  916.     this.drawPassabilityOverlay = enabled;
  917.     this.setDrawMapBmp();
  918. };
  919.  
  920. // Dev note: this method can be severely optimized by replacing it with a modified version of the $GameMap.checkPassage(). Calling gameMap.isPassable() 4x per tile is not effective because internally it starts looping through them 4x instead of 1.
  921. Window_Minimap.prototype.generatePassabilityBmp = function()
  922. {
  923.     var tile_w = $gameMap.tileWidth();
  924.     var tile_h = $gameMap.tileHeight();
  925.     var bmp = new Bitmap($gameMap.width() * tile_w, $gameMap.height() * tile_h);
  926.     bmp.paintOpacity = Silv.Minimap.PassabilityOverlayOpacity;
  927.     var borderTickness = 8;
  928.    
  929.     for (var y=0; y<$dataMap.height; y++)
  930.     {
  931.         for (var x=0; x<$dataMap.width; x++)
  932.         {
  933.             var passability = {2:$gameMap.isPassable(x, y, 2), 4:$gameMap.isPassable(x, y, 4), 6:$gameMap.isPassable(x, y, 6), 8:$gameMap.isPassable(x, y, 8)};
  934.            
  935.             if (!passability[2] && !passability[4] && !passability[6] && !passability[8])
  936.             {
  937.                 bmp.fillRect(x * tile_w, y * tile_h, tile_w, tile_h, Silv.Minimap.ImpassabilityColor);
  938.             }
  939.             else
  940.             {
  941.                 bmp.paintOpacity = 255;
  942.                 if (!passability[8]) { bmp.fillRect(x * tile_w, y * tile_h, tile_w, borderTickness, Silv.Minimap.ImpassabilityColor); } // top
  943.                 if (!passability[6]) { bmp.fillRect(x * tile_w + tile_w - borderTickness, y * tile_h, borderTickness, tile_h, Silv.Minimap.ImpassabilityColor); } // right
  944.                 if (!passability[2]) { bmp.fillRect(x * tile_w, y * tile_h + tile_h - borderTickness, tile_w, borderTickness, Silv.Minimap.ImpassabilityColor); } // bottom
  945.                 if (!passability[4]) { bmp.fillRect(x * tile_w, y * tile_h, borderTickness, tile_h, Silv.Minimap.ImpassabilityColor); } // left
  946.                 bmp.paintOpacity = Silv.Minimap.PassabilityOverlayOpacity;
  947.                
  948.                 bmp.fillRect(x * tile_w, y * tile_h, tile_w, tile_h, Silv.Minimap.PassabilityColor);
  949.             }
  950.         }
  951.     }
  952.     return bmp;
  953. };
  954.  
  955. //----------------------------------------------------------------------------------------------------
  956. // #Generate Maps
  957. //----------------------------------------------------------------------------------------------------
  958. Window_Minimap.prototype.generateMap = function(colors)
  959. {
  960.     var tile_w = $gameMap.tileWidth();
  961.     var tile_h = $gameMap.tileHeight();
  962.     var bmp = new Bitmap($gameMap.width() * tile_w, $gameMap.height() * tile_h);
  963.    
  964.     for (var y=0; y<$dataMap.height; y++)
  965.     {
  966.         for (var x=0; x<$dataMap.width; x++)
  967.         {
  968.             bmp.fillRect(x * tile_w, y * tile_h, tile_w, tile_h, colors[$gameMap.terrainTag(x, y)]); // Default: lightgreen, blue, brown, darkgreen, lightbrown
  969.         }
  970.     }
  971.     return bmp;
  972. };
  973.  
  974. //----------------------------------------------------------------------------------------------------
  975. // <Asorted>
  976. //----------------------------------------------------------------------------------------------------
  977. Window_Minimap.prototype.showMapMenuScene = function()
  978. {
  979.     Silv.Minimap.Window.pushMapScene();
  980. };
  981.  
  982. Window_Minimap.prototype.clamp = function(value, min, max)
  983. {
  984.     return Math.min(Math.max(value, min), max);
  985. };
  986.    
  987. // This function requires this.mapBmp to be fully initialized.
  988. // #Aspect #Ratio #AspectRatio
  989. Window_Minimap.prototype.setAspectRatio = function()
  990. {
  991.     // this.mapAspRatInfo.scaleDelta_x is the difference in size between the mapwidth (in pixels, NOT in tiles) and the minimap (render)width.
  992.     this.mapAspRatInfo = { w: 0.0, h: 0.0, offset_x: 0.0, offset_y: 0.0, scaleDelta_x: 0.0, scaleDelta_y: 0.0 };
  993.     var w = $gameMap.width();
  994.     var h = $gameMap.height();
  995.    
  996.     // Map Aspect Ratio
  997.     if (!Silv.Minimap.MaintainAspectRatio || (w == h))
  998.     {
  999.         this.mapAspRatInfo.w = 1.0;
  1000.         this.mapAspRatInfo.h = 1.0;
  1001.     }
  1002.     else if (w > h)
  1003.     {
  1004.         this.mapAspRatInfo.w = 1.0;
  1005.         this.mapAspRatInfo.h = h / parseFloat(w);
  1006.     }
  1007.     else // if (h > w)
  1008.     {
  1009.         this.mapAspRatInfo.w = w / parseFloat(h);
  1010.         this.mapAspRatInfo.h = 1.0;
  1011.     }
  1012.    
  1013.     this.mapAspRatInfo.scaleDelta_x = this.drawAreaWidth / parseFloat($gameMap.width() * $gameMap.tileWidth());
  1014.     this.mapAspRatInfo.scaleDelta_y = this.drawAreaHeight / parseFloat($gameMap.height() * $gameMap.tileHeight());
  1015. };
  1016.  
  1017. // #Events
  1018. Window_Minimap.prototype.loadEvents = function()
  1019. {
  1020.     Silv.Minimap.Events = [];
  1021.     for (var ev_idx = 1; ev_idx < $dataMap.events.length; ev_idx++) // Note: start at 1. Because the first one is always null.
  1022.     {
  1023.         if ($dataMap.events[ev_idx] !== null)
  1024.         {
  1025.             var ev = $gameMap.event(ev_idx);
  1026.            
  1027.             // Check Event Note
  1028.             if ($dataMap.events[ev_idx].note != '' || ('mm_show' in ev))
  1029.             {
  1030.                 var cmds = $dataMap.events[ev_idx].note.toLowerCase().split(' ');
  1031.                 if ((cmds.indexOf('mm_show') > -1) ||  ('mm_show' in ev))
  1032.                 {
  1033.                     var new_ev = {event: ev, sprite: this.getEventCharacterSprite(ev.eventId())};
  1034.                     Silv.Minimap.Events.push(new_ev); // Add event to the array so we can render it on the minimap
  1035.                 }
  1036.             }
  1037.         }
  1038.     }
  1039.     if (Silv.Minimap.DebugMode) { console.log('Loaded Events:'); console.log(Silv.Minimap.Events); }
  1040. };
  1041.  
  1042. Window_Minimap.prototype.getEventCharacterSprite = function(ev_id)
  1043. {
  1044.     for (var i=0; i < SceneManager._scene._spriteset._characterSprites.length; i++)
  1045.     {
  1046.         var eventSprite = SceneManager._scene._spriteset._characterSprites[i];
  1047.         if (eventSprite._character.eventId() == ev_id)
  1048.         {
  1049.             return eventSprite;
  1050.         }
  1051.     }
  1052.     throw 'getEventCharacterSprite() did not find a match for ev_id: ' + ev_id;
  1053. };
  1054.    
  1055. // #update
  1056. Window_Minimap.prototype.update = function()
  1057. {
  1058.     if (!this.skipFrame() && (this.originalMapBmp === null || this.originalMapBmp.isReady()))
  1059.     {
  1060.         Window_Base.prototype.update.call(this);
  1061.         this.updateFadeOut();
  1062.         this.updateInput();
  1063.         if (Silv.Minimap.PlayerBlinks) { this.updatePlayerBlink(); }
  1064.         this.updateMapScroll(this.isFirstProcessedUpdate);
  1065.         this.playerInfo = this.getPlayerBitmap();
  1066.         if (this.requiresDrawing) { this.setDrawMapBmp(); }
  1067.         this.drawMinimap();
  1068.         this.lastPlayerLoc.x  = $gamePlayer._realX;
  1069.         this.lastPlayerLoc.y  = $gamePlayer._realY;
  1070.         this.isFirstProcessedUpdate = false;
  1071.        
  1072.         // Teleport
  1073.         if (Silv.Minimap.TP_Dest !== null)
  1074.         {
  1075.             this.teleport(Silv.Minimap.TP_Dest);
  1076.             Silv.Minimap.TP_Dest = null;
  1077.         }
  1078.        
  1079.         if (this.passabilityRequiresRedraw && this.originalMapBmp.isReady()) { this.bltPassabilityOverlay(); }
  1080.     }
  1081.    
  1082.     if (Input.isTriggered(Silv.Minimap.Menu.MenuKey)) { this.showMapMenuScene(); }
  1083. };
  1084.  
  1085. Window_Minimap.prototype.getPlayerBitmap = function()
  1086. {
  1087.     var playerSpr = Spriteset_Map.prototype.playerSprite;
  1088.     // Player is not in bush, so return the regular player-graphic
  1089.     if (playerSpr._bushDepth == 0 || playerSpr._lowerBody === null)
  1090.     {
  1091.         return { bmp:playerSpr._bitmap, src:playerSpr._frame };
  1092.     }
  1093.  
  1094.     // Create Bush graphic (which is divided into 2 graphics by the RM-code..)
  1095.     var playerBmp = new Bitmap(Silv.Minimap.PlayerSpriteSrcFrame_Width, Silv.Minimap.PlayerSpriteSrcFrame_Height);
  1096.     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,
  1097.                   0, Silv.Minimap.PlayerSpriteSrcFrame_Height - playerSpr._bushDepth, Silv.Minimap.PlayerIconSize, Silv.Minimap.PlayerIconSize);
  1098.     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,
  1099.                   0, 0, Silv.Minimap.PlayerIconSize, Silv.Minimap.PlayerIconSize);
  1100.    
  1101.     return {bmp:playerBmp, src:this.playerFrame};
  1102. };
  1103.  
  1104. Window_Minimap.prototype.updateInput = function()
  1105. {
  1106.     if (Input.isPressed(Silv.Minimap.ManualScrollKeyUp))    { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x, Silv.Minimap.Window.mapScroll.y - Silv.Minimap.ManualScrollspeed); }
  1107.     if (Input.isPressed(Silv.Minimap.ManualScrollKeyRight)) { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x + Silv.Minimap.ManualScrollspeed, Silv.Minimap.Window.mapScroll.y); }
  1108.     if (Input.isPressed(Silv.Minimap.ManualScrollKeyDown))  { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x, Silv.Minimap.Window.mapScroll.y + Silv.Minimap.ManualScrollspeed); }
  1109.     if (Input.isPressed(Silv.Minimap.ManualScrollKeyLeft))  { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x - Silv.Minimap.ManualScrollspeed, Silv.Minimap.Window.mapScroll.y); }
  1110. };
  1111.  
  1112. Window_Minimap.prototype.teleport = function(tp_info)
  1113. {
  1114.     var direction = $gamePlayer._direction;
  1115.     if (tp_info[2] != 0) { direction = parseInt(tp_info[2]); }
  1116.  
  1117.     $gamePlayer.reserveTransfer($gameMap._mapId, tp_info[0], tp_info[1], direction, parseInt(tp_info[3]));
  1118. };
  1119.  
  1120. Window_Minimap.prototype.playerLocChanged = function()
  1121. {
  1122.     return this.lastPlayerLoc.x != $gamePlayer._realX || this.lastPlayerLoc.y != $gamePlayer._realY;
  1123. };
  1124.  
  1125. //----------------------------------------------------------------------------------------------------
  1126. // #Scroll
  1127. //----------------------------------------------------------------------------------------------------
  1128. Window_Minimap.prototype.updateMapScroll = function(force)
  1129. {
  1130.     switch (this.cameraFocusType)
  1131.     {
  1132.         case 'player':
  1133.             if (this.playerLocChanged() || force) // Only update mapscroll if the player changed location. This way manual-scrolling is made possible.
  1134.             {
  1135.                 this.isManualScrolling = false;
  1136.                 this.scrollToMapObject($gamePlayer._realX, $gamePlayer._realY);
  1137.             }
  1138.             break;
  1139.         case 'event':
  1140.             this.isManualScrolling = false;
  1141.             this.scrollToMapObject(this.cameraFocusObject._realX, this.cameraFocusObject._realY);
  1142.             break;
  1143.         case 'coordinate':
  1144.             this.isManualScrolling = false;
  1145.             this.scrollToMapObject(this.cameraFocusObject.x, this.cameraFocusObject.y);
  1146.             break;
  1147.         default:
  1148.             throw 'Invalid switch-value in updateMapScroll(). Value: ' + this.cameraFocusType;
  1149.     }
  1150. };
  1151.  
  1152. Window_Minimap.prototype.setCameraFollowTarget = function(followType, value)
  1153. {
  1154.     this.cameraFocusType = followType; // Must be set before calling updateMapScroll()
  1155.     switch (followType)
  1156.     {
  1157.         case 'player':
  1158.             this.cameraFocusObject = null;
  1159.             this.updateMapScroll(true); // refresh the camera to focus on the player. Because he may not be moving when this was called.
  1160.             break;
  1161.         case 'event':
  1162.             this.cameraFocusObject = $gameMap.event(parseInt(value));
  1163.             if (typeof this.cameraFocusObject === 'undefined') { throw 'setCameraFollowTarget() invalid event-id: ' + value; }
  1164.             break;
  1165.         case 'coordinate':
  1166.             if (Object.prototype.toString.call( value ) !== '[object Array]') { throw 'setCameraFollowTarget() value-param must be an array. Received type: ' + typeof value; }
  1167.             this.cameraFocusObject = { x:value[0], y:value[1] };
  1168.             break;
  1169.         default:
  1170.             throw 'Invalid switch-value in setCameraFollowTarget(). Value: ' + followType;
  1171.     }
  1172.    
  1173. };
  1174.  
  1175. Window_Minimap.prototype.scrollToMapObject = function(real_x, real_y)
  1176. {
  1177.     this.setMapScroll(real_x * $gameMap.tileWidth() - (this.drawAreaWidth / 2 * this.mapZoomInverse), real_y * $gameMap.tileHeight() - (this.drawAreaHeight / 2 * this.mapZoomInverse));
  1178. };
  1179.  
  1180. Window_Minimap.prototype.setMapScroll = function(scroll_x, scroll_y)
  1181. {
  1182.     var old_x = this.mapScroll.x = scroll_x;
  1183.     var source_w = this.drawAreaWidth * this.mapZoomInverse;
  1184.     this.mapScroll.x = this.clamp(this.mapScroll.x, 0, this.mapBmp.width - source_w);
  1185.     this.mapScroll.adjustment_x = old_x - this.mapScroll.x; // clamp difference
  1186.    
  1187.     var old_y = this.mapScroll.y = scroll_y;
  1188.     var source_h = this.drawAreaHeight * this.mapZoomInverse;
  1189.     this.mapScroll.y = this.clamp(this.mapScroll.y, 0, this.mapBmp.height - source_h);
  1190.     this.mapScroll.adjustment_y = old_y - this.mapScroll.y; // clamp difference
  1191. };
  1192. //----------------------------------------------------------------------------------------------------
  1193.  
  1194. Window_Minimap.prototype.manualScroll = function(scroll_x, scroll_y)
  1195. {
  1196.     this.setMapScroll(scroll_x, scroll_y);
  1197.     this.isManualScrolling = true;
  1198. };
  1199.  
  1200. // Skips frame (returns true) if frameSkipCnt > frameSkip
  1201. Window_Minimap.prototype.skipFrame = function()
  1202. {
  1203.     if (this.frameSkip == 0) { return false; } // process frame
  1204.    
  1205.     this.frameSkipCnt++;
  1206.     if (this.frameSkipCnt < this.frameSkip)
  1207.     {
  1208.         return true; // skip frame
  1209.     }
  1210.     else
  1211.     {
  1212.         this.frameSkipCnt = 0;
  1213.         return false; // process frame
  1214.     }
  1215. };
  1216.  
  1217. Window_Minimap.prototype.updatePlayerBlink = function()
  1218. {
  1219.     this.playerBlinkCnt--;
  1220.     if (this.playerBlinkCnt <= 0)      
  1221.     {  
  1222.         this.playerBlinkCnt = Silv.Minimap.PlayerBlinkDelay;
  1223.         this.playerBlink_IsVisible = !this.playerBlink_IsVisible;
  1224.     }
  1225. };
  1226.  
  1227. //----------------------------------------------------------------------------------------------------
  1228. // Window Fading
  1229. //----------------------------------------------------------------------------------------------------
  1230. Window_Minimap.prototype.updateFadeOut = function()
  1231. {
  1232.     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.
  1233.     if (this.isFadingOut) { this.fadeOut(); }
  1234. };
  1235.  
  1236. Window_Minimap.prototype.fadeOut = function()
  1237. {
  1238.     this.opacity = this.contentsOpacity -= Silv.Minimap.FadeoutSpeed;
  1239.     this.isFadedOut = (this.opacity <= 0);
  1240. };
  1241.  
  1242. Window_Minimap.prototype.resetFade = function()
  1243. {
  1244.     this.isFadingOut = false;
  1245.     this.fadeOutCnt = 0;
  1246.     this.opacity = this.contentsOpacity  = 255;
  1247.     this.isFadedOut = false;
  1248. };
  1249.  
  1250. Window_Minimap.prototype.fadeOutInstantly = function()
  1251. {
  1252.     this.opacity = this.contentsOpacity = 0;
  1253.     this.isFadedOut = true;
  1254. };
  1255.  
  1256. //----------------------------------------------------------------------------------------------------
  1257. // #Menu
  1258. //----------------------------------------------------------------------------------------------------
  1259. // This method is required for compatibility with Yanfly's Main Menu Manager.
  1260. Scene_Menu.prototype.commandSilvMap = function()
  1261. {
  1262.     Silv.Minimap.Window.pushMapScene();
  1263. };
  1264.  
  1265. var alias_silv_Scene_Map_callMenu = Scene_Map.prototype.callMenu;
  1266. Scene_Map.prototype.callMenu = function()
  1267. {
  1268.     if (Silv.Minimap.Menu.Enabled) { Silv.Minimap.Window.createMenuData();  }
  1269.     alias_silv_Scene_Map_callMenu.call(this);
  1270. };
  1271.  
  1272. Window_Minimap.prototype.createMenuData = function()
  1273. {
  1274.     this.createMenuBmp();
  1275.     this.createMenuMarkers();
  1276. };
  1277.  
  1278. Window_Minimap.prototype.pushMapScene = function()
  1279. {
  1280.     this.createMenuData();
  1281.     if (Silv.Minimap.Menu.Enabled)
  1282.     {
  1283.         if (Silv.Minimap.Menu.Bmp !== null) { SceneManager.push(Scene_MiniMap); }
  1284.         else { throw 'pushMapScene() was called, the minimap-menu was enabled BUT Silv.Minimap.Menu.Bmp equals null?'; }
  1285.     }
  1286.     else
  1287.     {
  1288.         throw 'pushMapScene() was called but the Minimap (menu) was not enabled.';
  1289.     }
  1290. };
  1291. //----------------------------------------------------------------------------------------------------
  1292. // Create Menu Bitmap
  1293. //----------------------------------------------------------------------------------------------------
  1294. Window_Minimap.prototype.createMenuBmp = function()
  1295. {
  1296.     Silv.Minimap.Menu.Bmp = new Bitmap(this.mapBmp.width * this.menuZoom, this.mapBmp.height * this.menuZoom);
  1297.    
  1298.     this.tileInfo = {
  1299.             w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.menuZoom,
  1300.             h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.menuZoom
  1301.         };
  1302.    
  1303.     // Draw Map
  1304.     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);
  1305.    
  1306.     // Draw Debug Grid
  1307.     if (Silv.Minimap.DrawDebugGrid)
  1308.     {
  1309.         for (var i=0; i < $gameMap.width(); i++)
  1310.         {
  1311.             for (var j=0; j < $gameMap.height(); j++)
  1312.             {
  1313.                 var debugTileLoc = this.translateLocationMenu(this, i, j, this.tileInfo.w * this.menuZoom, this.tileInfo.h * this.menuZoom);
  1314.                 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);
  1315.             }
  1316.         }
  1317.     }
  1318.    
  1319.     // Draw POI's
  1320.     for (var i = 0; i < this.getAllPOI().length; i++)
  1321.     {
  1322.         var poi = this.getPOIByIdx(i);
  1323.         var poiLoc = this.translateLocationMenu(this, poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  1324.         Silv.Minimap.Menu.Bmp.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
  1325.                                   poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
  1326.     }
  1327.    
  1328.     // Draw Events
  1329.     for (var i=0; i < Silv.Minimap.Events.length; i++)
  1330.     {
  1331.         var ev = Silv.Minimap.Events[i].event;
  1332.         var ev_sprite = Silv.Minimap.Events[i].sprite;
  1333.         var evMapLoc = this.translateLocationMenu(this, ev._realX, ev._realY, Silv.Minimap.Menu.EventRenderSize, Silv.Minimap.Menu.EventRenderSize);
  1334.         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);
  1335.     }
  1336.    
  1337.     // Draw Player
  1338.     if (this.playerBlipEnabled)
  1339.     {
  1340.         this.drawPlayerBlip(Silv.Minimap.Menu.Bmp, this.translateLocationMenu, this.playerInfo.src.x, this.playerInfo.src.y, this.playerInfo.src.width, this.playerInfo.src.height,
  1341.                             Silv.Minimap.Menu.PlayerIconSize, Silv.Minimap.Menu.PlayerIconSize);
  1342.     }
  1343. };
  1344. //----------------------------------------------------------------------------------------------------
  1345. // Menu Create #Markers
  1346. //----------------------------------------------------------------------------------------------------
  1347. Window_Minimap.prototype.createMenuMarkers = function()
  1348. {
  1349.     Silv.Minimap.Menu.Markers = [];
  1350.    
  1351.     // Player
  1352.     var playerMapLoc = this.translateLocationMenu(this, $gamePlayer._realX, $gamePlayer._realY, Silv.Minimap.Menu.PlayerIconSize, Silv.Minimap.Menu.PlayerIconSize);
  1353.     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});
  1354.    
  1355.     // POI's
  1356.     for (var i = 0; i < this.getAllPOI().length; i++)
  1357.     {
  1358.         var poi = this.getPOIByIdx(i);
  1359.         var poiLoc = this.translateLocationMenu(this, poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  1360.        
  1361.         var tp = poi.tp.slice(0); // slice(0) clones it
  1362.         if (this.allowTeleportation && (poi.tp !== null))
  1363.         {
  1364.             tp[0] = parseInt(tp[0]) + parseInt(poi.real_x);
  1365.             tp[1] = parseInt(tp[1]) + parseInt(poi.real_y);
  1366.         }
  1367.        
  1368.         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});
  1369.     }
  1370.    
  1371.     // Events
  1372.     for (var i=0; i < Silv.Minimap.Events.length; i++)
  1373.     {
  1374.         var ev = Silv.Minimap.Events[i].event;
  1375.         var evMapLoc = this.translateLocationMenu(this, ev._realX, ev._realY, Silv.Minimap.Menu.EventRenderSize, Silv.Minimap.Menu.EventRenderSize);
  1376.        
  1377.         var desc = '';
  1378.         if ('mm_desc' in ev) { desc = ev.mm_desc.join(' '); }
  1379.        
  1380.         var tp = null;
  1381.         if (this.allowTeleportation && ('mm_tp' in ev))
  1382.         {
  1383.             tp = ev.mm_tp.slice(0); // slice(0) clones it
  1384.             tp[0] = parseInt(tp[0]) + parseInt(ev._x);
  1385.             tp[1] = parseInt(tp[1]) + parseInt(ev._y);
  1386.         }
  1387.        
  1388.         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});
  1389.     }
  1390. };
  1391. //----------------------------------------------------------------------------------------------------
  1392. // #Rendering #Drawing
  1393. //----------------------------------------------------------------------------------------------------
  1394. Window_Minimap.prototype.setPlayerBlip = function(filename)
  1395. {
  1396.     this.usePlayerBlipGfx = (filename == ':player');
  1397.     if (this.usePlayerBlipGfx) { this.playerBlipBmp = null; }
  1398.     else { this.playerBlipBmp = ImageManager.loadMinimap(filename); }
  1399. };
  1400.  
  1401. Window_Minimap.prototype.drawPlayerBlip = function(destBmp, translateFunc, src_x, src_y, src_w, src_h, dest_w, dest_h)
  1402. {
  1403.     var playerMapLoc = translateFunc(this, $gamePlayer._realX, $gamePlayer._realY, dest_w, dest_h);
  1404.     if (this.usePlayerBlipGfx)
  1405.     {
  1406.         destBmp.blt(this.playerInfo.bmp, src_x, src_y, src_w, src_h, playerMapLoc.x, playerMapLoc.y, dest_w, dest_h);
  1407.     }
  1408.     else
  1409.     {
  1410.         // Use custom player blip graphic
  1411.         if (this.playerBlipBmp.isReady())
  1412.         {
  1413.             destBmp.blt(this.playerBlipBmp, 0, 0, this.playerBlipBmp.width, this.playerBlipBmp.height, playerMapLoc.x, playerMapLoc.y, dest_w, dest_h);
  1414.         }
  1415.     }
  1416. };
  1417.  
  1418. Window_Minimap.prototype.drawMinimap = function()
  1419. {
  1420.     this.contents.clear();
  1421.    
  1422.     // BG fill colour, if applicable
  1423.     this.contents.fillRect(Silv.Minimap.BorderWidth, Silv.Minimap.BorderHeight, this.drawAreaWidth, this.drawAreaHeight, Silv.Minimap.MapBGFillColor);
  1424.    
  1425.     switch(this.mapStyle)
  1426.     {
  1427.         case 'autofit':
  1428.             this.drawstyleAutofit();
  1429.             break;
  1430.         case 'scroll':
  1431.             this.drawstyleScroll();
  1432.             break; 
  1433.         default:
  1434.             throw 'Window_Minimap.prototype.drawMinimap invalid switch value: ' + this.mapStyle;
  1435.     }
  1436. };
  1437.  
  1438. Window_Minimap.prototype.drawstyleAutofit = function()
  1439. {
  1440.     // Opacity
  1441.     this.contents.paintOpacity = this.opacity = Silv.Minimap.Window_Opacity;
  1442.    
  1443.     var destination_w = this.drawAreaWidth  * this.mapAspRatInfo.w;
  1444.     var destination_h = this.drawAreaHeight * this.mapAspRatInfo.h;
  1445.    
  1446.     // Calculate the aspect ratio offsets
  1447.     this.mapAspRatInfo.offset_x = 0.0; // to center the map
  1448.     this.mapAspRatInfo.offset_y = 0.0; // to center the map
  1449.     if (this.mapAspRatInfo.w < 1.0) { this.mapAspRatInfo.offset_x = (this.drawAreaWidth  - destination_w) / 2.0; }
  1450.     if (this.mapAspRatInfo.h < 1.0) { this.mapAspRatInfo.offset_y = (this.drawAreaHeight - destination_h) / 2.0; }
  1451.    
  1452.     // This variable saves on calculations further down the road during this update
  1453.     // w = width, hw=  half width, zhw = zoomed half width
  1454.     this.tileInfo = {
  1455.             w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.mapAspRatInfo.w,
  1456.             h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.mapAspRatInfo.h
  1457.         };
  1458.    
  1459.     // Draw Map
  1460.     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);
  1461.  
  1462.     // Debug Grid (if applicable)
  1463.     if (Silv.Minimap.DrawDebugGrid)
  1464.     {
  1465.         for (var i=0; i < $gameMap.width(); i++)
  1466.         {
  1467.             for (var j=0; j < $gameMap.height(); j++)
  1468.             {
  1469.                 var debugTileLoc = this.translateLocationAutofit(this, i, j, this.tileInfo.w * this.mapAspRatInfo.w, this.tileInfo.h * this.mapAspRatInfo.h);
  1470.                 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);
  1471.             }
  1472.         }
  1473.     }
  1474.    
  1475.     // Draw POI's
  1476.     for (var i = 0; i < this.getAllPOI().length; i++)
  1477.     {
  1478.         var poi = this.getPOIByIdx(i);
  1479.         var poiLoc = this.translateLocationAutofit(this, poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  1480.         this.contents.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
  1481.                           poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
  1482.     }
  1483.    
  1484.     // Draw Events
  1485.     for (var i=0; i < Silv.Minimap.Events.length; i++)
  1486.     {
  1487.         var ev = Silv.Minimap.Events[i].event;
  1488.         var ev_sprite = Silv.Minimap.Events[i].sprite;
  1489.         var evMapLoc = this.translateLocationAutofit(this, ev._realX, ev._realY, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
  1490.         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);
  1491.     }
  1492.    
  1493.     // Draw Player
  1494.     if (this.playerBlipEnabled && this.playerBlink_IsVisible)
  1495.     {
  1496.         this.drawPlayerBlip(this.contents, this.translateLocationAutofit, this.playerInfo.src.x, this.playerInfo.src.y, this.playerInfo.src.width, this.playerInfo.src.height,
  1497.                             Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
  1498.     }
  1499.    
  1500.     // Overlay (if applicable)
  1501.     if (Silv.Minimap.DrawOverlay) { this.drawOverlay(); }
  1502. };
  1503.  
  1504. Window_Minimap.prototype.drawstyleScroll = function()
  1505. {
  1506.     // Opacity
  1507.     this.contents.paintOpacity = this.opacity = Silv.Minimap.Window_Opacity;
  1508.    
  1509.     // 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
  1510.     if (this.mapScroll.x < 0 || this.drawAreaWidth  * this.mapZoomInverse > this.mapBmp.width ||
  1511.         this.mapScroll.y < 0 || this.drawAreaHeight * this.mapZoomInverse > this.mapBmp.height)
  1512.         {
  1513.             this.drawstyleAutofit();
  1514.             return;
  1515.         }
  1516.    
  1517.     // This variable saves on calculations further down the road during this update
  1518.     // w = width, hw=  half width, zhw = zoomed half width
  1519.     this.tileInfo = {
  1520.             w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.mapZoom,
  1521.             h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.mapZoom
  1522.         };
  1523.    
  1524.     // Draw Map
  1525.     var map_src_rect = { x:0.0, y:0.0, w:0.0, h:0.0};
  1526.     map_src_rect.x = this.mapScroll.x;
  1527.     map_src_rect.y = this.mapScroll.y;
  1528.     map_src_rect.w = this.drawAreaWidth * this.mapZoomInverse;
  1529.     map_src_rect.h = this.drawAreaHeight * this.mapZoomInverse;
  1530.    
  1531.     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);
  1532.    
  1533.     // Debug Grid (if applicable)
  1534.     if (Silv.Minimap.DrawDebugGrid)
  1535.     {
  1536.         for (var i=0; i < $gameMap.width(); i++)
  1537.         {
  1538.             for (var j=0; j < $gameMap.height(); j++)
  1539.             {
  1540.                 var debugTileLoc = this.translateLocationScroll(this, i, j, this.tileInfo.w * this.mapZoom, this.tileInfo.h * this.mapZoom);
  1541.                 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);
  1542.             }
  1543.         }
  1544.     }
  1545.    
  1546.     // Draw POI's
  1547.     for (var i = 0; i < this.getAllPOI().length; i++)
  1548.     {
  1549.         var poi = this.getPOIByIdx(i);
  1550.         var poiLoc = this.translateLocationScroll(this, poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  1551.         this.contents.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
  1552.                           poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
  1553.     }
  1554.  
  1555.     // Draw Events
  1556.     for (var i=0; i < Silv.Minimap.Events.length; i++)
  1557.     {
  1558.         var ev = Silv.Minimap.Events[i].event;
  1559.         var ev_sprite = Silv.Minimap.Events[i].sprite;
  1560.         var evMapLoc = this.translateLocationScroll(this, ev._realX, ev._realY, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
  1561.         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);
  1562.     }
  1563.    
  1564.     // Draw Player
  1565.     if (this.playerBlipEnabled && this.playerBlink_IsVisible)
  1566.     {
  1567.         this.drawPlayerBlip(this.contents, this.translateLocationScroll, this.playerInfo.src.x, this.playerInfo.src.y, this.playerInfo.src.width, this.playerInfo.src.height,
  1568.                             Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
  1569.     }
  1570.    
  1571.     // Overlay (if applicable)
  1572.     if (Silv.Minimap.DrawOverlay) { this.drawOverlay(); }
  1573. };
  1574.  
  1575. Window_Minimap.prototype.drawOverlay = function()
  1576. {
  1577.     this.contents.blt(this.overlayBmp, 0, 0, this.overlayBmp.width, this.overlayBmp.height, 0, 0, this.width, this.height);
  1578. };
  1579. //----------------------------------------------------------------------------------------------------
  1580. // #Translate functions
  1581. // Important: Because the translate functions are assigned to a variable, the this-keyword will be undefined! Therefor this can not be used and that's why I used "that" as a parameter :P. Also Silv.Minim.Window may be null so it must be a parameter.
  1582. // For more info see: http://stackoverflow.com/questions/4011793/this-is-undefined-in-javascript-class-methods
  1583. //----------------------------------------------------------------------------------------------------
  1584. // returns {x, y}
  1585. Window_Minimap.prototype.translateLocationScroll = function(that, obj_real_x, obj_real_y, obj_w, obj_h)
  1586. {
  1587.     var obj_x = (obj_real_x * that.tileInfo.w + that.tileInfo.hw) * that.mapZoom - that.mapScroll.x * that.mapZoom - obj_w / 2.0 + Silv.Minimap.BorderWidth;
  1588.     var obj_y = (obj_real_y * that.tileInfo.h + that.tileInfo.hh) * that.mapZoom - that.mapScroll.y * that.mapZoom - obj_h / 2.0 + Silv.Minimap.BorderHeight;
  1589.     return {x: obj_x, y: obj_y};
  1590. };
  1591.  
  1592. // returns {x, y}
  1593. Window_Minimap.prototype.translateLocationAutofit = function(that, obj_real_x, obj_real_y, obj_w, obj_h)
  1594. {
  1595.     var obj_x = (obj_real_x * that.tileInfo.w + that.tileInfo.hw) * that.mapAspRatInfo.scaleDelta_x * that.mapAspRatInfo.w - obj_w / 2.0 + that.mapAspRatInfo.offset_x + Silv.Minimap.BorderWidth;
  1596.     var obj_y = (obj_real_y * that.tileInfo.h + that.tileInfo.hh) * that.mapAspRatInfo.scaleDelta_y * that.mapAspRatInfo.h - obj_h / 2.0 + that.mapAspRatInfo.offset_y + Silv.Minimap.BorderHeight;
  1597.     return {x: obj_x, y: obj_y};
  1598. };
  1599.  
  1600. // returns {x, y}
  1601. Window_Minimap.prototype.translateLocationMenu = function(that, obj_real_x, obj_real_y, obj_w, obj_h)
  1602. {
  1603.     var obj_x = (obj_real_x * that.tileInfo.w + that.tileInfo.hw) * that.menuZoom - obj_w / 2.0;
  1604.     var obj_y = (obj_real_y * that.tileInfo.h + that.tileInfo.hh) * that.menuZoom - obj_h / 2.0;
  1605.     return {x: obj_x, y: obj_y};
  1606. };
  1607. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1608. // #POI
  1609. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1610. function MM_POI() { this.initialize.apply(this, arguments); }
  1611. // Set Constructor
  1612. MM_POI.prototype.constructor = MM_POI;
  1613.  
  1614. // Initialization
  1615. // real_x & real_y are in tiles
  1616. 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)
  1617. {
  1618.   this.id = poi_id;
  1619.   this.name = name;
  1620.   this.desc = desc;
  1621.   this.real_x = real_x;
  1622.   this.real_y = real_y;
  1623.   this.folderPath = folderPath; // Required for saving&loading
  1624.   this.filename = filename; // Required for saving&loading
  1625.   this.bmp = ImageManager.loadBitmap(folderPath, filename, 0, false);
  1626.   this.src = { x:source_x, y:source_y, w:source_w, h:source_h };
  1627.   this.destSize = { w:draw_w, h:draw_h };
  1628.   this.tp = null;
  1629. };
  1630.  
  1631. // Note: Does not include the Bitmap
  1632. MM_POI.prototype.makeSaveContents = function()
  1633. {
  1634.     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 };
  1635. };
  1636.  
  1637. // Retrieves all the POI's for the current active $gameMap
  1638. Window_Minimap.prototype.getAllPOI = function()
  1639. {
  1640.     return Silv.Minimap.POI[$gameMap._mapId];
  1641. };
  1642.  
  1643. // Retrieves the specified POI by index for the current active $gameMap. Note this is NOT by POI id, this is by index.
  1644. Window_Minimap.prototype.getPOIByIdx = function(index)
  1645. {
  1646.     return Silv.Minimap.POI[$gameMap._mapId][index];
  1647. };
  1648.  
  1649. Window_Minimap.prototype.getPOIByID = function(id)
  1650. {
  1651.     for (var i=0; i<Silv.Minimap.POI[$gameMap._mapId].length; i++)
  1652.     {
  1653.         if (Silv.Minimap.POI[$gameMap._mapId][i].id == id) { return Silv.Minimap.POI[$gameMap._mapId][i]; }
  1654.     }
  1655.     throw 'getPOIByID(' + id + ') not found.';
  1656. };
  1657. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1658. // #Create the Minimap window
  1659. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1660. //----------------------------------------------------------------------------------------------------
  1661. // Scene Map (alias): Create Display Objects
  1662. //----------------------------------------------------------------------------------------------------
  1663. var alias_silver_mm_createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
  1664. Scene_Map.prototype.createDisplayObjects = function()
  1665. {
  1666.     alias_silver_mm_createDisplayObjects.call(this);
  1667.     var didMapChange = $gameMap._mapId != Silv.Minimap.LastMapID;
  1668.     if (didMapChange)
  1669.     {
  1670.         if (Silv.Minimap.WasLoadedFromSave)
  1671.         {
  1672.             Silv.Minimap.WasLoadedFromSave = false;
  1673.         }
  1674.         else
  1675.         {
  1676.             if (Silv.Minimap.AutoClearPOI) { Silv.Minimap.POI[$gameMap._mapId] = []; }
  1677.         }
  1678.     }
  1679.    
  1680.     // Create empty POI array if it's not defined yet for this map
  1681.     if (typeof Silv.Minimap.POI[$gameMap._mapId] === 'undefined') {Silv.Minimap.POI[$gameMap._mapId] = []; }
  1682.  
  1683.     this.attemptToCreateMinimap();
  1684.     Silv.Minimap.LastMapID = $gameMap._mapId;
  1685. };
  1686. //----------------------------------------------------------------------------------------------------
  1687. // Attempt To Create Minimap
  1688. //----------------------------------------------------------------------------------------------------
  1689. Scene_Map.prototype.attemptToCreateMinimap = function()
  1690. {
  1691.     var mapName = lpad_mapname($gameMap._mapId, '0') + '.png';
  1692.     if ('mm_mapshot' in $dataMap.meta)
  1693.     {
  1694.         if (Silv.Minimap.DebugMode) { console.log('A mapshot-notetag was found:' + $dataMap.meta.mm_mapshot + '.'); }
  1695.         mapName = lpad_mapname($dataMap.meta.mm_mapshot, '0') + '.png';
  1696.     }
  1697.    
  1698.     var createMinimap = false;
  1699.     var minimapType = null;
  1700.     var hasRequiredItems = this.MinimapHasRequiredItems();
  1701.    
  1702.     if(Silv.Minimap.Window !== null)
  1703.     {
  1704.         // #Dispose
  1705.         // 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.
  1706.         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...
  1707.         Silv.Minimap.Window = null;
  1708.         Silv.Minimap.Menu.Enabled = false;
  1709.         Silv.Minimap.Menu.Bmp = null;
  1710.         Silv.Minimap.Menu.Markers = [];
  1711.     }
  1712.    
  1713.     var windowWasVisible = Silv.Minimap.Visible;
  1714.     if (minimapImageExists(mapName))
  1715.     {
  1716.         if (hasRequiredItems)
  1717.         {
  1718.             createMinimap = true;
  1719.             minimapType = 'regular';
  1720.         }
  1721.     }
  1722.     else
  1723.     {
  1724.         if (Silv.Minimap.DebugMode) { console.log('No minimap \'' + mapName + '\' found for map with map-id: ' + $gameMap._mapId + '.'); }
  1725.        
  1726.         if (hasRequiredItems)
  1727.         {
  1728.             if (('mm_generate_worldmap' in $dataMap.meta) || ('mm_generate_overworld' in $dataMap.meta))
  1729.             {
  1730.                 if (Silv.Minimap.DebugMode && !$gameMap.isOverworld()) { console.log('Current map is NOT an overworld map but the minimap is set to treat it like a regular one.'); }
  1731.                 createMinimap = true;
  1732.                 minimapType = 'generate_overworld';
  1733.             } else if ('mm_generate_map' in $dataMap.meta)
  1734.             {
  1735.                 if (Silv.Minimap.DebugMode && $gameMap.isOverworld()) { console.log('Current map is an overworld map but the minimap is set to treat it like an overworld map.'); }
  1736.                 createMinimap = true;
  1737.                 minimapType = 'generate_map';
  1738.             }
  1739.         }
  1740.     }
  1741.    
  1742.     if (createMinimap)
  1743.     {
  1744.         this.createMinimapWindow(mapName.replace('.png', ''), minimapType);
  1745.         if (!windowWasVisible) { 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.
  1746.         if ('mm_generate_passability_overlay' in $dataMap.meta) { Silv.Minimap.Window.setPassabilityOverlay(true); }
  1747.     }
  1748.     // else
  1749.     // {
  1750.         //'Dispose'
  1751.         //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.
  1752.         // Silv.Minimap.Window = null;
  1753.     // }
  1754. };
  1755. //----------------------------------------------------------------------------------------------------
  1756. // Scene_Base: Remove Window
  1757. //----------------------------------------------------------------------------------------------------
  1758. // Omg why does RPG Maker not have this method by default...
  1759. Scene_Base.prototype.removeWindow = function(window)
  1760. {
  1761.     var index = this.children.indexOf(window);
  1762.     if (index > -1) { this.children.splice(index, 1); }
  1763. };
  1764. //----------------------------------------------------------------------------------------------------
  1765. // Create Minimap Window
  1766. //----------------------------------------------------------------------------------------------------
  1767. Scene_Map.prototype.createMinimapWindow = function(mapname, minimapType)
  1768. {
  1769.     var x = 0;
  1770.     if (Silv.Minimap.WindowHorizontalAlignment == 'right') { x = Graphics.width - Silv.Minimap.WindowWidth; }
  1771.     var y = 0;
  1772.     if (Silv.Minimap.WindowVerticalAlignment == 'bottom') { y = Graphics.height - Silv.Minimap.WindowHeight; }
  1773.    
  1774.     Silv.Minimap.Window = new Window_Minimap(x + Silv.Minimap.Window_X, y + Silv.Minimap.Window_Y, Silv.Minimap.WindowWidth, Silv.Minimap.WindowHeight, mapname, minimapType);
  1775.     Silv.Minimap.Window.resetFade();
  1776.    
  1777.     // override frameskip (map-specific frameskip)
  1778.     if ('mm_frameskip' in $dataMap.meta)
  1779.     {
  1780.         Silv.Minimap.Window.frameSkip = parseInt($dataMap.meta.mm_frameskip);
  1781.         if (Silv.Minimap.DebugMode) { console.log('Global frameskip: ' + Silv.Minimap.FrameSkip + ' was overriden by the map-specific frameskip of: ' + $dataMap.meta.mm_frameskip + '.'); }
  1782.     }
  1783.    
  1784.     this.addChildAt(Silv.Minimap.Window, 1);
  1785. };
  1786. //----------------------------------------------------------------------------------------------------
  1787. // Has Required Items
  1788. //----------------------------------------------------------------------------------------------------
  1789. Scene_Map.prototype.MinimapHasRequiredItems = function()
  1790. {
  1791.     // Check global item
  1792.     if (Silv.Minimap.GlobalRequiredItem > 0)
  1793.     {
  1794.         if (!$gameParty.hasItem($dataItems[Silv.Minimap.GlobalRequiredItem], false))
  1795.         {
  1796.             if (Silv.Minimap.DebugMode) { console.log('Minimap (or mapshot-notetag) was found but party does not possess the required global item: ' + $dataItems[Silv.Minimap.GlobalRequiredItem].name); }
  1797.             return false;
  1798.         }
  1799.     }
  1800.    
  1801.     // Check map-specific items
  1802.     if ('mm_req_itm' in $dataMap.meta)
  1803.     {
  1804.         var req_item_ids = $dataMap.meta.mm_req_itm.split(' ').filter(Boolean); // .filter(Boolean) removes empty strings from array
  1805.         for (var i = 0; i < req_item_ids.length; i++)
  1806.         {
  1807.             if (!$gameParty.hasItem($dataItems[req_item_ids[i]], false))
  1808.             {
  1809.                 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); }
  1810.                 return false;
  1811.             }
  1812.         }
  1813.     }
  1814.    
  1815.     return true;
  1816. };
  1817. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1818. // Saving & Loading #Save #Saving #Loading
  1819. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1820. var alias_silv_mm_makeSaveContents = DataManager.makeSaveContents;
  1821. DataManager.makeSaveContents = function()
  1822. {
  1823.     contents = alias_silv_mm_makeSaveContents.call(this);
  1824.    
  1825.     contents.minimap = {};
  1826.     contents.minimap.poi = {};
  1827.    
  1828.     // POI
  1829.     for (var mapID in Silv.Minimap.POI)
  1830.     {
  1831.         if (Silv.Minimap.POI.hasOwnProperty(mapID))
  1832.         {
  1833.             if(Silv.Minimap.POI[mapID].length > 0) { contents.minimap.poi[mapID] = []; }
  1834.             for(var poi_idx=0; poi_idx<Silv.Minimap.POI[mapID].length; poi_idx++)
  1835.             {
  1836.                 contents.minimap.poi[mapID].push(Silv.Minimap.Window.getPOIByIdx(poi_idx).makeSaveContents());
  1837.             }
  1838.         }
  1839.     }
  1840.     return contents;
  1841. };
  1842.  
  1843. var alias_silv_mm_extractSaveContents = DataManager.extractSaveContents;
  1844. DataManager.extractSaveContents = function(contents)
  1845. {
  1846.     alias_silv_mm_extractSaveContents.call(this, contents);
  1847.     Silv.Minimap.POI = {};
  1848.    
  1849.    
  1850.     // POI
  1851.     for (var mapID in contents.minimap.poi)
  1852.     {
  1853.         if (contents.minimap.poi.hasOwnProperty(mapID))
  1854.         {
  1855.             if(contents.minimap.poi[mapID].length > 0) { Silv.Minimap.POI[mapID] = []; }
  1856.             for(var poi_idx=0; poi_idx<contents.minimap.poi[mapID].length; poi_idx++)
  1857.             {
  1858.                 var poi = contents.minimap.poi[mapID][poi_idx];
  1859.                 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);
  1860.                 newPOI.tp = poi.tp;
  1861.                 Silv.Minimap.POI[mapID].push(newPOI);
  1862.             }
  1863.         }
  1864.     }
  1865.    
  1866.     // Prevent the minimap from autoclearing it's POI's (if AutoClearPOI is enabled) when loading a savegame
  1867.     Silv.Minimap.WasLoadedFromSave = true;
  1868. };
  1869. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1870. // #Plugin Command
  1871. // Note: The items are separated by spaces. The command is the first word and any following words are args. args is an array.
  1872. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1873. var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  1874. Game_Interpreter.prototype.pluginCommand = function(command, args)
  1875. {
  1876.     _Game_Interpreter_pluginCommand.call(this, command, args);
  1877.     if (command.toLowerCase() == 'minimap') { PluginCommand(command, args); }
  1878. };
  1879.  
  1880. function PluginCommand(cmd, args)
  1881. {
  1882.     if (Silv.Minimap.Window === null) { throw 'Minimap Plugin Commands can not be used when there is no active minimap. Either create one from a mapshot or generate one automatically'; }
  1883.    
  1884.     switch(args[0].toLowerCase())
  1885.     {
  1886.         case 'hide':
  1887.             Silv.Minimap.Window.hide();
  1888.             break;
  1889.         case 'show':
  1890.             Silv.Minimap.Window.show();
  1891.             break;
  1892.         case 'fadeout':
  1893.             Silv.Minimap.Window.isFadingOut = true;
  1894.             break;
  1895.         case 'fadereset':
  1896.             Silv.Minimap.Window.resetFade();
  1897.             break;
  1898.         case 'refresh':
  1899.             SceneManager._scene.attemptToCreateMinimap(false);
  1900.             break;
  1901.         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
  1902.             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])));
  1903.             SceneManager._scene.attemptToCreateMinimap(false);
  1904.             break;
  1905.         case 'deletepoi':
  1906.             Silv.Minimap.POI[$gameMap._mapId] = Silv.Minimap.POI[$gameMap._mapId].filter(function(poi) { return poi.id != args[1]; });
  1907.             break;
  1908.         case 'poidesc':
  1909.               Silv.Minimap.Window.getPOIByID(parseInt(args[1])).desc = args.join(' ').substr(2 + args[0].length + args[1].length);
  1910.             break;
  1911.         case 'poi_tp': // POI_TP <poi_id x_offset, y_offset, direction, fadeType>
  1912.             Silv.Minimap.Window.getPOIByID(parseInt(args[1])).tp = [parseInt(args[2]), parseInt(args[3]), parseInt(args[4]), parseInt(args[5])];
  1913.             break;
  1914.         case 'refreshevents':
  1915.             Silv.Minimap.Window.loadEvents();
  1916.             break;
  1917.         case 'increasescroll':
  1918.             Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x + parseFloat(args[1]), Silv.Minimap.Window.mapScroll.y + parseFloat(args[2]));
  1919.             break;
  1920.         case 'setscroll':
  1921.             Silv.Minimap.Window.manualScroll(parseFloat(args[1]), parseFloat(args[2]));
  1922.             break;
  1923.         case 'generate_passability_overlay':
  1924.         case 'gen_pass_ov':
  1925.             Silv.Minimap.setPassabilityOverlay(args[1].toLowerCase() == 'true');
  1926.             break;
  1927.         case 'showmapmenu':
  1928.             Silv.Minimap.Window.showMapMenuScene();
  1929.             break;
  1930.         case 'setplayerblip':
  1931.             Silv.Minimap.Window.setPlayerBlip(args[1]);
  1932.             break;
  1933.         case 'setmapstyle':
  1934.             Silv.Minimap.Window.mapStyle = args[1].toLowerCase();
  1935.             break;
  1936.         case 'setfollowtarget':
  1937.         case 'setcamera':
  1938.             var followType = args[1].toLowerCase();
  1939.             if (followType == 'coordinate')
  1940.             {
  1941.                 Silv.Minimap.Window.setCameraFollowTarget(followType, [parseInt(args[2]), parseInt(args[3])]);
  1942.             }
  1943.             else
  1944.             {
  1945.                 Silv.Minimap.Window.setCameraFollowTarget(followType, args[2]);
  1946.             }
  1947.             break;
  1948.         default:
  1949.             throw 'Minimap, unknown Plugin Command: ' + args[0];
  1950.     }
  1951. }
  1952. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1953. })();
  1954. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1955. // Map Menu #Scene
  1956. // Note: Must be placed outside of the })();
  1957. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1958. function Scene_MiniMap() { this.initialize.apply(this, arguments); }
  1959.  
  1960. Scene_MiniMap.prototype = Object.create(Scene_MenuBase.prototype);
  1961. Scene_MiniMap.prototype.constructor = Scene_MiniMap;
  1962.  
  1963. Scene_MiniMap.prototype.initialize = function()
  1964. {
  1965.     Scene_MenuBase.prototype.initialize.call(this);
  1966.     SoundManager.playOk();
  1967. };
  1968.  
  1969. Scene_MiniMap.prototype.create = function()
  1970. {
  1971.     Scene_MenuBase.prototype.create.call(this);
  1972.     this.createLeftWindow();
  1973.     this.createMapSectionWindow();
  1974.     this.createMapHelpWindow();
  1975.     this.refreshHelpWindow();
  1976. };
  1977.  
  1978. Scene_MiniMap.prototype.createLeftWindow = function()
  1979. {
  1980.     this._window_left = new Window_MinimapMenuLeft(0, 0);
  1981.     this._window_left.setHandler('ok',     this.onRangeOk.bind(this));
  1982.     this._window_left.setHandler('cancel', this.popScene.bind(this));
  1983.     this._window_left.setHandler('index_changed', this.index_changed.bind(this));
  1984.     this.addWindow(this._window_left);
  1985. };
  1986.  
  1987. Scene_MiniMap.prototype.createMapSectionWindow = function()
  1988. {
  1989.     var wx = this._window_left.width;
  1990.     var ww = Graphics.boxWidth - wx;
  1991.     this._mapSectionWindow = new Window_MapSection(wx, 0, ww);
  1992.     this._mapSectionWindow.setHandler('cancel', this.onEditCancel.bind(this));
  1993.     this._window_left.setMapWindow(this._mapSectionWindow);
  1994.     this.addWindow(this._mapSectionWindow);
  1995. };
  1996.  
  1997. Scene_MiniMap.prototype.createMapHelpWindow = function()
  1998. {
  1999.     var wx = this._mapSectionWindow.x;
  2000.     var wy = this._mapSectionWindow.height;
  2001.     var ww = this._mapSectionWindow.width;
  2002.     var wh = Graphics.boxHeight - wy;
  2003.     this._mapHelpWindow = new Window_Base(wx, wy, ww, wh);
  2004.     this.addWindow(this._mapHelpWindow);
  2005. };
  2006.  
  2007. Scene_MiniMap.prototype.index_changed = function()
  2008. {
  2009.     this.refreshHelpWindow();
  2010. };
  2011.  
  2012. Scene_MiniMap.prototype.onRangeOk = function()
  2013. {
  2014.     this._mapSectionWindow.activate();
  2015.     this._mapSectionWindow.select(0);
  2016.     this.refreshHelpWindow();
  2017. };
  2018.  
  2019. Scene_MiniMap.prototype.onEditCancel = function()
  2020. {
  2021.     this._window_left.activate();
  2022.     this._mapSectionWindow.deselect();
  2023.     this.refreshHelpWindow();
  2024. };
  2025.  
  2026. Scene_MiniMap.prototype.refreshHelpWindow = function()
  2027. {
  2028.     this._mapHelpWindow.contents.clear();
  2029.     this._mapHelpWindow.drawTextEx(this.helpText(), 4, 0);
  2030. };
  2031.  
  2032. Scene_MiniMap.prototype.helpText = function()
  2033. {
  2034.     var marker = this._window_left.marker();
  2035.     var tp_text = '';
  2036.     if (marker.tp !== null) { tp_text = '\nTeleports you to: ' + marker.tp[0] + ',' + marker.tp[1]; }
  2037.     return this._window_left.marker().desc + tp_text;
  2038. };
  2039. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2040. // Left Window #leftwindow
  2041. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2042. function Window_MinimapMenuLeft() { this.initialize.apply(this, arguments); }
  2043.  
  2044. Window_MinimapMenuLeft.prototype = Object.create(Window_Selectable.prototype);
  2045. Window_MinimapMenuLeft.prototype.constructor = Window_MinimapMenuLeft;
  2046.  
  2047. Window_MinimapMenuLeft.lastTopRow = 0;
  2048. Window_MinimapMenuLeft.lastIndex  = 0;
  2049.  
  2050. Window_MinimapMenuLeft.prototype.initialize = function(x, y)
  2051. {
  2052.     var width = this.windowWidth();
  2053.     var height = this.windowHeight();
  2054.     Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  2055.     this.refresh();
  2056.     this.setTopRow(Window_MinimapMenuLeft.lastTopRow);
  2057.     this.select(Window_MinimapMenuLeft.lastIndex);
  2058.     this.activate();
  2059. };
  2060.  
  2061. Window_MinimapMenuLeft.prototype.windowWidth = function()
  2062. {
  2063.     return Silv.Minimap.Menu.WindowWidth_Left;
  2064. };
  2065.  
  2066. Window_MinimapMenuLeft.prototype.windowHeight = function()
  2067. {
  2068.     return Graphics.boxHeight;
  2069. };
  2070.  
  2071. Window_MinimapMenuLeft.prototype.maxItems = function()
  2072. {
  2073.     return Silv.Minimap.Menu.Markers.length;
  2074. };
  2075.  
  2076. Window_MinimapMenuLeft.prototype.update = function()
  2077. {
  2078.     Window_Selectable.prototype.update.call(this);
  2079.     if (this._mapWindow) { this._mapWindow.setMarker(this.marker()); }
  2080.     if (this.index() != Window_MinimapMenuLeft.lastIndex)
  2081.     {
  2082.         Window_MinimapMenuLeft.lastIndex = this.index();
  2083.         this.callHandler('index_changed');
  2084.     }
  2085.    
  2086.     if (Input.isTriggered('ok'))
  2087.     {
  2088.         var marker = this.marker();
  2089.         if(marker.tp !== null)
  2090.         {
  2091.             // Add the teleport location to the minimap and dequeue this scene to return to the previous scene
  2092.             SoundManager.playOk();
  2093.             Silv.Minimap.TP_Dest = marker.tp;
  2094.             SceneManager.pop();
  2095.         }
  2096.     }
  2097.    
  2098.     if (Input.isTriggered(Silv.Minimap.Menu.MenuKey))
  2099.     {
  2100.         SoundManager.playCancel();
  2101.         SceneManager.pop();
  2102.     }
  2103. };
  2104.  
  2105. Window_MinimapMenuLeft.prototype.marker = function()
  2106. {
  2107.     return Silv.Minimap.Menu.Markers[this.index()];
  2108. };
  2109.  
  2110. Window_MinimapMenuLeft.prototype.refresh = function()
  2111. {
  2112.     this.createContents();
  2113.     this.drawAllItems();
  2114. };
  2115.  
  2116. Window_MinimapMenuLeft.prototype.drawItem = function(index)
  2117. {
  2118.     var rect = this.itemRectForText(index);
  2119.     var text = Silv.Minimap.Menu.Markers[index].text;
  2120.     this.drawText(text, rect.x, rect.y, rect.width);
  2121. };
  2122.  
  2123. Window_MinimapMenuLeft.prototype.isCancelTriggered = function()
  2124. {
  2125.     return (Window_Selectable.prototype.isCancelTriggered());
  2126. };
  2127.  
  2128. Window_MinimapMenuLeft.prototype.processCancel = function()
  2129. {
  2130.     Window_Selectable.prototype.processCancel.call(this);
  2131.     Window_MinimapMenuLeft.lastTopRow = this.topRow();
  2132.     Window_MinimapMenuLeft.lastIndex = this.index();
  2133. };
  2134.  
  2135. Window_MinimapMenuLeft.prototype.setMapWindow = function(mapWindow)
  2136. {
  2137.     this._mapWindow = mapWindow;
  2138.     this.update();
  2139. };
  2140. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2141. // Map Section Window
  2142. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2143. function Window_MapSection() { this.initialize.apply(this, arguments); }
  2144.  
  2145. Window_MapSection.prototype = Object.create(Window_Selectable.prototype);
  2146. Window_MapSection.prototype.constructor = Window_MapSection;
  2147.  
  2148. Window_MapSection.prototype.initialize = function(x, y, width)
  2149. {
  2150.     var height = Silv.Minimap.Menu.WindowHeight_MapSection;
  2151.     Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  2152.     this._marker = 1;
  2153.     this.mapScroll = {x:0, y:0};
  2154.     this.mapZoom = 1.0;
  2155.     this.centerLoc = {x:width / 2.0, y: height / 2.0};
  2156.     this.refresh();
  2157. };
  2158.  
  2159. // Hide the cursor
  2160. Window_MapSection.prototype.updateCursor = function()
  2161. {
  2162.     this.setCursorRect(0, 0, 0, 0);
  2163. };
  2164.  
  2165. Window_MapSection.prototype.maxItems = function() { return 0; };
  2166.  
  2167. Window_MapSection.prototype.refresh = function()
  2168. {
  2169.     this.contents.clear();
  2170.     this.drawMap();
  2171. };
  2172.  
  2173. // Prevent anything from being drawn in the base-class
  2174. Window_MapSection.prototype.drawAllItems = function(){};
  2175.  
  2176. Window_MapSection.prototype.drawMap = function()
  2177. {
  2178.     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);
  2179. };
  2180.  
  2181. Window_MapSection.prototype.centerOnMarker = function(marker)
  2182. {
  2183.     this.mapScroll.x = this.centerLoc.x - marker.map_x - marker.w / 2.0;
  2184.     this.mapScroll.y = this.centerLoc.y - marker.map_y - marker.h / 2.0;
  2185.     this.refresh();
  2186. };
  2187.  
  2188. Window_MapSection.prototype.setMarker = function(marker)
  2189. {
  2190.     if (this._marker !== marker)
  2191.     {
  2192.         this._marker = marker;
  2193.         this.centerOnMarker(marker);
  2194.     }
  2195. };
  2196.  
  2197. Window_MapSection.prototype.update = function()
  2198. {
  2199.     Window_Selectable.prototype.update.call(this);
  2200.     if (this.active) {
  2201.         if (Input.isPressed('up')) { this.mapScroll.y += 10; this.refresh(); }
  2202.         if (Input.isPressed('right')) { this.mapScroll.x -= 10; this.refresh(); }
  2203.         if (Input.isPressed('down')) { this.mapScroll.y -= 10; this.refresh(); }
  2204.         if (Input.isPressed('left')) { this.mapScroll.x += 10; this.refresh(); }
  2205.         if (Input.isPressed(Silv.Minimap.Menu.ManualScrollKey_Reset)) { this.mapScroll.x = 0; this.mapScroll.y = 0; this.refresh(); }
  2206.        
  2207.         if (Input.isPressed(Silv.Minimap.Menu.ManualZoomKey_In))
  2208.         {
  2209.             this.mapZoom += 0.05;
  2210.             if (this.mapZoom > Silv.Minimap.Menu.ManualZoom_Max) { this.mapZoom = Silv.Minimap.Menu.ManualZoom_Max; }
  2211.             this.refresh();
  2212.         }
  2213.         if (Input.isPressed(Silv.Minimap.Menu.ManualZoomKey_Out))
  2214.         {
  2215.             this.mapZoom -= 0.05;
  2216.             if (this.mapZoom < Silv.Minimap.Menu.ManualZoom_Min) { this.mapZoom = Silv.Minimap.Menu.ManualZoom_Min; }
  2217.             this.refresh();
  2218.         }
  2219.         if  (Input.isPressed(Silv.Minimap.Menu.ManualZoomKey_Reset)) { this.mapZoom = 1.0; this.refresh(); }
  2220.     }
  2221. };
  2222. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2223. // This is the end of this awesome script! Why did you even read this line ;)
  2224. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement