freeso/TSOClient/FSO.IDE/EditorComponent/OperandForms/OpValueControl.cs
riperiperi b57ebbd141 Cleanup: Remove most unused usings and MPL per-file licenses
MPL per-file was used in older project files, but should apply to the whole project, so having it there was redundant.
2023-11-25 03:45:29 +00:00

61 lines
1.9 KiB
C#

using System;
using System.Windows.Forms;
using FSO.SimAntics.Engine;
using FSO.IDE.EditorComponent.OperandForms.DataProviders;
namespace FSO.IDE.EditorComponent.OperandForms
{
public partial class OpValueControl : UserControl, IOpControl
{
private OpValueBoundsProvider BoundsProvider;
private BHAVEditor Master;
private VMPrimitiveOperand Operand;
private EditorScope Scope;
private string Property;
private bool IgnoreSet;
public OpValueControl()
{
InitializeComponent();
}
public OpValueControl(BHAVEditor master, EditorScope scope, VMPrimitiveOperand operand, string title, string property, OpValueBoundsProvider bounds, bool isHex = false)
{
InitializeComponent();
Master = master;
Scope = scope;
Operand = operand;
TitleLabel.Text = title;
ValueEntry.Hexadecimal = isHex;
Property = property;
BoundsProvider = bounds;
this.Dock = DockStyle.Fill;
OperandUpdated();
}
public void OperandUpdated()
{
var bounds = BoundsProvider.GetBounds(Scope, Operand);
ValueEntry.Minimum = bounds[0];
ValueEntry.Maximum = bounds[1];
var prop = OpUtils.GetOperandProperty(Operand, Property);
if (prop.GetType() == typeof(uint)) prop = unchecked((int)Convert.ToUInt32(prop));
int value = Convert.ToInt32(prop);
IgnoreSet = true;
ValueEntry.Value = value;
IgnoreSet = false;
}
private void ValueEntry_ValueChanged(object sender, EventArgs e)
{
if (IgnoreSet) return;
OpUtils.SetOperandProperty(Operand, Property, ValueEntry.Value);
Master.SignalOperandUpdate();
}
}
}