TeamColor.cs (7710B)
1 // 2 // Copyright 2020 Electronic Arts Inc. 3 // 4 // The Command & Conquer Map Editor and corresponding source code is free 5 // software: you can redistribute it and/or modify it under the terms of 6 // the GNU General Public License as published by the Free Software Foundation, 7 // either version 3 of the License, or (at your option) any later version. 8 9 // The Command & Conquer Map Editor and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 using System.Drawing; 16 using System.Numerics; 17 using System.Xml; 18 19 namespace MobiusEditor.Utility 20 { 21 public class TeamColor 22 { 23 private readonly TeamColorManager teamColorManager; 24 private readonly MegafileManager megafileManager; 25 26 public string Variant { get; private set; } 27 28 public string Name { get; private set; } 29 30 private Color? lowerBounds; 31 public Color LowerBounds => lowerBounds.HasValue ? lowerBounds.Value : ((Variant != null) ? teamColorManager[Variant].LowerBounds : default); 32 33 private Color? upperBounds; 34 public Color UpperBounds => upperBounds.HasValue ? upperBounds.Value : ((Variant != null) ? teamColorManager[Variant].UpperBounds : default); 35 36 private float? fudge; 37 public float Fudge => fudge.HasValue ? fudge.Value : ((Variant != null) ? teamColorManager[Variant].Fudge : default); 38 39 private Vector3? hsvShift; 40 public Vector3 HSVShift => hsvShift.HasValue ? hsvShift.Value : ((Variant != null) ? teamColorManager[Variant].HSVShift : default); 41 42 private Vector3? inputLevels; 43 public Vector3 InputLevels => inputLevels.HasValue ? inputLevels.Value : ((Variant != null) ? teamColorManager[Variant].InputLevels : default); 44 45 private Vector2? outputLevels; 46 public Vector2 OutputLevels => outputLevels.HasValue ? outputLevels.Value : ((Variant != null) ? teamColorManager[Variant].OutputLevels : default); 47 48 private Vector3? overallInputLevels; 49 public Vector3 OverallInputLevels => overallInputLevels.HasValue ? overallInputLevels.Value : ((Variant != null) ? teamColorManager[Variant].OverallInputLevels : default); 50 51 private Vector2? overallOutputLevels; 52 public Vector2 OverallOutputLevels => overallOutputLevels.HasValue ? overallOutputLevels.Value : ((Variant != null) ? teamColorManager[Variant].OverallOutputLevels : default); 53 54 private Color? radarMapColor; 55 public Color RadarMapColor => radarMapColor.HasValue ? radarMapColor.Value : ((Variant != null) ? teamColorManager[Variant].RadarMapColor : default); 56 57 public TeamColor(TeamColorManager teamColorManager, MegafileManager megafileManager) 58 { 59 this.teamColorManager = teamColorManager; 60 this.megafileManager = megafileManager; 61 } 62 63 public void Load(string xml) 64 { 65 XmlDocument xmlDoc = new XmlDocument(); 66 xmlDoc.LoadXml(xml); 67 68 var node = xmlDoc.FirstChild; 69 Name = node.Attributes["Name"].Value; 70 Variant = node.Attributes["Variant"]?.Value; 71 72 var lowerBoundsNode = node.SelectSingleNode("LowerBounds"); 73 if (lowerBoundsNode != null) 74 { 75 lowerBounds = Color.FromArgb( 76 (int)(float.Parse(lowerBoundsNode.SelectSingleNode("R").InnerText) * 255), 77 (int)(float.Parse(lowerBoundsNode.SelectSingleNode("G").InnerText) * 255), 78 (int)(float.Parse(lowerBoundsNode.SelectSingleNode("B").InnerText) * 255) 79 ); 80 } 81 82 var upperBoundsNode = node.SelectSingleNode("UpperBounds"); 83 if (upperBoundsNode != null) 84 { 85 upperBounds = Color.FromArgb( 86 (int)(float.Parse(upperBoundsNode.SelectSingleNode("R").InnerText) * 255), 87 (int)(float.Parse(upperBoundsNode.SelectSingleNode("G").InnerText) * 255), 88 (int)(float.Parse(upperBoundsNode.SelectSingleNode("B").InnerText) * 255) 89 ); 90 } 91 92 var fudgeNode = node.SelectSingleNode("Fudge"); 93 if (fudgeNode != null) 94 { 95 fudge = float.Parse(fudgeNode.InnerText); 96 } 97 98 var hsvShiftNode = node.SelectSingleNode("HSVShift"); 99 if (hsvShiftNode != null) 100 { 101 hsvShift = new Vector3( 102 float.Parse(hsvShiftNode.SelectSingleNode("X").InnerText), 103 float.Parse(hsvShiftNode.SelectSingleNode("Y").InnerText), 104 float.Parse(hsvShiftNode.SelectSingleNode("Z").InnerText) 105 ); 106 } 107 108 var inputLevelsNode = node.SelectSingleNode("InputLevels"); 109 if (inputLevelsNode != null) 110 { 111 inputLevels = new Vector3( 112 float.Parse(inputLevelsNode.SelectSingleNode("X").InnerText), 113 float.Parse(inputLevelsNode.SelectSingleNode("Y").InnerText), 114 float.Parse(inputLevelsNode.SelectSingleNode("Z").InnerText) 115 ); 116 } 117 118 var outputLevelsNode = node.SelectSingleNode("OutputLevels"); 119 if (outputLevelsNode != null) 120 { 121 outputLevels = new Vector2( 122 float.Parse(outputLevelsNode.SelectSingleNode("X").InnerText), 123 float.Parse(outputLevelsNode.SelectSingleNode("Y").InnerText) 124 ); 125 } 126 127 var overallInputLevelsNode = node.SelectSingleNode("OverallInputLevels"); 128 if (overallInputLevelsNode != null) 129 { 130 overallInputLevels = new Vector3( 131 float.Parse(overallInputLevelsNode.SelectSingleNode("X").InnerText), 132 float.Parse(overallInputLevelsNode.SelectSingleNode("Y").InnerText), 133 float.Parse(overallInputLevelsNode.SelectSingleNode("Z").InnerText) 134 ); 135 } 136 137 var overallOutputLevelsNode = node.SelectSingleNode("OverallOutputLevels"); 138 if (outputLevelsNode != null) 139 { 140 overallOutputLevels = new Vector2( 141 float.Parse(overallOutputLevelsNode.SelectSingleNode("X").InnerText), 142 float.Parse(overallOutputLevelsNode.SelectSingleNode("Y").InnerText) 143 ); 144 } 145 146 var radarMapColorNode = node.SelectSingleNode("RadarMapColor"); 147 if (radarMapColorNode != null) 148 { 149 radarMapColor = Color.FromArgb( 150 (int)(float.Parse(radarMapColorNode.SelectSingleNode("R").InnerText) * 255), 151 (int)(float.Parse(radarMapColorNode.SelectSingleNode("G").InnerText) * 255), 152 (int)(float.Parse(radarMapColorNode.SelectSingleNode("B").InnerText) * 255) 153 ); 154 } 155 } 156 157 public void Flatten() 158 { 159 lowerBounds = LowerBounds; 160 upperBounds = UpperBounds; 161 fudge = Fudge; 162 hsvShift = HSVShift; 163 inputLevels = InputLevels; 164 outputLevels = OutputLevels; 165 overallInputLevels = OverallInputLevels; 166 overallOutputLevels = OverallOutputLevels; 167 radarMapColor = RadarMapColor; 168 } 169 } 170 }