Ejemplo n.º 1
0
        public GUIMessage(string text, Color color, Vector2 worldPosition, Vector2 velocity, float lifeTime, Alignment textAlignment = Alignment.Center, ScalableFont font = null)
        {
            coloredText   = new ColoredText(text, color, false);
            WorldSpace    = true;
            pos           = worldPosition;
            Timer         = lifeTime;
            Velocity      = velocity;
            this.lifeTime = lifeTime;

            Font = font;

            size = font.MeasureString(text);

            Origin = new Vector2((int)(0.5f * size.X), (int)(0.5f * size.Y));
            if (textAlignment.HasFlag(Alignment.Left))
            {
                Origin.X -= size.X * 0.5f;
            }

            if (textAlignment.HasFlag(Alignment.Right))
            {
                Origin.X += size.X * 0.5f;
            }

            if (textAlignment.HasFlag(Alignment.Top))
            {
                Origin.Y -= size.Y * 0.5f;
            }

            if (textAlignment.HasFlag(Alignment.Bottom))
            {
                Origin.Y += size.Y * 0.5f;
            }
        }
Ejemplo n.º 2
0
        public GUIFrame CreateInfoFrame(GUIFrame frame)
        {
            new GUIImage(new Rectangle(0, 0, 30, 30), HeadSprite, Alignment.TopLeft, frame);

            ScalableFont font = frame.Rect.Width < 280 ? GUI.SmallFont : GUI.Font;

            int x = 0, y = 0;

            new GUITextBlock(new Rectangle(x + 60, y, 200, 20), Name, "", frame, font);
            y += 20;

            if (Job != null)
            {
                new GUITextBlock(new Rectangle(x + 60, y, 200, 20), Job.Name, "", frame, font);
                y += 30;

                var skills = Job.Skills;
                skills.Sort((s1, s2) => - s1.Level.CompareTo(s2.Level));

                new GUITextBlock(new Rectangle(x, y, 200, 20), "Skills:", "", frame, font);
                y += 20;
                foreach (Skill skill in skills)
                {
                    Color textColor = Color.White * (0.5f + skill.Level / 200.0f);
                    new GUITextBlock(new Rectangle(x, y, 200, 20), skill.Name, Color.Transparent, textColor, Alignment.Left, "", frame).Font = font;
                    new GUITextBlock(new Rectangle(x, y, 200, 20), skill.Level.ToString(), Color.Transparent, textColor, Alignment.Right, "", frame).Font = font;
                    y += 20;
                }
            }


            return(frame);
        }
Ejemplo n.º 3
0
        public GUITickBox(RectTransform rectT, string label, ScalableFont font = null, string style = "") : base(null, rectT)
        {
            CanBeFocused = true;

            layoutGroup = new GUILayoutGroup(new RectTransform(Vector2.One, rectT), true);

            box = new GUIFrame(new RectTransform(Vector2.One, layoutGroup.RectTransform, scaleBasis: ScaleBasis.BothHeight)
            {
                IsFixedSize = false
            }, string.Empty, Color.DarkGray)
            {
                HoverColor    = Color.Gray,
                SelectedColor = Color.DarkGray,
                CanBeFocused  = false
            };
            GUI.Style.Apply(box, style == "" ? "GUITickBox" : style);
            Vector2 textBlockScale = new Vector2((float)(Rect.Width - Rect.Height) / (float)Math.Max(Rect.Width, 1.0), 1.0f);

            text = new GUITextBlock(new RectTransform(textBlockScale, layoutGroup.RectTransform), label, font: font, textAlignment: Alignment.CenterLeft)
            {
                CanBeFocused = false
            };
            GUI.Style.Apply(text, "GUIButtonHorizontal", this);
            Enabled = true;

            ResizeBox();

            rectT.ScaleChanged += ResizeBox;
            rectT.SizeChanged  += ResizeBox;
        }
Ejemplo n.º 4
0
        private Vector2 InflateSize(ref Point size, string label, ScalableFont font)
        {
            Vector2 textSize = font.MeasureString(label);

            size.X  = Math.Max((int)Math.Ceiling(textSize.X), size.X);
            size.Y += (int)Math.Ceiling(textSize.Y);
            return(textSize);
        }
Ejemplo n.º 5
0
        public static void Init(ContentManager content)
        {
            Font      = new ScalableFont("Content/Exo2-Medium.otf", 14, graphicsDevice);
            SmallFont = new ScalableFont("Content/Exo2-Light.otf", 12, graphicsDevice);
            LargeFont = new ScalableFont("Content/Code Pro Bold.otf", 22, graphicsDevice);

            cursor = new Sprite("Content/UI/cursor.png", Vector2.Zero);

            Style = new GUIStyle("Content/UI/style.xml");
        }
Ejemplo n.º 6
0
        public ServerListScreen()
        {
            int width  = Math.Min(GameMain.GraphicsWidth - 160, 1000);
            int height = Math.Min(GameMain.GraphicsHeight - 160, 700);

            Rectangle panelRect = new Rectangle(0, 0, width, height);

            menu         = new GUIFrame(panelRect, null, Alignment.Center, "");
            menu.Padding = new Vector4(40.0f, 40.0f, 40.0f, 20.0f);

            new GUITextBlock(new Rectangle(0, -25, 0, 30), "Join Server", "", Alignment.CenterX, Alignment.CenterX, menu, false, GUI.LargeFont);

            new GUITextBlock(new Rectangle(0, 30, 0, 30), "Your Name:", "", menu);
            clientNameBox = new GUITextBox(new Rectangle(0, 60, 200, 30), "", menu);

            new GUITextBlock(new Rectangle(0, 100, 0, 30), "Server IP:", "", menu);
            ipBox = new GUITextBox(new Rectangle(0, 130, 200, 30), "", menu);

            int middleX = (int)(width * 0.4f);

            serverList            = new GUIListBox(new Rectangle(middleX, 60, 0, height - 160), "", menu);
            serverList.OnSelected = SelectServer;

            float[] columnRelativeX = new float[] { 0.15f, 0.5f, 0.15f, 0.2f };
            columnX = new int[columnRelativeX.Length];
            for (int n = 0; n < columnX.Length; n++)
            {
                columnX[n] = (int)(columnRelativeX[n] * serverList.Rect.Width);
                if (n > 0)
                {
                    columnX[n] += columnX[n - 1];
                }
            }

            ScalableFont font = GUI.SmallFont; // serverList.Rect.Width < 400 ? GUI.SmallFont : GUI.Font;

            new GUITextBlock(new Rectangle(middleX, 30, 0, 30), "Password", "", menu).Font = font;

            new GUITextBlock(new Rectangle(middleX + columnX[0], 30, 0, 30), "Name", "", menu).Font          = font;
            new GUITextBlock(new Rectangle(middleX + columnX[1], 30, 0, 30), "Players", "", menu).Font       = font;
            new GUITextBlock(new Rectangle(middleX + columnX[2], 30, 0, 30), "Round started", "", menu).Font = font;

            joinButton           = new GUIButton(new Rectangle(-170, 0, 150, 30), "Refresh", Alignment.BottomRight, "", menu);
            joinButton.OnClicked = RefreshServers;

            joinButton           = new GUIButton(new Rectangle(0, 0, 150, 30), "Join", Alignment.BottomRight, "", menu);
            joinButton.OnClicked = JoinServer;

            GUIButton button = new GUIButton(new Rectangle(-20, -20, 100, 30), "Back", Alignment.TopLeft, "", menu);

            button.OnClicked     = GameMain.MainMenuScreen.SelectTab;
            button.SelectedColor = button.Color;

            refreshDisableTimer = DateTime.Now;
        }
        public GUIMessage(string text, Color color, float lifeTime, ScalableFont font = null)
        {
            coloredText   = new ColoredText(text, color, false, false);
            this.lifeTime = lifeTime;
            Timer         = lifeTime;

            size   = font.MeasureString(text);
            Origin = new Vector2(0, size.Y * 0.5f);

            Font = font;
        }
Ejemplo n.º 8
0
        private GUIComponent AddTextElement(XElement element, RectTransform parent, string overrideText = null, Anchor anchor = Anchor.Center)
        {
            var       text      = overrideText ?? element.ElementInnerText().Replace(@"\n", "\n");
            Color     color     = element.GetAttributeColor("color", Color.White);
            float     scale     = element.GetAttributeFloat("scale", 1.0f);
            Alignment alignment = Alignment.Center;

            Enum.TryParse(element.GetAttributeString("alignment", "Center"), out alignment);
            ScalableFont font = GUI.Font;

            switch (element.GetAttributeString("font", "Font").ToLowerInvariant())
            {
            case "font":
                font = GUI.Font;
                break;

            case "smallfont":
                font = GUI.SmallFont;
                break;

            case "largefont":
                font = GUI.LargeFont;
                break;

            case "videotitlefont":
                font = GUI.VideoTitleFont;
                break;

            case "objectivetitlefont":
                font = GUI.ObjectiveTitleFont;
                break;

            case "objectivenamefont":
                font = GUI.ObjectiveNameFont;
                break;
            }

            var textHolder = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.0f), parent), style: null);
            var textBlock  = new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.0f), textHolder.RectTransform, anchor),
                                              text,
                                              color,
                                              font,
                                              alignment,
                                              wrap: true)
            {
                TextScale = scale
            };

            textBlock.RectTransform.IsFixedSize    = textHolder.RectTransform.IsFixedSize = true;
            textBlock.RectTransform.NonScaledSize  = new Point(textBlock.Rect.Width, textBlock.Rect.Height);
            textHolder.RectTransform.NonScaledSize = new Point(textHolder.Rect.Width, textBlock.Rect.Height);
            return(textHolder);
        }
Ejemplo n.º 9
0
        public GUIStyle(string file, GraphicsDevice graphicsDevice)
        {
            componentStyles = new Dictionary <string, GUIComponentStyle>();

            XDocument doc;

            try
            {
                ToolBox.IsProperFilenameCase(file);
                doc = XDocument.Load(file, LoadOptions.SetBaseUri);
            }
            catch (Exception e)
            {
                DebugConsole.ThrowError("Loading style \"" + file + "\" failed", e);
                return;
            }

            foreach (XElement subElement in doc.Root.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "font":
                    Font = new ScalableFont(subElement, graphicsDevice);
                    break;

                case "smallfont":
                    SmallFont = new ScalableFont(subElement, graphicsDevice);
                    break;

                case "largefont":
                    LargeFont = new ScalableFont(subElement, graphicsDevice);
                    break;

                case "cursor":
                    CursorSprite = new Sprite(subElement);
                    break;

                case "uiglow":
                    UIGlow = new UISprite(subElement);
                    break;

                case "focusindicator":
                    FocusIndicator = new SpriteSheet(subElement);
                    break;

                default:
                    GUIComponentStyle componentStyle = new GUIComponentStyle(subElement);
                    componentStyles.Add(subElement.Name.ToString().ToLowerInvariant(), componentStyle);
                    break;
                }
            }
        }
Ejemplo n.º 10
0
        private void DrawLanguageSelectionPrompt(SpriteBatch spriteBatch, GraphicsDevice graphicsDevice)
        {
            if (languageSelectionFont == null)
            {
                languageSelectionFont = new ScalableFont("Content/Fonts/NotoSans/NotoSans-Bold.ttf",
                                                         (uint)(30 * (GameMain.GraphicsHeight / 1080.0f)), graphicsDevice);
            }
            if (languageSelectionFontCJK == null)
            {
                languageSelectionFontCJK = new ScalableFont("Content/Fonts/NotoSans/NotoSansCJKsc-Bold.otf",
                                                            (uint)(30 * (GameMain.GraphicsHeight / 1080.0f)), graphicsDevice, dynamicLoading: true);
            }
            if (languageSelectionCursor == null)
            {
                languageSelectionCursor = new Sprite("Content/UI/cursor.png", Vector2.Zero);
            }

            Vector2 textPos     = new Vector2(GameMain.GraphicsWidth / 2, GameMain.GraphicsHeight * 0.3f);
            Vector2 textSpacing = new Vector2(0.0f, (GameMain.GraphicsHeight * 0.5f) / TextManager.AvailableLanguages.Count());

            foreach (string language in TextManager.AvailableLanguages)
            {
                string localizedLanguageName = TextManager.GetTranslatedLanguageName(language);
                var    font = TextManager.IsCJK(localizedLanguageName) ? languageSelectionFontCJK : languageSelectionFont;

                Vector2 textSize = font.MeasureString(localizedLanguageName);
                bool    hover    =
                    Math.Abs(PlayerInput.MousePosition.X - textPos.X) < textSize.X / 2 &&
                    Math.Abs(PlayerInput.MousePosition.Y - textPos.Y) < textSpacing.Y / 2;

                font.DrawString(spriteBatch, localizedLanguageName, textPos - textSize / 2,
                                hover ? Color.White : Color.White * 0.6f);
                if (hover && PlayerInput.PrimaryMouseButtonClicked())
                {
                    GameMain.Config.Language = language;
                    //reload tip in the selected language
                    selectedTip = TextManager.Get("LoadingScreenTip", true);
                    GameMain.Config.SetDefaultBindings(legacy: false);
                    GameMain.Config.CheckBindings(useDefaults: true);
                    WaitForLanguageSelection = false;
                    languageSelectionFont?.Dispose(); languageSelectionFont       = null;
                    languageSelectionFontCJK?.Dispose(); languageSelectionFontCJK = null;
                    break;
                }

                textPos += textSpacing;
            }

            languageSelectionCursor.Draw(spriteBatch, PlayerInput.LatestMousePosition, scale: 0.5f);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Returns the default font of the currently selected language
 /// </summary>
 public ScalableFont LoadCurrentDefaultFont()
 {
     defaultFont?.Dispose();
     defaultFont = null;
     foreach (XElement subElement in configElement.Elements())
     {
         switch (subElement.Name.ToString().ToLowerInvariant())
         {
         case "font":
             defaultFont = LoadFont(subElement, graphicsDevice);
             break;
         }
     }
     return(defaultFont);
 }
Ejemplo n.º 12
0
        public void CreatePreviewWindow(GUIComponent parent)
        {
            var content = new GUIFrame(new RectTransform(Vector2.One, parent.RectTransform), style: null);

            if (PreviewImage == null)
            {
                new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), content.RectTransform), TextManager.Get(SavedSubmarines.Contains(this) ? "SubPreviewImageNotFound" : "SubNotDownloaded"));
            }
            else
            {
                var submarinePreviewBackground = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.5f), content.RectTransform), style: null)
                {
                    Color = Color.Black
                };
                new GUIImage(new RectTransform(new Vector2(0.98f), submarinePreviewBackground.RectTransform, Anchor.Center), PreviewImage, scaleToFit: true);
                new GUIFrame(new RectTransform(Vector2.One, submarinePreviewBackground.RectTransform), "InnerGlow", color: Color.Black);
            }
            var descriptionBox = new GUIListBox(new RectTransform(new Vector2(1, 0.5f), content.RectTransform, Anchor.BottomCenter))
            {
                UserData         = "descriptionbox",
                ScrollBarVisible = true,
                Spacing          = 5
            };

            ScalableFont font = parent.Rect.Width < 350 ? GUI.SmallFont : GUI.Font;

            CreateSpecsWindow(descriptionBox, font);

            //space
            new GUIFrame(new RectTransform(new Vector2(1.0f, 0.05f), descriptionBox.Content.RectTransform), style: null);

            if (!string.IsNullOrEmpty(Description))
            {
                new GUITextBlock(new RectTransform(new Vector2(1, 0), descriptionBox.Content.RectTransform),
                                 TextManager.Get("SaveSubDialogDescription", fallBackTag: "WorkshopItemDescription"), font: GUI.Font, wrap: true)
                {
                    CanBeFocused = false, ForceUpperCase = true
                };
            }

            new GUITextBlock(new RectTransform(new Vector2(1, 0), descriptionBox.Content.RectTransform), Description, font: font, wrap: true)
            {
                CanBeFocused = false
            };
        }
Ejemplo n.º 13
0
        /// <summary>
        /// This is the new constructor.
        /// If the rectT height is set 0, the height is calculated from the text.
        /// </summary>
        public GUITextBlock(RectTransform rectT, string text, Color?textColor = null, ScalableFont font = null,
                            Alignment textAlignment = Alignment.Left, bool wrap = false, string style = "", Color?color = null,
                            bool playerInput        = false, bool parseRichText = false)
            : base(style, rectT)
        {
            if (color.HasValue)
            {
                this.color = color.Value;
            }
            if (textColor.HasValue)
            {
                OverrideTextColor(textColor.Value);
            }

            if (parseRichText)
            {
                RichTextData = Barotrauma.RichTextData.GetRichTextData(text, out text);
            }

            //if the text is in chinese/korean/japanese and we're not using a CJK-compatible font,
            //use the default CJK font as a fallback
            var selectedFont = originalFont = font ?? GUI.Font;

            if (TextManager.IsCJK(text) && !selectedFont.IsCJK)
            {
                selectedFont = GUI.CJKFont;
            }
            this.Font          = selectedFont;
            this.textAlignment = textAlignment;
            this.Wrap          = wrap;
            this.Text          = text ?? "";
            this.playerInput   = playerInput;
            if (rectT.Rect.Height == 0 && !string.IsNullOrEmpty(text))
            {
                CalculateHeightFromText();
            }
            SetTextPos();

            RectTransform.ScaleChanged += SetTextPos;
            RectTransform.SizeChanged  += SetTextPos;

            Enabled = true;
            Censor  = false;
        }
Ejemplo n.º 14
0
        public static string LimitString(string str, ScalableFont font, int maxWidth)
        {
            if (maxWidth <= 0 || string.IsNullOrWhiteSpace(str))
            {
                return("");
            }

            float currWidth = font.MeasureString("...").X;

            for (int i = 0; i < str.Length; i++)
            {
                currWidth += font.MeasureString(str[i].ToString()).X;

                if (currWidth > maxWidth)
                {
                    return(str.Substring(0, Math.Max(i - 2, 1)) + "...");
                }
            }

            return(str);
        }
Ejemplo n.º 15
0
        public GUITickBox(Rectangle rect, string label, Alignment alignment, ScalableFont font, GUIComponent parent)
            : base(null)
        {
            if (parent != null)
            {
                parent.AddChild(this);
            }

            box               = new GUIFrame(rect, Color.DarkGray, "", this);
            box.HoverColor    = Color.Gray;
            box.SelectedColor = Color.DarkGray;
            box.CanBeFocused  = false;

            GUI.Style.Apply(box, "GUITickBox");

            text = new GUITextBlock(new Rectangle(rect.Right, rect.Y, 20, rect.Height), label, "", Alignment.TopLeft, Alignment.Left | Alignment.CenterY, this, false, font);
            GUI.Style.Apply(text, "GUIButtonHorizontal", this);

            this.rect = new Rectangle(box.Rect.X, box.Rect.Y, 240, rect.Height);

            Enabled = true;
        }
Ejemplo n.º 16
0
        public GUITickBox(RectTransform rectT, string label, ScalableFont font = null, string style = "") : base(null, rectT)
        {
            CanBeFocused = true;
            HoverCursor  = CursorState.Hand;

            layoutGroup = new GUILayoutGroup(new RectTransform(Vector2.One, rectT), true);

            box = new GUIFrame(new RectTransform(Vector2.One, layoutGroup.RectTransform, Anchor.CenterLeft, scaleBasis: ScaleBasis.BothHeight)
            {
                IsFixedSize = true
            }, string.Empty, Color.DarkGray)
            {
                HoverColor    = Color.Gray,
                SelectedColor = Color.DarkGray,
                CanBeFocused  = false
            };
            GUI.Style.Apply(box, style == "" ? "GUITickBox" : style);
            if (box.RectTransform.MinSize.Y > 0)
            {
                RectTransform.MinSize = box.RectTransform.MinSize;
                RectTransform.MaxSize = box.RectTransform.MaxSize;
                RectTransform.Resize(new Point(RectTransform.NonScaledSize.X, RectTransform.MinSize.Y));
                box.RectTransform.MinSize = new Point(box.RectTransform.MinSize.Y);
                box.RectTransform.Resize(box.RectTransform.MinSize);
            }
            Vector2 textBlockScale = new Vector2((float)(Rect.Width - Rect.Height) / (float)Math.Max(Rect.Width, 1.0), 1.0f);

            text = new GUITextBlock(new RectTransform(textBlockScale, layoutGroup.RectTransform, Anchor.CenterLeft), label, font: font, textAlignment: Alignment.CenterLeft)
            {
                CanBeFocused = false
            };
            GUI.Style.Apply(text, "GUITextBlock", this);
            Enabled = true;

            ResizeBox();

            rectT.ScaleChanged += ResizeBox;
            rectT.SizeChanged  += ResizeBox;
        }
Ejemplo n.º 17
0
        private void CreateItemFrame(MapEntityPrefab ep, GUIListBox listBox, int width)
        {
            GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 50), "ListBoxElement", listBox);

            frame.UserData = ep;
            frame.Padding  = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);

            frame.ToolTip = ep.Description;

            ScalableFont font = listBox.Rect.Width < 280 ? GUI.SmallFont : GUI.Font;

            GUITextBlock textBlock = new GUITextBlock(
                new Rectangle(50, 0, 0, 25),
                ep.Name,
                null, null,
                Alignment.Left, Alignment.CenterX | Alignment.Left,
                "", frame);

            textBlock.Font    = font;
            textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
            textBlock.ToolTip = ep.Description;

            if (ep.sprite != null)
            {
                GUIImage img = new GUIImage(new Rectangle(0, 0, 40, 40), ep.sprite, Alignment.CenterLeft, frame);
                img.Color = ep.SpriteColor;
                img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f);
            }

            textBlock = new GUITextBlock(
                new Rectangle(width - 80, 0, 80, 25),
                ep.Price.ToString(),
                null, null, Alignment.TopLeft,
                Alignment.TopLeft, "", frame);
            textBlock.Font    = font;
            textBlock.ToolTip = ep.Description;
        }
Ejemplo n.º 18
0
        public GUITickBox(RectTransform rectT, string label, ScalableFont font = null, string style = "") : base(null, rectT)
        {
            box = new GUIFrame(new RectTransform(new Point(rectT.Rect.Height, rectT.Rect.Height), rectT, Anchor.CenterLeft)
            {
                IsFixedSize = false
            }, string.Empty, Color.DarkGray)
            {
                HoverColor    = Color.Gray,
                SelectedColor = Color.DarkGray,
                CanBeFocused  = false
            };
            GUI.Style.Apply(box, style == "" ? "GUITickBox" : style);
            text = new GUITextBlock(new RectTransform(Vector2.One, rectT, Anchor.CenterLeft)
            {
                AbsoluteOffset = new Point(box.Rect.Width, 0)
            }, label, font: font, textAlignment: Alignment.CenterLeft);
            GUI.Style.Apply(text, "GUIButtonHorizontal", this);
            Enabled = true;

            ResizeBox();

            rectT.ScaleChanged += ResizeBox;
            rectT.SizeChanged  += ResizeBox;
        }
Ejemplo n.º 19
0
        public void CreatePreviewWindow(GUIComponent parent)
        {
            var content = new GUIFrame(new RectTransform(Vector2.One, parent.RectTransform), style: null);

            var previewButton = new GUIButton(new RectTransform(new Vector2(1f, 0.5f), content.RectTransform), style: null)
            {
                CanBeFocused = SubmarineElement != null,
                OnClicked    = (btn, obj) => { SubmarinePreview.Create(this); return(false); },
            };

            var previewImage = PreviewImage ?? savedSubmarines.Find(s => s.Name.Equals(Name, StringComparison.OrdinalIgnoreCase))?.PreviewImage;

            if (previewImage == null)
            {
                new GUITextBlock(new RectTransform(Vector2.One, previewButton.RectTransform), TextManager.Get(SavedSubmarines.Contains(this) ? "SubPreviewImageNotFound" : "SubNotDownloaded"));
            }
            else
            {
                var submarinePreviewBackground = new GUIFrame(new RectTransform(Vector2.One, previewButton.RectTransform), style: null)
                {
                    Color         = Color.Black,
                    HoverColor    = Color.Black,
                    SelectedColor = Color.Black,
                    PressedColor  = Color.Black,
                    CanBeFocused  = false,
                };
                new GUIImage(new RectTransform(new Vector2(0.98f), submarinePreviewBackground.RectTransform, Anchor.Center), previewImage, scaleToFit: true)
                {
                    CanBeFocused = false
                };
                new GUIFrame(new RectTransform(Vector2.One, submarinePreviewBackground.RectTransform), "InnerGlow", color: Color.Black)
                {
                    CanBeFocused = false
                };
            }

            if (SubmarineElement != null)
            {
                new GUIFrame(new RectTransform(Vector2.One * 0.12f, previewButton.RectTransform, anchor: Anchor.BottomRight, pivot: Pivot.BottomRight, scaleBasis: ScaleBasis.BothHeight)
                {
                    AbsoluteOffset = new Point((int)(0.03f * previewButton.Rect.Height))
                },
                             "ExpandButton", Color.White)
                {
                    Color        = Color.White,
                    HoverColor   = Color.White,
                    PressedColor = Color.White
                };
            }

            var descriptionBox = new GUIListBox(new RectTransform(new Vector2(1, 0.5f), content.RectTransform, Anchor.BottomCenter))
            {
                UserData         = "descriptionbox",
                ScrollBarVisible = true,
                Spacing          = 5
            };

            ScalableFont font = parent.Rect.Width < 350 ? GUI.SmallFont : GUI.Font;

            CreateSpecsWindow(descriptionBox, font, includeDescription: true);
        }
Ejemplo n.º 20
0
        public GUIFrame CreateInfoFrame(GUIFrame frame)
        {
            var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.7f), frame.RectTransform, Anchor.TopCenter)
            {
                RelativeOffset = new Vector2(0.0f, 0.1f)
            })
            {
                Stretch         = true,
                RelativeSpacing = 0.03f
            };

            var headerArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.4f), paddedFrame.RectTransform), isHorizontal: true)
            {
                RelativeSpacing = 0.05f,
                Stretch         = true
            };

            new GUICustomComponent(new RectTransform(new Vector2(0.25f, 1.0f), headerArea.RectTransform),
                                   onDraw: (sb, component) => DrawIcon(sb, component.Rect.Center.ToVector2(), targetAreaSize: component.Rect.Size.ToVector2()));

            ScalableFont font = paddedFrame.Rect.Width < 280 ? GUI.SmallFont : GUI.Font;

            var headerTextArea = new GUILayoutGroup(new RectTransform(new Vector2(0.75f, 1.0f), headerArea.RectTransform))
            {
                RelativeSpacing = 0.05f,
                Stretch         = true
            };

            Color?nameColor = null;

            if (Job != null)
            {
                nameColor = Job.Prefab.UIColor;
            }
            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), headerTextArea.RectTransform),
                             Name, textColor: nameColor, font: GUI.LargeFont)
            {
                Padding   = Vector4.Zero,
                AutoScale = true
            };

            if (Job != null)
            {
                new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), headerTextArea.RectTransform),
                                 Job.Name, textColor: Job.Prefab.UIColor, font: font);
            }

            if (personalityTrait != null)
            {
                new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), headerTextArea.RectTransform),
                                 TextManager.Get("PersonalityTrait") + ": " + personalityTrait.Name, font: font);
            }

            //spacing
            new GUIFrame(new RectTransform(new Vector2(1.0f, 0.05f), paddedFrame.RectTransform), style: null);

            if (Job != null)
            {
                var skills = Job.Skills;
                skills.Sort((s1, s2) => - s1.Level.CompareTo(s2.Level));

                new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedFrame.RectTransform),
                                 TextManager.Get("Skills") + ":", font: font);

                foreach (Skill skill in skills)
                {
                    Color textColor = Color.White * (0.5f + skill.Level / 200.0f);

                    var skillName = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedFrame.RectTransform),
                                                     TextManager.Get("SkillName." + skill.Identifier), textColor: textColor, font: font);
                    new GUITextBlock(new RectTransform(new Vector2(1.0f, 1.0f), skillName.RectTransform),
                                     ((int)skill.Level).ToString(), textColor: textColor, font: font, textAlignment: Alignment.CenterRight);
                }
            }

            return(frame);
        }
Ejemplo n.º 21
0
        public GUIComponent CreateInfoFrame(GUIFrame frame, bool returnParent, Sprite permissionIcon = null)
        {
            var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.874f, 0.58f), frame.RectTransform, Anchor.TopCenter)
            {
                RelativeOffset = new Vector2(0.0f, 0.05f)
            })
            {
                RelativeSpacing = 0.05f
                                  //Stretch = true
            };

            var headerArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.322f), paddedFrame.RectTransform), isHorizontal: true);

            new GUICustomComponent(new RectTransform(new Vector2(0.425f, 1.0f), headerArea.RectTransform),
                                   onDraw: (sb, component) => DrawInfoFrameCharacterIcon(sb, component.Rect));

            ScalableFont font = paddedFrame.Rect.Width < 280 ? GUI.SmallFont : GUI.Font;

            var headerTextArea = new GUILayoutGroup(new RectTransform(new Vector2(0.575f, 1.0f), headerArea.RectTransform))
            {
                RelativeSpacing = 0.02f,
                Stretch         = true
            };

            Color?nameColor = null;

            if (Job != null)
            {
                nameColor = Job.Prefab.UIColor;
            }

            GUITextBlock characterNameBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), headerTextArea.RectTransform), ToolBox.LimitString(Name, GUI.Font, headerTextArea.Rect.Width), textColor: nameColor, font: GUI.Font)
            {
                ForceUpperCase = true,
                Padding        = Vector4.Zero
            };

            if (permissionIcon != null)
            {
                Point iconSize  = permissionIcon.SourceRect.Size;
                int   iconWidth = (int)((float)characterNameBlock.Rect.Height / iconSize.Y * iconSize.X);
                new GUIImage(new RectTransform(new Point(iconWidth, characterNameBlock.Rect.Height), characterNameBlock.RectTransform)
                {
                    AbsoluteOffset = new Point(-iconWidth - 2, 0)
                }, permissionIcon)
                {
                    IgnoreLayoutGroups = true
                };
            }

            if (Job != null)
            {
                new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), headerTextArea.RectTransform), Job.Name, textColor: Job.Prefab.UIColor, font: font)
                {
                    Padding = Vector4.Zero
                };
            }

            if (personalityTrait != null)
            {
                new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), headerTextArea.RectTransform), TextManager.AddPunctuation(':', TextManager.Get("PersonalityTrait"), TextManager.Get("personalitytrait." + personalityTrait.Name.Replace(" ", ""))), font: font)
                {
                    Padding = Vector4.Zero
                };
            }

            if (Job != null && (Character == null || !Character.IsDead))
            {
                var skillsArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.63f), paddedFrame.RectTransform, Anchor.BottomCenter, Pivot.BottomCenter))
                {
                    Stretch = true
                };

                var skills = Job.Skills;
                skills.Sort((s1, s2) => - s1.Level.CompareTo(s2.Level));

                new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), skillsArea.RectTransform), TextManager.AddPunctuation(':', TextManager.Get("skills"), string.Empty), font: font)
                {
                    Padding = Vector4.Zero
                };

                foreach (Skill skill in skills)
                {
                    Color textColor = Color.White * (0.5f + skill.Level / 200.0f);

                    var skillName = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), skillsArea.RectTransform), TextManager.Get("SkillName." + skill.Identifier), textColor: textColor, font: font)
                    {
                        Padding = Vector4.Zero
                    };

                    float modifiedSkillLevel = skill.Level;
                    if (Character != null)
                    {
                        modifiedSkillLevel = Character.GetSkillLevel(skill.Identifier);
                    }
                    if (!MathUtils.NearlyEqual(MathF.Round(modifiedSkillLevel), MathF.Round(skill.Level)))
                    {
                        int    skillChange = (int)MathF.Round(modifiedSkillLevel - skill.Level);
                        string changeText  = $"{(skillChange > 0 ? "+" : "") + skillChange}";
                        new GUITextBlock(new RectTransform(new Vector2(1.0f, 1.0f), skillName.RectTransform), $"{(int)skill.Level} ({changeText})", textColor: textColor, font: font, textAlignment: Alignment.CenterRight);
                    }
                    else
                    {
                        new GUITextBlock(new RectTransform(new Vector2(1.0f, 1.0f), skillName.RectTransform), ((int)skill.Level).ToString(), textColor: textColor, font: font, textAlignment: Alignment.CenterRight);
                    }
                }
            }
            else if (Character != null && Character.IsDead)
            {
                var deadArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.63f), paddedFrame.RectTransform, Anchor.BottomCenter, Pivot.BottomCenter))
                {
                    Stretch = true
                };

                string deadDescription = TextManager.AddPunctuation(':', TextManager.Get("deceased") + "\n" + Character.CauseOfDeath.Affliction?.CauseOfDeathDescription ??
                                                                    TextManager.AddPunctuation(':', TextManager.Get("CauseOfDeath"), TextManager.Get("CauseOfDeath." + Character.CauseOfDeath.Type.ToString())));

                new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), deadArea.RectTransform), deadDescription, textColor: GUI.Style.Red, font: font, textAlignment: Alignment.TopLeft)
                {
                    Padding = Vector4.Zero
                };
            }

            if (returnParent)
            {
                return(frame);
            }
            else
            {
                return(paddedFrame);
            }
        }
Ejemplo n.º 22
0
        public GUITextBox(RectTransform rectT, string text = "", Color?textColor       = null, ScalableFont font = null,
                          Alignment textAlignment          = Alignment.Left, bool wrap = false, string style     = "", Color?color = null)
            : base(style, rectT)
        {
            Enabled    = true;
            this.color = color ?? Color.White;
            frame      = new GUIFrame(new RectTransform(Vector2.One, rectT, Anchor.Center), style, color);
            GUI.Style.Apply(frame, style == "" ? "GUITextBox" : style);
            textBlock = new GUITextBlock(new RectTransform(Vector2.One, frame.RectTransform, Anchor.Center), text, textColor, font, textAlignment, wrap, playerInput: true);
            GUI.Style.Apply(textBlock, "", this);
            CaretEnabled  = true;
            caretPosDirty = true;

            Font = textBlock.Font;

            rectT.SizeChanged  += () => { caretPosDirty = true; };
            rectT.ScaleChanged += () => { caretPosDirty = true; };
        }
Ejemplo n.º 23
0
        public void CreatePreviewWindow(GUIComponent parent)
        {
            var upperPart      = new GUILayoutGroup(new RectTransform(new Vector2(1, 0.5f), parent.RectTransform, Anchor.Center, Pivot.BottomCenter));
            var descriptionBox = new GUIListBox(new RectTransform(new Vector2(1, 0.5f), parent.RectTransform, Anchor.Center, Pivot.TopCenter))
            {
                ScrollBarVisible = true,
                Spacing          = 5
            };

            if (PreviewImage == null)
            {
                new GUITextBlock(new RectTransform(new Vector2(1.0f, 1), upperPart.RectTransform), TextManager.Get(SavedSubmarines.Contains(this) ? "SubPreviewImageNotFound" : "SubNotDownloaded"));
            }
            else
            {
                var submarinePreviewBackground = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), upperPart.RectTransform))
                {
                    Color = Color.Black
                };
                new GUIImage(new RectTransform(new Vector2(1.0f, 1.0f), submarinePreviewBackground.RectTransform), PreviewImage, scaleToFit: true);
            }

            //space
            new GUIFrame(new RectTransform(new Vector2(1.0f, 0.03f), descriptionBox.Content.RectTransform), style: null);

            new GUITextBlock(new RectTransform(new Vector2(1, 0), descriptionBox.Content.RectTransform), Name, font: GUI.LargeFont, wrap: true)
            {
                ForceUpperCase = true, CanBeFocused = false
            };

            float leftPanelWidth  = 0.6f;
            float rightPanelWidth = 0.4f / leftPanelWidth;

            ScalableFont font = descriptionBox.Rect.Width < 350 ? GUI.SmallFont : GUI.Font;

            Vector2 realWorldDimensions = Dimensions * Physics.DisplayToRealWorldRatio;

            if (realWorldDimensions != Vector2.Zero)
            {
                string dimensionsStr = TextManager.GetWithVariables("DimensionsFormat", new string[2] {
                    "[width]", "[height]"
                }, new string[2] {
                    ((int)realWorldDimensions.X).ToString(), ((int)realWorldDimensions.Y).ToString()
                });

                var dimensionsText = new GUITextBlock(new RectTransform(new Vector2(leftPanelWidth, 0), descriptionBox.Content.RectTransform),
                                                      TextManager.Get("Dimensions"), textAlignment: Alignment.TopLeft, font: font, wrap: true)
                {
                    CanBeFocused = false
                };
                new GUITextBlock(new RectTransform(new Vector2(rightPanelWidth, 0.0f), dimensionsText.RectTransform, Anchor.TopRight, Pivot.TopLeft),
                                 dimensionsStr, textAlignment: Alignment.TopLeft, font: font, wrap: true)
                {
                    CanBeFocused = false
                };
                dimensionsText.RectTransform.MinSize = new Point(0, dimensionsText.Children.First().Rect.Height);
            }

            if (RecommendedCrewSizeMax > 0)
            {
                var crewSizeText = new GUITextBlock(new RectTransform(new Vector2(leftPanelWidth, 0), descriptionBox.Content.RectTransform),
                                                    TextManager.Get("RecommendedCrewSize"), textAlignment: Alignment.TopLeft, font: font, wrap: true)
                {
                    CanBeFocused = false
                };
                new GUITextBlock(new RectTransform(new Vector2(rightPanelWidth, 0.0f), crewSizeText.RectTransform, Anchor.TopRight, Pivot.TopLeft),
                                 RecommendedCrewSizeMin + " - " + RecommendedCrewSizeMax, textAlignment: Alignment.TopLeft, font: font, wrap: true)
                {
                    CanBeFocused = false
                };
                crewSizeText.RectTransform.MinSize = new Point(0, crewSizeText.Children.First().Rect.Height);
            }

            if (!string.IsNullOrEmpty(RecommendedCrewExperience))
            {
                var crewExperienceText = new GUITextBlock(new RectTransform(new Vector2(leftPanelWidth, 0), descriptionBox.Content.RectTransform),
                                                          TextManager.Get("RecommendedCrewExperience"), textAlignment: Alignment.TopLeft, font: font, wrap: true)
                {
                    CanBeFocused = false
                };
                new GUITextBlock(new RectTransform(new Vector2(rightPanelWidth, 0.0f), crewExperienceText.RectTransform, Anchor.TopRight, Pivot.TopLeft),
                                 TextManager.Get(RecommendedCrewExperience), textAlignment: Alignment.TopLeft, font: font, wrap: true)
                {
                    CanBeFocused = false
                };
                crewExperienceText.RectTransform.MinSize = new Point(0, crewExperienceText.Children.First().Rect.Height);
            }

            if (RequiredContentPackages.Any())
            {
                var contentPackagesText = new GUITextBlock(new RectTransform(new Vector2(leftPanelWidth, 0), descriptionBox.Content.RectTransform),
                                                           TextManager.Get("RequiredContentPackages"), textAlignment: Alignment.TopLeft, font: font)
                {
                    CanBeFocused = false
                };
                new GUITextBlock(new RectTransform(new Vector2(rightPanelWidth, 0.0f), contentPackagesText.RectTransform, Anchor.TopRight, Pivot.TopLeft),
                                 string.Join(", ", RequiredContentPackages), textAlignment: Alignment.TopLeft, font: font, wrap: true)
                {
                    CanBeFocused = false
                };
                contentPackagesText.RectTransform.MinSize = new Point(0, contentPackagesText.Children.First().Rect.Height);
            }

            GUITextBlock.AutoScaleAndNormalize(descriptionBox.Content.Children.Where(c => c is GUITextBlock).Cast <GUITextBlock>());

            //space
            new GUIFrame(new RectTransform(new Vector2(1.0f, 0.05f), descriptionBox.Content.RectTransform), style: null);

            if (!string.IsNullOrEmpty(Description))
            {
                new GUITextBlock(new RectTransform(new Vector2(1, 0), descriptionBox.Content.RectTransform),
                                 TextManager.Get("SaveSubDialogDescription", fallBackTag: "WorkshopItemDescription"), font: GUI.Font, wrap: true)
                {
                    CanBeFocused = false, ForceUpperCase = true
                };
            }

            new GUITextBlock(new RectTransform(new Vector2(1, 0), descriptionBox.Content.RectTransform), Description, font: font, wrap: true)
            {
                CanBeFocused = false
            };
        }
Ejemplo n.º 24
0
 public GUITextBlock(RectTransform rectT, List <RichTextData> richTextData, string text, Color?textColor = null, ScalableFont font = null, Alignment textAlignment = Alignment.Left, bool wrap = false, string style = "", Color?color = null, bool playerInput = false)
     : this(rectT, text, textColor, font, textAlignment, wrap, style, color, playerInput)
 {
     this.RichTextData = richTextData;
 }
 public virtual void AddToEditor(ParamsEditor editor, bool recursive = true, int space = 0, ScalableFont titleFont = null)
 {
     SerializableEntityEditor = new SerializableEntityEditor(editor.EditorBox.Content.RectTransform, this, inGame: false, showName: true, titleFont: titleFont ?? GUI.LargeFont);
     if (recursive)
     {
         SubParams.ForEach(sp => sp.AddToEditor(editor, true, titleFont: titleFont ?? GUI.SmallFont));
     }
     if (space > 0)
     {
         new GUIFrame(new RectTransform(new Point(editor.EditorBox.Rect.Width, space), editor.EditorBox.Content.RectTransform), style: null, color: new Color(20, 20, 20, 255))
         {
             CanBeFocused = false
         };
     }
 }
Ejemplo n.º 26
0
        private void SelectSubmarine(SubmarineInfo info, Rectangle backgroundRect)
        {
#if !DEBUG
            if (selectedSubmarine == info)
            {
                return;
            }
#endif
            specsFrame.Content.ClearChildren();
            selectedSubmarine = info;

            if (info != null)
            {
                bool owned = GameMain.GameSession.IsSubmarineOwned(info);

                if (owned)
                {
                    confirmButton.Text      = deliveryFee > 0 ? deliveryText : switchText;
                    confirmButton.OnClicked = (button, userData) =>
                    {
                        ShowTransferPrompt();
                        return(true);
                    };
                }
                else
                {
                    confirmButton.Text      = purchaseAndSwitchText;
                    confirmButton.OnClicked = (button, userData) =>
                    {
                        ShowBuyPrompt(false);
                        return(true);
                    };

                    confirmButtonAlt.Text      = purchaseOnlyText;
                    confirmButtonAlt.OnClicked = (button, userData) =>
                    {
                        ShowBuyPrompt(true);
                        return(true);
                    };
                }

                SetConfirmButtonState(selectedSubmarine.Name != CurrentOrPendingSubmarine().Name);

                selectedSubmarineIndicator.RectTransform.NonScaledSize  = backgroundRect.Size;
                selectedSubmarineIndicator.RectTransform.AbsoluteOffset = new Point(backgroundRect.Left - submarineHorizontalGroup.Rect.Left, 0);

                Sprite previewImage = GetPreviewImage(info);
                listBackground.Sprite = previewImage;
                listBackground.SetCrop(true);

                ScalableFont font = GUI.Font;
                info.CreateSpecsWindow(specsFrame, font);
                descriptionTextBlock.Text = info.Description;
                descriptionTextBlock.CalculateHeightFromText();
            }
            else
            {
                listBackground.Sprite = null;
                listBackground.SetCrop(false);
                descriptionTextBlock.Text = string.Empty;
                selectedSubmarineIndicator.RectTransform.NonScaledSize = Point.Zero;
                SetConfirmButtonState(false);
            }
        }
Ejemplo n.º 27
0
        public static void DrawString(SpriteBatch sb, Vector2 pos, string text, Color color, Color?backgroundColor = null, int backgroundPadding = 0, ScalableFont font = null)
        {
            if (font == null)
            {
                font = Font;
            }
            if (backgroundColor != null)
            {
                Vector2 textSize = font.MeasureString(text);
                DrawRectangle(sb, pos - Vector2.One * backgroundPadding, textSize + Vector2.One * 2.0f * backgroundPadding, (Color)backgroundColor, true);
            }

            font.DrawString(sb, text, pos, color);
        }
Ejemplo n.º 28
0
        public void CreateSpecsWindow(GUIListBox parent, ScalableFont font, bool includeTitle = true, bool includeClass = true, bool includeDescription = false)
        {
            float  leftPanelWidth  = 0.6f;
            float  rightPanelWidth = 0.4f;
            string className       = !HasTag(SubmarineTag.Shuttle) ? TextManager.Get($"submarineclass.{SubmarineClass}") : TextManager.Get("shuttle");

            int classHeight       = (int)GUI.SubHeadingFont.MeasureString(className).Y;
            int leftPanelWidthInt = (int)(parent.Rect.Width * leftPanelWidth);

            GUITextBlock submarineNameText  = null;
            GUITextBlock submarineClassText = null;

            if (includeTitle)
            {
                int nameHeight = (int)GUI.LargeFont.MeasureString(DisplayName, true).Y;
                submarineNameText = new GUITextBlock(new RectTransform(new Point(leftPanelWidthInt, nameHeight + HUDLayoutSettings.Padding / 2), parent.Content.RectTransform), DisplayName, textAlignment: Alignment.CenterLeft, font: GUI.LargeFont)
                {
                    CanBeFocused = false
                };
                submarineNameText.RectTransform.MinSize = new Point(0, (int)submarineNameText.TextSize.Y);
            }
            if (includeClass)
            {
                submarineClassText = new GUITextBlock(new RectTransform(new Point(leftPanelWidthInt, classHeight), parent.Content.RectTransform), className, textAlignment: Alignment.CenterLeft, font: GUI.SubHeadingFont)
                {
                    CanBeFocused = false
                };
                submarineClassText.RectTransform.MinSize = new Point(0, (int)submarineClassText.TextSize.Y);
            }
            Vector2 realWorldDimensions = Dimensions * Physics.DisplayToRealWorldRatio;

            if (realWorldDimensions != Vector2.Zero)
            {
                string dimensionsStr = TextManager.GetWithVariables("DimensionsFormat", new string[2] {
                    "[width]", "[height]"
                }, new string[2] {
                    ((int)realWorldDimensions.X).ToString(), ((int)realWorldDimensions.Y).ToString()
                });
                var dimensionsText = new GUITextBlock(new RectTransform(new Vector2(leftPanelWidth, 0), parent.Content.RectTransform),
                                                      TextManager.Get("Dimensions"), textAlignment: Alignment.TopLeft, font: font, wrap: true)
                {
                    CanBeFocused = false
                };
                new GUITextBlock(new RectTransform(new Vector2(rightPanelWidth, 0.0f), dimensionsText.RectTransform, Anchor.TopRight, Pivot.TopLeft),
                                 dimensionsStr, textAlignment: Alignment.TopLeft, font: font, wrap: true)
                {
                    CanBeFocused = false
                };
                dimensionsText.RectTransform.MinSize = new Point(0, dimensionsText.Children.First().Rect.Height);
            }

            string cargoCapacityStr = CargoCapacity < 0 ? TextManager.Get("unknown") : TextManager.GetWithVariables("cargocapacityformat", new string[1] {
                "[cratecount]"
            }, new string[1] {
                CargoCapacity.ToString()
            });
            var cargoCapacityText = new GUITextBlock(new RectTransform(new Vector2(leftPanelWidth, 0), parent.Content.RectTransform),
                                                     TextManager.Get("cargocapacity"), textAlignment: Alignment.TopLeft, font: font, wrap: true)
            {
                CanBeFocused = false
            };

            new GUITextBlock(new RectTransform(new Vector2(rightPanelWidth, 0.0f), cargoCapacityText.RectTransform, Anchor.TopRight, Pivot.TopLeft),
                             cargoCapacityStr, textAlignment: Alignment.TopLeft, font: font, wrap: true)
            {
                CanBeFocused = false
            };
            cargoCapacityText.RectTransform.MinSize = new Point(0, cargoCapacityText.Children.First().Rect.Height);

            if (RecommendedCrewSizeMax > 0)
            {
                var crewSizeText = new GUITextBlock(new RectTransform(new Vector2(leftPanelWidth, 0), parent.Content.RectTransform),
                                                    TextManager.Get("RecommendedCrewSize"), textAlignment: Alignment.TopLeft, font: font, wrap: true)
                {
                    CanBeFocused = false
                };
                new GUITextBlock(new RectTransform(new Vector2(rightPanelWidth, 0.0f), crewSizeText.RectTransform, Anchor.TopRight, Pivot.TopLeft),
                                 RecommendedCrewSizeMin + " - " + RecommendedCrewSizeMax, textAlignment: Alignment.TopLeft, font: font, wrap: true)
                {
                    CanBeFocused = false
                };
                crewSizeText.RectTransform.MinSize = new Point(0, crewSizeText.Children.First().Rect.Height);
            }

            if (!string.IsNullOrEmpty(RecommendedCrewExperience))
            {
                var crewExperienceText = new GUITextBlock(new RectTransform(new Vector2(leftPanelWidth, 0), parent.Content.RectTransform),
                                                          TextManager.Get("RecommendedCrewExperience"), textAlignment: Alignment.TopLeft, font: font, wrap: true)
                {
                    CanBeFocused = false
                };
                new GUITextBlock(new RectTransform(new Vector2(rightPanelWidth, 0.0f), crewExperienceText.RectTransform, Anchor.TopRight, Pivot.TopLeft),
                                 TextManager.Get(RecommendedCrewExperience), textAlignment: Alignment.TopLeft, font: font, wrap: true)
                {
                    CanBeFocused = false
                };
                crewExperienceText.RectTransform.MinSize = new Point(0, crewExperienceText.Children.First().Rect.Height);
            }

            if (RequiredContentPackages.Any())
            {
                var contentPackagesText = new GUITextBlock(new RectTransform(new Vector2(leftPanelWidth, 0), parent.Content.RectTransform),
                                                           TextManager.Get("RequiredContentPackages"), textAlignment: Alignment.TopLeft, font: font)
                {
                    CanBeFocused = false
                };
                new GUITextBlock(new RectTransform(new Vector2(rightPanelWidth, 0.0f), contentPackagesText.RectTransform, Anchor.TopRight, Pivot.TopLeft),
                                 string.Join(", ", RequiredContentPackages), textAlignment: Alignment.TopLeft, font: font, wrap: true)
                {
                    CanBeFocused = false
                };
                contentPackagesText.RectTransform.MinSize = new Point(0, contentPackagesText.Children.First().Rect.Height);
            }

            // show what game version the submarine was created on
            if (!IsVanillaSubmarine() && GameVersion != null)
            {
                var versionText = new GUITextBlock(new RectTransform(new Vector2(leftPanelWidth, 0), parent.Content.RectTransform),
                                                   TextManager.Get("serverlistversion"), textAlignment: Alignment.TopLeft, font: font, wrap: true)
                {
                    CanBeFocused = false
                };
                new GUITextBlock(new RectTransform(new Vector2(rightPanelWidth, 0.0f), versionText.RectTransform, Anchor.TopRight, Pivot.TopLeft),
                                 GameVersion.ToString(), textAlignment: Alignment.TopLeft, font: font, wrap: true)
                {
                    CanBeFocused = false
                };

                versionText.RectTransform.MinSize = new Point(0, versionText.Children.First().Rect.Height);
            }

            if (submarineNameText != null)
            {
                submarineNameText.AutoScaleHorizontal = true;
            }

            GUITextBlock descBlock = null;

            if (includeDescription)
            {
                //space
                new GUIFrame(new RectTransform(new Vector2(1.0f, 0.05f), parent.Content.RectTransform), style: null);

                if (!string.IsNullOrEmpty(Description))
                {
                    var wsItemDesc = new GUITextBlock(new RectTransform(new Vector2(1, 0), parent.Content.RectTransform),
                                                      TextManager.Get("SaveSubDialogDescription", fallBackTag: "WorkshopItemDescription"), font: GUI.Font, wrap: true)
                    {
                        CanBeFocused = false, ForceUpperCase = true
                    };

                    descBlock = new GUITextBlock(new RectTransform(new Vector2(1, 0), parent.Content.RectTransform), Description, font: font, wrap: true)
                    {
                        CanBeFocused = false
                    };
                }
            }
            GUITextBlock.AutoScaleAndNormalize(parent.Content.GetAllChildren <GUITextBlock>().Where(c => c != submarineNameText && c != descBlock));
        }
Ejemplo n.º 29
0
        public GUITextBox(RectTransform rectT, string text = "", Color?textColor       = null, ScalableFont font = null,
                          Alignment textAlignment          = Alignment.Left, bool wrap = false, string style     = "", Color?color = null, bool createClearButton = false)
            : base(style, rectT)
        {
            HoverCursor  = CursorState.IBeam;
            CanBeFocused = true;

            this.color = color ?? Color.White;
            frame      = new GUIFrame(new RectTransform(Vector2.One, rectT, Anchor.Center), style, color);
            GUI.Style.Apply(frame, style == "" ? "GUITextBox" : style);
            textBlock = new GUITextBlock(new RectTransform(Vector2.One, frame.RectTransform, Anchor.CenterLeft), text, textColor, font, textAlignment, wrap, playerInput: true);
            GUI.Style.Apply(textBlock, "", this);
            CaretEnabled  = true;
            caretPosDirty = true;

            new GUICustomComponent(new RectTransform(Vector2.One, frame.RectTransform), onDraw: DrawCaretAndSelection);

            int clearButtonWidth = 0;

            if (createClearButton)
            {
                var clearButton = new GUIButton(new RectTransform(new Vector2(0.6f, 0.6f), frame.RectTransform, Anchor.CenterRight, scaleBasis: ScaleBasis.BothHeight)
                {
                    AbsoluteOffset = new Point(5, 0)
                }, style: "GUICancelButton")
                {
                    OnClicked = (bt, userdata) =>
                    {
                        Text = "";
                        frame.Flash(Color.White);
                        return(true);
                    }
                };
                textBlock.RectTransform.MaxSize = new Point(frame.Rect.Width - clearButton.Rect.Height - clearButton.RectTransform.AbsoluteOffset.X * 2, int.MaxValue);
                clearButtonWidth = (int)(clearButton.Rect.Width * 1.2f);
            }

            if (this.style != null && this.style.ChildStyles.ContainsKey("textboxicon"))
            {
                icon = new GUIImage(new RectTransform(new Vector2(0.6f, 0.6f), frame.RectTransform, Anchor.CenterRight, scaleBasis: ScaleBasis.BothHeight)
                {
                    AbsoluteOffset = new Point(5 + clearButtonWidth, 0)
                }, null, scaleToFit: true);
                icon.ApplyStyle(this.style.ChildStyles["textboxicon"]);
                textBlock.RectTransform.MaxSize = new Point(frame.Rect.Width - icon.Rect.Height - clearButtonWidth - icon.RectTransform.AbsoluteOffset.X * 2, int.MaxValue);
            }
            Font = textBlock.Font;

            Enabled = true;

            rectT.SizeChanged += () =>
            {
                if (icon != null)
                {
                    textBlock.RectTransform.MaxSize = new Point(frame.Rect.Width - icon.Rect.Height - icon.RectTransform.AbsoluteOffset.X * 2, int.MaxValue);
                }
                caretPosDirty = true;
            };
            rectT.ScaleChanged += () =>
            {
                if (icon != null)
                {
                    textBlock.RectTransform.MaxSize = new Point(frame.Rect.Width - icon.Rect.Height - icon.RectTransform.AbsoluteOffset.X * 2, int.MaxValue);
                }
                caretPosDirty = true;
            };
        }
Ejemplo n.º 30
0
        private GUIComponent CreateItemFrame(PurchasedItem pi, PriceInfo priceInfo, GUIListBox listBox, int width)
        {
            GUIFrame frame = new GUIFrame(new RectTransform(new Point(listBox.Content.Rect.Width, (int)(GUI.Scale * 50)), listBox.Content.RectTransform), style: "ListBoxElement")
            {
                UserData = pi,
                ToolTip  = pi.ItemPrefab.Description
            };

            var content = new GUILayoutGroup(new RectTransform(Vector2.One, frame.RectTransform), isHorizontal: true)
            {
                RelativeSpacing = 0.02f,
                Stretch         = true
            };

            ScalableFont font = listBox.Rect.Width < 280 ? GUI.SmallFont : GUI.Font;

            Sprite itemIcon = pi.ItemPrefab.InventoryIcon ?? pi.ItemPrefab.sprite;

            if (itemIcon != null)
            {
                GUIImage img = new GUIImage(new RectTransform(new Point((int)(content.Rect.Height * 0.8f)), content.RectTransform, Anchor.CenterLeft), itemIcon, scaleToFit: true)
                {
                    Color = itemIcon == pi.ItemPrefab.InventoryIcon ? pi.ItemPrefab.InventoryIconColor : pi.ItemPrefab.SpriteColor
                };
                img.RectTransform.MaxSize = img.Rect.Size;
                //img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f);
            }

            GUITextBlock textBlock = new GUITextBlock(new RectTransform(new Vector2(0.6f, 1.0f), content.RectTransform),
                                                      pi.ItemPrefab.Name, font: font)
            {
                ToolTip = pi.ItemPrefab.Description
            };

            new GUITextBlock(new RectTransform(new Vector2(0.2f, 1.0f), content.RectTransform),
                             priceInfo.BuyPrice.ToString(), font: font, textAlignment: Alignment.CenterRight)
            {
                ToolTip = pi.ItemPrefab.Description
            };

            //If its the store menu, quantity will always be 0
            GUINumberInput amountInput = null;

            if (pi.Quantity > 0)
            {
                amountInput = new GUINumberInput(new RectTransform(new Vector2(0.3f, 1.0f), content.RectTransform),
                                                 GUINumberInput.NumberType.Int)
                {
                    MinValueInt = 0,
                    MaxValueInt = 100,
                    UserData    = pi,
                    IntValue    = pi.Quantity
                };
                amountInput.OnValueChanged += (numberInput) =>
                {
                    PurchasedItem purchasedItem = numberInput.UserData as PurchasedItem;

                    //Attempting to buy
                    if (numberInput.IntValue > purchasedItem.Quantity)
                    {
                        int quantity = numberInput.IntValue - purchasedItem.Quantity;
                        //Cap the numberbox based on the amount we can afford.
                        quantity = Campaign.Money <= 0 ?
                                   0 : Math.Min((int)(Campaign.Money / (float)priceInfo.BuyPrice), quantity);
                        for (int i = 0; i < quantity; i++)
                        {
                            BuyItem(numberInput, purchasedItem);
                        }
                        numberInput.IntValue = purchasedItem.Quantity;
                    }
                    //Attempting to sell
                    else
                    {
                        int quantity = purchasedItem.Quantity - numberInput.IntValue;
                        for (int i = 0; i < quantity; i++)
                        {
                            SellItem(numberInput, purchasedItem);
                        }
                    }
                };
            }
            listBox.RecalculateChildren();
            content.Recalculate();
            content.RectTransform.RecalculateChildren(true, true);
            amountInput?.LayoutGroup.Recalculate();
            textBlock.Text = ToolBox.LimitString(textBlock.Text, textBlock.Font, textBlock.Rect.Width);
            content.RectTransform.IsFixedSize = true;
            content.RectTransform.Children.ForEach(c => c.IsFixedSize = true);

            return(frame);
        }