[SOLVED][UI] newtaskbar.lua buttons

Very nice!! Could you please write a tutorial?

I will give a link to the psd file when I’ll do the full tutorial :slight_smile:

The buttons are working.

Next I want to be able to disable a button if the corresponding game rule setting is disabled.

I have figured out how to hide the buttons using UI_SetElementVisible(). However, I am still able to press hotkeys to activate the child windows. How do I disable the hotkeys?

I tried this:

UI_BindKeyEvent(PKEY, "do_nothing")

but it has no effect. The hotkey still triggers the button.

UI_UnBindKeyEvent(PKEY) ?

Thanks!

I’m having problems.

This works:

	UI_BindKeyEvent(PKEY, "Toggle_ProgressScreen")

This doesn’t:

	UI_BindKeyEvent(LESSTHAN, "Toggle_ProgressScreen")

I don’t understand why.

A word of warning… there’s a non-zero chance that UI_BindKeyEvent won’t work in the future…

The places ‘we’ use it in campaign will go away for a better system, for reasons I can’t get into. It is always best to setup key bindings the user can assign via the controls screen. Those will work.

1 Like

So I have to use keybindings.lua instead?

No idea, seems like a valid key in the exe :confused:

Did you try with GREATERTHAN ?
(you would also need to disable {164,"SelectNextIdleHarvester()",INKE_KeyDown,0,"$5443",{GREATERTHAN}}, in keybindings.lua I suppose)

Edit : not fast enough ^^

I like it when you’re being mysterious ^^

I’m really amazed that you’re still working on new things for this game !

Don’t forget that doscanfile can be used to scan a folder for lua, and run it - meaning, with a single line of code at the bottom of keybindings.lua, you can make it just load bindings for ‘whatever’ - and it is easy to have those files edit the structure from the root one.

I have set up some buttons/key bindings for my mod. How do I disable them when a game rule setting is not enabled? I only want the button to work if the setting is turned on. I came up with two methods, but both depend on UI_BindKeyEvent().

Put code in the called LUA that checks the rule?

I don’t understand.

Also, what is doscanfile?

I seem to remember reading something about it in the past, but I don’t manage to track it down

edit :
i found this for doscanpath but nothing for doscanfile

edit2 :
I didn’t see any reference to doscanfile into the exe so I suppose @BitVenom meant doscanpath

given the way lua works, it’d just have to add entries to an existing table without creating that variable as a new empty table. You could do some nil checking first and create the table if it doesn’t already exist to avoid terribleness.

Which table in which file?

This ended up not working, sadly. I guess keybinding.lua trumps any game rule script.

I didn’t see any reference to doscanfile into the exe so I suppose @BitVenom meant doscanpath

If your specific case, even a simple dofilepath could do the trick I suppose.
You can add a dofilepath(“data:mymod/mymodKeybindings.lua”) at the end of the keybindings file.
And create the mymodKeybindings.lua file with something like this in it :

--specific keybinding for gamerule type 1
mykeybindings_gamerule1 = {
    { 301, eDock,                        INKE_KeyDown,    0,                 "$5313",                            {DKEY} },
    { 302, eParade,                      INKE_KeyDown,    0,                 "$5314",                            {SHIFTKEY, PKEY} },
}

--specific keybinding for gamerule type 2
mykeybindings_gamerule2 = {
    { 301, eDock,                        INKE_KeyDown,    0,                 "$5313",                            {CONTROLKEY, SHIFTKEY, XKEY}},
    { 302, eParade,                      INKE_KeyDown,    0,                 "$5314",                            {NKEY }},
}

-- calculate the number of elements already present in the "keys" table in keybindings.lua
keys_index = getn(keys) + 1

-- here you set which keybinding to add depending of the activated gamerule
-- THIS IS ONLY A SIMPLE EXAMPLE TO SHOW THE LOGIC
if gamerule = "gamerule1" then
    mykeybindings = mykeybindings_Rule1
elseif gamerule = "gamerule2" then
    mykeybindings = mykeybindings_Rule2
end

-- this will add all the correct keybindings to the original "keys" table
for index,element in mykeybindings do
    keys[keys_index] = element
    keys_index = keys_index+1
end

This is the part I don’t understand. Isn’t keybindings.lua loaded before the game rule? How can you check for something that hasn’t been loaded yet?

Also, what function do you use to check for a game rule?