Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // SilvMinimap.js
  3. // Version: 1.13
  4. // Requires plugin: SilvKeys (place this one below it)
  5. //=============================================================================
  6. /*:
  7.  * @plugindesc v1.13 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 Visible By Default?
  24.  * @desc Will the minimap be visible by default. This applies to each map. If set to false, also overrides any plugin commands upon entering a new map. true/false
  25.  * @default true
  26.  *
  27.  * @param -- Positioning & Size --
  28.  *
  29.  * @param X
  30.  * @desc x-location of minimap window. If window-alignment is set to Right, this will act as an offset value instead
  31.  * @default -2
  32.  *
  33.  * @param Y
  34.  * @desc y-location of minimap window. If window-alignment is set to Top, this will act as an offset value instead
  35.  * @default 2
  36.  *
  37.  * @param Horizontal Alignment
  38.  * @desc Left/Right
  39.  * @default Right
  40.  *
  41.  * @param Vertical Alignment
  42.  * @desc Top/Bottom
  43.  * @default Bottom
  44.  *
  45.  * @param Width
  46.  * @desc width of the minimap
  47.  * @default 320
  48.  *
  49.  * @param Height
  50.  * @desc height of the minimap
  51.  * @default 320
  52.  *
  53.  * @param Border Width
  54.  * @desc Border width of the minimap
  55.  * @default 12
  56.  *
  57.  * @param Border Height
  58.  * @desc Border height of the minimap
  59.  * @default 12
  60.  *
  61.  * @param -- Player Blip --
  62.  *
  63.  * @param Render Player Blip
  64.  * @desc Render the player blip in the minimap (=usually the center icon)? true/false
  65.  * @default true
  66.  *
  67.  * @param Player Blip Graphic
  68.  * @desc Name of the image (in /img/minimap/) to use as the blip. or use :player to use the realtime-player-graphic.
  69.  * @default :player
  70.  *
  71.  * @param Player Icon Width
  72.  * @desc Standard Window Padding
  73.  * @default 16
  74.  *
  75.  * @param Player Icon Height
  76.  * @desc Standard Window Padding
  77.  * @default 16
  78.  *
  79.  * @param Player Blink Delay
  80.  * @desc Blinks the player icon (in frames). Set to 0 to disable. Does nothing if "Draw Player Icon" is set to false
  81.  * @default 0
  82.  *
  83.  * @param -- Menu --
  84.  *
  85.  * @param Menu Key
  86.  * @desc The key used to show the map-menu. Use none to disable.
  87.  * @default m
  88.  *
  89.  * @param Menu Player Description
  90.  * @desc The description of the player marker in the menu. Spaces are allowed.
  91.  * @default You
  92.  *
  93.  * @param Menu Zoom
  94.  * @desc Map Zoomlevel for the menu
  95.  * @default 0.3. A value of 1 means 1:1
  96.  *
  97.  * @param Menu Left Window Width
  98.  * @desc Width of the left window
  99.  * @default 240
  100.  *
  101.  * @param Menu Topright Window Height
  102.  * @desc Height of the topright window
  103.  * @default 510
  104.  *
  105.  * @param Menu Event Render Size
  106.  * @desc How big the events are that are drawn onto the menu map
  107.  * @default 24
  108.  *
  109.  * @param Menu Player Icon Size
  110.  * @desc How big the player is drawn onto the menu map
  111.  * @default 64
  112.  *
  113.  * @param Menu Min Manual Zoom
  114.  * @desc How far the player can zoom out
  115.  * @default 0.20
  116.  *
  117.  * @param Menu Max Manual Zoom
  118.  * @desc How far the player can zoom in
  119.  * @default 10.0
  120.  *
  121.  * @param Menu Zoomin Key
  122.  * @desc Key for zooming in. 33 = pageup
  123.  * @default pageup
  124.  *
  125.  * @param Menu Zoomout Key
  126.  * @desc Key for zooming out. 34 = pagedown
  127.  * @default pagedown
  128.  *
  129.  * @param Menu Reset Zoom Key
  130.  * @desc Key for resetting the zoom. 36 = home
  131.  * @default home
  132.  *
  133.  * @param Menu Reset Scroll Key
  134.  * @desc Key to reset the mapscroll
  135.  * @default end
  136.  *
  137.  * @param -- Passability Map --
  138.  *
  139.  * @param Passability Overlay Opacity
  140.  * @desc 0 = invisible, 255 = fully opaque. 0-255
  141.  * @default 128
  142.  *
  143.  * @param Passability Color
  144.  * @desc Color for walkable tiles
  145.  * @default #6B8E23
  146.  *
  147.  * @param Impassability Color
  148.  * @desc Color for unwalkable tiles
  149.  * @default #FF0000
  150.  *
  151.  * @param -- Map Generator --
  152.  *
  153.  * @param Map 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 ####### ####### #FFFFFF
  156.  *
  157.  * @param Overworld Gen Tag Colors
  158.  * @desc 0-7, use a ####### value to ignore that terrain-tag. Default: lightgreen, blue, brown, darkgreen, lightbrown
  159.  * @default #6B8E23 #00008B #8B4513 #006400 #F4A460 ####### ####### #FFFFFF
  160.  *
  161.  * @param Map Gen Region Colors
  162.  * @desc Use <region_id>:<hex_color> to add a color. Each entry is separated by a space. Note that regions will override tag-colors.
  163.  * @default 10:#6B8E23 11:#00008B 12:#8B4513 13:#006400 14:#F4A460
  164.  *
  165.  * @param Overworld Gen Region Colors
  166.  * @desc Use <region_id>:<hex_color> to add a color. Each entry is separated by a space. Note that regions will override tag-colors.
  167.  * @default 10:#6B8E23 11:#00008B 12:#8B4513 13:#006400 14:#F4A460
  168.  *
  169.  * @param -- The rest --
  170.  *
  171.  * @param Allow Teleportation
  172.  * @desc By default, allow teleportation to events/poi's that support it? true/false
  173.  * @default true
  174.  *
  175.  * @param Standard Padding
  176.  * @desc Standard Window Padding. Best to leave at 0
  177.  * @default 0
  178.  *
  179.  * @param Window Skin
  180.  * @desc Name of the window skin to use for this window
  181.  * @default Window_Minimap
  182.  *
  183.  * @param Fill Color
  184.  * @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.
  185.  * @default 0 0 0 255
  186.  *
  187.  * @param Maintain Aspect Ratio
  188.  * @desc Maintains minimap aspect ratio if set to true. true/false
  189.  * @default true
  190.  *
  191.  * @param Fadeout Speed
  192.  * @desc How fast the minimap fades out
  193.  * @default 3
  194.  *
  195.  * @param Global Required Item
  196.  * @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
  197.  * @default 0
  198.  *
  199.  * @param Event Render Size
  200.  * @desc How big the events are that are drawn onto the minimap
  201.  * @default 16
  202.  *
  203.  * @param Auto Clear POI
  204.  * @desc Automatically clear POI's between map transfers? true/false
  205.  * @default false
  206.  *
  207.  * @param Render Minimap Overlay
  208.  * @desc If enabled, add the image: /img/minimap/Overlay.png and it will be drawn on top of the minimap. true/false
  209.  * @default true
  210.  *
  211.  * @param -- Fog of War --
  212.  *
  213.  * @param FoW Enabled
  214.  * @desc Enable Fog of War? Can be overridden on a per-map-basis. true/false
  215.  * @default false
  216.  *
  217.  * @param Default FoW Overlay
  218.  * @desc The default Fog of War (PNG) overlay image name in "<project>/img/minimap/"
  219.  * @default FoW
  220.  *
  221.  * @param Default FoW Radius
  222.  * @desc How far into the FoW the player can see.
  223.  * @default 5
  224.  *
  225.  * @param -- Manual Scrolling --
  226.  *
  227.  * @param Allow Manual Scrolling
  228.  * @desc true/false
  229.  * @default true
  230.  *
  231.  * @param Manual Scrollspeed
  232.  * @desc How fast the map is scrolled
  233.  * @default 24
  234.  *
  235.  * @param Manual Scroll Key Up
  236.  * @desc Key for scrolling the map upwards. Default: u  http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
  237.  * @default u
  238.  *
  239.  * @param Manual Scroll Key Right
  240.  * @desc Key for scrolling the map upwards. Default: k
  241.  * @default k
  242.  *
  243.  * @param Manual Scroll Key Down
  244.  * @desc Key for scrolling the map upwards. Default: j
  245.  * @default j
  246.  *
  247.  * @param Manual Scroll Key Left
  248.  * @desc Key for scrolling the map upwards. Default: h
  249.  * @default h
  250.  *
  251.  * @param -- Advanced & Debug --
  252.  *
  253.  * @param Player Sprite Sourceframe Width
  254.  * @desc Width of the playersprite sourceframe
  255.  * @default 48
  256.  *
  257.  * @param Player Sprite Sourceframe Height
  258.  * @desc Heigth of the playersprite sourceframe
  259.  * @default 48
  260.  *
  261.  * @param Frame Skip
  262.  * @desc Skips some minimap calculations&rendering if set to value > 0 to safe performance. The value equals the amount of frames skipped.
  263.  * @default 0
  264.  *
  265.  * @param Mapshot Filename Length
  266.  * @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
  267.  * @default 3
  268.  *
  269.  * @param Debug Mode
  270.  * @desc Prints extra info if set to true. true/false
  271.  * @default false
  272.  *
  273.  * @param Render Debug Grid
  274.  * @desc Draws a debug grid. Requires "/img/Minimap/DebugGrid.png" which is 48x48 in size. Drains a lot of performance!
  275.  * @default false
  276.  *
  277.  * @param Debug Grid Image
  278.  * @desc Name of the debug-grid image
  279.  * @default DebugGrid01
  280.  *
  281.  * @help
  282.  * 1. Make a mapshot of your map. You may use http://forums.rpgmakerweb.com/index.php?/topic/49711-orange-mapshot/
  283.  * 2. Install this script: http://pastebin.com/FF6jh3S0 and make sure to put it above the minimap script.
  284.  * 3. Copy the files to:
  285.  * 4. /img/minimap/Overlay.png
  286.  * 5. /img/minimap/DebugGrid01.png
  287.  * 6. /img/system/Window_Minimap.png
  288.  * 7. Place your mapshots in the /img/minimap/ directory and rename them 001.png, 002.png etc. (matching the id of your map)
  289.  *
  290.  * - If you prefer to use automatic generated maps instead, use the map-notetags and you then obviously do not require mapshots of course.
  291.  * - To enable Fog of War, copy the new FoW.png to the <project>/img/minimap/ folder and set the parameter "FoW Enabled" to true. And make sure that the current map has a minimap of course ;).
  292.  *   FoW also works for generated maps. POI's and Events however will always be displayed on top of the FoW. This is intended.
  293.  *
  294.  *--------------------------------------
  295.  * Yanfly's Main Menu Manager Setup (optional)
  296.  *--------------------------------------
  297.  *
  298.  * 1. Download & Install YEP_MainMenuManager.js
  299.  * 2. Configure the parameters as follow:
  300.  * Menu Name: "Map"
  301.  * Menu Symbol: silvMap
  302.  * Menu Show: true
  303.  * Menu Enabled: Silv.Minimap.Menu.Enabled
  304.  * Menu Main Bind: this.commandSilvMap.bind(this)
  305.  *
  306.  *--------------------------------------
  307.  * Map notetags (most are case sensitive!)
  308.  *--------------------------------------
  309.  * <mm_req_itm:item_id1 item_id2 etc>
  310.  * Example: <mm_req_itm:1, 2, 3>
  311.  *
  312.  * <mm_mapstyle:Scroll/Autofit>
  313.  * Examples:
  314.  * <mm_mapstyle:Scroll>
  315.  * <mm_mapstyle:AutoFit>
  316.  *
  317.  * <mm_frameskip:value>
  318.  * Example: <mm_frameskip:1>
  319.  * Note: overrides the global frameskip parameter for this map
  320.  *
  321.  * <mm_mapzoom:value>
  322.  * Example: <mm_mapzoom:0.15>
  323.  * Note: overrides the global mapzoom parameter for this map
  324.  *
  325.  * <mm_allowmanualscroll:value>
  326.  * Example: <mm_allowmanualscroll:false>
  327.  * Allowed values: true/false
  328.  * Note: overrides the global "Allow Manual Scrolling" parameter for this map
  329.  *
  330.  * <mm_menuzoom:value>
  331.  * Example: <mm_menuzoom:0.75>
  332.  * Note: overrides the global "Menu Zoom" parameter for this map
  333.  *
  334.  * <mm_size:x y>
  335.  * Example: <mm_size:128 128>
  336.  * Note: overrides the global "Width" and "Height" parameters for this map
  337.  *
  338.  * Allow/disallow teleportation.
  339.  * <mm_tp_allow:value>
  340.  * Example: <mm_tp_allow:false>
  341.  * Note: overrides the global "Allow Teleportation" parameter for this map
  342.  *
  343.  * Generate a worldmap-minimap if there is no image (does increase load-time, the first time, for the map)
  344.  * <mm_generate_worldmap>
  345.  * <mm_generate_overworld>
  346.  *
  347.  * Generate regular map (same as mm_generate_overworld but uses a different parameter-color-generator-tag)
  348.  * <mm_generate_map>
  349.  *
  350.  * Generate and overlay a generated passability-map on top of the minimap
  351.  * <mm_generate_passability_overlay>
  352.  *
  353.  * Change the player-blip
  354.  * <mm_player_blip:value>
  355.  * Example to use the realtime player graphic:
  356.  * <mm_player_blip::player>
  357.  * Example to use a custom blip graphic:
  358.  * <mm_player_blip:myCustomPlayerBlip>
  359.  * Note that in the above example, the game requires the image /img/minimap/myCustomPlayerBlip.png"
  360.  *
  361.  * Use another map's mapshot (handy for duplicate maps)
  362.  * <mm_mapshot:map_id>
  363.  * Example: <mm_mapshot:2>
  364.  * Note: leading zero's are optional but not required.
  365.  *
  366.  * To use a different map-image for the map-scene:
  367.  * <mm_menu_bg:imageName>
  368.  * Example: <mm_menu_bg:myFantasticMap>
  369.  * Note1: Must be in png-format
  370.  * Note2: Must be placed in the same folder that also stores the mapshots
  371.  * Note3: If the size differs from the real mapshot (or generated map) then positioning of objects like the player-location may occur. So respect the original size!
  372.  *
  373.  * <mm_fow_enabled:value> // value: true/false
  374.  * Example: <mm_fow_enabled:false>
  375.  * Note: overrides the default "FoW Enabled" parameter
  376.  *
  377.  * <mm_fow_ov:value> // value: name of PNG-image placed in <project>/img/minimap/
  378.  * Example: <mm_fow_enabled:FoW2>
  379.  * Note: overrides the default "Default FoW Overlay" parameter
  380.  *
  381.  * <mm_fow_radius:value> // value is an integer value with a minimum value of 0.
  382.  *
  383.  * <mm_fow_completion:value> // an integer value (positive or negative) that will add/subtract to the total amount of 'explorable' tiles count for the Fog of War. This will only affect the completion % (how many tiles the player revealed for that map).
  384.  *
  385.  *--------------------------------------
  386.  * Event notetags (not case sensitive)
  387.  *--------------------------------------
  388.  * mm_show
  389.  *
  390.  *--------------------------------------
  391.  * Plugin Commands (not case-sensitive)
  392.  *--------------------------------------
  393.  * Minimap Hide
  394.  * Minimap Show
  395.  * Minimap FadeOut
  396.  * Minimap FadeReset
  397.  * Minimap Refresh
  398.  * Minimap RefreshEvents
  399.  * Minimap IncreaseScroll <x> <y>
  400.  * Minimap SetScroll <x> <y>
  401.  * Minimap DeletePOI <poi_id>
  402.  * Minimap Generate_Passability_Overlay <true/false>
  403.  * Minimap Gen_Pass_Ov <true/false>
  404.  * Minimap ShowMapMenu
  405.  * Minimap SetPlayerBlip <filename/:player>
  406.  *
  407.  * Minimap SetFollowTarget <type> <value>
  408.  * Minimap setcamera <type> <value>
  409.  * Allowed types: player, event, coordinate
  410.  * Note: the player-type has no value parameter.
  411.  * Examples:
  412.  * Minimap SetFollowTarget player
  413.  * Minimap SetFollowTarget event 1
  414.  * Minimap SetFollowTarget coordinate 10 20
  415.  *
  416.  * Minimap POIDesc <description>
  417.  * Example: Minimap POIDesc An Awesome City!
  418.  *
  419.  * Minimap POI_TP <poi_id x_offset y_offset direction fadeType>
  420.  * Example: Minimap POI_TP 1 1 0 0 0
  421.  * Note that teleporting with both offsets set to 0, will teleport the player straight into the center of the poi.
  422.  *
  423.  * Adding POI's (advanced plugin command!):
  424.  * 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
  425.  * Example that draws Actor1_3 on tile 10,10:
  426.  * Minimap AddPOI 1 A_Friend 10 10 img/enemies/ Actor1_3 0 0 254 225 64 64
  427.  * Note:
  428.  * - The real_x & real_y are in maptiles and not in coordinates. 0,0 is in the upper left corner.
  429.  * - name-value replaces underscores _  with spaces.
  430.  *
  431.  * Minimap FoWShowTile x y
  432.  * Minimap FoWHideTile x y
  433.  * Example: Minimap FoWShowTile 10 15
  434.  * Note: no sanity-checks are performed for these 2 plugin commands. So for example: if you show/hide a tile outside of the map boundaries or supply a NaN-value or other weird value for the x&y, it's your problem.
  435.  *
  436.  * Minimap FoWChangeTiles x1 y1 x2 y2 reveal // reveal: true/false
  437.  * Example to reveal all tiles between 10,10 and 15,15:
  438.  * Minimap FoWChangeTiles 10 10 15 15 true
  439.  *
  440.  * Minimap FoWRevealTiles x1, y1, x2, y2
  441.  * Minimap FoWHideTiles x1, y1, x2, y2
  442.  * Minimap FoWRevealAll
  443.  *
  444.  * To fully cover the map again in FoW:
  445.  * Minimap FoWReset value // value is optional and defaults to true. value: true/false. When the value is set to false, the minimap won't remove the FoW around the player immediately after this plugin command.
  446.  * Minimap FoWHideAll     // is same as "Minimap FoWReset" shown above.
  447.  *--------------------------------------
  448.  * Event comment-tags (case sentitive!)
  449.  *--------------------------------------
  450.  * To show an event on the minimap:
  451.  * <mm_show>
  452.  *
  453.  * To add a description to an event (for the minimap-scene)
  454.  * <mm_desc>
  455.  *
  456.  * To add teleport to the event:
  457.  * <mm_tp:offset_x offset_y direction fadeType>
  458.  * Example: <mm_tp:1 0 2 0>
  459.  * Notes:
  460.  *        - Offset is the offset in tiles with the event-location itself being 0 0
  461.  *        - Possible direction values: 2 (down), 4 (left), 6 (right), 8 (up). Or use a value of 0 to maintain the current player-facing-direction
  462.  *        - Possible fadeType values: 0 (black), 1 (white), 2 (none)
  463.  *
  464.  *
  465.  * Note to other scripters: You can access the variable that contains the window through this: "Silv.Minimap.Window" w/o the quotes.
  466.  *
  467.  *
  468.  *--------------------------------------
  469.  * Script Calls & Event triggers (for advanced users & scripters ONLY!)
  470.  *--------------------------------------
  471.  * Getting a reference to the minimap window:
  472.  * Silv.Minimap.Window
  473.  *
  474.  * Retrieving the Fog of War completion status:
  475.  * Silv.Minimap.getFowCompletion(mapId);
  476.  * Note 1: mapId is optional (if a map is active) and when left out, it will be replaced with the id of the current map.
  477.  * Note 2: It will return an object
  478.  *
  479.  * Silv.Minimap.Window.onFullyRevealedMap(x, y) is called whenever the map is fully revealed (no more Fog of War tiles left) by the player and the x, y are the coordinates of the last revealed tile.
  480.  *
  481.  *--------------------------------------
  482.  * License / Terms
  483.  *--------------------------------------
  484.  * For the license and/or terms see: http://forums.rpgmakerweb.com/index.php?/topic/51307-silvers-advanced-minimap-now-with-fog-of-war/&page=1
  485.  * They are subject to change.
  486.  *
  487.  *--------------------------------------
  488.  * #Version #History:
  489.  *--------------------------------------
  490.  * v1.13 (09 February 2016) [Updated Parameters]
  491.  *   - Added a new parameter to assign the default map visibility.
  492.  *   - The plugin command "Minimap Refresh" can now be called when there is no active minimap.
  493.  *   - The minimap now automatically attempts to create itself upon gaining the required map-item while the player is on that same map.
  494.  *   - Automatic map-generation can now also be performed through regions. Regions override tile-tags but both can be used simultaneously.
  495.  *
  496.  * v1.12 (28 January 2016)
  497.  *   - Fixed a crash when the height of the map was bigger than it's width.
  498.  *
  499.  * v1.11 (03 January 2016) [Updated Parameters]
  500.  *   - Added Fog of War with new plugin commands. It obviously also works with looping maps, comes with persistence and you can determine what maps have FoW and which don't.
  501.  *     - You can optionally customize the Fog overlay image on a per-map-basis.
  502.  *     - Added a sample Fog of War overlay-image (FoW.png) to the forum post. I made it using the "The Gimp".
  503.  *     - New map-notetags: <mm_fow_enabled:value> <mm_fow_ov:value> <mm_fow_radius:value> <mm_fow_completion:value>
  504.  *     - Added a script-call to retrieve the FoW completion status: Silv.Minimap.getFowCompletion(mapId);
  505.  *     - Performs well even on super large (overworld) maps. It does use ~60-120MB of RAM on super large maps and only takes up to ~17kb of savegame file-size for super large maps.
  506.  *  - Added a new help section: "Script Calls & Event triggers".
  507.  *
  508.  * v1.10 (30 December 2015)
  509.  *   - Added the requested option to use a custom map-scene-image that is different from the actual map displayed in the minimap.
  510.  *   - Added a new mapnotetag: <mm_menu_bg:customImageName>
  511.  *
  512.  * v1.09 (27 December 2015)
  513.  *   - Fixed a crash that occurred when events (other than the last one) were deleted (in the map-editor) leaving behind null-values in the $dataMap.
  514.  *   - Renamed the plugin-command alias (before, there was a possible compatibility issue with some of my other scripts).
  515.  *   - Minor refactoring again and applied my new coding standards. Aliases are now stored outside of the anonymous function in a single variable.
  516.  *
  517.  * v1.08 (22 December 2015)
  518.  *   - Fixed a crash when getting onto a vehicle in the overworld when no minimap was active (line 1099) and when getting off a vehicle.
  519.  *   - Improved error reporting
  520.  *   - Switched to the Imported-variable. Thus this plugin now requires Silvers Key plugin 1.02!
  521.  *
  522.  * v1.07 (12 December 2015)
  523.  *   - New feature: Automatically shows vehicles on the minimap as the playerblip when entering a vehicle. Only applies if "Player Blip Graphic" is set to :player .
  524.  *   - Fixed a crash when generating an overworld map without a minimap-image and with the passability-overlay enabled.
  525.  *   - Is now compatible with dynamic map/dungeon generators. You can now recreate the minimap by calling: Silv.Minimap.setup(); after generating your random map.
  526.  *
  527.  * v1.06 (06 December 2015)
  528.  *   - 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
  529.  *     you do not have an active minimap or simply do not possess the required items.
  530.  *   - 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
  531.  *     to prevent ending up with duplicate minimap images in your project folder.
  532.  *   - Removed a console.log() that I forgot to remove in 1.05 before release.
  533.  *
  534.  * v1.05 (30 November 2015)
  535.  *   - 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.
  536.  *   - Fixed a crash when fading the scene without an active minimap.
  537.  *
  538.  * v1.04 (27 November 2015) [Updated Parameters]
  539.  *   - Disabled strict-mode (Either Javascript or RPG Maker seems not to support this fully...).
  540.  *   - Fixed a typo that caused the minimap to not resize in height.
  541.  *   - Grouped the player-blink parameters together and removed the unused "Draw Player Icon" parameter (v.1.03 only removed it partially).
  542.  *   - New feature: focus the minimap-camera onto (moving-)events, coordinates or the player.
  543.  *   - Minor refactoring.
  544.  *
  545.  * v1.03 (26 November 2015) [Updated Parameters]
  546.  *   - New feature: Use custom player blip.
  547.  *     - 2 new parameters: "Render Player Blip" & "Player Blip Graphic" and new mapnotetag: <mm_player_blip::player> and a new plugin parameter "Minimap setplayerblip <value>".
  548.  *     - Removed parameter "Draw Player Icon".
  549.  *   - Added a parameter to change minimap-opacity.
  550.  *   - Added plugin commands and map-notetags to switch between AutoScroll and Autofit map-modes, <mm_mapstyle:Scroll/Autofit>
  551.  *
  552.  * v1.02 (25 November 2015) [Updated Parameters]
  553.  *   - Enabled strict mode.
  554.  *   - Added the 'Minimap ShowMapMenu' plugin-command.
  555.  *   - 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>].
  556.  *   - New feature: generate passability overlay. Also comes with new map-notetag & plugin command. Supports 4-direction-passability.
  557.  *   - 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).
  558.  *   - Fixed the minimap-visibility again (it was still not properly fixed in v1.01).
  559.  *   - Now requires Silvers Keybinding script 1.01 instead of 1.00.
  560.  *
  561.  * v1.01 (24 November 2015) [Updated Parameters]
  562.  *   - Fixed the player-blip becoming invisible when walking on grass. Because of this I had to add 2 more advanced parameters.
  563.  *   - Fixed: The minimap no longer automatically shows itself again when it was manually hidden after opening a menu.
  564.  *   - Updated the version number to 1.01 (it was still 0.91) in the plugin description.
  565.  *   - Cleaned up some more out-commented code.
  566.  *   - Fixed: minimap can now hide again when it contains POI's.
  567.  *   - 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.
  568.  *
  569.  * v1.00 (23 November 2015)
  570.  *   - First release.
  571.  *
  572.  * v0.90-0.92 (November 2015)
  573.  *   - First alpha release.
  574.  *
  575.  */
  576. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  577. // Script start
  578. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  579. // Imported
  580. var Imported = Imported || {};
  581. Imported.SILV_Minimap = 1.13;
  582.  
  583. // Dependency check
  584. if (!('SILV_Keys' in Imported) || Imported.SILV_Keys < 1.02) { throw new Error('ERROR: Silvers Minimap requires Silvers KeyMapper v1.02 or higher. It must be placed above the minimap script.'); }
  585.  
  586. // Get Plugin #Parameters
  587. var Silv = Silv || {};
  588. Silv.Parameters = $plugins.filter(function(p) { return p.description.contains('<SilvMinimap>'); })[0].parameters;
  589. Silv.Minimap = Silv.Minimap || {};
  590. Silv.Minimap.Menu = Silv.Minimap.Menu || {};
  591. Silv.Minimap.Generator = Silv.Minimap.Generator || {};
  592. // Non-parameters
  593. Silv.Minimap.Window                 = null;
  594. Silv.Minimap.POI                    = {};
  595. Silv.Minimap.Events                 = []; // Is an array of objects [{ Game_Event, Sprite_Character }]. USe .event and .sprite to retrieve the values.
  596. Silv.Minimap.ScreenIsFading         = false;
  597. Silv.Minimap.Menu.Bmp               = null;
  598. Silv.Minimap.Menu.Markers           = [];
  599. Silv.Minimap.Menu.Enabled           = false;
  600. Silv.Minimap.WasLoadedFromSave      = false;
  601. 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.
  602. Silv.Minimap.TP_Dest                = null;
  603. Silv.Minimap.CreateFunctionIsLocked = false;
  604. Silv.Minimap.Visible                = true;
  605. Silv.Minimap.FoWData                = {};
  606. // General
  607. Silv.Minimap.MapStyle                     = Silv.Parameters['Map Style'].toLowerCase();
  608. Silv.Minimap.GlobalMapZoom                = parseFloat(Silv.Parameters['Global Map Zoom']);
  609. Silv.Minimap.Window_Opacity               = parseInt(Silv.Parameters['Minimap Opacity']);
  610. Silv.Minimap.VisibleByDefault             = Silv.Parameters['Visible By Default?'].toLowerCase() === 'true';
  611. // Positioning & Size
  612. Silv.Minimap.Window_X                     = parseInt(Silv.Parameters['X']);
  613. Silv.Minimap.Window_Y                     = parseInt(Silv.Parameters['Y']);
  614. Silv.Minimap.WindowWidth                  = parseInt(Silv.Parameters['Width']);
  615. Silv.Minimap.WindowHeight                 = parseInt(Silv.Parameters['Height']);
  616. Silv.Minimap.BorderWidth                  = parseInt(Silv.Parameters['Border Width']);
  617. Silv.Minimap.BorderHeight                 = parseInt(Silv.Parameters['Border Height']);
  618. Silv.Minimap.WindowHorizontalAlignment    = Silv.Parameters['Horizontal Alignment'].toLowerCase();
  619. Silv.Minimap.WindowVerticalAlignment      = Silv.Parameters['Vertical Alignment'].toLowerCase();
  620. // Player Blip
  621. Silv.Minimap.PlayerBlipEnabled            = Silv.Parameters['Render Player Blip'].toLowerCase() === 'true';
  622. Silv.Minimap.PlayerBlipGraphic            = Silv.Parameters['Player Blip Graphic'].toLowerCase();
  623. Silv.Minimap.PlayerIconWidth              = parseInt(Silv.Parameters['Player Icon Width']);
  624. Silv.Minimap.PlayerIconHeight             = parseInt(Silv.Parameters['Player Icon Height']);
  625. Silv.Minimap.PlayerBlinks                 = parseInt(Silv.Parameters['Player Blink Delay']) > 0; // note: is not directly a parameter but uses one to calculate the value instead
  626. Silv.Minimap.PlayerBlinkDelay             = parseInt(Silv.Parameters['Player Blink Delay']);
  627. // Menu
  628. Silv.Minimap.Menu.MenuKey                 = Silv.Keys.fromStringParam(Silv.Parameters['Menu Key']);
  629. Silv.Minimap.Menu.PlayerDesc              = Silv.Parameters['Menu Player Description'];
  630. Silv.Minimap.Menu.Zoom                    = parseFloat(Silv.Parameters['Menu Zoom']);
  631. Silv.Minimap.Menu.WindowWidth_Left        = parseInt(Silv.Parameters['Menu Left Window Width']);
  632. Silv.Minimap.Menu.WindowHeight_MapSection = parseInt(Silv.Parameters['Menu Topright Window Height']);
  633. Silv.Minimap.Menu.EventRenderSize         = parseInt(Silv.Parameters['Menu Event Render Size']);
  634. Silv.Minimap.Menu.PlayerIconSize          = parseInt(Silv.Parameters['Menu Player Icon Size']);
  635. Silv.Minimap.Menu.ManualZoom_Min          = parseFloat(Silv.Parameters['Menu Min Manual Zoom']);
  636. Silv.Minimap.Menu.ManualZoom_Max          = parseFloat(Silv.Parameters['Menu Max Manual Zoom']);
  637. Silv.Minimap.Menu.ManualZoomKey_In        = Silv.Keys.fromStringParam(Silv.Parameters['Menu Zoomin Key']);
  638. Silv.Minimap.Menu.ManualZoomKey_Out       = Silv.Keys.fromStringParam(Silv.Parameters['Menu Zoomout Key']);
  639. Silv.Minimap.Menu.ManualZoomKey_Reset     = Silv.Keys.fromStringParam(Silv.Parameters['Menu Reset Zoom Key']);
  640. Silv.Minimap.Menu.ManualScrollKey_Reset   = Silv.Keys.fromStringParam(Silv.Parameters['Menu Reset Scroll Key']);
  641. // Passability Map
  642. Silv.Minimap.PassabilityOverlayOpacity    = parseInt(Silv.Parameters['Passability Overlay Opacity']);
  643. Silv.Minimap.PassabilityColor             = Silv.Parameters['Passability Color'];
  644. Silv.Minimap.ImpassabilityColor           = Silv.Parameters['Impassability Color'];
  645. // Generator
  646. Silv.Minimap.Generator.MapColors          = Silv.Parameters['Map Gen Tag Colors'].split(' ');
  647. Silv.Minimap.Generator.WorldColors        = Silv.Parameters['Overworld Gen Tag Colors'].split(' ');
  648. Silv.Minimap.Generator.RegionMapColors    = Silv.Parameters['Map Gen Region Colors'].split(' ');
  649. Silv.Minimap.Generator.RegionWorldColors  = Silv.Parameters['Overworld Gen Region Colors'].split(' ');
  650. // The Rest
  651. Silv.Minimap.AllowTeleportation           = Silv.Parameters['Allow Teleportation'].toLowerCase() === 'true';
  652. Silv.Minimap.StandardPadding              = parseInt(Silv.Parameters['Standard Padding']);
  653. Silv.Minimap.WindowSkin                   = Silv.Parameters['Window Skin'];
  654. Silv.Minimap.MapBGFillColor               = Silv.Parameters['Fill Color'].split(' ');
  655. Silv.Minimap.MaintainAspectRatio          = Silv.Parameters['Maintain Aspect Ratio'].toLowerCase() === 'true';
  656. Silv.Minimap.FadeoutSpeed                 = parseInt(Silv.Parameters['Fadeout Speed']);
  657. Silv.Minimap.GlobalRequiredItem           = parseInt(Silv.Parameters['Global Required Item']);
  658. Silv.Minimap.EventRenderSize              = parseInt(Silv.Parameters['Event Render Size']);
  659. Silv.Minimap.AutoClearPOI                 = Silv.Parameters['Auto Clear POI'].toLowerCase() === 'true';
  660. Silv.Minimap.DrawOverlay                  = Silv.Parameters['Render Minimap Overlay'].toLowerCase() === 'true';
  661. // Fog of War
  662. Silv.Minimap.FoWEnabled                   = Silv.Parameters['FoW Enabled'].toLowerCase() === 'true';
  663. Silv.Minimap.DefaultFoWBmpName            = Silv.Parameters['Default FoW Overlay'];
  664. Silv.Minimap.DefaultFoWRadius             = parseInt(Silv.Parameters['Default FoW Radius']);
  665. // Manual Scrolling
  666. Silv.Minimap.AllowManualScrolling         = Silv.Parameters['Allow Manual Scrolling'].toLowerCase() === 'true';
  667. Silv.Minimap.ManualScrollspeed            = parseFloat(Silv.Parameters['Manual Scrollspeed']);
  668. Silv.Minimap.ManualScrollKeyUp            = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Up']);
  669. Silv.Minimap.ManualScrollKeyRight         = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Right']);
  670. Silv.Minimap.ManualScrollKeyDown          = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Down']);
  671. Silv.Minimap.ManualScrollKeyLeft          = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Left']);
  672. // Advanced & Debug
  673. Silv.Minimap.PlayerSpriteSrcFrame_Width   = parseInt(Silv.Parameters['Player Sprite Sourceframe Width']);
  674. Silv.Minimap.PlayerSpriteSrcFrame_Height  = parseInt(Silv.Parameters['Player Sprite Sourceframe Height']);
  675. Silv.Minimap.FrameSkip                    = parseInt(Silv.Parameters['Frame Skip']);
  676. Silv.Minimap.MapFilenameLength            = parseInt(Silv.Parameters['Mapshot Filename Length']);
  677. Silv.Minimap.DebugMode                    = Silv.Parameters['Debug Mode'].toLowerCase() === 'true';
  678. Silv.Minimap.DrawDebugGrid                = Silv.Parameters['Render Debug Grid'].toLowerCase() === 'true';
  679. Silv.Minimap.DebugGridImage               = Silv.Parameters['Debug Grid Image'];
  680.  
  681. // Parameter after-care
  682. (function()
  683. {
  684.     var convertParams = function(param) // param SHOULD be passed by reference because it is typeof Array. But it is not when a new value is assigned to that array... Therefore we use the return value. And adding a new method to Array won't work either because you can't change "this". Fuck Javascript... Fucking half-assed language.
  685.     {
  686.         var newArray = [];
  687.         for(var i=0; i<param.length; i++)
  688.         {
  689.             var splitValue = param[i].split(':');
  690.             newArray[parseInt(splitValue[0])] = splitValue[1];
  691.         }
  692.         return newArray;
  693.     };
  694.    
  695.     Silv.Minimap.Generator.RegionMapColors = convertParams(Silv.Minimap.Generator.RegionMapColors);
  696.     Silv.Minimap.Generator.RegionWorldColors = convertParams(Silv.Minimap.Generator.RegionWorldColors);
  697. })();
  698.  
  699. // Alias
  700. Silv.Alias = Silv.Alias || {};
  701. if (!Silv.AddAlias)
  702. {
  703.     Silv.AddAlias = function(alias, original_method)
  704.     {
  705.         if (Silv.Alias[alias]) { throw new Error('Alias already exists: ' + alias); }
  706.         Silv.Alias[alias] = original_method;
  707.     };
  708. }
  709.  
  710. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  711. (function()
  712. {
  713. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  714. // #Utilities & Misc
  715. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  716. // Example: lpad('2', '0') // result: '002'
  717. function lpad_mapname(word, padStr)
  718. {
  719.     word = String(word);
  720.     while (word.length < Silv.Minimap.MapFilenameLength) word = padStr + word;
  721.     return word;
  722. }
  723.  
  724. function minimapFolderPath()
  725. {
  726.     var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, "/img/minimap/");
  727.     if (path.match(/^\/([A-Z]\:)/)) { path = path.slice(1); }
  728.     path = decodeURIComponent(path);
  729.     return path;
  730. }
  731.  
  732. function getFullMinimapPath(filename)
  733. {
  734.     return minimapFolderPath() + filename;
  735. }
  736.  
  737. // filename example: '002.png'
  738. function minimapImageExists(filename)
  739. {
  740.     var fs = require('fs');
  741.     return fs.existsSync(getFullMinimapPath(filename));
  742. }
  743.  
  744. function dataMapGetEventByID(ev_id)
  745. {
  746.     for(var i=1; i< $dataMap.events.length; i++)
  747.     {
  748.         // $dataMap.events may contain null-values when placing several events in the editor and then deleting an even (other than the last one). Therefore the ($dataMap.events[i] !== null) check is required.
  749.         if (($dataMap.events[i] !== null) && $dataMap.events[i].id == ev_id) { return $dataMap.events[i]; }
  750.     }
  751.     return null;
  752. }
  753.  
  754. ImageManager.loadMinimap = function(filename, hue)
  755. {
  756.     return this.loadBitmap('img/minimap/', filename, hue, false);
  757. };
  758.  
  759. // Do not just show the minimap on top of a faded-out screen.
  760. Silv.AddAlias('mm_Game_Screen_updateFadeOut', Game_Screen.prototype.updateFadeOut);
  761. Game_Screen.prototype.updateFadeOut = function()
  762. {
  763.     Silv.Alias.mm_Game_Screen_updateFadeOut.apply(this, arguments);
  764.    
  765.     if (this._brightness < 255) // (this._fadeOutDuration > 0)
  766.     {
  767.         Silv.Minimap.ScreenIsFading = true;
  768.         if (Silv.Minimap.Window !== null)
  769.         {
  770.             Silv.Minimap.Window.opacity = this._brightness;
  771.             Silv.Minimap.Window.contents.paintOpacity  = this._brightness;
  772.         }
  773.     }
  774.     else
  775.     {
  776.         Silv.Minimap.ScreenIsFading = false;
  777.     }
  778. };
  779. //------------------------------------------------------------------------------------------------------------------------------------
  780. // Store a reference to the player graphic.
  781. //------------------------------------------------------------------------------------------------------------------------------------
  782. Silv.AddAlias('mm_Spriteset_Map_createCharacters', Spriteset_Map.prototype.createCharacters);
  783. Spriteset_Map.prototype.createCharacters = function()
  784. {
  785.     Silv.Alias.mm_Spriteset_Map_createCharacters.apply(this, arguments);
  786.    
  787.     for (var i = this._characterSprites.length - 1; i >= 0; i--)
  788.     {
  789.         if (this._characterSprites[i]._character == $gamePlayer)
  790.         {
  791.             Spriteset_Map.prototype.playerSprite = this._characterSprites[i];
  792.             break;
  793.         }  
  794.     }
  795. };
  796. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  797. // Automatically create a event-Notetag from event-comments on the active page
  798. // Example usage: console.log($gameMap.event(1).event.silvNote);
  799. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  800. Silv.AddAlias('mm_Game_Event_setupPage',  Game_Event.prototype.setupPage);
  801. Game_Event.prototype.setupPage = function()
  802. {
  803.     Silv.Alias.mm_Game_Event_setupPage.apply(this, arguments);
  804.     this.silvCreateNote();
  805. };
  806.  
  807. Game_Event.prototype.silvCreateNote = function()
  808. {
  809.     this.silvNote = '';
  810.     if (typeof this.page() === 'undefined') { return; }
  811.    
  812.     var list = this.list();
  813.     var str = null;
  814.     for (var commandProperty in list)
  815.     {
  816.         if (list.hasOwnProperty(commandProperty))
  817.         {
  818.             var command = list[commandProperty];
  819.             var commandCode = command.code;
  820.             if (commandCode == 108) // 108: new comment-item, always the first line.
  821.             {
  822.                 if (str !== null) { this.silvNote += str; }
  823.                 str = command.parameters[0];
  824.             }
  825.             else if (commandCode == 408) // 408: comment-line, but not the first one.
  826.             {
  827.                 this.silvNote += command.parameters[0];
  828.             }
  829.             else if (str) // It's not a comment-code, so add the previous str (if any) to the note.
  830.             {
  831.                 this.silvNote += str;
  832.                 str = null;
  833.             }
  834.         }
  835.     }
  836.     if (this.silvNote !== '') { this.extractSilvMetadata(); }
  837. };
  838.  
  839. // <mm_tp:1> will result in: '1'
  840. // <mm_tp:1> will result in: ['1', '0'];
  841. Game_Event.prototype.extractSilvMetadata = function() {
  842.     var re = /<([^<>:]+)(:?)([^>]*)>/g;
  843.     this.meta = {};
  844.     for (;;)
  845.     {
  846.         var match = re.exec(this.silvNote);
  847.         if (match)
  848.         {
  849.             if (match[2] === ':')
  850.             {
  851.                 var value = match[3];
  852.                 if (match[3].indexOf(' ') >= 0) { value = match[3].split(' '); }
  853.                
  854.                 this[match[1]] = value;
  855.             }
  856.             else
  857.             {
  858.                 this[match[1]] = true;
  859.             }
  860.         }
  861.         else
  862.         {
  863.             break;
  864.         }
  865.     }
  866. };
  867. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  868. // Minimap Window
  869. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  870. function Window_Minimap() { this.initialize.apply(this, arguments); }
  871. // Inherit from base window
  872. Window_Minimap.prototype = Object.create(Window_Base.prototype);
  873. // Set Constructor
  874. Window_Minimap.prototype.constructor = Window_Minimap;
  875.  
  876. Window_Minimap.prototype.loadWindowskin = function() { this.windowskin = ImageManager.loadSystem(Silv.Minimap.WindowSkin); };
  877. Window_Minimap.prototype.standardPadding = function() { return Silv.Minimap.StandardPadding; };
  878. //Window_Minimap.prototype.standardFontSize = function() { return Silv.Minimap.FontSize; }
  879. Window_Minimap.prototype.bmpPreloadTotal = 1; // The amount of images to preload before the minimap can be rendered.
  880.  
  881.  
  882. // #Initialization
  883. Window_Minimap.prototype.initialize = function(x, y, width, height, mapName, minimapType)
  884. {
  885.     this.mapName = mapName;
  886.     this.minimapType = minimapType;
  887.     if ('mm_size' in $dataMap.meta)
  888.     {
  889.         var newSize = $dataMap.meta.mm_size.split(' ');
  890.         this.width = parseInt(newSize[0]);
  891.         this.height = parseInt(newSize[1]);
  892.     }
  893.    
  894.     Window_Base.prototype.initialize.call(this, x, y, width, height);
  895.     this._helpWindow = null;
  896.     this._handlers = {};
  897.     this._touching = false;
  898.     this.deactivate();
  899.  
  900.     this.bmpPreloadCnt = 0;
  901.     this.finishedBmpPreloading = false;
  902.    
  903.     // Fog of War
  904.     if ('mm_fow_enabled' in $dataMap.meta)
  905.     {
  906.         this.fowEnabled = $dataMap.meta.mm_fow_enabled.toLowerCase() === 'true';
  907.     }
  908.     else
  909.     {
  910.         this.fowEnabled = Silv.Minimap.FoWEnabled;
  911.     }
  912.     this.fowBmpName = ('mm_fow_ov' in $dataMap.meta) ? $dataMap.meta.mm_fow_ov : Silv.Minimap.DefaultFoWBmpName;
  913.     if (typeof Silv.Minimap.FoWData[$gameMap._mapId] === 'undefined') // This if-statement must be placed before preloading the FoW-bitmap
  914.     {
  915.         this.resetFoWData();
  916.         this.fowRequiresRefresh = false;
  917.     }
  918.     else
  919.     {
  920.         this.fowRequiresRefresh = true;
  921.     }
  922.     this.fowOriginalBmp = ImageManager.loadMinimap(this.fowBmpName);
  923.     this.fowOriginalBmp.addLoadListener(function() { this.onFinishOriginalFoWBmpLoad(); }.bind(this));
  924.     this.fowRadius = ('mm_fow_radius' in $dataMap.meta) ? parseInt($dataMap.meta.mm_fow_radius) : Silv.Minimap.DefaultFoWRadius;
  925.    
  926.     this.originalMapBmp = null;
  927.     this.passabilityBmp = null;
  928.     this.drawPassabilityOverlay = false;
  929.     this.isFadingOut = false;
  930.     this.isFadedOut = false;
  931.     this.setDrawMapBmp();
  932.     this.overlayBmp = ImageManager.loadMinimap('Overlay');
  933.     this.drawAreaWidth = this.contents.width - Silv.Minimap.BorderWidth * 2;
  934.     this.drawAreaHeight = this.contents.height - Silv.Minimap.BorderHeight * 2;
  935.     this.mapWidth = parseFloat($gameMap.width());
  936.     this.mapHeight = parseFloat($gameMap.height());
  937.     this.setAspectRatio();
  938.     this.playerBlinkCnt = Silv.Minimap.PlayerBlinkDelay;
  939.     this.playerBlink_IsVisible = true;
  940.     this.frameSkip = Silv.Minimap.FrameSkip;
  941.     this.frameSkipCnt = 0;
  942.     Silv.Minimap.Menu.Enabled = true;
  943.     this.mapZoom = ('mm_mapzoom' in $dataMap.meta) ? parseFloat($dataMap.meta.mm_mapzoom) : Silv.Minimap.GlobalMapZoom;
  944.     this.mapZoomInverse = 1 / this.mapZoom;
  945.     this.isFirstProcessedUpdate = true;
  946.     this.requiresDrawing = true; // as in AFTER isReady().
  947.     this.isManualScrolling = false;
  948.     this.allowManualScroll = ('mm_allowmanualscroll' in $dataMap.meta) ? $dataMap.meta.mm_allowmanualscroll.toLowerCase() === 'true' : Silv.Minimap.AllowManualScrolling;
  949.     this.mapScroll = {x: 0, y: 0, adjustment_x: 0, adjustment_y: 0};
  950.     this.lastPlayerLoc = {x: $gamePlayer._realX, y: $gamePlayer._realY};
  951.     this.menuZoom = ('mm_menuzoom' in $dataMap.meta) ? $dataMap.meta.mm_menuzoom.toLowerCase() === 'true' : Silv.Minimap.Menu.Zoom;
  952.     this.allowTeleportation = ('mm_tp_allow' in $dataMap.meta) ? $dataMap.meta.mm_tp_allow.toLowerCase() === 'true' : Silv.Minimap.AllowTeleportation;
  953.     this.playerFrame = { x:0, y:0, width:Silv.Minimap.PlayerSpriteSrcFrame_Width, height:Silv.Minimap.PlayerSpriteSrcFrame_Height };
  954.     this.mapStyle = ('mm_mapstyle' in $dataMap.meta) ? $dataMap.meta.mm_mapstyle.toLowerCase() : Silv.Minimap.MapStyle;
  955.     this.cameraFocusType = 'player'; // player / event / coordinate
  956.     this.cameraFocusObject = null; // null / reference to event / {x:real_x, y:real_y}
  957.     this.vehicleCharSprite = null;
  958.     this.menuBG = ('mm_menu_bg' in $dataMap.meta) ? ImageManager.loadMinimap($dataMap.meta.mm_menu_bg) : null;
  959.    
  960.     this.initPlayerBlip();
  961.    
  962.     this.loadEvents();
  963.     this.debugGridBmp = ImageManager.loadMinimap(Silv.Minimap.DebugGridImage);
  964.        
  965.     // The update must be called AFTER all the initialization code.
  966.     this.update();
  967.    
  968.     // Default visibility
  969.     if (!Silv.Minimap.VisibleByDefault) { this.hide(); }
  970. };
  971.  
  972. Window_Minimap.prototype.finishBmpLoad = function()
  973. {
  974.     this.bmpPreloadCnt++;
  975.     if (this.bmpPreloadCnt === this.bmpPreloadTotal) { this.finishedBmpPreloading = true; }
  976. };
  977.  
  978. Window_Minimap.prototype.setOpacity = function()
  979. {
  980.     this.opacity = Silv.Minimap.Window_Opacity;
  981. };
  982.  
  983. Window_Minimap.prototype.initPlayerBlip = function()
  984. {
  985.     this.playerBlipEnabled = Silv.Minimap.PlayerBlipEnabled;
  986.     this.playerBlipGfx = Silv.Minimap.PlayerBlipGraphic;
  987.     this.playerBlipBmp = null;
  988.    
  989.     if ('mm_player_blip' in $dataMap.meta) { this.setPlayerBlip($dataMap.meta.mm_player_blip); }
  990.     else { this.setPlayerBlip(Silv.Minimap.PlayerBlipGraphic); }
  991. };
  992. //----------------------------------------------------------------------------------------------------
  993. // Set Drawing Bitmaps
  994. //----------------------------------------------------------------------------------------------------
  995. Window_Minimap.prototype.setDrawMapBmp = function()
  996. {
  997.     switch (this.minimapType)
  998.     {
  999.         case 'regular':
  1000.             if (this.originalMapBmp === null)
  1001.             {
  1002.                 this.originalMapBmp = ImageManager.loadMinimap(this.mapName);
  1003.                 this.mapBmp = ImageManager.loadMinimap(this.mapName);
  1004.             }
  1005.             else if (this.originalMapBmp.isReady())
  1006.             {
  1007.                 this.mapBmp = new Bitmap(this.originalMapBmp.width, this.originalMapBmp.height);
  1008.                 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...
  1009.                 this.requiresDrawing = false;
  1010.             }
  1011.             break;
  1012.         case 'generate_map':
  1013.             this.mapBmp          = this.generateMap(Silv.Minimap.Generator.MapColors, Silv.Minimap.Generator.RegionMapColors);
  1014.             this.originalMapBmp  = this.generateMap(Silv.Minimap.Generator.MapColors, Silv.Minimap.Generator.RegionMapColors);
  1015.             this.requiresDrawing = false;
  1016.             break;
  1017.         case 'generate_overworld':
  1018.             this.mapBmp          = this.generateMap(Silv.Minimap.Generator.WorldColors, Silv.Minimap.Generator.RegionWorldColors);
  1019.             this.originalMapBmp  = this.generateMap(Silv.Minimap.Generator.WorldColors, Silv.Minimap.Generator.RegionWorldColors);
  1020.             this.requiresDrawing = false;
  1021.             break;
  1022.         default:
  1023.             throw new Error('Window_Minimap.prototype.GetMapBmp has invalid switch-value: ' + this.minimapType);
  1024.     }
  1025.    
  1026.     if (this.drawPassabilityOverlay)
  1027.     {
  1028.         if (this.originalMapBmp.isReady()) { this.bltPassabilityOverlay(); }
  1029.         else { this.passabilityRequiresRedraw = true; }
  1030.     }
  1031. };
  1032. //----------------------------------------------------------------------------------------------------
  1033. // #Show & #Hide
  1034. //----------------------------------------------------------------------------------------------------
  1035. Window_Minimap.prototype.hide = function()
  1036. {
  1037.     Window_Base.prototype.hide.apply(this, arguments);
  1038.     Silv.Minimap.Visible = false;
  1039. };
  1040.  
  1041. Window_Minimap.prototype.show = function()
  1042. {
  1043.     Window_Base.prototype.show.apply(this, arguments);
  1044.     Silv.Minimap.Visible = true;
  1045. };
  1046. //----------------------------------------------------------------------------------------------------
  1047. // #Passability #Overlay
  1048. //----------------------------------------------------------------------------------------------------
  1049. Window_Minimap.prototype.bltPassabilityOverlay = function()
  1050. {
  1051.     // Generate the bitmap if it wasn't done already
  1052.     if (this.passabilityBmp === null) { this.passabilityBmp = this.generatePassabilityBmp(); }
  1053.    
  1054.     // Blt the overlay on top of the this.mapBmp
  1055.     this.mapBmp.blt(this.passabilityBmp, 0, 0, this.passabilityBmp.width, this.passabilityBmp.height, 0, 0);
  1056.    
  1057.     this.passabilityRequiresRedraw = false;
  1058. };
  1059.  
  1060. Window_Minimap.prototype.setPassabilityOverlay = function(enabled)
  1061. {
  1062.     this.drawPassabilityOverlay = enabled;
  1063.     this.setDrawMapBmp();
  1064. };
  1065.  
  1066. // 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.
  1067. Window_Minimap.prototype.generatePassabilityBmp = function()
  1068. {
  1069.     var tile_w = $gameMap.tileWidth();
  1070.     var tile_h = $gameMap.tileHeight();
  1071.     var bmp = new Bitmap($gameMap.width() * tile_w, $gameMap.height() * tile_h);
  1072.     bmp.paintOpacity = Silv.Minimap.PassabilityOverlayOpacity;
  1073.     var borderTickness = 8;
  1074.    
  1075.     for (var y=0; y<$dataMap.height; y++)
  1076.     {
  1077.         for (var x=0; x<$dataMap.width; x++)
  1078.         {
  1079.             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)};
  1080.            
  1081.             if (!passability[2] && !passability[4] && !passability[6] && !passability[8])
  1082.             {
  1083.                 bmp.fillRect(x * tile_w, y * tile_h, tile_w, tile_h, Silv.Minimap.ImpassabilityColor);
  1084.             }
  1085.             else
  1086.             {
  1087.                 bmp.paintOpacity = 255;
  1088.                 if (!passability[8]) { bmp.fillRect(x * tile_w, y * tile_h, tile_w, borderTickness, Silv.Minimap.ImpassabilityColor); } // top
  1089.                 if (!passability[6]) { bmp.fillRect(x * tile_w + tile_w - borderTickness, y * tile_h, borderTickness, tile_h, Silv.Minimap.ImpassabilityColor); } // right
  1090.                 if (!passability[2]) { bmp.fillRect(x * tile_w, y * tile_h + tile_h - borderTickness, tile_w, borderTickness, Silv.Minimap.ImpassabilityColor); } // bottom
  1091.                 if (!passability[4]) { bmp.fillRect(x * tile_w, y * tile_h, borderTickness, tile_h, Silv.Minimap.ImpassabilityColor); } // left
  1092.                 bmp.paintOpacity = Silv.Minimap.PassabilityOverlayOpacity;
  1093.                
  1094.                 bmp.fillRect(x * tile_w, y * tile_h, tile_w, tile_h, Silv.Minimap.PassabilityColor);
  1095.             }
  1096.         }
  1097.     }
  1098.     return bmp;
  1099. };
  1100.  
  1101. //----------------------------------------------------------------------------------------------------
  1102. // #Generate Maps
  1103. //----------------------------------------------------------------------------------------------------
  1104. Window_Minimap.prototype.generateMap = function(tagColors, regionColors)
  1105. {
  1106.     var tile_w = $gameMap.tileWidth();
  1107.     var tile_h = $gameMap.tileHeight();
  1108.     var bmp = new Bitmap($gameMap.width() * tile_w, $gameMap.height() * tile_h);
  1109.    
  1110.     for (var y=0; y<$dataMap.height; y++)
  1111.     {
  1112.         for (var x=0; x<$dataMap.width; x++)
  1113.         {
  1114.             var effectiveColor = regionColors[$gameMap.regionId(x, y)];
  1115.             if (typeof effectiveColor === 'undefined') { color = tagColors[$gameMap.terrainTag(x, y)]; }
  1116.             bmp.fillRect(x * tile_w, y * tile_h, tile_w, tile_h, effectiveColor);
  1117.         }
  1118.     }
  1119.     return bmp;
  1120. };
  1121.  
  1122. //----------------------------------------------------------------------------------------------------
  1123. // <Asorted>
  1124. //----------------------------------------------------------------------------------------------------
  1125. Window_Minimap.prototype.showMapMenuScene = function()
  1126. {
  1127.     Silv.Minimap.Window.pushMapScene();
  1128. };
  1129.  
  1130. Window_Minimap.prototype.clamp = function(value, min, max)
  1131. {
  1132.     return Math.min(Math.max(value, min), max);
  1133. };
  1134.    
  1135. // This function requires this.mapBmp to be fully initialized.
  1136. // #Aspect #Ratio #AspectRatio
  1137. Window_Minimap.prototype.setAspectRatio = function()
  1138. {
  1139.     // this.mapAspRatInfo.scaleDelta_x is the difference in size between the mapwidth (in pixels, NOT in tiles) and the minimap (render)width.
  1140.     this.mapAspRatInfo = { w: 0.0, h: 0.0, offset_x: 0.0, offset_y: 0.0, scaleDelta_x: 0.0, scaleDelta_y: 0.0 };
  1141.     var w = $gameMap.width();
  1142.     var h = $gameMap.height();
  1143.    
  1144.     // Map Aspect Ratio
  1145.     if (!Silv.Minimap.MaintainAspectRatio || (w == h))
  1146.     {
  1147.         this.mapAspRatInfo.w = 1.0;
  1148.         this.mapAspRatInfo.h = 1.0;
  1149.     }
  1150.     else if (w > h)
  1151.     {
  1152.         this.mapAspRatInfo.w = 1.0;
  1153.         this.mapAspRatInfo.h = h / parseFloat(w);
  1154.     }
  1155.     else // if (h > w)
  1156.     {
  1157.         this.mapAspRatInfo.w = w / parseFloat(h);
  1158.         this.mapAspRatInfo.h = 1.0;
  1159.     }
  1160.    
  1161.     this.mapAspRatInfo.scaleDelta_x = this.drawAreaWidth / parseFloat($gameMap.width() * $gameMap.tileWidth());
  1162.     this.mapAspRatInfo.scaleDelta_y = this.drawAreaHeight / parseFloat($gameMap.height() * $gameMap.tileHeight());
  1163. };
  1164.  
  1165. // #Events
  1166. Window_Minimap.prototype.loadEvents = function()
  1167. {
  1168.     Silv.Minimap.Events = [];
  1169.     for (var ev_idx = 1; ev_idx < $dataMap.events.length; ev_idx++) // Note: start at 1. Because the first one is always null.
  1170.     {
  1171.         if ($dataMap.events[ev_idx] !== null)
  1172.         {
  1173.             var ev = $gameMap.event(ev_idx);
  1174.            
  1175.             // Check Event Note
  1176.             if ($dataMap.events[ev_idx].note !== '' || ('mm_show' in ev))
  1177.             {
  1178.                 var cmds = $dataMap.events[ev_idx].note.toLowerCase().split(' ');
  1179.                 if ((cmds.indexOf('mm_show') > -1) ||  ('mm_show' in ev))
  1180.                 {
  1181.                     var new_ev = {event: ev, sprite: this.getEventCharacterSprite(ev.eventId())};
  1182.                     Silv.Minimap.Events.push(new_ev); // Add event to the array so we can render it on the minimap
  1183.                 }
  1184.             }
  1185.         }
  1186.     }
  1187.     if (Silv.Minimap.DebugMode) { console.log('Loaded Events:'); console.log(Silv.Minimap.Events); }
  1188. };
  1189.  
  1190. Window_Minimap.prototype.getEventCharacterSprite = function(ev_id)
  1191. {
  1192.     for (var i=0; i < SceneManager._scene._spriteset._characterSprites.length; i++)
  1193.     {
  1194.         var eventSprite = SceneManager._scene._spriteset._characterSprites[i];
  1195.         if (eventSprite._character.eventId() == ev_id)
  1196.         {
  1197.             return eventSprite;
  1198.         }
  1199.     }
  1200.     throw new Error('getEventCharacterSprite() did not find a match for ev_id: ' + ev_id);
  1201. };
  1202.    
  1203. // #update
  1204. Window_Minimap.prototype.update = function()
  1205. {
  1206.     // Do nothing if some images haven't finished loading yet
  1207.     if (!this.finishedBmpPreloading) { return; }
  1208.    
  1209.     if (!this.skipFrame() && (this.originalMapBmp === null || this.originalMapBmp.isReady()))
  1210.     {
  1211.         Window_Base.prototype.update.call(this);
  1212.         this.updateFadeOut();
  1213.         this.updateInput();
  1214.         if (Silv.Minimap.PlayerBlinks) { this.updatePlayerBlink(); }
  1215.         this.updateMapScroll(this.isFirstProcessedUpdate);
  1216.         this.playerInfo = this.getPlayerBitmap();
  1217.         if (this.requiresDrawing) { this.setDrawMapBmp(); }
  1218.         this.drawMinimap();
  1219.         this.lastPlayerLoc.x  = $gamePlayer._realX;
  1220.         this.lastPlayerLoc.y  = $gamePlayer._realY;
  1221.         this.isFirstProcessedUpdate = false;
  1222.        
  1223.         // Teleport
  1224.         if (Silv.Minimap.TP_Dest !== null)
  1225.         {
  1226.             this.teleport(Silv.Minimap.TP_Dest);
  1227.             Silv.Minimap.TP_Dest = null;
  1228.         }
  1229.        
  1230.         if (this.passabilityRequiresRedraw && this.originalMapBmp.isReady()) { this.bltPassabilityOverlay(); }
  1231.     }
  1232.    
  1233.     if (Input.isTriggered(Silv.Minimap.Menu.MenuKey)) { this.showMapMenuScene(); }
  1234. };
  1235.  
  1236. //----------------------------------------------------------------------------------------------------
  1237. // Get #Player #Blip Bitmap
  1238. //----------------------------------------------------------------------------------------------------
  1239. Window_Minimap.prototype.getPlayerBitmap = function()
  1240. {
  1241.     if (this.vehicleCharSprite === null)
  1242.     {
  1243.         var playerSpr = Spriteset_Map.prototype.playerSprite;
  1244.         // Player is not in bush, so return the regular player-graphic
  1245.         if (playerSpr._bushDepth == 0 || playerSpr._lowerBody === null)
  1246.         {
  1247.             return { bmp:playerSpr._bitmap, src:playerSpr._frame };
  1248.         }
  1249.  
  1250.         // Create Bush graphic (which is divided into 2 graphics by the RM-code..)
  1251.         var playerBmp = new Bitmap(Silv.Minimap.PlayerSpriteSrcFrame_Width, Silv.Minimap.PlayerSpriteSrcFrame_Height);
  1252.         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,
  1253.                       0, Silv.Minimap.PlayerSpriteSrcFrame_Height - playerSpr._bushDepth, Silv.Minimap.PlayerIconSize, Silv.Minimap.PlayerIconSize);
  1254.         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,
  1255.                       0, 0, Silv.Minimap.PlayerIconSize, Silv.Minimap.PlayerIconSize);
  1256.        
  1257.         return {bmp:playerBmp, src:this.playerFrame};
  1258.     }
  1259.     else // return vehicle instead
  1260.     {
  1261.         return { bmp:this.vehicleCharSprite._bitmap, src:this.vehicleCharSprite._frame };
  1262.     }
  1263. };
  1264. //----------------------------------------------------------------------------------------------------
  1265. // #Vehicle Compatibility for Player Blip Bitmap
  1266. //----------------------------------------------------------------------------------------------------
  1267. Silv.AddAlias('mm_Game_Vehicle_getOnVehicle', Game_Vehicle.prototype.getOn);
  1268. Game_Vehicle.prototype.getOn = function()
  1269. {
  1270.     Silv.Alias.mm_Game_Vehicle_getOnVehicle.apply(this, arguments);
  1271.    
  1272.     if (Silv.Minimap.Window)
  1273.     {
  1274.         var charSprites = SceneManager._scene._spriteset._characterSprites;
  1275.         for (var i = charSprites.length - 1; i >= 0; i--)
  1276.         {
  1277.             if (charSprites[i]._character == this)
  1278.             {
  1279.                 Silv.Minimap.Window.vehicleCharSprite = charSprites[i];
  1280.                 break;
  1281.             }
  1282.         }
  1283.        
  1284.         if (Silv.Minimap.Window.vehicleCharSprite === null)
  1285.         {
  1286.             console.log("ERROR: can't find vehicle sprite for:");
  1287.             console.log(this);
  1288.             throw new Error("ERROR: Couldn't find vehicle sprite.");
  1289.         }
  1290.     }
  1291. };
  1292.  
  1293. Silv.AddAlias('mm_Game_Vehicle_getOffVehicle', Game_Vehicle.prototype.getOff);
  1294. Game_Vehicle.prototype.getOff = function()
  1295. {
  1296.     Silv.Alias.mm_Game_Vehicle_getOffVehicle.apply(this, arguments);
  1297.     if (Silv.Minimap.Window) { Silv.Minimap.Window.vehicleCharSprite = null; }
  1298. };
  1299. //----------------------------------------------------------------------------------------------------
  1300. Window_Minimap.prototype.updateInput = function()
  1301. {
  1302.     if (Input.isPressed(Silv.Minimap.ManualScrollKeyUp))    { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x, Silv.Minimap.Window.mapScroll.y - Silv.Minimap.ManualScrollspeed); }
  1303.     if (Input.isPressed(Silv.Minimap.ManualScrollKeyRight)) { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x + Silv.Minimap.ManualScrollspeed, Silv.Minimap.Window.mapScroll.y); }
  1304.     if (Input.isPressed(Silv.Minimap.ManualScrollKeyDown))  { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x, Silv.Minimap.Window.mapScroll.y + Silv.Minimap.ManualScrollspeed); }
  1305.     if (Input.isPressed(Silv.Minimap.ManualScrollKeyLeft))  { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x - Silv.Minimap.ManualScrollspeed, Silv.Minimap.Window.mapScroll.y); }
  1306. };
  1307.  
  1308. Window_Minimap.prototype.teleport = function(tp_info)
  1309. {
  1310.     var direction = $gamePlayer._direction;
  1311.     if (tp_info[2] != 0) { direction = parseInt(tp_info[2]); }
  1312.  
  1313.     $gamePlayer.reserveTransfer($gameMap._mapId, tp_info[0], tp_info[1], direction, parseInt(tp_info[3]));
  1314. };
  1315.  
  1316. Window_Minimap.prototype.playerLocChanged = function()
  1317. {
  1318.     return this.lastPlayerLoc.x != $gamePlayer._realX || this.lastPlayerLoc.y != $gamePlayer._realY;
  1319. };
  1320.  
  1321. //----------------------------------------------------------------------------------------------------
  1322. // #Scroll
  1323. //----------------------------------------------------------------------------------------------------
  1324. Window_Minimap.prototype.updateMapScroll = function(force)
  1325. {
  1326.     switch (this.cameraFocusType)
  1327.     {
  1328.         case 'player':
  1329.             if (this.playerLocChanged() || force) // Only update mapscroll if the player changed location. This way manual-scrolling is made possible.
  1330.             {
  1331.                 this.isManualScrolling = false;
  1332.                 this.scrollToMapObject($gamePlayer._realX, $gamePlayer._realY);
  1333.             }
  1334.             break;
  1335.         case 'event':
  1336.             this.isManualScrolling = false;
  1337.             this.scrollToMapObject(this.cameraFocusObject._realX, this.cameraFocusObject._realY);
  1338.             break;
  1339.         case 'coordinate':
  1340.             this.isManualScrolling = false;
  1341.             this.scrollToMapObject(this.cameraFocusObject.x, this.cameraFocusObject.y);
  1342.             break;
  1343.         default:
  1344.             throw new Error('Invalid switch-value in updateMapScroll(). Value: ' + this.cameraFocusType);
  1345.     }
  1346. };
  1347.  
  1348. Window_Minimap.prototype.setCameraFollowTarget = function(followType, value)
  1349. {
  1350.     this.cameraFocusType = followType; // Must be set before calling updateMapScroll()
  1351.     switch (followType)
  1352.     {
  1353.         case 'player':
  1354.             this.cameraFocusObject = null;
  1355.             this.updateMapScroll(true); // refresh the camera to focus on the player. Because he may not be moving when this was called.
  1356.             break;
  1357.         case 'event':
  1358.             this.cameraFocusObject = $gameMap.event(parseInt(value));
  1359.             if (typeof this.cameraFocusObject === 'undefined') { throw 'setCameraFollowTarget() invalid event-id: ' + value; }
  1360.             break;
  1361.         case 'coordinate':
  1362.             if (Object.prototype.toString.call( value ) !== '[object Array]') { throw 'setCameraFollowTarget() value-param must be an array. Received type: ' + typeof value; }
  1363.             this.cameraFocusObject = { x:value[0], y:value[1] };
  1364.             break;
  1365.         default:
  1366.             throw new Error('Invalid switch-value in setCameraFollowTarget(). Value: ' + followType);
  1367.     }
  1368.    
  1369. };
  1370.  
  1371. Window_Minimap.prototype.scrollToMapObject = function(real_x, real_y)
  1372. {
  1373.     this.setMapScroll(real_x * $gameMap.tileWidth() - (this.drawAreaWidth / 2 * this.mapZoomInverse), real_y * $gameMap.tileHeight() - (this.drawAreaHeight / 2 * this.mapZoomInverse));
  1374. };
  1375.  
  1376. Window_Minimap.prototype.setMapScroll = function(scroll_x, scroll_y)
  1377. {
  1378.     var old_x = this.mapScroll.x = scroll_x;
  1379.     var source_w = this.drawAreaWidth * this.mapZoomInverse;
  1380.     this.mapScroll.x = this.clamp(this.mapScroll.x, 0, this.mapBmp.width - source_w);
  1381.     this.mapScroll.adjustment_x = old_x - this.mapScroll.x; // clamp difference
  1382.    
  1383.     var old_y = this.mapScroll.y = scroll_y;
  1384.     var source_h = this.drawAreaHeight * this.mapZoomInverse;
  1385.     this.mapScroll.y = this.clamp(this.mapScroll.y, 0, this.mapBmp.height - source_h);
  1386.     this.mapScroll.adjustment_y = old_y - this.mapScroll.y; // clamp difference
  1387. };
  1388. //----------------------------------------------------------------------------------------------------
  1389.  
  1390. Window_Minimap.prototype.manualScroll = function(scroll_x, scroll_y)
  1391. {
  1392.     this.setMapScroll(scroll_x, scroll_y);
  1393.     this.isManualScrolling = true;
  1394. };
  1395.  
  1396. // Skips frame (returns true) if frameSkipCnt > frameSkip
  1397. Window_Minimap.prototype.skipFrame = function()
  1398. {
  1399.     if (this.frameSkip === 0) { return false; } // process frame
  1400.    
  1401.     this.frameSkipCnt++;
  1402.     if (this.frameSkipCnt < this.frameSkip)
  1403.     {
  1404.         return true; // skip frame
  1405.     }
  1406.     else
  1407.     {
  1408.         this.frameSkipCnt = 0;
  1409.         return false; // process frame
  1410.     }
  1411. };
  1412.  
  1413. Window_Minimap.prototype.updatePlayerBlink = function()
  1414. {
  1415.     this.playerBlinkCnt--;
  1416.     if (this.playerBlinkCnt <= 0)      
  1417.     {  
  1418.         this.playerBlinkCnt = Silv.Minimap.PlayerBlinkDelay;
  1419.         this.playerBlink_IsVisible = !this.playerBlink_IsVisible;
  1420.     }
  1421. };
  1422.  
  1423. //----------------------------------------------------------------------------------------------------
  1424. // Window Fading
  1425. //----------------------------------------------------------------------------------------------------
  1426. Window_Minimap.prototype.updateFadeOut = function()
  1427. {
  1428.     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.
  1429.     if (this.isFadingOut) { this.fadeOut(); }
  1430. };
  1431.  
  1432. Window_Minimap.prototype.fadeOut = function()
  1433. {
  1434.     this.opacity = this.contentsOpacity -= Silv.Minimap.FadeoutSpeed;
  1435.     this.isFadedOut = (this.opacity <= 0);
  1436. };
  1437.  
  1438. Window_Minimap.prototype.resetFade = function()
  1439. {
  1440.     this.isFadingOut = false;
  1441.     this.fadeOutCnt = 0;
  1442.     this.opacity = this.contentsOpacity  = 255;
  1443.     this.isFadedOut = false;
  1444. };
  1445.  
  1446. Window_Minimap.prototype.fadeOutInstantly = function()
  1447. {
  1448.     this.opacity = this.contentsOpacity = 0;
  1449.     this.isFadedOut = true;
  1450. };
  1451.  
  1452. //----------------------------------------------------------------------------------------------------
  1453. // #Menu
  1454. //----------------------------------------------------------------------------------------------------
  1455. // This method is required for compatibility with Yanfly's Main Menu Manager.
  1456. Scene_Menu.prototype.commandSilvMap = function()
  1457. {
  1458.     Silv.Minimap.Window.pushMapScene();
  1459. };
  1460.  
  1461. Silv.AddAlias('mm_Scene_Map_callMenu', Scene_Map.prototype.callMenu);
  1462. Scene_Map.prototype.callMenu = function()
  1463. {
  1464.     if (Silv.Minimap.Menu.Enabled) { Silv.Minimap.Window.createMenuData(); }
  1465.     Silv.Alias.mm_Scene_Map_callMenu.apply(this, arguments);
  1466. };
  1467.  
  1468. Window_Minimap.prototype.createMenuData = function()
  1469. {
  1470.     this.createMenuBmp();
  1471.     this.createMenuMarkers();
  1472. };
  1473.  
  1474. Window_Minimap.prototype.pushMapScene = function()
  1475. {
  1476.     this.createMenuData();
  1477.     if (Silv.Minimap.Menu.Enabled)
  1478.     {
  1479.         if (Silv.Minimap.Menu.Bmp !== null) { SceneManager.push(Scene_MiniMap); }
  1480.         else { throw new Error('pushMapScene() was called, the minimap-menu was enabled BUT Silv.Minimap.Menu.Bmp equals null?'); }
  1481.     }
  1482.     else
  1483.     {
  1484.         throw new Error('pushMapScene() was called but the Minimap (menu) was not enabled.');
  1485.     }
  1486. };
  1487. //----------------------------------------------------------------------------------------------------
  1488. // Create #Menu Bitmap
  1489. //----------------------------------------------------------------------------------------------------
  1490. Window_Minimap.prototype.createMenuBmp = function()
  1491. {
  1492.     Silv.Minimap.Menu.Bmp = new Bitmap(this.mapBmp.width * this.menuZoom, this.mapBmp.height * this.menuZoom);
  1493.    
  1494.     this.tileInfo = {
  1495.             w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.menuZoom,
  1496.             h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.menuZoom
  1497.         };
  1498.    
  1499.     // Draw Map
  1500.     var backgroundBmp = (this.menuBG) ? this.menuBG : this.mapBmp;
  1501.     Silv.Minimap.Menu.Bmp.blt(backgroundBmp, 0, 0, backgroundBmp.width, backgroundBmp.height, 0, 0, Silv.Minimap.Menu.Bmp.width, Silv.Minimap.Menu.Bmp.height);
  1502.    
  1503.     // Draw Debug Grid
  1504.     if (Silv.Minimap.DrawDebugGrid)
  1505.     {
  1506.         for (var i=0; i < $gameMap.width(); i++)
  1507.         {
  1508.             for (var j=0; j < $gameMap.height(); j++)
  1509.             {
  1510.                 var debugTileLoc = this.translateLocationMenu(this, i, j, this.tileInfo.w * this.menuZoom, this.tileInfo.h * this.menuZoom);
  1511.                 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);
  1512.             }
  1513.         }
  1514.     }
  1515.    
  1516.     // Draw POI's
  1517.     for (var i = 0; i < this.getAllPOI().length; i++)
  1518.     {
  1519.         var poi = this.getPOIByIdx(i);
  1520.         var poiLoc = this.translateLocationMenu(this, poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  1521.         Silv.Minimap.Menu.Bmp.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
  1522.                                   poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
  1523.     }
  1524.    
  1525.     // Draw Events
  1526.     for (var i=0; i < Silv.Minimap.Events.length; i++)
  1527.     {
  1528.         var ev = Silv.Minimap.Events[i].event;
  1529.         var ev_sprite = Silv.Minimap.Events[i].sprite;
  1530.         var evMapLoc = this.translateLocationMenu(this, ev._realX, ev._realY, Silv.Minimap.Menu.EventRenderSize, Silv.Minimap.Menu.EventRenderSize);
  1531.         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);
  1532.     }
  1533.    
  1534.     // Draw Player
  1535.     if (this.playerBlipEnabled)
  1536.     {
  1537.         this.drawPlayerBlip(Silv.Minimap.Menu.Bmp, this.translateLocationMenu, this.playerInfo.src.x, this.playerInfo.src.y, this.playerInfo.src.width, this.playerInfo.src.height,
  1538.                             Silv.Minimap.Menu.PlayerIconSize, Silv.Minimap.Menu.PlayerIconSize);
  1539.     }
  1540. };
  1541. //----------------------------------------------------------------------------------------------------
  1542. // Menu Create #Markers
  1543. //----------------------------------------------------------------------------------------------------
  1544. Window_Minimap.prototype.createMenuMarkers = function()
  1545. {
  1546.     Silv.Minimap.Menu.Markers = [];
  1547.    
  1548.     // Player
  1549.     var playerMapLoc = this.translateLocationMenu(this, $gamePlayer._realX, $gamePlayer._realY, Silv.Minimap.Menu.PlayerIconSize, Silv.Minimap.Menu.PlayerIconSize);
  1550.     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});
  1551.    
  1552.     // POI's
  1553.     for (var i = 0; i < this.getAllPOI().length; i++)
  1554.     {
  1555.         var poi = this.getPOIByIdx(i);
  1556.         var poiLoc = this.translateLocationMenu(this, poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  1557.        
  1558.         var tp = poi.tp.slice(0); // slice(0) clones it
  1559.         if (this.allowTeleportation && (poi.tp !== null))
  1560.         {
  1561.             tp[0] = parseInt(tp[0]) + parseInt(poi.real_x);
  1562.             tp[1] = parseInt(tp[1]) + parseInt(poi.real_y);
  1563.         }
  1564.        
  1565.         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});
  1566.     }
  1567.    
  1568.     // Events
  1569.     for (var i=0; i < Silv.Minimap.Events.length; i++)
  1570.     {
  1571.         var ev = Silv.Minimap.Events[i].event;
  1572.         var dataMapEvent = dataMapGetEventByID(ev._eventId);
  1573.         if (dataMapEvent)
  1574.         {
  1575.             var evMapLoc = this.translateLocationMenu(this, ev._realX, ev._realY, Silv.Minimap.Menu.EventRenderSize, Silv.Minimap.Menu.EventRenderSize);
  1576.            
  1577.             var desc = '';
  1578.             if ('mm_desc' in ev) { desc = ev.mm_desc.join(' '); }
  1579.            
  1580.             var tp = null;
  1581.             if (this.allowTeleportation && ('mm_tp' in ev))
  1582.             {
  1583.                 tp = ev.mm_tp.slice(0); // slice(0) clones it
  1584.                 tp[0] = parseInt(tp[0]) + parseInt(ev._x);
  1585.                 tp[1] = parseInt(tp[1]) + parseInt(ev._y);
  1586.             }
  1587.  
  1588.             Silv.Minimap.Menu.Markers.push({ text:dataMapEvent.name, map_x:evMapLoc.x, map_y:evMapLoc.y, w:Silv.Minimap.Menu.EventRenderSize, h:Silv.Minimap.Menu.EventRenderSize, desc:desc, tp:tp });
  1589.         }
  1590.     }
  1591. };
  1592. //----------------------------------------------------------------------------------------------------
  1593. // #FoW / #Fog of War
  1594. //----------------------------------------------------------------------------------------------------
  1595. Window_Minimap.prototype.onFinishOriginalFoWBmpLoad = function()
  1596. {
  1597.     this.cloneOriginalFoWBmpToCurrent();
  1598.    
  1599.     this.fowSection_w = this.fowCurrentBmp.width;
  1600.     this.fowSection_h = this.fowCurrentBmp.height;
  1601.    
  1602.     this.finishBmpLoad();
  1603.    
  1604.     if (this.fowRequiresRefresh)
  1605.     {
  1606.         this.refreshFoWBmp();
  1607.         this.fowRequiresRefresh = false;
  1608.     }
  1609.    
  1610.     // The line below reveals the tiles around the player for when the player enters a map for the first time
  1611.     if (this.fowEnabled) { this.updateFoW(); }
  1612. };
  1613.  
  1614. // 'Clone' the original bitmap over the current one.
  1615. Window_Minimap.prototype.cloneOriginalFoWBmpToCurrent = function()
  1616. {
  1617.     this.fowCurrentBmp = new Bitmap($gameMap.width() * $gameMap.tileWidth(), $gameMap.height() * $gameMap.tileHeight());//new Bitmap(this.fowOriginalBmp.width, this.fowOriginalBmp.height);
  1618.     this.fowCurrentBmp.blt(this.fowOriginalBmp, 0, 0, this.fowOriginalBmp.width, this.fowOriginalBmp.height, 0, 0, this.fowCurrentBmp.width, this.fowCurrentBmp.height);
  1619. };
  1620.  
  1621. // Renders the current FoW bmp onto the specified bmp
  1622. // src_x and src_y are the UNSCALED x&y source-locations of the this.fowCurrentBmp.
  1623. Window_Minimap.prototype.applyFoWSection = function(toThisBmp, borderOffset_x, borderOffset_y, src_x, src_y, scale_x, scale_y, isAutoFitMode, src_w, src_h)
  1624. {
  1625.     var srcCalcBmp = isAutoFitMode ? this.fowCurrentBmp : toThisBmp;
  1626.    
  1627.     var dest_w = toThisBmp.width - borderOffset_x * 2;
  1628.     var dest_h = toThisBmp.height - borderOffset_y * 2;
  1629.    
  1630.     if (src_w === null) { src_w = srcCalcBmp.width / scale_x; }
  1631.     if (src_x + src_w > this.fowCurrentBmp.width) { src_w -= (src_x + src_w) - this.fowCurrentBmp.width; }
  1632.     if (src_h === null) { src_h = srcCalcBmp.height / scale_y; }
  1633.     if (src_y + src_h > this.fowCurrentBmp.height) { src_h -= (src_y + src_h) - this.fowCurrentBmp.height; }
  1634.    
  1635.     toThisBmp.blt(this.fowCurrentBmp, src_x, src_y, src_w, src_h, borderOffset_x, borderOffset_y, dest_w, dest_h);
  1636. };
  1637.  
  1638. // Note: does NOT reset the this.fowCurrentBmp
  1639. Window_Minimap.prototype.resetFoWData = function()
  1640. {
  1641.     Silv.Minimap.FoWData[$gameMap._mapId] = {};
  1642.    
  1643.     // Create a new 2d array: Silv.Minimap.FoWData[$gameMap._mapId].tiles[x][y]
  1644.     Silv.Minimap.FoWData[$gameMap._mapId].tiles = new Array($gameMap.width()); 
  1645.     var mapHeight = $gameMap.height();
  1646.     for (var i=0; i<Silv.Minimap.FoWData[$gameMap._mapId].tiles.length; i++) { Silv.Minimap.FoWData[$gameMap._mapId].tiles[i] = new Array(mapHeight); }
  1647.    
  1648.     // Fill the arrays with: false instead of the default undefined.
  1649.     // Note that the loop must start with x instead of y because of how the length in the 2nd loop is calculated
  1650.     for(var x=0; x<Silv.Minimap.FoWData[$gameMap._mapId].tiles.length; x++)
  1651.     {
  1652.         for(var y=0; y<Silv.Minimap.FoWData[$gameMap._mapId].tiles[x].length; y++)
  1653.         {
  1654.             Silv.Minimap.FoWData[$gameMap._mapId].tiles[x][y] = false;
  1655.         }
  1656.     }
  1657.    
  1658.     // Create the Completion Data
  1659.     this.resetFoWCompletion();
  1660. };
  1661.  
  1662. Window_Minimap.prototype.resetFoWCompletion = function()
  1663. {
  1664.     var adjust = ('mm_fow_completion' in $dataMap.meta) ? adjust = parseInt($dataMap.meta.mm_fow_completion) : 0;
  1665.    
  1666.     var totalTileCnt = $gameMap.width() * $gameMap.height() + adjust;
  1667.     Silv.Minimap.FoWData[$gameMap._mapId].completion =
  1668.     {
  1669.         totalTiles:totalTileCnt,
  1670.         emptyTileCnt:totalTileCnt,
  1671.         completedTileCnt:0,
  1672.         completePerc:0.00
  1673.     };
  1674. };
  1675.  
  1676. // Reveal tiles when the player arrived on a new tile
  1677. Silv.AddAlias('mm_Game_Player_updateMove', Game_Player.prototype.updateMove);
  1678. Game_Player.prototype.updateMove = function()
  1679. {
  1680.     Silv.Alias.mm_Game_Player_updateMove.apply(this, arguments);
  1681.     if (!this.isMoving()) { this.preUpdateFoW(); }
  1682. };
  1683.  
  1684. // Reveal tiles after a transfer
  1685. // code below wont work because the image isnt loaded at that point anyway, like ever
  1686. // Silv.AddAlias('mm_Game_Player_clearTransferInfo', Game_Player.prototype.clearTransferInfo);
  1687. // Game_Player.prototype.clearTransferInfo = function()
  1688. // {
  1689.     // Silv.Alias.mm_Game_Player_clearTransferInfo.apply(this, arguments);
  1690.     // this.preUpdateFoW();
  1691. // };
  1692.  
  1693. Game_Player.prototype.preUpdateFoW = function()
  1694. {
  1695.     if (Silv.Minimap.Window && Silv.Minimap.Window.fowEnabled) { Silv.Minimap.Window.updateFoW(); }
  1696. };
  1697.  
  1698. Window_Minimap.prototype.updateFoW = function()
  1699. {
  1700.     // Do nothing if the player has no radius and also do nothing if the bitmaps have not yet finished loading
  1701.     if ((this.fowRadius < 1) || !this.finishedBmpPreloading) { return; }
  1702.    
  1703.     //Reveal the tiles within the player's radius, if not already revealed.
  1704.     for (var delta_y = -this.fowRadius + 1; delta_y<this.fowRadius; delta_y++)
  1705.     {
  1706.         for (var delta_x = -this.fowRadius + 1; delta_x<this.fowRadius; delta_x++)
  1707.         {
  1708.             if (Math.abs(delta_x) + Math.abs(delta_y) < this.fowRadius) // this if-statement transforms the 'reveal-square' into a 45 degree rotated 'reveal-square'
  1709.             {
  1710.                 var x = this.clamp($gamePlayer._x + delta_x, 0, $gameMap.width() - 1);
  1711.                 var y = this.clamp($gamePlayer._y + delta_y, 0, $gameMap.height() - 1);
  1712.                 this.updateFoWTile(x, y, true);
  1713.             }
  1714.         }
  1715.     }
  1716. };
  1717.  
  1718. Window_Minimap.prototype.updateFoWTile = function(x, y, value)
  1719. {
  1720.     if (Silv.Minimap.FoWData[$gameMap._mapId].tiles[x][y] !== value)
  1721.     {
  1722.         Silv.Minimap.FoWData[$gameMap._mapId].tiles[x][y] = value;
  1723.         (value) ? this.fowRevealTileInBmp(x, y) : this.fowHideTileInBmp(x, y);
  1724.        
  1725.         // Modify completion data
  1726.         var completionValue = (value) ? 1 : -1;
  1727.         Silv.Minimap.FoWData[$gameMap._mapId].completion.emptyTileCnt     -= completionValue;
  1728.         Silv.Minimap.FoWData[$gameMap._mapId].completion.completedTileCnt += completionValue;
  1729.         Silv.Minimap.FoWData[$gameMap._mapId].completion.completePerc      = Math.min(1.0, Silv.Minimap.FoWData[$gameMap._mapId].completion.completedTileCnt / parseFloat(Silv.Minimap.FoWData[$gameMap._mapId].completion.totalTiles));
  1730.         if (Silv.Minimap.FoWData[$gameMap._mapId].completion.completePerc === 1.0) { this.onFullyRevealedMap(x, y); }
  1731.     }
  1732. };
  1733.  
  1734. Window_Minimap.prototype.fowRevealTileInBmp = function(x, y)
  1735. {
  1736.     var tile_w = $gameMap.tileWidth();
  1737.     var tile_h = $gameMap.tileHeight();
  1738.     this.fowCurrentBmp.clearRect(x * tile_w, y * tile_h, tile_w, tile_h);
  1739. };
  1740.  
  1741. Window_Minimap.prototype.fowHideTileInBmp = function(x, y)
  1742. {
  1743.     var tile_w = $gameMap.tileWidth();
  1744.     var tile_h = $gameMap.tileHeight();
  1745.     var dest_x = x * tile_w;
  1746.     var dest_y = y * tile_h;
  1747.     var zoom_x = this.fowOriginalBmp.width / parseFloat(this.fowCurrentBmp.width);
  1748.     var zoom_y = this.fowOriginalBmp.height / parseFloat(this.fowCurrentBmp.height);
  1749.    
  1750.     this.fowCurrentBmp.blt(this.fowOriginalBmp, dest_x * zoom_x, dest_y * zoom_y, tile_w * zoom_x, tile_h * zoom_y, dest_x, dest_y, tile_w, tile_h);
  1751. };
  1752.  
  1753. // Recalculates the entire this.fowCurrentBmp from the Silv.Minimap.FoWData
  1754. Window_Minimap.prototype.refreshFoWBmp = function()
  1755. {
  1756.     this.cloneOriginalFoWBmpToCurrent();
  1757.     for (var y=0; y<$gameMap.height(); y++)
  1758.     {
  1759.         for (var x=0; x<$gameMap.width(); x++)
  1760.         {
  1761.             if (Silv.Minimap.FoWData[$gameMap._mapId].tiles[x][y]) { this.fowRevealTileInBmp(x, y); }
  1762.         }
  1763.     }
  1764. };
  1765.  
  1766. // Reveals OR hides all the tiles between 2 tile-coordinates. Note that the tile-coordinates itself are also included.
  1767. Window_Minimap.prototype.fowChangeTilesBetweenCoords = function(x1, y1, x2, y2, value)
  1768. {
  1769.     for (var y=y1; y<=y2; y++)
  1770.     {
  1771.         for (var x=x1; x<=x2; x++)
  1772.         {
  1773.             this.updateFoWTile(x, y, value);
  1774.         }
  1775.     }
  1776. };
  1777.  
  1778. Window_Minimap.prototype.getFowCompletion = function(mapId)
  1779. {
  1780.     if (!mapId) { mapId = $gameMap._mapId; }
  1781.     if (!Silv.Minimap.FoWData[mapId]) { return 0; }
  1782.     return Silv.Minimap.FoWData[mapId].completion;
  1783. };
  1784.  
  1785. Window_Minimap.prototype.fowRevealEntireMap = function()
  1786. {
  1787.     for(var y=0; y<Silv.Minimap.FoWData[$gameMap._mapId].tiles.length; y++)
  1788.     {
  1789.         for(var x=0; x<Silv.Minimap.FoWData[$gameMap._mapId].tiles[y].length; x++)
  1790.         {
  1791.             Silv.Minimap.FoWData[$gameMap._mapId].tiles[x][y] = true;
  1792.         }
  1793.     }
  1794.    
  1795.     // Reveal Bitmap
  1796.     this.fowCurrentBmp = new Bitmap(this.fowCurrentBmp.width, this.fowCurrentBmp.height);
  1797.    
  1798.     // Modify completion data
  1799.     Silv.Minimap.FoWData[$gameMap._mapId].completion.emptyTileCnt     = 0;
  1800.     Silv.Minimap.FoWData[$gameMap._mapId].completion.completedTileCnt = Silv.Minimap.FoWData[$gameMap._mapId].completion.totalTiles;
  1801.     Silv.Minimap.FoWData[$gameMap._mapId].completion.completePerc     = 1.0;
  1802.     this.onFullyRevealedMap($gameMap.width() - 1, $gameMap.height() - 1);
  1803. };
  1804.  
  1805. Window_Minimap.prototype.fowHideEntireMap = function(revealTilesAroundPlayer)
  1806. {
  1807.     this.resetFoWData();
  1808.     this.cloneOriginalFoWBmpToCurrent();
  1809.     if (revealTilesAroundPlayer) { this.updateFoW(); }
  1810. };
  1811.  
  1812. Window_Minimap.prototype.onFullyRevealedMap = function(x, y){};
  1813.  
  1814. //----------------------------------------------------------------------------------------------------
  1815. // #Rendering #Drawing
  1816. //----------------------------------------------------------------------------------------------------
  1817. Window_Minimap.prototype.setPlayerBlip = function(filename)
  1818. {
  1819.     this.usePlayerBlipGfx = (filename == ':player');
  1820.     if (this.usePlayerBlipGfx) { this.playerBlipBmp = null; }
  1821.     else { this.playerBlipBmp = ImageManager.loadMinimap(filename); }
  1822. };
  1823.  
  1824. Window_Minimap.prototype.drawPlayerBlip = function(destBmp, translateFunc, src_x, src_y, src_w, src_h, dest_w, dest_h)
  1825. {
  1826.     var playerMapLoc = translateFunc(this, $gamePlayer._realX, $gamePlayer._realY, dest_w, dest_h);
  1827.     if (this.usePlayerBlipGfx)
  1828.     {
  1829.         destBmp.blt(this.playerInfo.bmp, src_x, src_y, src_w, src_h, playerMapLoc.x, playerMapLoc.y, dest_w, dest_h);
  1830.     }
  1831.     else
  1832.     {
  1833.         // Use custom player blip graphic
  1834.         if (this.playerBlipBmp.isReady())
  1835.         {
  1836.             destBmp.blt(this.playerBlipBmp, 0, 0, this.playerBlipBmp.width, this.playerBlipBmp.height, playerMapLoc.x, playerMapLoc.y, dest_w, dest_h);
  1837.         }
  1838.     }
  1839. };
  1840.  
  1841. Window_Minimap.prototype.drawMinimap = function()
  1842. {
  1843.     this.contents.clear();
  1844.    
  1845.     // BG fill colour, if applicable
  1846.     this.contents.fillRect(Silv.Minimap.BorderWidth, Silv.Minimap.BorderHeight, this.drawAreaWidth, this.drawAreaHeight, Silv.Minimap.MapBGFillColor);
  1847.    
  1848.     switch(this.mapStyle)
  1849.     {
  1850.         case 'autofit':
  1851.             this.drawstyleAutofit();
  1852.             break;
  1853.         case 'scroll':
  1854.             this.drawstyleScroll();
  1855.             break; 
  1856.         default:
  1857.             throw new Error('Window_Minimap.prototype.drawMinimap invalid switch value: ' + this.mapStyle);
  1858.     }
  1859. };
  1860.  
  1861. Window_Minimap.prototype.drawstyleAutofit = function()
  1862. {
  1863.     // Opacity
  1864.     this.contents.paintOpacity = this.opacity = Silv.Minimap.Window_Opacity;
  1865.    
  1866.     var destination_w = this.drawAreaWidth  * this.mapAspRatInfo.w;
  1867.     var destination_h = this.drawAreaHeight * this.mapAspRatInfo.h;
  1868.    
  1869.     // Calculate the aspect ratio offsets
  1870.     this.mapAspRatInfo.offset_x = 0.0; // to center the map
  1871.     this.mapAspRatInfo.offset_y = 0.0; // to center the map
  1872.     if (this.mapAspRatInfo.w < 1.0) { this.mapAspRatInfo.offset_x = (this.drawAreaWidth  - destination_w) / 2.0; }
  1873.     if (this.mapAspRatInfo.h < 1.0) { this.mapAspRatInfo.offset_y = (this.drawAreaHeight - destination_h) / 2.0; }
  1874.    
  1875.     // This variable saves on calculations further down the road during this update
  1876.     // w = width, hw=  half width, zhw = zoomed half width
  1877.     this.tileInfo = {
  1878.             w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.mapAspRatInfo.w,
  1879.             h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.mapAspRatInfo.h
  1880.         };
  1881.    
  1882.     // Draw Map
  1883.     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);
  1884.     if (this.fowEnabled) { this.applyFoWSection(this.contents, Silv.Minimap.BorderWidth, Silv.Minimap.BorderHeight, 0, 0, this.mapAspRatInfo.w, this.mapAspRatInfo.h, true, null, null); }
  1885.  
  1886.     // Debug Grid (if applicable)
  1887.     if (Silv.Minimap.DrawDebugGrid)
  1888.     {
  1889.         for (var i=0; i < $gameMap.width(); i++)
  1890.         {
  1891.             for (var j=0; j < $gameMap.height(); j++)
  1892.             {
  1893.                 var debugTileLoc = this.translateLocationAutofit(this, i, j, this.tileInfo.w * this.mapAspRatInfo.w, this.tileInfo.h * this.mapAspRatInfo.h);
  1894.                 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);
  1895.             }
  1896.         }
  1897.     }
  1898.    
  1899.     // Draw POI's
  1900.     for (var i = 0; i < this.getAllPOI().length; i++)
  1901.     {
  1902.         var poi = this.getPOIByIdx(i);
  1903.         var poiLoc = this.translateLocationAutofit(this, poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  1904.         this.contents.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
  1905.                           poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
  1906.     }
  1907.    
  1908.     // Draw Events
  1909.     for (var i=0; i < Silv.Minimap.Events.length; i++)
  1910.     {
  1911.         var ev = Silv.Minimap.Events[i].event;
  1912.         var ev_sprite = Silv.Minimap.Events[i].sprite;
  1913.         var evMapLoc = this.translateLocationAutofit(this, ev._realX, ev._realY, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
  1914.         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);
  1915.     }
  1916.    
  1917.     // Draw Player
  1918.     if (this.playerBlipEnabled && this.playerBlink_IsVisible)
  1919.     {
  1920.         this.drawPlayerBlip(this.contents, this.translateLocationAutofit, this.playerInfo.src.x, this.playerInfo.src.y, this.playerInfo.src.width, this.playerInfo.src.height,
  1921.                             Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
  1922.     }
  1923.    
  1924.     // Overlay (if applicable)
  1925.     if (Silv.Minimap.DrawOverlay) { this.drawOverlay(); }
  1926. };
  1927.  
  1928. Window_Minimap.prototype.drawstyleScroll = function()
  1929. {
  1930.     // Opacity
  1931.     this.contents.paintOpacity = this.opacity = Silv.Minimap.Window_Opacity;
  1932.    
  1933.     // 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
  1934.     if (this.mapScroll.x < 0 || this.drawAreaWidth  * this.mapZoomInverse > this.mapBmp.width ||
  1935.         this.mapScroll.y < 0 || this.drawAreaHeight * this.mapZoomInverse > this.mapBmp.height)
  1936.         {
  1937.             this.drawstyleAutofit();
  1938.             return;
  1939.         }
  1940.    
  1941.     // This variable saves on calculations further down the road during this update
  1942.     // w = width, hw=  half width, zhw = zoomed half width
  1943.     this.tileInfo = {
  1944.             w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.mapZoom,
  1945.             h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.mapZoom
  1946.         };
  1947.    
  1948.     // Draw Map
  1949.     // var map_src_rect = { x:0.0, y:0.0, w:0.0, h:0.0};
  1950.     // map_src_rect.x = this.mapScroll.x;
  1951.     // map_src_rect.y = this.mapScroll.y;
  1952.     // map_src_rect.w = this.drawAreaWidth * this.mapZoomInverse;
  1953.     // map_src_rect.h = this.drawAreaHeight * this.mapZoomInverse;
  1954.     // Draw Map
  1955.     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);
  1956.     if (this.fowEnabled) { this.applyFoWSection(this.contents, Silv.Minimap.BorderWidth, Silv.Minimap.BorderHeight, this.mapScroll.x - 0, this.mapScroll.y - 0, this.mapZoom, this.mapZoom, false, this.drawAreaWidth * this.mapZoomInverse, this.drawAreaHeight * this.mapZoomInverse); }
  1957.    
  1958.     // Debug Grid (if applicable)
  1959.     if (Silv.Minimap.DrawDebugGrid)
  1960.     {
  1961.         for (var i=0; i < $gameMap.width(); i++)
  1962.         {
  1963.             for (var j=0; j < $gameMap.height(); j++)
  1964.             {
  1965.                 var debugTileLoc = this.translateLocationScroll(this, i, j, this.tileInfo.w * this.mapZoom, this.tileInfo.h * this.mapZoom);
  1966.                 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);
  1967.             }
  1968.         }
  1969.     }
  1970.    
  1971.     // Draw POI's
  1972.     for (var i = 0; i < this.getAllPOI().length; i++)
  1973.     {
  1974.         var poi = this.getPOIByIdx(i);
  1975.         var poiLoc = this.translateLocationScroll(this, poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  1976.         this.contents.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
  1977.                           poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
  1978.     }
  1979.  
  1980.     // Draw Events
  1981.     for (var i=0; i < Silv.Minimap.Events.length; i++)
  1982.     {
  1983.         var ev = Silv.Minimap.Events[i].event;
  1984.         var ev_sprite = Silv.Minimap.Events[i].sprite;
  1985.         var evMapLoc = this.translateLocationScroll(this, ev._realX, ev._realY, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
  1986.         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);
  1987.     }
  1988.    
  1989.     // Draw Player
  1990.     if (this.playerBlipEnabled && this.playerBlink_IsVisible)
  1991.     {
  1992.         this.drawPlayerBlip(this.contents, this.translateLocationScroll, this.playerInfo.src.x, this.playerInfo.src.y, this.playerInfo.src.width, this.playerInfo.src.height,
  1993.                             Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
  1994.     }
  1995.    
  1996.     // Overlay (if applicable)
  1997.     if (Silv.Minimap.DrawOverlay) { this.drawOverlay(); }
  1998. };
  1999.  
  2000. Window_Minimap.prototype.drawOverlay = function()
  2001. {
  2002.     this.contents.blt(this.overlayBmp, 0, 0, this.overlayBmp.width, this.overlayBmp.height, 0, 0, this.width, this.height);
  2003. };
  2004. //----------------------------------------------------------------------------------------------------
  2005. // #Translate functions
  2006. // Important: Because the translate functions are assigned to a variable, the this-keyword will be undefined! Therefore 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.
  2007. // For more info see: http://stackoverflow.com/questions/4011793/this-is-undefined-in-javascript-class-methods
  2008. //----------------------------------------------------------------------------------------------------
  2009. // returns {x, y}
  2010. Window_Minimap.prototype.translateLocationScroll = function(that, obj_real_x, obj_real_y, obj_w, obj_h)
  2011. {
  2012.     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;
  2013.     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;
  2014.     return {x: obj_x, y: obj_y};
  2015. };
  2016.  
  2017. // returns {x, y}
  2018. Window_Minimap.prototype.translateLocationAutofit = function(that, obj_real_x, obj_real_y, obj_w, obj_h)
  2019. {
  2020.     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;
  2021.     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;
  2022.     return {x: obj_x, y: obj_y};
  2023. };
  2024.  
  2025. // returns {x, y}
  2026. Window_Minimap.prototype.translateLocationMenu = function(that, obj_real_x, obj_real_y, obj_w, obj_h)
  2027. {
  2028.     var obj_x = (obj_real_x * that.tileInfo.w + that.tileInfo.hw) * that.menuZoom - obj_w / 2.0;
  2029.     var obj_y = (obj_real_y * that.tileInfo.h + that.tileInfo.hh) * that.menuZoom - obj_h / 2.0;
  2030.     return {x: obj_x, y: obj_y};
  2031. };
  2032. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2033. // #POI
  2034. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2035. function MM_POI() { this.initialize.apply(this, arguments); }
  2036. // Set Constructor
  2037. MM_POI.prototype.constructor = MM_POI;
  2038.  
  2039. // Initialization
  2040. // real_x & real_y are in tiles
  2041. 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)
  2042. {
  2043.   this.id = poi_id;
  2044.   this.name = name;
  2045.   this.desc = desc;
  2046.   this.real_x = real_x;
  2047.   this.real_y = real_y;
  2048.   this.folderPath = folderPath; // Required for saving&loading
  2049.   this.filename = filename; // Required for saving&loading
  2050.   this.bmp = ImageManager.loadBitmap(folderPath, filename, 0, false);
  2051.   this.src = { x:source_x, y:source_y, w:source_w, h:source_h };
  2052.   this.destSize = { w:draw_w, h:draw_h };
  2053.   this.tp = null;
  2054. };
  2055.  
  2056. // Note: Does not include the Bitmap
  2057. MM_POI.prototype.makeSaveContents = function()
  2058. {
  2059.     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 };
  2060. };
  2061.  
  2062. // Retrieves all the POI's for the current active $gameMap
  2063. Window_Minimap.prototype.getAllPOI = function()
  2064. {
  2065.     return Silv.Minimap.POI[$gameMap._mapId];
  2066. };
  2067.  
  2068. // Retrieves the specified POI by index for the current active $gameMap. Note this is NOT by POI id, this is by index.
  2069. Window_Minimap.prototype.getPOIByIdx = function(index)
  2070. {
  2071.     return Silv.Minimap.POI[$gameMap._mapId][index];
  2072. };
  2073.  
  2074. Window_Minimap.prototype.getPOIByID = function(id)
  2075. {
  2076.     for (var i=0; i<Silv.Minimap.POI[$gameMap._mapId].length; i++)
  2077.     {
  2078.         if (Silv.Minimap.POI[$gameMap._mapId][i].id == id) { return Silv.Minimap.POI[$gameMap._mapId][i]; }
  2079.     }
  2080.     throw new Error('getPOIByID(' + id + ') not found.');
  2081. };
  2082. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2083. // #Create the Minimap window
  2084. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2085. //----------------------------------------------------------------------------------------------------
  2086. // Scene Map (alias): Create Display Objects
  2087. //----------------------------------------------------------------------------------------------------
  2088. Silv.AddAlias('mm_Scene_Map_createDisplayObjects', Scene_Map.prototype.createDisplayObjects);
  2089. Scene_Map.prototype.createDisplayObjects = function()
  2090. {
  2091.     Silv.Alias.mm_Scene_Map_createDisplayObjects.apply(this, arguments);
  2092.     Silv.Minimap.setup();
  2093. };
  2094. //----------------------------------------------------------------------------------------------------
  2095. // Setup Minimap
  2096. // Call this method to create or re-create the minimap, if required. It does only create a minimap
  2097. // if it passes all the checks.
  2098. // Example: Silv.Minimap.setup();
  2099. //----------------------------------------------------------------------------------------------------
  2100. Silv.Minimap.setup = function()
  2101. {
  2102.     var didMapChange = $gameMap._mapId != this.LastMapID;
  2103.     if (didMapChange)
  2104.     {
  2105.         if (this.WasLoadedFromSave)
  2106.         {
  2107.             this.WasLoadedFromSave = false;
  2108.         }
  2109.         else
  2110.         {
  2111.             if (this.AutoClearPOI) { this.POI[$gameMap._mapId] = []; }
  2112.         }
  2113.     }
  2114.    
  2115.     // Create empty POI array if it's not defined yet for this map
  2116.     if (typeof this.POI[$gameMap._mapId] === 'undefined') { this.POI[$gameMap._mapId] = []; }
  2117.  
  2118.     SceneManager._scene.attemptToCreateMinimap();
  2119.     this.LastMapID = $gameMap._mapId;
  2120. };
  2121. //----------------------------------------------------------------------------------------------------
  2122. // Attempt To Create Minimap
  2123. //----------------------------------------------------------------------------------------------------
  2124. Scene_Map.prototype.attemptToCreateMinimap = function()
  2125. {
  2126.     var mapName = lpad_mapname($gameMap._mapId, '0') + '.png';
  2127.     if ('mm_mapshot' in $dataMap.meta)
  2128.     {
  2129.         if (Silv.Minimap.DebugMode) { console.log('A mapshot-notetag was found:' + $dataMap.meta.mm_mapshot + '.'); }
  2130.         mapName = lpad_mapname($dataMap.meta.mm_mapshot, '0') + '.png';
  2131.     }
  2132.    
  2133.     var createMinimap = false;
  2134.     var minimapType = null;
  2135.     var hasRequiredItems = this.MinimapHasRequiredItems();
  2136.    
  2137.     if (Silv.Minimap.Window !== null)
  2138.     {
  2139.         // #Dispose
  2140.         // 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.
  2141.         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...
  2142.         Silv.Minimap.Window = null;
  2143.         Silv.Minimap.Menu.Enabled = false;
  2144.         Silv.Minimap.Menu.Bmp = null;
  2145.         Silv.Minimap.Menu.Markers = [];
  2146.     }
  2147.    
  2148.     var windowWasVisible = Silv.Minimap.Visible;
  2149.     if (minimapImageExists(mapName))
  2150.     {
  2151.         if (hasRequiredItems)
  2152.         {
  2153.             createMinimap = true;
  2154.             minimapType = 'regular';
  2155.         }
  2156.     }
  2157.     else
  2158.     {
  2159.         if (Silv.Minimap.DebugMode) { console.log('No minimap \'' + mapName + '\' found for map with map-id: ' + $gameMap._mapId + '.'); }
  2160.        
  2161.         if (hasRequiredItems)
  2162.         {
  2163.             if (('mm_generate_worldmap' in $dataMap.meta) || ('mm_generate_overworld' in $dataMap.meta))
  2164.             {
  2165.                 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.'); }
  2166.                 createMinimap = true;
  2167.                 minimapType = 'generate_overworld';
  2168.             } else if ('mm_generate_map' in $dataMap.meta)
  2169.             {
  2170.                 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.'); }
  2171.                 createMinimap = true;
  2172.                 minimapType = 'generate_map';
  2173.             }
  2174.         }
  2175.     }
  2176.    
  2177.     if (createMinimap)
  2178.     {
  2179.         this.createMinimapWindow(mapName.replace('.png', ''), minimapType);
  2180.         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.
  2181.         if ('mm_generate_passability_overlay' in $dataMap.meta) { Silv.Minimap.Window.setPassabilityOverlay(true); }
  2182.     }
  2183.     // else
  2184.     // {
  2185.         //'Dispose'
  2186.         //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.
  2187.         // Silv.Minimap.Window = null;
  2188.     // }
  2189. };
  2190. //----------------------------------------------------------------------------------------------------
  2191. // Scene_Base: Remove Window
  2192. //----------------------------------------------------------------------------------------------------
  2193. // Omg why does RPG Maker not have this method by default...
  2194. Scene_Base.prototype.removeWindow = function(window)
  2195. {
  2196.     var index = this.children.indexOf(window);
  2197.     if (index > -1) { this.children.splice(index, 1); }
  2198. };
  2199. //----------------------------------------------------------------------------------------------------
  2200. // Create Minimap Window
  2201. //----------------------------------------------------------------------------------------------------
  2202. Scene_Map.prototype.createMinimapWindow = function(mapname, minimapType)
  2203. {
  2204.     var x = 0;
  2205.     if (Silv.Minimap.WindowHorizontalAlignment == 'right') { x = Graphics.width - Silv.Minimap.WindowWidth; }
  2206.     var y = 0;
  2207.     if (Silv.Minimap.WindowVerticalAlignment == 'bottom') { y = Graphics.height - Silv.Minimap.WindowHeight; }
  2208.    
  2209.     Silv.Minimap.Window = new Window_Minimap(x + Silv.Minimap.Window_X, y + Silv.Minimap.Window_Y, Silv.Minimap.WindowWidth, Silv.Minimap.WindowHeight, mapname, minimapType);
  2210.     Silv.Minimap.Window.resetFade();
  2211.    
  2212.     // override frameskip (map-specific frameskip)
  2213.     if ('mm_frameskip' in $dataMap.meta)
  2214.     {
  2215.         Silv.Minimap.Window.frameSkip = parseInt($dataMap.meta.mm_frameskip);
  2216.         if (Silv.Minimap.DebugMode) { console.log('Global frameskip: ' + Silv.Minimap.FrameSkip + ' was overriden by the map-specific frameskip of: ' + $dataMap.meta.mm_frameskip + '.'); }
  2217.     }
  2218.    
  2219.     this.addChildAt(Silv.Minimap.Window, 1);
  2220. };
  2221. //----------------------------------------------------------------------------------------------------
  2222. // Has Required Items
  2223. //----------------------------------------------------------------------------------------------------
  2224. Scene_Map.prototype.MinimapHasRequiredItems = function()
  2225. {
  2226.     // Check global item
  2227.     if (Silv.Minimap.GlobalRequiredItem > 0)
  2228.     {
  2229.         if (!$gameParty.hasItem($dataItems[Silv.Minimap.GlobalRequiredItem], false))
  2230.         {
  2231.             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); }
  2232.             return false;
  2233.         }
  2234.     }
  2235.    
  2236.     // Check map-specific items
  2237.     if ('mm_req_itm' in $dataMap.meta)
  2238.     {
  2239.         var req_item_ids = $dataMap.meta.mm_req_itm.split(' ').filter(Boolean); // .filter(Boolean) removes empty strings from array
  2240.         for (var i = 0; i < req_item_ids.length; i++)
  2241.         {
  2242.             if (!$gameParty.hasItem($dataItems[req_item_ids[i]], false))
  2243.             {
  2244.                 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); }
  2245.                 return false;
  2246.             }
  2247.         }
  2248.     }
  2249.    
  2250.     return true;
  2251. };
  2252. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2253. // Show Map upon gaining the required item
  2254. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2255. Silv.AddAlias('mm_Game_Interpreter_command126', Game_Interpreter.prototype.command126);
  2256. Game_Interpreter.prototype.command126 = function()
  2257. {
  2258.     var retVal = Silv.Alias.mm_Game_Interpreter_command126.apply(this, arguments);
  2259.    
  2260.     if ((Silv.Minimap.Window === null) && SceneManager._scene.MinimapHasRequiredItems())
  2261.     {
  2262.         SceneManager._scene.attemptToCreateMinimap(false);
  2263.     }
  2264.    
  2265.     return retVal;
  2266. };
  2267.  
  2268. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2269. // Saving & Loading #Save #Saving #Loading
  2270. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2271. Silv.AddAlias('mm_DataManager_makeSaveContents', DataManager.makeSaveContents);
  2272. DataManager.makeSaveContents = function()
  2273. {
  2274.     contents = Silv.Alias.mm_DataManager_makeSaveContents.apply(this, arguments);
  2275.    
  2276.     contents.minimap = {};
  2277.     contents.minimap.poi = {};
  2278.    
  2279.     // POI
  2280.     for (var mapID in Silv.Minimap.POI)
  2281.     {
  2282.         if (Silv.Minimap.POI.hasOwnProperty(mapID))
  2283.         {
  2284.             if(Silv.Minimap.POI[mapID].length > 0) { contents.minimap.poi[mapID] = []; }
  2285.             for(var poi_idx=0; poi_idx<Silv.Minimap.POI[mapID].length; poi_idx++)
  2286.             {
  2287.                 contents.minimap.poi[mapID].push(Silv.Minimap.Window.getPOIByIdx(poi_idx).makeSaveContents());
  2288.             }
  2289.         }
  2290.     }
  2291.    
  2292.     // FoW
  2293.     contents.minimap.fowData = Silv.Minimap.FoWData;
  2294.    
  2295.     return contents;
  2296. };
  2297.  
  2298. Silv.AddAlias('mm_DataManager_extractSaveContents', DataManager.extractSaveContents);
  2299. DataManager.extractSaveContents = function(contents)
  2300. {
  2301.     Silv.Alias.mm_DataManager_extractSaveContents.apply(this, arguments);
  2302.  
  2303.     // POI
  2304.     Silv.Minimap.POI = {};
  2305.     for (var mapID in contents.minimap.poi)
  2306.     {
  2307.         if (contents.minimap.poi.hasOwnProperty(mapID))
  2308.         {
  2309.             if(contents.minimap.poi[mapID].length > 0) { Silv.Minimap.POI[mapID] = []; }
  2310.             for(var poi_idx=0; poi_idx<contents.minimap.poi[mapID].length; poi_idx++)
  2311.             {
  2312.                 var poi = contents.minimap.poi[mapID][poi_idx];
  2313.                 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);
  2314.                 newPOI.tp = poi.tp;
  2315.                 Silv.Minimap.POI[mapID].push(newPOI);
  2316.             }
  2317.         }
  2318.     }
  2319.    
  2320.     // FoW
  2321.     Silv.Minimap.FoWData = contents.minimap.fowData;
  2322.    
  2323.     // Prevent the minimap from autoclearing it's POI's (if AutoClearPOI is enabled) when loading a savegame
  2324.     Silv.Minimap.WasLoadedFromSave = true;
  2325. };
  2326. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2327. // #Plugin Command
  2328. // Note: The items are separated by spaces. The command is the first word and any following words are args. args is an array.
  2329. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2330. Silv.AddAlias('mm_Game_Interpreter_pluginCommand', Game_Interpreter.prototype.pluginCommand);
  2331. Game_Interpreter.prototype.pluginCommand = function(command, args)
  2332. {
  2333.     Silv.Alias.mm_Game_Interpreter_pluginCommand.apply(this, arguments);
  2334.     if (command.toLowerCase() == 'minimap') { PluginCommand(command, args); }
  2335. };
  2336.  
  2337. function PluginCommand(cmd, args)
  2338. {
  2339.     var arg0 = args[0].toLowerCase();
  2340.     if ((Silv.Minimap.Window === null) && (arg0 !== 'refresh')) { throw new Error('Minimap Plugin Commands can not be used when there is no active minimap. Either create one from a mapshot or generate one automatically'); }
  2341.    
  2342.     switch(arg0)
  2343.     {
  2344.         case 'hide':
  2345.             Silv.Minimap.Window.hide();
  2346.             break;
  2347.         case 'show':
  2348.             Silv.Minimap.Window.show();
  2349.             break;
  2350.         case 'fadeout':
  2351.             Silv.Minimap.Window.isFadingOut = true;
  2352.             break;
  2353.         case 'fadereset':
  2354.             Silv.Minimap.Window.resetFade();
  2355.             break;
  2356.         case 'refresh':
  2357.             SceneManager._scene.attemptToCreateMinimap(false);
  2358.             break;
  2359.         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
  2360.             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])));
  2361.             SceneManager._scene.attemptToCreateMinimap(false);
  2362.             break;
  2363.         case 'deletepoi':
  2364.             Silv.Minimap.POI[$gameMap._mapId] = Silv.Minimap.POI[$gameMap._mapId].filter(function(poi) { return poi.id != args[1]; });
  2365.             break;
  2366.         case 'poidesc':
  2367.               Silv.Minimap.Window.getPOIByID(parseInt(args[1])).desc = args.join(' ').substr(2 + args[0].length + args[1].length);
  2368.             break;
  2369.         case 'poi_tp': // POI_TP <poi_id x_offset, y_offset, direction, fadeType>
  2370.             Silv.Minimap.Window.getPOIByID(parseInt(args[1])).tp = [parseInt(args[2]), parseInt(args[3]), parseInt(args[4]), parseInt(args[5])];
  2371.             break;
  2372.         case 'refreshevents':
  2373.             Silv.Minimap.Window.loadEvents();
  2374.             break;
  2375.         case 'increasescroll':
  2376.             Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x + parseFloat(args[1]), Silv.Minimap.Window.mapScroll.y + parseFloat(args[2]));
  2377.             break;
  2378.         case 'setscroll':
  2379.             Silv.Minimap.Window.manualScroll(parseFloat(args[1]), parseFloat(args[2]));
  2380.             break;
  2381.         case 'generate_passability_overlay':
  2382.         case 'gen_pass_ov':
  2383.             Silv.Minimap.setPassabilityOverlay(args[1].toLowerCase() == 'true');
  2384.             break;
  2385.         case 'showmapmenu':
  2386.             Silv.Minimap.Window.showMapMenuScene();
  2387.             break;
  2388.         case 'setplayerblip':
  2389.             Silv.Minimap.Window.setPlayerBlip(args[1]);
  2390.             break;
  2391.         case 'setmapstyle':
  2392.             Silv.Minimap.Window.mapStyle = args[1].toLowerCase();
  2393.             break;
  2394.         case 'setfollowtarget':
  2395.         case 'setcamera':
  2396.             var followType = args[1].toLowerCase();
  2397.             if (followType == 'coordinate')
  2398.             {
  2399.                 Silv.Minimap.Window.setCameraFollowTarget(followType, [parseInt(args[2]), parseInt(args[3])]);
  2400.             }
  2401.             else
  2402.             {
  2403.                 Silv.Minimap.Window.setCameraFollowTarget(followType, args[2]);
  2404.             }
  2405.             break;
  2406.         case 'fowshowtile':
  2407.             if (Silv.Minimap.Window && Silv.Minimap.Window.fowEnabled) { Silv.Minimap.Window.updateFoWTile(parseInt(args[1]), parseInt(args[2]), true); }
  2408.             break;
  2409.         case 'fowhidetile':
  2410.             if (Silv.Minimap.Window && Silv.Minimap.Window.fowEnabled) { Silv.Minimap.Window.updateFoWTile(parseInt(args[1]), parseInt(args[2]), false); }
  2411.             break;
  2412.         case 'fowrevealtiles':
  2413.             if (Silv.Minimap.Window && Silv.Minimap.Window.fowEnabled) { Silv.Minimap.Window.fowChangeTilesBetweenCoords(parseInt(args[1]), parseInt(args[2]), parseInt(args[3]), parseInt(args[4]), true); }
  2414.             break;
  2415.         case 'fowhidetiles':
  2416.             if (Silv.Minimap.Window && Silv.Minimap.Window.fowEnabled) { Silv.Minimap.Window.fowChangeTilesBetweenCoords(parseInt(args[1]), parseInt(args[2]), parseInt(args[3]), parseInt(args[4]), false); }
  2417.             break;
  2418.         case 'fowchangetiles':
  2419.             if (Silv.Minimap.Window && Silv.Minimap.Window.fowEnabled) { Silv.Minimap.Window.fowChangeTilesBetweenCoords(parseInt(args[1]), parseInt(args[2]), parseInt(args[3]), parseInt(args[4]), (args[5].toLowerCase() === 'true')); }
  2420.             break;
  2421.         case 'fowrevealall':
  2422.             if (Silv.Minimap.Window && Silv.Minimap.Window.fowEnabled) { Silv.Minimap.Window.fowRevealEntireMap(); }
  2423.             break;
  2424.         case 'fowreset':
  2425.         case 'fowhideall':
  2426.             var showTilesAroundPlayer = (typeof args[1] === 'undefined') ? true : (args[1].toLowerCase() === 'true');
  2427.             if (Silv.Minimap.Window && Silv.Minimap.Window.fowEnabled) { Silv.Minimap.Window.fowHideEntireMap(showTilesAroundPlayer); }
  2428.             break;
  2429.         default:
  2430.             throw new Error('Minimap, unknown Plugin Command: ' + args[0]);
  2431.     }
  2432. }
  2433. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2434. })();
  2435. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2436. // Map Menu #Scene
  2437. // Note: Must be placed outside of the })();
  2438. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2439. function Scene_MiniMap() { this.initialize.apply(this, arguments); }
  2440.  
  2441. Scene_MiniMap.prototype = Object.create(Scene_MenuBase.prototype);
  2442. Scene_MiniMap.prototype.constructor = Scene_MiniMap;
  2443.  
  2444. Scene_MiniMap.prototype.initialize = function()
  2445. {
  2446.     Scene_MenuBase.prototype.initialize.call(this);
  2447.     SoundManager.playOk();
  2448. };
  2449.  
  2450. Scene_MiniMap.prototype.create = function()
  2451. {
  2452.     Scene_MenuBase.prototype.create.call(this);
  2453.     this.createLeftWindow();
  2454.     this.createMapSectionWindow();
  2455.     this.createMapHelpWindow();
  2456.     this.refreshHelpWindow();
  2457. };
  2458.  
  2459. Scene_MiniMap.prototype.createLeftWindow = function()
  2460. {
  2461.     this._window_left = new Window_MinimapMenuLeft(0, 0);
  2462.     this._window_left.setHandler('ok',     this.onRangeOk.bind(this));
  2463.     this._window_left.setHandler('cancel', this.popScene.bind(this));
  2464.     this._window_left.setHandler('index_changed', this.index_changed.bind(this));
  2465.     this.addWindow(this._window_left);
  2466. };
  2467.  
  2468. Scene_MiniMap.prototype.createMapSectionWindow = function()
  2469. {
  2470.     var wx = this._window_left.width;
  2471.     var ww = Graphics.boxWidth - wx;
  2472.     this._mapSectionWindow = new Window_MapSection(wx, 0, ww);
  2473.     this._mapSectionWindow.setHandler('cancel', this.onEditCancel.bind(this));
  2474.     this._window_left.setMapWindow(this._mapSectionWindow);
  2475.     this.addWindow(this._mapSectionWindow);
  2476. };
  2477.  
  2478. Scene_MiniMap.prototype.createMapHelpWindow = function()
  2479. {
  2480.     var wx = this._mapSectionWindow.x;
  2481.     var wy = this._mapSectionWindow.height;
  2482.     var ww = this._mapSectionWindow.width;
  2483.     var wh = Graphics.boxHeight - wy;
  2484.     this._mapHelpWindow = new Window_Base(wx, wy, ww, wh);
  2485.     this.addWindow(this._mapHelpWindow);
  2486. };
  2487.  
  2488. Scene_MiniMap.prototype.index_changed = function()
  2489. {
  2490.     this.refreshHelpWindow();
  2491. };
  2492.  
  2493. Scene_MiniMap.prototype.onRangeOk = function()
  2494. {
  2495.     this._mapSectionWindow.activate();
  2496.     this._mapSectionWindow.select(0);
  2497.     this.refreshHelpWindow();
  2498. };
  2499.  
  2500. Scene_MiniMap.prototype.onEditCancel = function()
  2501. {
  2502.     this._window_left.activate();
  2503.     this._mapSectionWindow.deselect();
  2504.     this.refreshHelpWindow();
  2505. };
  2506.  
  2507. Scene_MiniMap.prototype.refreshHelpWindow = function()
  2508. {
  2509.     this._mapHelpWindow.contents.clear();
  2510.     this._mapHelpWindow.drawTextEx(this.helpText(), 4, 0);
  2511. };
  2512.  
  2513. Scene_MiniMap.prototype.helpText = function()
  2514. {
  2515.     var marker = this._window_left.marker();
  2516.     var tp_text = '';
  2517.     if (marker.tp !== null) { tp_text = '\nTeleports you to: ' + marker.tp[0] + ',' + marker.tp[1]; }
  2518.     return this._window_left.marker().desc + tp_text;
  2519. };
  2520. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2521. // Left Window #leftwindow
  2522. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2523. function Window_MinimapMenuLeft() { this.initialize.apply(this, arguments); }
  2524.  
  2525. Window_MinimapMenuLeft.prototype = Object.create(Window_Selectable.prototype);
  2526. Window_MinimapMenuLeft.prototype.constructor = Window_MinimapMenuLeft;
  2527.  
  2528. Window_MinimapMenuLeft.lastTopRow = 0;
  2529. Window_MinimapMenuLeft.lastIndex  = 0;
  2530.  
  2531. Window_MinimapMenuLeft.prototype.initialize = function(x, y)
  2532. {
  2533.     var width = this.windowWidth();
  2534.     var height = this.windowHeight();
  2535.     Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  2536.     this.refresh();
  2537.     this.setTopRow(Window_MinimapMenuLeft.lastTopRow);
  2538.     this.select(Window_MinimapMenuLeft.lastIndex);
  2539.     this.activate();
  2540. };
  2541.  
  2542. Window_MinimapMenuLeft.prototype.windowWidth = function()
  2543. {
  2544.     return Silv.Minimap.Menu.WindowWidth_Left;
  2545. };
  2546.  
  2547. Window_MinimapMenuLeft.prototype.windowHeight = function()
  2548. {
  2549.     return Graphics.boxHeight;
  2550. };
  2551.  
  2552. Window_MinimapMenuLeft.prototype.maxItems = function()
  2553. {
  2554.     return Silv.Minimap.Menu.Markers.length;
  2555. };
  2556.  
  2557. Window_MinimapMenuLeft.prototype.update = function()
  2558. {
  2559.     Window_Selectable.prototype.update.call(this);
  2560.     if (this._mapWindow) { this._mapWindow.setMarker(this.marker()); }
  2561.     if (this.index() != Window_MinimapMenuLeft.lastIndex)
  2562.     {
  2563.         Window_MinimapMenuLeft.lastIndex = this.index();
  2564.         this.callHandler('index_changed');
  2565.     }
  2566.    
  2567.     if (Input.isTriggered('ok'))
  2568.     {
  2569.         var marker = this.marker();
  2570.         if(marker.tp !== null)
  2571.         {
  2572.             // Add the teleport location to the minimap and dequeue this scene to return to the previous scene
  2573.             SoundManager.playOk();
  2574.             Silv.Minimap.TP_Dest = marker.tp;
  2575.             SceneManager.pop();
  2576.         }
  2577.     }
  2578.    
  2579.     if (Input.isTriggered(Silv.Minimap.Menu.MenuKey))
  2580.     {
  2581.         SoundManager.playCancel();
  2582.         SceneManager.pop();
  2583.     }
  2584. };
  2585.  
  2586. Window_MinimapMenuLeft.prototype.marker = function()
  2587. {
  2588.     return Silv.Minimap.Menu.Markers[this.index()];
  2589. };
  2590.  
  2591. Window_MinimapMenuLeft.prototype.refresh = function()
  2592. {
  2593.     this.createContents();
  2594.     this.drawAllItems();
  2595. };
  2596.  
  2597. Window_MinimapMenuLeft.prototype.drawItem = function(index)
  2598. {
  2599.     var rect = this.itemRectForText(index);
  2600.     var text = Silv.Minimap.Menu.Markers[index].text;
  2601.     this.drawText(text, rect.x, rect.y, rect.width);
  2602. };
  2603.  
  2604. Window_MinimapMenuLeft.prototype.isCancelTriggered = function()
  2605. {
  2606.     return (Window_Selectable.prototype.isCancelTriggered());
  2607. };
  2608.  
  2609. Window_MinimapMenuLeft.prototype.processCancel = function()
  2610. {
  2611.     Window_Selectable.prototype.processCancel.call(this);
  2612.     Window_MinimapMenuLeft.lastTopRow = this.topRow();
  2613.     Window_MinimapMenuLeft.lastIndex = this.index();
  2614. };
  2615.  
  2616. Window_MinimapMenuLeft.prototype.setMapWindow = function(mapWindow)
  2617. {
  2618.     this._mapWindow = mapWindow;
  2619.     this.update();
  2620. };
  2621. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2622. // Map Section Window
  2623. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2624. function Window_MapSection() { this.initialize.apply(this, arguments); }
  2625.  
  2626. Window_MapSection.prototype = Object.create(Window_Selectable.prototype);
  2627. Window_MapSection.prototype.constructor = Window_MapSection;
  2628.  
  2629. Window_MapSection.prototype.initialize = function(x, y, width)
  2630. {
  2631.     var height = Silv.Minimap.Menu.WindowHeight_MapSection;
  2632.     Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  2633.     this._marker = 1;
  2634.     this.mapScroll = {x:0, y:0};
  2635.     this.mapZoom = 1.0;
  2636.     this.centerLoc = {x:width / 2.0, y: height / 2.0};
  2637.     this.refresh();
  2638. };
  2639.  
  2640. // Hide the cursor
  2641. Window_MapSection.prototype.updateCursor = function()
  2642. {
  2643.     this.setCursorRect(0, 0, 0, 0);
  2644. };
  2645.  
  2646. Window_MapSection.prototype.maxItems = function() { return 0; };
  2647.  
  2648. Window_MapSection.prototype.refresh = function()
  2649. {
  2650.     this.contents.clear();
  2651.     this.drawMap();
  2652. };
  2653.  
  2654. // Prevent anything from being drawn in the base-class
  2655. Window_MapSection.prototype.drawAllItems = function(){};
  2656.  
  2657. Window_MapSection.prototype.drawMap = function()
  2658. {
  2659.     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);
  2660. };
  2661.  
  2662. Window_MapSection.prototype.centerOnMarker = function(marker)
  2663. {
  2664.     this.mapScroll.x = this.centerLoc.x - marker.map_x - marker.w / 2.0;
  2665.     this.mapScroll.y = this.centerLoc.y - marker.map_y - marker.h / 2.0;
  2666.     this.refresh();
  2667. };
  2668.  
  2669. Window_MapSection.prototype.setMarker = function(marker)
  2670. {
  2671.     if (this._marker !== marker)
  2672.     {
  2673.         this._marker = marker;
  2674.         this.centerOnMarker(marker);
  2675.     }
  2676. };
  2677.  
  2678. Window_MapSection.prototype.update = function()
  2679. {
  2680.     Window_Selectable.prototype.update.call(this);
  2681.     if (this.active) {
  2682.         if (Input.isPressed('up')) { this.mapScroll.y += 10; this.refresh(); }
  2683.         if (Input.isPressed('right')) { this.mapScroll.x -= 10; this.refresh(); }
  2684.         if (Input.isPressed('down')) { this.mapScroll.y -= 10; this.refresh(); }
  2685.         if (Input.isPressed('left')) { this.mapScroll.x += 10; this.refresh(); }
  2686.         if (Input.isPressed(Silv.Minimap.Menu.ManualScrollKey_Reset)) { this.mapScroll.x = 0; this.mapScroll.y = 0; this.refresh(); }
  2687.        
  2688.         if (Input.isPressed(Silv.Minimap.Menu.ManualZoomKey_In))
  2689.         {
  2690.             this.mapZoom += 0.05;
  2691.             if (this.mapZoom > Silv.Minimap.Menu.ManualZoom_Max) { this.mapZoom = Silv.Minimap.Menu.ManualZoom_Max; }
  2692.             this.refresh();
  2693.         }
  2694.         if (Input.isPressed(Silv.Minimap.Menu.ManualZoomKey_Out))
  2695.         {
  2696.             this.mapZoom -= 0.05;
  2697.             if (this.mapZoom < Silv.Minimap.Menu.ManualZoom_Min) { this.mapZoom = Silv.Minimap.Menu.ManualZoom_Min; }
  2698.             this.refresh();
  2699.         }
  2700.         if  (Input.isPressed(Silv.Minimap.Menu.ManualZoomKey_Reset)) { this.mapZoom = 1.0; this.refresh(); }
  2701.     }
  2702. };
  2703. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2704. // This is the end of this awesome script! Why did you even read this line ;)
  2705. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement