raiguard / QuickItemSearch

Factorio mod - quickly search for items in your inventory or connected logistic network.
MIT License
3 stars 0 forks source link

Sort items first by availability, then by name #18

Closed azaghal closed 3 years ago

azaghal commented 3 years ago

Is your feature request related to a problem? Please describe.

When searching for an item in my inventory using Quick Item Search, I find it frustrating that items which are present in my inventory do not take priority over items which are not present in my inventory.

For example, if I have reached mid-game and decided to switch to using fast transport belts by default, most likely I will have the regular transport belts trashed automatically, and instead have only fast transport belts in my inventory. When I try to search for word "belt", however, the list will show the regular transport belts at top (with 0 items available in my inventory) in preference to fast transport belts. This means that I need to perform that one extra key stroke for picking the correct belt type from inventory.

Describe the solution you'd like

The quick item search list should favour listing matching items present in inventory before items available in logistics network and items that are not available in either.

Additional context

This is related primarily to new GUI change starting with version 2.0.0. The belt description is somewhat artificial - but I think it provides a good example. Maybe a better example would be searching for "Wood" - especially early game when you want to insert it into furnaces and miners. Or perhaps rocket fuel - if you type "Rocket", first two items in the list would be "Rocket silo" and "Rocket control unit" - items which are rarely being requested or used (while you might have rocket fuel on you all the time when placing new trains and such).

I could potentially see that the way new implementation lists items is beneficial in terms of being more consistent in the listing. E.g. every time you type in a new term, you get the same ordering. For me personally it was always useful to quickly locate item and just press "Enter" twice in succession to pick the correct item.

Perhaps it would be possible to introduce an option to pick sorting order instead to cater for both variants?

raiguard commented 3 years ago

I can do this, but it will significantly degrade the performance of searching. I changed it to be the way it is right now because it turns what was previously three separate loops into a single loop of all items. It more than doubles search performance. Prioritizing inventory items means iterating them all first, then iterating all items again to get the ones that were missed.

So it's not off the table, but it comes with that caveat.

azaghal commented 3 years ago

Hm... Perhaps it could be an optional (off by default) feature in that case?

I would assume that the biggest problem could come in case of public(ish) multiplayer servers?

While I understand small numbers can add-up to quite a bit in the end, is it a heavy performance hit relative to the rest of processing that happens in the game?

raiguard commented 3 years ago

I think I've decided not to do this, because like I said before, it would be convoluted and require two separate search loops. I like the way it is now. Sorry!

azaghal commented 3 years ago

Hey, no worries, thanks for looking into it at least :)

Would you be interested at all in a pull request that would make this an optional behavior, though?

Or, if not, would you have any interest in creating a common base/library that would be decoupled from the GUI?

I ask because my intention would be to avoid potential forking if I would ever come around to making the tweaks that work at least for me better, or at the very least to avoid having essentially duplicated code (not to mention I would probably base changes off of your code in either case).

Just to emphasize - this is not a knee-jerk reaction, even in case of a fork I would prefer it to be considered a "friendly" fork with fixes etc flowing upstream - I consider Quick Item Search one of the best usability improvement mods out there :)

raiguard commented 3 years ago

I'm just confused why you really want it. When I use the mod, I usually only end up with two or three results when I'm done typing, if that. I only did it the original way because I was distinctly separating inventory items and logistic items, but now they're combined. Is it really that much of a hassle to type a few extra letters to avoid the problem altogether?

azaghal commented 3 years ago

Probably just got used to the way it worked before, and when the change came in, it threw me off. Muscle memory and all. As for the extra typing, it kinda depends on how often it would happen - if you end-up skipping certain items all the time in searches, that's probably a good indicator some of the sorting could be improved.

Here's what I'll do, though - I'll try to give this particular change another chance, and see how it works out. Although I might need to roll-out at least locally a fix for #17, because that one actually does throw me off and keeps me going back to older release :)

And if it turns out to be an actual hassle, I'll first make sure to put my foot where my mouth is, and come up with a PR first :)

P.S. Just getting back into Factorio 1.1 after a long break from it, so haven't really had a chance to do any serious playthroughs.

raiguard commented 3 years ago

Sorry if I came off as rude, it wasn't my intention. I'm glad you're giving the update another chance.

I will be implementing #17, but it's less straightforward than I thought it would be, so it'll take a bit of time. Thanks for using the mod!