• [RPG MV] 2017.05.29 PM 05:55

게시물 주소 FONT글자 작게하기 글자 키우기

/*:

* @help SceneManager.goto(SelectScene)

* @plugindesc 목록을 선택할 새 씬과 윈도우를 출력한다. V2

* @author 파렌하이트

*/


// --scene--

// 씬 생성

    function SelectScene() {

        this.initialize.apply(this, arguments);

    }


    SelectScene.prototype = Object.create(Scene_MenuBase.prototype);

    SelectScene.prototype.constructor = Scene_Menu;


    SelectScene.prototype.initialize = function() {

        Scene_MenuBase.prototype.initialize.call(this);

    };


    SelectScene.prototype.create = function() {

        Scene_MenuBase.prototype.create.call(this);

        this.createWindow();

    };


    SelectScene.prototype.start = function() {

        Scene_MenuBase.prototype.start.call(this);

        this.Connect();

    };


    SelectScene.prototype.createWindow = function(){

        this._newWindow = new SelectWindow(0, 0);

        this.addWindow(this._newWindow);

    }

    

    SelectScene.prototype.update = function(){

        Scene_MenuBase.prototype.update.call(this);

        

        if(Input.isTriggered('cancel')){    // out

            this.DisConnect();

        }

    }

    

    // Scene 실행시

    SelectScene.prototype.Connect = function(){

        console.log('connect');

    }

    // Scene 종료시

    SelectScene.prototype.DisConnect = function(){

        SceneManager.goto(Scene_Map);

        SoundManager.playCancel();

        console.log('disconnect');

    }

    

// --variables

// 변수들

        var length = 15;

        var list = new Array(length);

        for(var i = 0; i < list.length; i++)

        {

            list[i] = 'slot ' + i;

        }



// ---Selectable window---

// 선택박스를 출력하는 윈도우를 구현한다.

    function SelectWindow() {

        this.initialize.apply(this, arguments);

    }


    SelectWindow.prototype = Object.create(Window_Selectable.prototype);

    SelectWindow.prototype.constructor = SelectWindow;


    SelectWindow.prototype.initialize = function(x, y, width, height) {

        Window_Selectable.prototype.initialize.call(this, x, y, 200, 500);

        this.select(0); // 초기 커서의 위치

        this.maxItems();

        this.drawAllItems();

    }

    

    // 아이템 배열의 최대값을 지정한다.

    SelectWindow.prototype.maxItems = function() {

        return length;

    };


    // 지정된 아이템 배열의 수 만큼 반복한다.

    SelectWindow.prototype.drawAllItems = function() {

    var topIndex = this.topIndex();

    for (var i = 0; i < this.maxPageItems(); i++) {

        var index = topIndex + i;

        if (index < this.maxItems()) {

            this.drawItem(index);

            }

        }

    };


    // 지정된 아이템 배열 값을 출력한다.

    SelectWindow.prototype.drawItem = function(index) {

        var rect = this.itemRectForText(index);

        // var align = this.itemTextAlign();

        // this.resetTextColor();

        // this.changePaintOpacity(this.isCommandEnabled(index));

        this.drawText(list[index], rect.x, rect.y, rect.width, 0);

    };

    

    SelectWindow.prototype.update = function(){

        Window_Selectable.prototype.update.call(this);

        this.cursorMove();

        this.scrollingKey();

        this.scrollingWheel();

    }

    

    // 커서를 움직인다.

    SelectWindow.prototype.cursorMove = function(){

        if (Input.isRepeated('up')) {

            this.cursorUp(Input.isTriggered('up'));

        }

        else if (Input.isRepeated('down')) {

            this.cursorDown(Input.isTriggered('down'));

        //  console.log(this._index);

        }

    }

    

    // 키보드의 페이지업/다운키로 스크롤을 움직인다.

    SelectWindow.prototype.scrollingKey = function(){

        if (!this.isHandled('pagedown') && Input.isTriggered('pagedown')) {

            this.cursorPagedown();

        }

        if (!this.isHandled('pageup') && Input.isTriggered('pageup')) {

            this.cursorPageup();

        }

    }

    

    // 마우스 휠로 스크롤을 움직인다.

    SelectWindow.prototype.scrollingWheel = function(){

        if (TouchInput.wheelY >= 20) {

            this.scrollDown();

        }

        if (TouchInput.wheelY <= -20) {

            this.scrollUp();

        }

    }

 

과거 단순히 씬과 윈도우를 만들어 출력하는 것에서 살짝 더 발전하여, 선택이 가능한 목록을 구현하였다.

유니티에서 써먹었던 꼼수로도 구현이 가능하나, 효율이 엄청나게 나빠지기 때문에 어쩔수없이 기본으로 지원하는 함수들을 이리저리 찾아가며 구현하였다. 뭐 이렇게 표현을 했지만 대부분 복사, 붙여넣기 신공이고 몇몇 변수를 살짝 바꾸어주니 운좋게 작동하는 것 뿐이지.

 

댓글 : 0 개
친구글 비밀글 댓글 쓰기