コード例 #1
0
        public static void SaveHostData(MCMHost host)
        {
            var filePath = HostFilePath(host);

            // Open it for writing
            try
            {
                Scribe.InitWriting(filePath, "ModConfigurationData");
                if (Scribe.mode == LoadSaveMode.Saving)
                {
                    // Write this library version as the one saved with
                    string version = Version.Current.ToString();
                    Scribe_Values.LookValue <string>(ref version, "ccl_version");

                    // Call the worker scribe
                    Scribe_Deep.LookDeep <MCMHost>(ref host, host.key);
                }
            }
            catch (Exception e)
            {
                CCL_Log.Trace(
                    Verbosity.NonFatalErrors,
                    string.Format("Unexpected error scribing data for mod {0}\n{1}", host.Label, e.ToString()),
                    "Mod Configuration Menu");
            }
            finally
            {
                // Finish
                Scribe.FinalizeWriting();
                Scribe.mode = LoadSaveMode.Inactive;
                Messages.Message("ModConfigurationSaved".Translate(host.Label), MessageSound.Standard);
            }
            host.OpenedThisSession = false;
        }
コード例 #2
0
        public static bool InitializeHosts(bool preload = false)
        {
            if (preload)
            {
                Controller.Data.MCMHosts.Clear();
            }

            // Get the mods with config menus
            foreach (var mhd in Controller.Data.ModHelperDefs)
            {
                // Create all the menus for it
                if (!mhd.ModConfigurationMenus.NullOrEmpty())
                {
                    foreach (var mcm in mhd.ModConfigurationMenus)
                    {
                        if ( // Filter out preload during non-preload and non-preload during preload
                            (
                                (preload) &&
                                (mcm.preload)
                            ) ||
                            (
                                (!preload) &&
                                (!mcm.preload)
                            )
                            )
                        {
                            var host = Controller.Data.MCMHosts.Find(m => m.worker.InjectionSet == mcm);
                            if (host != null)
                            {   // MCM already created....?
                                CCL_Log.TraceMod(
                                    mhd,
                                    Verbosity.Warnings,
                                    string.Format("{0} - Tried to create an MCM when an MCM already exists", mcm.mcmClass.ToString())
                                    );
                                continue;
                            }
                            host        = new MCMHost();
                            host.Label  = mcm.label;
                            host.worker = (ModConfigurationMenu)Activator.CreateInstance(mcm.mcmClass);
                            if (host.worker == null)
                            {
                                CCL_Log.Error(string.Format("Unable to create instance of {0}", mcm.mcmClass.ToString()));
                                return(false);
                            }
                            else
                            {   // Initialize, add it to the menu list and then load it's data
                                host.worker.InjectionSet = mcm;
                                host.worker.Initialize();
                                Controller.Data.MCMHosts.Add(host);
                                LoadHostData(host);
                            }
                        }
                    }
                }
            }
            return(true);
        }
コード例 #3
0
        private static string HostFilePath(MCMHost host)
        {
            // Generate the config file name
            string filePath = Path.Combine(GenFilePaths.ConfigFolderPath, ConfigFilePrefix);

            filePath += host.key;
            filePath += ConfigFileSuffix;
            return(filePath);
        }
コード例 #4
0
        private static string HostFilePath(MCMHost host)
        {
            // Generate the config file name
            // A14 - ConfigFolderPath became private - take a step back from the public ConfigFilePath
            // - Fluffy
            string configFolder = Path.GetDirectoryName(GenFilePaths.ConfigFilePath);
            string filePath     = Path.Combine(configFolder, ConfigFilePrefix);

            filePath += host.key;
            filePath += ConfigFileSuffix;
            return(filePath);
        }
コード例 #5
0
        void DrawSelectionArea(Rect rect)
        {
            Widgets.DrawMenuSection(rect);

            _filterUpdate();
            var filterRect = new Rect(rect.xMin + Margin, rect.yMin + Margin, rect.width - 3 * Margin - 30f, 30f);
            var clearRect  = new Rect(filterRect.xMax + Margin + 3f, rect.yMin + Margin + 3f, 24f, 24f);

            _filterString = Widgets.TextField(filterRect, _filterString);
            if (_filterString != "")
            {
                if (Widgets.ImageButton(clearRect, Widgets.CheckboxOffTex))
                {
                    ResetFilter();
                }
            }

            Rect outRect = rect;

            outRect.yMin += 40f;
            outRect.xMax -= 2f;             // some spacing around the scrollbar

            float viewWidth = SelectionHeight > outRect.height ? outRect.width - 16f : outRect.width;
            var   viewRect  = new Rect(0f, 0f, viewWidth, SelectionHeight);

            GUI.BeginGroup(outRect);
            Widgets.BeginScrollView(outRect.AtZero(), ref SelectionScrollPos, viewRect);

            if (!filteredHosts.NullOrEmpty())
            {
                Vector2 cur = Vector2.zero;

                foreach (var host in filteredHosts)
                {
                    if (DrawHost(ref cur, viewRect, host))
                    {
                        SelectedHost = host;
                    }
                }

                SelectionHeight = cur.y;
            }

            Widgets.EndScrollView();
            GUI.EndGroup();
        }
コード例 #6
0
        public override void PreClose()
        {
            if (SelectedHost != null)
            {
                SelectedHost.worker.PostClose();
            }
            base.PreClose();

            for (int index = 0; index < Controller.Data.MCMHosts.Count; ++index)
            {
                // Get host to work with
                var host = Controller.Data.MCMHosts[index];

                if (host.OpenedThisSession)
                {
                    MCMHost.SaveHostData(host);
                }
            }
        }
コード例 #7
0
        private bool DrawHost(ref Vector2 cur, Rect view, MCMHost host)
        {
            float  width  = view.width - cur.x - Margin;
            float  height = EntryHeight;
            string label  = host.Label;

            if (Text.CalcHeight(label, width) > EntryHeight)
            {
                Text.Font = GameFont.Tiny;
                float height2 = Text.CalcHeight(label, width);
                height = Mathf.Max(height, height2);
            }

            Text.Anchor = TextAnchor.MiddleLeft;
            Rect labelRect = new Rect(cur.x + Margin, cur.y, width - Margin, height);

            Widgets.Label(labelRect, label);
            Text.Anchor = TextAnchor.UpperLeft;
            Text.Font   = GameFont.Small;

            // full viewRect width for overlay and button
            Rect buttonRect = view;

            buttonRect.yMin = cur.y;
            cur.y          += height;
            buttonRect.yMax = cur.y;
            GUI.color       = Color.grey;
            Widgets.DrawLineHorizontal(view.xMin, cur.y, view.width);
            GUI.color = Color.white;
            if (SelectedHost == host)
            {
                Widgets.DrawHighlightSelected(buttonRect);
            }
            else
            {
                Widgets.DrawHighlightIfMouseover(buttonRect);
            }
            return(Widgets.InvisibleButton(buttonRect));
        }
コード例 #8
0
        public static void LoadHostData(MCMHost host)
        {
            var filePath = HostFilePath(host);

            if (!File.Exists(filePath))
            {
                return;
            }

            try
            {
                // Open it for reading
                Scribe.InitLoading(filePath);
                if (Scribe.mode == LoadSaveMode.LoadingVars)
                {
                    // Version check
                    string version = "";
                    Scribe_Values.LookValue <string>(ref version, "ccl_version");

                    bool okToLoad = true;
                    var  result   = Version.Compare(version);
                    if (result == Version.VersionCompare.GreaterThanMax)
                    {
                        CCL_Log.Trace(
                            Verbosity.NonFatalErrors,
                            string.Format("Data for {0} is newer ({1}) than the version you are using ({2}).", host.Label, version, Version.Current.ToString()),
                            "Mod Configuration Menu");
                        okToLoad = false;
                    }
                    else if (result == Version.VersionCompare.Invalid)
                    {
                        CCL_Log.Trace(
                            Verbosity.NonFatalErrors,
                            string.Format("Data for {0} is corrupt and will be discarded", host.Label),
                            "Mod Configuration Menu");
                        okToLoad = false;
                    }

                    if (okToLoad)
                    {
                        // Call the worker scribe
                        var args = new object[]
                        {
                            host.Label,
                            host.worker
                        };
                        Scribe_Deep.LookDeep <MCMHost>(ref host, host.key, args);
                    }
                }
            }
            catch (Exception e)
            {
                CCL_Log.Trace(
                    Verbosity.NonFatalErrors,
                    string.Format("Unexpected error scribing data for mod {0}\n{1}", host.Label, e.ToString()),
                    "Mod Configuration Menu");
            }
            finally
            {
                // Finish
                Scribe.FinalizeLoading();
                Scribe.mode = LoadSaveMode.Inactive;
            }
        }
コード例 #9
0
 public Window_ModConfigurationMenu(ModConfigurationMenu selectedMenu)
 {
     cTor_Common();
     this.SelectedHost = filteredHosts.Find(host => host.worker == selectedMenu);
 }
コード例 #10
0
        void DrawDisplayArea(Rect rect)
        {
            Widgets.DrawMenuSection(rect);

            if (SelectedHost == null)
            {
                return;
            }
            if (
                (PreviouslySelectedHost != null) &&
                (PreviouslySelectedHost != SelectedHost)
                )
            {
                PreviouslySelectedHost.worker.PostClose();
            }
            if (PreviouslySelectedHost != SelectedHost)
            {
                SelectedHost.OpenedThisSession = true;
                SelectedHost.worker.PreOpen();
            }
            PreviouslySelectedHost = SelectedHost;

            Text.Font     = GameFont.Medium;
            Text.WordWrap = false;
            var titleRect = new Rect(rect.xMin, rect.yMin, rect.width, 60f);

            Text.Anchor = TextAnchor.MiddleCenter;
            Widgets.Label(titleRect, SelectedHost.Label);

            Text.Font     = GameFont.Small;
            Text.Anchor   = TextAnchor.UpperLeft;
            Text.WordWrap = true;

            Rect outRect = rect.ContractedBy(Margin);

            outRect.yMin += 60f;
            Rect viewRect = outRect;

            viewRect.width -= 16f;
            viewRect.height = ContentHeight;

            GUI.BeginGroup(outRect);
            Widgets.BeginScrollView(outRect.AtZero(), ref DisplayScrollPos, viewRect.AtZero());

            bool   userError    = false;
            string userErrorStr = string.Empty;

            try
            {
                ContentHeight = SelectedHost.worker.DoWindowContents(viewRect.AtZero());
            }
            catch (Exception e)
            {
                userError    = true;
                userErrorStr = e.ToString();
            }

            Widgets.EndScrollView();
            GUI.EndGroup();

            if (userError)
            {
                CCL_Log.Trace(
                    Verbosity.NonFatalErrors,
                    userErrorStr,
                    "Mod Configuration Menu"
                    );
            }
        }
コード例 #11
0
        public static bool InitializeHosts( bool preload = false )
        {
            if( preload )
            {
                Controller.Data.MCMHosts.Clear();
            }

            // Get the mods with config menus
            foreach( var mhd in Controller.Data.ModHelperDefs )
            {
                // Create all the menus for it
                if( !mhd.ModConfigurationMenus.NullOrEmpty() )
                {
                    foreach( var mcm in mhd.ModConfigurationMenus )
                    {
                        if( // Filter out preload during non-preload and non-preload during preload
                           (
                               ( preload )&&
                               ( mcm.preload )
                              )||
                           (
                               ( !preload )&&
                               ( !mcm.preload )
                              )
                          )
                        {
                            var host = Controller.Data.MCMHosts.Find( m => m.worker.InjectionSet == mcm );
                            if( host != null )
                            {   // MCM already created....?
                                CCL_Log.TraceMod(
                                    mhd,
                                    Verbosity.Warnings,
                                    string.Format( "{0} - Tried to create an MCM when an MCM already exists", mcm.mcmClass.ToString() )
                                );
                                continue;
                            }
                            host = new MCMHost();
                            host.Label = mcm.label;
                            host.worker = (ModConfigurationMenu)Activator.CreateInstance( mcm.mcmClass );
                            if( host.worker == null )
                            {
                                CCL_Log.Error( string.Format( "Unable to create instance of {0}", mcm.mcmClass.ToString() ) );
                                return false;
                            }
                            else
                            {   // Initialize, add it to the menu list and then load it's data
                                host.worker.InjectionSet = mcm;
                                host.worker.Initialize();
                                Controller.Data.MCMHosts.Add( host );
                                LoadHostData( host );
                            }
                        }
                    }
                }
            }
            return true;
        }
コード例 #12
0
 private static string HostFilePath( MCMHost host )
 {
     // Generate the config file name
     // A14 - ConfigFolderPath became private - take a step back from the public ConfigFilePath
     // - Fluffy
     string configFolder = Path.GetDirectoryName( GenFilePaths.ConfigFilePath );
     string filePath = Path.Combine( configFolder, ConfigFilePrefix );
     filePath += host.key;
     filePath += ConfigFileSuffix;
     return filePath;
 }
コード例 #13
0
        public static void SaveHostData( MCMHost host )
        {
            var filePath = HostFilePath( host );

            // Open it for writing
            try
            {
                Scribe.InitWriting( filePath, "ModConfigurationData" );
                if( Scribe.mode == LoadSaveMode.Saving )
                {
                    // Write this library version as the one saved with
                    string version = Version.Current.ToString();
                    Scribe_Values.LookValue<string>( ref version, "ccl_version" );

                    // Call the worker scribe
                    Scribe_Deep.LookDeep<MCMHost>( ref host, host.key );
                }
            }
            catch( Exception e )
            {
                CCL_Log.Trace(
                    Verbosity.NonFatalErrors,
                    string.Format( "Unexpected error scribing data for mod {0}\n{1}", host.Label, e.ToString() ),
                    "Mod Configuration Menu" );
            }
            finally
            {
                // Finish
                Scribe.FinalizeWriting();
                Scribe.mode = LoadSaveMode.Inactive;
                Messages.Message( "ModConfigurationSaved".Translate( host.Label ), MessageSound.Standard );
            }
            host.OpenedThisSession = false;
        }
コード例 #14
0
        public static void LoadHostData( MCMHost host )
        {
            var filePath = HostFilePath( host );

            if( !File.Exists( filePath ) )
            {
                return;
            }

            try
            {
                // Open it for reading
                Scribe.InitLoading( filePath );
                if( Scribe.mode == LoadSaveMode.LoadingVars )
                {
                    // Version check
                    string version = "";
                    Scribe_Values.LookValue<string>( ref version, "ccl_version" );

                    bool okToLoad = true;
                    var result = Version.Compare( version );
                    if( result == Version.VersionCompare.GreaterThanMax )
                    {
                        CCL_Log.Trace(
                            Verbosity.NonFatalErrors,
                            string.Format( "Data for {0} is newer ({1}) than the version you are using ({2}).", host.Label, version, Version.Current.ToString() ),
                            "Mod Configuration Menu" );
                        okToLoad = false;
                    }
                    else if( result == Version.VersionCompare.Invalid )
                    {
                        CCL_Log.Trace(
                            Verbosity.NonFatalErrors,
                            string.Format( "Data for {0} is corrupt and will be discarded", host.Label ),
                            "Mod Configuration Menu" );
                        okToLoad = false;
                    }

                    if( okToLoad )
                    {
                        // Call the worker scribe
                        var args = new object[]
                        {
                            host.Label,
                            host.worker
                        };
                        Scribe_Deep.LookDeep<MCMHost>( ref host, host.key, args );
                    }
                }
            }
            catch( Exception e )
            {
                CCL_Log.Trace(
                    Verbosity.NonFatalErrors,
                    string.Format( "Unexpected error scribing data for mod {0}\n{1}", host.Label, e.ToString() ),
                    "Mod Configuration Menu" );
            }
            finally
            {
                // Finish
                Scribe.FinalizeLoading();
                Scribe.mode = LoadSaveMode.Inactive;
            }
        }