public void AddSwatch(Color color, SwatchType type) { // Check for Bad Data if (color == null) { return; } // No Player Duplicates if (Swatches.FindIndex(i => i.color == color) >= 0) { return; } Swatch swatch = MakeSwatch(color); if (swatch == null) { return; } if (type == SwatchType.Player) { District.PlayerAddedColors.Add(ColorConversions.ConvertColorToVector3(color)); } else { District.DefaultAddedColors.Add(ColorConversions.ConvertColorToVector3(color)); } }
/// <summary> /// Sets up the properties of an instantiated generator, using the given parameters. /// </summary> /// <param name="generator">Generator to set up.</param> /// <param name="handX">String value for the horizontal hand offset in pixels, presumably from a text field. /// Value should be convertable to an integer.</param> /// <param name="handY">String value for the vertical hand offset in pixels, presumably from a text field. /// Value should be convertable to an integer.</param> /// <param name="ignoreColor">String value of the color to ignore, presumably from a text field. /// If given, value should be formatted RRGGBB or RRGGBBAA (hexadecimal string).</param> /// <returns>Reference to the given object.</returns> public static DrawablesGenerator SetUpGenerator(DrawablesGenerator generator, string handX, string handY, string ignoreColor = null) { generator.OffsetX = Convert.ToInt32(handX) + 1; generator.OffsetY = Convert.ToInt32(handY); generator.RotateFlipStyle = System.Drawing.RotateFlipType.RotateNoneFlipY; generator.ReplaceBlank = true; generator.ReplaceWhite = true; string colorString = ignoreColor.Replace("#", ""); if (colorString.Length == 6 || colorString.Length == 8) { int r = ColorConversions.HexToInt(colorString.Substring(0, 2)); r = Clamp(r, 0, 255); int g = ColorConversions.HexToInt(colorString.Substring(2, 2)); g = Clamp(g, 0, 255); int b = ColorConversions.HexToInt(colorString.Substring(4, 2)); b = Clamp(b, 0, 255); int a = colorString.Length == 8 ? ColorConversions.HexToInt(colorString.Substring(6, 2)) : 255; a = Clamp(a, 0, 255); generator.IgnoreColor = System.Drawing.Color.FromArgb(a, r, g, b); } return(generator); }
public void OnLoaded(object sender, OnLoadedEvent loadedEvent) { try{ foreach (Vector3 vector in District.PlayerAddedColors.ToArray()) { Color color = ColorConversions.ConvertVector3ToColor(vector); Swatch swatch = District.Swatches.Find(i => i.color == color); if (swatch != null) { District.Swatches.Remove(swatch); Destroy(swatch.gameObject); } } }catch (Exception err) { Mod.helper.Log(err.ToString()); } string json = LoadSave.ReadDataGeneric("DistrictModV2", "DistrictModV2Identifier"); if (json != null) { var savedObject = Newtonsoft.Json.JsonConvert.DeserializeObject <DistrictSave>(json); District.DistrictBuildingData = savedObject.DistrictBuildingData; District.PlayerAddedColors = ColorConversions.ConvertArrayToList(savedObject.PlayerAddedColors); } else { Mod.helper.Log("JSON IS NULL"); } LoadSwatches(); LoadBuildingColors(); }
public IEnumerable <Color> GetColors(Bitmap source) { for (int y = 0; y < source.Height; y++) { for (int x = 0; x < source.Width; x++) { yield return(ColorConversions.SystemColorToColor(source.GetPixel(x, y))); } } }
void LoadSwatches() { try{ foreach (Vector3 vector in District.PlayerAddedColors.ToArray()) { Color color = ColorConversions.ConvertVector3ToColor(vector); AddSwatch(color, SwatchType.Player); } }catch (Exception err) { Mod.helper.Log(err.ToString()); } }
void LoadBuildingColors() { foreach (KeyValuePair <Guid, Vector3[]> entry in District.DistrictBuildingData) { Building b = Player.inst.GetBuilding(entry.Key); if (b != null) { for (int i = 0; i < b.fullMaterial.Count; i++) { if (entry.Value[i] != null) { this.ApplyShader(b.fullMaterial[i]); b.fullMaterial[i].color = ColorConversions.ConvertVector3ToColor(entry.Value[i]); b.useSharedMaterialIfPossible = false; b.UpdateMaterialSelection(); } } } } }
public void AssignColor(Color color) { if (District.DistrictBuildingData.ContainsKey(this.currentBuilding.guid)) { currentColors = District.DistrictBuildingData[this.currentBuilding.guid]; } else { currentColors = new Vector3[this.currentBuilding.fullMaterial.Count]; } currentColors[this.dropdown.value] = ColorConversions.ConvertColorToVector3(color); this.ApplyShader(this.currentBuilding.fullMaterial[this.dropdown.value]); this.currentBuilding.fullMaterial[this.dropdown.value].color = color; this.currentBuilding.useSharedMaterialIfPossible = false; AssignColorEvent(color); District.DistrictBuildingData[this.currentBuilding.guid] = this.currentColors; this.currentBuilding.UpdateMaterialSelection(); }
public Bitmap ReplaceColors(Bitmap xml, IEnumerable <Color> colors) { int x = 0; int y = 0; foreach (var color in colors) { if (y >= xml.Height || x >= xml.Width) { break; } xml.SetPixel(x, y, ColorConversions.ColorToSystemColor(color)); x++; if (x >= xml.Width) { x = 0; y++; } } return(xml); }
public void TestGenerate() { int w = 4, h = 4; string path = CreateTempBitmap(w * 32, h * 8); try { DrawablesGenerator dg = new DrawablesGenerator(path); DrawablesOutput dOutput = dg.Generate(); for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { Drawable drawable = dOutput.Drawables[i, j]; StringBuilder debuilder = new StringBuilder(drawable.Directives); debuilder.Remove(0, 8); while (debuilder.Length >= 18) { string from = debuilder.ToString(1, 6), to = debuilder.ToString(10, 6); int rFrom = Convert.ToInt32(from.Substring(0, 2)), bFrom = Convert.ToInt32(from.Substring(4, 2)); int rTo = ColorConversions.HexToInt(to.Substring(0, 2)), bTo = ColorConversions.HexToInt(to.Substring(4, 2)); if (rTo > 32) { rTo = --rTo % 32; rTo++; } if (bTo > 8) { bTo = --bTo % 8; bTo++; } Assert.AreEqual(rFrom, rTo); Assert.AreEqual(bFrom, bTo); debuilder.Remove(0, 18); } } } } } dg.IgnoreColor = Color.Blue; dg.OffsetX = 5; dg.OffsetY = 3; dg.Generate(); dg.ReplaceBlank = true; dg.ReplaceWhite = true; dg.Generate(); dg.RotateFlipStyle = RotateFlipType.Rotate180FlipY; dg.Generate(); } catch (DrawableException exc) { Assert.Fail(exc.Message); } finally { if (File.Exists(path)) { File.Delete(path); } } }