示例#1
0
        private void ShowModErrorsMessageBox()
        {
            var errors = MyDefinitionErrors.GetErrors();

            if (m_currentModErrorsMessageBox != null)
            {
                RemoveScreen(m_currentModErrorsMessageBox);
            }

            var errorMessage = MyTexts.Get(MyCommonTexts.MessageBoxErrorModLoadingFailure);

            errorMessage.Append("\n");

            foreach (var error in errors)
            {
                if (error.Severity == TErrorSeverity.Critical && error.ModName != null)
                {
                    errorMessage.Append("\n");
                    errorMessage.Append(error.ModName);
                }
            }
            errorMessage.Append("\n");

            m_currentModErrorsMessageBox = MyGuiSandbox.CreateMessageBox(messageText: errorMessage, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError));
            AddScreen(m_currentModErrorsMessageBox);
        }
示例#2
0
        public override void RecreateControls(bool constructor)
        {
            AddCaption(MySpaceTexts.ScreenDebugOfficial_ErrorLogCaption, captionOffset: new Vector2(0.0f, MyGuiConstants.SCREEN_CAPTION_DELTA_Y * -0.5f));

            m_currentPosition.Y += MyGuiConstants.SCREEN_CAPTION_DELTA_Y;

            var text = AddMultilineText(size: Size - new Vector2(0.0f, MyGuiConstants.SCREEN_CAPTION_DELTA_Y), offset: Size * -0.5f, textScale: 0.7f);

            if (MyDefinitionErrors.GetErrors().Count() == 0)
            {
                text.AppendText(MyTexts.Get(MySpaceTexts.ScreenDebugOfficial_NoErrorText));
            }
            foreach (var error in MyDefinitionErrors.GetErrors())
            {
                text.AppendText(error.ToString(), text.Font, text.TextScaleWithLanguage, error.GetSeverityColor().ToVector4());
                text.AppendLine();
                text.AppendLine(); // Extra newline to separate different errors
            }
        }
        private void CopyErrorLogToClipboard(MyGuiControlButton obj)
        {
            StringBuilder text = new StringBuilder();

            if (MyDefinitionErrors.GetErrors().Count() == 0)
            {
                text.Append(MyTexts.Get(MySpaceTexts.ScreenDebugOfficial_NoErrorText));
            }
            foreach (var error in MyDefinitionErrors.GetErrors())
            {
                text.Append(error.ToString());
                text.AppendLine();
            }

            Thread thread = new Thread(() => System.Windows.Forms.Clipboard.SetText(text.ToString()));

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
        }
        private void CopyErrorLogToClipboard(MyGuiControlButton obj)
        {
#if !XB1
            StringBuilder text = new StringBuilder();

            if (MyDefinitionErrors.GetErrors().Count() == 0)
            {
                text.Append(MyTexts.Get(MyCommonTexts.ScreenDebugOfficial_NoErrorText));
            }
            foreach (var error in MyDefinitionErrors.GetErrors())
            {
                text.Append(error.ToString());
                text.AppendLine();
            }

            Thread thread = new Thread(() => System.Windows.Forms.Clipboard.SetText(text.ToString()));
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
#else // XB1
            System.Diagnostics.Debug.Assert(false, "XB1 TODO?");
#endif // XB1
        }
示例#5
0
        /// <summary>
        /// Compiles the mod
        /// </summary>
        /// <returns></returns>
        public bool Compile()
        {
            // Compile
            if (m_compile)
            {
                if (m_type == WorkshopType.Mod)
                {
                    if (_compileMethod != null)
                    {
                        MySandboxGame.Log.WriteLineAndConsole("Compiling...");
#if SE
                        var mod = new MyModContext();

                        // Because of a regression in SE, we need to create a checkpoint ModItem to set the Id.
                        var modob = new MyObjectBuilder_Checkpoint.ModItem();
                        modob.Name = Path.GetFileName(m_modPath);

                        if (ModId.Length > 0)
                        {
                            modob.PublishedFileId      = m_workshopItems[m_modId[0]].Id;
                            modob.PublishedServiceName = m_workshopItems[m_modId[0]].ServiceName;
                            modob.FriendlyName         = m_workshopItems[m_modId[0]].Title;
                            modob.SetModData(m_workshopItems[m_modId[0]]);
                        }
                        else
                        {
                            // Fake it, so the compile still works
                            modob.PublishedFileId      = 0;
                            modob.PublishedServiceName = MyGameService.GetDefaultUGC().ServiceName;
                            modob.FriendlyName         = Title;
                        }
                        mod.Init(modob);

                        // Call init again, to make sure the path in set properly to the local mod directory
                        mod.Init(m_title, null, m_modPath);
#else
                        var workshopItem = new MyLocalWorkshopItem(new VRage.ObjectBuilders.SerializableModReference(Path.GetFileName(m_modPath), 0));
                        var mod          = new MyModContext(workshopItem, 0);
#endif
                        _compileMethod(
#if SE
                            m_modPath,
#endif
                            mod
                            );

                        // Process any errors
#if SE
                        var errors = MyDefinitionErrors.GetErrors();
#else
                        var compileMessages = _scriptManager.GetType().GetField("m_messages", BindingFlags.NonPublic | BindingFlags.Instance);
                        var errors          = (compileMessages.GetValue(_scriptManager) as List <MyScriptCompiler.Message>) ?? new List <MyScriptCompiler.Message>();
#endif
                        if (errors.Count > 0)
                        {
                            int errorCount   = 0;
                            int warningCount = 0;

                            // This is not efficient, but I'm lazy
                            foreach (var error in errors)
                            {
                                if (error.Severity >= TErrorSeverity.Error)
                                {
                                    errorCount++;
                                }
                                if (error.Severity == TErrorSeverity.Warning)
                                {
                                    warningCount++;
                                }
                            }

                            if (errorCount > 0)
                            {
                                MySandboxGame.Log.WriteLineAndConsole(string.Format("There are {0} compile errors:", errorCount));
                            }
                            if (warningCount > 0)
                            {
                                MySandboxGame.Log.WriteLineAndConsole(string.Format("There are {0} compile warnings:", warningCount));
                            }

                            // Output raw message, which is usually in msbuild friendly format, for automated tools
                            foreach (var error in errors)
#if SE
                            { System.Console.WriteLine(error.Message); }
#else
                            { System.Console.WriteLine(error.Text); }
#endif

#if SE
                            MyDefinitionErrors.Clear();     // Clear old ones, so next mod starts fresh
#endif

                            if (errorCount > 0)
                            {
                                MySandboxGame.Log.WriteLineAndConsole("Compilation FAILED!");
                                return(false);
                            }
                        }
                        MySandboxGame.Log.WriteLineAndConsole("Compilation successful!");
                    }
                    else
                    {
                        MySandboxGame.Log.WriteLineAndConsole(string.Format(Constants.ERROR_Reflection, "LoadScripts"));
                    }
                }
#if SE
                else if (m_type == WorkshopType.IngameScript)
                {
                    // Load the ingame script from the disk
                    // I don't like this, but meh
                    var input   = new StreamReader(Path.Combine(m_modPath, "Script.cs"));
                    var program = input.ReadToEnd();
                    input.Close();
                    var scripts = new List <Script>();
                    scripts.Add(MyScriptCompiler.Static.GetIngameScript(program, "Program", typeof(Sandbox.ModAPI.Ingame.MyGridProgram).Name, "sealed partial"));

                    var messages = new List <Message>();
                    var assembly = MyVRage.Platform.Scripting.CompileIngameScriptAsync(Path.Combine(VRage.FileSystem.MyFileSystem.UserDataPath, "SEWT-Script" + Path.GetFileName(m_modPath)), program, out messages, "SEWT Compiled PB Script", "Program", typeof(Sandbox.ModAPI.Ingame.MyGridProgram).Name).Result;

                    if (messages.Count > 0)
                    {
                        MySandboxGame.Log.WriteLineAndConsole(string.Format("There are {0} compile messages:", messages.Count));
                        int errors = 0;
                        foreach (var msg in messages)
                        {
                            MySandboxGame.Log.WriteLineAndConsole(msg.Text);

                            if (msg.IsError)
                            {
                                errors++;
                            }
                        }
                        if (errors > 0)
                        {
                            return(false);
                        }
                    }

                    if (assembly == null)
                    {
                        return(false);
                    }
                }
#endif
                return(true);
            }
            return(true);
        }
        public override void RecreateControls(bool constructor)
        {
            base.RecreateControls(constructor);

            Vector2 cbOffset         = new Vector2(-0.05f, 0.0f);
            Vector2 controlPadding   = new Vector2(0.02f, 0.02f);   // X: Left & Right, Y: Bottom & Top
            Vector2 multilinePadding = new Vector2(0.008f, 0.005f); // X: Left, Y: Bottom & Top

            float textScale     = 0.8f;
            float separatorSize = 0.02f;
            float usableWidth   = SCREEN_SIZE.X - HIDDEN_PART_RIGHT - controlPadding.X * 2;
            float hiddenPartTop = (SCREEN_SIZE.Y - 1.0f) / 2.0f;

            m_currentPosition    = -m_size.Value / 2.0f;
            m_currentPosition   += controlPadding;
            m_currentPosition.Y += hiddenPartTop;
            m_scale              = textScale;

            var caption = AddCaption(MyCommonTexts.ScreenDebugOfficial_Caption, Color.White.ToVector4(), controlPadding + new Vector2(-HIDDEN_PART_RIGHT, hiddenPartTop));

            m_currentPosition.Y += MyGuiConstants.SCREEN_CAPTION_DELTA_Y * 2.0f;

            AddCheckBox(MyCommonTexts.ScreenDebugOfficial_EnableDebugDraw, () => MyDebugDrawSettings.ENABLE_DEBUG_DRAW, (bool b) => MyDebugDrawSettings.ENABLE_DEBUG_DRAW = b, color: Color.White.ToVector4(), checkBoxOffset: cbOffset);

            m_currentPosition.Y += separatorSize;

            AddCheckBox(MyCommonTexts.ScreenDebugOfficial_ModelDummies, () => MyDebugDrawSettings.DEBUG_DRAW_MODEL_DUMMIES, (bool b) => MyDebugDrawSettings.DEBUG_DRAW_MODEL_DUMMIES = b, color: Color.White.ToVector4(), checkBoxOffset: cbOffset);
            AddCheckBox(MyCommonTexts.ScreenDebugOfficial_MountPoints, () => MyDebugDrawSettings.DEBUG_DRAW_MOUNT_POINTS, (bool b) => MyDebugDrawSettings.DEBUG_DRAW_MOUNT_POINTS    = b, color: Color.White.ToVector4(), checkBoxOffset: cbOffset);
            AddCheckBox(MyCommonTexts.ScreenDebugOfficial_PhysicsPrimitives, () => MyDebugDrawSettings.DEBUG_DRAW_PHYSICS_SHAPES, (bool b) => { MyDebugDrawSettings.DEBUG_DRAW_PHYSICS |= b; MyDebugDrawSettings.DEBUG_DRAW_PHYSICS_SHAPES = b; }, color: Color.White.ToVector4(), checkBoxOffset: cbOffset);

            m_currentPosition.Y += separatorSize;

            CreateDebugButton(usableWidth, MyCommonTexts.ScreenDebugOfficial_ReloadTextures, ReloadTextures);
            CreateDebugButton(usableWidth, MyCommonTexts.ScreenDebugOfficial_ReloadModels, ReloadModels);
            CreateDebugButton(usableWidth, MyCommonTexts.ScreenDebugOfficial_SavePrefab, SavePrefab, MyClipboardComponent.Static != null ? MyClipboardComponent.Static.Clipboard.HasCopiedGrids() : false, MyCommonTexts.ToolTipSaveShip);

            // Don't enable the SE bot debugging in official builds yet
            if (MyPerGameSettings.Game == GameEnum.ME_GAME || !MyFinalBuildConstants.IS_OFFICIAL)
            {
                CreateDebugButton(usableWidth, MyCommonTexts.ScreenDebugOfficial_BotSettings, OpenBotsScreen);
            }

            AddSubcaption(MyTexts.GetString(MyCommonTexts.ScreenDebugOfficial_ErrorLogCaption), Color.White.ToVector4(), new Vector2(-HIDDEN_PART_RIGHT, 0.0f));

            CreateDebugButton(usableWidth, MyCommonTexts.ScreenDebugOfficial_OpenErrorLog, CreateErrorLogScreen);
            CreateDebugButton(usableWidth, MyCommonTexts.ScreenDebugOfficial_CopyErrorLogToClipboard, CopyErrorLogToClipboard);

            m_currentPosition.Y += separatorSize;

            Vector2 textboxSize = (MyGuiManager.GetMaxMouseCoord() / 2.0f) - m_currentPosition;

            textboxSize.X        = usableWidth;
            textboxSize.Y       -= controlPadding.Y;
            m_currentPosition.X += multilinePadding.X / 2.0f;

            // Because multiline text does not allow padding
            var textBackground = new MyGuiControlPanel(m_currentPosition - multilinePadding, textboxSize + new Vector2(multilinePadding.X, multilinePadding.Y * 2.0f), originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);

            textBackground.BackgroundTexture = MyGuiConstants.TEXTURE_SCROLLABLE_LIST;
            Controls.Add(textBackground);

            var text = AddMultilineText(size: textboxSize);

            if (MyDefinitionErrors.GetErrors().Count() == 0)
            {
                text.AppendText(MyTexts.Get(MyCommonTexts.ScreenDebugOfficial_NoErrorText));
            }
            else
            {
                var errors          = MyDefinitionErrors.GetErrors();
                var errorDictionary = new Dictionary <string, Tuple <int, TErrorSeverity> >();

                // Count the number of most severe error per mod
                // Errors are already sorted by severity, so the first one per mod is the most severe
                foreach (var error in errors)
                {
                    var modName = error.ModName ?? "Local Content";

                    if (errorDictionary.ContainsKey(modName))
                    {
                        if (errorDictionary[modName].Item2 == error.Severity)
                        {
                            var info = errorDictionary[modName];
                            errorDictionary[modName] = new Tuple <int, TErrorSeverity>(info.Item1 + 1, info.Item2);
                        }
                    }
                    else
                    {
                        errorDictionary[modName] = new Tuple <int, TErrorSeverity>(1, error.Severity);
                    }
                }

                // Convert to list and sort to make sure most severe is displayed first
                var errorList = new List <Tuple <string, int, TErrorSeverity> >();
                foreach (var entry in errorDictionary)
                {
                    errorList.Add(new Tuple <string, int, TErrorSeverity>(entry.Key, entry.Value.Item1, entry.Value.Item2));
                }

                Comparison <Tuple <string, int, TErrorSeverity> > comp = (e1, e2) => e2.Item3 - e1.Item3;
                errorList.Sort(comp);

                foreach (var error in errorList)
                {
                    var errorText = new StringBuilder();
                    errorText.Append(error.Item1);
                    errorText.Append(" [");
                    if (error.Item3 == TErrorSeverity.Critical)
                    {
                        errorText.Append(MyDefinitionErrors.Error.GetSeverityName(error.Item3, false));
                        errorText.Append("]");
                    }
                    else
                    {
                        errorText.Append(error.Item2.ToString());
                        errorText.Append(" ");
                        errorText.Append(MyDefinitionErrors.Error.GetSeverityName(error.Item3, error.Item2 != 1));
                        errorText.Append("]");
                    }
                    text.AppendText(errorText, text.Font, text.TextScaleWithLanguage, MyDefinitionErrors.Error.GetSeverityColor(error.Item3).ToVector4());
                    text.AppendLine();
                }
            }
        }
示例#7
0
        /// <summary>
        /// Compiles the mod
        /// </summary>
        /// <returns></returns>
        public bool Compile()
        {
            // Compile
            if (m_compile)
            {
                if (m_type == WorkshopType.Mod)
                {
                    if (_compileMethod != null)
                    {
                        MySandboxGame.Log.WriteLineAndConsole("Compiling...");
#if SE
                        var mod = new MyModContext();
                        mod.Init(m_title, null, m_modPath);
#else
                        var workshopItem = new MyLocalWorkshopItem(new VRage.ObjectBuilders.SerializableModReference(Path.GetFileName(m_modPath), 0));
                        var mod          = new MyModContext(workshopItem, 0);
#endif
                        _compileMethod(
#if SE
                            m_modPath,
#endif
                            mod
                            );

                        // Process any errors
#if SE
                        var errors = MyDefinitionErrors.GetErrors();
#else
                        var compileMessages = _scriptManager.GetType().GetField("m_messages", BindingFlags.NonPublic | BindingFlags.Instance);
                        var errors          = (compileMessages.GetValue(_scriptManager) as List <MyScriptCompiler.Message>) ?? new List <MyScriptCompiler.Message>();
#endif
                        if (errors.Count > 0)
                        {
                            int errorCount   = 0;
                            int warningCount = 0;

                            // This is not efficient, but I'm lazy
                            foreach (var error in errors)
                            {
                                if (error.Severity >= TErrorSeverity.Error)
                                {
                                    errorCount++;
                                }
                                if (error.Severity == TErrorSeverity.Warning)
                                {
                                    warningCount++;
                                }
                            }

                            if (errorCount > 0)
                            {
                                MySandboxGame.Log.WriteLineAndConsole(string.Format("There are {0} compile errors:", errorCount));
                            }
                            if (warningCount > 0)
                            {
                                MySandboxGame.Log.WriteLineAndConsole(string.Format("There are {0} compile warnings:", warningCount));
                            }

                            // Output raw message, which is usually in msbuild friendly format, for automated tools
                            foreach (var error in errors)
#if SE
                            { System.Console.WriteLine(error.Message); }
#else
                            { System.Console.WriteLine(error.Text); }
#endif

#if SE
                            MyDefinitionErrors.Clear();     // Clear old ones, so next mod starts fresh
#endif

                            if (errorCount > 0)
                            {
                                MySandboxGame.Log.WriteLineAndConsole("Compilation FAILED!");
                                return(false);
                            }
                        }
                        MySandboxGame.Log.WriteLineAndConsole("Compilation successful!");
                    }
                    else
                    {
                        MySandboxGame.Log.WriteLineAndConsole(string.Format(Constants.ERROR_Reflection, "LoadScripts"));
                    }
                }
#if SE
                else if (m_type == WorkshopType.IngameScript)
                {
                    // Load the ingame script from the disk
                    // I don't like this, but meh
                    var input   = new StreamReader(Path.Combine(m_modPath, "Script.cs"));
                    var program = input.ReadToEnd();
                    input.Close();
                    var ingamescript = MyScriptCompiler.Static.GetIngameScript(program, "Program", typeof(Sandbox.ModAPI.Ingame.MyGridProgram).Name, "sealed partial");
                    var messages     = new List <MyScriptCompiler.Message>();
                    var assembly     = MyScriptCompiler.Static.Compile(MyApiTarget.Ingame, null, ingamescript, messages, null).Result;

                    if (messages.Count > 0)
                    {
                        MySandboxGame.Log.WriteLineAndConsole(string.Format("There are {0} compile messages:", messages.Count));
                        int errors = 0;
                        foreach (var msg in messages)
                        {
                            MySandboxGame.Log.WriteLineAndConsole(msg.Text);

                            if (msg.Severity > TErrorSeverity.Warning)
                            {
                                errors++;
                            }
                        }
                        if (errors > 0)
                        {
                            return(false);
                        }
                    }

                    if (assembly == null)
                    {
                        return(false);
                    }
                }
#endif
                return(true);
            }
            return(true);
        }
示例#8
0
        /// <summary>
        /// Compiles the mod
        /// </summary>
        /// <returns></returns>
        public bool Compile()
        {
            // Compile
            if (m_compile)
            {
                if (m_type == WorkshopType.Mod)
                {
                    if (_compileMethod != null)
                    {
                        MySandboxGame.Log.WriteLineAndConsole("Compiling...");
                        var mod = new MyModContext();
                        mod.Init(m_title, null, m_modPath);
                        _compileMethod.Invoke(_scriptManager, new object[]
                        {
                            m_modPath,
                            mod
                        });

                        // Process any errors
                        var errors = MyDefinitionErrors.GetErrors();
                        if (errors.Count > 0)
                        {
                            int errorCount   = 0;
                            int warningCount = 0;

                            // This is not efficient, but I'm lazy
                            foreach (var error in errors)
                            {
                                if (error.Severity >= TErrorSeverity.Error)
                                {
                                    errorCount++;
                                }
                                if (error.Severity == TErrorSeverity.Warning)
                                {
                                    warningCount++;
                                }
                            }

                            if (errorCount > 0)
                            {
                                MySandboxGame.Log.WriteLineAndConsole(string.Format("There are {0} compile errors:", errorCount));
                            }
                            if (warningCount > 0)
                            {
                                MySandboxGame.Log.WriteLineAndConsole(string.Format("There are {0} compile warnings:", warningCount));
                            }

                            // Output raw message, which is usually in msbuild friendly format, for automated tools
                            foreach (var error in errors)
                            {
                                System.Console.WriteLine(error.Message);
                            }

                            MyDefinitionErrors.Clear();     // Clear old ones, so next mod starts fresh

                            if (errorCount > 0)
                            {
                                MySandboxGame.Log.WriteLineAndConsole("Compilation FAILED!");
                                return(false);
                            }
                        }
                        MySandboxGame.Log.WriteLineAndConsole("Compilation successful!");
                    }
                    else
                    {
                        MySandboxGame.Log.WriteLineAndConsole(string.Format(Constants.ERROR_Reflection, "LoadScripts"));
                    }
                }
                else if (m_type == WorkshopType.IngameScript)
                {
                    // Load the ingame script from the disk
                    // I don't like this, but meh
                    var input   = new StreamReader(Path.Combine(m_modPath, "Script.cs"));
                    var program = input.ReadToEnd();
                    input.Close();
                    var ingamescript = MyScriptCompiler.Static.GetIngameScript(program, "Program", typeof(Sandbox.ModAPI.Ingame.MyGridProgram).Name, "sealed partial");
                    var messages     = new List <MyScriptCompiler.Message>();
                    var assembly     = MyScriptCompiler.Static.Compile(MyApiTarget.Ingame, null, ingamescript, messages).Result;

                    if (messages.Count > 0)
                    {
                        MySandboxGame.Log.WriteLineAndConsole(string.Format("There are {0} compile messages:", messages.Count));
                        int errors = 0;
                        foreach (var msg in messages)
                        {
                            MySandboxGame.Log.WriteLineAndConsole(msg.Text);

                            if (msg.Severity > TErrorSeverity.Warning)
                            {
                                errors++;
                            }
                        }
                        if (errors > 0)
                        {
                            return(false);
                        }
                    }

                    if (assembly == null)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(true);
        }