Guest User

Minimap

a guest
Nov 21st, 2015
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.81 KB | None | 0 0
  1. //=============================================================================
  2. // SilvMinimap.js
  3. // Version: 0.91
  4. //=============================================================================
  5. /*:
  6. * @plugindesc v0.91 Minimap. <SilvMinimap>
  7. * @author Silver
  8. *
  9. * @param Map Style
  10. * @desc Is the minimap scaled to fit? Or does it zoom and scroll? Autofit/Scroll
  11. * @default Scroll
  12. *
  13. * @param Global Map Zoom
  14. * @desc Only applies if MapStyle is set to: Scroll. Determines the default zoom level for all maps. A value of 1 means 1:1.
  15. * @default 0.25
  16. *
  17. * @param -- Positioning & Size --
  18. *
  19. * @param X
  20. * @desc x-location of minimap window. If window-alignment is set to Right, this will act as an offset value instead
  21. * @default -2
  22. *
  23. * @param Y
  24. * @desc y-location of minimap window. If window-alignment is set to Top, this will act as an offset value instead
  25. * @default 2
  26. *
  27. * @param Horizontal Alignment
  28. * @desc Left/Right
  29. * @default Right
  30. *
  31. * @param Vertical Alignment
  32. * @desc Top/Bottom
  33. * @default Bottom
  34. *
  35. * @param Width
  36. * @desc width of the minimap
  37. * @default 320
  38. *
  39. * @param Height
  40. * @desc height of the minimap
  41. * @default 320
  42. *
  43. * @param Border Width
  44. * @desc Border width of the minimap
  45. * @default 12
  46. *
  47. * @param Border Height
  48. * @desc Border height of the minimap
  49. * @default 12
  50. *
  51. * @param -- The rest --
  52. *
  53. * @param Standard Padding
  54. * @desc Standard Window Padding. Best to leave at 0.
  55. * @default 0
  56. *
  57. * @param Window Skin
  58. * @desc Name of the window skin to use for this window
  59. * @default Window_Minimap
  60. *
  61. * @param Player Icon Width
  62. * @desc Standard Window Padding
  63. * @default 16
  64. *
  65. * @param Player Icon Height
  66. * @desc Standard Window Padding
  67. * @default 16
  68. *
  69. * @param Draw Player Icon
  70. * @desc Draw player on the map? true/false
  71. * @default true
  72. *
  73. * @param Player Blink Delay
  74. * @desc Blinks the player icon (in frames). Set to 0 to disable. Does nothing if "Draw Player Icon" is set to false
  75. * @default 0
  76. *
  77. * @param Fill Color
  78. * @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.
  79. * @default 0 0 0 255
  80. *
  81. * @param Maintain Aspect Ratio
  82. * @desc Maintains minimap aspect ratio if set to true. true/false
  83. * @default true
  84. *
  85. * @param Fadeout Speed
  86. * @desc How fast the minimap fades out
  87. * @default 3
  88. *
  89. * @param Global Required Item
  90. * @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
  91. * @default 0
  92. *
  93. * @param Event Render Size
  94. * @desc How big the events are that are drawn onto the minimap
  95. * @default 16
  96. *
  97. * @param Auto Clear POI
  98. * @desc Automatically clear POI's between map transfers? true/false
  99. * @default true
  100. *
  101. * @param Render Minimap Overlay
  102. * @desc If enabled, add the image: /img/Minimap/Overlay.png and it will be drawn on top of the minimap. true/false
  103. * @default true
  104. *
  105. * @param -- Manual Scrolling --
  106. *
  107. * @param Allow Manual Scrolling
  108. * @desc true/false
  109. * @default true
  110. *
  111. * @param Manual Scrollspeed
  112. * @desc How fast the map is scrolled
  113. * @default 24
  114. *
  115. * @param Manual Scroll Key Up
  116. * @desc Key for scrolling the map upwards. Default: u http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
  117. * @default 85
  118. *
  119. * @param Manual Scroll Key Right
  120. * @desc Key for scrolling the map upwards. Default: k
  121. * @default 75
  122. *
  123. * @param Manual Scroll Key Down
  124. * @desc Key for scrolling the map upwards. Default: j
  125. * @default 74
  126. *
  127. * @param Manual Scroll Key Left
  128. * @desc Key for scrolling the map upwards. Default: h
  129. * @default 72
  130. *
  131. * @param -- Advanced & Debug --
  132. *
  133. * @param Frame Skip
  134. * @desc Skips some minimap calculations&rendering if set to value > 0 to safe performance. The value equals the amount of frames skipped.
  135. * @default 0
  136. *
  137. * @param Mapshot Filename Length
  138. * @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
  139. * @default 3
  140. *
  141. * @param Debug Mode
  142. * @desc Prints extra info if set to true. true/false
  143. * @default true
  144. *
  145. * @param Render Debug Grid
  146. * @desc Draws a debug grid. Requires "/img/Minimap/DebugGrid.png" which is 48x48 in size. Drains a lot of performance!
  147. * @default false
  148. *
  149. * @param Debug Grid Image
  150. * @desc Name of the debug-grid image
  151. * @default DebugGrid01
  152. *
  153. * @help
  154. * 1. Make a mapshot of your map. You may use http://forums.rpgmakerweb.com/index.php?/topic/49711-orange-mapshot/
  155. * 2. Make sure the mapshot is a png file (not a jpg!).
  156. * 3. Rename the mapshot to the map-id and make it 3 numbers total.
  157. Example for map id 1: 001.png
  158. Example for map id 16: 016.png
  159. 4. Place the mapshots in <project folder>/img/minimap/
  160. Example: D:\MyAwesomeGame\img\minimap\001.png
  161. * 5. Place a Window_Minimap.png in your <project>/img/system/ folder. You can obviously also use your own.
  162. *
  163. *
  164. *--------------------------------------
  165. * Map notetags (case sensitive!)
  166. *--------------------------------------
  167. * <mm_req_itm:item_id1 item_id2 etc>
  168. * Example: <mm_req_itm:1, 2, 3>
  169. *
  170. * <mm_frameskip:value>
  171. * Example: <mm_frameskip:1>
  172. * Note: overrides the global frameskip parameter for this map
  173. *
  174. * <mm_mapzoom:value>
  175. * Example: <mm_mapzoom:0.15>
  176. * Note: overrides the global mapzoom parameter for this map
  177. *
  178. * <mm_allowmanualscroll:value>
  179. * Example: <mm_allowmanualscroll:false>
  180. * Allowed values: true/false
  181. * Note: overrides the global "Allow Manual Scrolling" parameter for this map
  182. *
  183. *--------------------------------------
  184. * Event notetags (not case sensitive)
  185. *--------------------------------------
  186. * mm_show
  187. *
  188. *--------------------------------------
  189. * Plugin Commands (not case-sensitive)
  190. *--------------------------------------
  191. * Minimap Hide
  192. * Minimap Show
  193. * Minimap FadeOut
  194. * Minimap FadeReset
  195. * Minimap Refresh
  196. * Minimap RefreshEvents
  197. * Minimap IncreaseScroll <x> <y>
  198. * Minimap SetScroll <x> <y>
  199. *
  200. * Adding POI's (advanced plugin command!):
  201. * Minimap AddPOI real_x, real_y, bitmap folder, bitmap filename, s_x, s_y, s_w, s_h, draw_w, draw_h
  202. * Example that draws Actor1_3 on tile 10,10:
  203. * Minimap AddPOI 10 10 img/enemies/ Actor1_3 0 0 254 225 64 64
  204. * Note that real_x & real_y are in maptiles and not in coordinates. 0,0 is in the upper left corner.
  205. *
  206. * Note to other scripters: You can access the variable that contains the window through this: "Silv.Minimap.Window" w/o the quotes.
  207. */
  208.  
  209. // Get Plugin Parameters
  210. var Silv = Silv || {};
  211. Silv.Parameters = $plugins.filter(function(p) { return p.description.contains('<SilvMinimap>'); })[0].parameters;
  212. Silv.Minimap = Silv.Minimap || {};
  213. Silv.Minimap.Window = null;
  214. Silv.Minimap.POI = new Array();
  215. Silv.Minimap.Events = new Array(); // Is an array of objects [{ Game_Event, Sprite_Character }]. USe .event and .sprite to retrieve the values.
  216. Silv.Minimap.ScreenIsFading = false;
  217. Silv.Minimap.MapStyle = Silv.Parameters['Map Style'].toLowerCase();
  218. Silv.Minimap.GlobalMapZoom = parseFloat(Silv.Parameters['Global Map Zoom']);
  219. // Positioning & Size
  220. Silv.Minimap.Window_X = parseInt(Silv.Parameters['X']);
  221. Silv.Minimap.Window_Y = parseInt(Silv.Parameters['Y']);
  222. Silv.Minimap.WindowWidth = parseInt(Silv.Parameters['Width']);
  223. Silv.Minimap.WindowHeight = parseInt(Silv.Parameters['Height']);
  224. Silv.Minimap.BorderWidth = parseInt(Silv.Parameters['Border Width']);
  225. Silv.Minimap.BorderHeight = parseInt(Silv.Parameters['Border Height']);
  226. Silv.Minimap.WindowHorizontalAlignment = Silv.Parameters['Horizontal Alignment'].toLowerCase();
  227. Silv.Minimap.WindowVerticalAlignment = Silv.Parameters['Vertical Alignment'].toLowerCase();
  228. // The Rest
  229. Silv.Minimap.StandardPadding = parseInt(Silv.Parameters['Standard Padding']);
  230. Silv.Minimap.WindowSkin = Silv.Parameters['Window Skin'];
  231. Silv.Minimap.PlayerIconWidth = parseInt(Silv.Parameters['Player Icon Width']);
  232. Silv.Minimap.PlayerIconHeight = parseInt(Silv.Parameters['Player Icon Height']);
  233. Silv.Minimap.DrawPlayerIcon = Silv.Parameters['Draw Player Icon'].toLowerCase() == 'true';
  234. Silv.Minimap.PlayerBlinks = parseInt(Silv.Parameters['Player Blink Delay']) > 0;
  235. Silv.Minimap.PlayerBlinkDelay = parseInt(Silv.Parameters['Player Blink Delay']);
  236. Silv.Minimap.MapBGFillColor = Silv.Parameters['Fill Color'].split(' ');
  237. Silv.Minimap.MaintainAspectRatio = Silv.Parameters['Maintain Aspect Ratio'].toLowerCase() == 'true';
  238. Silv.Minimap.FadeoutSpeed = parseInt(Silv.Parameters['Fadeout Speed']);
  239. Silv.Minimap.GlobalRequiredItem = parseInt(Silv.Parameters['Global Required Item']);
  240. Silv.Minimap.EventRenderSize = parseInt(Silv.Parameters['Event Render Size']);
  241. Silv.Minimap.AutoClearPOI = Silv.Parameters['Auto Clear POI'].toLowerCase() == 'true';
  242. Silv.Minimap.DrawOverlay = Silv.Parameters['Render Minimap Overlay'].toLowerCase() == 'true';
  243. // Manual Scrolling
  244. Silv.Minimap.AllowManualScrolling = Silv.Parameters['Allow Manual Scrolling'].toLowerCase() == 'true';
  245. Silv.Minimap.ManualScrollspeed = parseFloat(Silv.Parameters['Manual Scrollspeed']);
  246. Silv.Minimap.ManualScrollKeyUp = parseInt(Silv.Parameters['Manual Scroll Key Up']);
  247. Silv.Minimap.ManualScrollKeyRight = parseInt(Silv.Parameters['Manual Scroll Key Right']);
  248. Silv.Minimap.ManualScrollKeyDown = parseInt(Silv.Parameters['Manual Scroll Key Down']);
  249. Silv.Minimap.ManualScrollKeyLeft = parseInt(Silv.Parameters['Manual Scroll Key Left']);
  250. // Advanced & Debug
  251. Silv.Minimap.FrameSkip = parseInt(Silv.Parameters['Frame Skip']);
  252. Silv.Minimap.MapFilenameLength = parseInt(Silv.Parameters['Mapshot Filename Length']);
  253. Silv.Minimap.DebugMode = Silv.Parameters['Debug Mode'].toLowerCase() == 'true';
  254. Silv.Minimap.DrawDebugGrid = Silv.Parameters['Render Debug Grid'].toLowerCase() == 'true';
  255. Silv.Minimap.DebugGridImage = Silv.Parameters['Debug Grid Image'];
  256. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  257. (function()
  258. {
  259. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  260. // Utilities & Misc
  261. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  262. // Example: lpad('2', '0') // result: '002'
  263. function lpad_mapname(word, padStr)
  264. {
  265. word = String(word);
  266. while (word.length < Silv.Minimap.MapFilenameLength) word = padStr + word;
  267. return word;
  268. }
  269.  
  270. function minimapFolderPath()
  271. {
  272. var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, "/img/minimap/");
  273. if (path.match(/^\/([A-Z]\:)/)) { path = path.slice(1); }
  274. path = decodeURIComponent(path);
  275. return path;
  276. }
  277.  
  278. // filename example: '002.png'
  279. function minimapImageExists(filename)
  280. {
  281. var filename = minimapFolderPath() + filename;
  282. var fs = require('fs');
  283. return fs.existsSync(filename);
  284. }
  285.  
  286. ImageManager.loadMinimap = function(filename, hue)
  287. {
  288. return this.loadBitmap('img/minimap/', filename, hue, false);
  289. }
  290.  
  291. // Do not just show the minimap on top of a faded-out screen.
  292. var alias_silv_mm_updateFadeOut = Game_Screen.prototype.updateFadeOut;
  293. Game_Screen.prototype.updateFadeOut = function() {
  294. alias_silv_mm_updateFadeOut.call(this);
  295.  
  296. if (this._brightness < 255) // (this._fadeOutDuration > 0)
  297. {
  298. Silv.Minimap.ScreenIsFading = true;
  299. Silv.Minimap.Window.opacity = this._brightness;
  300. Silv.Minimap.Window.contents.paintOpacity = this._brightness;
  301. //Silv.Minimap.Window.visible = false;
  302. }
  303. else
  304. {
  305. Silv.Minimap.ScreenIsFading = false;
  306. //Silv.Minimap.Window.visible = true;
  307. }
  308. }
  309.  
  310. // Manual Scrolling
  311. var alias_silv_mm_onKeyDown = Input._onKeyDown;
  312. Input._onKeyDown = function(event)
  313. {
  314. alias_silv_mm_onKeyDown.call(this, event);
  315.  
  316. if (Silv.Minimap.Window.allowManualScroll && (SceneManager._scene instanceof Scene_Map))
  317. {
  318. switch(event.keyCode)
  319. {
  320. case Silv.Minimap.ManualScrollKeyUp:
  321. Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x, Silv.Minimap.Window.mapScroll.y - Silv.Minimap.ManualScrollspeed);
  322. break;
  323. case Silv.Minimap.ManualScrollKeyRight:
  324. Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x + Silv.Minimap.ManualScrollspeed, Silv.Minimap.Window.mapScroll.y);
  325. break;
  326. case Silv.Minimap.ManualScrollKeyDown:
  327. Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x, Silv.Minimap.Window.mapScroll.y + Silv.Minimap.ManualScrollspeed);
  328. break;
  329. case Silv.Minimap.ManualScrollKeyLeft:
  330. Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x - Silv.Minimap.ManualScrollspeed, Silv.Minimap.Window.mapScroll.y);
  331. break;
  332. }
  333. //AudioManager.playSe({name: 'Coin', volume: 90, pitch: 100, pan: 0});
  334. }
  335. }
  336. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  337. // Store a reference to the player graphic.
  338. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  339. var alias_silv_mm_createCharacters = Spriteset_Map.prototype.createCharacters;
  340. Spriteset_Map.prototype.createCharacters = function()
  341. {
  342. alias_silv_mm_createCharacters.call(this);
  343.  
  344. for (i = this._characterSprites.length - 1; i >= 0; i--)
  345. {
  346. if (this._characterSprites[i]._character == $gamePlayer)
  347. {
  348. Spriteset_Map.prototype.playerSprite = this._characterSprites[i];
  349. break;
  350. }
  351. }
  352. }
  353. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  354. // Window
  355. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  356. function Window_Minimap() { this.initialize.apply(this, arguments); }
  357. // Inherit from base window
  358. Window_Minimap.prototype = Object.create(Window_Base.prototype);
  359. // Set Constructor
  360. Window_Minimap.prototype.constructor = Window_Minimap;
  361.  
  362. Window_Minimap.prototype.loadWindowskin = function() { this.windowskin = ImageManager.loadSystem(Silv.Minimap.WindowSkin); }
  363. Window_Minimap.prototype.standardPadding = function() { return Silv.Minimap.StandardPadding; }
  364. //Window_Minimap.prototype.standardFontSize = function() { return Silv.Minimap.FontSize; }
  365.  
  366. var mapBmp;
  367. var drawAreaWidth;
  368. var drawAreaHeight;
  369. var mapWidth
  370. var mapHeight;
  371. var playerBlinkCnt;
  372. var playerBlink_IsVisible;
  373. var frameSkip;
  374. var frameSkipCnt;
  375. var mapAspRatInfo;
  376. var mapZoom;
  377. var mapZoomInverse;
  378. var isManualScrolling;
  379. var allowManualScroll;
  380. var mapScroll;
  381. var lastPlayerLoc;
  382. var isFirstProcessedUpdate;
  383. var debugGridBmp;
  384. var overlayBmp;
  385.  
  386. // Initialization
  387. Window_Minimap.prototype.initialize = function(x, y, width, height)
  388. {
  389. Window_Base.prototype.initialize.call(this, x, y, width, height);
  390. this._helpWindow = null;
  391. this._handlers = {};
  392. this._touching = false;
  393. this.deactivate();
  394.  
  395. this.isFadingOut = false;
  396. this.isFadedOut = false;
  397. this.mapBmp = ImageManager.loadMinimap(lpad_mapname($gameMap._mapId, '0'));
  398. this.overlayBmp = ImageManager.loadMinimap('Overlay');
  399. this.drawAreaWidth = this.contents.width - Silv.Minimap.BorderWidth * 2;
  400. this.drawAreaHeight = this.contents.height - Silv.Minimap.BorderHeight * 2;
  401. this.mapWidth = parseFloat($gameMap.width());
  402. this.mapHeight = parseFloat($gameMap.height());
  403. this.setAspectRatio();
  404. this.playerBlinkCnt = Silv.Minimap.PlayerBlinkDelay;
  405. this.playerBlink_IsVisible = true;
  406. this.frameSkip = Silv.Minimap.FrameSkip;
  407. this.frameSkipCnt = 0;
  408.  
  409. this.mapZoom = Silv.Minimap.GlobalMapZoom;
  410. if ('mm_mapzoom' in $dataMap.meta) { this.mapZoom = parseFloat($dataMap.meta.mm_mapzoom); }
  411. this.mapZoomInverse = 1 / this.mapZoom;
  412. this.isFirstProcessedUpdate = true;
  413.  
  414. this.isManualScrolling = false;
  415. this.allowManualScroll = Silv.Minimap.AllowManualScrolling;
  416. if ('mm_allowmanualscroll' in $dataMap.meta) { this.allowManualScroll = $dataMap.meta.mm_allowmanualscroll == 'true'; }
  417. this.mapScroll = {x: 0, y: 0, adjustment_x: 0, adjustment_y: 0};
  418. this.lastPlayerLoc = {x: $gamePlayer._realX, y: $gamePlayer._realY};
  419. this.loadEvents();
  420.  
  421. this.debugGridBmp = ImageManager.loadMinimap(Silv.Minimap.DebugGridImage);
  422.  
  423. // The update must be called AFTER all the initialization code.
  424. this.update(true);
  425. }
  426.  
  427. Window_Minimap.prototype.clamp = function(value, min, max)
  428. {
  429. return Math.min(Math.max(value, min), max);
  430. }
  431.  
  432. // This function requires this.mapBmp to be fully initialized.
  433. // #Aspect #Ratio #AspectRatio
  434. Window_Minimap.prototype.setAspectRatio = function()
  435. {
  436. // this.mapAspRatInfo.scaleDelta_x is the difference in size between the mapwidth (in pixels, NOT in tiles) and the minimap (render)width.
  437. this.mapAspRatInfo = { w: 0.0, h: 0.0, offset_x: 0.0, offset_y: 0.0, scaleDelta_x: 0.0, scaleDelta_y: 0.0 }
  438. var w = $gameMap.width();
  439. var h = $gameMap.height();
  440.  
  441. // Map Aspect Ratio
  442. if (!Silv.Minimap.MaintainAspectRatio || (w == h))
  443. {
  444. this.mapAspRatInfo.w = 1.0;
  445. this.mapAspRatInfo.h = 1.0;
  446. }
  447. else if (w > h)
  448. {
  449. this.mapAspRatInfo.w = 1.0;
  450. this.mapAspRatInfo.h = h / parseFloat(w);
  451. }
  452. else // if (h > w)
  453. {
  454. this.mapAspRatInfo.w = w / parseFloat(h);
  455. this.mapAspRatInfo.h = 1.0;
  456. }
  457.  
  458. this.mapAspRatInfo.scaleDelta_x = this.drawAreaWidth / parseFloat($gameMap.width() * $gameMap.tileWidth());
  459. this.mapAspRatInfo.scaleDelta_y = this.drawAreaHeight / parseFloat($gameMap.height() * $gameMap.tileHeight());
  460. }
  461.  
  462. Window_Minimap.prototype.loadEvents = function()
  463. {
  464. Silv.Minimap.Events = new Array();
  465. for (ev_idx = 1; ev_idx < $dataMap.events.length; ev_idx++) // Note: start at 1. Because the first one is always null.
  466. {
  467. if (($dataMap.events[ev_idx] != null) && ($dataMap.events[ev_idx].note != ''))
  468. {
  469. var cmds = $dataMap.events[ev_idx].note.toLowerCase().split(' ');
  470. if (cmds.indexOf('mm_show') > -1)
  471. {
  472. var ev = $gameMap.event(ev_idx);
  473. Silv.Minimap.Events.push({event: ev, sprite: this.getEventCharacterSprite(ev.eventId())}); // Add event to the array so we can render it on the minimap
  474. }
  475. }
  476. }
  477. if (Silv.Minimap.DebugMode) { console.log('Loaded Events:'); console.log(Silv.Minimap.Events); }
  478. }
  479.  
  480. Window_Minimap.prototype.getEventCharacterSprite = function(ev_id)
  481. {
  482. for (i=0; i < SceneManager._scene._spriteset._characterSprites.length; i++)
  483. {
  484. var eventSprite = SceneManager._scene._spriteset._characterSprites[i];
  485. if (eventSprite._character.eventId() == ev_id)
  486. {
  487. return eventSprite;
  488. }
  489. }
  490. throw 'getEventCharacterSprite() did not find a match for ev_id: ' + ev_id;
  491. }
  492.  
  493. Window_Minimap.prototype.update = function()
  494. {
  495. if (!this.skipFrame() && this.mapBmp.isReady())
  496. {
  497. Window_Base.prototype.update.call(this);
  498. this.updateFadeOut();
  499. if (Silv.Minimap.PlayerBlinks) { this.updatePlayerBlink(); }
  500. this.updateMapScroll(this.isFirstProcessedUpdate);
  501. this.drawMinimap();
  502. this.lastPlayerLoc.x = $gamePlayer._realX;
  503. this.lastPlayerLoc.y = $gamePlayer._realY;
  504. this.isFirstProcessedUpdate = false;
  505. }
  506. }
  507.  
  508. Window_Minimap.prototype.playerLocChanged = function()
  509. {
  510. return this.lastPlayerLoc.x != $gamePlayer._realX || this.lastPlayerLoc.y != $gamePlayer._realY;
  511. }
  512.  
  513. Window_Minimap.prototype.updateMapScroll = function(force)
  514. {
  515. if (this.playerLocChanged() || force) // Only update mapscroll if the player changed location. This way manually scrolling is made possible.
  516. {
  517. this.isManualScrolling = false;
  518. this.setMapScroll($gamePlayer._realX * $gameMap.tileWidth() - (this.drawAreaWidth / 2 * this.mapZoomInverse), $gamePlayer._realY * $gameMap.tileHeight() - (this.drawAreaHeight / 2 * this.mapZoomInverse));
  519. }
  520. }
  521.  
  522. Window_Minimap.prototype.setMapScroll = function(scroll_x, scroll_y)
  523. {
  524. var old_x = this.mapScroll.x = scroll_x;
  525. var source_w = this.drawAreaWidth * this.mapZoomInverse;
  526. this.mapScroll.x = this.clamp(this.mapScroll.x, 0, this.mapBmp.width - source_w);
  527. this.mapScroll.adjustment_x = old_x - this.mapScroll.x; // clamp difference
  528.  
  529. var old_y = this.mapScroll.y = scroll_y;
  530. var source_h = this.drawAreaHeight * this.mapZoomInverse;
  531. this.mapScroll.y = this.clamp(this.mapScroll.y, 0, this.mapBmp.width - source_h);
  532. this.mapScroll.adjustment_y = old_y - this.mapScroll.y; // clamp difference
  533. }
  534.  
  535. Window_Minimap.prototype.manualScroll = function(scroll_x, scroll_y)
  536. {
  537. this.setMapScroll(scroll_x, scroll_y);
  538. this.isManualScrolling = true;
  539. }
  540.  
  541. // Skips frame (returns true) if frameSkipCnt > frameSkip
  542. Window_Minimap.prototype.skipFrame = function()
  543. {
  544. if (this.frameSkip == 0) { return false; } // process frame
  545.  
  546. this.frameSkipCnt++;
  547. if (this.frameSkipCnt < this.frameSkip)
  548. {
  549. return true; // skip frame
  550. }
  551. else
  552. {
  553. this.frameSkipCnt = 0;
  554. return false; // process frame
  555. }
  556. }
  557.  
  558. Window_Minimap.prototype.updatePlayerBlink = function()
  559. {
  560. this.playerBlinkCnt--;
  561. if (this.playerBlinkCnt <= 0)
  562. {
  563. this.playerBlinkCnt = Silv.Minimap.PlayerBlinkDelay;
  564. this.playerBlink_IsVisible = !this.playerBlink_IsVisible;
  565. }
  566. }
  567.  
  568. Window_Minimap.prototype.updateFadeOut = function()
  569. {
  570. 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.
  571. if (this.isFadingOut) { this.fadeOut(); }
  572. }
  573.  
  574. Window_Minimap.prototype.fadeOut = function()
  575. {
  576. this.opacity = this.contentsOpacity -= Silv.Minimap.FadeoutSpeed;
  577. this.isFadedOut = (this.opacity <= 0);
  578. }
  579.  
  580. Window_Minimap.prototype.resetFade = function()
  581. {
  582. this.isFadingOut = false;
  583. this.fadeOutCnt = 0;
  584. this.opacity = this.contentsOpacity = 255;
  585. this.isFadedOut = false;
  586. }
  587.  
  588. Window_Minimap.prototype.fadeOutInstantly = function()
  589. {
  590. this.opacity = this.contentsOpacity = 0;
  591. this.isFadedOut = true;
  592. }
  593.  
  594. //----------------------------------------------------------------------------------------------------
  595. // #Rendering #Drawing
  596. //----------------------------------------------------------------------------------------------------
  597. Window_Minimap.prototype.drawMinimap = function()
  598. {
  599. this.contents.clear();
  600.  
  601. // BG fill colour, if applicable
  602. this.contents.fillRect(Silv.Minimap.BorderWidth, Silv.Minimap.BorderHeight, this.drawAreaWidth, this.drawAreaHeight, Silv.Minimap.MapBGFillColor);
  603.  
  604. switch(Silv.Minimap.MapStyle)
  605. {
  606. case 'autofit':
  607. this.drawstyleAutofit();
  608. break;
  609. case 'scroll':
  610. this.drawstyleScroll();
  611. break;
  612. default:
  613. throw 'Window_Minimap.prototype.drawMinimap invalid switch value: ' + Silv.Minimap.MapStyle;
  614. }
  615. }
  616.  
  617. Window_Minimap.prototype.drawstyleAutofit = function()
  618. {
  619. var destination_w = this.drawAreaWidth * this.mapAspRatInfo.w;
  620. var destination_h = this.drawAreaHeight * this.mapAspRatInfo.h;
  621.  
  622. // Calculate the aspect ratio offsets
  623. this.mapAspRatInfo.offset_x = 0.0; // to center the map
  624. this.mapAspRatInfo.offset_y = 0.0; // to center the map
  625. if (this.mapAspRatInfo.w < 1.0) { this.mapAspRatInfo.offset_x = (this.drawAreaWidth - destination_w) / 2.0; }
  626. if (this.mapAspRatInfo.h < 1.0) { this.mapAspRatInfo.offset_y = (this.drawAreaHeight - destination_h) / 2.0; }
  627.  
  628. // This variable saves on calculations further down the road during this update
  629. // w = width, hw= half width, zhw = zoomed half width
  630. this.tileInfo = {
  631. w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.mapAspRatInfo.w,
  632. h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.mapAspRatInfo.h
  633. };
  634.  
  635. // Draw Map
  636. 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);
  637.  
  638. // Debug Grid (if applicable)
  639. if (Silv.Minimap.DrawDebugGrid)
  640. {
  641. for (i=0; i < $gameMap.width(); i++)
  642. {
  643. for (j=0; j < $gameMap.height(); j++)
  644. {
  645. var testLoc = this.translateLocationAutofit(i, j, this.tileInfo.w * this.mapAspRatInfo.w, this.tileInfo.h * this.mapAspRatInfo.h);
  646. 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);
  647. }
  648. }
  649. }
  650.  
  651. // Draw POI's
  652. for (i = 0; i < Silv.Minimap.POI.length; i++)
  653. {
  654. var poi = Silv.Minimap.POI[i];
  655. var poiLoc = this.translateLocationAutofit(poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  656. this.contents.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
  657. poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
  658. }
  659.  
  660. // Draw Events
  661. for (i=0; i < Silv.Minimap.Events.length; i++)
  662. {
  663. var ev = Silv.Minimap.Events[i].event;
  664. var ev_sprite = Silv.Minimap.Events[i].sprite;
  665. var evMapLoc = this.translateLocationAutofit(ev._realX, ev._realY, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
  666. 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);
  667. }
  668.  
  669. // Draw Player
  670. if (Silv.Minimap.DrawPlayerIcon && this.playerBlink_IsVisible)
  671. {
  672. var playerMapLoc = this.translateLocationAutofit($gamePlayer._realX, $gamePlayer._realY, Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
  673. 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,
  674. playerMapLoc.x, playerMapLoc.y, Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
  675. }
  676.  
  677. // Overlay (if applicable)
  678. if(Silv.Minimap.DrawOverlay) { this.drawOverlay(); }
  679. }
  680.  
  681. Window_Minimap.prototype.drawstyleScroll = function()
  682. {
  683. // 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
  684. if (this.mapScroll.x < 0 || this.drawAreaWidth * this.mapZoomInverse > this.mapBmp.width ||
  685. this.mapScroll.y < 0 || this.drawAreaHeight * this.mapZoomInverse > this.mapBmp.height)
  686. {
  687. this.drawstyleAutofit();
  688. return;
  689. }
  690.  
  691. // This variable saves on calculations further down the road during this update
  692. // w = width, hw= half width, zhw = zoomed half width
  693. this.tileInfo = {
  694. w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.mapZoom,
  695. h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.mapZoom
  696. };
  697.  
  698. // Draw Map
  699. var map_src_rect = { x:0.0, y:0.0, w:0.0, h:0.0};
  700. map_src_rect.x = this.mapScroll.x;
  701. map_src_rect.y = this.mapScroll.y;
  702. map_src_rect.w = this.drawAreaWidth * this.mapZoomInverse;
  703. map_src_rect.h = this.drawAreaHeight * this.mapZoomInverse;
  704.  
  705. 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);
  706.  
  707. // Debug Grid (if applicable)
  708. if (Silv.Minimap.DrawDebugGrid)
  709. {
  710. for (i=0; i < $gameMap.width(); i++)
  711. {
  712. for (j=0; j < $gameMap.height(); j++)
  713. {
  714. var testLoc = this.translateLocationScroll(i, j, this.tileInfo.w * this.mapZoom, this.tileInfo.h * this.mapZoom);
  715. 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);
  716. }
  717. }
  718. }
  719.  
  720. // Draw POI's
  721. for (i = 0; i < Silv.Minimap.POI.length; i++)
  722. {
  723. var poi = Silv.Minimap.POI[i];
  724. var poiLoc = this.translateLocationScroll(poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  725. this.contents.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
  726. poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
  727. }
  728.  
  729. // Draw Events
  730. for (i=0; i < Silv.Minimap.Events.length; i++)
  731. {
  732. var ev = Silv.Minimap.Events[i].event;
  733. var ev_sprite = Silv.Minimap.Events[i].sprite;
  734. var evMapLoc = this.translateLocationScroll(ev._realX, ev._realY, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
  735. 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);
  736. }
  737.  
  738. // Draw Player
  739. if (Silv.Minimap.DrawPlayerIcon && this.playerBlink_IsVisible)
  740. {
  741. /* if (!this.isManualScrolling) // note to self, can't the player just be drawn without this if-statement?
  742. {
  743. var playerLoc_x = this.drawAreaWidth / 2.0 + this.mapScroll.adjustment_x * this.mapZoom;
  744. var playerLoc_y = this.drawAreaHeight / 2.0 + this.mapScroll.adjustment_y * this.mapZoom;
  745. // Now center the location in the center of the tiles instead of the topleft corner
  746. playerLoc_x += this.tileInfo.zhw - Silv.Minimap.PlayerIconWidth / 2.0;
  747. playerLoc_y += this.tileInfo.zhh - Silv.Minimap.PlayerIconHeight / 2.0;
  748. 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,
  749. Silv.Minimap.BorderWidth + playerLoc_x, Silv.Minimap.BorderHeight + playerLoc_y, Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
  750. }
  751. else
  752. {*/
  753. var playerLoc = this.translateLocationScroll($gamePlayer._realX, $gamePlayer._realY, Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
  754. 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,
  755. playerLoc.x, playerLoc.y, Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
  756. //}
  757. }
  758. // Overlay (if applicable)
  759. if(Silv.Minimap.DrawOverlay) { this.drawOverlay(); }
  760. }
  761.  
  762. Window_Minimap.prototype.drawOverlay = function()
  763. {
  764. this.contents.blt(this.overlayBmp, 0, 0, this.overlayBmp.width, this.overlayBmp.height, 0, 0, this.width, this.height);
  765. }
  766.  
  767. // #Translate
  768. // returns {x, y}
  769. Window_Minimap.prototype.translateLocationScroll = function(obj_real_x, obj_real_y, obj_w, obj_h)
  770. {
  771. 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;
  772. 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;
  773. return {x: obj_x, y: obj_y};
  774. }
  775.  
  776. // returns {x, y}
  777. Window_Minimap.prototype.translateLocationAutofit = function(obj_real_x, obj_real_y, obj_w, obj_h)
  778. {
  779. 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;
  780. 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;
  781. return {x: obj_x, y: obj_y};
  782. }
  783. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  784. // POI
  785. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  786. function MM_POI() { this.initialize.apply(this, arguments); }
  787. // Set Constructor
  788. MM_POI.prototype.constructor = MM_POI;
  789.  
  790. // Initialization
  791. MM_POI.prototype.initialize = function(real_x, real_y, bmp, source_x, source_y, source_w, source_h, draw_w, draw_h)
  792. {
  793. this.real_x = real_x;
  794. this.real_y = real_y;
  795. this.bmp = bmp;
  796. this.src = { x:source_x, y:source_y, w:source_w, h:source_h };
  797. this.destSize = { w:draw_w, h:draw_h };
  798. }
  799. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  800. // Create the Minimap window
  801. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  802. Scene_Map.prototype.createMinimapWindow = function()
  803. {
  804. x = 0;
  805. if (Silv.Minimap.WindowHorizontalAlignment == 'right') { x = Graphics.width - Silv.Minimap.WindowWidth; }
  806. y = 0;
  807. if (Silv.Minimap.WindowVerticalAlignment == 'bottom') { y = Graphics.height - Silv.Minimap.WindowHeight; }
  808.  
  809. 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);
  810. Silv.Minimap.Window.resetFade();
  811.  
  812. // override frameskip (map-specific frameskip)
  813. if ('mm_frameskip' in $dataMap.meta)
  814. {
  815. Silv.Minimap.Window.frameSkip = parseInt($dataMap.meta.mm_frameskip);
  816. if (Silv.Minimap.DebugMode) { console.log('Global frameskip: ' + Silv.Minimap.FrameSkip + ' was overriden by the map-specific frameskip of: ' + $dataMap.meta.mm_frameskip + '.'); }
  817. }
  818.  
  819. this.addChildAt(this.window_Minimap, 1);
  820. }
  821.  
  822. Scene_Map.prototype.AttemptToCreateMinimap = function()
  823. {
  824. var mapname = lpad_mapname($gameMap._mapId, '0') + '.png';
  825. if (minimapImageExists(mapname))
  826. {
  827. if (this.MinimapHasRequiredItems())
  828. {
  829. this.createMinimapWindow();
  830. }
  831. }
  832. else
  833. {
  834. if (Silv.Minimap.DebugMode) { console.log('No minimap \'' + mapname + '\' found for map with map-id: ' + $gameMap._mapId + '.'); }
  835. }
  836. }
  837.  
  838. var alias_silver_mm_createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
  839. Scene_Map.prototype.createDisplayObjects = function()
  840. {
  841. alias_silver_mm_createDisplayObjects.call(this);
  842.  
  843. if (Silv.Minimap.AutoClearPOI) { Silv.Minimap.POI = new Array(); }
  844.  
  845. this.AttemptToCreateMinimap();
  846. }
  847.  
  848. Scene_Map.prototype.MinimapHasRequiredItems = function()
  849. {
  850. // Check global item
  851. if (Silv.Minimap.GlobalRequiredItem > 0)
  852. {
  853. if (!$gameParty.hasItem($dataItems[Silv.Minimap.GlobalRequiredItem], false))
  854. {
  855. if (Silv.Minimap.DebugMode) { console.log('Minimap was found but party does not possess the required global item: ' + $dataItems[Silv.Minimap.GlobalRequiredItem].name); }
  856. return false;
  857. }
  858. }
  859.  
  860. // Check map-specific items
  861. if ('mm_req_itm' in $dataMap.meta)
  862. {
  863. var req_item_ids = $dataMap.meta.mm_req_itm.split(' ').filter(Boolean); // .filter(Boolean) removes empty strings from array
  864. for (i = 0; i < req_item_ids.length; i++)
  865. {
  866. if (!$gameParty.hasItem($dataItems[req_item_ids[i]], false))
  867. {
  868. 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); }
  869. return false;
  870. }
  871. }
  872. }
  873.  
  874. return true;
  875. }
  876. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  877. // Plugin Command
  878. // Note: The items are separated by spaces. The command is the first word and any following words are args. args is an array.
  879. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  880. var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  881. Game_Interpreter.prototype.pluginCommand = function(command, args)
  882. {
  883. _Game_Interpreter_pluginCommand.call(this, command, args);
  884. if (command.toLowerCase() == 'minimap') { PluginCommand(command, args); }
  885. }
  886.  
  887. function PluginCommand(cmd, args)
  888. {
  889. switch(args[0].toLowerCase())
  890. {
  891. case 'hide':
  892. Silv.Minimap.Window.hide();
  893. break;
  894. case 'show':
  895. Silv.Minimap.Window.show();
  896. break;
  897. case 'fadeout':
  898. Silv.Minimap.Window.isFadingOut = true;
  899. break;
  900. case 'fadereset':
  901. Silv.Minimap.Window.resetFade();
  902. break;
  903. case 'refresh':
  904. SceneManager._scene.AttemptToCreateMinimap();
  905. break;
  906. case 'addpoi': //Minimap addpoi real_x, real_y, bitmap folder, bitmap filename, s_x, s_y, s_w, s_h, draw_w, draw_h
  907. 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])));
  908. SceneManager._scene.AttemptToCreateMinimap();
  909. break;
  910. case 'refreshevents':
  911. Silv.Minimap.Window.loadEvents();
  912. break;
  913. case 'increasescroll':
  914. Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x + parseFloat(args[1]), Silv.Minimap.Window.mapScroll.y + parseFloat(args[2]));
  915. break;
  916. case 'setscroll':
  917. Silv.Minimap.Window.manualScroll(parseFloat(args[1]), parseFloat(args[2]));
  918. break;
  919. default:
  920. throw 'Minimap, unknown Plugin Command: ' + args[0];
  921. }
  922. }
  923. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  924. })();
Advertisement
Add Comment
Please, Sign In to add comment