Sort item icons in rich text by where they would appear in the inventory
Posted: Thu Apr 08, 2021 6:50 pm
by Sachertorte
Train stops are currently sorted alphabetically. When train stop names contain rich text icons, this ordering becomes nonintuitive, because the '[item=internal-entity-name]' syntax is invisible to the user. While the user might still guess that the stops are sorted alphabetically by item name, in languages other than English this is near impossible - the ordering appears to be effectively random. There's a mental barrier to picking a train stop from a long list.
I propose sorting rich text icons by their entity's internal 'order' string so that icons in train stops are ordered the same as the player's inventory. I feel this ordering is very intuitive.
In the below example note how the science stops, circuit stops are all next to each other and 'in order'. The current behaviour on the left, while logical, appears nonsensical in comparison.
train-stop-sorting.png (70.46 KiB) Viewed 2523 times
I've been using icons to name my rail stops. I was hoping that this would cause the rail stops to be 'alphabetised' by that icon's position in the crafting menu, leading to an intuitive ordering - for example, the science stops would all be listed next to each other and in order.
However, that's not what happens - the ordering appears to the layman (me) to be effectively random (see image).
It would be nice to have the sort order for icons be by their position in the entity selection menu.
EDIT: I realise that this would be the same order that the inventory is sorted in - so the ordering system already exists, right? I have updated this post's title to reflect this.
trains.png (109.09 KiB) Viewed 4224 times
Re: Sort icons by their position in the crafting menu
Posted: Thu Apr 08, 2021 6:56 pm
by NotRexButCaesar
Sachertorte wrote: ↑Thu Apr 08, 2021 6:50 pm
the ordering appears to the layman (me) to be effectively random (see image).
Those icons are really hidden text. If you copy paste into a text editor you will see something like [item=automation-science-pack]. https://wiki.factorio.com/Rich_text
The text is then sorted alphabetically:
plastic-bar
production-science-pack
productivity-module
rail
steel-plate
stone-brick
stone
sulphur (get it right devs )
transport-belt
Re: Sort icons by their position in the crafting menu
Posted: Fri Apr 09, 2021 5:25 am
by ssilk
This is very hard to be fixed, because the internal name will not change anymore, but the displayed name is translated.
The sorting routine must do the same as the display-routine: scan over the name, pick out the icons, lookup the translation for this icon, and replace it with the icon. Then it can start to sort. For some long lists will influence the performance hard.
NotRexButCaesar wrote: ↑Thu Apr 08, 2021 6:56 pm
[*] sulphur (get it right devs )
Both writings are correct English.
Re: Sort icons by their position in the crafting menu
NotRexButCaesar wrote: ↑Thu Apr 08, 2021 6:56 pm
[*] sulphur (get it right devs )
Both writings are correct English.
"sulphur" seems to be british and "sulfur" american
Re: Sort icons by their position in the crafting menu
Posted: Fri Apr 09, 2021 8:01 am
by GrumpyJoe
Alumin(i)um
chchch
Re: Sort icons by their position in the crafting menu
Posted: Fri Apr 09, 2021 6:22 pm
by Sachertorte
ssilk wrote: ↑Fri Apr 09, 2021 5:25 am
This is very hard to be fixed, because the internal name will not change anymore, but the displayed name is translated.
The sorting routine must do the same as the display-routine: scan over the name, pick out the icons, lookup the translation for this icon, and replace it with the icon. Then it can start to sort. For some long lists will influence the performance hard.
If the code to create a stone wall icon, for example, is [item=stone-wall] in English regardless of client language (I assume "stone-wall" is the 'internal name'), surely alphabetising this syntax by position in the crafting menu would replace looking up that item's name in the client language? It might be a heavier operation but if that's correct then it's at least not additive.
NotRexButCaesar wrote: ↑Thu Apr 08, 2021 6:56 pm
[*] sulphur (get it right devs )
Both writings are correct English.
I know, it was sarcasm.
Re: Sort icons by their position in the crafting menu
Posted: Wed Apr 14, 2021 10:41 am
by Krid
my workaroud suggestion: (works in most ERP Systems untested for factorio)
get a Name Icon
get b Name Icon
get c Name Icon
or if you need more letters for sorting:
get ab Name Icon
get ac Name Icon
get a Name Icon
or if that not enough
get aaa Name Icon ....
(if you use 2 or more letter codes as prefix; i guess you can even put the icon in front)
Re: Alphabetise item icons in rich text by inventory order
Posted: Tue Oct 24, 2023 11:32 pm
by Sachertorte
I've been thinking about a mod that attempts to implement this, but I don't think it's feasible.
In theory, creating the new order should be easy. If the lexograhpical sort function can be hijacked, or if another sort can be inserted inside/after each method that produces such a list, e.g. LuaGameScript::get_train_stops:
Get the train stop name, e.g. from my first screenshot, "get [item=productivity-module]Modules"
For each rich text icon syntax in the string, extract the internal name of the item
Look up the order string from the corresponding item prototype - e.g. game.entity_prototypes[name].order
Subsitute the order string back into the train stop name - e.g. "get c[productivity]-a[productivity-module-1]Modules"
Sort the first list using the second list as the key
Problem is I don't think it's possible to just insert that behaviour somewhere and call it a day. You can't just override class methods in Lua like you can in, say, Ruby. You can't just have the trains GUI call this new function - not without building an entirely new GUI that looks the same, anyway, and that's way out of scope for this (and for me!)
Anyone have any suggestions on how it might be possible to get a mod to do this?
Re: Sort icons by their position in the crafting menu
Posted: Tue Oct 24, 2023 11:48 pm
by Illiander42
ssilk wrote: ↑Fri Apr 09, 2021 5:25 am
[*] sulphur (get it right devs )
Both writings are correct English.
[/quote]
We really need to normalise the knowledge that English and American are different, but mutually intelligable languages. Same as the Danish/Norwegian/Swedish set.
Re: Alphabetise item icons in rich text by inventory order
Posted: Wed Oct 25, 2023 11:45 am
by Koub
TBH, I'm not fond of the suggestion. Icons are icons, and the alphabet is the alphabet. Sorting with alphabetic order is one thing, ordering pictures by the the alphabetic order of the word they're supposed to represent is another.
Even sorting characters can be tricky when numbers are involved : should the sorting be alphabetical or numerical based ? Order 5, 320, 12, 130, and 20.
5, 12, 20, 130, 320 (by increasing numbers) or 12, 130, 20, 320, 5 (increasing number in the alphanumeric ordering) ? There is no consensus, and off topic in the context of the original suggestion, just an example that not all sorting systems are universal. And sorting pictures is probably the least universal of all
Re: Alphabetise item icons in rich text by inventory order
Posted: Wed Oct 25, 2023 1:40 pm
by Illiander42
How about we sort pictures by the RGB values in the order they are in the pixel buffer, sorted alphabetically? Just to get really confusing
Re: Sort icons by their position in the crafting menu
Posted: Wed Oct 25, 2023 4:11 pm
by Qon
ssilk wrote: ↑Fri Apr 09, 2021 5:25 am
This is very hard to be fixed, because the internal name will not change anymore, but the displayed name is translated.
It's not hard.
It doesn't really matter if it changes. The order it is in now is not really the one you expect if you use the GUI to enter the icons anyways. But you find it by scrolling through the list, and a familiar order of icons will feel more consistent. Who selects train stops by list index number?
Translated name is irrelevant for the thread. No one asked for translated name to affect the order. And even if the order changed every time you changed display language, who cares? And no one changes display language anyways.
ssilk wrote: ↑Fri Apr 09, 2021 5:25 am
The sorting routine must do the same as the display-routine: scan over the name, pick out the icons, lookup the translation for this icon, and replace it with the icon. Then it can start to sort. For some long lists will influence the performance hard.
Not translation, the sort order property. It's another internal string. But a computer can sort a million items instantly. The list order is only updated when stations are added or removed or renamed. Yeah doing lookups will slow the process down a bit, but this happens so rarely. And how much will it slow down this rare task, really? If done in Lua yeah maybe you could skip a frame when adding a station on the largest train base ever. But it's not like people doing rails to the edge of the map add a stop on every tile with a million unique icon prototypes to iterate through. And even if they did, the sort is already happening and you aren't arguing against presenting in text order all together for speed ups.
Koub wrote: ↑Wed Oct 25, 2023 11:45 am
TBH, I'm not fond of the suggestion. Icons are icons, and the alphabet is the alphabet. Sorting with alphabetic order is one thing, ordering pictures by the the alphabetic order of the word they're supposed to represent is another.
You didn't understand the suggestion. Currently the icons ARE sorted in alphabetical order (of the internal name). You arguing for the status quo is you arguing against your reasoning.
Facts: The user benefits from having the list sorted in a predictable order. The list is strings of both icons and letters. The icons are internally represented by text strings, but this is not obvious to all users and can't be a reason for arguing that the order is the expected one. It's sorting on text currently, but it doesn't have to be that way when names can be exclusively icons now. The internal name doesn't even perfectly correspond to the EN translation. But for users playing with another display language the icons being sorted by an English internal name will be completely unpredictable unless they write in the icons as text themselves.
If the icons were sorted in same order as the display language translation, then users could replace the name in a train station with the icon and the stations would stay in the same order, meaning they could scroll to the end of the list to quickly find the sulfur if it was spelled "zzzulfur" in their language, regardless if the name was written or represented by the sulfur icon. That would be an improvement for them.
If the icons were sorted in the same order as the crafting GUI, then that is also a familiar order that helps you quickly scroll to the right position to find the stop named [sulfur icon].
But yes, it would be slower. And it would require dev time. And is it really necessary? I might be convinced either way that the dev time is not worth it for a useless feature, personally I am building self building factories so I don't need a GUI at all mostly. But you can't convince me that the current system is the only one the devs are capable of programming and other better solutions are too hard. You can't convince me that the current order is better for the users, all else being equal. It's objectively inferior for the users that the icons are sorted "randomly".
Re: Sort icons by their position in the crafting menu
Koub wrote: ↑Wed Oct 25, 2023 11:45 am
TBH, I'm not fond of the suggestion. Icons are icons, and the alphabet is the alphabet. Sorting with alphabetic order is one thing, ordering pictures by the the alphabetic order of the word they're supposed to represent is another.
You didn't understand the suggestion. Currently the icons ARE sorted in alphabetical order (of the internal name). You arguing for the status quo is you arguing against your reasoning.
Facts: The user benefits from having the list sorted in a predictable order. The list is strings of both icons and letters. The icons are internally represented by text strings, but this is not obvious to all users and can't be a reason for arguing that the order is the expected one. It's sorting on text currently, but it doesn't have to be that way when names can be exclusively icons now. The internal name doesn't even perfectly correspond to the EN translation. But for users playing with another display language the icons being sorted by an English internal name will be completely unpredictable unless they write in the icons as text themselves.
If the icons were sorted in same order as the display language translation, then users could replace the name in a train station with the icon and the stations would stay in the same order, meaning they could scroll to the end of the list to quickly find the sulfur if it was spelled "zzzulfur" in their language, regardless if the name was written or represented by the sulfur icon. That would be an improvement for them.
If the icons were sorted in the same order as the crafting GUI, then that is also a familiar order that helps you quickly scroll to the right position to find the stop named [sulfur icon].
But yes, it would be slower. And it would require dev time. And is it really necessary? I might be convinced either way that the dev time is not worth it for a useless feature, personally I am building self building factories so I don't need a GUI at all mostly. But you can't convince me that the current system is the only one the devs are capable of programming and other better solutions are too hard. You can't convince me that the current order is better for the users, all else being equal. It's objectively inferior for the users that the icons are sorted "randomly".
I see what you mean. You mostly convinced me on this one.
Mostly but not totally, because I see the point of a reliable sorting order, but I think sorting works best when is a consensus on how it should be sorted.
Should the order be "as in the crafting menu" (aka universal), or "as in the current language display name" (aka language specific) ? Can't be both, and if one is chosen, people expecting the other will be disappointed.
Do you think most people expect the "name" sorting, or the "crafting menu" sorting ?
Re: Sort icons by their position in the crafting menu
Posted: Wed Oct 25, 2023 6:04 pm
by FuryoftheStars
Koub wrote: ↑Wed Oct 25, 2023 5:33 pm
Do you think most people expect the "name" sorting, or the "crafting menu" sorting ?
Regardless of if anyone expects "name" sorting (I'm sure there are some out there), the same order as in the crafting menu does make more sense. As the example given with science packs, name sorting will put them all over the place instead of clumped together. That, too, and the current internal name that it sorts by doesn't always start with the exact letter/word that someone would expect it to who isn't familiar with them.
Re: Alphabetise item icons in rich text by inventory order
Posted: Wed Oct 25, 2023 6:05 pm
by Sachertorte
Qon wrote: ↑Wed Oct 25, 2023 4:11 pm
It's objectively inferior for the users that the icons are sorted "randomly".
It seems like it should have been so obvious in retrospect, but yes I did initially think the stops were effectively random, as I mentioned in the OP. And that's an excellent point about it being even worse for users not using the English locale. Perhaps that indicates this isn't such a weird suggestion after all
Koub wrote: ↑Wed Oct 25, 2023 5:33 pm
Should the order be "as in the crafting menu" (aka universal), or "as in the current language display name" (aka language specific) ? Can't be both, and if one is chosen, people expecting the other will be disappointed.
Do you think most people expect the "name" sorting, or the "crafting menu" sorting ?
Definitely the universal option. I think the only person in this thread advocating for alphabetical-by-localised-item-name sorting was ssilk, who I suspect might have also misinterpreted what I was asking for. (a few people have done this, so that's my fault for not being clear enough!)
The sort order per the crafting menu is IMO just intuitively the order that icons are supposed to be in. I don't care that Advanced Circuits come before Electronic Circuits alphabetically, at least in English, and that's not how my brain processes it - red circuits always come after green circuits and that just feels like that's how it should be. Anything else is a cognitive dissonance, at least for me.
Re: Sort icons by their position in the crafting menu
Posted: Wed Oct 25, 2023 6:49 pm
by Qon
Koub wrote: ↑Wed Oct 25, 2023 5:33 pm
I see what you mean. You mostly convinced me on this one.
Re-read my message until you are convinced then q:
Ok, I'll slot in the final pieces...
Koub wrote: ↑Wed Oct 25, 2023 5:33 pm
Mostly but not totally, because I see the point of a reliable sorting order, but I think sorting works best when is a consensus on how it should be sorted.
Should the order be "as in the crafting menu" (aka universal), or "as in the current language display name" (aka language specific) ? Can't be both, and if one is chosen, people expecting the other will be disappointed.
Do you think most people expect the "name" sorting, or the "crafting menu" sorting ?
Currently everyone is disappointed, ~0% of users would choose the current order. Either is better than the current system.
And no, I don't think anyone is going to be "disappointed" that the items aren't sorted on their display language name. It's preferred to the current one, but none of them are asking for the crafting menu to be sorted on name or localized name. The order they appear in crafting menu is the way they usually experience their order, it will be just fall so natural to find them in that order that they will not think of scrolling to where the item would have been if the name was written out. No one actually deeply wishes for their localized names they write in their train stop names that are then converted to icons to stay in the same order. It's just preferable the current random sorting that confuses them. When the order changes because they change text to icons the train stops will just appear in such a natural order that they probably won't notice that the order changed, they will just move on playing the game without noticing that in the past others would encounter random stop listing sorting.
The items have a sort order property, literally called "order", a string property that exists for the items to be sorted on.
It's obvious what the objectively correct answer is. No one will be disappointed. 100% user satisfaction. Only the type of person that complains about a bug fix would argue for a change from the correct answer to anything else.
Re: Sort icons by their position in the crafting menu
Okay, okay, I'm sold. Sorting the icons with the same order as in the crafting menu would probably be the best solution.
One of my two favourite xkcd strips BTW .
Re: Alphabetise item icons in rich text by inventory order
Posted: Wed Oct 25, 2023 10:40 pm
by Sachertorte
I've added an image to the OP with a visual example of what I'm hoping for, to hopefully make it crystal clear to everyone (and any devs who happen to stumble across this post) what this suggestion is about
Re: Alphabetise item icons in rich text by inventory order
Posted: Tue Oct 31, 2023 2:09 am
by Sachertorte
Alright, I've gone ahead and made my first mod to implement this as a proof-of-concept.
This mod adds a pane to the train UI with a list of all stops on that train's surface, ordered as per this thread's suggestion. Example screenshot on the mod page.
Trying to actually use it in a larger world reveals a couple of shortcomings - e.g. fluids are unsorted, duplicate stops aren't condensed, no indication of whether the train can actually reach each stop - but as a first proof-of-concept this is more than sufficient IMO. I'll be using and tweaking it going forward.
I'd still really like to see this behaviour in the base game, as even in its current state I'd personally much rather use this makeshift menu over the current dropdown (at least when I have to sift through a hundred stops). I really do feel that this order is an objective improvement everyone could benefit from.
Thanks to _CodeGreen and Bilka for lending a hand with understanding how GUIs work in Discord.
Example screenshot from the mod page
Mod source code
A copy-paste of the mod's source code as of right now. I won't be updating this forum post if I update the mod.
It's all from control.lua, there are no other files.
-- Construct list when locomotive UI is opened
script.on_event(
defines.events.on_gui_opened,
function(event)
if event.entity == nil then return end
if event.entity.type == "locomotive" then
local player = game.get_player(event.player_index)
make_train_stop_list_ui(player, event.entity)
end
end
)
-- Destroy list when locomotive UI is closed
script.on_event(
defines.events.on_gui_closed,
function(event)
if event.entity == nil then return end
if event.entity.type ~= "locomotive" then return end
local player = game.get_player(event.player_index)
destroy_train_stop_list_ui(player)
end
)
-- Add train to stop on button click
script.on_event(
defines.events.on_gui_click,
function(event)
if event.element.tags == nil then return end
if event.element.tags["action"] ~= "add_train_stop_to_schedule" then return end
local player = game.get_player(event.player_index)
add_stop_to_train_schedule(player.opened, event.element.caption)
end
)
-- Construct list UI
function make_train_stop_list_ui(player, locomotive)
if player.gui.relative.train_stop_list_container ~= nil then
destroy_train_stop_list_ui(player)
end
local container = player.gui.relative.add({
name = "train_stop_list_container",
type = "frame",
anchor = {
gui = defines.relative_gui_type.train_gui,
position = defines.relative_gui_position.left
},
caption = "Train stops",
direction = "vertical"
})
container.style.vertically_stretchable = true
local info_label = container.add({
type = "label",
caption = "Sorted with rich text icons ordered by inventory position. Click to add stop to the schedule"
})
info_label.style.single_line = false
info_label.style.maximal_width = 300
local list_container = container.add({
name = "train_stop_list_container",
type = "frame",
style = "inside_deep_frame",
direction = "vertical"
})
list_container.style.vertically_stretchable = true
local list = list_container.add({
name = "train_stop_list",
type = "scroll-pane",
style = "scroll_pane_with_dark_background_under_subheader",
direction = "vertical"
})
list.style.vertically_stretchable = true
list.style.minimal_width = 250
list.style.maximal_width = 300
-- Get list of train stops and sort them, respecting rich text
surface_train_stops = game.get_train_stops({
surface = locomotive.surface
})
table.sort(
surface_train_stops,
function(stop_1, stop_2)
stop_1_name = replace_item_in_stop_name_with_order_string(game, stop_1)
stop_2_name = replace_item_in_stop_name_with_order_string(game, stop_2)
return stop_1_name < stop_2_name
end
)
for index, train_stop in ipairs(surface_train_stops) do
local button = list.add({
type = "button",
name = "train_stop_button_"..index,
tags = { action = "add_train_stop_to_schedule" },
caption = train_stop.backer_name,
style = "list_box_item"
})
button.style.horizontally_stretchable = true
end
end
-- Destroy list UI
function destroy_train_stop_list_ui(player)
if player == nil then return end
if not player.gui.relative.train_stop_list_container then return end
player.gui.relative.train_stop_list_container.destroy()
end
function replace_item_in_stop_name_with_order_string(game, stop)
-- Doesn't handle non-items e.g. fluids
local stop_name = string.gsub(
stop.backer_name,
"%[item=(.-)%]",
function(item_name)
local item = game.item_prototypes[item_name]
return item.group.order..item.subgroup.order..item.order
end
)
return stop_name
end
function add_stop_to_train_schedule(locomotive, stop_name)
if locomotive.train == nil then return end
local train = locomotive.train
local existing_schedule = train.schedule
local new_schedule = {
current = existing_schedule.current,
records = {}
}
for _, record in pairs(existing_schedule.records) do
table.insert(new_schedule.records, record)
end
table.insert(new_schedule.records, {
station = stop_name,
wait_conditions = {}
})
train.schedule = new_schedule
end