Advertisement
Guest User

Minimap

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