private void OnAttributeChanged(object sender, AttributeChangedEventArgs e) { AttributePanel pnl = sender as AttributePanel; // The attribute panels sends the requested newValue in the event args. Need to validate that the // user has the points left to be able to make this change. int pointCost = this.GetPointCost(e.OldValue, e.NewValue); if ((this.AttributePoints + pointCost) < 0) { // Cancel the request. e.Cancel = true; e.Message = "Not enough Attribute Points to change this Attribute."; } else if ((this.AttributePoints + pointCost) > MaxAttributePoints) { // Cancel the request. e.Cancel = true; e.Message = "Not enough Attribute Points to increase this Attribute."; } else { // Accept the request, increment or decrement the points. this.AttributePoints += pointCost; } lblPoints.Text = this.AttributePoints.ToString(); if (!e.Cancel) { // Bubble up the event. this.AttributeChanged(pnl, new AttributeChangedEventArgs(e.Name, e.OldValue, e.NewValue + pnl.AttributeMinimum)); } }
private void RaiseAttributeChangedEvent(int newValue) { AttributeChangedEventArgs args = new AttributeChangedEventArgs(this.StatName, this.AttributeValue - this.AttributeMinimum, newValue); args.MinValue = this.AttributeMinimum; this.AttributeChanged(this, args); if (!args.Cancel) { this.AttributeValue = newValue + this.AttributeMinimum; // Set the block according to the value of the attribute. this.RefreshView(); } else { this.Error(this, new NotificationEventArgs(args.Message)); } }