如下插件:每次选择完公共事件后,并也执行了,但一直没有关闭窗口的操作及命令,最后的Onok里this.close()似乎无效,导致无限弹窗,除非按取消。求执行完公共事件后关闭窗口。
JAVASCRIPT 代码 - //=============================================================================
- // EventSelector.js
- //=============================================================================
- /*:
- * @plugindesc 显示一个窗口来选择公共事件
- * @author Yoji Ojima
- *
- * @help 插件指令:
- * EventSelector open # 打开事件选择器
- * EventSelector add 3 # 添加3号公共事件到选择器中
- * EventSelector remove 4 # 从选择器中移除4号公共事件
- * EventSelector clear # 清除时间选择器
- */
- (function(){
- var eventSelectorStatus = '';
- var selectedCommonEvent = null;
- var _Game_Interpreter_pluginCommand =
- Game_Interpreter.prototype.pluginCommand;
- Game_Interpreter.prototype.pluginCommand = function(command, args){
- _Game_Interpreter_pluginCommand.call(this, command, args);
- if(command === 'EventSelector'){
- switch(args[0]){
- case'open':
- eventSelectorStatus = 'open';
- this.setWaitMode('EventSelector');
- break;
- case'add':
- $gameSystem.addToEventSelector(Number(args[1]));
- break;
- case'remove':
- $gameSystem.removeFromEventSelector(Number(args[1]));
- break;
- case'clear':
- $gameSystem.clearEventSelector();
- break;
- }
- }
- };
- var _Game_Interpreter_updateWaitMode =
- Game_Interpreter.prototype.updateWaitMode;
- Game_Interpreter.prototype.updateWaitMode = function(){
- if(this._waitMode === 'EventSelector'){
- if(eventSelectorStatus === 'close'){
- this._waitMode = '';
- if(selectedCommonEvent){
- this.setupChild(selectedCommonEvent.list);
- this._callingSelectedEvent = true;
- }
- eventSelectorStatus = '';
- }
- returntrue;
- }else{
- return _Game_Interpreter_updateWaitMode.call(this);
- }
- };
- var _Game_Interpreter_updateChild = Game_Interpreter.prototype.updateChild;
- Game_Interpreter.prototype.updateChild = function(){
- var result = _Game_Interpreter_updateChild.call(this);
- if(this._callingSelectedEvent && !result){
- this._callingSelectedEvent = false;
- eventSelectorStatus = 'open';
- this.setWaitMode('EventSelector');
- returntrue;
- }
- return result;
- };
- Game_System.prototype.addToEventSelector = function(commonEventId){
- if(!this._eventSelectorData){
- this.clearEventSelector();
- }
- if(!this._eventSelectorData.contains(commonEventId)){
- this._eventSelectorData.push(commonEventId);
- }
- };
- Game_System.prototype.removeFromEventSelector = function(commonEventId){
- if(this._eventSelectorData){
- var index = this._eventSelectorData.indexOf(commonEventId);
- if(index >= 0){
- this._eventSelectorData.splice(index, 1);
- }
- }
- };
- Game_System.prototype.clearEventSelector = function(){
- this._eventSelectorData = [];
- };
- Game_System.prototype.eventSelectorData = function(){
- if(this._eventSelectorData){
- returnthis._eventSelectorData.clone();
- }else{
- return[];
- }
- };
- var _Scene_Map_createAllWindows = Scene_Map.prototype.createAllWindows;
- Scene_Map.prototype.createAllWindows = function(){
- _Scene_Map_createAllWindows.call(this);
- this._eventSelectorWindow = new Window_EventSelector(0, 0);
- this.addChild(this._eventSelectorWindow);
- };
- function Window_EventSelector(){
- this.initialize.apply(this, arguments);
- }
- Window_EventSelector.prototype = Object.create(Window_Selectable.prototype);
- Window_EventSelector.prototype.constructor = Window_EventSelector;
- Window_EventSelector.lastTopRow = 0;
- Window_EventSelector.lastIndex = 0;
- Window_EventSelector.prototype.initialize = function(x, y){
- var width = Graphics.boxWidth/4;
- var height = this.fittingHeight(10);
- Window_Selectable.prototype.initialize.call(this, x, y, width, height);
- this.openness = 0;
- this.deactivate();
- this.setHandler('ok', this.onOk.bind(this));
- this.setHandler('cancel', this.onCancel.bind(this));
- };
- Window_EventSelector.prototype.maxCols = function(){
- return1;
- };
- Window_EventSelector.prototype.maxItems = function(){
- returnthis._list ? this._list.length : 0;
- };
- Window_EventSelector.prototype.update = function(){
- Window_Selectable.prototype.update.call(this);
- switch(eventSelectorStatus){
- case'open':
- this.refresh();
- this.setTopRow(Window_EventSelector.lastTopRow);
- this.select(Window_EventSelector.lastIndex);
- this.open();
- this.activate();
- eventSelectorStatus = 'select';
- break;
- case'select':
- if(this.isClosed()){
- eventSelectorStatus = 'close';
- }
- break;
- }
- };
- Window_EventSelector.prototype.refresh = function(){
- var data = $gameSystem.eventSelectorData();
- this._list = [];
- for(var i = 0; i < data.length; i++){
- var commonEvent = $dataCommonEvents[data[i]];
- if(commonEvent){
- this._list.push(commonEvent);
- }
- }
- this.createContents();
- this.drawAllItems();
- };
- Window_EventSelector.prototype.drawItem = function(index){
- var commonEvent = this._list[index];
- var rect = this.itemRectForText(index);
- this.drawText(commonEvent.name, rect.x, rect.y, rect.width);
- };
- Window_EventSelector.prototype.isCurrentItemEnabled = function(){
- var commonEvent = this._list[this.index()];
- return !!commonEvent;
- };
- Window_EventSelector.prototype.isOkTriggered = function(){
- return Input.isTriggered('ok');
- };
- Window_EventSelector.prototype.onOk = function(){
- selectedCommonEvent = this._list[this.index()];
- Window_EventSelector.lastTopRow = this.topRow();
- Window_EventSelector.lastIndex = this.index();
- this.close();
- };
- Window_EventSelector.prototype.onCancel = function(){
- selectedCommonEvent = null;
- Window_EventSelector.lastTopRow = this.topRow();
- Window_EventSelector.lastIndex = this.index();
- this.close();
- };
- })();
复制代码
本帖来自P1论坛作者负零,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址: https://rpg.blue/forum.php?mod=viewthread&tid=387861 若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。 |