Example #1
0
        public static void LogError(object msg)
        {
            string message = msg.ToString();
            Color  color   = Color.red;

            SGroup sGroup = new SGroup();

            sGroup.AutoGrowDirection = SGroup.EDirection.Vertical;
            sGroup.AutoLayout        = (SGroup g) => g.AutoLayoutHorizontal;
            sGroup.OnUpdateStyle     = delegate(SElement elem)
            {
                elem.Fill();
            };
            sGroup.AutoLayoutVerticalStretch   = false;
            sGroup.AutoLayoutHorizontalStretch = false;
            sGroup.GrowExtra         = Vector2.zero;
            sGroup.ContentSize       = Vector2.zero;
            sGroup.AutoLayoutPadding = 0;
            sGroup.Background        = Color.clear;

            LogLabel modname = new LogLabel(Initialisation.metadata.Name + ": ");

            modname.Colors[0] = color;
            sGroup.Children.Add(modname);

            LogLabel label = new LogLabel(message);

            label.Colors[0]  = color;
            label.Background = Color.clear;
            sGroup.Children.Add(label);

            ETGModConsole.Instance.GUI[0].Children.Add(sGroup);

            ETGModConsole.Instance.GUI[0].UpdateStyle();
        }
Example #2
0
        /// <summary>
        /// Used to log messages. messages can have the mod name, mod icon, both, or none in front.
        /// if color is set to null, messege color will be set to white
        /// note that modifiers are applied the sGroup children, not to the sGroup. if you want to change/add modifiers to the sGroup, use the returned sGroup
        /// n order to log an image in your text, you do "@(embedded file path, sizemult)" in your text, sizemult is not required, will default to 1.
        /// </summary>
        /// <param name="msg">the object or string you want to log</param>
        /// <param name="modifiers">an array of Selement modifiers to be added to each element logged</param>
        /// <param name="col">text color in unity Color32 or Color</param>
        /// <param name="HaveModName">whether your log messege will have the mod name at the front</param>
        /// <param name="HaveModIcon">whether your logged messege will have your mod icon at the front</param>
        public static SGroup Log(object msg, Color32?col = null, bool HaveModName = false, bool HaveModIcon = false, SModifier[] modifiers = null)
        {
            //in your module outside of methods you need:
            // public static ETGModuleMetadata metadata = new ETGModuleMetadata();

            //then in your modules init you need:
            // metadata = this.Metadata;
            Color color = Color.white;

            if (col != null)
            {
                color = col.Value;
            }
            string message = msg.ToString();

            SGroup sGroup = new SGroup();

            sGroup.AutoGrowDirection = SGroup.EDirection.Vertical;
            sGroup.AutoLayout        = (SGroup g) => g.AutoLayoutHorizontal;
            sGroup.OnUpdateStyle     = delegate(SElement elem)
            {
                elem.Fill();
            };
            sGroup.AutoLayoutVerticalStretch   = false;
            sGroup.AutoLayoutHorizontalStretch = false;
            sGroup.GrowExtra         = Vector2.zero;
            sGroup.ContentSize       = Vector2.zero;
            sGroup.AutoLayoutPadding = 0;
            sGroup.Background        = Color.clear;

            if (File.Exists(Initialisation.metadata.Archive))
            {
                if (HaveModIcon)
                {
                    SImage icon = new SImage(Initialisation.metadata.Icon);
                    sGroup.Children.Add(icon);
                }
            }
            if (HaveModName)
            {
                LogLabel modname = new LogLabel(Initialisation.metadata.Name + ": ");
                modname.Colors[0] = color;
                sGroup.Children.Add(modname);
            }
            string[] split = Regex.Split(message, "(@\\(.+?\\))");
            foreach (string item in split)
            {
                if (item.StartsWith("@("))
                {
                    string   image    = item.TrimStart('@', '(').TrimEnd(')');
                    string[] sizeMult = image.Split(',');
                    image = sizeMult[0];
                    float SizeMultButForReal = 1;

                    if (sizeMult.Length > 1)
                    {
                        if (sizeMult[1] != null && sizeMult[1] != "" && sizeMult[1] != " ")
                        {
                            SizeMultButForReal = float.Parse(sizeMult[1]);
                        }
                    }

                    string    extension = !image.EndsWith(".png") ? ".png" : "";
                    string    path      = image + extension;
                    Texture2D tex       = GetTextureFromResource(path);
                    TextureScale.Point(tex, Mathf.RoundToInt(tex.width * SizeMultButForReal), Mathf.RoundToInt(tex.height * SizeMultButForReal));

                    SImage img = new SImage(tex);
                    sGroup.Children.Add(img);
                    var idx = sGroup.Children.IndexOf(img);
                }
                else
                {
                    LogLabel label = new LogLabel(item);
                    label.Colors[0]  = color;
                    label.Background = Color.clear;
                    sGroup.Children.Add(label);
                }
                if (modifiers != null)
                {
                    for (int i = 0; i < modifiers.Length; i++)
                    {
                        sGroup.Children[sGroup.Children.Count - 1].Modifiers.Add(modifiers[i]);
                    }
                }
            }
            ETGModConsole.Instance.GUI[0].Children.Add(sGroup);

            ETGModConsole.Instance.GUI[0].UpdateStyle();
            return(sGroup);
        }