ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   AddOn Search/Requests (https://www.esoui.com/forums/forumdisplay.php?f=165)
-   -   "sort by level" (https://www.esoui.com/forums/showthread.php?t=1987)

esothomas 07/17/14 07:32 AM

"sort by level"
 
are items in this game categorizable by level? i feel like we could use a sorting mechanism in various crafting (and vendoring) windows that would allow us to quickly figure out what's worth using/saving, and what can be sold or whatever.

zgrssd 07/17/14 07:39 AM

Quote:

Originally Posted by esothomas (Post 10644)
are items in this game categorizable by level? i feel like we could use a sorting mechanism in various crafting (and vendoring) windows that would allow us to quickly figure out what's worth using/saving, and what can be sold or whatever.

Afaik it is impossible to apply sorting of any kind to teh inventroy views.
We can only apply filters.

It is a somewhat odd limitation, but afaik it is the one that is there.

esothomas 07/17/14 09:55 AM

so the only "hack" for this would be to manually detect level values, and setup a filter for that?

i don't get why ZOS didn't include this... :confused:

ingeniousclown 07/17/14 10:39 AM

This add-on proves that the inventory IS sortable, and probably even does what you're looking for.

esothomas 07/17/14 11:38 AM

i don't quite see what MrPlow actually does, though?

merlight 07/17/14 11:54 AM

From the description and images I think it sorts items in inventory in a more natural way. Like swords always before bows and staves, and such. I don't use it, but many times cursed why I have gloves made from various materials scattered all over my bag :D That's how it could be useful.

Anyway, when you asked the question, I took it as an excersise. The UI code is probably a mess, I was just picking pieces to make it work, but I managed to add a "Level" sorting header to the inventory, and with the way I've overridden sortFn, you can replace orderByItemLevel with custom comparison function.

Lua Code:
  1. local function orderByItemLevel(data1, data2)
  2.     local lv1 = GetItemLevel(data1.bagId, data1.slotIndex)
  3.     local lv2 = GetItemLevel(data2.bagId, data2.slotIndex)
  4.     return lv1 < lv2
  5. end
  6.  
  7. local function initializeCustomInventorySortFn(inventory)
  8.     inventory.sortFn = function(entry1, entry2)
  9.         local sortKey = inventory.currentSortKey
  10.         local sortOrder = inventory.currentSortOrder
  11.         local res
  12.         if type(sortKey) == "function" then
  13.             if inventory.currentSortOrder == ZO_SORT_ORDER_UP then
  14.                 res = sortKey(entry1.data, entry2.data)
  15.             else
  16.                 res = sortKey(entry2.data, entry1.data)
  17.             end
  18.         else
  19.             local sortKeys = ZO_Inventory_GetDefaultHeaderSortKeys()
  20.             res = ZO_TableOrderingFunction(entry1.data, entry2.data, sortKey, sortKeys, sortOrder)
  21.         end
  22.         return res
  23.     end
  24. end
  25.  
  26. -- call from EVENT_ADD_ON_LOADED
  27. local function experimentalSortInventoryByLevel()
  28.     local invSortBy = ZO_PlayerInventorySortBy
  29.     local nameHeader = invSortBy:GetNamedChild("Name")
  30.     local levelHeader = CreateControlFromVirtual("$(parent)Level", invSortBy, "ZO_SortHeader")
  31.     levelHeader:SetAnchor(RIGHT, nameHeader, RIGHT, -5, 0)
  32.     levelHeader:SetDimensions(80, 20)
  33.     ZO_SortHeader_Initialize(levelHeader, "Level", orderByItemLevel,
  34.                              ZO_SORT_ORDER_UP, TEXT_ALIGN_RIGHT, "ZoFontHeader")
  35.  
  36.     local inventory = PLAYER_INVENTORY.inventories[INVENTORY_BACKPACK]
  37.     initializeCustomInventorySortFn(inventory)
  38.     inventory.sortHeaders:AddHeader(levelHeader)
  39. end

esothomas 07/17/14 06:29 PM

Quote:

Originally Posted by merlight (Post 10654)
I managed to add a "Level" sorting header to the inventory, and with the way I've overridden sortFn, you can replace orderByItemLevel with custom comparison function.

sounds nice! would this conflict with other inventory ui mods? like, AdvancedFilters - i'm curious as to whether it's straightforward to implement in existing mods or not.

merlight 07/18/14 06:41 AM

I'm using AdvancedFilters, too. It doesn't conflict with filters, only sorts items that are in the (filtered) list. I noticed sometimes when I change filter category, the sort order resets to "Name", but so far I was unable to reproduce it reliably, it appears randomly.

The only real hack in my approach is this:
They use SortHeader to set currentSortKey="somestring", then pass this string along with a table describing how various keys are compared to ZO_TableOrderingFunction. I use a function as the sort key, not a string, and in sortFn check the type - if it's a function, call it, otherwise fall back to the original method. I admit I was a bit afraid it wouldn't work, but after scanning the sources didn't find any other place that would rely on sortKey being a string ;)

ingeniousclown 07/18/14 09:45 AM

You may find libSort useful if you plan on moving forward with the code.

esothomas 07/18/14 10:45 AM

Quote:

Originally Posted by ingeniousclown (Post 10689)

LibSort (now with an actual adress, teehee)

it'd be pretty cool to have a universal "level (range) sort", running alongside advancedfilters.

Randactyl 07/23/14 08:47 AM

I've actually already added filters for item level ranges to the drop down menus in Advanced Filters. I just have to wait to publish until 1.3 goes live as I'm using some of the new item link functions to get information.

I actually stumbled across this thread while I was looking for some tips on sorting the inventory by item quality. I'll probably pm you when I get home from work, merlight, as you're taking much of the same approach I was before I tried using libsort:)


All times are GMT -6. The time now is 08:18 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI