public void ToolReplacePaint(IMyCubeGrid grid, BlockMaterial oldPaint, PaintMaterial paint, bool includeSubgrids) { if (paint.Skin.HasValue) { // vanilla DLC-locked skins should use API, mod-added should use the packet to force skin change. SkinInfo skin = Main.Palette.GetSkinInfo(paint.Skin.Value); if (!skin.AlwaysOwned) { ReplaceColorInGrid(true, grid, oldPaint, paint, includeSubgrids, MyAPIGateway.Multiplayer.MyId); return; } } // for mod-added skins: Main.NetworkLibHandler.PacketReplacePaint.Send(grid, oldPaint, paint, includeSubgrids); }
public SerializedBlockMaterial(BlockMaterial material) { ColorMaskPacked = material.ColorMask.PackHSVToUint(); Skin = material.Skin; }
public bool MaterialEquals(BlockMaterial material) { return(Skin == material.Skin && Utils.ColorMaskEquals(ColorMask, material.ColorMask)); }
public bool PaintEquals(BlockMaterial blockMaterial) { return((!ColorMask.HasValue || Utils.ColorMaskEquals(ColorMask.Value, blockMaterial.ColorMask)) && (!Skin.HasValue || Skin.Value.Equals(blockMaterial.Skin))); }
/// <summary> /// <param name="sync"></param> arg determines if it sends the paint request using the API, and automatically checks skin ownership. Must be false for mod-added skins. /// </summary> public void ReplaceColorInGrid(bool sync, IMyCubeGrid selectedGrid, BlockMaterial oldPaint, PaintMaterial paint, bool includeSubgrids, ulong originalSenderSteamId) { //long timeStart = Stopwatch.GetTimestamp(); ConnectedGrids.Clear(); if (includeSubgrids) { MyAPIGateway.GridGroups.GetGroup(selectedGrid, GridLinkTypeEnum.Mechanical, ConnectedGrids); } else { ConnectedGrids.Add(selectedGrid); } bool queueCheck = paint.Skin.HasValue; // only care if new paint affects skin //int total = 0; int affected = 0; foreach (IMyCubeGrid grid in ConnectedGrids) { MyCubeGrid internalGrid = (MyCubeGrid)grid; // avoiding GetCubeBlock() lookup by feeding MySlimBlock directly // must remain `var` because it's uses a prohibited type in the generic. var enumerator = internalGrid.CubeBlocks.GetEnumerator(); try { while (enumerator.MoveNext()) { IMySlimBlock block = enumerator.Current; BlockMaterial blockMaterial = new BlockMaterial(block); if (paint.Skin.HasValue && blockMaterial.Skin != oldPaint.Skin) { continue; } if (paint.ColorMask.HasValue && !Utils.ColorMaskEquals(blockMaterial.ColorMask, oldPaint.ColorMask)) { continue; } if (sync) { grid.SkinBlocks(block.Position, block.Position, paint.ColorMask, paint.Skin?.String); if (queueCheck) { queueCheck = false; // only check first block CheckSkinned[block] = new CheckData(paint.Skin.Value); // replace, in case they swap out skins quickly } } else { internalGrid.ChangeColorAndSkin(enumerator.Current, paint.ColorMask, paint.Skin); if (queueCheck) { queueCheck = false; // only check first block CheckSkinned.Remove(block); } } affected++; } } finally { enumerator.Dispose(); } //total += grid.CubeBlocks.Count; } if (CheckSkinned.Count > 0) { SetUpdateMethods(UpdateFlags.UPDATE_AFTER_SIM, true); } //long timeEnd = Stopwatch.GetTimestamp(); if (originalSenderSteamId == MyAPIGateway.Multiplayer.MyId) { Main.Notifications.Show(2, $"Replaced color for {affected.ToString()} blocks.", MyFontEnum.Debug, 5000); //double seconds = (timeEnd - timeStart) / (double)Stopwatch.Frequency; //if(affected == total) // Main.Notifications.Show(2, $"Replaced color for all {affected.ToString()} blocks in {(seconds * 1000).ToString("0.######")}ms", MyFontEnum.White, 5000); //else // Main.Notifications.Show(2, $"Replaced color for {affected.ToString()} of {total.ToString()} blocks in {(seconds * 1000).ToString("0.######")}ms", MyFontEnum.White, 5000); } ConnectedGrids.Clear(); }