/*:
 * @plugindesc 
 * @author ぬぷ竜
 */
const DiPnlUIPath = "pictures/UI_DiadPnl/";
const SW_DiPnl = 402; 
const VN_DiPnlAns = 142; 
const VN_DiPnlVLv = 143; 
let dpFlame = 0; 
let dp_SrtFlame = 0; 
let dp_OpnFlame = 0; 
let dp_OpnSelNo = -1; //オープン選択No(0～8)
let _dpPnl_Arr = []; 
Game_Interpreter.prototype.PS_DiadPnl_Start = function () {
    dp_SrtFlame = 0;
    dpFlame = 0; 
    dp_OpnFlame = 0;
    if (Menu_ItemMode == 1) {
        this.Layer1_DelBtm(PN_IUBack); 
        this.Layer1_DelTop();
        Menu_EditLayer = 1; Menu_ItemMode = 0;
        MenuCngOkFlg = true;
    }
}
let _FullOpenFlg = false; 
let _dpMaxStart = 90;
let _dpEvFlg = false; 
Game_Interpreter.prototype.PS_DiadPnl = function () {
    if (dp_SrtFlame <= _dpMaxStart){ 
        if (dp_SrtFlame == 0) this.SetPictFIn(PN_LoadBase, DiPnlUIPath + "PN_LoadBase", 0, 0, 0, 0, 10);
        if (dp_SrtFlame >= 10 && dp_SrtFlame <= (_dpMaxStart - 10)){
            let _Wari = ((dp_SrtFlame - 10) / (_dpMaxStart - 20)) * 100;
            this.SetPict(PN_LoadGage, DiPnlUIPath + "PN_LoadGage", 403, 376, 255, _Wari);
        }
        dp_SrtFlame++;
        return true;
    }
    if (dpFlame == 0) {
        _FullOpenFlg = false;
        this.PS_DiadPnl_View();
        if (_FullOpenFlg) { 
            $gameVariables.setValue(VN_DiPnlAns, -1);
            return false;
        }
    }
    if (_dpEvFlg && dpFlame > 30) {
        if (TouchInput.isTriggered()) return false;
        return true;
    }
    if (dpFlame > 30 && dp_OpnFlame == 0) {
        this.PicCngColorArr(_dpPnl_Arr); 
        let _ckNo = overPointerCkArr(_dpPnl_Arr);
        if (_ckNo != -1) { 
            switch (_ckNo) {
                default:
                    dp_OpnSelNo = _ckNo - PN_dpPnl; 
                    if (!$gameSwitches.value(SW_DiPnl + dp_OpnSelNo)) {
                        this.PicCngColor(_ckNo, [100, 100, 100, 0]);
                        if (TouchInput.isTriggered()) {
                            $gameVariables.setValue(VN_DiPnlAns, dp_OpnSelNo); 
                            $gameSwitches.setValue(SW_DiPnl + dp_OpnSelNo, true); 
                            dp_OpnFlame = 1; 
                        }
                    }
                    break;
            }
        }
    }
    if (dp_OpnFlame >= 1){
        this.PS_DiadPnl_Open();
    }
    if (dp_OpnFlame == 120) { 
        //this.PS_DiadPnl_Close();
        return false;
    }
    dpFlame++;
    return true;
};
Game_Interpreter.prototype.PS_DiadPnl_Open = function () {
    let _copnflm = 15;
    if (dp_OpnFlame == 1) {
        this.MovePict(PN_dpPnl + dp_OpnSelNo, true, true, _copnflm, 255, 0);
    }
    if (dp_OpnFlame == _copnflm + 1) {
        this.PicCngColorArr(_dpPnl_Arr); 
        let _setX = dpPos._x + (dp_OpnSelNo % 3) * 168;
        let _rowNo = Math.floor(dp_OpnSelNo / 3);
        let _setY = dpPos._y + _rowNo * 168;
        this.SetPictC(PN_dpPnl + dp_OpnSelNo, DiPnlUIPath + "PN_dpPnl_" + dp_OpnSelNo,
            _setX, _setY, 255, 0);
        this.MovePict(PN_dpPnl + dp_OpnSelNo, true, true, 30, 255);
    }
    dp_OpnFlame++;
};
Game_Interpreter.prototype.PS_DiadPnl_Close = function () {
    for (let i = PN_LoadBase; i <= PN_spEnd; i++) {
        this.DelPict(i);
    }
    this.DelPict(126); 
};
let dpPos = new Pos2D(551, 356); 
Game_Interpreter.prototype.PS_DiadPnl_View = function () {
    let _opi = 0; 
    this.SetPict(PN_dpBack, DiPnlUIPath + "PN_dpBack", 0, 0, _opi);
    this.MovePict(PN_dpBack, true, true, 10);
    this.SetPict(PN_dpBar + 0, DiPnlUIPath + "PN_dpBar_T", 0, -30, _opi);
    this.SetPict(PN_dpBar + 1, DiPnlUIPath + "PN_dpBar_B", 0, +30, _opi);
    this.MovePict(PN_dpBar + 0, 0, 0, 30);
    this.MovePict(PN_dpBar + 1, 0, 0, 30);
    this.SetPict(PN_dpLevel, DiPnlUIPath + "PN_dpLevel", +30, 0, _opi);
    this.MovePict(PN_dpLevel, 0, 0, 30);
    this.SetPict(PN_dpRuru, DiPnlUIPath + "PN_dpRuru", -30, 0, _opi);
    this.MovePict(PN_dpRuru, 0, 0, 30);
    this.SetPict(PN_dpCmnt, DiPnlUIPath + "PN_dpCmnt", -30, 0, _opi);
    this.MovePict(PN_dpCmnt, 0, 0, 30);
    this.SetPict(PN_dpRoma, DiPnlUIPath + "PN_dpRoma_0", 0, 0, _opi);
    this.MovePict(PN_dpRoma, true, true, 40);
    let _opnCnt = 0; 
    for (let i = 0; i <= 9 - 1; i++) {
        let _setX = dpPos._x + (i % 3) * 168;
        let _rowNo = Math.floor(i / 3);
        let _setY = dpPos._y + _rowNo * 168;
        let _ckLv = 0;
        switch (_rowNo) {
            case 0: _ckLv = 2; break;
            case 1: _ckLv = 1; break;
            case 2: _ckLv = 3; break;
        }
        if ($gameSwitches.value(SW_DiPnl + i)) {
            this.SetPictC(PN_dpPnl + i, DiPnlUIPath + "PN_dpPnl_U_" + (_ckLv - 1) + "B", _setX, _setY, _opi);
            _opnCnt++;
        } else {
            let SetStr = "U_" + _rowNo;
            if ($gameVariables.value(VN_DiPnlVLv) < _ckLv) {
                SetStr = "L_" + _rowNo;
            } else {
                _dpPnl_Arr.push(PN_dpPnl + i);
            }
            this.SetPictC(PN_dpPnl + i, DiPnlUIPath + "PN_dpPnl_" + SetStr, _setX, _setY, _opi);
        }
        this.MovePict(PN_dpPnl + i, true, true, 30);
    }
     _FullOpenFlg = (_opnCnt >= 9);
}
let ad_SrtFlame = 0; let _adMaxStart = 90;
Game_Interpreter.prototype._アドレス追加_初期化 = function (_SetTime) {
    _SetTime = typeof _SetTime !== 'undefined' ? _SetTime : 90;
    ad_SrtFlame = 0; 
    _adMaxStart = _SetTime;
}
let _アドレス追加Img = "PN_AddBase";
Game_Interpreter.prototype._アドレス追加_演出 = function () {
    if (ad_SrtFlame <= _adMaxStart) { 
        if (ad_SrtFlame == 0) this.SetPictFIn(PN_LoadBase, DiPnlUIPath + _アドレス追加Img, 0, 0, 0, 0, 10);
        if (ad_SrtFlame >= 10 && ad_SrtFlame <= (_adMaxStart - 10)) {
            let _Wari = ((ad_SrtFlame - 10) / (_adMaxStart - 20)) * 100;
            this.SetPict(PN_LoadGage, DiPnlUIPath + "PN_LoadGage", 403, 376, 255, _Wari);
        }
        ad_SrtFlame++;
        return true;
    }
    return false;
}
Game_Interpreter.prototype._アドレス追加_終了 = function () {
    this.MovePict(PN_LoadBase, true, true, 15, 0);
    this.MovePict(PN_LoadGage, true, true, 15, 0);
}
