Thread Tools Display Modes
07/17/14, 07:32 AM   #1
esothomas
 
esothomas's Avatar
Join Date: Jun 2014
Posts: 24
"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.
  Reply With Quote
07/17/14, 07:39 AM   #2
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
Originally Posted by esothomas View Post
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.
  Reply With Quote
07/17/14, 09:55 AM   #3
esothomas
 
esothomas's Avatar
Join Date: Jun 2014
Posts: 24
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...
  Reply With Quote
07/17/14, 10:39 AM   #4
ingeniousclown
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 122
This add-on proves that the inventory IS sortable, and probably even does what you're looking for.
  Reply With Quote
07/17/14, 11:38 AM   #5
esothomas
 
esothomas's Avatar
Join Date: Jun 2014
Posts: 24
i don't quite see what MrPlow actually does, though?
  Reply With Quote
07/17/14, 11:54 AM   #6
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
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 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
  Reply With Quote
07/17/14, 06:29 PM   #7
esothomas
 
esothomas's Avatar
Join Date: Jun 2014
Posts: 24
Originally Posted by merlight View Post
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.
  Reply With Quote
07/18/14, 06:41 AM   #8
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
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
  Reply With Quote
07/18/14, 09:45 AM   #9
ingeniousclown
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 122
You may find libSort useful if you plan on moving forward with the code.
  Reply With Quote
07/18/14, 10:45 AM   #10
esothomas
 
esothomas's Avatar
Join Date: Jun 2014
Posts: 24
Originally Posted by ingeniousclown View Post
LibSort (now with an actual adress, teehee)

it'd be pretty cool to have a universal "level (range) sort", running alongside advancedfilters.
  Reply With Quote
07/23/14, 08:47 AM   #11
Randactyl
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 251
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
  Reply With Quote

ESOUI » AddOns » AddOn Search/Requests » "sort by level"


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off