Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // SilvMinimap.js
- // Version: 0.91
- //=============================================================================
- /*:
- * @plugindesc v0.91 Minimap. <SilvMinimap>
- * @author Silver
- *
- * @param Map Style
- * @desc Is the minimap scaled to fit? Or does it zoom and scroll? Autofit/Scroll
- * @default Scroll
- *
- * @param Global Map Zoom
- * @desc Only applies if MapStyle is set to: Scroll. Determines the default zoom level for all maps. A value of 1 means 1:1.
- * @default 0.25
- *
- * @param -- Positioning & Size --
- *
- * @param X
- * @desc x-location of minimap window. If window-alignment is set to Right, this will act as an offset value instead
- * @default -2
- *
- * @param Y
- * @desc y-location of minimap window. If window-alignment is set to Top, this will act as an offset value instead
- * @default 2
- *
- * @param Horizontal Alignment
- * @desc Left/Right
- * @default Right
- *
- * @param Vertical Alignment
- * @desc Top/Bottom
- * @default Bottom
- *
- * @param Width
- * @desc width of the minimap
- * @default 320
- *
- * @param Height
- * @desc height of the minimap
- * @default 320
- *
- * @param Border Width
- * @desc Border width of the minimap
- * @default 12
- *
- * @param Border Height
- * @desc Border height of the minimap
- * @default 12
- *
- * @param -- The rest --
- *
- * @param Standard Padding
- * @desc Standard Window Padding. Best to leave at 0.
- * @default 0
- *
- * @param Window Skin
- * @desc Name of the window skin to use for this window
- * @default Window_Minimap
- *
- * @param Player Icon Width
- * @desc Standard Window Padding
- * @default 16
- *
- * @param Player Icon Height
- * @desc Standard Window Padding
- * @default 16
- *
- * @param Draw Player Icon
- * @desc Draw player on the map? true/false
- * @default true
- *
- * @param Player Blink Delay
- * @desc Blinks the player icon (in frames). Set to 0 to disable. Does nothing if "Draw Player Icon" is set to false
- * @default 0
- *
- * @param Fill Color
- * @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.
- * @default 0 0 0 255
- *
- * @param Maintain Aspect Ratio
- * @desc Maintains minimap aspect ratio if set to true. true/false
- * @default true
- *
- * @param Fadeout Speed
- * @desc How fast the minimap fades out
- * @default 3
- *
- * @param Global Required Item
- * @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
- * @default 0
- *
- * @param Event Render Size
- * @desc How big the events are that are drawn onto the minimap
- * @default 16
- *
- * @param Auto Clear POI
- * @desc Automatically clear POI's between map transfers? true/false
- * @default true
- *
- * @param Render Minimap Overlay
- * @desc If enabled, add the image: /img/Minimap/Overlay.png and it will be drawn on top of the minimap. true/false
- * @default true
- *
- * @param -- Manual Scrolling --
- *
- * @param Allow Manual Scrolling
- * @desc true/false
- * @default true
- *
- * @param Manual Scrollspeed
- * @desc How fast the map is scrolled
- * @default 24
- *
- * @param Manual Scroll Key Up
- * @desc Key for scrolling the map upwards. Default: u http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
- * @default 85
- *
- * @param Manual Scroll Key Right
- * @desc Key for scrolling the map upwards. Default: k
- * @default 75
- *
- * @param Manual Scroll Key Down
- * @desc Key for scrolling the map upwards. Default: j
- * @default 74
- *
- * @param Manual Scroll Key Left
- * @desc Key for scrolling the map upwards. Default: h
- * @default 72
- *
- * @param -- Advanced & Debug --
- *
- * @param Frame Skip
- * @desc Skips some minimap calculations&rendering if set to value > 0 to safe performance. The value equals the amount of frames skipped.
- * @default 0
- *
- * @param Mapshot Filename Length
- * @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
- * @default 3
- *
- * @param Debug Mode
- * @desc Prints extra info if set to true. true/false
- * @default true
- *
- * @param Render Debug Grid
- * @desc Draws a debug grid. Requires "/img/Minimap/DebugGrid.png" which is 48x48 in size. Drains a lot of performance!
- * @default false
- *
- * @param Debug Grid Image
- * @desc Name of the debug-grid image
- * @default DebugGrid01
- *
- * @help
- * 1. Make a mapshot of your map. You may use http://forums.rpgmakerweb.com/index.php?/topic/49711-orange-mapshot/
- * 2. Make sure the mapshot is a png file (not a jpg!).
- * 3. Rename the mapshot to the map-id and make it 3 numbers total.
- Example for map id 1: 001.png
- Example for map id 16: 016.png
- 4. Place the mapshots in <project folder>/img/minimap/
- Example: D:\MyAwesomeGame\img\minimap\001.png
- * 5. Place a Window_Minimap.png in your <project>/img/system/ folder. You can obviously also use your own.
- *
- *
- *--------------------------------------
- * Map notetags (case sensitive!)
- *--------------------------------------
- * <mm_req_itm:item_id1 item_id2 etc>
- * Example: <mm_req_itm:1, 2, 3>
- *
- * <mm_frameskip:value>
- * Example: <mm_frameskip:1>
- * Note: overrides the global frameskip parameter for this map
- *
- * <mm_mapzoom:value>
- * Example: <mm_mapzoom:0.15>
- * Note: overrides the global mapzoom parameter for this map
- *
- * <mm_allowmanualscroll:value>
- * Example: <mm_allowmanualscroll:false>
- * Allowed values: true/false
- * Note: overrides the global "Allow Manual Scrolling" parameter for this map
- *
- *--------------------------------------
- * Event notetags (not case sensitive)
- *--------------------------------------
- * mm_show
- *
- *--------------------------------------
- * Plugin Commands (not case-sensitive)
- *--------------------------------------
- * Minimap Hide
- * Minimap Show
- * Minimap FadeOut
- * Minimap FadeReset
- * Minimap Refresh
- * Minimap RefreshEvents
- * Minimap IncreaseScroll <x> <y>
- * Minimap SetScroll <x> <y>
- *
- * Adding POI's (advanced plugin command!):
- * Minimap AddPOI real_x, real_y, bitmap folder, bitmap filename, s_x, s_y, s_w, s_h, draw_w, draw_h
- * Example that draws Actor1_3 on tile 10,10:
- * Minimap AddPOI 10 10 img/enemies/ Actor1_3 0 0 254 225 64 64
- * Note that real_x & real_y are in maptiles and not in coordinates. 0,0 is in the upper left corner.
- *
- * Note to other scripters: You can access the variable that contains the window through this: "Silv.Minimap.Window" w/o the quotes.
- */
- // Get Plugin Parameters
- var Silv = Silv || {};
- Silv.Parameters = $plugins.filter(function(p) { return p.description.contains('<SilvMinimap>'); })[0].parameters;
- Silv.Minimap = Silv.Minimap || {};
- Silv.Minimap.Window = null;
- Silv.Minimap.POI = new Array();
- Silv.Minimap.Events = new Array(); // Is an array of objects [{ Game_Event, Sprite_Character }]. USe .event and .sprite to retrieve the values.
- Silv.Minimap.ScreenIsFading = false;
- Silv.Minimap.MapStyle = Silv.Parameters['Map Style'].toLowerCase();
- Silv.Minimap.GlobalMapZoom = parseFloat(Silv.Parameters['Global Map Zoom']);
- // Positioning & Size
- Silv.Minimap.Window_X = parseInt(Silv.Parameters['X']);
- Silv.Minimap.Window_Y = parseInt(Silv.Parameters['Y']);
- Silv.Minimap.WindowWidth = parseInt(Silv.Parameters['Width']);
- Silv.Minimap.WindowHeight = parseInt(Silv.Parameters['Height']);
- Silv.Minimap.BorderWidth = parseInt(Silv.Parameters['Border Width']);
- Silv.Minimap.BorderHeight = parseInt(Silv.Parameters['Border Height']);
- Silv.Minimap.WindowHorizontalAlignment = Silv.Parameters['Horizontal Alignment'].toLowerCase();
- Silv.Minimap.WindowVerticalAlignment = Silv.Parameters['Vertical Alignment'].toLowerCase();
- // The Rest
- Silv.Minimap.StandardPadding = parseInt(Silv.Parameters['Standard Padding']);
- Silv.Minimap.WindowSkin = Silv.Parameters['Window Skin'];
- Silv.Minimap.PlayerIconWidth = parseInt(Silv.Parameters['Player Icon Width']);
- Silv.Minimap.PlayerIconHeight = parseInt(Silv.Parameters['Player Icon Height']);
- Silv.Minimap.DrawPlayerIcon = Silv.Parameters['Draw Player Icon'].toLowerCase() == 'true';
- Silv.Minimap.PlayerBlinks = parseInt(Silv.Parameters['Player Blink Delay']) > 0;
- Silv.Minimap.PlayerBlinkDelay = parseInt(Silv.Parameters['Player Blink Delay']);
- Silv.Minimap.MapBGFillColor = Silv.Parameters['Fill Color'].split(' ');
- Silv.Minimap.MaintainAspectRatio = Silv.Parameters['Maintain Aspect Ratio'].toLowerCase() == 'true';
- Silv.Minimap.FadeoutSpeed = parseInt(Silv.Parameters['Fadeout Speed']);
- Silv.Minimap.GlobalRequiredItem = parseInt(Silv.Parameters['Global Required Item']);
- Silv.Minimap.EventRenderSize = parseInt(Silv.Parameters['Event Render Size']);
- Silv.Minimap.AutoClearPOI = Silv.Parameters['Auto Clear POI'].toLowerCase() == 'true';
- Silv.Minimap.DrawOverlay = Silv.Parameters['Render Minimap Overlay'].toLowerCase() == 'true';
- // Manual Scrolling
- Silv.Minimap.AllowManualScrolling = Silv.Parameters['Allow Manual Scrolling'].toLowerCase() == 'true';
- Silv.Minimap.ManualScrollspeed = parseFloat(Silv.Parameters['Manual Scrollspeed']);
- Silv.Minimap.ManualScrollKeyUp = parseInt(Silv.Parameters['Manual Scroll Key Up']);
- Silv.Minimap.ManualScrollKeyRight = parseInt(Silv.Parameters['Manual Scroll Key Right']);
- Silv.Minimap.ManualScrollKeyDown = parseInt(Silv.Parameters['Manual Scroll Key Down']);
- Silv.Minimap.ManualScrollKeyLeft = parseInt(Silv.Parameters['Manual Scroll Key Left']);
- // Advanced & Debug
- Silv.Minimap.FrameSkip = parseInt(Silv.Parameters['Frame Skip']);
- Silv.Minimap.MapFilenameLength = parseInt(Silv.Parameters['Mapshot Filename Length']);
- Silv.Minimap.DebugMode = Silv.Parameters['Debug Mode'].toLowerCase() == 'true';
- Silv.Minimap.DrawDebugGrid = Silv.Parameters['Render Debug Grid'].toLowerCase() == 'true';
- Silv.Minimap.DebugGridImage = Silv.Parameters['Debug Grid Image'];
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (function()
- {
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Utilities & Misc
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Example: lpad('2', '0') // result: '002'
- function lpad_mapname(word, padStr)
- {
- word = String(word);
- while (word.length < Silv.Minimap.MapFilenameLength) word = padStr + word;
- return word;
- }
- function minimapFolderPath()
- {
- var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, "/img/minimap/");
- if (path.match(/^\/([A-Z]\:)/)) { path = path.slice(1); }
- path = decodeURIComponent(path);
- return path;
- }
- // filename example: '002.png'
- function minimapImageExists(filename)
- {
- var filename = minimapFolderPath() + filename;
- var fs = require('fs');
- return fs.existsSync(filename);
- }
- ImageManager.loadMinimap = function(filename, hue)
- {
- return this.loadBitmap('img/minimap/', filename, hue, false);
- }
- // Do not just show the minimap on top of a faded-out screen.
- var alias_silv_mm_updateFadeOut = Game_Screen.prototype.updateFadeOut;
- Game_Screen.prototype.updateFadeOut = function() {
- alias_silv_mm_updateFadeOut.call(this);
- if (this._brightness < 255) // (this._fadeOutDuration > 0)
- {
- Silv.Minimap.ScreenIsFading = true;
- Silv.Minimap.Window.opacity = this._brightness;
- Silv.Minimap.Window.contents.paintOpacity = this._brightness;
- //Silv.Minimap.Window.visible = false;
- }
- else
- {
- Silv.Minimap.ScreenIsFading = false;
- //Silv.Minimap.Window.visible = true;
- }
- }
- // Manual Scrolling
- var alias_silv_mm_onKeyDown = Input._onKeyDown;
- Input._onKeyDown = function(event)
- {
- alias_silv_mm_onKeyDown.call(this, event);
- if (Silv.Minimap.Window.allowManualScroll && (SceneManager._scene instanceof Scene_Map))
- {
- switch(event.keyCode)
- {
- case Silv.Minimap.ManualScrollKeyUp:
- Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x, Silv.Minimap.Window.mapScroll.y - Silv.Minimap.ManualScrollspeed);
- break;
- case Silv.Minimap.ManualScrollKeyRight:
- Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x + Silv.Minimap.ManualScrollspeed, Silv.Minimap.Window.mapScroll.y);
- break;
- case Silv.Minimap.ManualScrollKeyDown:
- Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x, Silv.Minimap.Window.mapScroll.y + Silv.Minimap.ManualScrollspeed);
- break;
- case Silv.Minimap.ManualScrollKeyLeft:
- Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x - Silv.Minimap.ManualScrollspeed, Silv.Minimap.Window.mapScroll.y);
- break;
- }
- //AudioManager.playSe({name: 'Coin', volume: 90, pitch: 100, pan: 0});
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Store a reference to the player graphic.
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- var alias_silv_mm_createCharacters = Spriteset_Map.prototype.createCharacters;
- Spriteset_Map.prototype.createCharacters = function()
- {
- alias_silv_mm_createCharacters.call(this);
- for (i = this._characterSprites.length - 1; i >= 0; i--)
- {
- if (this._characterSprites[i]._character == $gamePlayer)
- {
- Spriteset_Map.prototype.playerSprite = this._characterSprites[i];
- break;
- }
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Window
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function Window_Minimap() { this.initialize.apply(this, arguments); }
- // Inherit from base window
- Window_Minimap.prototype = Object.create(Window_Base.prototype);
- // Set Constructor
- Window_Minimap.prototype.constructor = Window_Minimap;
- Window_Minimap.prototype.loadWindowskin = function() { this.windowskin = ImageManager.loadSystem(Silv.Minimap.WindowSkin); }
- Window_Minimap.prototype.standardPadding = function() { return Silv.Minimap.StandardPadding; }
- //Window_Minimap.prototype.standardFontSize = function() { return Silv.Minimap.FontSize; }
- var mapBmp;
- var drawAreaWidth;
- var drawAreaHeight;
- var mapWidth
- var mapHeight;
- var playerBlinkCnt;
- var playerBlink_IsVisible;
- var frameSkip;
- var frameSkipCnt;
- var mapAspRatInfo;
- var mapZoom;
- var mapZoomInverse;
- var isManualScrolling;
- var allowManualScroll;
- var mapScroll;
- var lastPlayerLoc;
- var isFirstProcessedUpdate;
- var debugGridBmp;
- var overlayBmp;
- // Initialization
- Window_Minimap.prototype.initialize = function(x, y, width, height)
- {
- Window_Base.prototype.initialize.call(this, x, y, width, height);
- this._helpWindow = null;
- this._handlers = {};
- this._touching = false;
- this.deactivate();
- this.isFadingOut = false;
- this.isFadedOut = false;
- this.mapBmp = ImageManager.loadMinimap(lpad_mapname($gameMap._mapId, '0'));
- this.overlayBmp = ImageManager.loadMinimap('Overlay');
- this.drawAreaWidth = this.contents.width - Silv.Minimap.BorderWidth * 2;
- this.drawAreaHeight = this.contents.height - Silv.Minimap.BorderHeight * 2;
- this.mapWidth = parseFloat($gameMap.width());
- this.mapHeight = parseFloat($gameMap.height());
- this.setAspectRatio();
- this.playerBlinkCnt = Silv.Minimap.PlayerBlinkDelay;
- this.playerBlink_IsVisible = true;
- this.frameSkip = Silv.Minimap.FrameSkip;
- this.frameSkipCnt = 0;
- this.mapZoom = Silv.Minimap.GlobalMapZoom;
- if ('mm_mapzoom' in $dataMap.meta) { this.mapZoom = parseFloat($dataMap.meta.mm_mapzoom); }
- this.mapZoomInverse = 1 / this.mapZoom;
- this.isFirstProcessedUpdate = true;
- this.isManualScrolling = false;
- this.allowManualScroll = Silv.Minimap.AllowManualScrolling;
- if ('mm_allowmanualscroll' in $dataMap.meta) { this.allowManualScroll = $dataMap.meta.mm_allowmanualscroll == 'true'; }
- this.mapScroll = {x: 0, y: 0, adjustment_x: 0, adjustment_y: 0};
- this.lastPlayerLoc = {x: $gamePlayer._realX, y: $gamePlayer._realY};
- this.loadEvents();
- this.debugGridBmp = ImageManager.loadMinimap(Silv.Minimap.DebugGridImage);
- // The update must be called AFTER all the initialization code.
- this.update(true);
- }
- Window_Minimap.prototype.clamp = function(value, min, max)
- {
- return Math.min(Math.max(value, min), max);
- }
- // This function requires this.mapBmp to be fully initialized.
- // #Aspect #Ratio #AspectRatio
- Window_Minimap.prototype.setAspectRatio = function()
- {
- // this.mapAspRatInfo.scaleDelta_x is the difference in size between the mapwidth (in pixels, NOT in tiles) and the minimap (render)width.
- this.mapAspRatInfo = { w: 0.0, h: 0.0, offset_x: 0.0, offset_y: 0.0, scaleDelta_x: 0.0, scaleDelta_y: 0.0 }
- var w = $gameMap.width();
- var h = $gameMap.height();
- // Map Aspect Ratio
- if (!Silv.Minimap.MaintainAspectRatio || (w == h))
- {
- this.mapAspRatInfo.w = 1.0;
- this.mapAspRatInfo.h = 1.0;
- }
- else if (w > h)
- {
- this.mapAspRatInfo.w = 1.0;
- this.mapAspRatInfo.h = h / parseFloat(w);
- }
- else // if (h > w)
- {
- this.mapAspRatInfo.w = w / parseFloat(h);
- this.mapAspRatInfo.h = 1.0;
- }
- this.mapAspRatInfo.scaleDelta_x = this.drawAreaWidth / parseFloat($gameMap.width() * $gameMap.tileWidth());
- this.mapAspRatInfo.scaleDelta_y = this.drawAreaHeight / parseFloat($gameMap.height() * $gameMap.tileHeight());
- }
- Window_Minimap.prototype.loadEvents = function()
- {
- Silv.Minimap.Events = new Array();
- for (ev_idx = 1; ev_idx < $dataMap.events.length; ev_idx++) // Note: start at 1. Because the first one is always null.
- {
- if (($dataMap.events[ev_idx] != null) && ($dataMap.events[ev_idx].note != ''))
- {
- var cmds = $dataMap.events[ev_idx].note.toLowerCase().split(' ');
- if (cmds.indexOf('mm_show') > -1)
- {
- var ev = $gameMap.event(ev_idx);
- Silv.Minimap.Events.push({event: ev, sprite: this.getEventCharacterSprite(ev.eventId())}); // Add event to the array so we can render it on the minimap
- }
- }
- }
- if (Silv.Minimap.DebugMode) { console.log('Loaded Events:'); console.log(Silv.Minimap.Events); }
- }
- Window_Minimap.prototype.getEventCharacterSprite = function(ev_id)
- {
- for (i=0; i < SceneManager._scene._spriteset._characterSprites.length; i++)
- {
- var eventSprite = SceneManager._scene._spriteset._characterSprites[i];
- if (eventSprite._character.eventId() == ev_id)
- {
- return eventSprite;
- }
- }
- throw 'getEventCharacterSprite() did not find a match for ev_id: ' + ev_id;
- }
- Window_Minimap.prototype.update = function()
- {
- if (!this.skipFrame() && this.mapBmp.isReady())
- {
- Window_Base.prototype.update.call(this);
- this.updateFadeOut();
- if (Silv.Minimap.PlayerBlinks) { this.updatePlayerBlink(); }
- this.updateMapScroll(this.isFirstProcessedUpdate);
- this.drawMinimap();
- this.lastPlayerLoc.x = $gamePlayer._realX;
- this.lastPlayerLoc.y = $gamePlayer._realY;
- this.isFirstProcessedUpdate = false;
- }
- }
- Window_Minimap.prototype.playerLocChanged = function()
- {
- return this.lastPlayerLoc.x != $gamePlayer._realX || this.lastPlayerLoc.y != $gamePlayer._realY;
- }
- Window_Minimap.prototype.updateMapScroll = function(force)
- {
- if (this.playerLocChanged() || force) // Only update mapscroll if the player changed location. This way manually scrolling is made possible.
- {
- this.isManualScrolling = false;
- this.setMapScroll($gamePlayer._realX * $gameMap.tileWidth() - (this.drawAreaWidth / 2 * this.mapZoomInverse), $gamePlayer._realY * $gameMap.tileHeight() - (this.drawAreaHeight / 2 * this.mapZoomInverse));
- }
- }
- Window_Minimap.prototype.setMapScroll = function(scroll_x, scroll_y)
- {
- var old_x = this.mapScroll.x = scroll_x;
- var source_w = this.drawAreaWidth * this.mapZoomInverse;
- this.mapScroll.x = this.clamp(this.mapScroll.x, 0, this.mapBmp.width - source_w);
- this.mapScroll.adjustment_x = old_x - this.mapScroll.x; // clamp difference
- var old_y = this.mapScroll.y = scroll_y;
- var source_h = this.drawAreaHeight * this.mapZoomInverse;
- this.mapScroll.y = this.clamp(this.mapScroll.y, 0, this.mapBmp.width - source_h);
- this.mapScroll.adjustment_y = old_y - this.mapScroll.y; // clamp difference
- }
- Window_Minimap.prototype.manualScroll = function(scroll_x, scroll_y)
- {
- this.setMapScroll(scroll_x, scroll_y);
- this.isManualScrolling = true;
- }
- // Skips frame (returns true) if frameSkipCnt > frameSkip
- Window_Minimap.prototype.skipFrame = function()
- {
- if (this.frameSkip == 0) { return false; } // process frame
- this.frameSkipCnt++;
- if (this.frameSkipCnt < this.frameSkip)
- {
- return true; // skip frame
- }
- else
- {
- this.frameSkipCnt = 0;
- return false; // process frame
- }
- }
- Window_Minimap.prototype.updatePlayerBlink = function()
- {
- this.playerBlinkCnt--;
- if (this.playerBlinkCnt <= 0)
- {
- this.playerBlinkCnt = Silv.Minimap.PlayerBlinkDelay;
- this.playerBlink_IsVisible = !this.playerBlink_IsVisible;
- }
- }
- Window_Minimap.prototype.updateFadeOut = function()
- {
- 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.
- if (this.isFadingOut) { this.fadeOut(); }
- }
- Window_Minimap.prototype.fadeOut = function()
- {
- this.opacity = this.contentsOpacity -= Silv.Minimap.FadeoutSpeed;
- this.isFadedOut = (this.opacity <= 0);
- }
- Window_Minimap.prototype.resetFade = function()
- {
- this.isFadingOut = false;
- this.fadeOutCnt = 0;
- this.opacity = this.contentsOpacity = 255;
- this.isFadedOut = false;
- }
- Window_Minimap.prototype.fadeOutInstantly = function()
- {
- this.opacity = this.contentsOpacity = 0;
- this.isFadedOut = true;
- }
- //----------------------------------------------------------------------------------------------------
- // #Rendering #Drawing
- //----------------------------------------------------------------------------------------------------
- Window_Minimap.prototype.drawMinimap = function()
- {
- this.contents.clear();
- // BG fill colour, if applicable
- this.contents.fillRect(Silv.Minimap.BorderWidth, Silv.Minimap.BorderHeight, this.drawAreaWidth, this.drawAreaHeight, Silv.Minimap.MapBGFillColor);
- switch(Silv.Minimap.MapStyle)
- {
- case 'autofit':
- this.drawstyleAutofit();
- break;
- case 'scroll':
- this.drawstyleScroll();
- break;
- default:
- throw 'Window_Minimap.prototype.drawMinimap invalid switch value: ' + Silv.Minimap.MapStyle;
- }
- }
- Window_Minimap.prototype.drawstyleAutofit = function()
- {
- var destination_w = this.drawAreaWidth * this.mapAspRatInfo.w;
- var destination_h = this.drawAreaHeight * this.mapAspRatInfo.h;
- // Calculate the aspect ratio offsets
- this.mapAspRatInfo.offset_x = 0.0; // to center the map
- this.mapAspRatInfo.offset_y = 0.0; // to center the map
- if (this.mapAspRatInfo.w < 1.0) { this.mapAspRatInfo.offset_x = (this.drawAreaWidth - destination_w) / 2.0; }
- if (this.mapAspRatInfo.h < 1.0) { this.mapAspRatInfo.offset_y = (this.drawAreaHeight - destination_h) / 2.0; }
- // This variable saves on calculations further down the road during this update
- // w = width, hw= half width, zhw = zoomed half width
- this.tileInfo = {
- w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.mapAspRatInfo.w,
- h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.mapAspRatInfo.h
- };
- // Draw Map
- 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);
- // Debug Grid (if applicable)
- if (Silv.Minimap.DrawDebugGrid)
- {
- for (i=0; i < $gameMap.width(); i++)
- {
- for (j=0; j < $gameMap.height(); j++)
- {
- var testLoc = this.translateLocationAutofit(i, j, this.tileInfo.w * this.mapAspRatInfo.w, this.tileInfo.h * this.mapAspRatInfo.h);
- this.contents.blt(this.debugGridBmp, 0, 0, this.tileInfo.w, this.tileInfo.h, testLoc.x, testLoc.y, this.tileInfo.w * this.mapAspRatInfo.w, this.tileInfo.h * this.mapAspRatInfo.h);
- }
- }
- }
- // Draw POI's
- for (i = 0; i < Silv.Minimap.POI.length; i++)
- {
- var poi = Silv.Minimap.POI[i];
- var poiLoc = this.translateLocationAutofit(poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
- this.contents.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
- poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
- }
- // Draw Events
- for (i=0; i < Silv.Minimap.Events.length; i++)
- {
- var ev = Silv.Minimap.Events[i].event;
- var ev_sprite = Silv.Minimap.Events[i].sprite;
- var evMapLoc = this.translateLocationAutofit(ev._realX, ev._realY, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
- 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);
- }
- // Draw Player
- if (Silv.Minimap.DrawPlayerIcon && this.playerBlink_IsVisible)
- {
- var playerMapLoc = this.translateLocationAutofit($gamePlayer._realX, $gamePlayer._realY, Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
- this.contents.blt(Spriteset_Map.prototype.playerSprite._bitmap, Spriteset_Map.prototype.playerSprite._frame.x, Spriteset_Map.prototype.playerSprite._frame.y, Spriteset_Map.prototype.playerSprite._frame.width, Spriteset_Map.prototype.playerSprite._frame.height,
- playerMapLoc.x, playerMapLoc.y, Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
- }
- // Overlay (if applicable)
- if(Silv.Minimap.DrawOverlay) { this.drawOverlay(); }
- }
- Window_Minimap.prototype.drawstyleScroll = function()
- {
- // 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
- if (this.mapScroll.x < 0 || this.drawAreaWidth * this.mapZoomInverse > this.mapBmp.width ||
- this.mapScroll.y < 0 || this.drawAreaHeight * this.mapZoomInverse > this.mapBmp.height)
- {
- this.drawstyleAutofit();
- return;
- }
- // This variable saves on calculations further down the road during this update
- // w = width, hw= half width, zhw = zoomed half width
- this.tileInfo = {
- w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.mapZoom,
- h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.mapZoom
- };
- // Draw Map
- var map_src_rect = { x:0.0, y:0.0, w:0.0, h:0.0};
- map_src_rect.x = this.mapScroll.x;
- map_src_rect.y = this.mapScroll.y;
- map_src_rect.w = this.drawAreaWidth * this.mapZoomInverse;
- map_src_rect.h = this.drawAreaHeight * this.mapZoomInverse;
- 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);
- // Debug Grid (if applicable)
- if (Silv.Minimap.DrawDebugGrid)
- {
- for (i=0; i < $gameMap.width(); i++)
- {
- for (j=0; j < $gameMap.height(); j++)
- {
- var testLoc = this.translateLocationScroll(i, j, this.tileInfo.w * this.mapZoom, this.tileInfo.h * this.mapZoom);
- this.contents.blt(this.debugGridBmp, 0, 0, this.tileInfo.w, this.tileInfo.h, testLoc.x, testLoc.y, this.tileInfo.w * this.mapZoom, this.tileInfo.h * this.mapZoom);
- }
- }
- }
- // Draw POI's
- for (i = 0; i < Silv.Minimap.POI.length; i++)
- {
- var poi = Silv.Minimap.POI[i];
- var poiLoc = this.translateLocationScroll(poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
- this.contents.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
- poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
- }
- // Draw Events
- for (i=0; i < Silv.Minimap.Events.length; i++)
- {
- var ev = Silv.Minimap.Events[i].event;
- var ev_sprite = Silv.Minimap.Events[i].sprite;
- var evMapLoc = this.translateLocationScroll(ev._realX, ev._realY, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
- 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);
- }
- // Draw Player
- if (Silv.Minimap.DrawPlayerIcon && this.playerBlink_IsVisible)
- {
- /* if (!this.isManualScrolling) // note to self, can't the player just be drawn without this if-statement?
- {
- var playerLoc_x = this.drawAreaWidth / 2.0 + this.mapScroll.adjustment_x * this.mapZoom;
- var playerLoc_y = this.drawAreaHeight / 2.0 + this.mapScroll.adjustment_y * this.mapZoom;
- // Now center the location in the center of the tiles instead of the topleft corner
- playerLoc_x += this.tileInfo.zhw - Silv.Minimap.PlayerIconWidth / 2.0;
- playerLoc_y += this.tileInfo.zhh - Silv.Minimap.PlayerIconHeight / 2.0;
- this.contents.blt(Spriteset_Map.prototype.playerSprite._bitmap, Spriteset_Map.prototype.playerSprite._frame.x, Spriteset_Map.prototype.playerSprite._frame.y, Spriteset_Map.prototype.playerSprite._frame.width, Spriteset_Map.prototype.playerSprite._frame.height,
- Silv.Minimap.BorderWidth + playerLoc_x, Silv.Minimap.BorderHeight + playerLoc_y, Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
- }
- else
- {*/
- var playerLoc = this.translateLocationScroll($gamePlayer._realX, $gamePlayer._realY, Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
- this.contents.blt(Spriteset_Map.prototype.playerSprite._bitmap, Spriteset_Map.prototype.playerSprite._frame.x, Spriteset_Map.prototype.playerSprite._frame.y, Spriteset_Map.prototype.playerSprite._frame.width, Spriteset_Map.prototype.playerSprite._frame.height,
- playerLoc.x, playerLoc.y, Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
- //}
- }
- // Overlay (if applicable)
- if(Silv.Minimap.DrawOverlay) { this.drawOverlay(); }
- }
- Window_Minimap.prototype.drawOverlay = function()
- {
- this.contents.blt(this.overlayBmp, 0, 0, this.overlayBmp.width, this.overlayBmp.height, 0, 0, this.width, this.height);
- }
- // #Translate
- // returns {x, y}
- Window_Minimap.prototype.translateLocationScroll = function(obj_real_x, obj_real_y, obj_w, obj_h)
- {
- 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;
- 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;
- return {x: obj_x, y: obj_y};
- }
- // returns {x, y}
- Window_Minimap.prototype.translateLocationAutofit = function(obj_real_x, obj_real_y, obj_w, obj_h)
- {
- 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;
- 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;
- return {x: obj_x, y: obj_y};
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // POI
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function MM_POI() { this.initialize.apply(this, arguments); }
- // Set Constructor
- MM_POI.prototype.constructor = MM_POI;
- // Initialization
- MM_POI.prototype.initialize = function(real_x, real_y, bmp, source_x, source_y, source_w, source_h, draw_w, draw_h)
- {
- this.real_x = real_x;
- this.real_y = real_y;
- this.bmp = bmp;
- this.src = { x:source_x, y:source_y, w:source_w, h:source_h };
- this.destSize = { w:draw_w, h:draw_h };
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Create the Minimap window
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- Scene_Map.prototype.createMinimapWindow = function()
- {
- x = 0;
- if (Silv.Minimap.WindowHorizontalAlignment == 'right') { x = Graphics.width - Silv.Minimap.WindowWidth; }
- y = 0;
- if (Silv.Minimap.WindowVerticalAlignment == 'bottom') { y = Graphics.height - Silv.Minimap.WindowHeight; }
- Silv.Minimap.Window = this.window_Minimap = new Window_Minimap(x + Silv.Minimap.Window_X, y + Silv.Minimap.Window_Y, Silv.Minimap.WindowWidth, Silv.Minimap.WindowHeight);
- Silv.Minimap.Window.resetFade();
- // override frameskip (map-specific frameskip)
- if ('mm_frameskip' in $dataMap.meta)
- {
- Silv.Minimap.Window.frameSkip = parseInt($dataMap.meta.mm_frameskip);
- if (Silv.Minimap.DebugMode) { console.log('Global frameskip: ' + Silv.Minimap.FrameSkip + ' was overriden by the map-specific frameskip of: ' + $dataMap.meta.mm_frameskip + '.'); }
- }
- this.addChildAt(this.window_Minimap, 1);
- }
- Scene_Map.prototype.AttemptToCreateMinimap = function()
- {
- var mapname = lpad_mapname($gameMap._mapId, '0') + '.png';
- if (minimapImageExists(mapname))
- {
- if (this.MinimapHasRequiredItems())
- {
- this.createMinimapWindow();
- }
- }
- else
- {
- if (Silv.Minimap.DebugMode) { console.log('No minimap \'' + mapname + '\' found for map with map-id: ' + $gameMap._mapId + '.'); }
- }
- }
- var alias_silver_mm_createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
- Scene_Map.prototype.createDisplayObjects = function()
- {
- alias_silver_mm_createDisplayObjects.call(this);
- if (Silv.Minimap.AutoClearPOI) { Silv.Minimap.POI = new Array(); }
- this.AttemptToCreateMinimap();
- }
- Scene_Map.prototype.MinimapHasRequiredItems = function()
- {
- // Check global item
- if (Silv.Minimap.GlobalRequiredItem > 0)
- {
- if (!$gameParty.hasItem($dataItems[Silv.Minimap.GlobalRequiredItem], false))
- {
- if (Silv.Minimap.DebugMode) { console.log('Minimap was found but party does not possess the required global item: ' + $dataItems[Silv.Minimap.GlobalRequiredItem].name); }
- return false;
- }
- }
- // Check map-specific items
- if ('mm_req_itm' in $dataMap.meta)
- {
- var req_item_ids = $dataMap.meta.mm_req_itm.split(' ').filter(Boolean); // .filter(Boolean) removes empty strings from array
- for (i = 0; i < req_item_ids.length; i++)
- {
- if (!$gameParty.hasItem($dataItems[req_item_ids[i]], false))
- {
- 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); }
- return false;
- }
- }
- }
- return true;
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Plugin Command
- // Note: The items are separated by spaces. The command is the first word and any following words are args. args is an array.
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
- Game_Interpreter.prototype.pluginCommand = function(command, args)
- {
- _Game_Interpreter_pluginCommand.call(this, command, args);
- if (command.toLowerCase() == 'minimap') { PluginCommand(command, args); }
- }
- function PluginCommand(cmd, args)
- {
- switch(args[0].toLowerCase())
- {
- case 'hide':
- Silv.Minimap.Window.hide();
- break;
- case 'show':
- Silv.Minimap.Window.show();
- break;
- case 'fadeout':
- Silv.Minimap.Window.isFadingOut = true;
- break;
- case 'fadereset':
- Silv.Minimap.Window.resetFade();
- break;
- case 'refresh':
- SceneManager._scene.AttemptToCreateMinimap();
- break;
- case 'addpoi': //Minimap addpoi real_x, real_y, bitmap folder, bitmap filename, s_x, s_y, s_w, s_h, draw_w, draw_h
- Silv.Minimap.POI.push(new MM_POI(parseFloat(args[1]), parseFloat(args[2]), ImageManager.loadBitmap(args[3], args[4], 0, false), parseInt(args[5]), parseInt(args[6]), parseInt(args[7]), parseInt(args[8]), parseInt(args[9]), parseInt(args[10])));
- SceneManager._scene.AttemptToCreateMinimap();
- break;
- case 'refreshevents':
- Silv.Minimap.Window.loadEvents();
- break;
- case 'increasescroll':
- Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x + parseFloat(args[1]), Silv.Minimap.Window.mapScroll.y + parseFloat(args[2]));
- break;
- case 'setscroll':
- Silv.Minimap.Window.manualScroll(parseFloat(args[1]), parseFloat(args[2]));
- break;
- default:
- throw 'Minimap, unknown Plugin Command: ' + args[0];
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- })();
Advertisement
Add Comment
Please, Sign In to add comment