public override void Update() { this.TypeButton.IsEnabled = false; if (this.OKButton.IsClicked) { DialogsManager.HideDialog(this); } if (this.ImportButton.IsClicked) { if (!Directory.Exists(CreatorMain.CacheDirectory)) { Directory.CreateDirectory(CreatorMain.CacheDirectory); } string sdFile = CreatorMain.OneKeyFile; string _sdFile = CreatorMain.Export_OnekeyFile_Directory + "/" + (string)this.ListView.SelectedItem; if (!FileOperation.IsFileInUse(_sdFile) && (!File.Exists(sdFile) || !FileOperation.IsFileInUse(sdFile))) { FileStream fileStream = new FileStream(_sdFile, FileMode.Open); FileStream file = new FileStream(sdFile, FileMode.Create); fileStream.CopyTo(file); file.Dispose(); fileStream.Dispose(); player.ComponentGui.DisplaySmallMessage("导入成功!", true, false); } else { player.ComponentGui.DisplaySmallMessage("操作失败!", true, false); } DialogsManager.HideDialog(this); } if (DeleteButton.IsClicked) { string sdFile = CreatorMain.Export_OnekeyFile_Directory + "/" + (string)this.ListView.SelectedItem; if (FileOperation.Delete(sdFile)) { player.ComponentGui.DisplaySmallMessage("删除成功!", true, false); UpList(); } else { player.ComponentGui.DisplaySmallMessage("操作失败!", true, false); } } this.DerivedButton.IsEnabled = File.Exists(CreatorMain.OneKeyFile); if (this.DerivedButton.IsClicked) { DialogsManager.ShowDialog(player.View.GameWidget, new DerivedDialog(player, this, this.ListView)); } if (this.CreateButton.IsClicked) { if (creatorAPI.Position[2] == new Point3(0, -1, 0)) { player.ComponentGui.DisplaySmallMessage("请设置点3!", true, false); } else { Task.Run(() => { try { if (!Directory.Exists(CreatorMain.CacheDirectory)) { Directory.CreateDirectory(CreatorMain.CacheDirectory); } OnekeyGeneration.CreateOnekey(creatorAPI, CreatorMain.CacheDirectory + "/", "CacheFile.od", creatorAPI.Position[0], creatorAPI.Position[1], creatorAPI.Position[2]); } catch (Exception e) { player.ComponentGui.DisplaySmallMessage(e.Message, true, false); } }); } DialogsManager.HideDialog(this); } if (ListView.SelectedIndex == null) { this.ImportButton.IsEnabled = false; this.DeleteButton.IsEnabled = false; } else { this.ImportButton.IsEnabled = true; this.DeleteButton.IsEnabled = true; } if (creatorAPI.oneKeyGeneration) { OnAndOffButton.Color = Color.Yellow; } else { OnAndOffButton.Color = Color.Red; } if (OnAndOffButton.IsClicked) { if (creatorAPI.oneKeyGeneration) { creatorAPI.oneKeyGeneration = false; } else { creatorAPI.oneKeyGeneration = true; } } }
public override void Update() { if (this.cancelButton.IsClicked) { DialogsManager.HideDialog(this); } if (this.OK.IsClicked) { string dir = CreatorMain.Export_ModFile_Directory; string name; if (TextBox.Text.Length <= 0) { name = $"{DateTime.Now.ToString("yyyy-MM-dd")}_{DateTime.Now.ToLongTimeString().ToString()}"; } else { name = TextBox.Text; } try { if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string fileName = dir + "/" + name + ".wMod2";; if (this.dataType == DataType.Copy) { CopyAndPaste.ExportCopywMod2(CreatorMain.CopyFile, fileName); } else if (this.dataType == DataType.OneKey) { fileName = dir + "/" + name + ".oMod2"; OnekeyGeneration.ExportOnekeyoMod2(CreatorMain.OneKeyFile, fileName); } else if (this.dataType == DataType.OldCopy) { fileName = dir + "/" + name + ".wMod"; CopyAndPaste.ExportCopywMod(CreatorMain.CopyFile, fileName); } else if (this.dataType == DataType.OldOneKey) { fileName = dir + "/" + name + ".oMod"; OnekeyGeneration.ExportOnekeyoMod(CreatorMain.OneKeyFile, fileName); } else if (this.dataType == DataType.SpecialCopy) { fileName = dir + "/" + name + ".sMod"; FileStream fileStream = new FileStream(CreatorMain.SpecialCopyFile, FileMode.Open); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } FileStream files = new FileStream(fileName, FileMode.OpenOrCreate); fileStream.CopyTo(files); files.Dispose(); fileStream.Dispose(); } this.player.ComponentGui.DisplaySmallMessage($"导出成功!文件所在位置:\n{fileName}", true, false); DialogsManager.HideDialog(this); this.listView.ClearItems(); if (!Directory.Exists(CreatorMain.Export_ModFile_Directory)) { Directory.CreateDirectory(CreatorMain.Export_ModFile_Directory); } foreach (string file in Directory.GetFiles(CreatorMain.Export_ModFile_Directory)) { if (Path.GetExtension(file) == ".oMod" || Path.GetExtension(file) == ".wMod" || Path.GetExtension(file) == ".oMod2" || Path.GetExtension(file) == ".wMod2" || Path.GetExtension(file) == ".sMod") { this.listView.AddItem(Path.GetFileName(file)); } } } catch (Exception e) { this.player.ComponentGui.DisplaySmallMessage($"发生了一个很严重的错误,\n 错误提示 :{e.Message}\n{dir}", true, false); DialogsManager.HideDialog(this); DialogsManager.HideDialog(this.dialog); } DialogsManager.HideDialog(this); } }
public static bool Touch(CreatorAPI creatorAPI, Point3 position) { ComponentPlayer player = creatorAPI.componentMiner.ComponentPlayer; int cellValue = GameManager.Project.FindSubsystem <SubsystemTerrain>(true).Terrain.GetCellValue(position.X, position.Y, position.Z); /* if (creatorAPI.twoPointsOfAttachment && creatorAPI.numberPoint == CreatorAPI.NumberPoint.Two) * { * Task.Run(delegate * { * ChunkData chunkData = new ChunkData(creatorAPI); * creatorAPI.revokeData = new ChunkData(creatorAPI); * int num = 0; * foreach (Point3 point3 in creatorAPI.creatorGenerationAlgorithm.TwoPointLineGeneration2(creatorAPI.Position[0], creatorAPI.Position[1])) * { * creatorAPI.CreateBlock(point3, cellValue,chunkData); * num++; * } * chunkData.Render(); * player.ComponentGui.DisplaySmallMessage($"操作成功,共生成{num}个方块", true, true); * }); * } */ if (creatorAPI.oneKeyGeneration) { if (creatorAPI.onekeyType == CreatorAPI.OnekeyType.Build) { if (File.Exists(CreatorMain.OneKeyFile)) { Task.Run(delegate { OnekeyGeneration.GenerationData(creatorAPI, CreatorMain.OneKeyFile, position); }); } else { player.ComponentGui.DisplaySmallMessage($"未发现一键生成缓存文件,目录:{CreatorMain.OneKeyFile}\n请变更一键生成类型或关闭该功能", true, true); } } else { } return(false); } if (creatorAPI.ClearBlock) { Task.Run(delegate { creatorAPI.revokeData = new ChunkData(creatorAPI); int num = 0; List <Point3> clearBlockList = new List <Point3>(); List <Point3> addList = new List <Point3>(); clearBlockList.Add(position); while (true) { if (clearBlockList.Count <= 0) { break; } foreach (Point3 point3 in clearBlockList) { if (!creatorAPI.launch) { return; } if (creatorAPI.revokeData != null && creatorAPI.revokeData.GetChunk(point3.X, point3.Z) == null) { creatorAPI.revokeData.CreateChunk(point3.X, point3.Z, true); } creatorAPI.SetBlock(point3.X, point3.Y, point3.Z, 0); num++; for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { for (int z = -1; z <= 1; z++) { if (point3.Y + y > 127) { continue; } int blockID = GameManager.Project.FindSubsystem <SubsystemTerrain>(true).Terrain.GetCellContentsFast(point3.X + x, point3.Y + y, point3.Z + z); if (blockID == 0 || blockID == 1) { continue; } if (MathUtils.Abs(x) + MathUtils.Abs(y) + MathUtils.Abs(z) > 1) { continue; } Point3 p = new Point3(point3.X + x, point3.Y + y, point3.Z + z); if (!clearBlockList.Contains(p) && !addList.Contains(p)) { addList.Add(p); } } } } } clearBlockList = addList; addList = new List <Point3>(); } player.ComponentGui.DisplaySmallMessage($"操作成功,共清除{num}个方块", true, true); }); return(false); } return(true); }
public override void Update() { if (ListView.SelectedIndex == null) { this.ImportButton.IsEnabled = false; this.DeleteButton.IsEnabled = false; } else { this.ImportButton.IsEnabled = true; this.DeleteButton.IsEnabled = true; } if (this.OK.IsClicked) { DialogsManager.HideDialog(this); } if (DeleteButton.IsClicked) { string sdFile = CreatorMain.Export_ModFile_Directory + "/" + (string)this.ListView.SelectedItem; if (FileOperation.Delete(sdFile)) { player.ComponentGui.DisplaySmallMessage("删除成功!", true, false); UpList(); } else { player.ComponentGui.DisplaySmallMessage("操作失败!", true, false); } } this.ExportOnekeyButton.IsEnabled = File.Exists(CreatorMain.OneKeyFile); this.ExportCopyButton.IsEnabled = File.Exists(CreatorMain.CopyFile); this.ExportOldCopyButton.IsEnabled = File.Exists(CreatorMain.CopyFile); this.ExportOldOnekeyButton.IsEnabled = File.Exists(CreatorMain.OneKeyFile); this.DerivedSpecialButton.IsEnabled = File.Exists(CreatorMain.SpecialCopyFile); if (this.ExportOnekeyButton.IsClicked) { DialogsManager.ShowDialog(player.View.GameWidget, new DerivedDialog(player, this, this.ListView, DataType.OneKey)); } if (this.ExportCopyButton.IsClicked) { DialogsManager.ShowDialog(player.View.GameWidget, new DerivedDialog(player, this, this.ListView)); } if (this.ExportOldCopyButton.IsClicked) { DialogsManager.ShowDialog(player.View.GameWidget, new DerivedDialog(player, this, this.ListView, DataType.OldCopy)); } if (this.ExportOldOnekeyButton.IsClicked) { DialogsManager.ShowDialog(player.View.GameWidget, new DerivedDialog(player, this, this.ListView, DataType.OldOneKey)); } if (this.DerivedSpecialButton.IsClicked) { DialogsManager.ShowDialog(player.View.GameWidget, new DerivedDialog(player, this, this.ListView, DataType.SpecialCopy)); } if (this.ImportButton.IsClicked) { Task.Run(() => { if (!Directory.Exists(CreatorMain.CacheDirectory)) { Directory.CreateDirectory(CreatorMain.CacheDirectory); } string fileName = CreatorMain.Export_ModFile_Directory + "/" + (string)this.ListView.SelectedItem; if (FileOperation.IsFileInUse(fileName)) { player.ComponentGui.DisplaySmallMessage($"操作失败...\n{fileName}", true, false); DialogsManager.HideDialog(this); return; } if (Path.GetExtension(fileName) == ".oMod2") { OnekeyGeneration.ImportOnekeyoMod2(CreatorMain.OneKeyFile, fileName); player.ComponentGui.DisplaySmallMessage("导入一键生成MOD配置文件成功!", true, false); } else if (Path.GetExtension(fileName) == ".wMod2") { CopyAndPaste.ImportCopywMod2(CreatorMain.CopyFile, fileName); player.ComponentGui.DisplaySmallMessage("导入复制MOD配置文件成功!", true, false); } else if (Path.GetExtension(fileName) == ".wMod") { CopyAndPaste.ImportCopywMod(CreatorMain.CopyFile, fileName); player.ComponentGui.DisplaySmallMessage("导入复制MOD配置文件成功!", true, false); } else if (Path.GetExtension(fileName) == ".oMod") { player.ComponentGui.DisplaySmallMessage("抱歉,一键生成的旧文件数据无法导入!", true, false); } else if (Path.GetExtension(fileName) == ".sMod") { if (!Directory.Exists(CreatorMain.CacheDirectory)) { Directory.CreateDirectory(CreatorMain.CacheDirectory); } string sdFile = CreatorMain.SpecialCopyFile; if (!FileOperation.IsFileInUse(fileName) && (!File.Exists(sdFile) || !FileOperation.IsFileInUse(sdFile))) { FileStream fileStream = new FileStream(fileName, FileMode.Open); FileStream file = new FileStream(sdFile, FileMode.Create); fileStream.CopyTo(file); file.Dispose(); fileStream.Dispose(); player.ComponentGui.DisplaySmallMessage("导入成功!", true, false); } else { player.ComponentGui.DisplaySmallMessage("操作失败!", true, false); } } else { player.ComponentGui.DisplaySmallMessage($"操作失败...\n{fileName}", true, false); } }); DialogsManager.HideDialog(this); } }