public string GetReputationRewardText(Location currLocation) { List <string> reputationRewardTexts = new List <string>(); foreach (var reputationReward in ReputationRewards) { string name = ""; if (reputationReward.Key.Equals("location", StringComparison.OrdinalIgnoreCase)) { name = $"‖color:gui.orange‖{currLocation.Name}‖end‖"; } else { var faction = FactionPrefab.Prefabs.Find(f => f.Identifier.Equals(reputationReward.Key, StringComparison.OrdinalIgnoreCase)); if (faction != null) { name = $"‖color:{XMLExtensions.ColorToString(faction.IconColor)}‖{faction.Name}‖end‖"; } else { name = TextManager.Get(reputationReward.Key); } } float normalizedValue = MathUtils.InverseLerp(-100.0f, 100.0f, reputationReward.Value); string formattedValue = ((int)reputationReward.Value).ToString("+#;-#;0"); //force plus sign for positive numbers string rewardText = TextManager.GetWithVariables( "reputationformat", new string[] { "[reputationname]", "[reputationvalue]" }, new string[] { name, $"‖color:{XMLExtensions.ColorToString(Reputation.GetReputationColor(normalizedValue))}‖{formattedValue}‖end‖" }); reputationRewardTexts.Add(rewardText); } return(TextManager.AddPunctuation(':', TextManager.Get("reputation"), string.Join(", ", reputationRewardTexts))); }
private void SanitizeProperty() { sanitizedProperty = NewProperties switch { float f => f.FormatSingleDecimal(), Point point => XMLExtensions.PointToString(point), Vector2 vector2 => vector2.FormatZeroDecimal(), Vector3 vector3 => vector3.FormatSingleDecimal(), Vector4 vector4 => vector4.FormatSingleDecimal(), Color color => XMLExtensions.ColorToString(color), Rectangle rectangle => XMLExtensions.RectToString(rectangle), _ => NewProperties.ToString() }; }
public override XElement Save(XElement parentElement) { if (Submarine == null) { string errorMsg = "Error - tried to save a hull that's not a part of any submarine.\n" + Environment.StackTrace; DebugConsole.ThrowError(errorMsg); GameAnalyticsManager.AddErrorEventOnce("Hull.Save:WorldHull", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg); return(null); } XElement element = new XElement("Hull"); element.Add ( new XAttribute("ID", ID), new XAttribute("rect", (int)(rect.X - Submarine.HiddenSubPosition.X) + "," + (int)(rect.Y - Submarine.HiddenSubPosition.Y) + "," + rect.Width + "," + rect.Height), new XAttribute("water", waterVolume) ); if (linkedTo != null && linkedTo.Count > 0) { var saveableLinked = linkedTo.Where(l => l.ShouldBeSaved && !l.Removed).ToList(); element.Add(new XAttribute("linked", string.Join(",", saveableLinked.Select(l => l.ID.ToString())))); } if (OriginalAmbientLight != null) { element.Add(new XAttribute("originalambientlight", XMLExtensions.ColorToString(OriginalAmbientLight.Value))); } SerializableProperty.SerializeProperties(this, element); parentElement.Add(element); return(element); }
private void CreateReputationElement(GUIComponent parent, string name, float reputation, float normalizedReputation, float initialReputation, string shortDescription, string fullDescription, Sprite icon, Sprite backgroundPortrait, Color iconColor) { var factionFrame = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.3f), parent.RectTransform), style: null); if (backgroundPortrait != null) { new GUICustomComponent(new RectTransform(Vector2.One, factionFrame.RectTransform), onDraw: (sb, customComponent) => { backgroundPortrait.Draw(sb, customComponent.Rect.Center.ToVector2(), customComponent.Color, backgroundPortrait.size / 2, scale: customComponent.Rect.Width / backgroundPortrait.size.X); }) { HideElementsOutsideFrame = true, IgnoreLayoutGroups = true, Color = iconColor * 0.2f }; } var factionInfoHorizontal = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.9f), factionFrame.RectTransform, Anchor.Center), childAnchor: Anchor.CenterLeft, isHorizontal: true) { RelativeSpacing = 0.02f, Stretch = true }; var factionTextContent = new GUILayoutGroup(new RectTransform(Vector2.One, factionInfoHorizontal.RectTransform)) { RelativeSpacing = 0.05f, Stretch = true }; var factionIcon = new GUIImage(new RectTransform(new Point((int)(factionInfoHorizontal.Rect.Height * 0.7f)), factionInfoHorizontal.RectTransform, scaleBasis: ScaleBasis.Smallest), icon, scaleToFit: true) { Color = iconColor }; factionInfoHorizontal.Recalculate(); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.15f), factionTextContent.RectTransform), name, font: GUI.SubHeadingFont) { Padding = Vector4.Zero }; var factionDescription = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.6f), factionTextContent.RectTransform), shortDescription, font: GUI.SmallFont, wrap: true) { UserData = "description", Padding = Vector4.Zero }; if (shortDescription != fullDescription && !string.IsNullOrEmpty(fullDescription)) { factionDescription.ToolTip = fullDescription; } var sliderHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.1f), factionTextContent.RectTransform), childAnchor: Anchor.CenterLeft, isHorizontal: true) { RelativeSpacing = 0.05f, Stretch = true }; sliderHolder.RectTransform.MaxSize = new Point(int.MaxValue, GUI.IntScale(25.0f)); factionTextContent.Recalculate(); new GUICustomComponent(new RectTransform(new Vector2(0.8f, 1.0f), sliderHolder.RectTransform), onDraw: (sb, customComponent) => DrawReputationBar(sb, customComponent.Rect, normalizedReputation)); string reputationText = ((int)Math.Round(reputation)).ToString(); int reputationChange = (int)Math.Round(reputation - initialReputation); if (Math.Abs(reputationChange) > 0) { string changeText = $"{(reputationChange > 0 ? "+" : "") + reputationChange}"; string colorStr = XMLExtensions.ColorToString(reputationChange > 0 ? GUI.Style.Green : GUI.Style.Red); var rtData = RichTextData.GetRichTextData($"{reputationText} (‖color:{colorStr}‖{changeText}‖color:end‖)", out string sanitizedText); new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), sliderHolder.RectTransform), rtData, sanitizedText, textAlignment: Alignment.CenterLeft, font: GUI.SubHeadingFont); } else { new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), sliderHolder.RectTransform), reputationText, textAlignment: Alignment.CenterLeft, font: GUI.SubHeadingFont); } }
public static void SerializeProperties(ISerializableEntity obj, XElement element, bool saveIfDefault = false) { var saveProperties = GetProperties <Serialize>(obj); foreach (var property in saveProperties) { object value = property.GetValue(); if (value == null) { continue; } if (!saveIfDefault) { //only save // - if the attribute is saveable and it's different from the default value // - or can be changed in-game or in the editor bool save = false; foreach (var attribute in property.Attributes.OfType <Serialize>()) { if ((attribute.isSaveable && !attribute.defaultValue.Equals(value)) || property.Attributes.OfType <Editable>().Any()) { save = true; break; } } if (!save) { continue; } } string stringValue; string typeName; if (!supportedTypes.TryGetValue(value.GetType(), out typeName)) { if (property.PropertyType.IsEnum) { stringValue = value.ToString(); } else { DebugConsole.ThrowError("Failed to serialize the property \"" + property.Name + "\" of \"" + obj + "\" (type " + property.PropertyType + " not supported)"); continue; } } else { switch (typeName) { case "float": //make sure the decimal point isn't converted to a comma or anything else stringValue = ((float)value).ToString("G", CultureInfo.InvariantCulture); break; case "vector2": stringValue = XMLExtensions.Vector2ToString((Vector2)value); break; case "vector3": stringValue = XMLExtensions.Vector3ToString((Vector3)value); break; case "vector4": stringValue = XMLExtensions.Vector4ToString((Vector4)value); break; case "color": stringValue = XMLExtensions.ColorToString((Color)value); break; case "rectangle": stringValue = XMLExtensions.RectToString((Rectangle)value); break; default: stringValue = value.ToString(); break; } } element.SetAttributeValue(property.Name.ToLowerInvariant(), stringValue); } }