-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddSubSceneForm.cs
155 lines (130 loc) · 4.56 KB
/
AddSubSceneForm.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CaravelEditor
{
public partial class AddSubSceneForm : Form
{
public AddSubSceneForm()
{
InitializeComponent();
}
private string m_sCurrentProject;
private string[] m_Paths;
private string m_sParentPath;
private string m_sFileName;
private string m_sParentResourceBundle;
private static int lastIdUsed = 0;
public static string LastSceneUsed = "";
public AddSubSceneForm(string currProject, string[] paths, string parentPath, string parentResourceBundle)
{
InitializeComponent();
m_sCurrentProject = currProject;
m_sParentResourceBundle = parentResourceBundle;
m_sParentPath = parentPath;
this.m_Paths = paths;
this.addButton.Enabled = false;
string resourceBundleFullPath = Path.Combine(m_sCurrentProject, Path.GetFileNameWithoutExtension(m_sParentResourceBundle));
sceneResourceTextBox.Text = LastSceneUsed.Replace(resourceBundleFullPath + Path.DirectorySeparatorChar, "").Replace("\\", "/");
m_sFileName = LastSceneUsed;
lastIdUsed = 0;
string placeHolderName;
do
{
placeHolderName = Path.GetFileNameWithoutExtension(sceneResourceTextBox.Text) + "_" + lastIdUsed;
lastIdUsed++;
}
while (m_Paths.Contains(parentPath + "/" + placeHolderName));
textBox.Text = placeHolderName;
if (CanAddScene())
{
addButton.Enabled = true;
}
else
{
addButton.Enabled = false;
}
}
public string GetSceneName()
{
return textBox.Text;
}
public string GetSceneResource()
{
return sceneResourceTextBox.Text;
}
public void textBox_OnTextChanged(object sender, EventArgs eventArgs)
{
if (CanAddScene())
{
addButton.Enabled = true;
}
else
{
addButton.Enabled = false;
}
}
private void browseResourceButton_Click(object sender, EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
openFile.InitialDirectory = m_sCurrentProject;
openFile.Filter = "Caravel Scene | *.cvs";
openFile.ShowDialog();
if (openFile.FileNames.Length > 0)
{
string resourceBundleFullPath = Path.Combine(m_sCurrentProject, Path.GetFileNameWithoutExtension(m_sParentResourceBundle));
string fileName = openFile.FileNames[0];
if (fileName.StartsWith(resourceBundleFullPath))
{
m_sFileName = fileName;
sceneResourceTextBox.Text = fileName.Replace(resourceBundleFullPath + Path.DirectorySeparatorChar, "").Replace("\\", "/");
LastSceneUsed = fileName;
if (CanAddScene())
{
addButton.Enabled = true;
}
else
{
addButton.Enabled = false;
}
}
else
{
MessageBox.Show("Error - The scene file must be inside the same resource bundle as its parent scene.", "Error");
}
}
}
private bool FileIsPartOfBundle(string filePath)
{
if (filePath == null || filePath == "")
{
return false;
}
string resourceBundleFullPath = Path.Combine(m_sCurrentProject, Path.GetFileNameWithoutExtension(m_sParentResourceBundle));
if (filePath.StartsWith(resourceBundleFullPath))
{
return true;
}
return false;
}
private bool CanAddScene()
{
if (textBox.Text != "" && !m_Paths.Contains(m_sParentPath + "/" + textBox.Text)
&& FileIsPartOfBundle(m_sFileName) && textBox.Text != "Root")
{
return true;
}
else
{
return false;
}
}
}
}