IEnumerator SaveMultiWAVRoutine() { m_OperationInProgress = true; string selectedPath = TinyFileDialogs.SelectFolderDialog("Save multiple WAVES", UnityEngine.Application.dataPath); if (selectedPath == string.Empty || !Directory.Exists(selectedPath)) { m_OperationInProgress = false; yield break; } for (int i = 0; i < data.channels; i++) { for (int c = 0; c < data.channels; c++) { playback.mute [c] = c != i; } FileStream file = File.Create(selectedPath + "/PSG_" + i + ".wav"); yield return(StartCoroutine(SaveWAVRoutine(file, false))); m_OperationInProgress = true; } for (int c = 0; c < data.channels; c++) { playback.mute [c] = false; } FileStream masterFile = File.Create(selectedPath + "/PSG_ALL.wav"); yield return(StartCoroutine(SaveWAVRoutine(masterFile, true))); m_OperationInProgress = false; }
public void ZapSong() { if (!TinyFileDialogs.MessageBox("Nuking song!", "This will erase the entire song. All unsaved progress will be lost!", TinyFileDialogs.DialogType.OKCANCEL, TinyFileDialogs.IconType.WARNING, false)) { return; } patternView.playback.playbackSpeed = 6; UnityEngine.SceneManagement.SceneManager.LoadScene(0); }
public void ImportVGM() { if (fileModified && !TinyFileDialogs.MessageBox("Importing VGM", "Are you sure? You will lose all unsaved progress.", TinyFileDialogs.DialogType.YESNO, TinyFileDialogs.IconType.WARNING, false)) { return; } if (m_VgmImport.ShowDialog()) { BinaryReader br = new BinaryReader(m_VgmImport.OpenFile( )); vgmImport.ImportVGMFile(br); } }
public SongFile(SerializationInfo info, StreamingContext context) { fileVersion = -1; success = true; foreach (SerializationEntry e in info) { switch (e.Name) { case "version": fileVersion = ( int )e.Value; if (fileVersion > CURRENT_VERSION) { TinyFileDialogs.MessageBox("Incompatible file version!", "Trying to open file saved by a newer version!\n" + "(File version: " + fileVersion + ")", TinyFileDialogs.DialogType.OK, TinyFileDialogs.IconType.ERROR, true); success = false; return; } break; case "songName": songName = ( string )e.Value; break; case "artistName": artistName = (string)e.Value; break; case "patternLength": patternLength = ( int )e.Value; break; case "lookupTable": lookupTable = (List <int []>)e.Value; break; case "transposeTable": transposeTable = (List <int []>)e.Value; break; case "songData": songData = (List <SongData.ColumnEntry>)e.Value; break; case "instruments": if (fileVersion < CURRENT_VERSION) { instrumentsLegacy = (List <Instruments.InstrumentInstance>)info.GetValue("instruments", typeof(List <Instruments.InstrumentInstance>)); } else { instruments = (Instruments.InstrumentInstance [])e.Value; } break; } } }
void RefPalette() { GUILayout.BeginVertical("box", GUILayout.Width(145)); showRefPalette = GUILayout.Toggle(showRefPalette, "Source Palette", "boxhead"); int index = -1; if (showRefPalette) { GUILayout.BeginHorizontal(); if (GUILayout.Button("Load")) { string path = TinyFileDialogs.OpenFileDialog("Load Source Palette", Edit.GetDirectory(), new[] { "*.rpal" }, "Reptile Palettes (*.rpal)", false); if (!string.IsNullOrEmpty(path)) { actQueue.Enqueue(new LoadRefPaletteAct(System.IO.File.ReadAllBytes(path))); } } GUILayout.EndHorizontal(); refPalScroll = GUILayout.BeginScrollView(refPalScroll); for (int i = 0; i < Edit.use.refPalette.GetCount(); i++) { if (i % 4 == 0) { if (i > 0) { GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); } VColor c = Edit.use.refPalette.GetColor(i); index = Swatch(i == index, new Color32(c.r, c.g, c.b, c.a)) ? i : index; } GUILayout.EndHorizontal(); GUILayout.EndScrollView(); } GUILayout.EndVertical(); if (repaint) { boxRects.Add(GUILayoutUtility.GetLastRect()); } if (index >= 0) { actQueue.Enqueue(new ChangePaletteColorAct(ed.refPalette.GetColor(index), ed.tile.GetPalette().GetIndex())); } }
public void OptimizeSong() { if (!TinyFileDialogs.MessageBox("Optimizing song", "This will erase any unused patterns! Are you sure?", TinyFileDialogs.DialogType.YESNO, TinyFileDialogs.IconType.WARNING, false)) { return; } Dictionary <int, int> sortedIndicies = new Dictionary <int, int> ( ); List <ColumnEntry> sortedData = new List <ColumnEntry> ( ); foreach (int[] row in m_LookupTable) { for (int i = 0; i < 4; i++) { int oldIndex = row [i]; int newIndex = sortedData.Count; if (oldIndex >= 0 && !sortedIndicies.ContainsKey(oldIndex)) { sortedData.Add(m_SongData [row [i]]); sortedIndicies.Add(oldIndex, newIndex); } } } foreach (int [] row in m_LookupTable) { for (int i = 0; i < 4; i++) { if (sortedIndicies.ContainsKey(row [i])) { row [i] = sortedIndicies [row [i]]; } } } m_SongData = sortedData; patternMatrix.UpdateMatrix(); patternView.UpdatePatternData(); }
public void OpenFile() { if (fileModified && !TinyFileDialogs.MessageBox("Opening tune", "Are you sure? You will lose all unsaved progress.", TinyFileDialogs.DialogType.YESNO, TinyFileDialogs.IconType.WARNING, false)) { return; } playback.Stop( ); data.currentPattern = 0; if (m_TuneOpen.ShowDialog()) { IFormatter formatter = new BinaryFormatter( ); Stream fs = m_TuneOpen.OpenFile( ); SongFile open = (SongFile)formatter.Deserialize(fs); fs.Close( ); if (!open.success) { return; } data.SetPatternLength(open.patternLength); data.lookupTable = open.lookupTable; if (open.transposeTable != null && open.transposeTable.Count == open.lookupTable.Count) { data.transposeTable = open.transposeTable; } else { Debug.Log("Transpose table too shourt!!"); data.transposeTable = new List <int []> ( ); for (int i = 0; i < data.lookupTable.Count; i++) { int [] transposeEntry; if (open.transposeTable != null && i < open.transposeTable.Count) { transposeEntry = open.transposeTable [i]; } else { transposeEntry = new int [data.channels]; } data.transposeTable.Add(transposeEntry); } } data.songData = open.songData; SongData.songName = open.songName ?? ""; SongData.artistName = open.artistName ?? ""; keyboard.currentInstrument = 0; int presetCount = open.instruments.Length; Array.Resize(ref instruments.presets, presetCount); Array.Copy(open.instruments, instruments.presets, presetCount); m_OpenFile = m_TuneOpen.filePath; fileModified = false; if (onFileOpen != null) { onFileOpen( ); } patternMatrix.UpdateMatrix(); patternView.UpdatePatternData(); insEditor.UpdateInstruments(); insEditor.UpdateInstrumentInfo(); insEditor.SetSelectedInstrument(0); playback.playbackSpeed = 6; } }
void Palette() { GUILayout.BeginVertical("box", GUILayout.Width(145)); showPalette = GUILayout.Toggle(showPalette, "Palette", "boxhead"); int index = ed.tile.GetPalette().GetIndex(); VPalette palette = Edit.use.tile.GetPalette(); if (showPalette) { GUILayout.BeginHorizontal(); if (GUILayout.Button("Load")) { string path = TinyFileDialogs.OpenFileDialog("Load Palette", Edit.GetDirectory(), new[] { "*.rpal" }, "Reptile Palettes (*.rpal)", false); if (!string.IsNullOrEmpty(path)) { actQueue.Enqueue(new LoadPaletteAct(System.IO.File.ReadAllBytes(path))); } } if (GUILayout.Button("Save")) { string path = TinyFileDialogs.SaveFileDialog("Save Palette", Edit.GetDirectory(), new[] { "*.rpal" }, "Reptile Palettes (*.rpal)"); if (!string.IsNullOrEmpty(path)) { if (!path.Contains(".")) { path += ".rpal"; } System.IO.File.WriteAllBytes(path, new BinaryWriter(palette).GetOutput()); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (palette.GetCount() > 1 && GUILayout.Button("-", GUILayout.Width(25))) { actQueue.Enqueue(new RemovePaletteColorAct()); } GUILayout.FlexibleSpace(); if (palette.GetCount() < 256 && GUILayout.Button("+", GUILayout.Width(25))) { actQueue.Enqueue(new AddPaletteColorAct(new VColor(255, 255, 255, 255))); } GUILayout.EndHorizontal(); palScroll = GUILayout.BeginScrollView(palScroll); for (int i = 0; i < palette.GetCount(); i++) { if (i % 4 == 0) { if (i > 0) { GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); } VColor c = palette.GetColor(i); index = Swatch(i == index, new Color32(c.r, c.g, c.b, c.a)) ? i : index; } GUILayout.EndHorizontal(); GUILayout.EndScrollView(); } GUILayout.EndVertical(); if (repaint) { boxRects.Add(GUILayoutUtility.GetLastRect()); } if (index != ed.tile.GetPalette().GetIndex()) { actQueue.Enqueue(new ChangePaletteIndexAct(index)); } }
void Tile() { GUILayout.BeginVertical("box"); showTile = GUILayout.Toggle(showTile, "Tile", "boxhead"); if (showTile) { GUILayout.BeginHorizontal(); if (GUILayout.Button("Load")) { string path = TinyFileDialogs.OpenFileDialog("Load Tile", Edit.GetDirectory(), new[] { "*.rtile" }, "Reptile Tiles (*.rtile)", false); if (!string.IsNullOrEmpty(path)) { actQueue.Enqueue(new LoadTileAct(System.IO.File.ReadAllBytes(path))); } } if (GUILayout.Button("Save")) { string path = TinyFileDialogs.SaveFileDialog("Save Tile", Edit.GetDirectory(), new[] { "*.rtile" }, "Reptile Tiles (*.rtile)"); if (!string.IsNullOrEmpty(path)) { if (!path.Contains(".")) { path += ".rtile"; } System.IO.File.WriteAllBytes(path, new BinaryWriter(Edit.use.tile).GetOutput()); } } if (GUILayout.Button("New")) { actQueue.Enqueue(new NewTileAct()); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Label("Width"); int w; if (int.TryParse(GUILayout.TextField(Edit.width.ToString()), out w)) { if (w != ed.tile.GetWidth()) { Edit.width = w; } } ; GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Label("Height"); int h; if (int.TryParse(GUILayout.TextField(Edit.height.ToString()), out h)) { if (h != ed.tile.GetHeight()) { Edit.height = h; } } ; GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Label("Depth"); int d; if (int.TryParse(GUILayout.TextField(Edit.depth.ToString()), out d)) { if (d != ed.tile.GetDepth()) { Edit.depth = d; } } ; GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUI.enabled = Edit.width != ed.tile.GetWidth() || Edit.height != ed.tile.GetHeight() || Edit.depth != ed.tile.GetDepth(); if (GUILayout.Button("Apply")) { actQueue.Enqueue(new ResizeTileAct(Edit.width, Edit.height, Edit.depth)); } GUI.enabled = true; GUILayout.Label("Presets"); GUILayout.BeginHorizontal(); if (GUILayout.Button("8³")) { actQueue.Enqueue(new ResizeTileAct(8, 8, 8)); } if (GUILayout.Button("16³")) { actQueue.Enqueue(new ResizeTileAct(16, 16, 16)); } if (GUILayout.Button("32³")) { actQueue.Enqueue(new ResizeTileAct(32, 32, 32)); } GUILayout.EndHorizontal(); GUILayout.Label("Import"); GUILayout.BeginHorizontal(); if (GUILayout.Button("VOX")) { string path = TinyFileDialogs.OpenFileDialog("Import VOX", Edit.GetDirectory(), new[] { "*.vox" }, "MagicaVoxel Model (*.vox)", false); if (!string.IsNullOrEmpty(path)) { actQueue.Enqueue(new LoadTileAct(new BinaryWriter(ExportUtil.VoxToTile(System.IO.File.ReadAllBytes(path))).GetOutput())); } } GUILayout.EndHorizontal(); GUILayout.Label("Export"); GUILayout.BeginHorizontal(); if (GUILayout.Button("OBJ")) { string path = TinyFileDialogs.SaveFileDialog("Export OBJ", Edit.GetDirectory(), new[] { "*.obj" }, "Wavefront OBJ (*.obj)"); if (!string.IsNullOrEmpty(path)) { if (!path.Contains(".")) { path += ".obj"; } System.IO.File.WriteAllText(path, ExportUtil.TileToObj(Edit.use.tile)); System.IO.File.WriteAllBytes(path.Substring(0, path.LastIndexOf('.')) + ".png", ExportUtil.PaletteToPng(Edit.use.tile.GetPalette())); } } if (GUILayout.Button("VOX")) { string path = TinyFileDialogs.SaveFileDialog("Export VOX", Edit.GetDirectory(), new[] { "*.vox" }, "MagicaVoxel Model (*.vox)"); if (!string.IsNullOrEmpty(path)) { if (!path.Contains(".")) { path += ".vox"; } System.IO.File.WriteAllBytes(path, ExportUtil.TileToVox(Edit.use.tile)); } } if (GUILayout.Button("PNG")) { string path = TinyFileDialogs.SaveFileDialog("Export PNG", Edit.GetDirectory(), new[] { "*.png" }, "Portable Network Graphics (*.png)"); if (!string.IsNullOrEmpty(path)) { if (!path.Contains(".")) { path += ".png"; } System.IO.File.WriteAllBytes(path, ExportUtil.PaletteToPng(Edit.use.tile.GetPalette())); } } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); if (repaint) { boxRects.Add(GUILayoutUtility.GetLastRect()); } }