Jump to content

How do I force an open part GUI to resize itself after making changes to it?


Recommended Posts

The code I have makes changes to part GUI's.  But it ends up looking odd in open part GUI's as the window doesn't automatically resize and refit to the changes, so unless I manually refresh I get odd overlaps like this -

Untitledd.png

How do I force it to reload the open part GUI every time I make changes to it?  Here's the relevant bit of my code.

		public virtual void FixedUpdate()
		{
			if (Lib.IsEditor() && sample_amount > 0)
			{
				Capacity = sample_amount.ToString("F2") + " " + Local.SCIENCEARCHIVE_samples;
				Fields["Capacity"].guiActiveEditor = true;
			}

			if (Lib.IsFlight() && (remainingSampleMass / ExpInfo.SampleMass) > 0)
			{
				Capacity = (remainingSampleMass / ExpInfo.SampleMass).ToString("F2") + " " + Local.SCIENCEARCHIVE_samples;
				Fields["Capacity"].guiActive = true;
			}

			else if (Lib.IsFlight() && (remainingSampleMass / ExpInfo.SampleMass) <= 0)
			{
				Fields["Capacity"].guiActive = false;
			}

 

Link to comment
Share on other sites

Update :

I figured it out though its probably not the most elegant method.  I'm putting it out here anyway though in case its useful to someone else at some point.  I used boolean true or false and get/set accessors so that a part window update gets triggered whenever false changes to true or vice versa.  Like so -

		private bool _UpdateGUI;
		public bool UpdateGUI
		{
			get
			{
				return _UpdateGUI;
			}
			set
			{
				if (value != _UpdateGUI)
				{
					part.PartActionWindow.displayDirty = true;
				}
				_UpdateGUI = value;
			}
		}

// And

		public virtual void FixedUpdate()
		{
			if (Lib.IsEditor() && sample_amount > 0)
			{
				Capacity = sample_amount.ToString("F2") + " " + Local.SCIENCEARCHIVE_samples;
				Fields["Capacity"].guiActiveEditor = true;
			}

			if (Lib.IsFlight() && (remainingSampleMass / ExpInfo.SampleMass) > 0)
			{
				Capacity = (remainingSampleMass / ExpInfo.SampleMass).ToString("F2") + " " + Local.SCIENCEARCHIVE_samples;
				Fields["Capacity"].guiActive = true;
				UpdateGUI = false;
			}

			else if (Lib.IsFlight() && (remainingSampleMass / ExpInfo.SampleMass) <= 0)
			{
				Fields["Capacity"].guiActive = false;
				UpdateGUI = true;
			}

 

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