Exemplo n.º 1
0
        private static void GroupGui(ContractGroup contractGroup, int indent)
        {
            if (contractGroup != null)
            {
                GUILayout.BeginHorizontal();

                if (indent != 0)
                {
                    GUILayout.Label("", GUILayout.ExpandWidth(false), GUILayout.Width(indent * 16));
                }

                if (GUILayout.Button(contractGroup.expandInDebug ? "-" : "+", GUILayout.Width(20), GUILayout.Height(20)))
                {
                    contractGroup.expandInDebug = !contractGroup.expandInDebug;
                }

                GUIStyle style = greenLabel;
                if (!contractGroup.enabled)
                {
                    style = redLabel;
                }
                else
                {
                    if (contractGroup.hasWarnings)
                    {
                        style = yellowLabel;
                    }

                    foreach (ContractType contractType in guiContracts.Where(ct => contractGroup == null ? ct.group == null : contractGroup.BelongsToGroup(ct)))
                    {
                        if (!contractType.enabled)
                        {
                            style = redLabel;
                            break;
                        }
                        else if (contractType.hasWarnings)
                        {
                            style = yellowLabel;
                        }
                    }
                }

                GUILayout.Label(new GUIContent(contractGroup.ToString(), DebugInfo(contractGroup)), style);
                GUILayout.EndHorizontal();
            }

            if (contractGroup == null || contractGroup.expandInDebug)
            {
                // Child groups
                if (contractGroup != null)
                {
                    foreach (ContractGroup childGroup in ContractGroup.AllGroups.Where(g => g != null && g.parent != null && g.parent.name == contractGroup.name).OrderBy(cg => cg.name))
                    {
                        GroupGui(childGroup, indent + 1);
                    }
                }

                // Child contract types
                foreach (ContractType contractType in guiContracts.Where(ct => ct.group == contractGroup).OrderBy(ct => ct.name))
                {
                    GUILayout.BeginHorizontal();

                    if (contractGroup != null)
                    {
                        GUILayout.Label("", GUILayout.ExpandWidth(false), GUILayout.Width((indent + 1) * 16));
                    }

                    if (GUILayout.Button(contractType.expandInDebug ? "-" : "+", GUILayout.Width(20), GUILayout.Height(20)))
                    {
                        contractType.expandInDebug = !contractType.expandInDebug;
                    }
                    GUILayout.Label(new GUIContent(contractType.ToString(), DebugInfo(contractType)),
                                    contractType.enabled ? contractType.hasWarnings ? yellowLabel : GUI.skin.label : redLabel);
                    GUILayout.EndHorizontal();

                    if (contractType.expandInDebug)
                    {
                        // Output children
                        ParamGui(contractType, contractType.ParamFactories, indent + (contractGroup == null ? 1 : 2));
                        RequirementGui(contractType, contractType.Requirements, indent + (contractGroup == null ? 1 : 2));
                        BehaviourGui(contractType, contractType.BehaviourFactories, indent + (contractGroup == null ? 1 : 2));

                        GUILayout.Space(8);
                    }
                }
            }
        }
        protected bool CheckContractGroup(ConfiguredContract contract, ContractGroup group)
        {
            if (group != null)
            {
                // Check the group is enabled
                if (!ContractConfiguratorSettings.IsEnabled(group))
                {
                    throw new ContractRequirementException("Contract group " + group.name + " is not enabled.");
                }

                IEnumerable<ConfiguredContract> contractList = ContractSystem.Instance.GetCurrentContracts<ConfiguredContract>().
                    Where(c => c.contractType != null);

                // Special case for pre-loader contracts
                if (contract.ContractState == Contract.State.Withdrawn)
                {
                    contractList = contractList.Union(ContractPreLoader.Instance.PendingContracts(contract.Prestige));
                    contractList = contractList.Where(c => c != contract);
                }

                // Check the group active limit
                int activeContracts = contractList.Count(c => c.contractType != null && group.BelongsToGroup(c.contractType));
                if (contract.ContractState == Contract.State.Offered || contract.ContractState == Contract.State.Active)
                {
                    activeContracts--;
                }

                if (group.maxSimultaneous != 0 && activeContracts >= group.maxSimultaneous)
                {
                    throw new ContractRequirementException("Too many active contracts in group (" + group.name + ").");
                }

                // Check the group completed limit
                if (group.maxCompletions != 0)
                {
                    int finishedContracts = ContractSystem.Instance.GetCompletedContracts<ConfiguredContract>().Count(c => c.contractType != null && group.BelongsToGroup(c.contractType));
                    if (finishedContracts + activeContracts >= maxCompletions)
                    {
                        throw new ContractRequirementException("Too many completed contracts in group (" + group.name + ").");
                    }
                }

                return CheckContractGroup(contract, group.parent);
            }

            return true;
        }
Exemplo n.º 3
0
        protected bool CheckContractGroup(ConfiguredContract contract, ContractGroup group)
        {
            if (group != null)
            {
                // Check the group is enabled
                if (!((ContractGroupParametersTemplate)HighLogic.CurrentGame.Parameters.CustomParams(SettingsBuilder.GroupParametersType)).IsEnabled(group.Root.name))
                {
                    throw new ContractRequirementException("Contract group " + group.name + " is not enabled.");
                }

                IEnumerable <ConfiguredContract> contractList = ConfiguredContract.CurrentContracts.
                                                                Where(c => c.contractType != null && c != contract);

                // Check the group active limit
                int activeContracts = contractList.Count(c => c.contractType != null && group.BelongsToGroup(c.contractType));
                if (group.maxSimultaneous != 0 && activeContracts >= group.maxSimultaneous)
                {
                    throw new ContractRequirementException("Too many active contracts in group (" + group.name + ").");
                }

                // Check the group completed limit
                if (group.maxCompletions != 0)
                {
                    int finishedContracts = ConfiguredContract.CompletedContracts.Count(c => c.contractType != null && group.BelongsToGroup(c.contractType));
                    if (finishedContracts + activeContracts >= maxCompletions)
                    {
                        throw new ContractRequirementException("Too many completed contracts in group (" + group.name + ").");
                    }
                }

                return(CheckContractGroup(contract, group.parent));
            }

            return(true);
        }
        private static void GroupGui(ContractGroup contractGroup, int indent)
        {
            if (contractGroup != null)
            {
                GUILayout.BeginHorizontal();

                if (indent != 0)
                {
                    GUILayout.Label("", GUILayout.ExpandWidth(false), GUILayout.Width(indent * 16));
                }

                if (GUILayout.Button(contractGroup.expandInDebug ? "-" : "+", GUILayout.Width(20), GUILayout.Height(20)))
                {
                    contractGroup.expandInDebug = !contractGroup.expandInDebug;
                }

                GUIStyle style = greenLabel;
                if (!contractGroup.enabled)
                {
                    style = redLabel;
                }
                else
                {
                    if (contractGroup.hasWarnings)
                    {
                        style = yellowLabel;
                    }

                    foreach (ContractType contractType in guiContracts.Where(ct => contractGroup == null ? ct.group == null : contractGroup.BelongsToGroup(ct)))
                    {
                        if (!contractType.enabled)
                        {
                            style = redLabel;
                            break;
                        }
                        else if (contractType.hasWarnings)
                        {
                            style = yellowLabel;
                        }
                    }
                }

                GUILayout.Label(new GUIContent(contractGroup.ToString(), DebugInfo(contractGroup)), style);
                GUILayout.EndHorizontal();
            }

            if (contractGroup == null || contractGroup.expandInDebug)
            {
                // Child groups
                if (contractGroup != null)
                {
                    foreach (ContractGroup childGroup in ContractGroup.AllGroups.Where(g => g != null && g.parent != null && g.parent.name == contractGroup.name))
                    {
                        GroupGui(childGroup, indent + 1);
                    }
                }

                // Child contract types
                foreach (ContractType contractType in guiContracts.Where(ct => ct.group == contractGroup))
                {
                    GUILayout.BeginHorizontal();

                    if (contractGroup != null)
                    {
                        GUILayout.Label("", GUILayout.ExpandWidth(false), GUILayout.Width((indent+1) * 16));
                    }

                    if (GUILayout.Button(contractType.expandInDebug ? "-" : "+", GUILayout.Width(20), GUILayout.Height(20)))
                    {
                        contractType.expandInDebug = !contractType.expandInDebug;
                    }
                    GUILayout.Label(new GUIContent(contractType.ToString(), DebugInfo(contractType)),
                        contractType.enabled ? contractType.hasWarnings ? yellowLabel : GUI.skin.label : redLabel);
                    GUILayout.EndHorizontal();

                    if (contractType.expandInDebug)
                    {
                        // Output children
                        ParamGui(contractType, contractType.ParamFactories, indent + (contractGroup == null ? 1 : 2));
                        RequirementGui(contractType, contractType.Requirements, indent + (contractGroup == null ? 1 : 2));
                        BehaviourGui(contractType, contractType.BehaviourFactories, indent + (contractGroup == null ? 1 : 2));

                        GUILayout.Space(8);
                    }
                }
            }
        }
        protected bool CheckContractGroup(ConfiguredContract contract, ContractGroup group)
        {
            if (group != null)
            {
                // Check the group is enabled
                if (!ContractConfiguratorSettings.IsEnabled(group))
                {
                    throw new ContractRequirementException("Contract group " + group.name + " is not enabled.");
                }

                // Check the group active limit
                int activeContracts = ContractSystem.Instance.GetCurrentContracts<ConfiguredContract>().Count(c => c.contractType != null && group.BelongsToGroup(c.contractType));
                if (contract.ContractState == Contract.State.Offered || contract.ContractState == Contract.State.Active)
                {
                    activeContracts--;
                }

                if (group.maxSimultaneous != 0 && activeContracts >= group.maxSimultaneous)
                {
                    throw new ContractRequirementException("Too many active contracts in group (" + group.name + ").");
                }

                // Check the group completed limit
                if (group.maxCompletions != 0)
                {
                    int finishedContracts = ContractSystem.Instance.GetCompletedContracts<ConfiguredContract>().Count(c => c.contractType != null && group.BelongsToGroup(c.contractType));
                    if (finishedContracts + activeContracts >= maxCompletions)
                    {
                        throw new ContractRequirementException("Too many completed contracts in group (" + group.name + ").");
                    }
                }

                return CheckContractGroup(contract, group.parent);
            }

            return true;
        }
Exemplo n.º 6
0
        protected bool CheckContractGroup(ConfiguredContract contract, ContractGroup group)
        {
            if (group != null)
            {
                // Check the group active limit
                int activeContracts = ContractSystem.Instance.GetCurrentContracts <ConfiguredContract>().Count(c => c.contractType != null && group.BelongsToGroup(c.contractType));
                if (contract.ContractState == Contract.State.Offered || contract.ContractState == Contract.State.Active)
                {
                    activeContracts--;
                }

                if (group.maxSimultaneous != 0 && activeContracts >= group.maxSimultaneous)
                {
                    LoggingUtil.LogVerbose(this, "Didn't generate contract type " + name + ", too many active contracts in group.");
                    return(false);
                }

                // Check the group completed limit
                if (group.maxCompletions != 0)
                {
                    int finishedContracts = ContractSystem.Instance.GetCompletedContracts <ConfiguredContract>().Count(c => c.contractType != null && group.BelongsToGroup(c.contractType));
                    if (finishedContracts + activeContracts >= maxCompletions)
                    {
                        LoggingUtil.LogVerbose(this, "Didn't generate contract type " + name + ", too many completed contracts in group.");
                        return(false);
                    }
                }

                return(CheckContractGroup(contract, group.parent));
            }

            return(true);
        }