Advertisement
Guest User

Minimap

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