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

Toshico
記事: 8
登録日時: 2016年2月15日(月) 17:37

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

投稿記事by Toshico » 2018年4月23日(月) 18:31

スクリプト初心者です。
とんちんかんなことを言ってたらすみません。

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

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

Scene_Battleのみをいじる方法でも、Scene_Battleに追加したウィンドウをprocessVictory内で表示させる方法でも構いませんので、やりたいことを実現させる方法がありましたら、ご教示ください。
最後に編集したユーザー Toshico on 2018年4月23日(月) 21:29 [ 編集 1 回目 ]

アバター
しぐれん
記事: 972
登録日時: 2017年3月28日(火) 22:22
連絡を取る:

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

投稿記事by しぐれん » 2018年4月23日(月) 18:48

Toshico さんが書きました:スクリプト初心者です。
とんちんかんなことを言ってたらすみません。

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

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

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


とりあえず、書いたプラグインをここにアップしてみてください。
「ウィンドウが表示されない」は原因が複数あるので、中身を見ないと分かりません。
また、選択肢を表示とありますが、どのような内容を表示するのでしょうか?
現在、プラグイン依頼はお休み中です。
Toshico
記事: 8
登録日時: 2016年2月15日(月) 17:37

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

投稿記事by Toshico » 2018年4月23日(月) 19:24

コードはこんな感じです。
よろしくお願いします。

コード: 全て選択

(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);
    }
   
})();

Toshico
記事: 8
登録日時: 2016年2月15日(月) 17:37

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

投稿記事by Toshico » 2018年4月23日(月) 19:48

(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 とエラーが出てダメでした。
アバター
まっつUP
記事: 1155
登録日時: 2016年8月11日(木) 15:38
お住まい: タケノコ王国

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

投稿記事by まっつUP » 2018年4月23日(月) 19:57

Toshico様

this.createEndWindow;は
this.createEndWindow();にした方がよいと思います。
RPGで笑顔を・・・

ツイッター(ツクラーの巣窟)(閲覧は自己責任でお願いします)
https://twitter.com/mattuup

github
https://github.com/mattuup/RPGMakerMZ
Toshico
記事: 8
登録日時: 2016年2月15日(月) 17:37

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

投稿記事by Toshico » 2018年4月23日(月) 20:16

ご指摘ありがとうございます。
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);
    }
   
})();
Toshico
記事: 8
登録日時: 2016年2月15日(月) 17:37

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

投稿記事by Toshico » 2018年4月23日(月) 20:29

hide()をClose()に、show()をopen()に変えたら、戦闘開始時に選択肢がアクティブになってしまうのは回避できましたが、やはり、戦闘終了後の画面では↑の画像のように半端な表示になってしまうようです。
アバター
フトコロ
記事: 1029
登録日時: 2017年2月06日(月) 21:32

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

投稿記事by フトコロ » 2018年4月23日(月) 21:09

こんにちは。

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

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

このままだと、ログウィンドウよりも下になるため、
添付写真のようにログウィンドウに隠れてしまいます。
---------------------------------------------------------------------------------------------------
プラグイン置き場(GitHub)
https://github.com/futokoro/RPGMaker/blob/master/README.md

検討中の内容は上記リンク先の「対応するかもしれないプラグインのメモ」を参照してください。
アバター
まっつUP
記事: 1155
登録日時: 2016年8月11日(木) 15:38
お住まい: タケノコ王国

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

投稿記事by まっつUP » 2018年4月23日(月) 21:19

this._endWindow.active();のところって
this._endWindow.activate();でいいですよね。
RPGで笑顔を・・・

ツイッター(ツクラーの巣窟)(閲覧は自己責任でお願いします)
https://twitter.com/mattuup

github
https://github.com/mattuup/RPGMakerMZ
Toshico
記事: 8
登録日時: 2016年2月15日(月) 17:37

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

投稿記事by Toshico » 2018年4月23日(月) 21:25

>>フトコロさん、まっつUPさん
ご指摘の通りにしたところ、無事、思ってた通りの動きになりました。
みなさん、回答ありがとうございました。

“MV:質問” へ戻る