Author Topic: Removing a button from a menu  (Read 1301 times)

Offline Bat66wat6

  • Posts: 144
  • Cookies: 34
  • Running custom BC 1.1
Removing a button from a menu
« 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.
Great men are not peacemakers! Great men are conquerors!

Offline Mario

  • Senior Software Developer
  • Administrator
  • Posts: 2197
  • Cookies: 1706
  • Life is life
Re: Removing a button from a menu
« Reply #1 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.
Acta, non verba.
aka USS Sovereign

Offline Bat66wat6

  • Posts: 144
  • Cookies: 34
  • Running custom BC 1.1
Re: Removing a button from a menu
« Reply #2 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
Great men are not peacemakers! Great men are conquerors!

Offline Defiant

  • Posts: 398
  • Cookies: 1105
    • BC: Kobayashi Maru
Re: Removing a button from a menu
« Reply #3 on: July 13, 2012, 04:11:42 AM »
Code: [Select]
import Lib.LibEngineering

...

pMenu = Lib.LibEngineering.GetBridgeMenu("Tactical")
pMenu.DeleteChild(pButton)

Offline Bat66wat6

  • Posts: 144
  • Cookies: 34
  • Running custom BC 1.1
Re: Removing a button from a menu
« Reply #4 on: July 13, 2012, 09:05:52 AM »
 :yeahthat:

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

*gives cookie*
Great men are not peacemakers! Great men are conquerors!

Offline Mario

  • Senior Software Developer
  • Administrator
  • Posts: 2197
  • Cookies: 1706
  • Life is life
Re: Removing a button from a menu
« Reply #5 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.
Acta, non verba.
aka USS Sovereign

Offline Bat66wat6

  • Posts: 144
  • Cookies: 34
  • Running custom BC 1.1
Re: Removing a button from a menu
« Reply #6 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  :)
Great men are not peacemakers! Great men are conquerors!

Offline Nebula

  • BC elder / BCC Vice Admin
  • Administrator
  • Posts: 5500
  • Cookies: 1129
  • KM - Mod Team Member & BC - Elder (2002)
    • 9th fleet HQ
Re: Removing a button from a menu
« Reply #7 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
Canon is what people argue exists on ships that don't exist.