Page 1 of 1

Volatile selection tool (cursor-only).

Posted: Mon Jul 09, 2018 3:37 pm
by eradicator
What?
A selection tool that can only exist in the cursor_stack.

Whaat?
In a recent FFF you mentioned that 0.17 will have a copy/paste functionality that does not require an item. I'd like to have this functionality for mods too, to be able to select an area and trigger an event on selection without cluttering up the inventory with numerous selection tools.

Current problems/Possible Implementations:
While it is currently possible to put a "selection-tool" into the players cursor when a custom hotkey is pressed there is no way to ensure that they don't drop it on the floor/put it in a chest/etcpp. So a property for selection tools like cursor_only = true that automatically destroys the tool when it leaves the cursor stack should work. (I don't care if it's an actual selection tool or something else, as long as it works :).

Usecase:
I'm trying to update my old mod ScreenshotHotkey to use a selection-tool that only exists while it is in use.

Re: Volatile selection tool (cursor-only).

Posted: Mon Jul 09, 2018 5:44 pm
by Klonan
Would be useful for many cases

Re: Volatile selection tool (cursor-only).

Posted: Tue Jul 10, 2018 2:00 am
by eradicator
Just for the record, i did a partial solution for 0.16, if i wanted it perfect there's at least 6 different places to check every time the cursor changes.

Code: Select all

script.on_event({'er:controls:clean-cursor', --must work when inventory full!
  defines.events.on_player_cursor_stack_changed}, function(e)
  local player,pindex,pgui = get_player_data(e)
  local camera_settings = get_camera_settings(pindex)
  --prevent deleting in the same tick it is created
  if camera_settings.camera_tick == e.tick then return end
  --clean cursor stack
  if player.cursor_stack.valid_for_read
    and (player.cursor_stack.name == selection_tool_name)
    then player.cursor_stack.clear() end
  --clean opened entitiy
  if player.opened and (player.opened_gui_type == defines.gui_type.entity) then
    player.opened.remove_item{name=selection_tool_name,count=4e9}
    end
  --clean player inventories (main+toolbar)
  player.remove_item{name=selection_tool_name,count=4e9}
  --clean player trash slots
  local trash = player.get_inventory(defines.inventory.player_trash)
  if trash then
    trash.remove{name=selection_tool_name,count=4e9}
    end
  --clean items with inventory?
  --catch item dropped on belt?
  end)
Klonan wrote:Would be useful for many cases
I'll take that as a "yes" and am looking forward to 0.17 :p.

Re: Volatile selection tool (cursor-only).

Posted: Fri Aug 03, 2018 1:48 pm
by Klonan
Its added in 0.17 now as a flag, e.g:

Code: Select all

flags = {"only-in-cursor"}

Re: Volatile selection tool (cursor-only).

Posted: Wed Aug 08, 2018 12:37 pm
by eradicator
Wohoo! Lots of ugly code i can remove on my side when it comes :D.

Re: Volatile selection tool (cursor-only).

Posted: Wed Aug 22, 2018 1:39 pm
by kyranzor
holy crap this is super useful for my RTS mod concept as well!