Bridge Commander Central

BC Forums => BC Scripting => Topic started by: Bat66wat6 on July 12, 2012, 01:07:24 PM

Title: Removing a button from a menu
Post by: Bat66wat6 on July 12, 2012, 01:07:24 PM
I am using the method below (not sure how many others there are) to add a button and define its event handler function; what gets called when button is clicked.
Code: [Select]
pMenu = Lib.LibEngineering.GetBridgeMenu("Tactical")
pButton = Lib.LibEngineering.CreateMenuButton("New button", "Tactical", __name__ + ".NewButtonHandler")

I've managed to disable the button using pButton.SetDisabled(1) but have not yet been able to find a function that will allow me to completely remove the button from the menu it was added to.

I want the button to be removed from the menu when I transport to another ship. The only thing i'm certain of at this point is that the game must allow for this functionality one way or another because transporting from a ship with say a cloaking device to one without a cloaking device magically removes the "Cloak on" "Cloak off" button and other similar ones where appropriate (Phasers etc) from the weapons display.

I've gone through almost all the SDK files but for my level of knowledge in the Totally Games created Python framework the function could be right in front of me and i'd never see it.
Title: Re: Removing a button from a menu
Post by: Mario on July 12, 2012, 03:14:05 PM
Check DS9FXMenuLib.py which is located in Custom\DS9FX\DS9FXLib there is a method which does what you want.
Title: Re: Removing a button from a menu
Post by: Bat66wat6 on July 12, 2012, 09:31:32 PM
The mod you pointed me to wasn't on my machine so I had to go out and download the whole monster 700 MB for that one .py.

Anyways, i'm trying to use the DeleteButton function and (strangely) couldn't find any example of its use within any of the scripts in DS9FX. I threw the function into my script (with credits to its creators, of course) and used some guestimating and come up with calling the function as:
Code: [Select]
DeleteButton(pButton.GetName(), "Tactical")
The resulting error is:
Code: [Select]
File ".\Scripts\Custom\QBautostart\TheButton.py", line 577, in NewPlayerShip
    DeleteButton(pButton.GetName(), "Tactical")
TypeError: STButton_GetName requires exactly 2 arguments; 1 given

Honestly, beyond knowing it's a "TypeError" type error i'm unsure as to the remedy. So I tried to cast the button object so it'd be able to use the .GetName() function and see if that did the trick:
Code: [Select]
pButton = App.STButton_Cast(pButton)
DeleteButton(pButton.GetName(), "Tactical")

It just left me with the same error  :roll
Title: Re: Removing a button from a menu
Post by: Defiant on July 13, 2012, 04:11:42 AM
Code: [Select]
import Lib.LibEngineering

...

pMenu = Lib.LibEngineering.GetBridgeMenu("Tactical")
pMenu.DeleteChild(pButton)
Title: Re: Removing a button from a menu
Post by: Bat66wat6 on July 13, 2012, 09:05:52 AM
 :yeahthat:

Thanks Defiant. That's exactly what I was after.  :angel

*gives cookie*
Title: Re: Removing a button from a menu
Post by: Mario on July 13, 2012, 03:56:49 PM
You should have told me that you didn't have DS9FX. I'm used to people having it on their installs lol

The parameters it expects is the button caption IIRC.
Title: Re: Removing a button from a menu
Post by: Bat66wat6 on July 13, 2012, 04:13:55 PM
My bad I guess. Whilst KM is great and there are so many cool things in it I just find the game to be less stable and just plain don't like the way ships have been balanced.

Meh, thanks. You can have a cookie for your time anyways  :)
Title: Re: Removing a button from a menu
Post by: Nebula on July 15, 2012, 11:20:14 PM
I always meant to have all the ships rebalanced but the crew helping me with that disappeared xD :P