private async void nudBase_ValueChanged(object sender, EventArgs e) { int intValue = ((NumericUpDownEx)sender).ValueAsInt; if (intValue == _oldBase) { return; } if (!await CanBeMetatypeMax( Math.Max( nudKarma.DoThreadSafeFunc(x => x.ValueAsInt) + AttributeObject.FreeBase + AttributeObject.RawMinimum + AttributeObject.AttributeValueModifiers, AttributeObject.TotalMinimum) + intValue)) { await nudBase.DoThreadSafeAsync(x => { decimal newValue = Math.Max(x.Value - 1, 0); if (newValue > x.Maximum) { newValue = x.Maximum; } if (newValue < x.Minimum) { newValue = x.Minimum; } x.Value = newValue; }); return; } await this.DoThreadSafeAsync(x => x.ValueChanged?.Invoke(this, e)); _oldBase = intValue; }
private async void nudKarma_ValueChanged(object sender, EventArgs e) { int intValue = ((NumericUpDownEx)sender).ValueAsInt; if (intValue == _oldKarma) { return; } if (!await CanBeMetatypeMax( Math.Max( nudBase.DoThreadSafeFunc(x => x.ValueAsInt) + AttributeObject.FreeBase + AttributeObject.RawMinimum + AttributeObject.AttributeValueModifiers, AttributeObject.TotalMinimum) + intValue)) { // It's possible that the attribute maximum was reduced by an improvement, so confirm the appropriate value to bounce up/down to. if (_oldKarma > AttributeObject.KarmaMaximum) { _oldKarma = AttributeObject.KarmaMaximum - 1; } if (_oldKarma < 0) { await nudBase.DoThreadSafeAsync(x => { decimal newValue = Math.Max(x.Value - _oldKarma, 0); if (newValue > x.Maximum) { newValue = x.Maximum; } if (newValue < x.Minimum) { newValue = x.Minimum; } x.Value = newValue; }); _oldKarma = 0; } await nudKarma.DoThreadSafeAsync(x => x.Value = _oldKarma); return; } await this.DoThreadSafeAsync(x => x.ValueChanged?.Invoke(this, e)); _oldKarma = intValue; }
public void UpdateWidths(int intNameWidth, int intNudKarmaWidth, int intValueWidth, int intLimitsWidth) { tlpMain.DoThreadSafe(x => x.SuspendLayout()); try { if (intNameWidth >= 0) { lblName.DoThreadSafe(x => { if (x.MinimumSize.Width > intNameWidth) { x.MinimumSize = new Size(intNameWidth, x.MinimumSize.Height); } if (x.MaximumSize.Width != intNameWidth) { x.MaximumSize = new Size(intNameWidth, x.MinimumSize.Height); } if (x.MinimumSize.Width < intNameWidth) { x.MinimumSize = new Size(intNameWidth, x.MinimumSize.Height); } }); } if (intNudKarmaWidth >= 0 && nudBase?.DoThreadSafeFunc(x => x.Visible) == true) { nudKarma?.DoThreadSafe(x => { if (x.Visible) { x.Margin = new Padding( x.Margin.Right + Math.Max(intNudKarmaWidth - x.Width, 0), x.Margin.Top, x.Margin.Right, x.Margin.Bottom); } }); } if (intValueWidth >= 0) { lblValue.DoThreadSafe(x => { if (x.MinimumSize.Width > intValueWidth) { x.MinimumSize = new Size(intValueWidth, x.MinimumSize.Height); } if (x.MaximumSize.Width != intValueWidth) { x.MaximumSize = new Size(intValueWidth, x.MinimumSize.Height); } if (x.MinimumSize.Width < intValueWidth) { x.MinimumSize = new Size(intValueWidth, x.MinimumSize.Height); } }); } if (intLimitsWidth >= 0) { lblLimits.DoThreadSafe(x => { if (x.MinimumSize.Width > intLimitsWidth) { x.MinimumSize = new Size(intLimitsWidth, x.MinimumSize.Height); } if (x.MaximumSize.Width != intLimitsWidth) { x.MaximumSize = new Size(intLimitsWidth, x.MinimumSize.Height); } if (x.MinimumSize.Width < intLimitsWidth) { x.MinimumSize = new Size(intLimitsWidth, x.MinimumSize.Height); } }); } } finally { tlpMain.DoThreadSafe(x => x.ResumeLayout()); } }