查看: 3783|回复: 1

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

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

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

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

×
如下插件:每次选择完公共事件后,并也执行了,但一直没有关闭窗口的操作及命令,最后的Onok里this.close()似乎无效,导致无限弹窗,除非按取消。求执行完公共事件后关闭窗口。
[pre lang="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 = '';
            }
            return true;
        } 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');
            return true;
        }
        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) {
            return this._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() {
        return 1;
    };

    Window_EventSelector.prototype.maxItems = function() {
        return this._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];
            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();
    };

})();
[/pre]
梦石
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.

在本版发帖返回顶部