Click or drag to resize

Message Class

A class to wrap a simple localizable UI string.
Inheritance Hierarchy

Namespace:  KSPDev.GUIUtils
Assembly:  KSPDev_Utils.2.5 (in KSPDev_Utils.2.5.dll) Version: 2.5 for KSP v1
Syntax
C#
public sealed class Message : LocalizableMessage
Request Example View Source

The Message type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleMessage
Constructs a localizable message.
Top
Methods
  NameDescription
Public methodCode exampleFormat
Returns the message string.
Top
Operators
Remarks
Messages of this type don't have placeholders and can be just casted to a string.
Examples
public class MessageDemo : PartModule {
  // The encouraged way of defining a message.
  static readonly Message msg1 = new Message(
      "#myLocalizationTag",
      defaultTemplate: "Sample text in English",
      description: "A string to present in the KSPDevUtils documentation example. It illustrates"
      + " how the class can be used to localize a message.",
      example: "Sample text in English");

  // A simple way when no extra details are provided.
  static readonly Message msg2 = "#myLocalizationTag";

  public override void OnAwake() {
    base.OnAwake();

    // This will load the localized string and print it into the log.
    HostedDebugLog.Info(this, msg1.Format());

    // The next example will only work if there is a localizable string defined. Otherwise, it will
    // print the tag.
    HostedDebugLog.Info(this, msg2.Format());

    // A simple message can be just casted to string to get the localized content.
    PrintString(msg1);
  }

  void PrintString(string str) {
    HostedDebugLog.Info(this, str);
  }
}
See Also

Reference