[SCRIPTING] [RMMV] SELECTABLE WINDOWS AND DATABASES

Posts

Pages: 1
Good morning,

It's been a long time since I went back to working on codes. Going with MV was a bit of a shocker (going from RGSS then a long hiatus, then JavaScript), so I'm... in a bit of a slump.

I watched a tutorial about making a basic window (which makes a window, but you can't do any action on it). So my question is...

...How is a selectable window made (and probably accessed through an event)?
...Is it possible to have the contents of the selectable window be from the database (like, showing the list of Actors, their classes, and level)?

I've included a mockup in Excel that I'm trying to accomplish:


Thank you very much~
Marrend
Guardian of the Description Thread
21781
I'm not exactly sure what the references are in MV, but, under VX Ace, the reference would be $game_actors[x].name for the actor's name, where x is their ID in the database. Class would be pretty similar ($game_actors[x].class.name), as would level ($game_actors[x].level).

I imagine formatting it into a table would be similar to the process in VX Ace. I assume MV has something similar to the Window_Selectable class, and it's "col_max" function that you could use to define how many columns are in the table. As for rows, I believe that's a combination of a number of "draw_text" functions to actually draw the text (Window_Selectable inherits this function from Window_Base), and probably "item_max" (from Window_Selectable).

Here's a semi-relevant screenshot from one of my games. This specific screen shot may not display the kind of information you want. However, I believe it gives an idea that what you're looking for is possible in Ace, and should be equally possible in MV. It would just be coded differently than it would in Ace. I'm sorry I can't be of more help, and tell you exactly what that would look like in MV, though.
Yes, I did work on something similar back in Ace, and I forgot where I placed the file... I'm not sure about the implementation in MV, and hopefully I can explore it more fully in the weekend.
My end goal with that table is to display a list of recruitable party members (to which you can confirm if you want to add them or not to your current party, but this part can come later on), and that the values in this list (or the database that is used by this list) is updated by player's choice (so an option to update or not).
I believe the mechanics is something similar to Devil Survivor 2 or something.
With a bit of fiddling, I found the game actors variable same with Ace.

$gameActors.actor(1).name()
$gameActors.actor(1)._level

So this one accesses the name and level for the first actor. I'm not sure how to access the class, though.
So I worked on this a bit. Now, I'm not sure how to have this script run after triggering an event (like speaking to an NPC). I also don't know how to work on making this selectable... any help would be appreciated. Thanks!


(function() {

var _Scene_Map_start = Scene_Map.prototype.start;
var _Actor_List = Window_Selectable.prototype.start; //addition
var _actor_Size = 40; //size of party

Scene_Map.prototype.start = function() {
_Scene_Map_start.call(this);
this._myWindow = new Compendium_Window(0, 0);
this.addWindow(this._myWindow);
};

function Compendium_Window() {
this.initialize.apply(this, arguments);
}

Compendium_Window.prototype = Object.create(Window_Selectable.prototype);
Compendium_Window.prototype.constructor = Compendium_Window;

Compendium_Window.prototype.initialize = function(x, y) {
Window_Base.prototype.initialize.call(this, x, y, this.windowWidth(), this.windowHeight()*_actor_Size);
this._index = 1;
this._cursorFixed = false;
this._cursorAll = false;
this._stayCount = 0;
this._helpWindow = null;
this._handlers = {};
this._touching = true;
this._scrollX = 0;
this._scrollY = 0;
this.deactivate();
for (n = 1; n < _actor_Size; n++){
this.drawText($gameActors.actor(n).name()+ "\t\t\t\t" +$gameActors.actor(n)._level, 0, this.windowHeight()*(n-1), this.windowWidth(), this.windowHeight());
}

};

Compendium_Window.prototype.windowWidth = function(){
return 816;
};
Compendium_Window.prototype.windowHeight = function(){
return this.fittingHeight(0);
};



})();
I took the liberty of trying this out. There are a few shortcuts, such as with the header text and cursor hack, that I could do better with more time, but it's after midnight here.

Is this more or less what you were thinking of? Bring up the window by using the plugin command "actorlist"

//=============================================================================

// actorlist.js
//=============================================================================

/*:
* @plugindesc Display a list of actors
* @author Geri Khan
*
* @param none
* @desc none
* @default false
*
* @help
*
* Plugin Command:
*
* actorlist - displays the actor list
*
*/

(function() {

var _Scene_Map_createallwindows = Scene_Map.prototype.createAllWindows;
var _Game_Message_isBusy = Game_Message.prototype.isBusy;
var _Actor_List = Window_Selectable.prototype.start; //addition
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;


// adds the 'actorlist' plugin command
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === 'actorlist') {
for (n = 1; n<=40; n++) {
$gameParty.addActor(n);
}
if (!$gameParty.inBattle()) {
SceneManager._scene._myWindow.refresh();
SceneManager._scene._myWindow.show();
SceneManager._scene._myWindow.open();
SceneManager._scene._myWindow.activate();
SceneManager._scene._myWindow.select(1);
};
}
};

// prevents various things happening while the new window is open,
// such as the player moving
Game_Message.prototype.isBusy = function() {
if (SceneManager._scene._myWindow.isOpen()) { return true; }
return _Game_Message_isBusy.call(this);
};

// create the compendium window while starting the map
Scene_Map.prototype.createAllWindows = function() {
_Scene_Map_createallwindows.call(this);
this._myWindow = new Compendium_Window(0, 0);
this.addWindow(this._myWindow);
this._myWindow.close();
};

// define the compendum window class
function Compendium_Window() {
this.initialize.apply(this, arguments);
}

Compendium_Window.prototype = Object.create(Window_Command.prototype);
Compendium_Window.prototype.constructor = Compendium_Window;

// set the width of the window
Compendium_Window.prototype.windowWidth = function() {
return 816;
};

// set the number of items in the list. Could use different values here,
// such as $gameParty.members() or $gameParty.battleMembers()
Compendium_Window.prototype.maxItems = function() {
return $gameActors._data.length;
};

// the number of visible rows in the window. Without this the height of the
// window could be too tall for the screen with large numbers of actors
Compendium_Window.prototype.numVisibleRows = function() {
return Math.min(10,this.maxItems());
};

// draw each line of the window. Its width is evenly divided into three
Compendium_Window.prototype.drawItem = function(index) {
if (index == 0) {
this.drawHeader();
return;
}
var actor = $gameActors.actor(index);
var rect = this.itemRectForText(index);
var segmentWidth = rect.width/3;
if (actor) {
this.drawActorClass(actor, rect.x, rect.y, segmentWidth);
this.drawActorName(actor, rect.x+segmentWidth, rect.y, segmentWidth);
this.drawActorLevel(actor, rect.x+(segmentWidth*2), rect.y, segmentWidth);
}
};

// refresh the window, including moving it into position
Compendium_Window.prototype.refresh = function() {
this.move(0,0,this.windowWidth(),this.fittingHeight(this.numVisibleRows()));
this.createContents();
this.drawAllItems();
};

// draw the header text for each column
Compendium_Window.prototype.drawHeader = function() {
var rect = this.itemRectForText(0);
var segmentWidth = rect.width/3;
this.drawText('Class', rect.x, rect.y, segmentWidth);
this.drawText('Name', rect.x+segmentWidth, rect.y, segmentWidth);
this.drawText('Level', rect.x+(segmentWidth*2), rect.y, segmentWidth);
};

// the header text is on line 0, which is selectable but shouldn't be.
// Modifying the cursor code means the cursor can't stop on it
Compendium_Window.prototype.cursorDown = function(wrap) {
Window_Selectable.prototype.cursorDown.call(this,wrap);
if (this.index() == 0) {
this.cursorDown(wrap);
}
};

Compendium_Window.prototype.cursorUp = function(wrap) {
Window_Selectable.prototype.cursorUp.call(this,wrap);
if (this.index() == 0) {
this.cursorUp(wrap);
}
};

})();
Yes, this is very close to what I want to accomplish, basically. I'll try including a sort function (so it sorts by class, by name, or by level). I'll also explore how to go with this opening and closing a window that shows the information about the selected actor if you press 'ok' or something.
I'll experiment with this one. The concern with this code is it doesn't allow you to quit the list. Thanks so much for the big, big help. :D
Just noticed that I left this testing code in, you should probably remove it

for (n = 1; n<=40; n++) {

$gameParty.addActor(n);
}


The cursor code could probably be changed too to make it less recursive.

   // Modifying the cursor code means the cursor can't stop on it

Compendium_Window.prototype.cursorDown = function(wrap) {
Window_Selectable.prototype.cursorDown.call(this,wrap);
if (this.index() == 0) {
Window_Selectable.prototype.cursorDown.call(this,wrap);
}

};



Compendium_Window.prototype.cursorUp = function(wrap) {
Window_Selectable.prototype.cursorUp.call(this,wrap);
if (this.index() == 0) {
Window_Selectable.prototype.cursorUp.call(this,wrap);
}
};
Thanks! I guess the next step would be to make a new window that opens and closes when you select an actor (and displays the stats and profile of the actor). Is the action of selecting the actor part of the script or would that be a scene (or a separate script)?
I don't have time to look into it today but have a look at how handlers are set and called. That determines what the window does when you press OK or Cancel.

You can probably put what happens next in the same script. I don't know what you're planning, but if it's to be a different scene maybe start by getting it opening Scene_Status for the character?


... also I made the Compendium_Window inherit Window_Command in the example above. In hindsight that should probably be Window_Selectable.
It's totally fine. I appreciate the help. I'll take the time over the next weekend to review the codes. For now I'm making maps and updating databases before I go back to work T_T
So I changed the Compenium_Window to Window_Selectable... now what happens is that it doesn't allow close and hangs when a user selects an item (which I assume is because there's nothing defined when an item is selected, which supposed to open up a window with the actor's information).

Here's what I have so far:

//=============================================================================
//
// compendium2.js
//
//=============================================================================



/*:
 * @plugindesc Display a list of actors
 * @author Geri Khan
 *
 * @param none
 * @desc none
 * @default false
 *
 * @help
 *
 * Plugin Command:
 *
 * actorlist - displays the actor list
 *
 */

(function() {
  var _Scene_Map_createallwindows = Scene_Map.prototype.createAllWindows;
  var _Game_Message_isBusy = Game_Message.prototype.isBusy;
  var _Actor_List = Window_Selectable.prototype.start; //addition
  var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  
  // adds the 'actorlist' plugin command
  Game_Interpreter.prototype.pluginCommand = function(command, args) {
    _Game_Interpreter_pluginCommand.call(this, command, args);
    if (command === 'actorlist') {
      /*for (n = 1; n<=335; n++) {
        $gameParty.addActor(n);
      }*/

      if (!$gameParty.inBattle()) {
        SceneManager._scene._myWindow.refresh();
        SceneManager._scene._myWindow.show();
        SceneManager._scene._myWindow.open();
        SceneManager._scene._myWindow.activate();
        SceneManager._scene._myWindow.select(1);
      };
    }
  };

  // prevents various things happening while the new window is open,
  // such as the player moving
  Game_Message.prototype.isBusy = function() {
    if (SceneManager._scene._myWindow.isOpen()) {
      return true;
    }
    return _Game_Message_isBusy.call(this);
  };

  // create the compendium window while starting the map
  Scene_Map.prototype.createAllWindows = function() {
    _Scene_Map_createallwindows.call(this);
    this._myWindow = new Compendium_Window(0, 0);
    this.addWindow(this._myWindow);
    this._myWindow.close();
  };

  // define the compendum window class
  function Compendium_Window() {
    this.initialize.apply(this, arguments);
  }
  
  //Compendium_Window.prototype = Object.create(Window_Command.prototype);
  Compendium_Window.prototype = Object.create(Window_Selectable.prototype);
  Compendium_Window.prototype.constructor = Compendium_Window;

  // set the width of the window
  Compendium_Window.prototype.windowWidth = function() {
     return 816;
  };

  // set the number of items in the list. Could use different values here,
  // such as $gameParty.members() or $gameParty.battleMembers()
  Compendium_Window.prototype.maxItems = function() {
    return $gameActors._data.length;
  };

  // the number of visible rows in the window. Without this the height of the
  // window could be too tall for the screen with large numbers of actors

  Compendium_Window.prototype.numVisibleRows = function() {
    return Math.min(10,this.maxItems());
  };

  // draw each line of the window. Its width is evenly divided into three
  Compendium_Window.prototype.drawItem = function(index) {
    if (index == 0) {
      this.drawHeader();
      return;
    }
    var actor = $gameActors.actor(index);
    var rect = this.itemRectForText(index);
    var segmentWidth = rect.width/3;
    if (actor) {
      this.drawActorClass(actor, rect.x, rect.y, segmentWidth);
      this.drawActorName(actor, rect.x+segmentWidth, rect.y, segmentWidth);
      this.drawActorLevel(actor, rect.x+(segmentWidth*2), rect.y, segmentWidth);
    }
  };

  // refresh the window, including moving it into position
  Compendium_Window.prototype.refresh = function() {
    this.move(0,0,this.windowWidth(),this.fittingHeight(this.numVisibleRows()));
    this.createContents();
    this.drawAllItems();
  };

  // draw the header text for each column
  Compendium_Window.prototype.drawHeader = function() {
    var rect = this.itemRectForText(0);
    var segmentWidth = rect.width/3;
    this.drawText('Class', rect.x, rect.y, segmentWidth);
    this.drawText('Name', rect.x+segmentWidth, rect.y, segmentWidth);
    this.drawText('Level', rect.x+(segmentWidth*2), rect.y, segmentWidth);
  };

  // the header text is on line 0, which is selectable but shouldn't be.
  // Modifying the cursor code means the cursor can't stop on it
  Compendium_Window.prototype.cursorDown = function(wrap) {
    Window_Selectable.prototype.cursorDown.call(this,wrap);
    if (this.index() == 0) {
      Window_Selectable.prototype.cursorDown.call(this,wrap);
    }
  };

  Compendium_Window.prototype.cursorUp = function(wrap) {
    Window_Selectable.prototype.cursorUp.call(this,wrap);
    if (this.index() == 0) {
      Window_Selectable.prototype.cursorUp.call(this,wrap);
    }
  };

  Compendium_Window.prototype.isOkEnabled = function() {
    return true;
  };
  Compendium_Window.prototype.isCancelEnabled = function() {
    return this.isHandled('cancel');
  };
  Compendium_Window.prototype.callCancelHandler = function() {
    this.callHandler('cancel');
  }

  Compendium_Window.prototype.processCancel = function() {
    SoundManager.playCancel();
    this.updateInputData();
    this.deactivate();
    this.callCancelHandler();
  };
  Compendium_Window.prototype.close = function() {
    if (!this.isClosed()) {
        this._closing = true;
    }
    this._opening = false;
  };
  Compendium_Window.prototype.isOkTriggered = function() {
    return Input.isRepeated('ok');
  };

  Compendium_Window.prototype.isCancelTriggered = function() {
    return Input.isRepeated('cancel');
  };

  Compendium_Window.prototype.processOk = function() {
      if (this.isCurrentItemEnabled()) {
          this.playOkSound();
          this.updateInputData();
          this.deactivate();
          this.callOkHandler();
      } else {
          this.playBuzzerSound();
      }
  };
})();
Yeah, it's hanging because you've not told it to do anything. Looking at these two functions...

Compendium_Window.prototype.processOk = function() {
      if (this.isCurrentItemEnabled()) {
          this.playOkSound();
          this.updateInputData();
          this.deactivate();
          this.callOkHandler();
      } else {
          this.playBuzzerSound();
      }
  };

  Compendium_Window.prototype.processCancel = function() {
    SoundManager.playCancel();
    this.updateInputData();
    this.deactivate();
    this.callCancelHandler();
  };

Both deactivate the window without doing anything. They do call the OK/Cancel handlers, but nothing happens because you haven't defined what they are.

Two ways you could go about this:

1) Put the commands to close the window and execute whatever needs to happen in the functions themselves.

Compendium_Window.prototype.processOk = function() {
      if (this.isCurrentItemEnabled()) {
          this.playOkSound();
          this.updateInputData();
          this.deactivate();
          //
          // I've added the next two lines to close the window and output
          // the index of the selected item to the console
          //
          this.close();
          console.log('OK triggered, index = '+this.index());
          this.callOkHandler();
      } else {
          this.playBuzzerSound();
      }
  };

  Compendium_Window.prototype.processCancel = function() {
    SoundManager.playCancel();
    this.updateInputData();
    this.deactivate();
    //
    // same here
    //
    this.close();
    console.log('Cancel triggered');
    this.callCancelHandler();
  };

If you do this, you will need to edit the isOkEnabled and isCancelEnabled functions to get them to work. Just have them always return true.

or 2) Create and bind the handler functions. The relevant parts would be

// set the handlers in the initialise function
  Compendium_Window.prototype.initialize = function(x, y, width, height) {
    Window_Selectable.prototype.initialize.call(this, x, y, width, height);
    this.setHandler('ok',     this.onOk.bind(this));
    this.setHandler('cancel', this.onCancel.bind(this));
  };

  // create the function to run when the OK handler is called
  Compendium_Window.prototype.onOk = function() {
    this.close();
    console.log('OK triggered, index = '+this.index());
  };

  // create the function to run when the Cancel handler is called
  Compendium_Window.prototype.onCancel = function() {
    this.close();
    console.log('Cancel triggered');
  };

Obviously substitute those console.logs for what you actually want to happen. Now when processOk and ProcessCancel use callOkHandler and callCancelHandler, it'll run those bound functions.

The former way is probably simpler, the latter way is probably tidier.
Thanks! I'll check this out in the weekend. Am I right to assume that the new window that I'll be making (this opens when an actor is selected) can be worked in the same code, right? I'll just have to work on making a Window_Base for that, with its own handlers?
Heads up, just discovered that code I gave you will crash in battle.

Quick fix:

// prevents various things happening while the new window is open,
  // such as the player moving
  Game_Message.prototype.isBusy = function() {
    if (SceneManager._scene._myWindow && SceneManager._scene._myWindow.isOpen()) {
      return true;
    }
    return _Game_Message_isBusy.call(this);
  };
Ah, thanks for this. I haven't tested battling yet, so I haven't encountered such a scenario

At any case, I tried to change the code a bit from all actors to all members of the party. I simply changed $gameActors to $gameParty, and it crashed. XD
I'm working on a similar implementation on this one, although this one would call on several windows. I'm stuck on the first phase, which is trying to get the player to select the first ingredient to fuse.
I do not know how to add a 'help' window on the top that prompts the user to select the first party member, nor go to a second window where the 'help' window would display the party member selected from the first window.

Here's the code that I have...

/*:
 * @plugindesc Display a list of actors for fusion
 *
 * @param none
 * @desc none
 * @default false
 *
 * @help
 *
 * Plugin Command:
 *
 * fusion - initiates the fusion thinggy
 *
 */


 //--------------------------------------------------------------------
 //
 // Global Variables
 //
 // Fusion result array and selected demons
 // 
 //--------------------------------------------------------------------

var resultArray = [32];
	// 2 - Avatar
	resultArray[0] = [0,20,29,23,0,25,23,0,16,7,7,23,0,0,20,23,0,6,25,31,23,20,16,6,2,20,33,24,0,6,6,0,7];
	// 3 - Avian
	resultArray[1] = [20,0,13,23,25,29,16,0,0,27,29,5,0,0,23,25,0,25,24,0,23,24,0,6,3,13,25,23,0,0,23,0,27];
	// 4 - Beast
	resultArray[2] = [29,13,9,13,2,20,29,4,20,7,27,15,27,33,2,11,33,0,2,3,34,20,29,0,4,11,33,5,27,15,20,22,12];
	// 5 - Brute
	resultArray[3] = [23,23,13,9,23,34,27,5,16,27,0,4,18,33,0,7,15,0,3,23,0,0,0,0,5,23,16,0,18,18,0,11,13];
	// 6 - Deity
	resultArray[4] = [0,25,2,23,0,25,0,6,25,27,16,24,0,8,0,25,0,10,25,12,5,16,0,0,6,31,30,23,0,0,23,3,25];
	// 7 - Divine
	resultArray[5] = [25,29,20,34,25,9,25,7,25,0,31,4,31,11,0,25,22,25,0,0,27,0,0,0,7,29,15,11,31,12,20,12,29];
	// 8 - Dragon
	resultArray[6] = [23,16,29,27,0,25,0,0,24,29,29,27,0,29,0,20,0,20,30,29,23,16,28,0,8,13,0,24,0,29,24,3,2];
	// 9 - Element
	resultArray[7] = [0,0,4,5,6,7,0,26,0,11,12,13,0,15,16,0,18,0,20,0,22,23,24,25,9,27,0,29,30,31,0,33,34];
	// 10 - Entity
	resultArray[8] = [16,0,20,16,25,25,24,0,0,25,23,24,0,5,24,16,0,6,23,27,16,16,16,6,10,5,31,16,0,0,16,5,25];
	// 11 - Fairy
	resultArray[9] = [7,27,7,27,27,0,29,11,25,9,34,18,27,18,5,0,27,20,25,18,34,5,34,12,11,29,18,34,28,27,0,34,20];
	// 12 - Fallen
	resultArray[10] = [7,29,27,22,16,31,29,12,23,34,9,33,16,31,31,0,27,24,4,31,5,27,16,7,12,18,15,4,16,5,24,27,22];
	// 13 - Femme
	resultArray[11] = [23,5,15,0,24,4,27,13,24,18,33,9,24,33,24,27,15,0,24,0,33,24,23,11,13,22,15,23,24,5,8,12,5];
	// 14 - Fiend
	resultArray[12] = [0,0,27,4,0,31,0,0,0,27,16,24,0,0,6,34,0,10,21,0,33,0,8,0,14,24,0,5,0,0,0,0,27];
	// 15 - Foul
	resultArray[13] = [0,0,33,18,8,11,29,15,5,18,31,33,0,0,0,0,0,12,0,18,13,0,31,0,15,5,31,12,18,18,0,4,29];
	// 16 - Fury
	resultArray[14] = [20,23,2,24,0,6,0,16,24,5,31,24,6,0,0,24,0,31,23,23,13,24,31,6,16,24,30,23,6,30,6,0,20];
	// 17 - Genma
	resultArray[15] = [23,25,11,0,25,25,20,0,16,0,0,27,34,0,24,0,0,25,34,16,24,25,13,7,17,20,24,13,34,34,20,34,0];
	// 18 - Haunt
	resultArray[16] = [0,0,33,7,0,22,0,18,0,27,27,15,0,0,0,0,0,0,0,33,31,0,31,0,18,34,0,0,15,15,0,22,22];
	// 19 - Herald
	resultArray[17] = [6,25,0,15,10,25,20,0,6,20,24,0,10,12,31,25,0,9,7,12,0,7,6,6,19,12,0,8,12,7,23,0,25];
	// 20 - Holy
	resultArray[18] = [25,24,2,3,25,11,30,20,23,25,4,24,21,0,23,34,0,7,9,5,4,24,2,7,20,11,33,23,0,0,23,0,7];
	// 21 - Jaki
	resultArray[19] = [31,0,3,23,12,0,29,0,27,18,31,0,0,18,23,16,33,12,5,0,33,4,13,0,21,15,4,0,12,0,17,0,32];
	// 22 - Jirae
	resultArray[20] = [23,23,34,11,5,27,23,22,16,34,5,33,33,13,13,24,31,0,4,33,9,29,4,24,22,15,15,12,33,18,23,21,4];
	// 23 - Kishin
	resultArray[21] = [20,24,20,29,16,31,16,23,16,5,27,24,0,0,24,25,0,7,24,4,29,0,16,24,23,13,30,13,0,0,16,0,13];
	// 24 - Lady
	resultArray[22] = [16,0,29,16,0,25,28,24,16,34,16,23,8,31,31,13,31,6,2,13,4,16,0,0,24,23,23,13,0,0,23,18,27];
	// 25 - Megami
	resultArray[23] = [6,6,0,13,0,20,0,25,6,12,7,11,0,0,6,7,0,6,7,0,24,24,16,0,25,12,30,11,0,16,6,31,23];
	// 26 - Mitama
	resultArray[24] = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,27,28,29,30,31,32,33,34];
	// 27 - Night
	resultArray[25] = [20,13,11,0,31,29,13,27,5,29,18,22,24,5,24,20,34,12,11,15,15,13,23,12,27,9,31,0,24,24,0,4,7];
	// 28 - Raptor
	resultArray[26] = [33,25,33,23,30,15,0,0,31,18,15,15,0,31,30,24,0,0,33,4,15,30,23,30,28,31,0,15,16,16,0,31,18];
	// 29 - Snake
	resultArray[27] = [24,23,5,4,23,11,24,29,16,34,4,23,5,12,23,13,0,8,23,0,12,13,13,11,29,0,15,9,5,28,23,0,27];
	// 30 - Tyrant
	resultArray[28] = [0,0,27,0,0,31,0,30,0,28,16,24,0,18,6,34,15,12,0,12,33,0,0,0,30,24,16,5,0,16,0,27,27];
	// 31 - Vile
	resultArray[29] = [6,0,15,18,0,12,29,31,0,27,5,5,0,18,30,34,15,7,0,0,18,0,0,16,31,24,16,28,16,0,23,15,22];
	// 32 - Wargod
	resultArray[30] = [6,23,20,18,23,20,24,0,16,0,24,8,0,0,6,20,0,23,23,17,23,16,23,6,32,0,0,23,0,23,0,0,0];
	// 33 - Wilder
	resultArray[31] = [0,0,22,0,3,12,3,33,5,34,27,12,0,4,0,34,22,0,0,0,21,0,18,31,33,4,31,0,0,15,0,9,4];
	// 34 - Yoma
	resultArray[32] = [7,27,12,13,25,29,2,34,25,20,22,5,27,29,20,0,22,25,7,32,4,13,27,23,34,7,18,27,27,22,0,4,9];

var firstDemonClass = 2;
var secondDemonClass = 8;


 //--------------------------------------------------------------------
 //
 // Select the 1st party member
 //
 // This must show all part members and determine whether they are fusable 
 // or not based on their classes.
 // 
 //--------------------------------------------------------------------


(function() {
	var _Scene_Map_createallwindows = Scene_Map.prototype.createAllWindows;
	var _Game_Message_isBusy = Game_Message.prototype.isBusy;
	var _Actor_List = Window_Selectable.prototype.start; //addition
	var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;

	// adds the 'actorlist' plugin command
	Game_Interpreter.prototype.pluginCommand = function(command, args) {
		_Game_Interpreter_pluginCommand.call(this, command, args);
		if (command === 'fusion') {
			console.log(firstDemonClass);
			console.log(secondDemonClass);
			//console.log(resultArray[firstDemonClass - 2][secondDemonClass - 2]);
			console.log('First Demon Class is ' + $dataClasses[firstDemonClass].name);
			console.log('Second Demon Class is ' + $dataClasses[secondDemonClass].name);
			console.log('Resulting Demon Class is ' + $dataClasses[resultArray[firstDemonClass - 2][secondDemonClass - 2]].name);
			if (!$gameParty.inBattle()) {
				SceneManager._scene._myWindow.refresh();
				SceneManager._scene._myWindow.show();
				SceneManager._scene._myWindow.open();
				SceneManager._scene._myWindow.activate();
				SceneManager._scene._myWindow.select(1);
				SceneManager._scene._myWindow.setHelpWindow(this._helpWindow);
			};
		}
	};


	Game_Message.prototype.isBusy = function() {
		if (SceneManager._scene._myWindow && SceneManager._scene._myWindow.isOpen()) {
			return true;
		}
		return _Game_Message_isBusy.call(this);
	};

	// create the compendium window while starting the map
	Scene_Map.prototype.createAllWindows = function() {
		_Scene_Map_createallwindows.call(this);
		this._myWindow = new Fusion1_Window(0, 0);
		this.addWindow(this._myWindow);
		this._myWindow.close();
	};

	// define the compendum window class
	function Fusion1_Window() {
		this.initialize.apply(this, arguments);
	}

	//Fusion1_Window.prototype = Object.create(Window_Command.prototype);
	Fusion1_Window.prototype = Object.create(Window_Selectable.prototype);
	Fusion1_Window.prototype.constructor = Fusion1_Window;
	
	// set the width of the window
	Fusion1_Window.prototype.windowWidth = function() {
		return 816;
	};


	Fusion1_Window.prototype.standardFontSize = function() {
	    return 18;
	};
	// set the number of items in the list. Could use different values here,
	// such as $gameParty.members() or $gameParty.battleMembers()
	Fusion1_Window.prototype.maxItems = function() {
		return $gameParty.size();
	//return Game_Party.size();

	};

	// the number of visible rows in the window. Without this the height of the
	// window could be too tall for the screen with large numbers of actors
	Fusion1_Window.prototype.numVisibleRows = function() {
		return Math.min(10,this.maxItems());
	};

	// draw each line of the window. Its width is evenly divided into three
	Fusion1_Window.prototype.drawItem = function(index) {
		if (index == 0) {
			this.drawHeader();
		return;
		}
		//var actor = $gameActors.actor(index);
		var actor = $gameParty.members()[index];
		console.log('actor: ' + actor.name);
		var rect = this.itemRectForText(index);
		//var segmentWidth = rect.width/3;
		var segmentWidth1 = rect.width/2;
		//partition of the selection part
		var segmentWidth2 = segmentWidth1/10;
		var segmentWidth3 = segmentWidth1/10;
		var actorClass = $gameParty.members()[index]._classId;
		if (actor) {
			this.drawText(index, rect.x, rect.y, segmentWidth2);
			this.drawActorClass(actor, rect.x+segmentWidth2, rect.y, segmentWidth2*4);
			this.drawActorName(actor, rect.x+(segmentWidth2*4), rect.y, segmentWidth2*4);
			this.drawActorLevel(actor, rect.x+(segmentWidth2*8), rect.y, segmentWidth2*8);

			//This part shows whether they're fuseable or not
			//refers to the resultsArray above
			for (i = 0; i < this.maxItems()-1; i++){
				//check case if not equal or not zero, then possible for fusion. Otherwise, not possible
				console.log('=-=-=-=-');
				
				console.log('actor Class: ' + actorClass);
				console.log('i: ' + i);
				console.log('Game Party Member for this line: '+ $gameParty.members()[i+1]._name);

				//Checks wether they are the same party member.
				if ( $gameParty.members()[i+1]._actorId == $gameParty.members()[index]._actorId){
					this.drawText( '-', rect.x+segmentWidth1+(segmentWidth3*i), rect.y, segmentWidth3);
				}
				//If element
				else if ( resultArray[actorClass - 2][ $gameParty.members()[i+1]._classId - 2] == 9 ){
					this.drawText( 'E', rect.x+segmentWidth1+(segmentWidth3*i), rect.y, segmentWidth3);
				}
				//If not same party member, process the results
				else{
					if( resultArray[actorClass - 2][ $gameParty.members()[i+1]._classId - 2] != 0 ){
						this.drawText( 'O', rect.x+segmentWidth1+(segmentWidth3*i), rect.y, segmentWidth3);
					}
					
					else{
						this.drawText( 'X', rect.x+segmentWidth1+(segmentWidth3*i), rect.y, segmentWidth3);	
					}
				}
			}
		}
	};

	// refresh the window, including moving it into position
	Fusion1_Window.prototype.refresh = function() {
		this.move(0,60,this.windowWidth(),this.fittingHeight(this.numVisibleRows()));
		this.createContents();
		this.drawAllItems();
	};

	//No need to display the term 'lvl'
	Fusion1_Window.prototype.drawActorLevel = function(actor, x, y) {
	    this.drawText(actor.level, x, y, 36, 'left');
	};

	// draw the header text for each column
	Fusion1_Window.prototype.drawHeader = function() {
		var rect = this.itemRectForText(0);
		//divide between the selection and the result
		var segmentWidth1 = rect.width/2;
		//partition of the selection part
		var segmentWidth2 = segmentWidth1/10;
		var segmentWidth3 = segmentWidth1/10;
		this.changeTextColor(this.systemColor());
		this.drawText('#', rect.x, rect.y, segmentWidth2);
		this.drawText('Class', rect.x+segmentWidth2, rect.y, segmentWidth2*4);
		this.drawText('Name', rect.x+(segmentWidth2*4), rect.y, segmentWidth2*4);
		this.drawText('LV', rect.x+(segmentWidth2*8), rect.y, segmentWidth2*8);
		for (i = 0; i < this.maxItems()-1; i++){
			this.drawText( (i+1), rect.x+segmentWidth1+(segmentWidth3*i), rect.y, segmentWidth3);
		}
		this.resetTextColor();
	};

	// the header text is on line 0, which is selectable but shouldn't be.
	// Modifying the cursor code means the cursor can't stop on it
	Fusion1_Window.prototype.cursorDown = function(wrap) {
		Window_Selectable.prototype.cursorDown.call(this,wrap);
		if (this.index() == 0) {
			Window_Selectable.prototype.cursorDown.call(this,wrap);
		}
	};

	Fusion1_Window.prototype.cursorUp = function(wrap) {
		Window_Selectable.prototype.cursorUp.call(this,wrap);
		if (this.index() == 0) {
			Window_Selectable.prototype.cursorUp.call(this,wrap);
		}
	};

	Fusion1_Window.prototype.isOkEnabled = function() {
		return true;
	};
	Fusion1_Window.prototype.isCancelEnabled = function() {
		return this.isHandled('cancel');
	};
	Fusion1_Window.prototype.callCancelHandler = function() {
	//this.callHandler('cancel');
		Fusion1_Window.close();
	}

	Fusion1_Window.prototype.processCancel = function() {
		SoundManager.playCancel();
		this.updateInputData();
		this.deactivate();
		//
		// same here
		//
		this.close();
		console.log('Cancel triggered');
		this.callCancelHandler();
	};

	Fusion1_Window.prototype.close = function() {
		if (!this.isClosed()) {
			this._closing = true;
		}
		this._opening = false;
		};
		Fusion1_Window.prototype.isOkTriggered = function() {
		return Input.isRepeated('ok');
	};

	Fusion1_Window.prototype.isCancelTriggered = function() {
		return Input.isRepeated('cancel');
	};

	Fusion1_Window.prototype.processOk = function() {
		if (this.isCurrentItemEnabled()) {
			this.playOkSound();
			this.updateInputData();
			this.deactivate();
			this.callOkHandler();

		}
		else {
			this.playBuzzerSound();
		}
	};



})();




 //--------------------------------------------------------------------
 //
 // Select the 2nd Demon
 //
 // The selected demon from the first screen must be shown on this
 // screen, along with the result of the fusion
 // Nothing here so far.
 //--------------------------------------------------------------------
Pages: 1