/* 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(); }
private void ReloadList() { modelList.Items.Clear(); ModelsFile.Load(levelPath); TexturesFile.Load(levelPath); foreach (Model model in ModelsFile.GetFiles()) { if (!modelList.Items.Contains(model.modelName)) { modelList.Items.Add(model.modelName); //We share names between LOD0&1, so don't duplicate } } }
/* Import */ private void importModel_Click(object sender, EventArgs e) { if (modelName.Text == "") { MessageBox.Show("Name cannot be blank!", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (pathToLod0.Text == "" || pathToLod1.Text == "") { MessageBox.Show("Models must be selected for both LOD 0 & 1!", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } for (int i = 0; i < ModelsFile.GetFiles().Count; i++) { if (ModelsFile.GetFiles()[i].modelName == modelName.Text) { MessageBox.Show("Model name must be unique!", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } Model newModelLOD0 = new Model(modelName.Text, LevelOfDetail.HIGH); if (!newModelLOD0.LoadFromOBJ(pathToLod0.Text)) { MessageBox.Show("Model selected for LOD0 is invalid!\nModel must be triangulated and contain UV data.", "Invalid LOD0", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Model newModelLOD1 = new Model(modelName.Text, LevelOfDetail.LOW); if (!newModelLOD1.LoadFromOBJ(pathToLod1.Text)) { MessageBox.Show("Model selected for LOD1 is invalid!\nModel must be triangulated and contain UV data.", "Invalid LOD0", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ModelsFile.AddFile(newModelLOD0); TexturesFile.AddFilesFromModel(newModelLOD0); ModelsFile.AddFile(newModelLOD1); TexturesFile.AddFilesFromModel(newModelLOD1); MessageBox.Show("Model successfully imported.", "Import 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(); }