Added GUINumberInputs to the extra cargo menu, minor additions to GUINumberInput
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -271,50 +271,20 @@ namespace Barotrauma.Networking
|
||||
|
||||
int cargoVal = 0;
|
||||
extraCargo.TryGetValue(pf.Name, out cargoVal);
|
||||
var countText = new GUITextBlock(
|
||||
new Rectangle(160, 0, 55, 25),
|
||||
cargoVal.ToString(),
|
||||
"",
|
||||
Alignment.Left, Alignment.Center, textBlock);
|
||||
var amountInput = new GUINumberInput(new Rectangle(160, 0, 50, 20), "", 0, 100, textBlock);
|
||||
amountInput.Value = cargoVal;
|
||||
|
||||
var incButton = new GUIButton(new Rectangle(200, 5, 15, 15), ">", "", textBlock);
|
||||
incButton.UserData = countText;
|
||||
incButton.OnClicked = (button, obj) =>
|
||||
amountInput.OnValueChanged += (numberInput, value) =>
|
||||
{
|
||||
int val;
|
||||
if (extraCargo.TryGetValue(pf.Name, out val))
|
||||
if (extraCargo.ContainsKey(pf.Name))
|
||||
{
|
||||
extraCargo[pf.Name]++; val = extraCargo[pf.Name];
|
||||
extraCargo[pf.Name] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
extraCargo.Add(pf.Name, 1); val = 1;
|
||||
extraCargo.Add(pf.Name, value);
|
||||
}
|
||||
((GUITextBlock)obj).Text = val.ToString();
|
||||
((GUITextBlock)obj).SetTextPos();
|
||||
return true;
|
||||
};
|
||||
|
||||
var decButton = new GUIButton(new Rectangle(160, 5, 15, 15), "<", "", textBlock);
|
||||
decButton.UserData = countText;
|
||||
decButton.OnClicked = (button, obj) =>
|
||||
{
|
||||
int val;
|
||||
if (extraCargo.TryGetValue(pf.Name, out val))
|
||||
{
|
||||
extraCargo[pf.Name]--;
|
||||
val = extraCargo[pf.Name];
|
||||
if (val <= 0)
|
||||
{
|
||||
extraCargo.Remove(pf.Name);
|
||||
val = 0;
|
||||
}
|
||||
((GUITextBlock)obj).Text = val.ToString();
|
||||
((GUITextBlock)obj).SetTextPos();
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user