public void RecolorBlocks(IMyCubeGrid grid, List <Vector3D> oldColors, List <Vector3D> newColors, List <string> newSkins) { for (int j = AllBlocks.Count - 1; j >= 0; j--) { var block = AllBlocks[j]; if (!CheckBlockValid(block)) { AllTerminalBlocks.RemoveAt(j); continue; } if (block.CubeGrid != grid) { continue; } for (int i = 0; i < oldColors.Count; i++) { if (i >= newColors.Count && i >= newSkins.Count) { break; } if (Math.Round(oldColors[i].X, 3) != Math.Round(block.ColorMaskHSV.X, 3)) { continue; } if (Math.Round(oldColors[i].Y, 3) != Math.Round(block.ColorMaskHSV.Y, 3)) { continue; } if (Math.Round(oldColors[i].Z, 3) != Math.Round(block.ColorMaskHSV.Z, 3)) { continue; } if (i < newColors.Count) { if (newColors[i] != new Vector3D(-10, -10, -10)) { grid.ColorBlocks(block.Min, block.Min, newColors[i]); } } if (i < newSkins.Count) { if (!string.IsNullOrWhiteSpace(newSkins[i])) { grid.SkinBlocks(block.Min, block.Min, null, newSkins[i]); } } } } }
/// <summary> /// Colours a block according to its integrity. /// </summary> private static void ColourBlock(IMySlimBlock realBlock, IMyCubeGrid holoGrid) { Logger.DebugLog("realBlock == null", Logger.severity.FATAL, condition: realBlock == null); float integrityRatio = (realBlock.BuildIntegrity - realBlock.CurrentDamage) / realBlock.MaxIntegrity; float criticalRatio = ((MyCubeBlockDefinition)realBlock.BlockDefinition).CriticalIntegrityRatio; float scaledRatio; Color blockColour; Logger.DebugLog("integrityRatio: " + integrityRatio + ", criticalRatio: " + criticalRatio + ", fatblock: " + realBlock.FatBlock.getBestName() + ", functional: " + (realBlock.FatBlock != null && realBlock.FatBlock.IsFunctional), condition: integrityRatio != 1f); if (integrityRatio > criticalRatio && (realBlock.FatBlock == null || realBlock.FatBlock.IsFunctional)) { scaledRatio = (integrityRatio - criticalRatio) / (1f - criticalRatio); blockColour = IntegrityFull * scaledRatio + IntegrityFunctional * (1f - scaledRatio); } else { scaledRatio = integrityRatio / criticalRatio; blockColour = IntegrityDamaged * scaledRatio + IntegrityZero * (1f - scaledRatio); } holoGrid.ColorBlocks(realBlock.Position, realBlock.Position, blockColour.ColorToHSVDX11()); }
/// <summary> /// Colours a block according to its integrity. /// </summary> private static void ColourBlock(IMySlimBlock realBlock, IMyCubeGrid holoGrid) { Static.logger.debugLog(realBlock == null, "realBlock == null", Logger.severity.FATAL); float integrityRatio = (realBlock.BuildIntegrity - realBlock.CurrentDamage) / realBlock.MaxIntegrity; float criticalRatio = ((MyCubeBlockDefinition)realBlock.BlockDefinition).CriticalIntegrityRatio; float scaledRatio; Color blockColour; Static.logger.debugLog(integrityRatio != 1f, "integrityRatio: " + integrityRatio + ", criticalRatio: " + criticalRatio + ", fatblock: " + realBlock.FatBlock.getBestName() + ", functional: " + (realBlock.FatBlock != null && realBlock.FatBlock.IsFunctional)); if (integrityRatio > criticalRatio && (realBlock.FatBlock == null || realBlock.FatBlock.IsFunctional)) { scaledRatio = (integrityRatio - criticalRatio) / (1f - criticalRatio); blockColour = IntegrityFull * scaledRatio + IntegrityFunctional * (1f - scaledRatio); } else { scaledRatio = integrityRatio / criticalRatio; blockColour = IntegrityDamaged * scaledRatio + IntegrityZero * (1f - scaledRatio); } holoGrid.ColorBlocks(realBlock.Position, realBlock.Position, blockColour.ColorToHSVDX11()); }