Пример #1
0
        private GUIFrame 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.1f), 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)
            {
                AbsoluteSpacing = GUI.IntScale(5),
                Stretch         = true
            };

            var factionTextContent = new GUILayoutGroup(new RectTransform(Vector2.One, factionInfoHorizontal.RectTransform))
            {
                AbsoluteSpacing = GUI.IntScale(10),
                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();

            var header = new GUITextBlock(new RectTransform(new Point(factionTextContent.Rect.Width, GUI.IntScale(40)), factionTextContent.RectTransform),
                                          name, font: GUI.SubHeadingFont)
            {
                Padding  = Vector4.Zero,
                UserData = "header"
            };

            header.RectTransform.IsFixedSize = true;

            var sliderHolder = new GUILayoutGroup(new RectTransform(new Point((int)(factionTextContent.Rect.Width * 0.8f), GUI.IntScale(20.0f)), factionTextContent.RectTransform),
                                                  childAnchor: Anchor.CenterLeft, isHorizontal: true)
            {
                RelativeSpacing = 0.05f,
                Stretch         = true
            };

            sliderHolder.RectTransform.IsFixedSize = true;
            factionTextContent.Recalculate();

            new GUICustomComponent(new RectTransform(new Vector2(0.8f, 1.0f), sliderHolder.RectTransform),
                                   onDraw: (sb, customComponent) => DrawReputationBar(sb, customComponent.Rect, normalizedReputation));

            string reputationText   = Reputation.GetFormattedReputationText(normalizedReputation, reputation, addColorTags: true);
            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, parseRichText: true);
            }

            //spacing
            new GUIFrame(new RectTransform(new Vector2(1.0f, 0.0f), factionTextContent.RectTransform)
            {
                MinSize = new Point(0, GUI.IntScale(5))
            }, style: null);

            var factionDescription = new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.6f), factionTextContent.RectTransform),
                                                      shortDescription, font: GUI.SmallFont, wrap: true)
            {
                UserData = "description",
                Padding  = Vector4.Zero
            };

            if (shortDescription != fullDescription && !string.IsNullOrEmpty(fullDescription))
            {
                factionDescription.ToolTip = fullDescription;
            }

            //spacing
            new GUIFrame(new RectTransform(new Vector2(1.0f, 0.0f), factionTextContent.RectTransform)
            {
                MinSize = new Point(0, GUI.IntScale(5))
            }, style: null);

            factionInfoHorizontal.Recalculate();
            factionTextContent.Recalculate();

            return(factionFrame);
        }
Пример #2
0
        public void CreateReputationInfoPanel(GUIComponent parent, CampaignMode campaignMode)
        {
            GUIListBox reputationList = new GUIListBox(new RectTransform(Vector2.One, parent.RectTransform))
            {
                Padding = new Vector4(4, 10, 0, 0) * GUI.Scale
            };

            reputationList.ContentBackground.Color = Color.Transparent;

            if (startLocation.Type.HasOutpost && startLocation.Reputation != null)
            {
                var iconStyle     = GUI.Style.GetComponentStyle("LocationReputationIcon");
                var locationFrame = CreateReputationElement(
                    reputationList.Content,
                    startLocation.Name,
                    startLocation.Reputation.Value, startLocation.Reputation.NormalizedValue, initialLocationReputation,
                    startLocation.Type.Name, "",
                    iconStyle?.GetDefaultSprite(), startLocation.Type.GetPortrait(0), iconStyle?.Color ?? Color.White);
                CreatePathUnlockElement(locationFrame, null, startLocation);
            }

            foreach (Faction faction in campaignMode.Factions)
            {
                float initialReputation = faction.Reputation.Value;
                if (initialFactionReputations.ContainsKey(faction))
                {
                    initialReputation = initialFactionReputations[faction];
                }
                else
                {
                    DebugConsole.AddWarning($"Could not determine reputation change for faction \"{faction.Prefab.Name}\" (faction was not present at the start of the round).");
                }
                var factionFrame = CreateReputationElement(
                    reputationList.Content,
                    faction.Prefab.Name,
                    faction.Reputation.Value, faction.Reputation.NormalizedValue, initialReputation,
                    faction.Prefab.ShortDescription, faction.Prefab.Description,
                    faction.Prefab.Icon, faction.Prefab.BackgroundPortrait, faction.Prefab.IconColor);
                CreatePathUnlockElement(factionFrame, faction, null);
            }

            float maxDescriptionHeight = 0.0f;

            foreach (GUIComponent child in reputationList.Content.Children)
            {
                var descriptionElement = child.FindChild("description", recursive: true) as GUITextBlock;
                maxDescriptionHeight = Math.Max(maxDescriptionHeight, descriptionElement.TextSize.Y * 1.1f);
            }
            foreach (GUIComponent child in reputationList.Content.Children)
            {
                var headerElement      = child.FindChild("header", recursive: true) as GUITextBlock;
                var descriptionElement = child.FindChild("description", recursive: true) as GUITextBlock;
                descriptionElement.RectTransform.NonScaledSize = new Point(descriptionElement.Rect.Width, (int)maxDescriptionHeight);
                descriptionElement.RectTransform.IsFixedSize   = true;
                child.RectTransform.NonScaledSize = new Point(child.Rect.Width, headerElement.Rect.Height + descriptionElement.RectTransform.Parent.Children.Sum(c => c.Rect.Height + ((GUILayoutGroup)descriptionElement.Parent).AbsoluteSpacing));
            }

            void CreatePathUnlockElement(GUIComponent reputationFrame, Faction faction, Location location)
            {
                if (GameMain.GameSession?.Campaign?.Map != null)
                {
                    foreach (LocationConnection connection in GameMain.GameSession.Campaign.Map.Connections)
                    {
                        if (!connection.Locked || (!connection.Locations[0].Discovered && !connection.Locations[1].Discovered))
                        {
                            continue;
                        }

                        var gateLocation = connection.Locations[0].IsGateBetweenBiomes ? connection.Locations[0] : connection.Locations[1];
                        var unlockEvent  =
                            EventSet.PrefabList.Find(ep => ep.UnlockPathEvent && ep.BiomeIdentifier == gateLocation.LevelData.Biome.Identifier) ??
                            EventSet.PrefabList.Find(ep => ep.UnlockPathEvent && string.IsNullOrEmpty(ep.BiomeIdentifier));

                        if (unlockEvent == null)
                        {
                            continue;
                        }
                        if (string.IsNullOrEmpty(unlockEvent.UnlockPathFaction) || unlockEvent.UnlockPathFaction.Equals("location", StringComparison.OrdinalIgnoreCase))
                        {
                            if (location == null || gateLocation != location)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            if (faction == null || !faction.Prefab.Identifier.Equals(unlockEvent.UnlockPathFaction, StringComparison.OrdinalIgnoreCase))
                            {
                                continue;
                            }
                        }

                        if (unlockEvent != null)
                        {
                            Reputation unlockReputation = gateLocation.Reputation;
                            Faction    unlockFaction    = null;
                            if (!string.IsNullOrEmpty(unlockEvent.UnlockPathFaction))
                            {
                                unlockFaction    = GameMain.GameSession.Campaign.Factions.Find(f => f.Prefab.Identifier.Equals(unlockEvent.UnlockPathFaction, StringComparison.OrdinalIgnoreCase));
                                unlockReputation = unlockFaction?.Reputation;
                            }
                            float  normalizedUnlockReputation = MathUtils.InverseLerp(unlockReputation.MinReputation, unlockReputation.MaxReputation, unlockEvent.UnlockPathReputation);
                            string unlockText = TextManager.GetWithVariables(
                                "lockedpathreputationrequirement",
                                new string[] { "[reputation]", "[biomename]" },
                                new string[] { Reputation.GetFormattedReputationText(normalizedUnlockReputation, unlockEvent.UnlockPathReputation, addColorTags: true), $"‖color:gui.orange‖{connection.LevelData.Biome.DisplayName}‖end‖" });
                            var unlockInfoPanel = new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.0f), reputationFrame.RectTransform, Anchor.BottomCenter)
                            {
                                MinSize = new Point(0, GUI.IntScale(30)), AbsoluteOffset = new Point(0, GUI.IntScale(3))
                            },
                                                                   unlockText, style: "GUIButtonRound", textAlignment: Alignment.Center, textColor: GUI.Style.TextColor, parseRichText: true);
                            unlockInfoPanel.Color = Color.Lerp(unlockInfoPanel.Color, Color.Black, 0.8f);
                            if (unlockInfoPanel.TextSize.X > unlockInfoPanel.Rect.Width * 0.7f)
                            {
                                unlockInfoPanel.Font = GUI.SmallFont;
                            }
                        }
                    }
                }
            }
        }