Added GUINumberInputs to the extra cargo menu, minor additions to GUINumberInput

This commit is contained in:
Joonas Rikkonen
2017-07-02 22:17:12 +03:00
parent 8ae2fb225c
commit 8e880b2ded
3 changed files with 20 additions and 41 deletions
@@ -6,6 +6,9 @@ namespace Barotrauma
{
class GUINumberInput : GUIComponent
{
public delegate void OnValueChangedHandler(GUINumberInput numberInput, int number);
public OnValueChangedHandler OnValueChanged;
private GUITextBox textBox;
private GUIButton plusButton, minusButton;
@@ -17,16 +20,22 @@ namespace Barotrauma
get { return value; }
set
{
if (value == this.value) return;
this.value = value;
if (MinValue != null)
{
this.value = Math.Max(this.value, (int)MinValue);
minusButton.Enabled = this.value > MinValue;
}
if (MaxValue != null)
{
this.value = Math.Min(this.value, (int)MaxValue);
plusButton.Enabled = this.value < MaxValue;
}
textBox.Text = this.value.ToString();
if (OnValueChanged != null) OnValueChanged(this, this.value);
}
}
@@ -49,14 +58,15 @@ namespace Barotrauma
textBox.OnTextChanged += TextChanged;
plusButton = new GUIButton(new Rectangle(0, 0, 15, rect.Height / 2), "+", Alignment.TopRight, style, this);
plusButton = new GUIButton(new Rectangle(0, 0, 15, rect.Height / 2), "+", null, Alignment.TopRight, Alignment.Center, style, this);
plusButton.OnClicked += ChangeValue;
minusButton = new GUIButton(new Rectangle(0, 0, 15, rect.Height / 2), "-", Alignment.BottomRight, style, this);
minusButton = new GUIButton(new Rectangle(0, 0, 15, rect.Height / 2), "-", null, Alignment.BottomRight, Alignment.Center, style, this);
minusButton.OnClicked += ChangeValue;
MinValue = minValue;
MaxValue = maxValue;
value = int.MaxValue;
Value = minValue != null ? (int)minValue : 0;
}
@@ -73,12 +73,11 @@ namespace Barotrauma
child.Rect = new Rectangle(child.Rect.X + value.X - rect.X, child.Rect.Y + value.Y - rect.Y, child.Rect.Width, child.Rect.Height);
}
rect = value;
if (value.Width != rect.Width || value.Height != rect.Height)
{
SetTextPos();
}
rect = value;
}
}