/* Save the new level */ private void saveLevel_Click(object sender, EventArgs e) { if (levelName.Text == "") { MessageBox.Show("Level must have a name!", "No level name.", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } for (int i = 0; i < LevelFile.GetData().Count; i++) { if (LevelFile.GetData()[i].levelName == levelName.Text) { MessageBox.Show("Level name must be unique!", "Level name already exists.", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } string pathToEnv = "ENV/PRODUCTION/" + levelName.Text.Trim().ToUpper().Replace(' ', '_') + "/"; LevelFile.GetData().Add(new Level(levelName.Text, "DATA/" + pathToEnv, (LevelType)levelType.SelectedIndex)); LevelFile.SaveData(); Directory.CreateDirectory(pathToEnv); File.WriteAllBytes(pathToEnv + "COMMANDS.BIN", Properties.Resources.COMMANDS_BIN); File.WriteAllBytes(pathToEnv + "COMMANDS.JSON", Properties.Resources.COMMANDS_JSON); ModelsFile.GetFiles().Clear(); ModelsFile.Save(pathToEnv); TexturesFile.GetFiles().Clear(); TexturesFile.Save(pathToEnv); MessageBox.Show("Saved!", "Complete.", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); }
/* Delete a model from the level */ private void deleteModel_Click(object sender, EventArgs e) { if (modelList.SelectedIndex == -1) { return; } for (int i = 0; i < ModelsFile.GetFiles().Count; i++) { if (ModelsFile.GetFiles()[i].modelName == modelList.Items[modelList.SelectedIndex].ToString()) { ModelsFile.RemoveFile(ModelsFile.GetFiles()[i]); } } Texture[] prevTexs = new Texture[TexturesFile.GetFiles().Count]; TexturesFile.GetFiles().CopyTo(prevTexs); TexturesFile.GetFiles().Clear(); for (int i = 0; i < ModelsFile.GetFiles().Count; i++) { for (int x = 0; x < ModelsFile.GetFiles()[i].modelParts.Count; x++) { for (int y = 0; y < prevTexs.Length; y++) { if (prevTexs[y].textureID == ModelsFile.GetFiles()[i].modelParts[x].thisMaterial.textureID) { TexturesFile.AddFile(prevTexs[y]); break; } } } } ModelsFile.Save(levelPath); TexturesFile.Save(levelPath); ReloadList(); }
/* Reload GUI List */ private void SaveAndReloadList(object sender, EventArgs e) { ModelsFile.Save(levelPath); TexturesFile.Save(levelPath); ReloadList(); }