[SOLVED][UI] newtaskbar.lua buttons

That’s what I supposed too, but from what @BitVenom told, I suppose it’s not the case ? :confused:

Edit :

Don’t know, thus my example for the “if” ^^ (I’ve never touched gamerules myself)

I also am unsure how players are going to edit the bindings if they depend on what game rule is loaded.

No idea ! Another good question for the great guru !

GetGameSettingAsNumber and GetGameSettingAsString perhaps ?

Also, we use UI_BindKeyEvent to allow player type in the number of goods they want to buy in our RPG mode… I don’t think there will be any guys who want to edit the bindings of those number keys, right?

Okay, a few things here…

  • Yes - GetGameSettingAsNumber / GetGameSettingAsString let you ask questions…
  • Sorry - doscanpath indeed.
  • UI_BindKeyEvent uses an internal callback that is ‘raw’ capture, and the key enums it uses are ancient, terrible things. The question isn’t if anyone would ever re-bind simple things like numbers - it’s why declaring them the ‘correct’ way isn’t workable. It is.
  • Why would bindings and controls visible in an ‘options’ screen care in any way, in any game, about a game mode? They wouldn’t. It is implied that some buttons are only for certain modes or specific use cases. That’s completely normal. Far MORE confusing are buttons that appear and disappear from a setup screen based on some external in-game choice. You can label them to make their context easy to understand, certainly. Don’t attempt to make your keybindings variant at load - that’s crazy (and has no mechanism).
1 Like

As far as I know, you can’t bind two commands to a same key in options screen right? So I think we cannot bind number keys to our “Buy Goods Menu” through the options screen, because they’re already bound to “Select Group”.

If you edit keybindings.lua you can remove the default bindings and replace them with whatever you want.

What code exactly?

I’m not going to “remove” default bindings… I just want, when players are fighting with enemy, they can use number key to select groups, but when they are buying goods, they can use number key to type in the number of goods they want. And player can still choose to bind “select groups” to any other key they want, but when they buy goods, they still use number key…

You can want anything you’d like - what you can get in reality may be something else entirely.

Are the numpad keys bound separately from the regular number keys? If so, you could rebind the numpad keys to something you want, and leave the other keys as they are.

1 Like

But the number keys used for the groups are the one on top of the letters on your keyboards, no ? (named ONEKEY, TWOKEY, etc… in keybindings.lua)

The number keys on the keypad are different ones (NUMPAD0, NUMPAD1, etc…), and so should be useable for your “buy goods” thing, no ?

Edit : not fast enough ^^

Using numpad keys only is not really a good idea - there’re many players who use a notebook computer and don’t really have a numpad. :disappointed_relieved:

@506933395 something extreme certainly but you could modify keybindings.lua this way, so that it acts differently depending if you are in your “buy goods” screen or not.

original code :

{ 70, eSelectGroup, INKE_KeyDown, 1, "$5368", {ONEKEY } },

new code :

{ 70, [[
    if (UI_IsScreenActive("BuyGoods")==1) then
        --your code here (external function call ?)
        MainUI_UserEventData( eSelectGroup, 1)
    ]], INKE_KeyDown, 1, "$5368", {ONEKEY } },

Ooooh, I will have to experiment with that!

just be careful with the second part of the code, there is two different types in keybindings.lua :

{ 70, eSelectGroup, INKE_KeyDown, 1, "$5368", {ONEKEY } },
where eSelectGroup seems to be a hardcoded event

{ 90, "SelectBuildFacility('Fighter')", INKE_KeyDown, 0, "$5388", {ALTKEY,FKEY } },
where “SelectBuildFacility(‘Fighter’)” is a string, calling a function

I don’t think it’s possible to mix those two kind of calls (event and string), so that’s why I made a whole big string in the example I gave in my previous post, by changing eSelectGroup to “MainUI_UserEventData( eSelectGroup, 1)” (which is equivalent, and used in newtaskbar.lua for example)

What I ended up doing was just clearing the screens so they are empty when not needed. The screens are still there, but you can’t tell since they’re empty of everything.

You know that you can hide / show a screen with UI_HideScreen / UI_ShowScreen, right ?

@BitVenom, another small question if I may.

I’m doing some tests with newtaskbar.lua, trying to replicate your method with doscanpath/dofilepath, to add a handy-button (left zone) in it without having to change the original file too much (just adding a dofilepath at the end), but I encountered a little problem.

The getn() and tinsert() lua functions are not recognized in UI context (parameter: attempt to call global `getn’ (a nil value) in HWRm.log), so I’m currently using a while sequence to find how many elements are already present in the table, to add my button after them, but it seems like a heavy method to do it.

Would it be possible to have the getn or tinsert function available in UI context, or do you know of another method I could use to replicate your mod-friendly thing, but for the UI ?