Highly customizable sorting plugin

Introduction:
Searching the forum and also google for sorting plugins surely brings up a bunch of results and those I had a look at definitely fulfilled the needs of multiple users, just not mine.

So what are my needs, and why have I written another sorting plugin?

I haven't played many RPGs, but most of them I have played offered at least two different pre-defined sort orders for the items.

So I had 2 different goals while developing this plugin:
- Offer multiple sort options to the player
- Offer customizability to the programmer(s) who will use this plugin
They should be able to decide which sort options are available in there game.

Credits and Use:
It's completely open to non-commercial and commercial projects and does not require any credits.

Features:
The plugin itself is very complex, because it has high customizability. So let's go over the plugin parameters:
Plugin Parameters.PNG

As you can see, it defines 5 structs for 5 different things that can be sorted by the plugin and a bunch of texts which are for a
new option in the "Options" menu which I explain later.
The plugin defines sorting options for Items, Weapons, Armor, Skills and Goods seperately.
The Goods option let's you define sort orders for the shop buy window, in case you wonder.

Now let's have a look at one of the structs:
It has a bunch of sub structs for pre-defined sorting options, each of them consisting of a "Name" you can customize and
a flag where you can set whether you want to use them in your game.
Particular Sort Option.PNG
Changes to the parameters which I have marked yellow won't affect your game once you have already started it with plugin installed before. Why this is the case I'll also explain later.

Now let's have a look at the custom option:
It is a list of sub structures, each consisting of the same two parameters 'Name' and 'Use' and a third one where you can define your custom javascript sort value calculation function:
Custom Methods.PNG

All these parameters will be converted into arrays by the plugin. The parameter 'Default Sort Method' is the index in this array.
So for Items this particularly means:
0: Unsorted (Database Order)
1: Lexicographically
2: By Price
3: By amount in possession
4: Custom option 1
5: Custom option 2
...
The option which is marked as 'Default' must always have the 'Use' flag set to 'true', otherwise the plugin will throw an error.

The parameter 'Descending' should be self explanatory.

The plugin parameters for the equipment have another sub option called parameters.
Here you can define the stats for which sorting options should be defined.
In the given example, they will be defined for:
1 - MaxMP
2 - Attack
4 - Magic Attack
6 - Agility and
7 - Luck
EquipmentOptions.PNG
Please define only valid numbers here, the plugin doesn't handle invalid numbers not very well
and please plan those beforehand. Adding or removing parameters after you have started you game once with the
plugin installed might mess with already defined sorting orders saved with the game.

What does this plugin lack:
- Ability to let the player swap items in the sort order (something many RPGs actually offer).
I found a plugin in the request section of this forum that actually implements such a functionality, but unfortunately
it won't be compatible with my plugin unless the player always uses the default sorting order. My sorting options will
definitely overwrite any sorting done by the player manually, so I won't implement such a feature into this plugin.

How does the plugin affect the game:
The first thing the plugin does is loading the values of the plugin parameters 'Default Sort Order' and 'Descending' of each individual struct into the ConfigManager, which means they will be saved globally with your game in the config.rpgsave file.
Unless you delete that file, the defaults from the plugin parameters will be overwritten with the saved configuration the next
time you start your game, thus any changes to those two plugin parameters won't have any effect.

The plugin adds a new option 'Sorting Rules' to your games option menu.
Game Options.PNG

If you are using YEP_OptionsCore this option won't appear. You have to add it seperately to the plugin parameters of Yanfly's plugin. The important parameter values are as follows:

Help Description:
Change default sorting rules for items, weapons,
armor, skills and shop goods.

Show/Hide:
show = Imported.BO_SortingOptions;

Symbol:
SortingRules

Draw Option Code:
Code:
var rect = this.itemRectForText(index);
var text = this.commandName(index);
this.resetTextColor();
this.changePaintOpacity(this.isCommandEnabled(index));
this.drawText(text, rect.x, rect.y, rect.width, 'left');

Process OK Code:
Code:
Yanfly.Options.Window_Options_processOk.call(this);

Set every parameter below the Process OK Code parameter to blank strings.
You also have to install YEP_OptionsCore below my plugin to make it work.

The new option will pop up a new scene, where you can change the sorting options and orders of the different types
by pressing the left and right keys:
Sorting Options Scene.PNG

If the menu is opened from the title screen any changes will be saved into the Config Manager and will automatically
taken over to the save files created by the 'New Game' option.

If the menu is opened from within the game any changes will be saved into a new object which is saved with your save file.
So there is a global option and individual options per save file.

Example:
Let's sort Armor descending by 'Magic Attack':
Sort Example.PNG
You can see, that equipment is sorted differently depending on whether you are in the item scene or in the equip scene.
In the item scene the equipment items are sorted by their raw stats (Power Ring offering 25, Ring 10 and Lost Ring only 5 Magic Attack)
In the equip scene they are sorted by the actual effect on the actor (Lost Ring has set a 400% Magic Attack trait, so it comes first).

Each time one of the windows that can be sorted with this plugin is opened it is sorted by the rules defined in the options,
e.g.

Sort Options Items.PNG

my Item Window is always sorted ascending by name when it is opened.
I can change the sort order by pression 'O' and the sort method by pressing 'S'.
These changes are not saved, when the window is closed or switched to 'Weapon'/'Armor'/'Key Item' mode.
The next time it is opened it is again sorted by the default sorting rule applied in the options.

The little info window which displayes the keys used for sorting will only show up as long as it's parent window
is active. Depending on the size of it's parent window it will either by vertical or horizontal:

Sort Options Shop.PNG

Compatibility:
- Should be compatible with any plugin, that does not sorting on it's own.
- Should be compatible with any plugin, that does not overwrite the function makeItemList of the following windows
Window_ItemList, Window_SkillList, Window_ShopBuy without calling an alias.
- Is in it's current development state at least compatible with the following Yanfly Plugins, as you might have already spotted
in last screenshot:
YEP_ItemCore: But won't use it with independend items, as sorting in general seems to mess up with this functionality.
YEP_X_ItemCategories: Any weapon, armor added to a new category defined by this plugin, will be sorted by the rules
for normal items.
YEP_EquipCore
YEP_SkillCore
YEP_ShopMenuCore
YEP_BattleEngineCore

This plugin has to be placed under those plugins, but above YEP_OptionsCore to function properly.

Is not compatible with key board customization or gamepads yet. I would really appreciate suggestions on how I can get compatible with those!!!

Thanks
Thanks go to Yanfly. I learned a lot from reading through the code of Yanflys plugins. Without these plugins it might have taken
a lot longer to develop this plugin.

The actual plugin:
As I currently do not have any acount on a content sharing platform, I cannot provide a test project even I really want to.
Therefore I will upload the plugin directly here. Please grab it if you are interested.
Any feedback would be appreciated.

Thanks you,
BurningOrca
Moderator note: Moving this to JS Plugin Releases (MV) now that it is complete.
I found a bug while testing another plugin in the goods sorting options for custom sort.
I replaced the plugin with version 1.1
To the 6 people who've already downloaded it you might want to get the new version.
I also added configuration of the keys for the 'Sort Order' and 'Sort Method' to the plugin parameters.
Great plugin!

It seems to me that it would be easier to access the sorting types from the Item menu instead of having to enter the options menu every time though. Just a thought!

Great work!
Thank you.

As I developed the plugin it went through a lot of changes:
First I added everything to the options menu.
Then I added keyboard input keys for accessing the sorting options within the appropriate menus and they were saved back to the options.
But then I thought the options do not make any sense if the sort order selected in the menu is permanently saved back to the options.
So I made the options the default and the selected sort order in the menu only to be remembered as long as the window is open and in
case of the item window, it's category is not changed.

If it is better to keep the last selected sorting within the menu, I could remove the options menu and reintroduce the permasave within the
item, skill and shop menus.

Or did I misunderstand your suggestions?
I have some issues with the "Custom" parameter. I set its "Use" value to false, but it keeps appearing in-game.
@JamesRyan Thank you for your bug report.
I didn't realized that "Use" was still a string, when I checked it and if( String ) is always true.
I now replaced it with a newer version, where it will work.
Thanks! It works like a charm now!
Hi @BurningOrca, Thanks for your Plugin,

However, I have a bug with the Yanfly Plugin "Item Upgrade Slots", When I improve an object with the sorting activated it is all the objects of the same name which are improved each time.

Can you help me?
Sorry for not answering quite a time. I've just read this entry.
I have to tell you, that I am sorry, but I am not able to reproduce this issue with just the following plugins:

1576910269413.png


So I can't help you just yet.
I even couldn't reproduce this if I put my plugin above all YEP.
So I need to ask you what further plugins do you use?
Hello @BurningOrca and thank you for your response,
Here is a list of my plugins (all are disabled except "Item Core", "Item Upgrade Slot" and your plugin.

The bug appears when I have several identical weapons in my inventory with random stats (Item Core), when I want to improve one (Upgrade Slots) The improvements alternate between each weapon of the same name.

The sorting is configured on "Name" and "Asc".


Sans titre.png
Oh I realized I had a old version of my plugin and didn't set anything in the options.
But after getting the version from this side and setting the options I still wasn't able to reproduce it.
Could you please give me your plugin settings for YEP and my plugin aswell as the database entries
and notetags for the concerned items?
1577123283639.png

1577123320525.png

1577123365460.png

1577123575811.png

I will show you a video with a bug.

[EDIT]
This is a video with a bug
I am so sorry. I now tried it with the french names from your video/screenshots and also with creating a safe file, afterwards installing my plugin and loading the safe and still could not reproduce it.
I guess without my plugin and only the one of Yanfly it won't happen, am I correct?
Could you please try if it happens in a fresh project?

I now also spotted a little difference. My YEP_X_ItemUpgradeSlots says it is Version 1.10 in the description while yours does not.

1577126299757.png

Maybe getting v1.10 will fix the problem.
It's good it works, the problem was that you had to delete the yanfly plugin "item upgrade" in the plugin manager because the update had not been done correctly in 1.10.

Thank you, and I would credit you in my game for the help provided.
Seems this was not compatible with MV 1.5.1. I changed that now. And hopefully I've used the correct version of the plugin as I had it lying on my disk on 3 different paths.

Original thread: https://forums.rpgmakerweb.com/threads/highly-customizable-sorting-plugin.108247/