const FTraPicPath = "pictures/UI_FastTra/";
const VN_FTra結果 = 144;
let _FTra初期選択No = 0;
let _転送Save = Game_System.prototype.initialize;
Game_System.prototype.initialize = function () { 
    _転送Save.call(this);
    this._FTraArr = []; 
};
let _ファストトラベル追加 = function (_TrNo) {
    if ($gameSystem._FTraArr.indexOf(_TrNo) == -1) {
        $gameSystem._FTraArr.push(_TrNo);
    }
}
let _FTra_SelNo_1 = -1;
let _FTra_SelNo_2 = -1;
let _FTra_Btn = []; 
let FTraPos = new Pos2D(115, 205);
let FTraSelPos = new Pos2D(106, 195);
let _FTraPicArr = [];
Game_Interpreter.prototype.FTraView = function () {
    _FTra_Btn = [];
    _FTra_SelNo_1 = _FTra_SelNo_2 = -1;
    this.SetPictFIn(PN_FBase, FTraPicPath + "PN_FBase", 0, 0, 0, 0, 15);
    for (let i = 0; i <= $gameSystem._FTraArr.length - 1; i++) {
        let _SetNo = $gameSystem._FTraArr[i];
        if (_FTra_Btn.length == 0) {
            _FTra_Btn.push([_SetNo]);
        } else {
            let _ckNo = Math.floor(_SetNo / 10);
            let _AddFlg = true;
            for (let j = 0; j <= _FTra_Btn.length - 1; j++) {
                if (Math.floor(_FTra_Btn[j][0] / 10) == _ckNo) {
                    _FTra_Btn[j].push(_SetNo);
                    _AddFlg = false;
                }
            }
            if (_AddFlg) _FTra_Btn.push([_SetNo]);
        }
    }
    _FTraPicArr = [];
    let _Cnt = 0;
    for (let i = 0; i <= _FTra_Btn.length - 1; i++) {
        let _ckNo = Math.floor(_FTra_Btn[i][0] / 10);
        let _PosX = FTraPos._x;
        let _PosY = FTraPos._y + _Cnt * 77;
        let _opi = 170;
        if (_Cnt == _FTra_SelNo_1) _opi = 255;
        this.SetPictFIn(PN_FBtn + i, FTraPicPath + "PN_FBtn" + _ckNo, _PosX, _PosY, 0, 0, 15, _opi);
        _FTraPicArr.push(PN_FBtn + i);
        _Cnt++;
    }
    if (_FTra_Btn.length >= _FTra初期選択No) _FTra初期選択No = _FTra_Btn.length - 1;
    this.SetPictFIn(PN_FBtn + 5, FTraPicPath + "PN_FBtn0", FTraPos._x, FTraPos._y + 5 * 77, 0, 0, 15);
    this.SetPictFIn(PN_FSelH, FTraPicPath + "PN_FSelH", FTraSelPos._x, FTraSelPos._y + _FTra初期選択No * 77, 0, 0, 15);
    this.FTraMoveBtnDraw(_FTra初期選択No);
    _FTra初期選択No = 0; 
};
let _FTraPicArr_2 = [];
Game_Interpreter.prototype.FTraMoveBtnDraw = function (_CngNo) {
    if (_CngNo == _FTra_SelNo_1) return; 
    _FTraPicArr_2 = [];
    this.DelPictSpan(PN_FBtn_2, PN_FBtn_2 + 5);
    for (let i = 0; i <= _FTra_Btn[_CngNo].length - 1; i++) {
        let _NoArr = String(_FTra_Btn[_CngNo][i]).split('');
        let _SetStr = "PN_FBtn" + _NoArr[0] + "_" + _NoArr[1];
        this.SetPictFIn(PN_FBtn_2 + i, FTraPicPath + _SetStr, FTraPos._x + 427, FTraPos._y + i * 77, 0, 0, 15);
        _FTraPicArr_2.push(PN_FBtn_2 + i);
    }
    _FTra_SelNo_1 = _CngNo;
}
Game_Interpreter.prototype.FTraUpdate = function () {
    let _CNo = overPointerCkArr(_FTraPicArr);
    if (_CNo != -1) {
        let _SetNo = _CNo - PN_FBtn;
        this.SetPict(PN_FSelH, FTraPicPath + "PN_FSelH", FTraSelPos._x, FTraSelPos._y + _SetNo * 77);
        for (let i = 0; i <= _FTra_Btn.length - 1; i++) {
            let _opi = 170;
            if (i == _SetNo) _opi = 255;
            this.MovePict(PN_FBtn + i, true, true, 5, _opi);
        }
        this.FTraMoveBtnDraw(_SetNo);
    }
    _CNo = overPointerCkArr(_FTraPicArr_2);
    if (_CNo != -1) {
        let _SetNo = _CNo - PN_FBtn_2;
        this.SetPict(PN_FSelH, FTraPicPath + "PN_FSelH2", FTraSelPos._x + 427, FTraSelPos._y + _SetNo * 77);
        if (TouchInput.isTriggered()) {
            let _RtnNo = _FTra_Btn[_FTra_SelNo_1][_SetNo];
            $gameVariables.setValue(VN_FTra結果, _RtnNo)
            return false;
        }
    }
    if (overPointerCk(PN_FBtn + 5)) {
        this.SetPict(PN_FSelH, FTraPicPath + "PN_FSelH", FTraSelPos._x, FTraSelPos._y + 5 * 77);
        if (TouchInput.isTriggered()) {
            $gameVariables.setValue(VN_FTra結果, 0)
            return false;
        }
    }
    if (Input.isTriggered('menu') || TouchInput.isCancelled()) {
        $gameVariables.setValue(VN_FTra結果, 0)
        return false; 
    }
    return true; 
};
Game_Interpreter.prototype._ファストトラベル終了 = function () {
    this.DelPict(PN_FBase);
    this.DelPictSpan(PN_FBtn, PN_FBtn + 5);
    this.DelPictSpan(PN_FBtn_2, PN_FBtn_2 + 5);
    this.DelPict(PN_FSelH);
}
