2013-07-19 15:30:58 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System;
|
2013-06-10 14:04:23 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
|
using CodeImp.DoomBuilder.GZBuilder.Tools;
|
2013-07-19 15:30:58 +00:00
|
|
|
|
using CodeImp.DoomBuilder.Properties;
|
|
|
|
|
|
|
|
|
|
#endregion
|
2013-06-10 14:04:23 +00:00
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.GZBuilder.Controls
|
|
|
|
|
{
|
|
|
|
|
public partial class PairedFieldsControl : UserControl
|
|
|
|
|
{
|
2013-07-19 15:30:58 +00:00
|
|
|
|
#region ================== Events
|
|
|
|
|
|
|
|
|
|
public event EventHandler OnValuesChanged;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
2013-06-10 14:04:23 +00:00
|
|
|
|
private float defaultValue;
|
|
|
|
|
private string field1;
|
|
|
|
|
private string field2;
|
2013-07-19 15:30:58 +00:00
|
|
|
|
private bool allowValueLinking;
|
|
|
|
|
private bool linkValues;
|
|
|
|
|
private bool blockUpdate;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
private readonly int bResetOffsetX;
|
2013-07-19 15:30:58 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Properties
|
2013-06-10 14:04:23 +00:00
|
|
|
|
|
|
|
|
|
public string Label { get { return label.Text; } set { label.Text = value; } }
|
|
|
|
|
public float DefaultValue { get { return defaultValue; } set { defaultValue = value; } }
|
|
|
|
|
public string Field1 { get { return field1; } set { field1 = value; } }
|
|
|
|
|
public string Field2 { get { return field2; } set { field2 = value; } }
|
|
|
|
|
public bool AllowDecimal { get { return value1.AllowDecimal; } set { value1.AllowDecimal = value; value2.AllowDecimal = value; } }
|
2013-07-08 13:39:06 +00:00
|
|
|
|
public int ButtonStep { get { return value1.ButtonStep; } set { value1.ButtonStep = value; value2.ButtonStep = value; } }
|
|
|
|
|
public float ButtonStepFloat { get { return value1.ButtonStepFloat; } set { value1.ButtonStepFloat = value; value2.ButtonStepFloat = value; } }
|
2013-07-19 15:30:58 +00:00
|
|
|
|
public bool AllowValueLinking { get { return allowValueLinking; } set { allowValueLinking = value; updateButtons(); } }
|
|
|
|
|
public bool LinkValues { get { return linkValues; } set { linkValues = value; updateButtons(); } }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Constructor
|
|
|
|
|
|
2013-06-10 14:04:23 +00:00
|
|
|
|
public PairedFieldsControl() {
|
|
|
|
|
InitializeComponent();
|
2013-07-29 12:01:06 +00:00
|
|
|
|
bResetOffsetX = this.Width - bReset.Left;
|
2013-06-10 14:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 15:30:58 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
|
|
public void SetValuesFrom(UniFields fields, bool first) {
|
|
|
|
|
blockUpdate = true;
|
|
|
|
|
|
2013-06-25 12:35:13 +00:00
|
|
|
|
string newValue1;
|
|
|
|
|
string newValue2;
|
2013-06-10 14:04:23 +00:00
|
|
|
|
|
2013-06-25 12:35:13 +00:00
|
|
|
|
if(AllowDecimal) {
|
|
|
|
|
float val1 = UDMFTools.GetFloat(fields, field1, defaultValue);
|
|
|
|
|
newValue1 = (val1 == Math.Round(val1) ? val1.ToString("0.0") : val1.ToString());
|
2013-06-10 14:04:23 +00:00
|
|
|
|
|
2013-06-25 12:35:13 +00:00
|
|
|
|
float val2 = UDMFTools.GetFloat(fields, field2, defaultValue);
|
|
|
|
|
newValue2 = (val2 == Math.Round(val2) ? val2.ToString("0.0") : val2.ToString());
|
|
|
|
|
} else {
|
|
|
|
|
newValue1 = UDMFTools.GetFloat(fields, field1, defaultValue).ToString();
|
|
|
|
|
newValue2 = UDMFTools.GetFloat(fields, field2, defaultValue).ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 15:30:58 +00:00
|
|
|
|
if(first) {
|
|
|
|
|
value1.Text = newValue1;
|
|
|
|
|
value2.Text = newValue2;
|
|
|
|
|
} else {
|
2014-01-20 08:47:49 +00:00
|
|
|
|
value1.Text = ((!string.IsNullOrEmpty(value1.Text) && value1.Text != newValue1) ? string.Empty : newValue1);
|
|
|
|
|
value2.Text = ((!string.IsNullOrEmpty(value2.Text) && value2.Text != newValue2) ? string.Empty : newValue2);
|
2013-07-19 15:30:58 +00:00
|
|
|
|
}
|
2013-06-10 14:04:23 +00:00
|
|
|
|
checkValues();
|
2013-07-19 15:30:58 +00:00
|
|
|
|
|
|
|
|
|
blockUpdate = false;
|
2013-06-10 14:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 15:30:58 +00:00
|
|
|
|
public void ApplyTo(UniFields fields, int min, int max, float oldValue1, float oldValue2) {
|
2014-01-20 08:47:49 +00:00
|
|
|
|
if(value1.Text != string.Empty)
|
2013-08-10 11:28:51 +00:00
|
|
|
|
UDMFTools.SetFloat(fields, field1, General.Clamp(value1.GetResultFloat(defaultValue), min, max), defaultValue);
|
2013-07-19 15:30:58 +00:00
|
|
|
|
else
|
2013-08-10 11:28:51 +00:00
|
|
|
|
UDMFTools.SetFloat(fields, field1, oldValue1, defaultValue);
|
2013-07-19 15:30:58 +00:00
|
|
|
|
|
2014-01-20 08:47:49 +00:00
|
|
|
|
if(value2.Text != string.Empty)
|
2013-08-10 11:28:51 +00:00
|
|
|
|
UDMFTools.SetFloat(fields, field2, General.Clamp(value2.GetResultFloat(defaultValue), min, max), defaultValue);
|
2013-07-19 15:30:58 +00:00
|
|
|
|
else
|
2013-08-10 11:28:51 +00:00
|
|
|
|
UDMFTools.SetFloat(fields, field2, oldValue2, defaultValue);
|
2013-06-10 14:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkValues() {
|
2013-09-11 08:49:45 +00:00
|
|
|
|
bool changed = string.IsNullOrEmpty(value1.Text) || string.IsNullOrEmpty(value2.Text)
|
|
|
|
|
|| value1.GetResultFloat(defaultValue) != defaultValue || value2.GetResultFloat(defaultValue) != defaultValue;
|
2013-06-10 14:04:23 +00:00
|
|
|
|
label.Enabled = changed;
|
2013-06-11 08:05:32 +00:00
|
|
|
|
bReset.Visible = changed;
|
2013-07-19 15:30:58 +00:00
|
|
|
|
|
|
|
|
|
if(!blockUpdate && OnValuesChanged != null) OnValuesChanged(this, EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateButtons() {
|
|
|
|
|
bLink.Visible = allowValueLinking;
|
|
|
|
|
|
|
|
|
|
if(!allowValueLinking) {
|
|
|
|
|
bReset.Left = bLink.Left;
|
|
|
|
|
} else {
|
2013-07-29 12:01:06 +00:00
|
|
|
|
bReset.Left = this.Width - bResetOffsetX;
|
2013-07-19 15:30:58 +00:00
|
|
|
|
bLink.Image = (linkValues ? Resources.Link : Resources.Unlink);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Events
|
|
|
|
|
|
|
|
|
|
private void bLink_Click(object sender, EventArgs e) {
|
|
|
|
|
linkValues = !linkValues;
|
|
|
|
|
bLink.Image = (linkValues ? Resources.Link : Resources.Unlink);
|
2013-06-10 14:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void bReset_Click(object sender, EventArgs e) {
|
|
|
|
|
string newValue = value1.AllowDecimal ? String.Format("{0:0.0}", defaultValue) : defaultValue.ToString();
|
|
|
|
|
value1.Text = newValue;
|
|
|
|
|
value2.Text = newValue;
|
|
|
|
|
checkValues();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void value1_WhenTextChanged(object sender, EventArgs e) {
|
2013-07-19 15:30:58 +00:00
|
|
|
|
if(blockUpdate) return;
|
|
|
|
|
|
|
|
|
|
if(linkValues) {
|
|
|
|
|
blockUpdate = true;
|
|
|
|
|
value2.Text = value1.Text;
|
|
|
|
|
blockUpdate = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkValues();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void value2_WhenTextChanged(object sender, EventArgs e) {
|
|
|
|
|
if(blockUpdate) return;
|
|
|
|
|
|
|
|
|
|
if(linkValues) {
|
|
|
|
|
blockUpdate = true;
|
|
|
|
|
value1.Text = value2.Text;
|
|
|
|
|
blockUpdate = false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 14:04:23 +00:00
|
|
|
|
checkValues();
|
|
|
|
|
}
|
2013-07-19 15:30:58 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
2013-06-10 14:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|