Jump to content

Force Redraw of Tweakables GUI


Recommended Posts

Is there any method available to force a redraw of the tweakables (right click) menu for a part?

For context, I've got a couple of GUI event buttons that toggle their visibility back and forth using "Events["eventName"].guiActiveEditor" which generally works great, but for some reason it occasionally fails to redraw the GUI to show the newly visible button and remove the button that had it's visibility set to false. Right clicking on the part again shows the GUI how it should be. However, this isn't necessarily intuitive, so is there any method available that can force a redraw of the tweakable GUI for that part?

Thanks.

Link to comment
Share on other sites

I don't know about a redraw, but just in case it doesn't exist: maybe you can trigger closing and reopening the menu programatically (the redraw is definitely a better solution if possible).

Airblader, that's not a bad idea. Though so far I can't find any way to do that either. Unfortunately the documentation for the new tweakables system seems... well, non-existent.

Link to comment
Share on other sites

The documentation for anything seems pretty much non-existent. I don't know a way either, I just thought it might be possible to somehow do that in a workaround manner (getting the corresponding game object and so on). Like I said, it'd definitely be a less preferable solution, though.

Link to comment
Share on other sites

  • 2 weeks later...
You should be able to search for the EZGUI implementation behind it in some expensive obscure lookup through Unity itself and set the dirty flag to force a redraw.

I have done this, although it does require a bit of hacky reflection code to do it. You need to access some private variables to find the right object.

I'm not currently at home, will post a code snippet when I'm there later today.

Link to comment
Share on other sites

Here it is:



void SomeFunction()
{
UIPartActionWindow window = FindWindow();
window.displayDirty = true;
}

private FieldInfo windowListField;
private UIPartActionWindow FindWindow()
{
// We need to do quite a bit of ****-farting about with reflection to
// dig the thing out.
UIPartActionController controller = UIPartActionController.Instance;

if(windowListField == null)
{
Type cntrType = typeof(UIPartActionController);
foreach (FieldInfo info in cntrType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
{
if (info.FieldType == typeof(List<UIPartActionWindow>))
{
windowListField = info;
goto foundField;
}
}
Debug.LogWarning("*TCS* Unable to find UIPartActionWindow list");
return null;
}
foundField:

foreach (UIPartActionWindow window in (List<UIPartActionWindow>)windowListField.GetValue(controller))
if (window.part == part)
return window;

return null;
}


Link to comment
Share on other sites

I'll present a simpler alternative from my own PartModule code as well:


protected void RefreshAssociatedWindows()
{
foreach ( UIPartActionWindow window in FindObjectsOfType( typeof( UIPartActionWindow ) ) )
{
if ( window.part == part )
{
window.displayDirty = true;
}
}
}

It's probably not as fast as that in the post above as it basically scans through every object in the game, but for non performance critical uses (like if you aren't spamming these in flight), that shouldn't make much of a difference and the code is quite straightforward.

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...