示例#1
0
        /// <summary>
        /// Called when initializing mod settings UI.
        /// </summary>
        /// <param name="helper">The helper.</param>
        public void OnSettingsUI(UIHelperBase helper)
        {
            try
            {
                this.InitializeHelper(helper);

                helper.AddCheckbox(
                    "Create HTML report automatically",
                    Global.Settings.CreateHtmlReportOnLevelLoaded,
                    value =>
                {
                    try
                    {
                        if (Global.Settings.CreateHtmlReportOnLevelLoaded != value)
                        {
                            Global.Settings.CreateHtmlReportOnLevelLoaded = value;
                            Global.Settings.Save();
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(this, "OnSettingsUI", ex, "CreateHtmlReportOnLevelLoaded", value);
                    }
                });

                helper.AddCheckbox(
                    "Create text file report automatically",
                    Global.Settings.CreateDataReportOnLevelLoaded,
                    value =>
                {
                    try
                    {
                        if (Global.Settings.CreateDataReportOnLevelLoaded != value)
                        {
                            Global.Settings.CreateDataReportOnLevelLoaded = value;
                            Global.Settings.Save();
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(this, "OnSettingsUI", ex, "CreateDataReportOnLevelLoaded", value);
                    }
                });

                this.HtmlReportButton = (UIComponent)helper.AddButton(
                    FileSystem.CanOpenFile ? "HTML report" : "Save HTML report",
                    () =>
                {
                    try
                    {
                        if (FileSystem.CanOpenFile)
                        {
                            AssetReporter.SaveReports(false, true, false);
                            AssetReporter.OpenHtmlReport();
                        }
                        else
                        {
                            AssetReporter.SaveReports(true, true, false);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(this, "OnSettingsUI", ex, "HtmlReportButton");
                    }
                });

                this.DataReportButton = (UIComponent)helper.AddButton(
                    FileSystem.CanOpenFile ? "Text report" : "Save text report",
                    () =>
                {
                    try
                    {
                        if (FileSystem.CanOpenFile)
                        {
                            AssetReporter.SaveReports(false, false, true);
                            AssetReporter.OpenDataReport();
                        }
                        else
                        {
                            AssetReporter.SaveReports(true, false, true);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(this, "OnSettingsUI", ex, "DataReportButton");
                    }
                });
            }
            catch (Exception ex)
            {
                Log.Error(this, "OnSettingsUI", ex);
            }
        }
        /// <summary>
        /// Called when map (etc) is loaded.
        /// </summary>
        /// <param name="mode">The load mode.</param>
        public override void OnLevelLoaded(LoadMode mode)
        {
            try
            {
                Log.Debug(this, "OnLevelLoaded", "Begin");

                Global.LevelLoaded = true;

                try
                {
                    // Save asset report.
                    try
                    {
                        AssetReporter.SaveReports(true, Global.Settings.CreateHtmlReportOnLevelLoaded, Global.Settings.CreateDataReportOnLevelLoaded);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(this, "OnLevelLoaded", ex);
                    }

                    // Save assets and objects.
                    if (Global.UseAseteers)
                    {
                        try
                        {
                            foreach (IAsseteer asseteer in Global.Asseteers)
                            {
                                Log.Debug(this, "OnLevelLoaded", "Save", asseteer.GetType().ToString());

                                // Save assets.
                                try
                                {
                                    Log.Debug(this, "OnLevelLoaded", asseteer.GetType().ToString());
                                    asseteer.SaveAssets();
                                }
                                catch (Exception ex)
                                {
                                    Log.Error(this, "OnLevelLoaded", ex, asseteer.GetType().ToString());
                                }

                                // Save objects.
                                try
                                {
                                    Log.Debug(this, "OnLevelLoaded", asseteer.GetType().ToString());
                                    asseteer.SaveObjects();
                                }
                                catch (Exception ex)
                                {
                                    Log.Error(this, "OnLevelLoaded", ex, asseteer.GetType().ToString());
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Error(this, "OnLevelLoaded", ex);
                        }
                    }
                }
                finally
                {
                    Log.Debug(this, "OnLevelLoaded", "Base");
                    base.OnLevelLoaded(mode);
                }

                Log.Debug(this, "OnLevelLoaded", "End");
            }
            finally
            {
                Log.Buffer = false;
            }
        }