-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddMaterialForm.cs
74 lines (61 loc) · 2.07 KB
/
AddMaterialForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using static Caravel.Core.Physics.Cv_GamePhysics;
namespace CaravelEditor
{
public partial class AddMaterialForm : Form
{
private string[] m_Materials;
private float m_fDensity;
private float m_fFriction;
private float m_fRestitution;
public AddMaterialForm(string[] materials)
{
InitializeComponent();
addButton.Enabled = false;
m_Materials = materials;
}
public string GetMaterialName()
{
return nameTextBox.Text;
}
public Cv_PhysicsMaterial GetMaterial()
{
return new Cv_PhysicsMaterial(m_fFriction, m_fRestitution, m_fDensity);
}
private bool CheckIfMaterialIsValid()
{
if (nameTextBox.Text == null || nameTextBox.Text == "" || m_Materials.Contains(nameTextBox.Text))
{
return false;
}
if (densityTextBox.Text == "" || !float.TryParse(densityTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out m_fDensity) || m_fDensity <= 0)
{
return false;
}
if (frictionTextBox.Text == "" || !float.TryParse(frictionTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out m_fFriction) || m_fFriction < 0)
{
return false;
}
if (restitutionTextBox.Text == "" || !float.TryParse(restitutionTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out m_fRestitution) || m_fRestitution < 0)
{
return false;
}
return true;
}
private void textBox_OnTextChanged(object sender, EventArgs eventArgs)
{
var textBox = (TextBox) sender;
if (CheckIfMaterialIsValid())
{
addButton.Enabled = true;
}
else
{
addButton.Enabled = false;
}
}
}
}