Example #1
0
        public override void SetVisible(bool newValue)
        {
            base.SetVisible(newValue);

            if (newValue)
            {
                //Get the play modes
                playModeNodes = playModeHelper.GetModes();

                //Get the button labels
                List <string> modeNames = new List <string>();
                foreach (ConfigNode node in playModeNodes)
                {
                    if (node.HasValue("name"))
                    {
                        modeNames.Add(node.GetValue("name"));
                    }
                }
                playModeNames = modeNames.ToArray();

                //Get the current play mode.
                selectedIndex = playModeHelper.GetCurrentModeIndex();
                currentIndex  = selectedIndex;

                //Get current mode
                currentPlayMode = playModeNames[currentIndex];
            }
        }
Example #2
0
        public void Awake()
        {
            //Only do this once...
            if (ModeMismatchChecked)
            {
                return;
            }
            ModeMismatchChecked = true;

            WBIPlayModeHelper helper = new WBIPlayModeHelper();

            //If we have a config file, then get the current mode.
            helper.GetModes();
            string playModeName = helper.GetPlayModeFromFile();
            int    index        = helper.GetPlayModeIndex(playModeName);

            if (index == -1)
            {
                //No config file so let's see if CRP is installed.
                string playModeFile = KSPUtil.ApplicationRootPath.Replace("\\", "/") + "GameData/CommunityResourcePack/CRP.version";

                //If the file exists then find the CRP play mode
                if (System.IO.File.Exists(playModeFile))
                {
                    index = helper.GetPlayModeIndex("CRP");
                    if (index == -1)
                    {
                        return;
                    }
                }
            }

            //Now auto-detect the current mode.
            int autoDetectIndex = helper.AutodetectMode();

            if (autoDetectIndex == -1)
            {
                return;
            }

            //If the modes don't match then make sure we're using the correct templates.
            //This will ensure that we can distribute mods with Classic Stock as the default mode
            //but not break players' saves.
            if (index != autoDetectIndex)
            {
                Debug.Log("[WBIModeChecker] - Play Mode mismatch detected, setting correct templates.");
                helper.SetPlayMode(index);
            }
        }