GUI element functionality to filter/sort by localised name

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
sparr
Filter Inserter
Filter Inserter
Posts: 975
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

GUI element functionality to filter/sort by localised name

Post by sparr » Tue Apr 03, 2018 4:21 am

This idea is meant to address viewtopic.php?f=28&t=32611 and related concerns. I currently find myself wanting to filter a list of technologies based on some user-entered search parameters, including name. I can't filter on localised name, for all the reasons already discussed in that thread.

What I propose is that the container GUI elements could accept some parameters that control the visibility or order of their children, executed at display time and not otherwise represented in game state.

Old way, statefully sorts on prototype name:

Code: Select all

-- make parent container
local flow = player.gui.top.add{type = "flow"}
-- get list of item names
local names = {}
local n=0
for name,_ in pairs(pairs(game.item_protytpes)) do
  n=n+1
  names[n]=name
end
names = table.sort(names)
-- add item buttons to parent in sorted order
for name in names do
  flow.add{type="button",caption=game.item_protytpes[name].localised_name}
end
Proposed way, locally/ephemerally sorts on localised name:

Code: Select all

-- make parent container, tell it how to sort children
local flow = player.gui.top.add{type = "flow", child_sort_attribute = "caption"}
-- add item buttons to parent
for _, prototype in pairs(game.item_protytpes) do
  flow.add{type="button",caption=prototype.localised_name}
end
Old way, statefully filters out some items based on prototype name:

Code: Select all

-- make parent container
local flow = player.gui.top.add{type = "flow"}
-- conditionally add item buttons to parent
for name, prototype in pairs(game.item_protytpes) do
  if string.find(name, "basic", 1, true) then
    flow.add{type="button",caption=prototype.localised_name}
  end
end
Proposed way, locally/ephemerally filters out some items based on localised name:

Code: Select all

-- make parent container, tell it which children to show
local flow = player.gui.top.add{type = "flow", child_filter_attribute = "caption", child_filter_regex = "basic"}
-- add item buttons to parent
for _, prototype in pairs(game.item_protytpes) do
  flow.add{type="button",caption=prototype.localised_name}
end

sparr
Filter Inserter
Filter Inserter
Posts: 975
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: GUI element functionality to filter/sort by localised name

Post by sparr » Tue Apr 03, 2018 4:45 am

The filter and sort criteria could be callback functions instead of a few hard-coded options in the engine. That would require exposing the lookup functions that the devs have denied us in the past, but maybe it could be done in such a way that calling them outside of this specific context would still be an error, but they could be called in this context.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 2604
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: GUI element functionality to filter/sort by localised name

Post by eradicator » Tue Apr 03, 2018 6:22 pm

The problem is not the filter function. The problem is that the "container" gui is part of the game state. And as such can not have a state that is locale-dependant because locales are currently only known to the instance (player) that runs them. So this does not solve the problem.

Here's a more recent thread: viewtopic.php?f=28&t=57945

sparr
Filter Inserter
Filter Inserter
Posts: 975
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: GUI element functionality to filter/sort by localised name

Post by sparr » Tue Apr 03, 2018 6:27 pm

What I am proposing is that the stored state of the GUI would be the entire list of *possible* child elements, in some order, just like the stored state of a caption is a LocalisedString table. Then the rendering engine itself would perform the filtering at display time, without changing game state, instead of currently us having to change game state by deleting/moving gui elements ourselves.

User avatar
mickael9
Fast Inserter
Fast Inserter
Posts: 112
Joined: Mon Mar 14, 2016 4:04 am
Contact:

Re: GUI element functionality to filter/sort by localised name

Post by mickael9 » Thu Apr 05, 2018 11:51 am

I agree with sparr, this should be possible. Also see my older proposal here: viewtopic.php?f=28&t=48164
Callbacks might be possible if you pass them as string instead of function object so they can run in their own context.

sparr
Filter Inserter
Filter Inserter
Posts: 975
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: GUI element functionality to filter/sort by localised name

Post by sparr » Thu Apr 05, 2018 6:56 pm

A callback could also work if the devs give us a "localize_string()" function like previous requests have asked for, BUT that function throws an error if it's called from anywhere except from a callback passed to a gui element, and those callbacks throw an error if they try to affect global state in any way.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 2604
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: GUI element functionality to filter/sort by localised name

Post by eradicator » Thu Apr 05, 2018 7:21 pm

I'm certainly not disagreeing that i want sortable gui elements. But implementing it via callbacks seems...unrealistic? As of now factorio has no callback functionality anywhere and trying to build bulkheads against all the things that mods could do wrong is a lot of error-prone work. And in the end you get a sort function that only works on gui elements. I think the "simple" approach of forcing all locales to be deterministic is much more realistic. And works for all of the mod-state, not just gui elements.

sparr
Filter Inserter
Filter Inserter
Posts: 975
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: GUI element functionality to filter/sort by localised name

Post by sparr » Thu Apr 05, 2018 9:21 pm

The devs have already repeatedly rejected the "simple" approach. Good luck with that :/

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 2604
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: GUI element functionality to filter/sort by localised name

Post by eradicator » Fri Apr 06, 2018 11:04 am

sparr wrote:The devs have already repeatedly rejected the "simple" approach. Good luck with that :/
Sounds like you didn't read the thread i initially linked to. Also in that case it would be rather strange if they instead chose to implement an even more complex mechanism :P.

sparr
Filter Inserter
Filter Inserter
Posts: 975
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: GUI element functionality to filter/sort by localised name

Post by sparr » Fri Apr 06, 2018 4:16 pm

The devs haven't rejected previous suggestions because of complexity. They have rejected them because they want to keep support for un-synced locale files.


sparr
Filter Inserter
Filter Inserter
Posts: 975
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: GUI element functionality to filter/sort by localised name

Post by sparr » Sat Apr 07, 2018 1:25 am

viewtopic.php?p=344301#p344803

Same thread, a few posts down, where the same dev explains why that idea is rejected

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 2604
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: GUI element functionality to filter/sort by localised name

Post by eradicator » Sat Apr 07, 2018 12:04 pm

sparr wrote:viewtopic.php?p=344301#p344803
Same thread, a few posts down, where the same dev explains why that idea is rejected
Except that's not a rejection. That's just an explanation of the main hurdle. If you read closely you'll notice it doesn't even contain the usual determinism argument. Not sure what you're trying to argument over. I already said i'm not against any improvement on that front.

sparr
Filter Inserter
Filter Inserter
Posts: 975
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: GUI element functionality to filter/sort by localised name

Post by sparr » Sat Apr 07, 2018 4:38 pm

Them not doing it for years is the rejection. Everything else is explanation of that implicit rejection.

Post Reply

Return to “Modding interface requests”

Who is online

Users browsing this forum: No registered users and 3 guests