How can I mark a quick bar slot as "active"?

Place to get help with not working mods / modding interface.
Post Reply
IvanGS
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sat Jan 25, 2020 2:32 am
Contact:

How can I mark a quick bar slot as "active"?

Post by IvanGS »

Working on a mod to help with some controller support.
One thing I'm trying to do is allow you to press a button to go forward and backwards along the quickbar.

I actually have most of it working. The process is basically:

* Check which quick bar slot is currently active
* Figure out what item is on the next index
* Find the stack of the item in your inventory
* Swap it for whatever's currently on the cursor

The one piece I can't figure out is how to actually how to mark a new quick bar slot as "active". I've noticed when you select a stack directly from your inventory, it behaves the same way.

Is there some sort of event I could manually trigger to force this? Or hook into the actual keyboard shortcut and simulate it? Or is this functionality actually impossible?

Definitely feel like I'm overlooking something here. My mod can work without it, but it's a bit awkward since I'd have to internally keep track of your "active index" of the quickbar and you wouldn't see it reflected in the UI, so going forward and backwards with it might be confusing.

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

Re: How can I mark a quick bar slot as "active"?

Post by eradicator »

After a quick search through the doc LuaPlayer.hand_location is the only reference I could find. I thought there was also something on LuaItemStack but I don't see anything right now. Support for modding of the "hand slot" isn't very good so you might need to post an interface request (though those can take a long time until they're implemented even if they're accepted).

Depending on how you intend to implement controller support it might be a viable option to just move the mouse cursor (like in classic console JRPG menus).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

IvanGS
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sat Jan 25, 2020 2:32 am
Contact:

Re: How can I mark a quick bar slot as "active"?

Post by IvanGS »

Yeah, I have a joytokey set up that I've iterated on, mouse cursor movement is definitely still necessary for placement and the like, but switching items was the really cumbersome part. That's kind of why I wanted to override the quickbar :mrgreen:

All the hand stuff seems to work out ok, I actually didn't even think about setting the hand location in the inventory, but I'm more interested in making the quickbar slot light up correctly. I'll play around with the "hand slot" piece though, it seems like another convenient step to add.

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

Re: How can I mark a quick bar slot as "active"?

Post by eradicator »

As the quickbar isn't an inventory and thus has no ItemStack I have no idea how that works.

@joytokey: I didn't mean that you should manually move the cursor with a stick_axis -> mouse_axis mapping. I meant that the slots have a known position relative to the factorio window so one could just jump the cursor there. Though I'd use autohotkey for that not joytokey.

But wait...why can't you just map the number buttons? After all the quickbar is just hotkeys so it should be easy to map. Albeit this would still require keeping an internal index but at least the in-game display would look as if you had just pressed the number hotkey.

(Disclaimer: I've thought a bunch about how to make AHK based controller support, but I never got around to acutally do it.)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

IvanGS
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sat Jan 25, 2020 2:32 am
Contact:

Re: How can I mark a quick bar slot as "active"?

Post by IvanGS »

Ah, I'm not as familiar with auto-hotkey, in joytokey you can set a sequence of presses, but it only seems to support 4, so I couldn't have it go through a whole hotbar. I haven't found a good way to map a whole hotbar to only a few buttons, really.

Maybe I need to start digging into auto-hotkey more.

Unless you mean there's a way to trigger one of the game's hotkey events from a mod? I wouldn't mind doing that.

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

Re: How can I mark a quick bar slot as "active"?

Post by eradicator »

IvanGS wrote:
Thu Apr 08, 2021 2:50 am
Unless you mean there's a way to trigger one of the game's hotkey events from a mod? I wouldn't mind doing that.
Nope, you can't produce "natural key input" from inside a mod. If there's no API you can't do it.

I made a quick example AHK script that makes the arrow keys interact with the quickbar. AHK is a weird language so be prepared for some headaches if you go that way.

Code: Select all

#Warn, all
#SingleInstance, force
#Persistent
SetTitleMatchMode, 2 ; "contain string"


; @dx, number , Move cursor horizontally
; @dy, boolean, Move cursor vertically
Quickbar(dx := "", dy := "") {
  local
  static col := 1
  static row := "upper"
  
  if (dx) {
    col := Mod(col + dx + 10, 10)
    }
  
  if (dy) {
    row := (row == "upper") ? "lower" : "upper"
    }
  
  if (row == "lower") {
    Send, % "x" col "x"
  } else {
    Send, % col
    }
  }

  
  
#IfWinActive ahk_exe factorio.exe

; Map Quickbar to arrow keys.
Left:: Quickbar(   -1) ; go one slot left
Right::Quickbar(    1) ; go one slot right
Up::   Quickbar(,true) ; change row
Down:: Send, % "q"     ; clear cursor



; Auto-reload for debugging.
#IfWinActive factorio_dpad_quickbar.ahk
~^s::reload
(Must be manually renamed to ".ahk" because the forum doesn't allow .ahk upload.)
factorio_dpad_quickbar_0.0.1.txt
(807 Bytes) Downloaded 64 times
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding help”