Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EditorNPCChatDialogItem"/> class.
        /// </summary>
        /// <param name="id">The ID.</param>
        /// <param name="text">The text.</param>
        /// <param name="title">The title.</param>
        public EditorNPCChatDialogItem(NPCChatDialogItemID id, string text, string title)
        {
            SetText(text);
            SetTitle(title);

            _id = id;
        }
Beispiel #2
0
        /// <summary>
        /// Tries to parse the <see cref="NPCChatDialogItemID"/> 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="NPCChatDialogItemID"/>.</param>
        /// <returns>True if the parsing was successfully; otherwise false.</returns>
        public static bool TryParse(this Parser parser, string value, out NPCChatDialogItemID outValue)
        {
            ushort tmp;
            var    ret = parser.TryParse(value, out tmp);

            outValue = new NPCChatDialogItemID(tmp);
            return(ret);
        }
Beispiel #3
0
        /// <summary>
        /// When overridden in the derived class, sets the values read from the Read method.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="page">The page.</param>
        /// <param name="text">The text.</param>
        /// <param name="conditionals">The conditionals.</param>
        /// <param name="actions">The actions.</param>
        protected override void SetReadValues(byte value, NPCChatDialogItemID page, string text,
                                              NPCChatConditionalCollectionBase conditionals, NPCChatResponseActionBase[] actions)
        {
            Debug.Assert(_value == default(byte) && _page == default(ushort), "Values were already set?");

            _value        = value;
            _page         = page;
            _conditionals = conditionals;
            _actions      = actions;
        }
        /// <summary>
        /// When overridden in the derived class, sets the values read from the Read method.
        /// </summary>
        /// <param name="page">The index.</param>
        /// <param name="title">The title.</param>
        /// <param name="text">The text.</param>
        /// <param name="isBranch">The IsBranch value.</param>
        /// <param name="responses">The responses.</param>
        /// <param name="conditionals">The conditionals.</param>
        protected override void SetReadValues(NPCChatDialogItemID page, string title, string text, bool isBranch,
                                              IEnumerable <NPCChatResponseBase> responses,
                                              NPCChatConditionalCollectionBase conditionals)
        {
            Debug.Assert(_id == default(NPCChatDialogItemID) && _responses == default(IEnumerable <NPCChatResponseBase>),
                         "Values were already set?");

            _id           = page;
            _isBranch     = isBranch;
            _responses    = responses.ToArray();
            _conditionals = conditionals;
        }
Beispiel #5
0
        /// <summary>
        /// When overridden in the derived class, sets the values read from the Read method.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="page">The page.</param>
        /// <param name="text">The text.</param>
        /// <param name="conditionals">The conditionals.</param>
        /// <param name="actions">The actions.</param>
        protected override void SetReadValues(byte value, NPCChatDialogItemID page, string text,
                                              NPCChatConditionalCollectionBase conditionals, NPCChatResponseActionBase[] actions)
        {
            _value = value;
            _page  = page;
            SetText(text);

            _actions.Clear();
            _actions.AddRange(actions);

            var c = conditionals as EditorNPCChatConditionalCollection;

            _conditionals = c ?? new EditorNPCChatConditionalCollection();
        }
Beispiel #6
0
        /// <summary>
        /// Sets the Page property.
        /// </summary>
        /// <param name="page">The new page.</param>
        public void SetPage(NPCChatDialogItemID page)
        {
            if (_page == page)
            {
                return;
            }

            _page = page;

            if (Changed != null)
            {
                Changed.Raise(this, EventArgs.Empty);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Gets the NPCChatDialogViewNode for the given NPCChatDialogItemBase. Nodes that redirect to the
        /// given NPCChatDialogItemBase are not included.
        /// </summary>
        /// <param name="dialogItemID">The index of the NPCChatDialogItemBase to find the NPCChatDialogViewNode for.</param>
        /// <returns>The NPCChatDialogViewNode for the given <paramref name="dialogItemID"/>, or null if
        /// no NPCChatDialogViewNode was found that handles the given <paramref name="dialogItemID"/> or
        /// if the <paramref name="dialogItemID"/> was for an invalid NPCChatDialogItemBase.</returns>
        public NPCChatDialogViewNode GetNodeForDialogItem(NPCChatDialogItemID dialogItemID)
        {
            if (NPCChatDialog == null)
            {
                return(null);
            }

            var dialogItem = NPCChatDialog.GetDialogItem(dialogItemID);

            if (dialogItem == null)
            {
                return(null);
            }

            return(GetNodeForDialogItem(dialogItem));
        }
Beispiel #8
0
        /// <summary>
        /// When overridden in the derived class, sets the values read from the Read method.
        /// </summary>
        /// <param name="page">The ID.</param>
        /// <param name="title">The title.</param>
        /// <param name="text">The text.</param>
        /// <param name="isBranch">The IsBranch value.</param>
        /// <param name="responses">The responses.</param>
        /// <param name="conditionals">The conditionals.</param>
        protected override void SetReadValues(NPCChatDialogItemID page, string title, string text, bool isBranch,
                                              IEnumerable <NPCChatResponseBase> responses,
                                              NPCChatConditionalCollectionBase conditionals)
        {
            _id       = page;
            _isBranch = isBranch;
            SetTitle(title);
            SetText(text);

            _responses.Clear();
            _responses.AddRange(responses.Cast <EditorNPCChatResponse>().OrderBy(x => x.Value));
            EnsureResponseValuesAreValid();

            var c = conditionals as EditorNPCChatConditionalCollection;

            _conditionals = c ?? new EditorNPCChatConditionalCollection();
        }
Beispiel #9
0
        /// <summary>
        /// Tries to get the value in the <paramref name="dict"/> entry at the given <paramref name="key"/> as a
        /// <see cref="NPCChatDialogItemID"/>.
        /// </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 NPCChatDialogItemID AsNPCChatDialogItemID <T>(this IDictionary <T, string> dict, T key,
                                                                    NPCChatDialogItemID defaultValue)
        {
            string value;

            if (!dict.TryGetValue(key, out value))
            {
                return(defaultValue);
            }

            NPCChatDialogItemID parsed;

            if (!Parser.Invariant.TryParse(value, out parsed))
            {
                return(defaultValue);
            }

            return(parsed);
        }
Beispiel #10
0
        /// <summary>
        /// When overridden in the derived class, gets the NPCChatDialogItemBase for the given page number.
        /// </summary>
        /// <param name="chatDialogItemID">The page number of the NPCChatDialogItemBase to get.</param>
        /// <returns>The NPCChatDialogItemBase for the given <paramref name="chatDialogItemID"/>, or null if
        /// no valid NPCChatDialogItemBase existed for the given <paramref name="chatDialogItemID"/> or if
        /// the <paramref name="chatDialogItemID"/> is equal to
        /// <see cref="NPCChatResponseBase.EndConversationPage"/>.</returns>
        public override NPCChatDialogItemBase GetDialogItem(NPCChatDialogItemID chatDialogItemID)
        {
            if (chatDialogItemID == NPCChatResponseBase.EndConversationPage)
            {
                return(null);
            }

            if (chatDialogItemID < 0 || chatDialogItemID >= _items.Length)
            {
                const string errmsg = "Invalid NPCChatDialogItemBase ID `{0}`.";
                Debug.Fail(string.Format(errmsg, chatDialogItemID));
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, chatDialogItemID);
                }
                return(null);
            }

            return(_items[(int)chatDialogItemID]);
        }
Beispiel #11
0
 /// <summary>
 /// Reads the <see cref="NPCChatDialogItemID"/> from an IValueReader.
 /// </summary>
 /// <param name="valueReader"><see cref="IValueReader"/> to read the <see cref="NPCChatDialogItemID"/> from.</param>
 /// <param name="name">The unique name of the value to read.</param>
 /// <returns>The <see cref="NPCChatDialogItemID"/> read from the IValueReader.</returns>
 public static NPCChatDialogItemID ReadNPCChatDialogItemID(this IValueReader valueReader, string name)
 {
     return(NPCChatDialogItemID.Read(valueReader, name));
 }
Beispiel #12
0
 /// <summary>
 /// Reads the <see cref="NPCChatDialogItemID"/> from a <see cref="BitStream"/>.
 /// </summary>
 /// <param name="bitStream"><see cref="BitStream"/> to read the <see cref="NPCChatDialogItemID"/> from.</param>
 /// <returns>The <see cref="NPCChatDialogItemID"/> read from the <see cref="BitStream"/>.</returns>
 public static NPCChatDialogItemID ReadNPCChatDialogItemID(this BitStream bitStream)
 {
     return(NPCChatDialogItemID.Read(bitStream));
 }
Beispiel #13
0
 /// <summary>
 /// Reads the <see cref="NPCChatDialogItemID"/> from an <see cref="IDataRecord"/>.
 /// </summary>
 /// <param name="r"><see cref="IDataRecord"/> to read the <see cref="NPCChatDialogItemID"/> from.</param>
 /// <param name="name">The name of the field to read the value from.</param>
 /// <returns>The <see cref="NPCChatDialogItemID"/> read from the <see cref="IDataRecord"/>.</returns>
 public static NPCChatDialogItemID GetNPCChatDialogItemID(this IDataRecord r, string name)
 {
     return(NPCChatDialogItemID.Read(r, name));
 }
Beispiel #14
0
 /// <summary>
 /// Reads the <see cref="NPCChatDialogItemID"/> from an <see cref="IDataRecord"/>.
 /// </summary>
 /// <param name="r"><see cref="IDataRecord"/> to read the <see cref="NPCChatDialogItemID"/> from.</param>
 /// <param name="i">The field index to read.</param>
 /// <returns>The <see cref="NPCChatDialogItemID"/> read from the <see cref="IDataRecord"/>.</returns>
 public static NPCChatDialogItemID GetNPCChatDialogItemID(this IDataRecord r, int i)
 {
     return(NPCChatDialogItemID.Read(r, i));
 }
Beispiel #15
0
 /// <summary>
 /// Writes a <see cref="NPCChatDialogItemID"/> 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="NPCChatDialogItemID"/> that will be used to distinguish it
 /// from other values when reading.</param>
 /// <param name="value"><see cref="NPCChatDialogItemID"/> to write.</param>
 public static void Write(this IValueWriter valueWriter, string name, NPCChatDialogItemID value)
 {
     value.Write(valueWriter, name);
 }
Beispiel #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EditorNPCChatDialogItem"/> class.
 /// </summary>
 /// <param name="id">The ID.</param>
 /// <param name="text">The text.</param>
 public EditorNPCChatDialogItem(NPCChatDialogItemID id, string text) : this(id, text, string.Empty)
 {
 }
Beispiel #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EditorNPCChatResponse"/> class.
 /// </summary>
 /// <param name="page">The page.</param>
 /// <param name="text">The text.</param>
 public EditorNPCChatResponse(NPCChatDialogItemID page, string text)
 {
     _page = page;
     _text = text;
 }
Beispiel #18
0
 /// <summary>
 /// When overridden in the derived class, sets the values read from the Read method.
 /// </summary>
 /// <param name="page">The index.</param>
 /// <param name="title">The title.</param>
 /// <param name="text">The text.</param>
 /// <param name="isBranch">The IsBranch value.</param>
 /// <param name="conditionals">The conditionals.</param>
 /// <param name="responses">The responses.</param>
 protected abstract void SetReadValues(NPCChatDialogItemID page, string title, string text, bool isBranch,
                                       IEnumerable <NPCChatResponseBase> responses,
                                       NPCChatConditionalCollectionBase conditionals);
Beispiel #19
0
 /// <summary>
 /// Writes a <see cref="NPCChatDialogItemID"/> to a <see cref="BitStream"/>.
 /// </summary>
 /// <param name="bitStream"><see cref="BitStream"/> to write to.</param>
 /// <param name="value"><see cref="NPCChatDialogItemID"/> to write.</param>
 public static void Write(this BitStream bitStream, NPCChatDialogItemID value)
 {
     value.Write(bitStream);
 }
Beispiel #20
0
 /// <summary>
 /// When overridden in the derived class, gets the NPCChatDialogItemBase for the given page number.
 /// </summary>
 /// <param name="chatDialogItemID">The page number of the NPCChatDialogItemBase to get.</param>
 /// <returns>The NPCChatDialogItemBase for the given <paramref name="chatDialogItemID"/>, or null if
 /// no valid NPCChatDialogItemBase existed for the given <paramref name="chatDialogItemID"/> or if
 /// the <paramref name="chatDialogItemID"/> is equal to
 /// <see cref="NPCChatResponseBase.EndConversationPage"/>.</returns>
 public override NPCChatDialogItemBase GetDialogItem(NPCChatDialogItemID chatDialogItemID)
 {
     return(GetDialogItemCasted(chatDialogItemID));
 }
 /// <summary>
 /// When overridden in the derived class, gets the <see cref="NPCChatDialogItemBase"/> for the given page number.
 /// </summary>
 /// <param name="chatDialogItemID">The page number of the <see cref="NPCChatDialogItemBase"/> to get.</param>
 /// <returns>
 /// The <see cref="NPCChatDialogItemBase"/> for the given <paramref name="chatDialogItemID"/>, or null if
 /// no valid <see cref="NPCChatDialogItemBase"/> existed for the given <paramref name="chatDialogItemID"/> or if
 /// the <paramref name="chatDialogItemID"/> is equal to
 /// <see cref="NPCChatResponseBase.EndConversationPage"/>.
 /// </returns>
 public abstract NPCChatDialogItemBase GetDialogItem(NPCChatDialogItemID chatDialogItemID);
 /// <summary>
 /// When overridden in the derived class, sets the values read from the Read method.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="page">The page.</param>
 /// <param name="text">The text.</param>
 /// <param name="conditionals">The conditionals.</param>
 /// <param name="actions">The actions.</param>
 protected abstract void SetReadValues(byte value, NPCChatDialogItemID page, string text,
                                       NPCChatConditionalCollectionBase conditionals, NPCChatResponseActionBase[] actions);