-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddEntityForm.cs
95 lines (79 loc) · 2.65 KB
/
AddEntityForm.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using static CaravelEditor.EditorForm;
namespace CaravelEditor
{
public partial class AddEntityForm : Form
{
private string[] m_Paths;
private string m_ParentPath;
private static int lastIdUsed = 0;
public static string LastEntityTypeResourceUsed = "";
public AddEntityForm(List<EntityTypeItem> types, string[] paths, string parentPath)
{
InitializeComponent();
int lastUsedIdx = -1;
m_ParentPath = parentPath;
var noType = new EntityTypeItem();
noType.Type = "None";
noType.Resource = "";
LastEntityTypeResourceUsed = LastEntityTypeResourceUsed.Replace("\\", "/");
this.typeComboBox.Items.Add(noType);
for(var i = 0; i < types.Count; i++)
{
var type = types[i];
if (type.Resource == LastEntityTypeResourceUsed)
{
lastUsedIdx = i;
}
this.typeComboBox.Items.Add(type);
}
if (lastUsedIdx >= 0)
{
typeComboBox.SelectedIndex = lastUsedIdx+1;
}
this.m_Paths = paths;
this.addButton.Enabled = false;
var placeHolderName = "";
lastUsedIdx = 0;
do
{
string prefix = "Entity";
if (typeComboBox.SelectedIndex > 0)
{
prefix = types[lastUsedIdx].Type;
}
placeHolderName = prefix + "_" + lastIdUsed;
lastIdUsed++;
}
while (m_Paths.Contains(parentPath + "/" + placeHolderName));
textBox.Text = placeHolderName;
}
public string GetEntityName()
{
return textBox.Text;
}
public string GetEntityType()
{
LastEntityTypeResourceUsed = ((EntityTypeItem)typeComboBox.SelectedItem).Resource;
return ((EntityTypeItem) typeComboBox.SelectedItem).Resource;
}
public bool TypeWasSelected()
{
return typeComboBox.SelectedIndex != -1 && typeComboBox.SelectedIndex != 0;
}
public void textBox_OnTextChanged(object sender, EventArgs eventArgs)
{
if (textBox.Text != "" && !m_Paths.Contains(m_ParentPath + "/" + textBox.Text))
{
addButton.Enabled = true;
}
else
{
addButton.Enabled = false;
}
}
}
}