Click or drag to resize

MessageLookupT Constructor

Constructs a lookup from the provided dictionary.

Namespace:  KSPDev.GUIUtils
Assembly:  KSPDev_Utils.2.0 (in KSPDev_Utils.2.0.dll) Version: 2.0 for KSP v1.8+
Syntax
C#
public MessageLookup(
	Dictionary<T, Message> initDict = null,
	Message defaultMessage = null
)
Request Example View Source

Parameters

initDict (Optional)
Type: System.Collections.GenericDictionaryT, Message
The dictionary to use as the lookup. If null when a new empty dictionary will be created for messages.
defaultMessage (Optional)
Type: KSPDev.GUIUtilsMessage
The message to return from the Lookup(T) method when no key found.
Remarks
It's encouraged to construct the dictionary from a statically defined messages instead of creating them in place. The LocalizationTool can only find the static messages.
Examples
public class MessageLookupDemo1 : PartModule {
  enum MyEnum {
    One,
    Two,
    Three
  }

  // Create the messages separately from the lookup to allow the LocalizationTool to pick them up.
  static readonly Message msg_1 = new Message("#msg1", defaultTemplate: "-ONE-");
  static readonly Message msg_2 = new Message("#msg2", defaultTemplate: "-TWO-");
  static readonly Message msg_3 = new Message("#msg3", defaultTemplate: "-THREE-");

  static readonly MessageLookup<MyEnum> msg = new MessageLookup<MyEnum>(
      new Dictionary<MyEnum, Message>() {
          {MyEnum.One, msg_1},
          {MyEnum.Two, msg_2},
          {MyEnum.Three, msg_3},
      });

  // Depending on the current language in the system, this method will present the values in
  // different languages.
  void Show() {
    Debug.Log(msg.Lookup(MyEnum.One));
    // Prints: "-ONE-"
    Debug.Log(msg.Lookup(MyEnum.Two));
    // Prints: "-TWO-"
    Debug.Log(msg.Lookup(MyEnum.Three));
    // Prints: "-THREE-"
  }
}
See Also