Advertisement
CompanionWulf

Map/Compass HUD (RMMV) v1.0

Mar 7th, 2016
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=======================================================================
  2. // Map/Compass HUD (RMMV) v1.0
  3. //=======================================================================
  4. // * The Map/Compass HUD  displays a window on the  map showing the map
  5. //   name and player coordinates.
  6. //
  7. //   This was originally created for the first "Paranormality" game for
  8. //   RMXP, which was then ported over to RMVX (mainly to see if I could
  9. //   do it). When development on "Otherworld" officially transferred to
  10. //   RMVXA, the script was also converted to RGSS3.
  11. //
  12. //   After the  decision to migrate  "Otherworld" to RMMV was made,  it
  13. //   naturally  followed that the  main scripts  would also  need to be
  14. //   converted to JGSS.
  15. //
  16. //       * © 2014-2016, Companion Wulf
  17. //
  18. //========================================================================
  19. // CW_MapCompassHud.js
  20. //========================================================================
  21.  
  22. var Imported = Imported || {}; Imported.CW_MapCompassHud = true;
  23. var CWT = CWT || {}; CWT.MapHud = CWT.MapHud || {};
  24.  
  25. CWT.Version = 1.0;
  26. CWT.Build = 11.7;
  27. CWT.Copyright = '© 2014-2016, Companion Wulf';
  28.  
  29.  
  30. /*:
  31.  @plugindesc Displays a window on the map with map name and player coordinates.
  32.  @author Companion Wulf
  33.  
  34.  @param Map HUD Default
  35.  @desc Automatically show/hide the map/compass HUD by default.
  36.  @default Show
  37.  
  38.  @param Map HUD Toggle
  39.  @desc Toggles the map/compass HUD on/off.
  40.  @default On
  41.  
  42.  @param Map HUD Position
  43.  @desc Sets the map/compass HUD position. TR = Top right; BR = Bottom right; TL = Top left; BL = Bottom left.
  44.  @default TR
  45.  
  46.  @param Map HUD Opacity
  47.  @desc Sets the opacity of the map/compass HUD.
  48.  @default 160
  49.  
  50.  @param Show Location
  51.  @desc Show/hide map location. True/false.
  52.  @default true
  53.  
  54.  @param Unknown Location
  55.  @desc Text to show if map display name is not defined.
  56.  @default Unknown
  57.  
  58.  @param Show Coordinates
  59.  @desc Show/hide player coordinates on the map.
  60.  @default true
  61.  
  62.  @param Show Compass Points
  63.  @desc Show/hide compass cardinal points.
  64.  @default true
  65.  
  66.  @param Show Compass Icons
  67.  @desc Show/hide icons for compass points.
  68.  @default true
  69.  
  70.  @param Compass Icon Filename
  71.  @desc The name of the iconset to use for the compass icons.
  72.  @default CompassIconSet
  73.  
  74.  
  75.  
  76.  @help
  77.  --------------------------------------------------------------
  78.   Compass Icons
  79.  --------------------------------------------------------------
  80.  The Map/Compass HUD plugin uses a separate iconset, rather than
  81.  modify the default system one.
  82.  
  83.  In this case, it's named "CompassIconSet", but you can create
  84.  your own with the four compass points. If you do use your own,
  85.  be sure to change the "Compass Icon Filename" parameter and
  86.  place your file in the "img/system" folder.
  87.  
  88.  The example iconset I've used can be downloaded here:
  89.  
  90.     https://goo.gl/qe3Gdn
  91.  
  92.  --------------------------------------------------------------
  93.   Plugin Commands
  94.  --------------------------------------------------------------
  95.  
  96.  In the event Plugin Command, use HUD followed by:
  97.  
  98.  show - Show the map/compass window on the map.
  99.  
  100.  hide - Hide the map/compass window on the map.
  101.  
  102.  
  103.  --------------------------------------------------------------
  104.   Terms & Conditions of Use
  105.  --------------------------------------------------------------
  106.  This plugin is free to use under CC BY-SA 4.0, but please refer to the
  107.  RPG Maker Times blogsite for other details, including commercial use.
  108.  
  109. Credit "Companion Wulf" or "RPG Maker Times" if using this plugin in
  110. your projects.
  111.  
  112.  */
  113.  
  114.  
  115. /*
  116.     ** STILL TO DO **
  117.     --Add meta map/compass HUD toggle plugin commands
  118.     --Add diagonal directions
  119.     --Dynamic window sizing for disabled elements
  120. */
  121.  
  122.  
  123.  (function() {
  124.      
  125.     //-----------------------------------------------------------------------------
  126.     // ** System Variables **
  127.     //-----------------------------------------------------------------------------
  128.     // * Version/Copyright
  129.     CWT.MapHud.releaseVersion = function() { return Number(CWT.Version).toFixed(1); };
  130.     CWT.MapHud.buildVersion = function() { return Number(CWT.Build).toFixed(2); };
  131.     CWT.MapHud.copyright = function() { return String(CWT.Copyright); };
  132.    
  133.     // * Icons Dimensions
  134.     CWT.MapHud.iconWidth = 32;
  135.     CWT.MapHud.iconHeight = 32;
  136.    
  137.     //-----------------------------------------------------------------------------
  138.     // ** Parameters **
  139.     //-----------------------------------------------------------------------------
  140.     CWT.parameters = PluginManager.parameters('CW_MapCompassHud');
  141.     CWT.mapHudDefault = String(CWT.parameters['Map HUD Default'] || 'Show');
  142.     CWT.mapHudToggle = String(CWT.parameters['Map HUD Toggle'] || 'On');
  143.     CWT.mapHudPosition = String(CWT.parameters['Map HUD Position'] || 'TR');
  144.     CWT.mapHudOpacity = Number(CWT.parameters['Map HUD Opacity'] || 160);
  145.     CWT.showMapLocation = String(CWT.parameters['Show Location'] || 'True');
  146.     CWT.unknownLocation = String(CWT.parameters['Unknown Location'] || 'Unknown');
  147.     CWT.showCoordinates = String(CWT.parameters['Show Coordinates'] || 'True');
  148.     CWT.showCompass = String(CWT.parameters['Show Coordinates'] || 'True');
  149.     CWT.showCompassIcons = String(CWT.parameters['Show Compass Icons'] || 'True');
  150.     CWT.compassIconsFiles = String(CWT.parameters['Compass Icon Filename'] || 'CompassIconSet');
  151.    
  152.     //-----------------------------------------------------------------------------
  153.     // ** Parameters Variables **
  154.     //-----------------------------------------------------------------------------
  155.     // * Map Variables
  156.     CWT.MapHud._mapHudWindowShow = CWT.mapHudDefault;
  157.    
  158.     //-----------------------------------------------------------------------------
  159.     // ** Plugin Manager **
  160.     //-----------------------------------------------------------------------------
  161.     CWT.MapHud.GameInterpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  162.     Game_Interpreter.prototype.pluginCommand = function(command, args) {
  163.         CWT.MapHud.GameInterpreter_pluginCommand.apply(this);
  164.         if (command.toUpperCase() === 'HUD') {
  165.             switch(args[0]) {
  166.             case 'show':
  167.                 CWT.MapHud._mapHudWindowShow = true;
  168.                 break;
  169.             case 'hide':
  170.                 CWT.MapHud._mapHudWindowShow = false;
  171.                 break;
  172.             }
  173.         }
  174.     };
  175.    
  176.    
  177.     //-----------------------------------------------------------------------------
  178.     // ** Scene_Map **
  179.     //-----------------------------------------------------------------------------
  180.     // * Initialize
  181.     CWT.MapHud.CW_SceneMap_start = Scene_Map.prototype.start;
  182.     Scene_Map.prototype.start = function() {
  183.         CWT.MapHud.CW_SceneMap_start.call(this);
  184.         this.createHudWindow();
  185.     };
  186.    
  187.     // * Update
  188.     CWT.MapHud.CW_SceneMap_update = Scene_Map.prototype.update;
  189.     Scene_Map.prototype.update = function() {
  190.         CWT.MapHud.CW_SceneMap_update.call(this);
  191.         CWT.MapHud._mapHudWindowShow ? this._mapHudWindow.show() : this._mapHudWindow.hide();
  192.         this._mapHudWindow.refresh();
  193.     };
  194.    
  195.     // * Create Hud Window
  196.     Scene_Map.prototype.createHudWindow = function() {
  197.         switch (CWT.mapHudPosition.toUpperCase()) {
  198.             case 'TL': var x = 5; var y = 5; break;
  199.             case 'BL': var x = 5; var y = 476; break;
  200.             case 'TR': var x = 631; var y = 5; break;
  201.             case 'BR': var x = 631; var y = 476; break;
  202.         };
  203.         this._mapHudWindow = new Window_MapHud(x, y);
  204.         this._mapHudWindow.opacity = CWT.mapHudOpacity;
  205.         this.addChild(this._mapHudWindow);
  206.     };
  207.    
  208.    
  209.    
  210.    
  211.     //-----------------------------------------------------------------------------
  212.     // ** Window_MapHud **
  213.     //-----------------------------------------------------------------------------
  214.     function Window_MapHud() {
  215.         this.initialize.apply(this, arguments);
  216.     }
  217.    
  218.     Window_MapHud.prototype = Object.create(Window_Base.prototype);
  219.     Window_MapHud.prototype.constructor = Window_MapHud;
  220.    
  221.     // * Initialize
  222.     Window_MapHud.prototype.initialize = function(x, y) {
  223.         var width = this.windowWidth();
  224.         var height = this.windowHeight();
  225.         Window_Base.prototype.initialize.call(this, x, y, width, height);
  226.         this.opacity = CWT.mapHudOpacity;
  227.         this.refresh();
  228.     };
  229.    
  230.     // * Window Width
  231.     Window_MapHud.prototype.windowWidth = function() {
  232.         return 180;
  233.     };
  234.  
  235.     // * Window Height
  236.     Window_MapHud.prototype.windowHeight = function() {
  237.         return this.fittingHeight(3);
  238.     };
  239.    
  240.     // * Window Refresh
  241.     Window_MapHud.prototype.refresh = function() {
  242.         if (!$gamePlayer.isMoving()) $gameMap.refreshIfNeeded();
  243.         this.contents.fontSize = 13;
  244.         var x = this.textPadding(); var y = 0;
  245.         var lh = this.lineHeight()/2;
  246.         var width = this.windowWidth - (this.contents.width - this.textPadding() * 2);
  247.         var height = this.windowHeight - this.contents.height;
  248.         this.contents.clear();
  249.        
  250.         // * Show Map Location
  251.         if (CWT.showMapLocation.toUpperCase() == 'TRUE') {
  252.             this.drawText('Location:', x, y, width, height);
  253.             this.changeTextColor('lightblue');
  254.             this.drawText($gameMap.displayName() || CWT.unknownLocation, x+60, y, width, height);
  255.             this.resetTextColor();
  256.             var y = y + lh * 2;
  257.         };
  258.        
  259.         // * Show Compass Points
  260.         if (CWT.showCompass.toUpperCase() == 'TRUE') {
  261.             var _iconIndex = 0;
  262.             switch($gamePlayer._direction) {
  263.                 case 2:
  264.                     var direction = 'South';
  265.                     var _iconIndex = 4;
  266.                     break;
  267.                 case 4:
  268.                     var direction = 'West';
  269.                     var _iconIndex = 3;
  270.                     break;
  271.                 case 6:
  272.                     var direction = 'East';
  273.                     var _iconIndex = 2;
  274.                     break;
  275.                 case 8:
  276.                     var direction = 'North';
  277.                     var _iconIndex = 1;
  278.                     break;
  279.             };
  280.             this.drawCompassIcon(_iconIndex, 0, 32);
  281.             this.drawText(direction, x+50, y, width, height);
  282.             var y = y + lh * 2;
  283.         };
  284.        
  285.         // * Show Coordinates
  286.         if (CWT.showCoordinates.toUpperCase() == 'TRUE') {
  287.             this.drawText('X:', x, y, width, height);
  288.             this.drawText('Y:', x+60, y, width, height);
  289.             this.changeTextColor('lightblue');
  290.             this.drawText($gamePlayer.x, x+16, y, width, height);
  291.             this.drawText($gamePlayer.y, x+76, y, width, height);
  292.             this.resetTextColor();
  293.         };
  294.     };
  295.    
  296.     Window_MapHud.prototype.drawCompassIcon = function(iconIndex, x, y) {
  297.         var bitmap = ImageManager.loadSystem(CWT.compassIconsFiles);
  298.         var iw = CWT.MapHud.iconWidth;
  299.         var ih = CWT.MapHud.iconHeight;
  300.         var ix = iconIndex % 16 * iw;
  301.         var iy = Math.floor(iconIndex / 16) * ih;
  302.         this.contents.blt(bitmap, ix, iy, iw, ih, x, y);
  303.     };
  304.    
  305.      
  306.      
  307.  })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement