public void BrowseApplicationExecuted() { var startPath = GameApplicationPath; if (string.IsNullOrEmpty(startPath)) { startPath = ToolboxUpdater.GetSteamFilePath(); if (!string.IsNullOrEmpty(startPath)) { startPath = Path.Combine(startPath, @"SteamApps\common"); } } IsValidApplication = false; IsWrongApplication = false; var openFileDialog = _openFileDialogFactory(); openFileDialog.CheckFileExists = true; openFileDialog.CheckPathExists = true; openFileDialog.DefaultExt = "exe"; openFileDialog.FileName = "SpaceEngineers"; openFileDialog.Filter = Res.DialogLocateApplicationFilter; openFileDialog.InitialDirectory = startPath; openFileDialog.Multiselect = false; openFileDialog.Title = Res.DialogLocateApplicationTitle; // Open the dialog if (_dialogService.ShowOpenFileDialog(this, openFileDialog) == DialogResult.OK) { GameApplicationPath = openFileDialog.FileName; } }
public void LocateSpaceEngineersApplication() { var location = ToolboxUpdater.GetApplicationFilePath(); Assert.IsNotNull(location, "SpaceEgineers should be installed on developer machine"); Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine"); }
public void Load(MyCubeSize cubeSize, MyObjectBuilderType typeId, string subTypeId) { CubeList.Clear(); var list = new SortedList <string, ComponentItemModel>(); var contentPath = ToolboxUpdater.GetApplicationContentPath(); var cubeDefinitions = SpaceEngineersCore.Resources.CubeBlockDefinitions.Where(c => c.CubeSize == cubeSize); foreach (var cubeDefinition in cubeDefinitions) { var c = new ComponentItemModel { Name = cubeDefinition.DisplayNameText, TypeId = cubeDefinition.Id.TypeId, TypeIdString = cubeDefinition.Id.TypeId.ToString(), SubtypeId = cubeDefinition.Id.SubtypeName, TextureFile = (cubeDefinition.Icons == null || cubeDefinition.Icons.First() == null) ? null : SpaceEngineersCore.GetDataPathOrDefault(cubeDefinition.Icons.First(), Path.Combine(contentPath, cubeDefinition.Icons.First())), Time = TimeSpan.FromSeconds(cubeDefinition.MaxIntegrity / cubeDefinition.IntegrityPointsPerSec), Accessible = cubeDefinition.Public, Mass = SpaceEngineersApi.FetchCubeBlockMass(cubeDefinition.Id.TypeId, cubeDefinition.CubeSize, cubeDefinition.Id.SubtypeName), CubeSize = cubeDefinition.CubeSize, Size = new BindableSize3DIModel(cubeDefinition.Size), }; list.Add(c.FriendlyName + c.TypeIdString + c.SubtypeId, c); } foreach (var kvp in list) { CubeList.Add(kvp.Value); } CubeItem = CubeList.FirstOrDefault(c => c.TypeId == typeId && c.SubtypeId == subTypeId); }
public void ConvertCubeToLightArmorExecuted() { MainViewModel.IsBusy = true; MainViewModel.ResetProgress(0, Selections.Count); var contentPath = ToolboxUpdater.GetApplicationContentPath(); bool changes = false; foreach (var cubeVm in Selections) { MainViewModel.Progress++; if (cubeVm.ConvertFromHeavyToLightArmor()) { changes = true; var idx = DataModel.CubeGrid.CubeBlocks.IndexOf(cubeVm.Cube); var cubeDefinition = SpaceEngineersApi.GetCubeDefinition(cubeVm.Cube.TypeId, GridSize, cubeVm.Cube.SubtypeName); var newCube = cubeVm.CreateCube(cubeVm.Cube.TypeId, cubeVm.Cube.SubtypeName, cubeDefinition); cubeVm.TextureFile = (cubeDefinition.Icons == null || cubeDefinition.Icons.First() == null) ? null : SpaceEngineersCore.GetDataPathOrDefault(cubeDefinition.Icons.First(), Path.Combine(contentPath, cubeDefinition.Icons.First())); DataModel.CubeGrid.CubeBlocks.RemoveAt(idx); DataModel.CubeGrid.CubeBlocks.Insert(idx, newCube); } } MainViewModel.ClearProgress(); if (changes) { MainViewModel.IsModified = true; } MainViewModel.IsBusy = false; }
public void CustomModel1LoadSave() { SpaceEngineersCore.LoadDefinitions(); var location = ToolboxUpdater.GetApplicationFilePath(); Assert.IsNotNull(location, "Space Engineers should be installed on developer machine"); Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine"); var contentPath = ToolboxUpdater.GetApplicationContentPath(); var cockpitModelPath = Path.Combine(contentPath, @"Models\Characters\Animations\cockpit1_large.mwm"); Assert.IsTrue(File.Exists(cockpitModelPath), "Filepath should exist on developer machine"); var modelData = MyModel.LoadCustomModelData(cockpitModelPath); var testFilePath = @".\TestOutput\cockpit_animation.mwm"; MyModel.SaveModelData(testFilePath, modelData); var originalBytes = File.ReadAllBytes(cockpitModelPath); var newBytes = File.ReadAllBytes(testFilePath); Assert.AreEqual(originalBytes.Length, newBytes.Length, "Bytestream content must equal"); Assert.IsTrue(originalBytes.SequenceEqual(newBytes), "Bytestream content must equal"); }
public SpaceEngineersCore() { var contentPath = ToolboxUpdater.GetApplicationContentPath(); string userDataPath = SpaceEngineersConsts.BaseLocalPath.DataPath; MyFileSystem.Reset(); MyFileSystem.Init(contentPath, userDataPath); MyLog.Default = MySandboxGame.Log; MySandboxGame.Config = new MyConfig("SpaceEngineers.cfg"); // TODO: Is specific to SE, not configurable to ME. MySandboxGame.Config.Load(); MyFileSystem.InitUserSpecific(null); SpaceEngineersGame.SetupPerGameSettings(); VRageRender.MyRenderProxy.Initialize(new MyNullRender()); // We create a whole instance of MySandboxGame! MySandboxGame gameTemp = new MySandboxGame(null); // creating MySandboxGame will reset the CurrentUICulture, so I have to reapply it. Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfoByIetfLanguageTag(GlobalSettings.Default.LanguageCode); SpaceEngineersApi.LoadLocalization(); _stockDefinitions = new SpaceEngineersResources(); _stockDefinitions.LoadDefinitions(); _manageDeleteVoxelList = new List <string>(); }
public void BaseModel1LoadSave() { SpaceEngineersCore.LoadDefinitions(); var location = ToolboxUpdater.GetApplicationFilePath(); Assert.IsNotNull(location, "Space Engineers should be installed on developer machine"); Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine"); var contentPath = ToolboxUpdater.GetApplicationContentPath(); var largeThruster = (MyObjectBuilder_CubeBlockDefinition)SpaceEngineersApi.GetDefinition(SpaceEngineersTypes.Thrust, "LargeBlockLargeThrust"); var thrusterModelPath = Path.Combine(contentPath, largeThruster.Model); Assert.IsTrue(File.Exists(thrusterModelPath), "Filepath should exist on developer machine"); var modelData = MyModel.LoadModelData(thrusterModelPath); //var modelData = MyModel.LoadCustomModelData(thrusterModelPath); var testFilePath = @".\TestOutput\Thruster.mwm"; MyModel.SaveModelData(testFilePath, modelData); var originalBytes = File.ReadAllBytes(thrusterModelPath); var newBytes = File.ReadAllBytes(testFilePath); Assert.AreEqual(originalBytes.Length, newBytes.Length, "Bytestream content must equal"); Assert.IsTrue(originalBytes.SequenceEqual(newBytes), "Bytestream content must equal"); }
public void VoxelLoadStock() { SpaceEngineersCore.LoadDefinitions(); var materials = SpaceEngineersCore.Resources.GetMaterialList(); Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?"); var contentPath = ToolboxUpdater.GetApplicationContentPath(); var redShipCrashedAsteroidPath = Path.Combine(contentPath, "VoxelMaps", "RedShipCrashedAsteroid.vx2"); var voxelMap = new MyVoxelMap(); voxelMap.Load(redShipCrashedAsteroidPath, materials[0].Id.SubtypeId); Assert.AreEqual(1, voxelMap.FileVersion, "FileVersion should be equal."); IList <byte> materialAssets; Dictionary <byte, long> materialVoxelCells; voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells); Assert.AreEqual(563742, materialAssets.Count, "Asset count should be equal."); var asset0 = materialAssets.Where(c => c == 0).ToList(); Assert.AreEqual(563742, asset0.Count, "asset0 count should be equal."); var assetNameCount = voxelMap.CountAssets(materialAssets); Assert.IsTrue(assetNameCount.Count > 0, "Contains assets."); var lengthOriginal = new FileInfo(redShipCrashedAsteroidPath).Length; Assert.AreEqual(51819, lengthOriginal, "File size must match."); }
public void CreateMenuTextures() { SpaceEngineersCore.LoadDefinitions(); var location = ToolboxUpdater.GetApplicationFilePath(); Assert.IsNotNull(location, "Space Engineers should be installed on developer machine"); Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine"); var contentPath = ToolboxUpdater.GetApplicationContentPath(); var smallBlockLandingGear = SpaceEngineersApi.GetDefinition(new MyObjectBuilderType(typeof(MyObjectBuilder_LandingGear)), "SmallBlockLandingGear"); var smallBlockLandingGearPath = Path.Combine(contentPath, smallBlockLandingGear.Icons.First()); Assert.IsTrue(File.Exists(smallBlockLandingGearPath), "Filepath should exist on developer machine"); Assert.IsTrue(smallBlockLandingGear is MyObjectBuilder_CubeBlockDefinition, "Type should match"); var smallBlockLandingGearBmp = TexUtil.CreateBitmap(smallBlockLandingGearPath); var gridItemPath = Path.Combine(contentPath, @"Textures\GUI\Controls\grid_item.dds"); Assert.IsTrue(File.Exists(gridItemPath), "Filepath should exist on developer machine"); var gridBmp = TexUtil.CreateBitmap(gridItemPath); var bmp = ImageTextureUtil.MergeImages(gridBmp, smallBlockLandingGearBmp, Brushes.Black); ImageTextureUtil.WriteImage(bmp, @".\TestOutput\Menu_SmallBlockLandingGear.png"); }
public void ReadBackgroundTextures() { var location = ToolboxUpdater.GetApplicationFilePath(); Assert.IsNotNull(location, "Space Engineers should be installed on developer machine"); Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine"); var contentPath = ToolboxUpdater.GetApplicationContentPath(); var backgroundPath = Path.Combine(contentPath, @"Textures\BackgroundCube\Final\BackgroundCube.dds"); Assert.IsTrue(File.Exists(backgroundPath), "Filepath should exist on developer machine"); var backgroundBmp = TexUtil.CreateBitmap(backgroundPath, 0, -1, -1); ImageTextureUtil.WriteImage(backgroundBmp, @".\TestOutput\BackgroundCube0_Full.png"); backgroundBmp = TexUtil.CreateBitmap(backgroundPath, 1, 1024, 1024); ImageTextureUtil.WriteImage(backgroundBmp, @".\TestOutput\BackgroundCube1_1024.png"); backgroundBmp = TexUtil.CreateBitmap(backgroundPath, 2, 512, 512); ImageTextureUtil.WriteImage(backgroundBmp, @".\TestOutput\BackgroundCube2_512.png"); backgroundBmp = TexUtil.CreateBitmap(backgroundPath, 3, 128, 128); ImageTextureUtil.WriteImage(backgroundBmp, @".\TestOutput\BackgroundCube3_128.png"); backgroundBmp = TexUtil.CreateBitmap(backgroundPath, 4, 64, 64); ImageTextureUtil.WriteImage(backgroundBmp, @".\TestOutput\BackgroundCube4_64.png"); backgroundBmp = TexUtil.CreateBitmap(backgroundPath, 5, 32, 32); ImageTextureUtil.WriteImage(backgroundBmp, @".\TestOutput\BackgroundCube5_32.png"); }
/// <summary> /// Updates the base library files from the Space Engineers application path. /// </summary> /// <param name="appFilePath"></param> /// <returns>True if it succeeded, False if there was an issue that blocked it.</returns> private static bool UpdateBaseFiles(string appFilePath) { var counter = 0; // Wait until SEToolbox is shut down. while (Process.GetProcessesByName("SEToolbox").Length > 0) { System.Threading.Thread.Sleep(100); counter++; if (counter > 100) { // 10 seconds is too long. Abort. return(false); } } var baseFilePath = ToolboxUpdater.GetApplicationFilePath(); foreach (var filename in ToolboxUpdater.CoreSpaceEngineersFiles) { var sourceFile = Path.Combine(baseFilePath, filename); try { if (File.Exists(sourceFile)) { File.Copy(sourceFile, Path.Combine(appFilePath, filename), true); } else { return(false); } } catch { return(false); } } foreach (var filename in ToolboxUpdater.OptionalSpaceEngineersFiles) { var sourceFile = Path.Combine(baseFilePath, filename); try { if (File.Exists(sourceFile)) { File.Copy(sourceFile, Path.Combine(appFilePath, filename), true); } } catch { return(false); } } return(true); }
internal void Additem(MyObjectBuilder_InventoryItem item) { var contentPath = ToolboxUpdater.GetApplicationContentPath(); item.ItemId = _inventory.nextItemId++; _inventory.Items.Add(item); Items.Add(CreateItem(item, contentPath)); }
public SpaceEngineersCore() { var contentPath = ToolboxUpdater.GetApplicationContentPath(); string userDataPath = SpaceEngineersConsts.BaseLocalPath.DataPath; MyFileSystem.Reset(); MyFileSystem.Init(contentPath, userDataPath); MyLog.Default = MySandboxGame.Log; MySandboxGame.Config = new MyConfig("SpaceEngineers.cfg"); // TODO: Is specific to SE, not configurable to ME. MySandboxGame.Config.Load(); MyFileSystem.InitUserSpecific(null); SpaceEngineersGame.SetupPerGameSettings(); VRageRender.MyRenderProxy.Initialize(new MyNullRender()); // We create a whole instance of MySandboxGame! // If this is causing an exception, then there is a missing dependency. MySandboxGame gameTemp = new MySandboxGame(new string[] { "-skipintro" }); // creating MySandboxGame will reset the CurrentUICulture, so I have to reapply it. Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfoByIetfLanguageTag(GlobalSettings.Default.LanguageCode); SpaceEngineersApi.LoadLocalization(); MyStorageBase.UseStorageCache = false; #region MySession creation // Replace the private constructor on MySession, so we can create it without getting involed with Havok and other depdancies. var keenStart = typeof(Sandbox.Game.World.MySession).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(MySyncLayer), typeof(bool) }, null); var ourStart = typeof(SEToolbox.Interop.MySession).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(MySyncLayer), typeof(bool) }, null); ReflectionUtil.ReplaceMethod(ourStart, keenStart); // Create an empty instance of MySession for use by low level code. Sandbox.Game.World.MySession mySession = ReflectionUtil.ConstructPrivateClass <Sandbox.Game.World.MySession>(new Type[0], new object[0]); ReflectionUtil.ConstructField(mySession, "m_sessionComponents"); // Required as the above code doesn't populate it during ctor of MySession. mySession.Settings = new MyObjectBuilder_SessionSettings { EnableVoxelDestruction = true }; VRage.MyVRage.Init(new ToolboxPlatform()); // change for the Clone() method to use XML cloning instead of Protobuf because of issues with MyObjectBuilder_CubeGrid.Clone() ReflectionUtil.SetFieldValue(typeof(VRage.ObjectBuilders.MyObjectBuilderSerializer), "ENABLE_PROTOBUFFERS_CLONING", false); // Assign the instance back to the static. Sandbox.Game.World.MySession.Static = mySession; Sandbox.Game.GameSystems.MyHeightMapLoadingSystem.Static = new MyHeightMapLoadingSystem(); Sandbox.Game.GameSystems.MyHeightMapLoadingSystem.Static.LoadData(); #endregion _stockDefinitions = new SpaceEngineersResources(); _stockDefinitions.LoadDefinitions(); _manageDeleteVoxelList = new List <string>(); }
public void LoadAllCubeTextures() { var files = Directory.GetFiles(Path.Combine(ToolboxUpdater.GetApplicationContentPath(), @"Textures\Models\Cubes"), "*.dds"); foreach (var filename in files) { var outputFilename = Path.Combine(@".\TestOutput", Path.GetFileNameWithoutExtension(filename) + ".png"); var imageBitmap = TestLoadTexture(filename); ImageTextureUtil.WriteImage(imageBitmap, outputFilename); } }
/// <summary> /// Clear app bin cache. /// </summary> private static void CleanBinCache() { var binCache = ToolboxUpdater.GetBinCachePath(); if (Directory.Exists(binCache)) { try { Directory.Delete(binCache, true); } catch { } } }
//[TestMethod] public void LoadModelFailures() { SpaceEngineersCore.LoadDefinitions(); var location = ToolboxUpdater.GetApplicationFilePath(); Assert.IsNotNull(location, "Space Engineers should be installed on developer machine"); Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine"); var contentPath = ToolboxUpdater.GetApplicationContentPath(); var files = Directory.GetFiles(Path.Combine(contentPath, "Models"), "*.mwm", SearchOption.AllDirectories); var badList = new List <string>(); var convertDiffers = new List <string>(); foreach (var file in files) { Dictionary <string, object> data = null; try { data = MyModel.LoadModelData(file); //data = MyModel.LoadCustomModelData(file); } catch (Exception) { badList.Add(file); continue; } if (data != null) { var testFilePath = @".\TestOutput\TempModelTest.mwm"; MyModel.SaveModelData(testFilePath, data); var originalBytes = File.ReadAllBytes(file); var newBytes = File.ReadAllBytes(testFilePath); if (!originalBytes.SequenceEqual(newBytes)) { convertDiffers.Add(file); } //Assert.AreEqual(originalBytes.Length, newBytes.Length, "File {0} Bytestream content must equal", file); //Assert.IsTrue(originalBytes.SequenceEqual(newBytes), "File {0} Bytestream content must equal", file); } } Assert.IsTrue(convertDiffers.Count > 0, ""); Assert.IsTrue(badList.Count > 0, ""); }
public static void LoadLocalization() { var languageTag = System.Threading.Thread.CurrentThread.CurrentUICulture.IetfLanguageTag; var contentPath = ToolboxUpdater.GetApplicationContentPath(); var localizationPath = Path.Combine(contentPath, @"Data\Localization"); var codes = languageTag.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); var maincode = codes.Length > 0 ? codes[0] : null; var subcode = codes.Length > 1 ? codes[1] : null; MyTexts.Clear(); MyTexts.LoadTexts(localizationPath, maincode, subcode); }
public void LoadComponentTexturesDx10PremultipliedAlpha() { var location = ToolboxUpdater.GetApplicationFilePath(); Assert.IsNotNull(location, "Space Engineers should be installed on developer machine"); Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine"); var contentPath = ToolboxUpdater.GetApplicationContentPath(); TestLoadTextureAndExport(Path.Combine(contentPath, @"Textures\GUI\Icons\Cubes\AdvancedMotor.dds")); TestLoadTextureAndExport(Path.Combine(contentPath, @"Textures\GUI\Icons\component\ExplosivesComponent.dds")); }
public static void LoadLocalization() { var culture = System.Threading.Thread.CurrentThread.CurrentUICulture; var languageTag = culture.IetfLanguageTag; var contentPath = ToolboxUpdater.GetApplicationContentPath(); var localizationPath = Path.Combine(contentPath, @"Data\Localization"); var codes = languageTag.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); var maincode = codes.Length > 0 ? codes[0] : null; var subcode = codes.Length > 1 ? codes[1] : null; MyTexts.Clear(); if (GlobalSettings.Default.UseCustomResource.HasValue && GlobalSettings.Default.UseCustomResource.Value) { // no longer required, as Chinese is now officially in game. // left as an example for later additional custom languages. //AddLanguage(MyLanguagesEnum.ChineseChina, "zh-CN", null, "Chinese", 1f, true); } MyTexts.LoadTexts(localizationPath, maincode, subcode); if (GlobalSettings.Default.UseCustomResource.HasValue && GlobalSettings.Default.UseCustomResource.Value) { // Load alternate localization in instead using game refined resources, as they may not yet exist. ResourceManager customGameResourceManager = new ResourceManager("SEToolbox.Properties.MyTexts", Assembly.GetExecutingAssembly()); ResourceSet customResourceSet = customGameResourceManager.GetResourceSet(culture, true, false); if (customResourceSet != null) { // Reflection copy of MyTexts.PatchTexts(string resourceFile) var m_strings = typeof(MyTexts).GetStaticField <Dictionary <MyStringId, string> >("m_strings"); var m_stringBuilders = typeof(MyTexts).GetStaticField <Dictionary <MyStringId, StringBuilder> >("m_stringBuilders"); foreach (DictionaryEntry dictionaryEntry in customResourceSet) { string text = dictionaryEntry.Key as string; string text2 = dictionaryEntry.Value as string; if (text != null && text2 != null) { MyStringId orCompute = MyStringId.GetOrCompute(text); m_strings[orCompute] = text2; m_stringBuilders[orCompute] = new StringBuilder(text2); } } } } }
public void LoadComponentTexturesDx11() { var location = ToolboxUpdater.GetApplicationFilePath(); Assert.IsNotNull(location, "Space Engineers should be installed on developer machine"); Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine"); var contentPath = ToolboxUpdater.GetApplicationContentPath(); TestLoadTextureAndExport(Path.Combine(contentPath, @"Textures\Models\Cubes\large_medical_room_cm.dds")); TestLoadTextureAndExport(Path.Combine(contentPath, @"Textures\Models\Cubes\large_medical_room_cm.dds"), true); }
public void CreateBackgroundPreview() { const int size = 128; const bool ignoreAlpha = true; var location = ToolboxUpdater.GetApplicationFilePath(); Assert.IsNotNull(location, "Space Engineers should be installed on developer machine"); Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine"); var contentPath = ToolboxUpdater.GetApplicationContentPath(); var backgroundPath = Path.Combine(contentPath, @"Textures\BackgroundCube\Final\BackgroundCube.dds"); Assert.IsTrue(File.Exists(backgroundPath), "Filepath should exist on developer machine"); var result = new Bitmap(size * 4, size * 3); using (var graphics = Graphics.FromImage(result)) { //set the resize quality modes to high quality graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; if (ignoreAlpha) { graphics.FillRectangle(Brushes.Black, size * 2, size * 1, size, size); graphics.FillRectangle(Brushes.Black, size * 0, size * 1, size, size); graphics.FillRectangle(Brushes.Black, size * 1, size * 0, size, size); graphics.FillRectangle(Brushes.Black, size * 1, size * 2, size, size); graphics.FillRectangle(Brushes.Black, size * 1, size * 1, size, size); graphics.FillRectangle(Brushes.Black, size * 3, size * 1, size, size); } graphics.DrawImage(TexUtil.CreateBitmap(backgroundPath, 0, size, size, ignoreAlpha), size * 2, size * 1, size, size); graphics.DrawImage(TexUtil.CreateBitmap(backgroundPath, 1, size, size, ignoreAlpha), size * 0, size * 1, size, size); graphics.DrawImage(TexUtil.CreateBitmap(backgroundPath, 2, size, size, ignoreAlpha), size * 1, size * 0, size, size); graphics.DrawImage(TexUtil.CreateBitmap(backgroundPath, 3, size, size, ignoreAlpha), size * 1, size * 2, size, size); graphics.DrawImage(TexUtil.CreateBitmap(backgroundPath, 4, size, size, ignoreAlpha), size * 1, size * 1, size, size); graphics.DrawImage(TexUtil.CreateBitmap(backgroundPath, 5, size, size, ignoreAlpha), size * 3, size * 1, size, size); // Approximate position of local Sun and light source. graphics.FillEllipse(Brushes.White, size * 1 + (int)(size * 0.7), size * 2 + (int)(size * 0.93), (int)(size * 0.06), (int)(size * 0.06)); } ImageTextureUtil.WriteImage(result, string.Format(@".\TestOutput\BackgroundCube_{0}.png", size)); }
public void Load(MyPositionAndOrientation characterPosition) { CharacterPosition = characterPosition; var vms = SpaceEngineersCore.Resources.Definitions.VoxelMapStorages; var contentPath = ToolboxUpdater.GetApplicationContentPath(); foreach (var voxelMap in vms) { var fileName = SpaceEngineersCore.GetDataPathOrDefault(voxelMap.StorageFile, Path.Combine(contentPath, voxelMap.StorageFile)); if (!File.Exists(fileName)) { continue; } var voxel = new GenerateVoxelDetailModel { Name = Path.GetFileNameWithoutExtension(voxelMap.StorageFile), SourceFilename = fileName, FileSize = new FileInfo(fileName).Length, Size = MyVoxelMap.LoadVoxelSize(fileName) }; VoxelFileList.Add(voxel); } // Custom voxel files directory. List <string> files = new List <string>(); if (!string.IsNullOrEmpty(GlobalSettings.Default.CustomVoxelPath) && Directory.Exists(GlobalSettings.Default.CustomVoxelPath)) { files.AddRange(Directory.GetFiles(GlobalSettings.Default.CustomVoxelPath, "*" + MyVoxelMap.V1FileExtension)); files.AddRange(Directory.GetFiles(GlobalSettings.Default.CustomVoxelPath, "*" + MyVoxelMap.V2FileExtension)); } VoxelFileList.AddRange(files.Select(file => new GenerateVoxelDetailModel { Name = Path.GetFileNameWithoutExtension(file), SourceFilename = file, FileSize = new FileInfo(file).Length, Size = MyVoxelMap.LoadVoxelSize(file) })); VoxelFileList = VoxelFileList.OrderBy(s => s.Name).ToList(); }
public void LoadSandbox_Compressed_BaseEasyStart() { var contentPath = ToolboxUpdater.GetApplicationContentPath(); var baseEasyStart1Path = Path.Combine(contentPath, @"Data\Prefabs\LargeShipRed.sbc"); Assert.IsTrue(File.Exists(baseEasyStart1Path), "Sandbox content file should exist"); MyObjectBuilder_Definitions prefabDefinitions; bool isCompressed; var ret = SpaceEngineersApi.TryReadSpaceEngineersFile(baseEasyStart1Path, out prefabDefinitions, out isCompressed); Assert.IsNotNull(prefabDefinitions, "Sandbox content should not be null"); Assert.IsTrue(ret, "Sandbox content should have been detected"); Assert.IsTrue(isCompressed, "Sandbox content should be compressed"); Assert.IsTrue(prefabDefinitions.Prefabs[0].CubeGrid.CubeBlocks.Count > 10, "Sandbox content should have cube blocks"); }
public void BrowseAppPathExecuted() { var startPath = SEBinPath; if (string.IsNullOrEmpty(startPath)) { startPath = ToolboxUpdater.GetSteamFilePath(); if (!string.IsNullOrEmpty(startPath)) { startPath = Path.Combine(startPath, @"SteamApps\common"); } } var openFileDialog = _openFileDialogFactory(); openFileDialog.CheckFileExists = true; openFileDialog.CheckPathExists = true; openFileDialog.DefaultExt = "exe"; openFileDialog.FileName = "SpaceEngineers"; openFileDialog.Filter = Res.DialogLocateApplicationFilter; openFileDialog.InitialDirectory = startPath; openFileDialog.Multiselect = false; openFileDialog.Title = Res.DialogLocateApplicationTitle; // Open the dialog if (_dialogService.ShowOpenFileDialog(this, openFileDialog) == DialogResult.OK) { var gameBinPath = openFileDialog.FileName; if (!string.IsNullOrEmpty(gameBinPath)) { try { var fullPath = Path.GetFullPath(gameBinPath); if (File.Exists(fullPath)) { gameBinPath = Path.GetDirectoryName(fullPath); } } catch { } } SEBinPath = gameBinPath; } }
public StructureVoxelModel(MyObjectBuilder_EntityBase entityBase, string voxelPath) : base(entityBase) { var contentPath = ToolboxUpdater.GetApplicationContentPath(); if (voxelPath != null) { VoxelFilepath = Path.Combine(voxelPath, Name + MyVoxelMap.V2FileExtension); var previewFile = VoxelFilepath; if (!File.Exists(VoxelFilepath)) { var oldFilepath = Path.Combine(voxelPath, Name + MyVoxelMap.V1FileExtension); if (File.Exists(oldFilepath)) { SourceVoxelFilepath = oldFilepath; previewFile = oldFilepath; SpaceEngineersCore.ManageDeleteVoxelList.Add(oldFilepath); } } // Has a huge upfront loading cost //ReadVoxelDetails(previewFile); } var materialList = new Dictionary <string, string>(); foreach (MyVoxelMaterialDefinition item in SpaceEngineersCore.Resources.VoxelMaterialDefinitions.OrderBy(m => m.Id.SubtypeName)) { string texture = item.GetVoxelDisplayTexture(); materialList.Add(item.Id.SubtypeName, texture == null ? null : SpaceEngineersCore.GetDataPathOrDefault(texture, Path.Combine(contentPath, texture))); } GameMaterialList = new List <VoxelMaterialAssetModel>(materialList.Select(m => new VoxelMaterialAssetModel { MaterialName = m.Key, DisplayName = m.Key, TextureFile = m.Value })); EditMaterialList = new List <VoxelMaterialAssetModel> { new VoxelMaterialAssetModel { MaterialName = null, DisplayName = Res.CtlVoxelMnuRemoveMaterial } }; EditMaterialList.AddRange(materialList.Select(m => new VoxelMaterialAssetModel { MaterialName = m.Key, DisplayName = m.Key, TextureFile = m.Value })); }
public static void LoadLocalization() { var culture = System.Threading.Thread.CurrentThread.CurrentUICulture; var languageTag = culture.IetfLanguageTag; var contentPath = ToolboxUpdater.GetApplicationContentPath(); var localizationPath = Path.Combine(contentPath, @"Data\Localization"); var codes = languageTag.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); var maincode = codes.Length > 0 ? codes[0] : null; var subcode = codes.Length > 1 ? codes[1] : null; MyTexts.Clear(); MyTexts.LoadTexts(localizationPath, maincode, subcode); GlobalSettings.Default.UseCustomResource = !MyTexts.Languages.Any(m => m.Value.FullCultureName.Equals(culture.IetfLanguageTag, StringComparison.InvariantCultureIgnoreCase) || m.Value.CultureName.Equals(culture.Parent.IetfLanguageTag, StringComparison.InvariantCultureIgnoreCase)); }
public void LoadSandbox_Fighter() { var contentPath = ToolboxUpdater.GetApplicationContentPath(); var fighterPath = Path.Combine(contentPath, @"Data\Prefabs\Fighter.sbc"); Assert.IsTrue(File.Exists(fighterPath), "Sandbox content file should exist"); MyObjectBuilder_Definitions prefabDefinitions; bool isCompressed; string errorInformation; var ret = SpaceEngineersApi.TryReadSpaceEngineersFile(fighterPath, out prefabDefinitions, out isCompressed, out errorInformation); Assert.IsNotNull(prefabDefinitions, "Sandbox content should not be null"); Assert.IsTrue(ret, "Sandbox content should have been detected"); Assert.IsFalse(isCompressed, "Sandbox content should not be compressed"); Assert.IsTrue(prefabDefinitions.Prefabs[0].CubeGrids[0].CubeBlocks.Count > 10, "Sandbox content should have cube blocks"); }
private void UpdateGeneralFromEntityBase() { var list = new ObservableCollection <InventoryModel>(); var contentPath = ToolboxUpdater.GetApplicationContentPath(); TotalVolume = 0; TotalMass = 0; if (_inventory != null) { foreach (MyObjectBuilder_InventoryItem item in _inventory.Items) { list.Add(CreateItem(item, contentPath)); } } Items = list; }
public void Validate() { GameBinPath = null; if (!string.IsNullOrEmpty(GameApplicationPath)) { try { var fullPath = Path.GetFullPath(GameApplicationPath); if (File.Exists(fullPath)) { GameBinPath = Path.GetDirectoryName(fullPath); } } catch { } } IsValidApplication = ToolboxUpdater.ValidateSpaceEngineersInstall(GameBinPath); IsWrongApplication = !IsValidApplication; }
public void ReplaceCubesExecuted() { var model = new SelectCubeModel(); var loadVm = new SelectCubeViewModel(this, model); model.Load(GridSize, SelectedCubeItem.Cube.TypeId, SelectedCubeItem.SubtypeId); var result = _dialogService.ShowDialog <WindowSelectCube>(this, loadVm); if (result == true) { MainViewModel.IsBusy = true; var contentPath = ToolboxUpdater.GetApplicationContentPath(); var change = false; MainViewModel.ResetProgress(0, Selections.Count); foreach (var cube in Selections) { MainViewModel.Progress++; if (cube.TypeId != model.CubeItem.TypeId || cube.SubtypeId != model.CubeItem.SubtypeId) { var idx = DataModel.CubeGrid.CubeBlocks.IndexOf(cube.Cube); DataModel.CubeGrid.CubeBlocks.RemoveAt(idx); var cubeDefinition = SpaceEngineersApi.GetCubeDefinition(model.CubeItem.TypeId, GridSize, model.CubeItem.SubtypeId); var newCube = cube.CreateCube(model.CubeItem.TypeId, model.CubeItem.SubtypeId, cubeDefinition); cube.TextureFile = SpaceEngineersCore.GetDataPathOrDefault(cubeDefinition.Icon, Path.Combine(contentPath, cubeDefinition.Icon)); DataModel.CubeGrid.CubeBlocks.Insert(idx, newCube); change = true; } } MainViewModel.ClearProgress(); if (change) { MainViewModel.IsModified = true; } MainViewModel.IsBusy = false; } }