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()); } }