/// <summary> /// Gets the <see cref="NPCChatDialogBase"/> at the specified index. /// </summary> /// <param name="id">Index of the <see cref="NPCChatDialogBase"/>.</param> /// <returns>The <see cref="NPCChatDialogBase"/> at the specified index, or null if invalid.</returns> /// <exception cref="MethodAccessException">Tried to set when <see cref="IsReadonly"/> was true.</exception> public NPCChatDialogBase this[NPCChatDialogID id] { get { // Check for a valid index if (!_npcChatDialogs.CanGet((int)id)) { const string errmsg = "Invalid NPC chat dialog index `{0}`."; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, id); } Debug.Fail(string.Format(errmsg, id)); return(null); } return(_npcChatDialogs[(int)id]); } set { if (IsReadonly) { throw CreateReadonlyException(); } _npcChatDialogs[(int)id] = value; } }
/// <summary> /// When overridden in the derived class, sets the values read from the Read method. /// </summary> /// <param name="id">The ID.</param> /// <param name="title">The title.</param> /// <param name="items">The dialog items.</param> protected override void SetReadValues(NPCChatDialogID id, string title, IEnumerable <NPCChatDialogItemBase> items) { Debug.Assert(_id == default(NPCChatDialogID) && _items == default(IEnumerable <NPCChatDialogItemBase>), "Values were already set?"); _id = id; _items = items.ToArray(); }
/// <summary> /// Tries to parse the <see cref="NPCChatDialogID"/> from a string. /// </summary> /// <param name="parser">The <see cref="Parser"/> to use.</param> /// <param name="value">The string to parse.</param> /// <param name="outValue">If this method returns true, contains the parsed <see cref="NPCChatDialogID"/>.</param> /// <returns>True if the parsing was successfully; otherwise false.</returns> public static bool TryParse(this Parser parser, string value, out NPCChatDialogID outValue) { ushort tmp; var ret = parser.TryParse(value, out tmp); outValue = new NPCChatDialogID(tmp); return(ret); }
/// <summary> /// Gets if a chat dialog exists at the given ID. /// </summary> /// <param name="id">The ID to check if contains a dialog.</param> /// <returns>True if a dialog exists at the given <paramref name="id"/>; otherwise false.</returns> public bool DialogExists(NPCChatDialogID id) { if (!_npcChatDialogs.CanGet((int)id)) { return(false); } return(_npcChatDialogs[(int)id] != null); }
/// <summary> /// When overridden in the derived class, sets the values read from the Read method. /// </summary> /// <param name="id">The ID.</param> /// <param name="title">The title.</param> /// <param name="items">The dialog items.</param> protected override void SetReadValues(NPCChatDialogID id, string title, IEnumerable <NPCChatDialogItemBase> items) { _id = id; _title = title; // Clear the array for (var i = 0; i < _items.Length; i++) { _items[i] = null; } // Set the new items foreach (var item in items) { Add((EditorNPCChatDialogItem)item); } }
/// <summary> /// Gets the <see cref="EditorNPCChatDialog"/> at the specified <paramref name="id"/>. /// </summary> /// <param name="id">The ID of the <see cref="EditorNPCChatDialog"/> to get.</param> /// <returns>The <see cref="EditorNPCChatDialog"/> at the specified <paramref name="id"/>.</returns> public static EditorNPCChatDialog GetDialog(NPCChatDialogID id) { if (!_instance.DialogExists(id)) { _instance.Reorganize(); if (!_instance.DialogExists(id)) { return(null); } } var ret = _instance[id]; // If we grabbed the wrong one, or nothing, try reorganizing if (ret == null || ret.ID != id) { _instance.Reorganize(); ret = _instance[id]; } // Return whatever we found, since its not like we can do anything else even if it is invalid return((EditorNPCChatDialog)ret); }
/// <summary> /// Writes a <see cref="NPCChatDialogID"/> to a <see cref="IValueWriter"/>. /// </summary> /// <param name="valueWriter"><see cref="IValueWriter"/> to write to.</param> /// <param name="name">Unique name of the <see cref="NPCChatDialogID"/> that will be used to distinguish it /// from other values when reading.</param> /// <param name="value"><see cref="NPCChatDialogID"/> to write.</param> public static void Write(this IValueWriter valueWriter, string name, NPCChatDialogID value) { value.Write(valueWriter, name); }
/// <summary> /// Writes a <see cref="NPCChatDialogID"/> to a <see cref="BitStream"/>. /// </summary> /// <param name="bitStream"><see cref="BitStream"/> to write to.</param> /// <param name="value"><see cref="NPCChatDialogID"/> to write.</param> public static void Write(this BitStream bitStream, NPCChatDialogID value) { value.Write(bitStream); }
/// <summary> /// Reads the <see cref="NPCChatDialogID"/> from an IValueReader. /// </summary> /// <param name="valueReader"><see cref="IValueReader"/> to read the <see cref="NPCChatDialogID"/> from.</param> /// <param name="name">The unique name of the value to read.</param> /// <returns>The <see cref="NPCChatDialogID"/> read from the IValueReader.</returns> public static NPCChatDialogID ReadNPCChatDialogID(this IValueReader valueReader, string name) { return(NPCChatDialogID.Read(valueReader, name)); }
/// <summary> /// Reads the <see cref="NPCChatDialogID"/> from a <see cref="BitStream"/>. /// </summary> /// <param name="bitStream"><see cref="BitStream"/> to read the <see cref="NPCChatDialogID"/> from.</param> /// <returns>The <see cref="NPCChatDialogID"/> read from the <see cref="BitStream"/>.</returns> public static NPCChatDialogID ReadNPCChatDialogID(this BitStream bitStream) { return(NPCChatDialogID.Read(bitStream)); }
/// <summary> /// Reads the <see cref="NPCChatDialogID"/> from an <see cref="IDataRecord"/>. /// </summary> /// <param name="r"><see cref="IDataRecord"/> to read the <see cref="NPCChatDialogID"/> from.</param> /// <param name="name">The name of the field to read the value from.</param> /// <returns>The <see cref="NPCChatDialogID"/> read from the <see cref="IDataRecord"/>.</returns> public static NPCChatDialogID GetNPCChatDialogID(this IDataRecord r, string name) { return(NPCChatDialogID.Read(r, name)); }
/// <summary> /// Reads the <see cref="NPCChatDialogID"/> from an <see cref="IDataRecord"/>. /// </summary> /// <param name="r"><see cref="IDataRecord"/> to read the <see cref="NPCChatDialogID"/> from.</param> /// <param name="i">The field index to read.</param> /// <returns>The <see cref="NPCChatDialogID"/> read from the <see cref="IDataRecord"/>.</returns> public static NPCChatDialogID GetNPCChatDialogID(this IDataRecord r, int i) { return(NPCChatDialogID.Read(r, i)); }
/// <summary> /// Tries to get the value in the <paramref name="dict"/> entry at the given <paramref name="key"/> as a /// <see cref="NPCChatDialogID"/>. /// </summary> /// <typeparam name="T">The key Type.</typeparam> /// <param name="dict">The <see cref="IDictionary{TKey, TValue}"/>.</param> /// <param name="key">The key for the value to get.</param> /// <param name="defaultValue">The value to use if the value at the <paramref name="key"/> could not be parsed.</param> /// <returns>The value at the given <paramref name="key"/> parsed as an int, or the /// <paramref name="defaultValue"/> if the <paramref name="key"/> did not exist in the <paramref name="dict"/> /// or the value at the given <paramref name="key"/> could not be parsed.</returns> public static NPCChatDialogID AsNPCChatDialogID <T>(this IDictionary <T, string> dict, T key, NPCChatDialogID defaultValue) { string value; if (!dict.TryGetValue(key, out value)) { return(defaultValue); } NPCChatDialogID parsed; if (!Parser.Invariant.TryParse(value, out parsed)) { return(defaultValue); } return(parsed); }
/// <summary> /// Sets the <see cref="ID"/>. /// </summary> /// <param name="value">The new value.</param> public void SetID(NPCChatDialogID value) { _id = value; }
/// <summary> /// When overridden in the derived class, sets the values read from the Read method. /// </summary> /// <param name="id">The ID.</param> /// <param name="title">The title.</param> /// <param name="items">The dialog items.</param> protected abstract void SetReadValues(NPCChatDialogID id, string title, IEnumerable <NPCChatDialogItemBase> items);