ページ 11

【解決済み】戦闘終了時に選択肢ウィンドウを表示する方法

Posted: 2018年4月23日(月) 18:31
by Toshico
スクリプト初心者です。
とんちんかんなことを言ってたらすみません。

・やりたいこと
戦闘の終わり(経験値等の処理が終了してからScene_Battleが終了するまでの間)に選択肢ウィンドウを表示させたいです。

・試した方法
BattleManager.processVictoryに処理を追加して実現しようと思ったのですが、BattleManagerにはWindowレイヤーが無いので、Scene_Battleに目的のウィンドウに関する処理を追加しました。
しかし、それをprocessVictory内で画面に表示させる方法がわからず、断念しました。

Scene_Battleのみをいじる方法でも、Scene_Battleに追加したウィンドウをprocessVictory内で表示させる方法でも構いませんので、やりたいことを実現させる方法がありましたら、ご教示ください。

Re: 戦闘終了時に選択肢ウィンドウを表示する方法

Posted: 2018年4月23日(月) 18:48
by しぐれん
Toshico さんが書きました:スクリプト初心者です。
とんちんかんなことを言ってたらすみません。

・やりたいこと
戦闘の終わり(経験値等の処理が終了してからScene_Battleが終了するまでの間)に選択肢ウィンドウを表示させたいです。

・試した方法
BattleManager.processVictoryに処理を追加して実現しようと思ったのですが、BattleManagerにはWindowレイヤーが無いので、Scene_Battleに目的のウィンドウに関する処理を追加しました。
しかし、それをprocessVictory内で画面に表示させる方法がわからず、断念しました。

Scene_Battleのみをいじる方法でも、Scene_Battleに追加したウィンドウをprocessVictory内で表示させる方法でも構いませんので、やりたいことを実現させる方法がありましたら、ご教示ください。
とりあえず、書いたプラグインをここにアップしてみてください。
「ウィンドウが表示されない」は原因が複数あるので、中身を見ないと分かりません。
また、選択肢を表示とありますが、どのような内容を表示するのでしょうか?

Re: 戦闘終了時に選択肢ウィンドウを表示する方法

Posted: 2018年4月23日(月) 19:24
by Toshico
コードはこんな感じです。
よろしくお願いします。

コード: 全て選択

(function () {
    'use strict';
    BattleManager.processVictory = function() {
        $gameParty.removeBattleStates();
        $gameParty.performVictory();
        this.playVictoryMe();
        this.replayBgmAndBgs();
        this.makeRewards();
        this.displayVictoryMessage();
        this.displayRewards();
        this.gainRewards();
        
        //このタイミングで選択肢を追加したい。戦闘シーンが終わる前ならここじゃなくてもいい。
        this.displayEndCommand();
        
        this.endBattle(0);
    };
    BattleManager.displayEndCommand = function(){
        //ここで選択肢ウィンドウを開きたい。
    }
    
    //Scene_Battleに選択肢を追加。
    var _Scene_Battle_createAllWindows = Scene_Battle.prototype.createAllWindows;
    Scene_Battle.prototype.createAllWindows = function(){
        this.createEndWindow;
        _Scene_Battle_createAllWindows.call(this);
    }
    Scene_Battle.prototype.createEndWindow = function(){
        this._endWindow = new Window_endCommand(560,300);
        this._endWindow.setHandler("yes",this.onYes.bind(this));
        this._endWindow.setHandler("no",this.onNo.bind(this));
        this._endWindow.setHandler("cancel",this.onNo.bind(this));
        this.addWindow(_endWindow);
    }
    Scene_Battle.prototype.onYes = function(){
        //はいの時の処理。
    }
    Scene_Battle.prototype.onNo = function(){
        //いいえの時の処理。
    }
    
    //選択肢ウィンドウを用意。
    function Window_endCommand(){
        this.initialize.apply(this,arguments);
    }
    Window_endCommand.prototype = Object.create(Window_Command.prototype);
    Window_endCommand.prototype.constructor = Window_endCommand;
    Window_endCommand.prototype.makeCommandList = function(){
        this.addCommand("はい","yes",true);
        this.addCommand("いいえ","no",true);
    }
    
})();


Re: 戦闘終了時に選択肢ウィンドウを表示する方法

Posted: 2018年4月23日(月) 19:48
by Toshico
(function () {
'use strict';
BattleManager.processVictory = function() {
$gameParty.removeBattleStates();
$gameParty.performVictory();
this.playVictoryMe();
this.replayBgmAndBgs();
this.makeRewards();
this.displayVictoryMessage();
this.displayRewards();
this.gainRewards();

//このタイミングで選択肢を追加したい。戦闘シーンが終わる前ならここじゃなくてもいい。
this.displayEndCommand();

this.endBattle(0);
};
BattleManager.displayEndCommand = function(){
//ここで選択肢ウィンドウを開きたい。
this._endWindow.show();
}
BattleManager.setEndCommand = function(endWindow){
this._endWindow = endWindow;
}


//Scene_Battleに選択肢を追加。
var _Scene_Battle_createAllWindows = Scene_Battle.prototype.createAllWindows;
Scene_Battle.prototype.createAllWindows = function(){
this.createEndWindow;
_Scene_Battle_createAllWindows.call(this);
}
Scene_Battle.prototype.createEndWindow = function(){
this._endWindow = new Window_endCommand(560,300);
this._endWindow.setHandler("yes",this.onYes.bind(this));
this._endWindow.setHandler("no",this.onNo.bind(this));
this._endWindow.setHandler("cancel",this.onNo.bind(this));
this._endWindow.hide();
this.addWindow(_endWindow);
BattleManager.setEndCommand(this._endWindow);
}
Scene_Battle.prototype.onYes = function(){
//はいの時の処理。
}
Scene_Battle.prototype.onNo = function(){
//いいえの時の処理。
}

//選択肢ウィンドウを用意。
function Window_endCommand(){
this.initialize.apply(this,arguments);
}
Window_endCommand.prototype = Object.create(Window_Command.prototype);
Window_endCommand.prototype.constructor = Window_endCommand;
Window_endCommand.prototype.makeCommandList = function(){
this.addCommand("はい","yes",true);
this.addCommand("いいえ","no",true);
}

})();

あと、自分で考えてこういう書き方もしてみたのですが、(太字が追加分)
Cannot read property 'show' of undefined とエラーが出てダメでした。

Re: 戦闘終了時に選択肢ウィンドウを表示する方法

Posted: 2018年4月23日(月) 19:57
by まっつUP
Toshico様

this.createEndWindow;は
this.createEndWindow();にした方がよいと思います。

Re: 戦闘終了時に選択肢ウィンドウを表示する方法

Posted: 2018年4月23日(月) 20:16
by Toshico
ご指摘ありがとうございます。
this.addWindow(_endWindow);
の引数にthis.が抜けてたところも気づいて直したらウィンドウは一応、一部表示されたのですが、思ったような表示になりませんでした。

画像

↑のように表示され、また戦闘開始時の「敵グループが出現。」というメッセージのところで決定キーを押す回数が1回増えていました。

コードは↓です。

コード: 全て選択

(function () {
    'use strict';
    BattleManager.processVictory = function() {
        $gameParty.removeBattleStates();
        $gameParty.performVictory();
        this.playVictoryMe();
        this.replayBgmAndBgs();
        this.makeRewards();
        this.displayVictoryMessage();
        this.displayRewards();
        this.gainRewards();
        
        //このタイミングで選択肢を追加したい。戦闘シーンが終わる前ならここじゃなくてもいい。
        this.displayEndCommand();
        
        this.endBattle(0);
    };
    BattleManager.displayEndCommand = function(){
        //ここで選択肢ウィンドウを開きたい。
        this._endWindow.show();
        this._endWindow.active();
    }
    BattleManager.setEndCommand = function(endWindow){
        this._endWindow = endWindow;
    }
    
    //Scene_Battleに選択肢を追加。
    var _Scene_Battle_createAllWindows = Scene_Battle.prototype.createAllWindows;
    Scene_Battle.prototype.createAllWindows = function(){
        this.createEndWindow();
        _Scene_Battle_createAllWindows.call(this);
    }
    Scene_Battle.prototype.createEndWindow = function(){
        this._endWindow = new Window_endCommand(560,300);
        this._endWindow.setHandler("yes",this.onYes.bind(this));
        this._endWindow.setHandler("no",this.onNo.bind(this));
        this._endWindow.setHandler("cancel",this.onNo.bind(this));
        this._endWindow.hide();
        this.addWindow(this._endWindow);
        BattleManager.setEndCommand(this._endWindow);
    }
    Scene_Battle.prototype.onYes = function(){
        //はいの時の処理。
    }
    Scene_Battle.prototype.onNo = function(){
        //いいえの時の処理。
    }
    
    //選択肢ウィンドウを用意。
    function Window_endCommand(){
        this.initialize.apply(this,arguments);
    }
    Window_endCommand.prototype = Object.create(Window_Command.prototype);
    Window_endCommand.prototype.constructor = Window_endCommand;
    Window_endCommand.prototype.makeCommandList = function(){
        this.addCommand("はい","yes",true);
        this.addCommand("いいえ","no",true);
    }
    
})();

Re: 戦闘終了時に選択肢ウィンドウを表示する方法

Posted: 2018年4月23日(月) 20:29
by Toshico
hide()をClose()に、show()をopen()に変えたら、戦闘開始時に選択肢がアクティブになってしまうのは回避できましたが、やはり、戦闘終了後の画面では↑の画像のように半端な表示になってしまうようです。

Re: 戦闘終了時に選択肢ウィンドウを表示する方法

Posted: 2018年4月23日(月) 21:09
by フトコロ
こんにちは。

恐らく選択肢ウィンドウの生成順番が問題かと。

//Scene_Battleに選択肢を追加。
var _Scene_Battle_createAllWindows = Scene_Battle.prototype.createAllWindows;
Scene_Battle.prototype.createAllWindows = function(){
this.createEndWindow;//これは、↓の処理の後がよい。
_Scene_Battle_createAllWindows.call(this);
}

このままだと、ログウィンドウよりも下になるため、
添付写真のようにログウィンドウに隠れてしまいます。

Re: 戦闘終了時に選択肢ウィンドウを表示する方法

Posted: 2018年4月23日(月) 21:19
by まっつUP
this._endWindow.active();のところって
this._endWindow.activate();でいいですよね。

Re: 戦闘終了時に選択肢ウィンドウを表示する方法

Posted: 2018年4月23日(月) 21:25
by Toshico
>>フトコロさん、まっつUPさん
ご指摘の通りにしたところ、無事、思ってた通りの動きになりました。
みなさん、回答ありがとうございました。