| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| (function() { |
| 'use strict'; |
| const script = document.currentScript; |
| const param = PluginManagerEx.createParameter(script); |
|
|
| PluginManager.registerCommand(PluginManagerEx.findPluginName(script), 'dText', function(args) { |
| $gameScreen.setDTextPicture(args.text, PluginManagerEx.convertVariables(args.fontSize)); |
| }); |
|
|
| PluginManagerEx.registerCommand(script, 'dTextSetting', function(args) { |
| $gameScreen.setDtextSetting(args); |
| }); |
|
|
| PluginManagerEx.registerCommand(script, 'dTextSettingClear', function(args) { |
| $gameScreen.clearDtextSetting(); |
| }); |
|
|
| PluginManagerEx.registerCommand(script, 'windowCursor', function(args) { |
| $gameScreen.setDTextWindowCursor(args.pictureId, args, args.activateSwitch); |
| }); |
|
|
| |
| |
| |
| |
| Game_Screen.prototype.setDtextSetting = function(setting) { |
| if (setting.backGroundColor !== '') { |
| this.dTextBackColor = setting.backGroundColor; |
| } |
| if (setting.gradationLeft !== '') { |
| this.dTextGradationLeft = setting.gradationLeft; |
| } |
| if (setting.gradationRight !== '') { |
| this.dTextGradationRight = setting.gradationRight; |
| } |
| if (setting.realTime !== '') { |
| this.dTextRealTime = setting.realTime; |
| } |
| if (setting.window !== '') { |
| this.dWindowFrame = setting.window; |
| } |
| if (setting.align !== '') { |
| this.dTextAlign = setting.align; |
| } |
| if (setting.fontFace !== '') { |
| this.dTextFontFace = setting.fontFace; |
| } |
| if (setting.lineHeight > 0) { |
| this.dTextLineHeight = setting.lineHeight; |
| } |
| if (setting.windowOpacity !== '') { |
| this.dTextWindowOpacity = setting.windowOpacity; |
| } |
| }; |
|
|
| Game_Screen.prototype.clearDtextSetting = function() { |
| this.dTextBackColor = null; |
| this.dTextGradationLeft = null; |
| this.dTextGradationRight = null; |
| this.dTextRealTime = null; |
| this.dWindowFrame = null; |
| this.dTextAlign = null; |
| this.dTextFontFace = null; |
| this.dTextLineHeight = null; |
| this.dTextWindowOpacity = null; |
| }; |
|
|
| Game_Screen.prototype.clearDTextPicture = function() { |
| this.dTextValue = null; |
| }; |
|
|
| Game_Screen.prototype.setDTextPicture = function(value, size) { |
| if (typeof TranslationManager !== 'undefined') { |
| TranslationManager.translateIfNeed(value, function(translatedText) { |
| value = translatedText; |
| }); |
| } |
| if (size > 0) { |
| value = `\\fs[${size}]${value}`; |
| } |
| this.dTextValue = value; |
| this.dTextSize = size; |
| }; |
|
|
| Game_Screen.prototype.setDTextWindowCursor = function(pictureId, rect, switchId) { |
| const picture = this.picture(pictureId); |
| if (picture) { |
| picture.setWindowCursor(rect, switchId); |
| } |
| }; |
|
|
| Game_Screen.prototype.getDTextPictureInfo = function() { |
| const prefix = param.prefixText || ''; |
| return { |
| value : prefix + this.dTextValue, |
| size : this.dTextSize, |
| color : this.dTextBackColor, |
| realTime : this.dTextRealTime, |
| windowFrame : this.dWindowFrame, |
| gradationLeft : this.dTextGradationLeft, |
| gradationRight: this.dTextGradationRight, |
| align : this.dTextAlign, |
| font : this.dTextFontFace, |
| lineHeight : this.dTextLineHeight, |
| windowOpacity : this.dTextWindowOpacity |
| }; |
| }; |
|
|
| Game_Screen.prototype.isSettingDText = function() { |
| return !!this.dTextValue; |
| }; |
|
|
| |
| |
| |
| |
| const _Game_Picture_initBasic = Game_Picture.prototype.initBasic; |
| Game_Picture.prototype.initBasic = function() { |
| _Game_Picture_initBasic.call(this); |
| this.dTextValue = null; |
| this.dTextInfo = null; |
| }; |
|
|
| const _Game_Picture_show = Game_Picture.prototype.show; |
| Game_Picture.prototype.show = function(name, origin, x, y, scaleX, |
| scaleY, opacity, blendMode) { |
| if ($gameScreen.isSettingDText() && !name) { |
| arguments[0] = Date.now().toString(); |
| this.dTextInfo = $gameScreen.getDTextPictureInfo(); |
| this.updateDText(); |
| $gameScreen.clearDTextPicture(); |
| } else { |
| this.dTextInfo = null; |
| this._dTextValue = null; |
| } |
| _Game_Picture_show.apply(this, arguments); |
| }; |
|
|
| const _Game_Picture_update = Game_Picture.prototype.update; |
| Game_Picture.prototype.update = function() { |
| _Game_Picture_update.apply(this, arguments); |
| if (this.dTextInfo && this.dTextInfo.realTime) { |
| this.updateDText(); |
| } |
| }; |
|
|
| Game_Picture.prototype.updateDText = function() { |
| const text = PluginManagerEx.convertEscapeCharacters(this.dTextInfo.value); |
| if (text !== this._dTextValue) { |
| this._name = Date.now().toString(); |
| } |
| this._dTextValue = text; |
| }; |
|
|
| Game_Picture.prototype.getDText = function() { |
| return this._dTextValue; |
| }; |
|
|
| Game_Picture.prototype.setWindowCursor = function(rect, switchId) { |
| this._windowCursor = rect; |
| this._windowCursorActive = switchId; |
| }; |
|
|
| Game_Picture.prototype.getWindowCursor = function() { |
| return this._windowCursor; |
| }; |
|
|
| Game_Picture.prototype.getWindowCursorActive = function() { |
| const switchId = this._windowCursorActive; |
| return !switchId || $gameSwitches.value(switchId); |
| }; |
|
|
| |
| |
| |
| |
| const _PluginManagerEx_convertEscapeCharactersEx = PluginManagerEx.convertEscapeCharactersEx; |
| PluginManagerEx.convertEscapeCharactersEx = function(text, data = null) { |
| text = _PluginManagerEx_convertEscapeCharactersEx.call(this, text, data); |
| text = text.replace(/\x1bV\[(\d+),\s*(\d+)]/gi, function() { |
| return this.getVariablePadCharacter($gameVariables.value(parseInt(arguments[1], 10)), arguments[2]); |
| }.bind(this)); |
| text = text.replace(/\x1bITEM\[(\d+)]/gi, function() { |
| const item = $dataItems[parseInt(arguments[1])]; |
| return this.getItemInfoText(item); |
| }.bind(this)); |
| text = text.replace(/\x1bWEAPON\[(\d+)]/gi, function() { |
| const item = $dataWeapons[parseInt(arguments[1])]; |
| return this.getItemInfoText(item); |
| }.bind(this)); |
| text = text.replace(/\x1bARMOR\[(\d+)]/gi, function() { |
| const item = $dataArmors[parseInt(arguments[1])]; |
| return this.getItemInfoText(item); |
| }.bind(this)); |
| text = text.replace(/\x1bSKILL\[(\d+)]/gi, function() { |
| const item = $dataSkills[parseInt(arguments[1])]; |
| return this.getItemInfoText(item); |
| }.bind(this)); |
| text = text.replace(/\x1bSTATE\[(\d+)]/gi, function() { |
| const item = $dataStates[parseInt(arguments[1])]; |
| return this.getItemInfoText(item); |
| }.bind(this)); |
| return text; |
| }; |
|
|
| PluginManagerEx.getItemInfoText = function(item) { |
| return item ?`\x1bi[${item.iconIndex}]${item.name}` : ''; |
| }; |
|
|
| PluginManagerEx.getVariablePadCharacter = function(value, digit) { |
| let numText = String(Math.abs(value)); |
| const pad = String(param.padCharacter) || '0'; |
| while (numText.length < digit) { |
| numText = pad + numText; |
| } |
| return (value < 0 ? '-' : '') + numText; |
| }; |
|
|
| |
| |
| |
| |
| const _Sprite_Picture_update = Sprite_Picture.prototype.update; |
| Sprite_Picture.prototype.update = function() { |
| _Sprite_Picture_update.apply(this, arguments); |
| if (this._frameWindow) { |
| this.updateFrameWindow(); |
| } |
| }; |
|
|
| Sprite_Picture.prototype.updateFrameWindow = function() { |
| const padding = param.frameWindowPadding; |
| this._frameWindow.x = this.x - (this.anchor.x * this.width * this.scale.x) - padding; |
| this._frameWindow.y = this.y - (this.anchor.y * this.height * this.scale.y) - padding; |
| this._frameWindow.opacity = this.opacity; |
| if (this.dTextInfo && this.dTextInfo.windowOpacity >= 0) { |
| this._frameWindow.backOpacity = this.dTextInfo.windowOpacity; |
| } |
| if (!this.visible || !this.dTextInfo) { |
| this.removeFrameWindow(); |
| return; |
| } |
| if (!this._addFrameWindow) { |
| this.addFrameWindow(); |
| } |
| if (Graphics.frameCount % 2 === 0) { |
| this.adjustScaleFrameWindow(); |
| } |
| this.updateFrameWindowCursor(); |
| }; |
|
|
| Sprite_Picture.prototype.updateFrameWindowCursor = function() { |
| const picture = this.picture(); |
| if (!picture) { |
| return; |
| } |
| const rect = picture.getWindowCursor(); |
| if (rect) { |
| const width = rect.width || this._frameWindow.contentsWidth(); |
| const height = rect.height || this._frameWindow.contentsHeight(); |
| const x = rect.x || 0; |
| const y = rect.y || 0; |
| this._frameWindow.setCursorRect(x, y, width, height); |
| this._frameWindow.active = picture.getWindowCursorActive(); |
| } else { |
| this._frameWindow.setCursorRect(0, 0, 0, 0); |
| } |
| }; |
|
|
| Sprite_Picture.prototype.adjustScaleFrameWindow = function() { |
| const padding = param.frameWindowPadding; |
| const newFrameWidth = Math.floor(this.width * this.scale.x + padding * 2); |
| const newFrameHeight = Math.floor(this.height * this.scale.x + padding * 2); |
| if (this._frameWindow.width !== newFrameWidth || this._frameWindow.height !== newFrameHeight) { |
| this._frameWindow.move(this._frameWindow.x, this._frameWindow.y, newFrameWidth, newFrameHeight); |
| } |
| }; |
|
|
| Sprite_Picture.prototype.addFrameWindow = function() { |
| const parent = this.parent; |
| if (parent) { |
| const index = parent.getChildIndex(this); |
| parent.addChildAt(this._frameWindow, index); |
| this._addFrameWindow = true; |
| } |
| }; |
|
|
| Sprite_Picture.prototype.removeFrameWindow = function() { |
| const parent = this.parent; |
| if (parent) { |
| parent.removeChild(this._frameWindow); |
| this._frameWindow = null; |
| this._addFrameWindow = false; |
| } |
| }; |
|
|
| Sprite_Picture.prototype.makeFrameWindow = function(width, height) { |
| const padding = param.frameWindowPadding; |
| const rect = new Rectangle(0, 0, width + padding * 2, height + padding * 2); |
| this._frameWindow = new Window_Base(rect); |
| if (param.frameWindowSkin) { |
| this._frameWindow.windowskin = ImageManager.loadSystem(param.frameWindowSkin); |
| } |
| }; |
|
|
| const _Sprite_Picture_loadBitmap = Sprite_Picture.prototype.loadBitmap; |
| Sprite_Picture.prototype.loadBitmap = function() { |
| this.dTextInfo = this.picture().dTextInfo; |
| if (this.dTextInfo) { |
| this.makeDynamicBitmap(); |
| } else { |
| _Sprite_Picture_loadBitmap.apply(this, arguments); |
| } |
| }; |
|
|
| Sprite_Picture.prototype.makeDynamicBitmap = function() { |
| const tempWindow = new Window_Dummy(); |
| this.bitmap = tempWindow.createTextContents(this.picture().getDText(), this.dTextInfo); |
| if (param.widthVariable) { |
| $gameVariables.setValue(param.widthVariable, this.bitmap.width); |
| } |
| if (param.heightVariable) { |
| $gameVariables.setValue(param.heightVariable, this.bitmap.height); |
| } |
| if (this.dTextInfo.color) { |
| this.makeDynamicBitmapBack(); |
| } |
| this.setColorTone([0, 0, 0, 0]); |
| tempWindow.drawTextContents(); |
| if (this._frameWindow) { |
| this.removeFrameWindow(); |
| } |
| if (this.dTextInfo.windowFrame) { |
| const scaleX = this.picture().scaleX() / 100; |
| const scaleY = this.picture().scaleY() / 100; |
| this.makeFrameWindow(this.bitmap.width * scaleX, this.bitmap.height * scaleY); |
| } |
| }; |
|
|
| Sprite_Picture.prototype.makeDynamicBitmapBack = function() { |
| this.bitmap.fillAll(this.dTextInfo.color); |
| const h = this.bitmap.height; |
| const w = this.bitmap.width; |
| const gradationLeft = this.dTextInfo.gradationLeft; |
| if (gradationLeft > 0) { |
| this.bitmap.clearRect(0, 0, gradationLeft, h); |
| this.bitmap.gradientFillRect(0, 0, gradationLeft, h, 'rgba(0, 0, 0, 0)', this.dTextInfo.color, false); |
| } |
| const gradationRight = this.dTextInfo.gradationRight; |
| if (gradationRight > 0) { |
| this.bitmap.clearRect(w - gradationRight, 0, gradationRight, h); |
| this.bitmap.gradientFillRect(w - gradationRight, 0, gradationRight, h, this.dTextInfo.color, 'rgba(0, 0, 0, 0)', false); |
| } |
| }; |
|
|
| |
| |
| |
| |
| class Window_Dummy extends Window_Base { |
| constructor() { |
| super(new Rectangle()); |
| } |
|
|
| createTextContents(text, dTextInfo) { |
| this._size = dTextInfo.size; |
| this._face = dTextInfo.font; |
| this._lineHeight = dTextInfo.lineHeight; |
| this._text = text; |
| const rect = this.textSizeEx(text); |
| this.textPictureWidth = rect.width; |
| this.textPictureAlign = dTextInfo.align; |
| this.contents = new Bitmap(rect.width, rect.height); |
| return this.contents; |
| } |
|
|
| drawTextContents() { |
| this.drawTextEx(this._text, 0, 0); |
| this.contents = null; |
| this.destroy(); |
| } |
|
|
| calcTextHeight(textState) { |
| return this._lineHeight || super.calcTextHeight(textState); |
| } |
|
|
| processAllText(textState) { |
| if (textState.drawing) { |
| this.setStartXForAlign(textState); |
| } |
| super.processAllText(textState); |
| } |
|
|
| processNewLine(textState) { |
| super.processNewLine(textState); |
| if (textState.drawing) { |
| this.setStartXForAlign(textState); |
| } |
| } |
|
|
| setStartXForAlign(textState) { |
| const lines = textState.text.slice(textState.index).split("\n"); |
| textState.widthList = lines.map(line => this.textSizeEx(line).width); |
| textState.x = this.findStartXForAlign(textState); |
| } |
|
|
| resetFontSettings() { |
| super.resetFontSettings(); |
| if (this._size) { |
| this.contents.fontSize = this._size; |
| } |
| if (this._face) { |
| this.contents.fontFace = this._face; |
| } |
| } |
|
|
| processEscapeCharacter(code, textState) { |
| super.processEscapeCharacter(code, textState); |
| switch (code) { |
| case 'OC': |
| const colorCode = this.obtainEscapeParamString(textState); |
| const colorIndex = Number(colorCode); |
| this.changeOutlineColor(!isNaN(colorIndex) ? ColorManager.textColor(colorIndex) : colorCode); |
| break; |
| case 'OW': |
| this.contents.outlineWidth = this.obtainEscapeParam(textState); |
| break; |
| case 'F': |
| this.changeFontStyle(this.obtainEscapeParamString(textState)); |
| break; |
| } |
| } |
|
|
| changeFontStyle(value) { |
| switch (value.toUpperCase()) { |
| case 'B': |
| this.contents.fontBold = true; |
| break; |
| case 'I': |
| this.contents.fontItalic = true; |
| break; |
| default: |
| this.contents.fontItalic = false; |
| this.contents.fontBold = false; |
| } |
| } |
|
|
| obtainEscapeParamString(textState) { |
| const arr = /^\[.+?]/.exec(textState.text.slice(textState.index)); |
| if (arr) { |
| textState.index += arr[0].length; |
| return arr[0].substring(1, arr[0].length - 1); |
| } else { |
| return ''; |
| } |
| } |
|
|
| findStartXForAlign(textState) { |
| const dx = this.textPictureWidth - textState.widthList.shift(); |
| if (this.textPictureAlign === 'center') { |
| return Math.floor(dx / 2); |
| } else if (this.textPictureAlign === 'right') { |
| return dx; |
| } else { |
| return 0; |
| } |
| } |
| } |
| })(); |
|
|