设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 54|回复: 0

[转载发布] SimpleText: Format and display text on map interface Version 1.3

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    慵懒
    3 天前
  • 签到天数: 207 天

    连续签到: 1 天

    [LV.7]常住居民III

    3646

    主题

    862

    回帖

    2万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    21262
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    25800

    灌水之王

    发表于 前天 11:30 | 显示全部楼层 |阅读模式
    Code:        
    /*: * @plugindesc Display texts on screen. Version: 2.0 * @author Rui * @help * ---------------------------------------- * SimpleText Write Text Args * ---------------------------------------- * write text on screen. all texts will be saved with map, only need to add once. *  * Text *       String without spaces. Apple_tree will be displayed as Apple tree. * Args *       eventID: event id which text will be centered at. value of -1 indicates player. ignore this parameter indicates center of screen. *       offsetX/offsetY: Offset from original position. Default: 0. *       duration: text display duration. value of 0 or less indicates permanent. default: 0.   *       moveX/moveY: movement of text. default: 0. *       isFollow: whether text follows event or not. this parameter is ignored when eventID is ignored. defualt: true   *       group: texts can be cleard by group. case insensitive. default: ALL. *       eg. SimpleText Write Player_1 eventID:-1,duration:0,isFollow:true *       eg. SimpleText Write -1 eventID:-1,duration:1000,isFollow:false,moveY:1 *       eg. SimpleText Write Map_1 offsetY:200 *       parameters are separated by comma. spaces are not allowed. *       all commands are case insensitive. * * ---------------------------------------- * SimpleText Font Args * ---------------------------------------- * setup font. call this command will not affect texts that have already been created. *  * Args *       font, size, isItalic, color, outlineWidth, outlineColor, opacity *       eg. SimpleText Font font:GameFont,color:#910010,size:26,outlineColor:rgba(0,0,0,0.5),opacity:255 *       parameters are separated by comma. spaces are not allowed. *       all commands are case insensitive. *         * ---------------------------------------- * SimpleText ClearAll * SimpleText ClearMap * SimpleText ClearByEventID eventID * SimpleText ClearByGroup group * ---------------------------------------- * clear texts on screen * Args *       eventID: clear all texts bind to this event. *       group: clear all texts bind to this group.         eg. SimpleText ClearByEventID -1 *       all commands are case insensitive. * * * License: Free for personal and commercial use */   (function() {     //SimpleText     function SimpleText() {         this.simpleTextObjList = {};    //dictionary with mapID as key         this.fontFace = "GameFont";         this.fontSize = 21;         this.fontItalic = false;         this.textColor = "#ffffff";         this.outlineColor = "rgba(0,0,0,0.5)";         this.outlineWidth = 2;         this.opacity = 255;     }      SimpleText.prototype.changeFont = function(args) {         var commandList = args.split(',');          for (var i = commandList.length - 1; i >= 0; i--) {             var command = commandList.toUpperCase();              if (command.lastIndexOf("FONT:", 0) === 0) {                 this.fontFace = command.substring("FONT:".length).replace(/_/g, " ");             }             else if (command.lastIndexOf("SIZE:", 0) === 0) {                 this.fontSize = parseInt(command.substring("SIZE:".length));             }             else if (command.lastIndexOf("ISITALIC:", 0) === 0) {                 this.fontItalic = command.substring("ISITALIC:".length) === "TRUE";             }             else if (command.lastIndexOf("COLOR:", 0) === 0) {                 this.textColor = command.substring("COLOR:".length);             }             else if (command.lastIndexOf("OUTLINEWIDTH:", 0) === 0) {                 this.outlineWidth = parseInt(command.substring("OUTLINEWIDTH:".length));             }             else if (command.lastIndexOf("OUTLINECOLOR:", 0) === 0) {                 this.outlineColor = command.substring("OUTLINECOLOR:".length);             }             else if (command.lastIndexOf("OPACITY:", 0) === 0) {                 this.opacity = parseInt(command.substring("OPACITY:".length));             }         }     }      SimpleText.prototype.getSimpleTextObjListByMapID = function() {         var mapID = $gameMap.mapId().toString();         if (DataManager.___simpleText___.simpleTextObjList.hasOwnProperty(mapID)) {             return DataManager.___simpleText___.simpleTextObjList[mapID];         }         else {             DataManager.___simpleText___.simpleTextObjList[mapID] = [];             return DataManager.___simpleText___.simpleTextObjList[mapID];         }             };         //SimpleTextObj object     function SimpleTextObj(text, args) {         this.text = text.replace(/_/g, " ");         this.eventID = null;         this.duration = null;         this.offsetX = 0;         this.offsetY = 0;         this.moveX = 0;         this.moveY = 0;         this.isFollow = true;         this.group = "ALL";          this.fontFace = DataManager.___simpleText___.fontFace;         this.fontSize = DataManager.___simpleText___.fontSize;         this.fontItalic = DataManager.___simpleText___.fontItalic;         this.textColor = DataManager.___simpleText___.textColor;         this.outlineColor = DataManager.___simpleText___.outlineColor;         this.outlineWidth = DataManager.___simpleText___.outlineWidth;         this.opacity = DataManager.___simpleText___.opacity;          var commandList = args.split(',');          for (var i = commandList.length - 1; i >= 0; i--) {             var command = commandList.toUpperCase();              if (command.lastIndexOf("EVENTID:", 0) === 0) {                 this.eventID = parseInt(command.substring("EVENTID:".length));             }             else if (command.lastIndexOf("DURATION:", 0) === 0) {                 this.duration = parseInt(command.substring("DURATION:".length));                 if (this.duration <= 0)                     this.duration = null;             }             else if (command.lastIndexOf("OFFSETX:", 0) === 0) {                 this.offsetX = parseInt(command.substring("OFFSETX:".length));             }             else if (command.lastIndexOf("OFFSETY:", 0) === 0) {                 this.offsetY = parseInt(command.substring("OFFSETY:".length));                 this.offsetY = this.offsetY * -1;             }             else if (command.lastIndexOf("MOVEX:", 0) === 0) {                 this.moveX = parseInt(command.substring("MOVEX:".length));             }             else if (command.lastIndexOf("MOVEY:", 0) === 0) {                 this.moveY = parseInt(command.substring("MOVEY:".length));                 this.moveY = this.moveY * -1;             }             else if (command.lastIndexOf("ISFOLLOW:", 0) === 0) {                 this.isFollow = command.substring("ISFOLLOW:".length);                 this.isFollow = this.isFollow === "TRUE"             }             else if (command.lastIndexOf("GROUP:", 0) === 0) {                 this.group = command.substring("GROUP:".length);             }         }          if (this.eventID != null && this.isFollow == false) {             var event = this.findEvent();             this.startX = event._realX;             this.startY = event._realY;             this.adjustY = event.shiftY() + event.jumpHeight();         }          this.delete = false;          DataManager.___simpleText___.getSimpleTextObjListByMapID().push(this);     }      //add sprite when creating text or starting scene     SimpleTextObj.prototype.addSprite = function(spriteset_Map, x, y) {         var sprite = new Sprite();         sprite.anchor.x = 0.5;         sprite.anchor.y = 1;         sprite.z = 9;         sprite.bitmap = new Bitmap(this.fontSize * this.text.length + this.outlineWidth * 2 + 6, this.fontSize + this.outlineWidth * 2 + 6);         sprite.bitmap.fontFace = this.fontFace;         sprite.bitmap.fontSize = this.fontSize;         sprite.bitmap.fontItalic = this.fontItalic;         sprite.bitmap.textColor = this.textColor;         sprite.bitmap.outlineColor = this.outlineColor;         sprite.bitmap.outlineWidth = this.outlineWidth;         sprite.bitmap.drawText(this.text, 0, 0, sprite.bitmap.width, sprite.bitmap.height, "center");         sprite.opacity = this.opacity;         sprite.___simpleTextObjRef___ = this;          spriteset_Map._tilemap.addChild(sprite);          sprite.x = x;         sprite.y = y;          return sprite;     };      //get event     SimpleTextObj.prototype.findEvent = function() {         if ($gameParty.inBattle()) {             return null;         }         else if (this.eventID == null) {             return null;         }         else if (this.eventID < 0) {             return $gamePlayer;         }         else {             return $gameMap.event(this.eventID);         }     }      //update function     SimpleTextObj.prototype.update = function(index, spriteset_Map) {         var event = null;         var found = false;         var child = null;          //if event is null         if (this.delete == false) {             if (this.eventID != null) {                 event = this.findEvent();                 if (event == null) {                     this.delete = true;                 }             }         }          //if duration not null         if (this.delete == false) {             if (this.duration != null) {                 this.duration--;                 if (this.duration <= 0) {                     this.delete = true;                 }             }         }          for (var i = spriteset_Map._tilemap.children.length - 1; i >= 0; i--) {             child = spriteset_Map._tilemap.children;              if (typeof(child.___simpleTextObjRef___)==='undefined') {                 continue;             }             else {                 if (child.___simpleTextObjRef___ == this) {                     found = true;                      if (this.delete == true) {                         child.bitmap = null;                         spriteset_Map._tilemap.removeChildAt(i);                     }                      break;                 }             }         }          if (this.delete == true) {             DataManager.___simpleText___.getSimpleTextObjListByMapID().splice(index, 1);             return;         }          //get center position         var centerX = 0;         var centerY = 0;          if (event == null) {             centerX = Graphics.width / 2;             centerY = Graphics.height / 2;         }         else {             if (this.isFollow == false) {                 var scrolledX = $gameMap.adjustX(this.startX);                 var scrolledY = $gameMap.adjustY(this.startY);                  var tw = $gameMap.tileWidth();                 var screenX = Math.round(scrolledX * tw + tw / 2);                  var th = $gameMap.tileHeight();                 var screenY = Math.round(scrolledY * th + th - this.adjustY);                  centerX = screenX;                 centerY = screenY - $gameMap.tileHeight();             }             else {                 centerX = event.screenX();                 centerY = event.screenY() - $gameMap.tileHeight();             }         }          centerX += this.offsetX;         centerY += this.offsetY;          if (found == false) {             child = this.addSprite(spriteset_Map, centerX, centerY);         }         else {             child.x = centerX;             child.y = centerY;         }             //update offsets         this.offsetX += this.moveX;         this.offsetY += this.moveY;     };      //create SimpleText in DataManager     var _DataManager_createGameObjects = DataManager.createGameObjects;     DataManager.createGameObjects = function() {         _DataManager_createGameObjects.call(this);          if (typeof(DataManager.___simpleText___)==='undefined')             DataManager.___simpleText___ = new SimpleText();     };      //remove sprites on creeate tilemap     var _Spriteset_Map_prototype_createTilemap = Spriteset_Map.prototype.createTilemap;     Spriteset_Map.prototype.createTilemap = function() {         _Spriteset_Map_prototype_createTilemap.call(this);          //remove all text sprites if exits         for (var i = this._tilemap.children.length - 1; i >= 0; i--) {             var child = this._tilemap.children;              if (typeof(child.___simpleTextObjRef___)==='undefined') {                 continue;             }             else {                 child.bitmap = null;                 this._tilemap.removeChildAt(i);             }         }     }      //update SimpleTextObjList     var _Spriteset_Map_prototype_updateTilemap = Spriteset_Map.prototype.updateTilemap;     Spriteset_Map.prototype.updateTilemap = function() {         _Spriteset_Map_prototype_updateTilemap.call(this);          var simpleTextObjList = DataManager.___simpleText___.getSimpleTextObjListByMapID();         for (var i = simpleTextObjList.length - 1; i >= 0; i--)             simpleTextObjList.update(i, this);     };      //read plugin command     var _Game_Interpreter_prototype_pluginCommand = Game_Interpreter.prototype.pluginCommand;     Game_Interpreter.prototype.pluginCommand = function(command, args) {         _Game_Interpreter_prototype_pluginCommand.call(this, command, args);                 //only work with Scene_Map         if (SceneManager._scene instanceof Scene_Map == false)             return;          if (command.toUpperCase() == "SIMPLETEXT") {             var argsLength = args.length;             var action = args[0].toUpperCase();             if (action == "WRITE") {                 if (argsLength == 3) {                     var simpleTextObj = new SimpleTextObj(args[1], args[2]);                 }             }             else if (action == "FONT") {                 if (argsLength == 2) {                     DataManager.___simpleText___.changeFont(args[1]);                 }             }             else if (action == "CLEARALL") {                 for (var mapID in DataManager.___simpleText___.simpleTextObjList) {                     var simpleTextObjList = DataManager.___simpleText___.simpleTextObjList[mapID];                      for (var i = simpleTextObjList.length - 1; i >= 0; i--)                         simpleTextObjList.delete = true;                 }             }             else if (action == "CLEARMAP") {                 var simpleTextObjList = DataManager.___simpleText___.getSimpleTextObjListByMapID();                 for (var i = simpleTextObjList.length - 1; i >= 0; i--)                     simpleTextObjList.delete = true;             }             else if (action == "CLEARBYEVENTID") {                 if (argsLength == 2) {                     var eventID = parseInt(args[1]);                      var simpleTextObjList = DataManager.___simpleText___.getSimpleTextObjListByMapID();                     for (var i = simpleTextObjList.length - 1; i >= 0; i--) {                         var simpleTextObj = simpleTextObjList;                         if (simpleTextObj.eventID === eventID)                             simpleTextObj.delete = true;                     }                 }             }             else if (action == "CLEARBYGROUP") {                 if (argsLength == 2) {                     var group = args[1].toUpperCase();                      var simpleTextObjList = DataManager.___simpleText___.getSimpleTextObjListByMapID();                     for (var i = simpleTextObjList.length - 1; i >= 0; i--) {                         var simpleTextObj = simpleTextObjList;                         if (simpleTextObj.group === group)                             simpleTextObj.delete = true;                     }                 }             }         }     }; })();




    本贴来自国际rpgmaker官方论坛作者:www处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/simpletext-format-and-display-text-on-map-interface-version-1-3.49732/
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-7-10 03:03 , Processed in 0.092771 second(s), 52 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表