Jump to content

How to replace override or callback for Fill button on Crew Assignment screen


Recommended Posts

I'm updating the CrewQueue mod, and I need to have the mod's functions be used instead of the stock actions.

Specifically, there is a button on the Crew Assignment which I see is defined as:

public void ButtonFill();

How can I replace the stock code with the code in this mod?

The old code used the old EZGui, which obviously can't be used.

I know that the launch button has ways to do this using "fetch", but the crew assignment dialog doesn't have a fetch, only a static Instance.  And while the EditorLogic has a public Button for launchBtn which I use in other mods, there is no public button for the CrewAssignmentDialog.

I'm guessing that reflection may come into play, but I haven't any idea of what the button is actually called internally.

Thanks in advance

 

Link to comment
Share on other sites

32 minutes ago, linuxgurugamer said:

I'm updating the CrewQueue mod, and I need to have the mod's functions be used instead of the stock actions.

Specifically, there is a button on the Crew Assignment which I see is defined as:


public void ButtonFill();

How can I replace the stock code with the code in this mod?

The old code used the old EZGui, which obviously can't be used.

I know that the launch button has ways to do this using "fetch", but the crew assignment dialog doesn't have a fetch, only a static Instance.  And while the EditorLogic has a public Button for launchBtn which I use in other mods, there is no public button for the CrewAssignmentDialog.

I'm guessing that reflection may come into play, but I haven't any idea of what the button is actually called internally.

Thanks in advance

 

I'm not pretending to have the answer, but maybe this can help. The ButtonFill() seems to be using scrollListAvail and scrollListCrew which are both public. But since it is not virtual, I have no idea if there is any way to override it.

        public UIList scrollListCrew;
        public UIList scrollListAvail;

        public void ButtonFill()
        {
        }

 

Edited by Warezcrawler
Link to comment
Share on other sites

1 minute ago, Warezcrawler said:

I'm not pretending to have the answer, but maybe this can help. The ButtonFill() seems to be using scrollListAvail and scrollListCrew which are both public. But since it is not virtual, I have no idea if there is any way to override it.


        public UIList scrollListCrew;
        public UIList scrollListAvail;

        public void ButtonFill()
        {
            int num = 0;
            while (true)
            {
                UIListItem uilistItemAt = this.scrollListAvail.GetUilistItemAt(0);
                if (uilistItemAt == null)
                {
                    break;
                }
                int num1 = num + 1;
                num = num1;
                UIListItem uIListItem = this.scrollListCrew.GetUilistItemAt(num1);
                if (uIListItem == null)
                {
                    return;
                }
                CrewListItem component = uIListItem.GetComponent<CrewListItem>();
                if (component != null && component.isEmpty)
                {
                    this.MoveCrewToEmptySeat(this.scrollListAvail, this.scrollListCrew, uilistItemAt, num);
                }
            }
        }

 

Not really, that looks like what is being called when the buttonfill is called.

Link to comment
Share on other sites

progress:

This code:

Button b1 = GameObject.Find("Button Fill").GetComponent<Button>();
b1.onClick.RemoveAllListeners();
b1.onClick.AddListener(OnFillButton);

is working to add my listener, but for some reason, the original listener is still being called.

Link to comment
Share on other sites

You're almost there. RemoveAllListeners only removes non-persistent listeners. You can disable the persistent ones with onClick.SetPersistentListenerState. You might also want to be more discerning with your GameObject.Find call. You can just grab the right transform directly:

CrewAssignmentDialog.Instance.transform.Find("VL/Buttons/Button Fill"); // <-- GetComponent<Button> on this if found

 

Link to comment
Share on other sites

Just now, xEvilReeperx said:

You're almost there. RemoveAllListeners only removes non-persistent listeners. You can disable the persistent ones with onClick.SetPersistentListenerState. You might also want to be more discerning with your GameObject.Find call. You can just grab the right transform directly:


CrewAssignmentDialog.Instance.transform.Find("VL/Buttons/Button Fill"); // <-- GetComponent<Button> on this if found

 

Thank you!!!

 

Link to comment
Share on other sites

For anyone who wants to see the final code for this:

public void RemapFillButton()
{
	var buttonFillBtn = CrewAssignmentDialog.Instance.transform.Find("VL/Buttons/Button Fill"); // <-- GetComponent<Button> on this if found
	if (buttonFillBtn == null)
		return;
	Button b1 = buttonFillBtn.GetComponent<Button>();
           
	if (b1 != null)
	{
		b1.onClick.RemoveAllListeners();                
		b1.onClick.SetPersistentListenerState(0, UnityEventCallState.Off);
		b1.onClick.AddListener(OnFillButton);
	}
}

 

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...