Add static text on Window

● ARCHIVED · READ-ONLY
Started by Meuhmeuh 5 posts View original ↗
  1. Hello,
     
    Ihave a question about scripting.
     
    I would like to do Yes No Window in menu.
     
    So i have made my Scene and My Window with a Window_Selectable, but i would like to add a static text into the top of the window ( not selectable ) how can i do this ? 
     
    Example:
     
    Would you like to do this ? 
    Yes                              No
  2. Try something like this.




    nameOfYourWindowSelectable.prototype.update = function() {


    Window_Selectable.prototype.update.call(this);


    this.contents.clear();


    this.drawStaticText(0, 0, this.windowWidth()/2);


    };


    nameOfYourWindowSelectable.prototype.drawStaticText = function(x, y, width) {


    this.resetTextColor();


    var unitWidth = Math.min(80);


    this.drawText('Would you like to do this?', x, y, width - unitWidth, 'center');


    this.changeTextColor(this.systemColor());


    };
  3. Hello, thanks for your answer.

    Here is my Windowcode :

    function Window_ConfirmExit(){ this.initialize.apply(this, arguments);}Window_ConfirmExit.prototype = Object.create(Window_Command.prototype);Window_ConfirmExit.prototype.constructor = Window_ConfirmExit;Window_ConfirmExit.prototype.initialize = function() { Window_Command.prototype.initialize.call(this, 0, 0); this.updatePlacement(); this.openness = 0; this.open();};Window_ConfirmExit.prototype.update = function() { Window_Selectable.prototype.update.call(this); this.contents.clear(); this.drawStatic(); this.drawAllItems();};Window_ConfirmExit.prototype.drawStatic = function() { this.drawStaticText(FWS.askExit, 0,0,this.windowWidth());};Window_ConfirmExit.prototype.windowWidth = function() { return Graphics._width/2;};Window_ConfirmExit.prototype.maxCols = function() { return 2;};Window_ConfirmExit.prototype.maxRows = function() { return 2;};Window_ConfirmExit.prototype.drawItem = function(index){ var rect = this.itemRectForText(index); rect.y = 100 ; //Moving Y of the items; var align = this.itemTextAlign(); this.resetTextColor(); this.changePaintOpacity(this.isCommandEnabled(index)); this.drawText(this.commandName(index), rect.x, rect.y, rect.width, align);}Window_ConfirmExit.prototype.updatePlacement = function() { this.x = (Graphics.boxWidth - this.width) / 2; this.y = (Graphics.boxHeight - this.height) / 2;};Window_ConfirmExit.prototype.makeCommandList = function() { this.addCommand(FWS.exitYes, 'exitYes'); this.addCommand(FWS.exitNo, 'exitNo');};Window_ConfirmExit.prototype.drawStaticText = function(text, x,y,width) { this.resetTextColor(); var unitWidth = Math.min(80) this.drawText(text, x, y, width - unitWidth, "center"); this.changeTextColor(this.systemColor());};In the drawItem i changed the rect.y with an hard value for testing.

    This is what i've got:



    And if i don't change the rect.y value :



    I tried to increase manualy the windowHeight value but this have no effect on the display of the command.

    Do yo uhave an idea ? 
  4. Lemme digest your code for a minute.
  5. Sorry for the doube post. 

    I find a way to do it, by surcharging the clearItem and updateCursor function. for each i moved the rect.y by a lineHeight. This way i can simulate a row.

    Window_ConfirmExit.prototype.drawItem = function(index){ var rect = this.itemRectForText(index); rect.y += this.lineHeight(); this.resetTextColor(); this.changePaintOpacity(this.isCommandEnabled(index)); this.drawText(this.commandName(index), rect.x, rect.y, rect.width, "center");}Window_ConfirmExit.prototype.clearItem = function(index) { var rect = this.itemRect(index); rect.y += this.lineHeight(); this.contents.clearRect(rect.x, rect.y, rect.width, rect.height);};Window_ConfirmExit.prototype.updateCursor = function() { if (this._cursorAll) { var allRowsHeight = this.maxRows() * this.itemHeight(); this.setCursorRect(0, 0, this.contents.width, allRowsHeight); this.setTopRow(0); } else if (this.isCursorVisible()) { var rect = this.itemRect(this.index()); rect.y += this.lineHeight(); this.setCursorRect(rect.x, rect.y, rect.width, rect.height); } else { this.setCursorRect(0, 0, 0, 0); }};I don't think this is the best solution, but it's work. 

    Thanks for the help.