/// <summary> /// Reads the values for this NPCChatDialogItemBase from an IValueReader. /// </summary> /// <param name="reader">IValueReader to read the values from.</param> protected void Read(IValueReader reader) { var id = reader.ReadNPCChatDialogItemID("ID"); var title = reader.ReadString("Title"); var text = reader.ReadString("Text"); var isBranch = reader.ReadBool("IsBranch"); var responses = reader.ReadManyNodes("Responses", CreateResponse); NPCChatConditionalCollectionBase conditionals = null; if (isBranch) { var cReader = reader.ReadNode("Conditionals"); var hasConditionals = cReader.ReadBool("HasConditionals"); if (hasConditionals) { conditionals = CreateConditionalCollection(); if (conditionals != null) { conditionals.Read(cReader); } } } SetReadValues(id, title, text, isBranch, responses, conditionals); AssertBranchHasTwoResponses(); AssertNonBranchHasNoConditionals(); AssertResponsesHaveValidValues(); }
/// <summary> /// Clears the Conditionals. /// </summary> public void ClearConditionals() { _conditionals = new EditorNPCChatConditionalCollection(); if (Changed != null) { Changed.Raise(this, EventArgs.Empty); } }
/// <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; }
/// <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(); }
/// <summary> /// Sets the ConditionalCollection. /// </summary> /// <param name="value">The NPCChatConditionalCollectionBase to set the ConditionalCollection as. /// If null, an empty NPCChatConditionalCollectionBase will be used.</param> public void SetConditionalCollection(NPCChatConditionalCollectionBase value) { var asEditorCollection = value as EditorNPCChatConditionalCollection; if (asEditorCollection != null) { ConditionalCollection = asEditorCollection; return; } var newCollection = new EditorNPCChatConditionalCollection(value); ConditionalCollection = newCollection; }
/// <summary> /// Copies the values of this NPCChatConditionalCollectionBase to another NPCChatConditionalCollectionBase. /// </summary> /// <param name="dest">The NPCChatConditionalCollectionBase to copy the values into.</param> public void CopyValuesTo(NPCChatConditionalCollectionBase dest) { var stream = new BitStream(256); using (var writer = BinaryValueWriter.Create(stream)) { Write(writer); } stream.PositionBits = 0; var reader = BinaryValueReader.Create(stream); dest.Read(reader); }
/// <summary> /// Tries to set the EditorNPCChatDialogItem as a normal (non-branch) dialog. /// </summary> /// <param name="error">Contains the message for the error if there was one, or an empty string /// if there was no error.</param> /// <returns>True if the EditorNPCChatDialogItem was successfully set as a non-branch; otherwise false.</returns> public bool TrySetAsNonBranch(out string error) { if (!IsBranch) { error = "Already set as a non-branch dialog item."; return(false); } // Clear the conditionals _conditionals = new EditorNPCChatConditionalCollection(); _isBranch = false; error = string.Empty; return(true); }
/// <summary> /// Copies the values of this NPCChatConditionalCollectionBase to another NPCChatConditionalCollectionBase. /// </summary> /// <param name="dest">The NPCChatConditionalCollectionBase to copy the values into.</param> public void CopyValuesTo(NPCChatConditionalCollectionBase dest) { var stream = new BitStream(256); using (var writer = BinaryValueWriter.Create(stream)) { Write(writer); } stream.PositionBits = 0; var reader = BinaryValueReader.Create(stream); dest.Read(reader); }
/// <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(); }
/// <summary> /// Initializes a new instance of the <see cref="EditorNPCChatConditionalCollection"/> class. /// </summary> /// <param name="source">The source <see cref="NPCChatConditionalCollectionBase"/> to copy the values from. If null, /// no values are copied.</param> public EditorNPCChatConditionalCollection(NPCChatConditionalCollectionBase source) { if (source == null) return; var stream = new BitStream(256); using (var writer = BinaryValueWriter.Create(stream)) { source.Write(writer); } stream.PositionBits = 0; IValueReader reader = BinaryValueReader.Create(stream); Read(reader); }
/// <summary> /// Sets the Conditionals property. /// </summary> /// <param name="value">The value.</param> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <c>null</c>.</exception> public void SetConditionals(NPCChatConditionalCollectionBase value) { if (value == null) { throw new ArgumentNullException("value"); } if (_conditionals == value) { return; } _conditionals = value; if (Changed != null) { Changed.Raise(this, EventArgs.Empty); } }
/// <summary> /// Initializes a new instance of the <see cref="EditorNPCChatConditionalCollection"/> class. /// </summary> /// <param name="source">The source <see cref="NPCChatConditionalCollectionBase"/> to copy the values from. If null, /// no values are copied.</param> public EditorNPCChatConditionalCollection(NPCChatConditionalCollectionBase source) { if (source == null) { return; } var stream = new BitStream(256); using (var writer = BinaryValueWriter.Create(stream)) { source.Write(writer); } stream.PositionBits = 0; IValueReader reader = BinaryValueReader.Create(stream); Read(reader); }
/// <summary> /// Tries to set the EditorNPCChatDialogItem as a branch dialog. /// </summary> /// <param name="error">Contains the message for the error if there was one, or an empty string /// if there was no error.</param> /// <returns>True if the EditorNPCChatDialogItem was successfully set as a branch; otherwise false.</returns> public bool TrySetAsBranch(out string error) { if (IsBranch) { error = "Already set as a branch dialog item."; return(false); } if (ResponseList.Count > 2) { error = "Cannot change to a branch dialog item when there are more than 2 responses."; return(false); } // Add responses until we have exactly 2 var responsesNeeded = 2 - ResponseList.Count; for (var i = 0; i < responsesNeeded; i++) { AddResponse(new EditorNPCChatResponse("New response")); } Debug.Assert(ResponseList.Count == 2); // Set up the responses _responses[0].SetText("False"); _responses[0].ClearConditionals(); _responses[1].SetText("True"); _responses[1].ClearConditionals(); if (_conditionals == null) { _conditionals = new EditorNPCChatConditionalCollection(); } _isBranch = true; error = string.Empty; return(true); }
/// <summary> /// Reads the values for this NPCChatResponseBase from an IValueReader. /// </summary> /// <param name="reader">IValueReader to read the values from.</param> protected void Read(IValueReader reader) { var value = reader.ReadByte("Value"); var page = reader.ReadNPCChatDialogItemID("Page"); var text = reader.ReadString("Text"); var actionNames = reader.ReadMany("Actions", ((r, name) => r.ReadString(name))); var actions = GetActionsFromNames(actionNames); var cReader = reader.ReadNode("Conditionals"); var hasConditionals = cReader.ReadBool("HasConditionals"); NPCChatConditionalCollectionBase conditionals = null; if (hasConditionals) { conditionals = CreateConditionalCollection(); if (conditionals != null) { conditionals.Read(cReader); } } SetReadValues(value, page, text, conditionals, actions); }
/// <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(); }
/// <summary> /// Tries to set the EditorNPCChatDialogItem as a branch dialog. /// </summary> /// <param name="error">Contains the message for the error if there was one, or an empty string /// if there was no error.</param> /// <returns>True if the EditorNPCChatDialogItem was successfully set as a branch; otherwise false.</returns> public bool TrySetAsBranch(out string error) { if (IsBranch) { error = "Already set as a branch dialog item."; return false; } if (ResponseList.Count > 2) { error = "Cannot change to a branch dialog item when there are more than 2 responses."; return false; } // Add responses until we have exactly 2 var responsesNeeded = 2 - ResponseList.Count; for (var i = 0; i < responsesNeeded; i++) { AddResponse(new EditorNPCChatResponse("New response")); } Debug.Assert(ResponseList.Count == 2); // Set up the responses _responses[0].SetText("False"); _responses[0].ClearConditionals(); _responses[1].SetText("True"); _responses[1].ClearConditionals(); if (_conditionals == null) _conditionals = new EditorNPCChatConditionalCollection(); _isBranch = true; error = string.Empty; return true; }
/// <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; }
/// <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);
/// <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) && _text == default(string), "Values were already set?"); _value = value; _page = page; _text = text; }
/// <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(); }
/// <summary> /// Sets the Conditionals property. /// </summary> /// <param name="value">The value.</param> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <c>null</c>.</exception> public void SetConditionals(NPCChatConditionalCollectionBase value) { if (value == null) throw new ArgumentNullException("value"); if (_conditionals == value) return; _conditionals = value; if (Changed != null) Changed.Raise(this, EventArgs.Empty); }
/// <summary> /// Clears the Conditionals. /// </summary> public void ClearConditionals() { _conditionals = new EditorNPCChatConditionalCollection(); if (Changed != null) Changed.Raise(this, EventArgs.Empty); }
/// <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);
/// <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);
/// <summary> /// Tries to set the EditorNPCChatDialogItem as a normal (non-branch) dialog. /// </summary> /// <param name="error">Contains the message for the error if there was one, or an empty string /// if there was no error.</param> /// <returns>True if the EditorNPCChatDialogItem was successfully set as a non-branch; otherwise false.</returns> public bool TrySetAsNonBranch(out string error) { if (!IsBranch) { error = "Already set as a non-branch dialog item."; return false; } // Clear the conditionals _conditionals = new EditorNPCChatConditionalCollection(); _isBranch = false; error = string.Empty; return true; }
/// <summary> /// Sets the ConditionalCollection. /// </summary> /// <param name="value">The NPCChatConditionalCollectionBase to set the ConditionalCollection as. /// If null, an empty NPCChatConditionalCollectionBase will be used.</param> public void SetConditionalCollection(NPCChatConditionalCollectionBase value) { var asEditorCollection = value as EditorNPCChatConditionalCollection; if (asEditorCollection != null) { ConditionalCollection = asEditorCollection; return; } var newCollection = new EditorNPCChatConditionalCollection(value); ConditionalCollection = newCollection; }
/// <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);