MV Is it possible to create a Window_Selectable with separate drawText?

I want to have my description above a yes or no answer. I've been using Eli's excellent Choice Manager plugin for in game stuff, but now that I'm creating a totally a menu scene for a custom feature in the game I'm working on, I'm wondering if it's possible to do this through JS or not?

Perhaps even if the first selection was index 2 instead of 0, and if it exceeded 3, return to 2, goes below 2, returns to 3, if that makes sense?

[edit]
Also trying to open a sub window, which I got working. When closing the window though, it keeps closing the main window on the same frame. Is there an obvious and easy way to close the sub window without this happening?
Yes, it's absolutely possible to add some new text to a window even if it's a selectable. Can you maybe make a draft with paint so I can imagine better how it should look like?

Perhaps even if the first selection was index 2 instead of 0, and if it exceeded 3, return to 2, goes below 2, returns to 3, if that makes sense?
Nope, that doesn't sound right. I think the correct way will be something else.
Hmmm, below is an example for base game where I made show choices window show line of text ('TEST') and then the choices below that. So I added itemHeight to the heights and itemRect (edit: itemRect y) and then made it draw the base text in drawAllItems. Hope I'm not forgetting anything.

For your question in the edit, are you sure you remembered to deactivate the "parent window"? Else it'll keep reading your inputs I think.


Window_ChoiceList.prototype.windowHeight = function() {
return this.fittingHeight(this.numVisibleRows()) + this.itemHeight();
};

Window_ChoiceList.prototype.contentsHeight = function() {
return this.maxItems() * this.itemHeight() + this.itemHeight();
};

Window_ChoiceList.prototype.itemRect = function(index) {
var rect = new Rectangle();
var maxCols = this.maxCols();
rect.width = this.itemWidth();
rect.height = this.itemHeight();
rect.x = index % maxCols * (rect.width + this.spacing()) - this._scrollX;
rect.y = Math.floor(index / maxCols) * rect.height - this._scrollY + this.itemHeight();
return rect;
};

Window_ChoiceList.prototype.drawAllItems = function() {
this.drawText('TEST', 0, 0, this.itemWidth(), 'center');
var topIndex = this.topIndex();
for (var i = 0; i < this.maxPageItems(); i++) {
var index = topIndex + i;
if (index < this.maxItems()) {
this.drawItem(index);
}
}
};
This is probably poorly explained on my part, it sounds like this is for the map scene. I'm creating a custom menu scene, like say, an equipment menu. Really, it's a pseudo crafting system, but not really a full crafting menu because I only want it to be able to edit very specific items and nothing else.

The menu works, I can scroll, information updates correctly, but when selecting an item, I want to convert it between an attack and defense item, so a choice box opens up asking "Atk > Def" or "Def > Atk", you make a selection and it will pay x gold, swap, and update. Currently, I'm drawing 2 windows, 1 with a descript and price, and the other with the options. I'm wondering if the options can be merged into that description window somehow.

I'm currently using Window_Selectable, is this the incorrect way to do this? Should I be using Window_ChoiceList instead?
That was just an example, as Window_ChoiceList inherits from Window_Command and Window_Selectable. So if you're making your custom windows, can't you do similar stuff? But maybe Aerosys will give you the full code.
I'm starting to make some progress here. Before I was trying to figure it out the only way I knew how with delays and stuff and I was like there has to be a better way.

Code:
Scene_CustomMenu.prototype.onSelectItem = function () {
    subMenu = true;
    this._convertExplanationWindow.show();
    this._convertSelectionWindow.show();
}

I added this to create:
Code:
    this._selectionWindow.setHandler("ok", this.onSelectItem.bind(this));
    this._selectionWindow.setHandler("cancel", this.onSelectItemCancel.bind(this));

This cancel just has a scene pop function in it, when pressing "ok", it opens the other menu but immediately freezes the scene. Any idea why update stopped running?

[edit]
Also, if I just want to create the choice list and have those two options, how do I do that? Like how do you format it:
Description
Cost
Choice1
Choice2
Let's assume that all options are visible without the need of scrolling, because scrolling would make it much more difficult.

There's a function called Window_Selectable.prototype.itemRect that you can modify for your window to move all options downwards by Y pixels, e.g.

Code:
Custom_Window.prototype.itemRect = function(index) {
  const rect = Window_Selectable.prototype.itemRect.call(this, index);
  rect.y += 100;
  return rect;
}
Or you write any custom function you need for your window.

Then you can draw any additional text like this:

Code:
Custom_Window.prototype.drawAllItems = function() {
  Window_Selectable.prototype.drawAllItems();

  this.drawText("whatever", 0, 0, this.contentsWidth());
}
Let's assume that all options are visible without the need of scrolling, because scrolling would make it much more difficult.

There's a function called Window_Selectable.prototype.itemRect that you can modify for your window to move all options downwards by Y pixels, e.g.

Code:
Custom_Window.prototype.itemRect = function(index) {
  const rect = Window_Selectable.prototype.itemRect.call(this, index);
  rect.y += 100;
  return rect;
}
Or you write any custom function you need for your window.

Then you can draw any additional text like this:

Code:
Custom_Window.prototype.drawAllItems = function() {
  Window_Selectable.prototype.drawAllItems();

  this.drawText("whatever", 0, 0, this.contentsWidth());
}
I got it to draw the text in one window, and move the selector, but I can't get it to draw the list of selectable items now, and it also freezes the entire game with the input handler.

Am I using this correctly?:
Code:
Window_Orbcraft_Conversion.prototype.drawItem = function (index) {
    this._list = ["Attack > Defence", "Defence < Attack"];
    var options = this._list[index];
    var rect = this.itemRectForText(index);
    this.drawText(options, rect.x, rect.y, rect.width);
};

[edit]
Okay, I figured out that .activate() is required when calling the handler, otherwise update will freeze.
Might be easier to inherit from Window_Command instead of Window_Selectable. Then you can do this instead:

Code:
Window_Orbcraft_Conversion.prototype.makeCommandList = function() {
  this.addCommand("Attack > Defense", "atkDef");
  this.addCommand("Defense > Attack", "defAtk");
}

Then you can remove your Window_Orbcraft_Conversion.prototype.drawItem override.
Then you can remove your Window_Orbcraft_Conversion.prototype.drawItem override.
Yeah, I haven't played with Window_Command yet, but this might be the way. I did manage to get selectable to display correctly now, but it's such a hassle and I didn't realize what the difference was between the two. I'm going to dig into that a bit more. It looks like with selectable in order to "select" options I'll have to check the index of select(), whereas it looks like command just binds right to the function I want instead.
This is horrific man. There's so little documentation or tutorials on this stuff and Window_Selectable, Window_Command, Window_ChoiceList, etc, are all controlled so drastically differently.

I just drew this out in Window_Selectable and had it working, but I erased everything to change it to Window_Command and now the I can't set X and Y positions of the window itself (what the actual f?), I can only either draw the text, or draw the commands, but not both? Deactivating the command window crashes the entire game?

How do you do this? I'm losing my sanity here, it shouldn't have to be this difficult.

[edit]
I gave up and returned to Window_Selectable. Everything works as intended and I just created a function that's a switch based on the window.select() indices to run the commands I want. This may not be the best way, but it works.
Well it's a bit unfortunate that they didn't make some tutorials (besides this one https://developer.rpgmakerweb.com/rpg-maker-mz/) but to answer your question...

How do you do this? I'm losing my sanity here, it shouldn't have to be this difficult.
The code itself is the documentation. And, furthermore, programming is difficult. Sure, learning the language itself is easy as the mass of "learn JavaScript in 60 minutes" tutorials out there demonstrate, but learn how to work with an already existing framework is not.

For those who are interested:
Spoiler: Why Selectable, Command, & ChoiceList?
This is not uncommon for software products, it's actually the reality.

Selectable is a superclass for every window where the player "selects" something from a list, e.g. Items or Skills.
Technically, it makes a difference whether you select an Item from a list, or a command such as "New Game" from the title screen, this is why we also have Window_Command. But because Window_Command inherits from Window_Selectable anyway it could sometimes a bit tricky to decide which window class to pick.
ChoiceList is only used for the Message Choices and, from my experience, is too situationally to be reused in other plugins.

What also helps is to look at already existing windows that look similar to yours like Window_TitleCommand
The code itself is the documentation. And, furthermore, programming is difficult. Sure, learning the language itself is easy as the mass of "learn JavaScript in 60 minutes" tutorials out there demonstrate, but learn how to work with an already existing framework is not.
I don't really agree with this. It's great that there is documentation for MZ, but it still isn't very good. I came to RPG Maker because I was feeling nostalgic and decided on MV because it already had a large amount of available plugins, both free and paid. Yes, learning how to program can be frustrating but comparing RM to Unity, if I want to do something in Unity, I can just look it up:
All properties, functions, parameters, etc, are all here. Is it going to be challenging? Sure, but it's significantly 1000% less challenging and frustrating than having to open up rpg_windows.js and sift through 6000 lines of someone else's code to try and make sense of how these objects work.

This isn't a case of "this is just how it is," I would consider RPG Maker to be up there with the top dogs in terms of availability and popularity. Godot, Unity, and UE all have clear documentation where RM does not.

What also helps is to look at already existing windows that look similar to yours like Window_TitleCommand
It doesn't though, because in some cases they'll be using an alias, or using some functions but not all. The closest usable resource I've found is https://github.com/rpgtkoolmv/corescript

As well as: https://kinoar.github.io/rmmv-doc-web/

These two resources as far as I'm aware are the only grip the community has on any form of documentation that shows properties, hierarchy, functions, etc.

I don't want this to be misconstrued, because I do appreciate the help. You did try to guide me in a direction that may work, but I gave up on Window_Command because:
Width and Height broke immediately. Why? Oh, because despite defining it, it has it's own functions for width and height:
Code:
Window_Command.prototype.initialize = function(x, y) {
    this.clearCommandList();
    this.makeCommandList();
    var width = this.windowWidth();
    var height = this.windowHeight();
    Window_Selectable.prototype.initialize.call(this, x, y, width, height);
    this.refresh();
    this.select(0);
    this.activate();
};
This is fine, I can change initialize, but it was easier for me to just use .windowWidth() and .windowHeight(), why wouldn't I? They're alread there.

The one I still don't understand is, it doesn't have it's own x or y, but kept setting x and y to 0 and despite everything I tried it just wouldn't stop doing this. Window_TitleCommand has an updatePlacement function, but I don't see anything like that in Window_Command, although I guess I could just make one.

It was so frustrating because I was so close to completing the plugin, and where I see the benefits of Window_Command it's like starting right from scratch even though it's an inherited object.
I lost interest in trying to find out why it doesn't work and just decided to use Window_Selectable, grab the indices for the Select() method and create switch cases for 0, 1, 2, etc, whatever I want my menu to input and built my own handler. I would like to learn how to use Window_Command eventually, but the menu is already completed and everything works exactly as intended.
I wasn't aware that you are using MV. The constructors for windows are a bit inconsistent in MV, luckily they improved that a lot in MZ. Anyway, let's go!

This is fine, I can change initialize, but it was easier for me to just use .windowWidth() and .windowHeight(), why wouldn't I? They're alread there.
Exactly, you want to use windowWidth (and maybe windowHeight), like this:

Code:
Custom_Window.prototype.windowWidth = function() {
  return 200;
}

Then you don't need a custom constructor for your window class, and I also recommend not having one, because the constructor of Window_Command is already robust.

You can also use that code snippet for the height, but by default, the Window_Command class does that automatically for you to fit it to the number of commands in the list (which is a bonus over the Window_Selectable).

The one I still don't understand is, it doesn't have it's own x or y, but kept setting x and y to 0 and despite everything I tried it just wouldn't stop doing this. Window_TitleCommand has an updatePlacement function, but I don't see anything like that in Window_Command, although I guess I could just make one.
I agree, this looks a bit awkward and is probably a reason why they changed it in MZ. It's perhaps the easiest to reposition the window not in the window class itself, but in the scene where you create it and add it to the screen.

Code:
...
const gameWindow = new Custom_Window(0, 0);
gameWindow.x = Graphics.boxWidth / 2 - gameWindow.width / 2;
gameWindow.y = Graphics.boxHeight / 2 - gameWindow.height / 2;
...

I could continue and dive deeper but when your plugin is already working using the Window_Selectable class then it's just fine 🙂 Personally, I think using Window_Command is best practice, but using Window_Selectable is not a bad practice either.

Original thread: https://forums.rpgmakerweb.com/threads/is-it-possible-to-create-a-window_selectable-with-separate-drawtext.180973/