Page 1 of 1

Read base game setting to keep player's inventory sorted

Posted: Mon Jun 15, 2020 9:45 am
by lovely_santa
Hi,

Currently I'm making some gui that contains the player inventory. When clicking a button, some item stacks go into the inventory, some go out of it. At the end of the button event, I'm redrawing the player's inventory. However, the player inventory is "unsorted" at this point, it is at the same stage where I left it after moving items around.

Depending on the player settings (see picture), this could be fine. The issue is, when the player has the setting enabled to always keep the player's main inventory sorted, I can solve this by calling sort_and_merge() on the inventory, however, when the player has this setting disabled, this becomes unwanted behaviour.

Hence my request to allow reading the "Always keep player's main inventory sorted" setting.
unknown[1].png
unknown[1].png (1.37 MiB) Viewed 1157 times

Re: Read base game setting to keep player's inventory sorted

Posted: Mon Jun 15, 2020 10:07 am
by lovely_santa
A small example:
  1. I start with opening my gui:
    unknown[3].png
    unknown[3].png (859.63 KiB) Viewed 1149 times
  2. I click on the left drive to select it, mimic it on the cursor stack (while it actually still is in the inventory)
  3. I click on the chest inventory slot, mimic the cursor stack to chest inventory move.
  4. Behind the scences, the selected player inventory stack is swapped with the selected chest inventory stack. This is done in order to maintain the item_number before/after inserting it in the chest. Hence why I cannot use player_inventory.remove() and chest_inventory.insert().
  5. After the move, the player inventory and the chest inventory are both redrawn (as the 'hand' icon is removed from the character inventory, and the chest now has an item inside. The result is shown in the picture below
    unknown[1].png
    unknown[1].png (529.22 KiB) Viewed 1149 times
  6. As you can see, on the new render of the gui in the picture above, the player inventory is unsorted, this is the expected result when you do not have your inventory sorting setting enabled, however I do have that setting enabled to auto sort it.
  7. As solution, I can sort_and_merge() the inventory before drawing the player inventory, and then I end up with the expected sorted inventory. But however this would mess up the inventory for players that do not want to have their inventory sorted. Hence why I want to read that setting. The result after calling the sort_and_merge prior to redrawing the gui is shown below.
    unknown[1].png
    unknown[1].png (698.64 KiB) Viewed 1149 times

Re: Read base game setting to keep player's inventory sorted

Posted: Wed Jun 17, 2020 5:34 am
by Rseding91
I added this in the last release.