MOG_MapNameHud.js【中文注解】【地图名称显示】

//=============================================================================
// MOG_MapNameHud.js
// 作用:进入地图,指定位置限制地图名称,可调整显示位置,持续时间,让玩家清楚的知道自己到哪儿了。
// 注:编辑地图的时候,有“地图名称”、“显示名称”,该插件使用“显示名称”
//=============================================================================

/*:
 * @plugindesc (v1.0) 自动显示地图的名字
 * @author Moghunter
 *
 * @param Hud X-Axis
 * @desc Definição da posição X-Axis da Hud. //显示框X轴
 * @default 250
 *
 * @param Hud Y-Axis
 * @desc Definição da posição Y-Axis da Hud. //显示框Y轴
 * @default 32
 *
 * @param Name X-Axis
 * @desc Definição da posição X-Axis do nome. //地图名称X轴
 * @default 105
 *
 * @param Name Y-Axis
 * @desc Definição da posição Y-Axis do nome. //地图名称Y轴
 * @default 30
 *
 * @param Duration
 * @desc Definição do tempo de apresentação. //显示持续时间
 * @default 120
 *
 * @param Font Size
 * @desc Definição do tamanho da fonte. //字体大小
 * @default 20
 *   
 * @help  
 * =============================================================================
 * +++ MOG Map Name Hud(v1.0) +++
 * By Moghunter 
 * https://atelierrgss.wordpress.com/
 * =============================================================================
 * Apresenta uma Hud com o nome do mapa.
 * Serão necessários os arquivos. (img/system/)
 *
 * MapName.png //显示框图片
 * 
 */

//=============================================================================
// ** PLUGIN PARAMETERS
//=============================================================================

//=============================================================================
// ** PLUGIN PARAMETERS
//=============================================================================
  var Imported = Imported || {};
  Imported.MOG_MapNameHud = true;
  var Moghunter = Moghunter || {}; 

   Moghunter.parameters = PluginManager.parameters('MOG_MapNameHud');
    //显示框参数
    Moghunter.mhud_pos_x = Number(Moghunter.parameters['Hud X-Axis'] || 250);
    Moghunter.mhud_pos_y = Number(Moghunter.parameters['Hud Y-Axis'] || 32);
    //地图名称参数
    Moghunter.mhud_text_x = Number(Moghunter.parameters['Name X-Axis'] || 105);
    Moghunter.mhud_text_y = Number(Moghunter.parameters['Name Y-Axis'] || 30);
    Moghunter.mhud_duration = Number(Moghunter.parameters['Duration'] || 120);
    Moghunter.mhud_fontsize = Number(Moghunter.parameters['Font Size'] || 20);

//=============================================================================
// ** Game_Temp
//=============================================================================

//==============================
// * Initialize
// * Game_Temp游戏临时参数,不做存储
//==============================
var _alias_mog_mhud_temp_initialize = Game_Temp.prototype.initialize;
Game_Temp.prototype.initialize = function() {
    _alias_mog_mhud_temp_initialize.call(this);
    this._mhud_sprite = [false,0,0];
    this._mhud_data = [false,null,0];
};

//=============================================================================
// ** Spriteset Map
//=============================================================================

//==============================
// * Create Upper Layer
//==============================
var _alias_mog_mhud_sprmap_createUpperLayer = Spriteset_Map.prototype.createUpperLayer;
Spriteset_Map.prototype.createUpperLayer = function() {
    _alias_mog_mhud_sprmap_createUpperLayer.call(this);
    this.create_mapname_hud();
};

//==============================
// * Create Map Name HUD
// * 创建地图名称显示
//==============================
Spriteset_Map.prototype.create_mapname_hud = function() {
    this._mapNameHud = new Map_Name_Hud();
    this.addChild(this._mapNameHud);
    if (this.needRefreshMhud()) { //刷新检查
        $gameTemp._mhud_data[0] = true;
        $gameTemp._mhud_data[1] = $gameMap.displayName();
    };
    if ($gameTemp._mhud_data[2] != $gameMap._mapId) {
        $gameTemp._mhud_sprite = [false,0,0]
    };
    $gameTemp._mhud_data[2] = $gameMap._mapId;
}; 

//==============================
// * Need Refresh MHud
// * 名称显示是否可用
// * 临时参数_mhud_data[2]与地图中地图Id是否一致
// * 地图显示名称为是否空
//==============================
Spriteset_Map.prototype.needRefreshMhud = function() {
    if (!$gameMap.isNameDisplayEnabled()) {return false};
    if ($gameTemp._mhud_data[2] === $gameMap._mapId) {return false};
    if (!$gameMap.displayName()) {return false};
    return true;
};

//=============================================================================
// * Map_Name_Hud
//=============================================================================
function Map_Name_Hud() {
    this.initialize.apply(this, arguments);
};

//继承自Sprite
Map_Name_Hud.prototype = Object.create(Sprite.prototype);
Map_Name_Hud.prototype.constructor = Map_Name_Hud;

//==============================
// * Initialize
//==============================
Map_Name_Hud.prototype.initialize = function() {    
    Sprite.prototype.initialize.call(this); 
    //位置信息
    this._pos_x = Moghunter.mhud_pos_x;
    this._pos_y = Moghunter.mhud_pos_y; 
    this.load_img(); //加载显示框指向this._layout_img
    this.create_sprites(); //创建显示精灵
    this.opacity = $gameTemp._mhud_sprite[1]; //临时参数中取透明度
    this.refresh();
};

//==============================
// * Load Img
//==============================
Map_Name_Hud.prototype.load_img = function() {
    this._layout_img = ImageManager.loadSystem("MapName");
};

//==============================
// * Create Layout
//==============================
Map_Name_Hud.prototype.create_layout = function() {
    this._layout = new Sprite(this._layout_img);
    this._layout.x = this._pos_x;
    this._layout.y = this._pos_y;
    this.addChild(this._layout);
};

//==============================
// * Create Text
// * 名称字符创建
//==============================
Map_Name_Hud.prototype.create_text = function() {
    this._text = new Sprite(new Bitmap(160,32));
    this._text.x = this._pos_x + Moghunter.mhud_text_x;
    this._text.y = this._pos_y + Moghunter.mhud_text_y;
    this._text.bitmap.fontSize = Moghunter.mhud_fontsize;
    this.addChild(this._text);
};

//==============================
// * Create Sprites
//==============================
Map_Name_Hud.prototype.create_sprites = function() {
     this.create_layout();
     this.create_text();     
};

//==============================
// * Name
// * 地图显示名称
//==============================
Map_Name_Hud.prototype.name = function() {
     return $gameTemp._mhud_data[1];
};

//==============================
// * Refresh Init
//==============================
Map_Name_Hud.prototype.refresh_init = function() {
  $gameTemp._mhud_data[0] = false;
  $gameTemp._mhud_sprite = [true,0,0];
  this.x = -50;
  this.opacity = 0;
};

//==============================
// * Refresh
//==============================
Map_Name_Hud.prototype.refresh = function() {
    if ($gameTemp._mhud_data[0]) {
        this.refresh_init()
    };  
    if (!this.name()) {return};
    this.refresh_name();
};

//==============================
// * Refresh Name
//==============================
Map_Name_Hud.prototype.refresh_name = function() {
    this._text.bitmap.clear();
    this._text.bitmap.drawText(this.name(),0,0,160,32,"center");
};

//==============================
// * Update visible
// * 淡入、持续展示、淡出
//==============================
Map_Name_Hud.prototype.update_position = function() {
    $gameTemp._mhud_sprite[1] += 1;
    if ($gameTemp._mhud_sprite[1] < 30) {
        this.opacity += 8.5;    
        this.x += 1.6;
    } else if ($gameTemp._mhud_sprite[1] < 20 + Moghunter.mhud_duration) {
        this.x = 0; 
        this.opacity = 255;
    } else { 
        this.opacity -= 8.5;    
        this.x += 1.6;
        if (this.opacity === 0) {
            $gameTemp._mhud_sprite[0] = false
        };
    };
};

//==============================
// * Update
//==============================
Map_Name_Hud.prototype.update = function() {    
    Sprite.prototype.update.call(this); 
    if ($gameTemp._mhud_sprite[0]) {
        this.update_position()
    } else {
        this.opacity = 0
    };
    if ($gameTemp._mhud_data[0]) {this.refresh()};
};

//=============================================================================
// * Refresh
//=============================================================================

//==============================
// * Refresh
//==============================
Window_MapName.prototype.refresh = function() {
     this.contents.clear(); 
};
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。