Ok. I've improved on this since last night. I notice MV was cancelling keyboard and wheel events preventing scrolling on the element, so I've commented out one line in the core. I've also added Trihan's command thing, so now you call either call this script by event...
or by commandPHP:loadTXTfile("loremipsum.txt");
PHP:loadTXTfile loremipsum.txtPHP:var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand; Game_Interpreter.prototype.pluginCommand = function(command, args) { _Game_Interpreter_pluginCommand.call(this, command, args); if (command.toLowerCase() === "loadtxtfile") { loadTXTfile(args); } }; var loadTXTfile = function(file){ if($gamePlayer.canMoveAfterTxt === undefined){ $gamePlayer.canMoveAfterTxt = $gamePlayer.canMove; Input._shouldPreventDefaultAfterTxt = Input._shouldPreventDefault; } var xhr = new XMLHttpRequest(); xhr.open("GET", file, true); xhr.onreadystatechange = function () { if(xhr.readyState === 4 && xhr.responseText.length > 0) { removeTXTelement(); $gamePlayer.canMove = function(){ return false; }; Input._shouldPreventDefault = function(){ return false; }; // create element var div = document.createElement("div"); // style element var css = { width:"420px", maxHeight:"420px", overflow:"auto", background:'url("img/pictures/paper.png") 0 0 scroll #fff', color:"#000", font:'"Lucida Sans Unicode", "Lucida Grande", sans-serif', position:"fixed", left:"50%", borderRadius:"5px", padding:"15px", border:"3px solid #000", boxShadow:"-3px 3px 50px #000", top:"50%", marginLeft:"-210px", marginTop:"-210px", zIndex:99999 }; for(sty in css){ div.style[sty] = css[sty]; } div.id = "DOMElementWithText"; // give the element the text of the text file div.innerHTML = xhr.responseText.replace(/\n/g, "<br>"); document.body.appendChild(div); document.getElementById("DOMElementWithText").focus(); window.addEventListener("keyup", removeTXTelement); } }; xhr.send(); }; var txtOpenInAction = false; var removeTXTelement = function(e){ var ok = e !== undefined && Input.keyMapper[e.keyCode] === "ok"; if(ok && !txtOpenInAction){ txtOpenInAction = true; // prevents from closing right when open } else if(ok && txtOpenInAction){ txtOpenInAction = false; window.removeEventListener("keyup", removeTXTelement); $gamePlayer.canMove = $gamePlayer.canMoveAfterTxt; Input._shouldPreventDefault = Input._shouldPreventDefaultAfterTxt; if(document.getElementById("DOMElementWithText") !== null) document.getElementById("DOMElementWithText").parentNode.removeChild( document.getElementById("DOMElementWithText") ); } }; TouchInput._setupEventHandlers = function() { document.addEventListener('mousedown', this._onMouseDown.bind(this)); document.addEventListener('mousemove', this._onMouseMove.bind(this)); document.addEventListener('mouseup', this._onMouseUp.bind(this)); // document.addEventListener('wheel', this._onWheel.bind(this)); document.addEventListener('touchstart', this._onTouchStart.bind(this)); document.addEventListener('touchmove', this._onTouchMove.bind(this)); document.addEventListener('touchend', this._onTouchEnd.bind(this)); document.addEventListener('touchcancel', this._onTouchCancel.bind(this)); document.addEventListener('pointerdown', this._onPointerDown.bind(this)); };
Wow! I really appreciate what you did! But please tell me exactly how can I use it on my project... I only know how to use .js files... I tried pasting this code in a .js file but nothing... I understand how to call the plugin or "code"... but I don´t understand how to use it! If you could help me with that too I would be very thankful, dude!