查看: 3836|回复: 1

[已经解决] 请教公共事件选择器BUG修正问题

[复制链接]
梦石
0
星屑
723
在线时间
530 小时
注册时间
2010-6-9
回帖
668
发表于 2015-12-31 12:22:06 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
如下插件:每次选择完公共事件后,并也执行了,但一直没有关闭窗口的操作及命令,最后的Onok里this.close()似乎无效,导致无限弹窗,除非按取消。求执行完公共事件后关闭窗口。
  1. //=============================================================================
  2. // EventSelector.js
  3. //=============================================================================

  4. /*:
  5. * @plugindesc 显示一个窗口来选择公共事件
  6. * @author Yoji Ojima
  7. *
  8. * @help 插件指令:
  9. *   EventSelector open       # 打开事件选择器
  10. *   EventSelector add 3      # 添加3号公共事件到选择器中
  11. *   EventSelector remove 4   # 从选择器中移除4号公共事件
  12. *   EventSelector clear      # 清除时间选择器
  13. */

  14. (function() {

  15.     var eventSelectorStatus = '';
  16.     var selectedCommonEvent = null;

  17.     var _Game_Interpreter_pluginCommand =
  18.             Game_Interpreter.prototype.pluginCommand;
  19.     Game_Interpreter.prototype.pluginCommand = function(command, args) {
  20.         _Game_Interpreter_pluginCommand.call(this, command, args);
  21.         if (command === 'EventSelector') {
  22.             switch (args[0]) {
  23.             case 'open':
  24.                 eventSelectorStatus = 'open';
  25.                 this.setWaitMode('EventSelector');
  26.                 break;
  27.             case 'add':
  28.                 $gameSystem.addToEventSelector(Number(args[1]));
  29.                 break;
  30.             case 'remove':
  31.                 $gameSystem.removeFromEventSelector(Number(args[1]));
  32.                 break;
  33.             case 'clear':
  34.                 $gameSystem.clearEventSelector();
  35.                 break;
  36.             }
  37.         }
  38.     };

  39.     var _Game_Interpreter_updateWaitMode =
  40.             Game_Interpreter.prototype.updateWaitMode;
  41.     Game_Interpreter.prototype.updateWaitMode = function() {
  42.         if (this._waitMode === 'EventSelector') {
  43.             if (eventSelectorStatus === 'close') {
  44.                 this._waitMode = '';
  45.                 if (selectedCommonEvent) {
  46.                     this.setupChild(selectedCommonEvent.list);
  47.                     this._callingSelectedEvent = true;
  48.                 }
  49.                 eventSelectorStatus = '';
  50.             }
  51.             return true;
  52.         } else {
  53.             return _Game_Interpreter_updateWaitMode.call(this);
  54.         }
  55.     };

  56.     var _Game_Interpreter_updateChild = Game_Interpreter.prototype.updateChild;
  57.     Game_Interpreter.prototype.updateChild = function() {
  58.         var result = _Game_Interpreter_updateChild.call(this);
  59.         if (this._callingSelectedEvent && !result) {
  60.             this._callingSelectedEvent = false;
  61.             eventSelectorStatus = 'open';
  62.             this.setWaitMode('EventSelector');
  63.             return true;
  64.         }
  65.         return result;
  66.     };

  67.     Game_System.prototype.addToEventSelector = function(commonEventId) {
  68.         if (!this._eventSelectorData) {
  69.             this.clearEventSelector();
  70.         }
  71.         if (!this._eventSelectorData.contains(commonEventId)) {
  72.             this._eventSelectorData.push(commonEventId);
  73.         }
  74.     };

  75.     Game_System.prototype.removeFromEventSelector = function(commonEventId) {
  76.         if (this._eventSelectorData) {
  77.             var index = this._eventSelectorData.indexOf(commonEventId);
  78.             if (index >= 0) {
  79.                 this._eventSelectorData.splice(index, 1);
  80.             }
  81.         }
  82.     };

  83.     Game_System.prototype.clearEventSelector = function() {
  84.         this._eventSelectorData = [];
  85.     };

  86.     Game_System.prototype.eventSelectorData = function() {
  87.         if (this._eventSelectorData) {
  88.             return this._eventSelectorData.clone();
  89.         } else {
  90.             return [];
  91.         }
  92.     };

  93.     var _Scene_Map_createAllWindows = Scene_Map.prototype.createAllWindows;
  94.     Scene_Map.prototype.createAllWindows = function() {
  95.         _Scene_Map_createAllWindows.call(this);
  96.         this._eventSelectorWindow = new Window_EventSelector(0, 0);
  97.         this.addChild(this._eventSelectorWindow);
  98.     };

  99.     function Window_EventSelector() {
  100.         this.initialize.apply(this, arguments);
  101.     }

  102.     Window_EventSelector.prototype = Object.create(Window_Selectable.prototype);
  103.     Window_EventSelector.prototype.constructor = Window_EventSelector;

  104.     Window_EventSelector.lastTopRow = 0;
  105.     Window_EventSelector.lastIndex  = 0;

  106.     Window_EventSelector.prototype.initialize = function(x, y) {
  107.         var width = Graphics.boxWidth/4;
  108.         var height = this.fittingHeight(10);
  109.         Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  110.         this.openness = 0;
  111.         this.deactivate();
  112.         this.setHandler('ok',     this.onOk.bind(this));
  113.         this.setHandler('cancel', this.onCancel.bind(this));
  114.     };

  115.     Window_EventSelector.prototype.maxCols = function() {
  116.         return 1;
  117.     };

  118.     Window_EventSelector.prototype.maxItems = function() {
  119.         return this._list ? this._list.length : 0;
  120.     };

  121.     Window_EventSelector.prototype.update = function() {
  122.         Window_Selectable.prototype.update.call(this);
  123.         switch (eventSelectorStatus) {
  124.         case 'open':
  125.             this.refresh();
  126.             this.setTopRow(Window_EventSelector.lastTopRow);
  127.             this.select(Window_EventSelector.lastIndex);
  128.             this.open();
  129.             this.activate();
  130.             eventSelectorStatus = 'select';
  131.             break;
  132.         case 'select':
  133.             if (this.isClosed()) {
  134.                 eventSelectorStatus = 'close';
  135.             }
  136.             break;
  137.         }
  138.     };

  139.     Window_EventSelector.prototype.refresh = function() {
  140.         var data = $gameSystem.eventSelectorData();
  141.         this._list = [];
  142.         for (var i = 0; i < data.length; i++) {
  143.             var commonEvent = $dataCommonEvents[data[i]];
  144.             if (commonEvent) {
  145.                 this._list.push(commonEvent);
  146.             }
  147.         }
  148.         this.createContents();
  149.         this.drawAllItems();
  150.     };

  151.     Window_EventSelector.prototype.drawItem = function(index) {
  152.         var commonEvent = this._list[index];
  153.         var rect = this.itemRectForText(index);
  154.         this.drawText(commonEvent.name, rect.x, rect.y, rect.width);
  155.     };

  156.     Window_EventSelector.prototype.isCurrentItemEnabled = function() {
  157.         var commonEvent = this._list[this.index()];
  158.         return !!commonEvent;
  159.     };

  160.     Window_EventSelector.prototype.isOkTriggered = function() {
  161.         return Input.isTriggered('ok');
  162.     };

  163.     Window_EventSelector.prototype.onOk = function() {
  164.         selectedCommonEvent = this._list[this.index()];
  165.         Window_EventSelector.lastTopRow = this.topRow();
  166.         Window_EventSelector.lastIndex = this.index();
  167.         this.close();
  168.     };

  169.     Window_EventSelector.prototype.onCancel = function() {
  170.         selectedCommonEvent = null;
  171.         Window_EventSelector.lastTopRow = this.topRow();
  172.         Window_EventSelector.lastIndex = this.index();
  173.         this.close();
  174.     };

  175. })();
复制代码
梦石
0
星屑
60
在线时间
306 小时
注册时间
2014-8-5
回帖
403
发表于 2015-12-31 20:26:58 | 显示全部楼层
本帖最后由 夏末渐离 于 2015-12-31 20:29 编辑

1.请将目光投在你贴出来的脚本的52行。

2.将52行改为this._callingSelectedEvent = false;

3.进入游戏测试。

点评

于是应该被版主改好了……  发表于 2016-1-1 19:30
当时好奇,能不能再点一次~~  发表于 2016-1-1 13:43
应该把本帖标记为已经解决而不是已经过期,方便其他人搜索  发表于 2015-12-31 21:21
感谢,认可该楼。  发表于 2015-12-31 20:53

评分

参与人数 2星屑 +10 梦石 +1 收起 理由
余烬之中 + 1 0x0
负零 + 10 认可答案

查看全部评分

  点我进入    
       ↓      
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部