Jump to content

Refreshing a PartModule's editor description


Recommended Posts

So partmodule.GetInfo() is called when a part is initially loaded to setup the editor module description. However, I would like to populate some portion of my GetInfo block with data that is generated when the editor loads. Is there a way to force the description block's text to be rebuilt manually? I've had a dig through the API with not a huge amount of luck.

Link to comment
Share on other sites

I am fairly certain that the GetInfo field is only populated by the part prefab, not any random instance of a part, so you'll have to look at AvailablePart.

I would like at PartLoader.LoadedPartsList for all of the parts. AvailablePart.moduleInfos is a list of all the part module GetInfo results. I think updating the relevant AvailablePart.ModuleInfo's info string should do it.

Link to comment
Share on other sites

I tried this on in the part's Start() without any errors, but without any success in updating the module info. Is this what you are describing?

AvailablePart p = PartLoader.LoadedPartsList.Find(pt => pt.name == part.name);
for (int i = 0; i < p.moduleInfos.Count; i++)
{
	if (p.moduleInfos[i].moduleName == "ModuleCryoTank")
	p.moduleInfos[i].info = GetInfo();
}
Link to comment
Share on other sites

This is in the editor? Maybe the editor part tooltip is assigned when the editor starts.

In KSP.UI.Screens.Editor there are a bunch of classes related to the PartListTooltips, one of those might have something accessible with the info field.

Link to comment
Share on other sites

This might be more work than it's worth at this point :P I was hoping it'd be relatively simple, but it seems like it might be easier to just drop a part action field in to show the field I want. 

Link to comment
Share on other sites

On 10/6/2016 at 8:34 AM, blowfish said:

Out of curiosity, what info do you need to display that can't be determined before the editor launches?

Hmm well I have a part that specifies the amount of a resource it consumes based on the total amount of the resource. Currently the tooltip says something like 50Ec per 1000units, but it would be better to just display the total cooling cost. However, I can't seem to get the resource amount when GetInfo gets called, I guess stuff isn't initialized or similar. 

Link to comment
Share on other sites

4 minutes ago, Nertea said:

Hmm well I have a part that specifies the amount of a resource it consumes based on the total amount of the resource. Currently the tooltip says something like 50Ec per 1000units, but it would be better to just display the total cooling cost. However, I can't seem to get the resource amount when GetInfo gets called, I guess stuff isn't initialized or similar. 

That's strange - the resources should all be there before PartModules are loaded.  Does this.part.Resources not contain the resource you're looking for?

Link to comment
Share on other sites

1 minute ago, blowfish said:

That's strange - the resources should all be there before PartModules are loaded.  Does this.part.Resources not contain the resource you're looking for?

Doesn't seem to. Here's the offending code:

public override string GetInfo()
{
  Debug.Log("GETINFO ");
  string msg = String.Format("Loss Rate: {0:F2}% {1}/hr", BoiloffRate, FuelName);
  if (CoolingCost > 0.0f)
  {
    double max = GetMaxResourceAmount(FuelName);
    msg += String.Format("\nCooling Cost: {0:F2} Ec/s", CoolingCost*(float)(max/1000.0));
  }
  return msg;
}

The error is thrown in GetMaxResourceAmount, a helper of the form

protected double GetMaxResourceAmount(string nm)
{
	PartResource res = this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(nm).id);
	return res.maxAmount;
}

 

Link to comment
Share on other sites

2 minutes ago, Nertea said:

The error is thrown in GetMaxResourceAmount, a helper of the form


protected double GetMaxResourceAmount(string nm)
{
	PartResource res = this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(nm).id);
	return res.maxAmount;
}

 

Is PartResourceLibrary.Instance.GetDefinition returning null or is part.Resources.Get returning null?

Link to comment
Share on other sites

6 minutes ago, Nertea said:

That I don't know. I'll have to test that when I get home... is there a workaround for the resource library showing null?

I'm just trying to figure out what's failing since as far as I know, this should work.  You should definitely be able to get a resource definition from the resource library at this stage.

Link to comment
Share on other sites

Hmm.  This might sound silly, but does the part actually have this resource from the start?  If it uses resource switching it probably won't be there.

If that was completely off the mark maybe try logging what resources are actually on the part?

Edited by blowfish
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...