Jump to content

Problem with GetModuleTitle


Recommended Posts

I'm having a bit of difficulty here and I need some more eyes.  My ElectricLights mod extends ModuleAnimateGeneric and ModuleColorChanger to consume electricity for the cockpits and command pods respectively.  I have a set of code which I have been localizing using the stock dictionary.

        public override string GetInfo()
        {
            StringBuilder info = new StringBuilder();
            info.AppendLine("<color=#FF8C00><b><<1>></b></color>").Replace("<<1>>", Localizer.GetStringByTag("#autoLOC_244332"));
            info.Append(Localizer.GetStringByTag("#autoLOC_244201"));
            info.Replace("<<1>>", Localizer.GetStringByTag("#autoLOC_501004"));
            info.Replace("<<2>>", (resourceRate * 60 * resourceAmount).ToString());
            return info.ToString();
        }

        public string GetModuleTitle()
        {
            return "#autoLOC_6003003";
        }

This code is exactly the same in both my extension modules.  The module that inherits ModuleAnimateGeneric produces the following:

x3uJKqM.png

So that is beautiful, it appears to be translating tags correctly and all is well.  Then I look at the extension of ModuleColorChanger:

sgQqO3W.png

Now, why does that say "Color Changer" instead of "Light"? 

I went back to my previous version DLL (with no localization, just static text) and it turns out it's broken there too.  This was working in 1.2 with static text, but now in 1.3 it doesn't seem to want to return the title from my implementation regardless.  Before you answer, no there is nothing to override in either module.

Link to comment
Share on other sites

Ok, so finally after hours of searching it would appear that Squad added a redundant method in PartModule and some modules are using one and some modules are using the other.  Why would you do this Squad?

        public string GetModuleTitle()
        {
            return "#autoLOC_6003003";
        }

        public override string GetModuleDisplayName()
        {
            return GetModuleTitle();
        }

That was the solution.

Edited by Alshain
Link to comment
Share on other sites

My recollection of how this works is

  • GetModuleTitle is the English title which is the "name" for a bunch of stuff in the code (like filters) - it fills the moduleInfo.Name value and is always in english - we didnt change that one as its the old name (I say name, but its called title for some reason :P
  • GetModuleDisplayName is the localized string thats printed in the UI
  • IModuleInfo is not changed

If the displayname is empty then it plugs in the "title" as the displayname

In the case of the ColorChanger the default displayName is "Color Changer" as your seeing there, 

A better way to do that code might be

public string GetModuleTitle() 
{
	return "Light";	
} 
public override string GetModuleDisplayName()
{
	return Localizer.Format("#autoLOC_6003003");	
}

 

Link to comment
Share on other sites

@TriggerAu

If that is how it is, I have to say, that is kinda dumb. IModuleInfo provides other display information (as seen in the first code snipit, GetInfo is in IModuleInfo)  There is also a callback in IModuleInfo to let you know when the info panel is drawn on screen.  So what you are saying is IModuleInfo contains and inconsistent combination of unique identifier and display information while you have to go to PartModule to find the rest of the display information.  On top of that, not all modules need display information, but they would need an identifier, so why would you put that identifier in an interface that may not be implemented and display information in the base class?

Sorry Trigger, but your explanation makes no sense.  Either that or someone over there at Squad is horrifically bad at organizing their classes.

EDIT: Also, why would you filter by an English name in a localized game?  Wouldn't you localize the filter?

Edited by Alshain
Link to comment
Share on other sites

Sorry I cant explain it sufficiently, but I can't share the code with you as to why its done this way which would probably clarify it. The way its done is the least impactful method we had available with the existing codebase.

If the game was built with Localization from the ground up then some of this would be different I can guarantee it, but in places where code uses names we stuck with English and have a display version for the UI - same as for actual filtering - its done by the name and displays a localized version.

I think thats the best I can do on the explanation, but hopefully the code example and the updated info in the modders notes means you can use it

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