Save-Point
Sorting Items in Shop Window - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Games Development (https://www.save-point.org/forum-4.html)
+--- Forum: Code Support (https://www.save-point.org/forum-20.html)
+--- Thread: Sorting Items in Shop Window (/thread-7208.html)

Pages: 1 2


Sorting Items in Shop Window - Melana - 01-16-2018

I'm looking for a way to sort the items in the shop window individually like it was in RM2k and not by ID.

Maybe a simple scriptcall would be enough, but at this point I'm not sure how to do it.


RE: Sorting Items in Shop Window - kyonides - 01-16-2018

It would require a custom script because all items or weapons or armors are hashes that store ID's and amounts, not items per se. Even if you separate every potion or bronze sword, they will be identical, you may pick any of them or the next one that it would not matter at all. Before anybody offers a solution, you would need to specify how you pretend to use it and where you need it, i.e. a bag menu, a shop menu, etc.


RE: Sorting Items in Shop Window - Melana - 01-16-2018

Just the normal shop window but with a custom order instead of sorted by ID.

Maybe you know the Call Shop command from RPG Maker 2000. There the items in the shop windows were sorted by the order how you put it into the command windows in the editor.

So you could have it like this:

[1] Bronze Sword
[5] Bronze Spear
[9] Bronze Axe
[2] Iron Sword
[6] Iron Spear
[10] Iron Axe

Without rearranging the whole database.


RE: Sorting Items in Shop Window - BeJeremiah - 01-17-2018

Try this. Not sure if this is what you are looking for but trying replacing refresh method in Shop Buy with this.

Code:
def refresh
   if self.contents != nil
     self.contents.dispose
     self.contents = nil
   end
   @data = []
   for goods_item in @shop_goods
     case goods_item[0]
     when 0
       item = $data_items[goods_item[1]]
     when 1
       item = $data_weapons[goods_item[1]]
     when 2
       item = $data_armors[goods_item[1]]
     end
     if item != nil
       @data.push(item)
     end
   end
   # Sort by Name
   @data.sort! { |a,b| a.name <=> b.name }
   # If item count is not 0, make a bit map and draw all items
   @item_max = @data.size
   if @item_max > 0
     self.contents = Bitmap.new(width - 32, row_max * 32)
     for i in 0...@item_max
       draw_item(i)
     end
   end
 end



RE: Sorting Items in Shop Window - Melana - 01-17-2018

That helps alot.
Thank you!

At least as long as the alphabetical order does the trick.^^


RE: Sorting Items in Shop Window - BeJeremiah - 01-17-2018

(01-17-2018, 12:55 AM)Melana Wrote: That helps alot.
Thank you!

At least as long as the alphabetical order does the trick.^^

if not, change .name to the attribute you need. You can sort by name, occasion, price, etc. As long as it is shared by items, weapons, and armor. Otherwise you have to edit a little more to specify when to apply the sorting and what to sort by.


RE: Sorting Items in Shop Window - Melana - 01-17-2018

Yes, that works fine.

The only complicated thing is to have a complete uncommon order without a specific sorting.
Like adding weapon[67],weapon[64] and weapon[70], and then weapon[5], weapon[8] and weapon[2] just because you want them in that specific order without a reason.

Might be very unlikely though.


RE: Sorting Items in Shop Window - BeJeremiah - 01-17-2018

(01-17-2018, 01:35 AM)Melana Wrote: Yes, that works fine.

The only complicated thing is to have a complete uncommon order without a specific sorting.
Like adding weapon[67],weapon[64] and weapon[70], and then weapon[5], weapon[8] and weapon[2] just because you want them in that specific order without a reason.

Might be very unlikely though.

Im not sure why it changes the natural order of the array in the first place other than it is creating a new one that is referencing the original $game_temp.shop_goods but not directly using it. 

Maybe someone a little more experienced than I would know.


RE: Sorting Items in Shop Window - kyonides - 01-17-2018

I don't recall quite clearly, but I thought the event command window tries to order them once you close the add goods subwindow, or was it during the addition of new goods? If there's no order implied by the maker itself, it should be showed the way they were added. If that's not the case, then it's obvious you'd need to check the corresponding Interpreter command that handles the shop option, there you may find if there is a sort method at some point. Keep in mind it stores info like this: [[0,1],[1,2],[2,4]]


RE: Sorting Items in Shop Window - Melana - 01-17-2018

Yes the event command sorts them already in the editor by ID.
If you put in the Iron Sword first and then the Bronze Sword, the Bronze Sword will stay on top.