2013-07-19 15:30:58 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
using System.Globalization;
|
2013-06-25 12:35:13 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2013-07-19 15:30:58 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2013-06-25 12:35:13 +00:00
|
|
|
|
namespace CodeImp.DoomBuilder.GZBuilder.Controls
|
|
|
|
|
{
|
|
|
|
|
public partial class PairedIntControl : UserControl
|
|
|
|
|
{
|
2013-07-19 15:30:58 +00:00
|
|
|
|
#region ================== Events
|
|
|
|
|
|
|
|
|
|
public event EventHandler OnValuesChanged;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
2013-06-25 12:35:13 +00:00
|
|
|
|
private int defaultValue;
|
2013-07-19 15:30:58 +00:00
|
|
|
|
private bool blockUpdate;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Properties
|
2013-06-25 12:35:13 +00:00
|
|
|
|
|
|
|
|
|
public string Label { get { return label.Text; } set { label.Text = value; } }
|
|
|
|
|
public int DefaultValue { get { return defaultValue; } set { defaultValue = value; } }
|
2014-01-20 08:47:49 +00:00
|
|
|
|
public int ButtonStep { get { return value1.ButtonStep; } set { value1.ButtonStep = value; value2.ButtonStep = value; } }
|
2013-06-25 12:35:13 +00:00
|
|
|
|
|
2013-07-19 15:30:58 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public PairedIntControl()
|
|
|
|
|
{
|
2013-06-25 12:35:13 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public void SetValues(int val1, int val2, bool first)
|
|
|
|
|
{
|
2013-07-19 15:30:58 +00:00
|
|
|
|
blockUpdate = true;
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if (first)
|
|
|
|
|
{
|
|
|
|
|
value1.Text = val1.ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
value2.Text = val2.ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(value1.Text) && value1.Text != val1.ToString(CultureInfo.InvariantCulture))
|
2014-01-20 08:47:49 +00:00
|
|
|
|
value1.Text = string.Empty;
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(value2.Text) && value2.Text != val2.ToString(CultureInfo.InvariantCulture))
|
2014-01-20 08:47:49 +00:00
|
|
|
|
value2.Text = string.Empty;
|
|
|
|
|
}
|
2013-07-19 15:30:58 +00:00
|
|
|
|
|
|
|
|
|
blockUpdate = false;
|
2013-06-25 12:35:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public int GetValue1(int original)
|
|
|
|
|
{
|
2013-06-25 12:35:13 +00:00
|
|
|
|
return value1.GetResult(original);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public int GetValue2(int original)
|
|
|
|
|
{
|
2013-06-25 12:35:13 +00:00
|
|
|
|
return value2.GetResult(original);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private void CheckValues()
|
|
|
|
|
{
|
2013-09-11 08:49:45 +00:00
|
|
|
|
bool changed = string.IsNullOrEmpty(value1.Text) || string.IsNullOrEmpty(value2.Text)
|
|
|
|
|
|| value1.GetResult(defaultValue) != defaultValue || value2.GetResult(defaultValue) != defaultValue;
|
2013-06-25 12:35:13 +00:00
|
|
|
|
label.Enabled = changed;
|
|
|
|
|
bReset.Visible = changed;
|
2013-07-19 15:30:58 +00:00
|
|
|
|
|
|
|
|
|
if(!blockUpdate && OnValuesChanged != null) OnValuesChanged(this, EventArgs.Empty);
|
2013-06-25 12:35:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private void bReset_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
value1.Text = defaultValue.ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
value2.Text = defaultValue.ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
CheckValues();
|
2013-06-25 12:35:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private void value1_WhenTextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CheckValues();
|
2013-06-25 12:35:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|