//=============================================================================
// AltMenuScreen2.js
//=============================================================================

/*:
 * @plugindesc Alternative menu screen layout.
 * @author Yoji Ojima, Sasuke KANNAZUKI
 *
 * @param backGroundBitmap
 * @desc background bitmap file at img/pictures.
 * @default
 *
 * @param maxColsMenu
 * @desc max column at menu window
 * @default 4
 *
 * @param commandRows
 * @desc number of visible rows at command window
 * @default 2
 *
 * @param isDisplayStatus
 * @desc whether display status or not. (1 = yes, 0 = no)
 * @default 0
 *
 * @help This plugin does not provide plugin commands.
 *  The differences with AltMenuscreen are follows:
 *   - windows are transparent
 *   - it can set the menu's background bitmap.
 *   - picture is actors' original
 *
 * Actor' note:
 *  set actor's standing picture at menu.
 *   put file at img/pictures.
 *
 * preferred size of actor's picture:
 * width: 174px(maxColsMenu=4), 240px(maxColsMenu=3)
 * height: 408px(commandRows=2), 444px(commandRows=1)
 */

/*:ja
 * @plugindesc レイアウトの異なるメニュー画面
 * @author Yoji Ojima, 神無月サスケ
 *
 * @param backGroundBitmap
 * @desc 背景にするビットマップファイルです。
 * img/pictures に置いてください。
 * @default
 *
 * @param maxColsMenu
 * @desc アクターを表示するウィンドウの1画面の登録最大数です。
 * @default 4
 *
 * @param commandRows
 * @desc コマンドウィンドウの行数です。
 * @default 2
 *
 * @param isDisplayStatus
 * @desc ステータスを表示するかしないかを選びます。(1 = yes, 0 = no)
 * @default 0
 *
 * @help このプラグインには、プラグインコマンドはありません。
 *
 *  AltMenuscreen との違いは以下です:
 *  - ウィンドウが透明です
 *  - 背景ビットマップを付けることが出来ます。
 *  - アクターに立ち絵を利用します。
 *
 * アクターのメモに以下のように書いてください:
 *  ファイル名が、そのアクターの立ち絵になります。
 *   ファイルは img/pictures に置いてください。
 *
 * 望ましいアクター立ち絵のサイズ:
 * 幅:3列:240px, 4列:174px
 * 高さ: コマンドウィンドウ 1行:444px 2行:408px
 *
 */

 /*:ch
 * @plugindesc
 * 通过填写参数来定制你的ESC菜单布局。
 *
 * @author
 * Yoji Ojima, Sasuke KANNAZUKI
 *
 * @param backGroundBitmap
 * @desc 背景图片(Bitmap),将背景图片保存在img/pictures。
 * @default
 *
 * @param maxColsMenu
 * @desc 菜单最大列数,菜单窗口的最大列数
 * @default 4
 *
 * @param commandRows
 * @desc 指令行数,在指令窗口内可见的指令行数
 * @default 2
 *
 * @param isDisplayStatus
 * @desc 是否显示角色状态,选择是否显示角色状态属性(1 = 显示,0 = 不显示)
 * @default 0
 *
 * @help
 * 本插件与AltMenuScreen插件的不同有以下几点:
 * - 窗口是透明的
 * - 可以自己设定窗口背景图
 * - 可定制角色的菜单显示图(默认为脸图)
 *   - 在角色的备注内填写,即可设置角色的菜单显示图
 *   - 注意图片应当放置在img/pictures目录下
 *   - filename不含后缀
 *
 * 角色的菜单显示图的最佳尺寸:
 * - 菜单最大列数为4时,宽度为174像素。
 * - 菜单最大列数为3时,宽度为240像素。
 * - 指令选项行数为2时,高度为408像素。
 * - 指令选项行数为1时,高度为444像素。
 */

(function() {

    // set parameters                                                                   // 设置参数
    var parameters = PluginManager.parameters('AltMenuScreen2');                        // 获取插件管理器中AltMenuScreen2的参数列表,保存到parameters中
    var backGroundBitmap = parameters['backGroundBitmap'] || '';                        // 获取“背景图片(参数)”内容,默认为空
    var maxColsMenuWnd = Number(parameters['maxColsMenu'] || 4);                        // 获取“菜单最大列数(参数)”内容,默认为4
    var rowsCommandWnd = Number(parameters['commandRows'] || 2);                        // 获取“指令行数(参数)”内容,默认为2
    var isDisplayStatus = !!Number(parameters['isDisplayStatus']);                      // 获取“是否显示角色状态(参数)”内容,默认为【?】

    var _Scene_Menu_create = Scene_Menu.prototype.create;                               // 用_Scene_Menu_create指向原始的创建菜单函数
    Scene_Menu.prototype.create = function() {                                          // 追加用于本插件的创建菜单函数
        _Scene_Menu_create.call(this);                                                      // 调用原始的创建菜单函数
        this._statusWindow.x = 0;                                                           // 设置状态窗口的X坐标为0
        this._statusWindow.y = this._commandWindow.height;                                  // 设置状态窗口的Y坐标为指令窗口的高度
        this._goldWindow.x = Graphics.boxWidth - this._goldWindow.width;                    // 设置金币窗口的X坐标为游戏窗口的宽度 - 金币窗口的宽度
        // make transparent for all windows at menu scene.                                  // 注释:设置ESC菜单界面内的所有窗口的透明度为0
        this._statusWindow.opacity = 0;                                                     // 设置状态窗口的透明度为0
        this._goldWindow.opacity = 0;                                                       // 设置金币窗口的透明度为0
        this._commandWindow.opacity = 0;                                                    // 设置指令窗口的透明度为0
    };

    // load bitmap that set in plugin parameters                                        // 注释:载入“背景图片”参数所指向的图片
    var _Scene_Menu_createBackground = Scene_Menu.prototype.createBackground;           // 用_Scene_Menu_createBackground指向原始的创建背景函数
    Scene_Menu.prototype.createBackground = function(){                                 // 追加用于本插件的创建背景函数
        if(backGroundBitmap){                                                               // 如果“背景图片”参数有内容
            this._backgroundSprite = new Sprite();                                              // 为本场景创建一个新的背景图精灵
            this._backgroundSprite.bitmap = ImageManager.loadPicture(backGroundBitmap);         // 调用图片管理器,为精灵的Bitmap设值,调用的图片路径为参数的地址
            this.addChild(this._backgroundSprite);                                              // 为本场景添加背景图精灵
            return;                                                                             // 结束本次函数运行
        }
        // if background file is invalid, it does original process.                         // 注释:如果背景文件不存在,则调用原始的创建背景函数
        _Scene_Menu_createBackground.call(this);                                            // 调用原始的创建背景函数
    };

    Window_MenuCommand.prototype.windowWidth = function() {                             // 重定义指令窗口的宽度
        return Graphics.boxWidth;                                                           // 返回游戏窗口宽度
    };

    Window_MenuCommand.prototype.maxCols = function() {                                 // 重定义指令窗口项目的最大列数
        return 4;                                                                           // 返回⑨
    };

    Window_MenuCommand.prototype.numVisibleRows = function() {                          // 重定义指令窗口项目的可见行数
        return rowsCommandWnd;                                                              // 返回“指令行数(参数)”
    };

    Window_MenuStatus.prototype.windowWidth = function() {                              // 重定义状态窗口的宽度
        return Graphics.boxWidth;                                                           // 返回游戏窗口宽度
    };

    Window_MenuStatus.prototype.windowHeight = function() {                             // 重定义状态窗口的高度
        var h1 = this.fittingHeight(1);                                                     // 【?】自动适配1行项目的高度
        var h2 = this.fittingHeight(rowsCommandWnd);                                        // 【?】自动适配“指令行数(参数)”行项目的高度
        return Graphics.boxHeight - h1 - h2;                                                // 返回游戏窗口高度-【?】-【?】
    };

    Window_MenuStatus.prototype.maxCols = function() {                                  // 重定义状态窗口的最大列数
        return maxColsMenuWnd;                                                              // 返回“指令列数(参数)”
    };

    Window_MenuStatus.prototype.numVisibleRows = function() {                           // 重定义状态窗口的可见行数
        return 1;                                                                           // 返回奥特曼变身器
    };

    Window_MenuStatus.prototype.drawItemImage = function(index) {                       // 重定义状态窗口的项目图片绘制函数
        var actor = $gameParty.members()[index];                                            // 获取角色队伍中排序为index的角色
        var rect = this.itemRectForText(index);                                             // 获取排序为index的项目图片绘制区域
        // load stand_picture                                                               // 注释:读取标准角色图
        var bitmapName = $dataActors[actor.actorId()].meta.stand_picture;                   // 【?】读取当前角色的标准角色图名字
        var bitmap = bitmapName ? ImageManager.loadPicture(bitmapName) : null;              // 如果角色图名字不为空,则载入角色图,否则不载入图片
        var w = Math.min(rect.width, (bitmapName ? bitmap.width : 144));                    // 如果角色图名字不为空,则读取项目图片绘制区域或角色图的宽度中较小的一个,如果没有角色图,则认为角色图宽度为144
        var h = Math.min(rect.height, (bitmapName ? bitmap.height : 144));                  // 如果角色图名字不为空,则读取项目图片绘制区域或角色图的高度中较小的一个,如果没有角色图,则认为角色图高度为144
        var lineHeight = this.lineHeight();                                                 // 读取状态窗口的行高
        this.changePaintOpacity(actor.isBattleMember());                                    // 【?】改变绘制功能的透明度
        if(bitmap){                                                                         // 如果存在角色图
            var sx = (bitmap.width > w) ? (bitmap.width - w) / 2 : 0;                           // 一套算法,用于计算出适配角色图的区域坐标
            var sy = (bitmap.height > h) ? (bitmap.height - h) / 2 : 0;                         // ...
            var dx = (bitmap.width > rect.width) ? rect.x :                                     // ...
                rect.x + (rect.width - bitmap.width) / 2;                                       // ...
            var dy = (bitmap.height > rect.height) ? rect.y :                                   // ...
                rect.y + (rect.height - bitmap.height) / 2;                                     // ...
            this.contents.blt(bitmap, sx, sy, w, h, dx, dy);                                    // ...
        } else { // when bitmap is not set, do the original process.                        // 如果不存在角色图,则调用原始的状态窗口的项目图片绘制函数
            this.drawActorFace(actor, rect.x, rect.y + lineHeight * 2.5, w, h);                 // 为当前角色绘制角色图(脸图)
        }
        this.changePaintOpacity(true);                                                      // 【?】恢复绘制功能的透明度
    };

    Window_MenuStatus.prototype.drawItemStatus = function(index) {                      // 重定义状态窗口的项目属性绘制函数
        if(!isDisplayStatus){                                                               // 如果“是否显示角色状态(参数)”为否
            return;                                                                             // 结束本次调用
        }
        var actor = $gameParty.members()[index];                                            // 读取角色队伍中排序为index的角色
        var rect = this.itemRectForText(index);                                             // 读取排序为index的项目图片绘制区域
        var x = rect.x;                                                                     // 获取排序为index的项目图片绘制区域的X坐标
        var y = rect.y;                                                                     // 获取排序为index的项目图片绘制区域的Y坐标
        var width = rect.width;                                                             // 获取排序为index的项目图片绘制区域的宽度
        var bottom = y + rect.height;                                                       // 获取排序为index的项目图片绘制区域的底部坐标
        var lineHeight = this.lineHeight();                                                 // 获取状态窗口的行高
        this.drawActorName(actor, x, y + lineHeight * 0, width);                            // 绘制排序为index的角色姓名
        this.drawActorLevel(actor, x, y + lineHeight * 1, width);                           // 绘制排序为index的角色等级
        this.drawActorClass(actor, x, bottom - lineHeight * 4, width);                      // 绘制排序为index的角色职业
        this.drawActorHp(actor, x, bottom - lineHeight * 3, width);                         // 绘制排序为index的角色生命值
        this.drawActorMp(actor, x, bottom - lineHeight * 2, width);                         // 绘制排序为index的角色魔法值
        this.drawActorIcons(actor, x, bottom - lineHeight * 1, width);                      // 【?】绘制排序为index的角色状态图标
    };

    var _Window_MenuActor_initialize = Window_MenuActor.prototype.initialize;           // 用_Window_MenuActor_initialize指向原始的菜单角色初始化函数
    Window_MenuActor.prototype.initialize = function() {                                // 重定义菜单角色初始化函数
        _Window_MenuActor_initialize.call(this);                                            // 调用原始的菜单角色初始化函数
        this.y = this.fittingHeight(2);                                                     // 【?】设置菜单角色的Y坐标为两行项目的行高
    };

})();