Guest User

Minimap

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