/// <summary> /// Initializes a new instance of the <see cref="EditorNPCChatConditionalCollectionItem"/> class. /// </summary> /// <param name="conditional">The conditional to use.</param> /// <exception cref="ArgumentNullException"><paramref name="conditional" /> is <c>null</c>.</exception> public EditorNPCChatConditionalCollectionItem(NPCChatConditionalBase conditional) { if (conditional == null) { throw new ArgumentNullException("conditional"); } _not = false; SetConditional(conditional); }
/// <summary> /// When overridden in the derived class, sets the values read from the Read method. /// </summary> /// <param name="conditional">The conditional.</param> /// <param name="not">The Not value.</param> /// <param name="parameters">The parameters.</param> protected override void SetReadValues(NPCChatConditionalBase conditional, bool not, NPCChatConditionalParameter[] parameters) { _conditional = conditional; _not = not; _parameters.Clear(); _parameters.AddRange(parameters); if (Changed != null) { Changed.Raise(this, EventArgs.Empty); } }
/// <summary> /// Sets the Conditional. /// </summary> /// <param name="conditional">The new <see cref="NPCChatConditionalBase"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="conditional" /> is <c>null</c>.</exception> public void SetConditional(NPCChatConditionalBase conditional) { if (conditional == null) { throw new ArgumentNullException("conditional"); } if (_conditional == conditional) { return; } // Set the new conditional _conditional = conditional; // Re-create all the parameters to the appropriate type for the new conditional var newParameters = new NPCChatConditionalParameter[Conditional.ParameterCount]; for (var i = 0; i < Conditional.ParameterCount; i++) { var neededType = Conditional.GetParameter(i); if (i < _parameters.Count && _parameters[i].ValueType == neededType) { // The type matches the old type, so just reuse it newParameters[i] = _parameters[i]; } else { // Different type or out of range, so make a new one newParameters[i] = NPCChatConditionalParameter.CreateParameter(neededType); } } // Set the new parameters _parameters.Clear(); _parameters.AddRange(newParameters); if (Changed != null) { Changed.Raise(this, EventArgs.Empty); } }