1 using Microsoft.Xna.Framework;
3 using System.Globalization;
43 get {
return _plusMinusButtonVisibility; }
46 if (_plusMinusButtonVisibility != value)
48 _plusMinusButtonVisibility = value;
49 UpdatePlusMinusButtonVisibility();
54 private void UpdatePlusMinusButtonVisibility()
60 HidePlusMinusButtons();
65 ShowPlusMinusButtons();
75 ShowPlusMinusButtons();
79 HidePlusMinusButtons();
91 get {
return inputType; }
94 if (inputType == value) {
return; }
96 UpdatePlusMinusButtonVisibility();
100 private float? minValueFloat, maxValueFloat;
103 get {
return minValueFloat; }
106 minValueFloat = value;
108 UpdatePlusMinusButtonVisibility();
113 get {
return maxValueFloat; }
116 maxValueFloat = value;
118 UpdatePlusMinusButtonVisibility();
122 private float floatValue;
131 if (Math.Abs(value - floatValue) < 0.0001f && MathUtils.NearlyEqual(value, floatValue)) {
return; }
134 float newValue = floatValue;
137 floatValue = newValue;
142 private int decimalsToDisplay = 1;
145 get {
return decimalsToDisplay; }
148 decimalsToDisplay = value;
153 private int? minValueInt, maxValueInt;
156 get {
return minValueInt; }
165 get {
return maxValueInt; }
173 private int intValue;
182 if (value == intValue) {
return; }
244 private float pressedTimer;
245 private readonly
float pressedDelay = 0.5f;
246 private bool IsPressedTimerRunning {
get {
return pressedTimer > 0; } }
252 Alignment textAlignment = Alignment.Center,
253 float? relativeButtonAreaWidth =
null,
259 float _relativeButtonAreaWidth = relativeButtonAreaWidth ?? MathHelper.Clamp(
Rect.Height / (
float)
Rect.Width, 0.1f, 0.25f);
295 if (customPlusMinusButtons.HasValue)
297 PlusButton = customPlusMinusButtons.Value.PlusButton;
298 MinusButton = customPlusMinusButtons.Value.MinusButton;
305 GUIStyle.Apply(
PlusButton,
"PlusButton",
this);
315 pressedTimer = pressedDelay;
325 if (!IsPressedTimerRunning)
334 pressedTimer = pressedDelay;
344 if (!IsPressedTimerRunning)
392 private void HidePlusMinusButtons()
400 private void ShowPlusMinusButtons()
408 private void ReduceValue()
415 else if (maxValueFloat.HasValue && minValueFloat.HasValue)
422 private void IncreaseValue()
441 private float Round()
443 if (!maxValueFloat.HasValue || !minValueFloat.HasValue) {
return 0; }
444 float onePercent = MathHelper.Lerp(minValueFloat.Value, maxValueFloat.Value, 0.01f);
445 float diff = maxValueFloat.Value - minValueFloat.Value;
446 int decimals = (int)MathHelper.Lerp(3, 0, MathUtils.InverseLerp(10, 1000, diff));
447 return MathHelper.Clamp((
float)Math.Round(onePercent, decimals), 0.1f, 1000);
450 private bool TextChanged(GUITextBox textBox,
string text)
455 if (
string.IsNullOrWhiteSpace(text) || text ==
"-")
459 else if (
int.TryParse(text, out
int newIntValue))
461 intValue = newIntValue;
465 if (
string.IsNullOrWhiteSpace(text) || text ==
"-")
469 else if (
float.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out
float newFloatValue))
471 floatValue = newFloatValue;
479 private void ClampFloatValue()
504 private void ClampIntValue()
528 private void UpdateText()
541 protected override void Update(
float deltaTime)
543 base.Update(deltaTime);
544 if (IsPressedTimerRunning)
546 pressedTimer -= deltaTime;
RectTransform RectTransform
TextBoxEvent OnDeselected
override RichString ToolTip
OnTextChangedHandler OnTextChanged
Don't set the Text property on delegates that register to this event, because modifying the Text will...
OnEnterHandler OnEnterPressed
Func< string, string > textFilterFunction