Esempio n. 1
0
        public override void OnLoad(ConfigNode node)
        {
            try
            {
                lastMCButton            = ConfigNodeUtil.ParseValue <MissionControlButton>(node, "lastMCButton", MissionControlButton.All);
                DisplayOfferedOrbits    = ConfigNodeUtil.ParseValue <bool?>(node, "DisplayOfferedOrbits", (bool?)ContractDefs.DisplayOfferedOrbits).Value;
                DisplayOfferedWaypoints = ConfigNodeUtil.ParseValue <bool?>(node, "DisplayOfferedWaypoints", (bool?)ContractDefs.DisplayOfferedWaypoints).Value;
                DisplayActiveOrbits     = ConfigNodeUtil.ParseValue <bool?>(node, "DisplayActiveOrbits", (bool?)true).Value;
                DisplayActiveWaypoints  = ConfigNodeUtil.ParseValue <bool?>(node, "DisplayActiveWaypoints", (bool?)true).Value;

                foreach (ConfigNode groupNode in node.GetNodes("CONTRACT_GROUP"))
                {
                    string groupName = groupNode.GetValue("group");

                    if (ContractGroup.contractGroups.ContainsKey(groupName))
                    {
                        ContractGroup group = ContractGroup.contractGroups[groupName];

                        ContractGroupDetails details = new ContractGroupDetails(group);
                        details.enabled = ConfigNodeUtil.ParseValue <bool>(groupNode, "enabled");

                        contractGroupDetails[group.name] = details;
                    }
                    else
                    {
                        LoggingUtil.LogWarning(this, "Couldn't find contract group with name '" + groupName + "'");
                    }
                }

                foreach (ConfigNode stateNode in node.GetNodes("CONTRACT_STATE"))
                {
                    string typeName = stateNode.GetValue("type");
                    if (!string.IsNullOrEmpty(typeName))
                    {
                        Type contractType = null;
                        try
                        {
                            contractType = ConfigNodeUtil.ParseTypeValue(typeName);
                            StockContractDetails details = new StockContractDetails(contractType);
                            details.enabled = ConfigNodeUtil.ParseValue <bool>(stateNode, "enabled");

                            stockContractDetails[contractType] = details;

                            ContractDisabler.SetContractState(contractType, details.enabled);
                        }
                        catch (ArgumentException)
                        {
                            LoggingUtil.LogWarning(this, "Couldn't find contract type with name '" + typeName + "'");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LoggingUtil.LogError(this, "Error loading ContractConfiguratorSettings from persistance file!");
                LoggingUtil.LogException(e);
                ExceptionLogWindow.DisplayFatalException(ExceptionLogWindow.ExceptionSituation.SCENARIO_MODULE_LOAD, e, "ContractConfiguratorSettings");
            }
        }
Esempio n. 2
0
            public StockContractDetails(Type contractType)
            {
                this.contractType = contractType;
                enabled           = ContractDisabler.IsEnabled(contractType);

                if (!stockGroupDetails.ContainsKey(contractType.Module))
                {
                    stockGroupDetails[contractType.Module] = new ContractGroupDetails(contractType.Module);
                }
            }
Esempio n. 3
0
        private void StockGroupLine()
        {
            foreach (KeyValuePair <Module, ContractGroupDetails> gpair in stockGroupDetails.OrderBy(p => p.Key.Name == "Assembly-CSharp.dll" ? "ZZZ" : p.Key.Name))
            {
                Module module = gpair.Key;
                ContractGroupDetails groupDetails = gpair.Value;

                GUILayout.BeginHorizontal();

                if (GUILayout.Button(groupDetails.expanded ? "-" : "+", expandButtonStyle, GUILayout.Width(20), GUILayout.Height(20)))
                {
                    groupDetails.expanded = !groupDetails.expanded;
                }
                string groupName = module.Name == "Assembly-CSharp.dll" ? "Stock Contracts" : module.Name.Remove(module.Name.Length - 4);
                GUILayout.Label(groupName, groupRegularText, GUILayout.ExpandWidth(true));
                GUILayout.EndHorizontal();

                if (groupDetails.expanded)
                {
                    foreach (KeyValuePair <Type, StockContractDetails> pair in stockContractDetails.Where(p => p.Key.Module == module).OrderBy(p => p.Key.Name))
                    {
                        Type subclass = pair.Key;
                        StockContractDetails details = pair.Value;

                        string hintText;
                        IEnumerable <ContractGroup> disablingGroups = ContractDisabler.DisablingGroups(subclass);
                        if (disablingGroups.Any())
                        {
                            hintText = subclass.Name + " disabled by: " +
                                       string.Join(", ", disablingGroups.Select(g => g == null ? "unknown" : g.displayName).ToArray()) + "\n";
                            hintText += "Click to " + (details.enabled ? "disable " : "re-enable ") + subclass.Name + ".";
                        }
                        else
                        {
                            hintText = "Click to " + (details.enabled ? "disable " : "enable ") + subclass.Name + ".";
                        }

                        GUILayout.BeginHorizontal();
                        GUILayout.Label("", contractRegularText, GUILayout.ExpandWidth(false), GUILayout.Width(32));
                        GUILayout.Label(new GUIContent(subclass.Name, hintText), details.enabled ? contractRegularText : contractDisabledText, GUILayout.ExpandWidth(true));

                        bool newState = GUILayout.Toggle(details.enabled, new GUIContent("", hintText),
                                                         contractToggleStyle, GUILayout.ExpandWidth(false));
                        GUILayout.EndHorizontal();

                        if (newState != details.enabled)
                        {
                            details.enabled = newState;
                            ContractDisabler.SetContractState(subclass, details.enabled);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            foreach (Type subclass in ContractConfigurator.GetAllTypes <Contract>().Where(t => t != null && !t.Name.StartsWith("ConfiguredContract")))
            {
                FieldInfo fi = GetType().GetField(SettingsBuilder.SanitizeName(subclass.Name));
                if (fi != null)
                {
                    bool val = (bool)fi.GetValue(this);
                    ContractDisabler.SetContractState(subclass, val);
                }
            }
        }
Esempio n. 5
0
        private void ContractGroupLine(ContractGroup contractGroup, int indent = 0)
        {
            string identifier = contractGroup == null ? "" : contractGroup.name;

            if (!contractGroupDetails.ContainsKey(identifier))
            {
                contractGroupDetails[identifier] = new ContractGroupDetails(contractGroup);
            }
            ContractGroupDetails details = contractGroupDetails[identifier];

            GUILayout.BeginHorizontal();

            GUILayout.Label("", contractRegularText, GUILayout.ExpandWidth(false), GUILayout.Width((indent + 1) * 16));

            string groupName = contractGroup == null ? "No Group" : contractGroup.displayName;

            GUILayout.Label(groupName, details.enabled ? contractRegularText : contractDisabledText, GUILayout.ExpandWidth(true));
            if (contractGroup != null && contractGroup.parent == null)
            {
                bool enabled = GUILayout.Toggle(details.enabled,
                                                new GUIContent("", "Click to " + (details.enabled ? "disable " : "enable ") + contractGroup.displayName + " contracts."),
                                                contractToggleStyle, GUILayout.ExpandWidth(false));

                if (enabled != details.enabled)
                {
                    details.enabled = enabled;
                    if (enabled)
                    {
                        foreach (KeyValuePair <Type, StockContractDetails> pair in stockContractDetails.
                                 Where(p => ContractDisabler.DisablingGroups(p.Key).Contains(contractGroup)))
                        {
                            pair.Value.enabled = false;
                            ContractDisabler.SetContractState(pair.Key, false);
                        }
                    }
                    else
                    {
                        foreach (KeyValuePair <Type, StockContractDetails> pair in stockContractDetails.
                                 Where(p => ContractDisabler.DisablingGroups(p.Key).Contains(contractGroup) &&
                                       ContractDisabler.DisablingGroups(p.Key).All(g => !IsEnabled(g))))
                        {
                            pair.Value.enabled = true;
                            ContractDisabler.SetContractState(pair.Key, true);
                        }
                    }
                }
            }
            GUILayout.EndHorizontal();
        }
Esempio n. 6
0
        private void SeedStockContractDetails()
        {
            // Enable everything
            foreach (Type subclass in ContractConfigurator.GetAllTypes <Contract>().Where(t => t != null && !t.Name.StartsWith("ConfiguredContract")))
            {
                ContractDisabler.SetContractState(subclass, true);
            }

            // Make sure that the initial state has been correctly set
            ContractDisabler.contractsDisabled = false;
            ContractDisabler.DisableContracts();

            foreach (Type subclass in ContractConfigurator.GetAllTypes <Contract>().Where(t => t != null && !t.Name.StartsWith("ConfiguredContract")))
            {
                if (!stockContractDetails.ContainsKey(subclass))
                {
                    stockContractDetails[subclass] = new StockContractDetails(subclass);
                    if (ContractSystem.ContractTypes != null)
                    {
                        stockContractDetails[subclass].enabled = ContractSystem.ContractTypes.Any(t => t == subclass);
                    }
                }
            }
        }
Esempio n. 7
0
 void Awake()
 {
     Instance = this;
     DontDestroyOnLoad(this);
 }
 void Awake()
 {
     Instance = this;
     DontDestroyOnLoad(this);
 }