コード例 #1
0
        /// <summary>
        /// Update the currently avaialble selection options and enabled/disabled status of the group and model selection widgets
        /// </summary>
        private void updateGui()
        {
            ModelSwitchGroup[] availableGroups = modelGroups.Where(m => m.isAvailable()).ToArray();
            int len = availableGroups.Length;

            string[] groupNames = new string[len];
            for (int i = 0; i < len; i++)
            {
                groupNames[i] = availableGroups[i].name;
            }
            ModelSwitchGroup group = Array.Find(modelGroups, m => m.name == guiGroupSelection);

            guiModelSelection = group.enabledModel.name;
            if (groupNames.Length > 1)
            {
                this.updateUIChooseOptionControl("guiGroupSelection", groupNames, groupNames, true, guiGroupSelection);
            }
            string[] modelNames = group.getModelNames();
            if (modelNames.Length > 1)
            {
                this.updateUIChooseOptionControl("guiModelSelection", modelNames, modelNames, true, guiModelSelection);
            }
            Fields["guiGroupSelection"].guiActiveEditor = groupNames.Length > 1;
            Fields["guiModelSelection"].guiActiveEditor = modelNames.Length > 1;
            Fields["guiModelSelection"].guiName         = groupNames.Length > 1 ? "GroupModel" : "Variant";
        }
コード例 #2
0
 /// <summary>
 /// initialize the default values for model-data; this occurs prior to load()
 /// </summary>
 internal void preInitialize()
 {
     if (!string.IsNullOrEmpty(parentGroup))
     {
         parent = owner.findGroup(parentGroup);
         if (parent == null)
         {
             MonoBehaviour.print("ERROR: Specified parent was null!");
         }
         parent.addChild(this);
     }
 }
コード例 #3
0
        public void onModelUpdated(BaseField field, object obj)
        {
            ModelSwitchGroup group = Array.Find(modelGroups, m => m.name == guiGroupSelection);

            group.enable(guiModelSelection);
            updateGui();
            guiModelSelection = group.enabledModel.name;
            updateContainerVolume();
            updateMassAndCost();
            updateDragCube();
            updateAttachNodes(true);
            updatePersistentData();
        }
コード例 #4
0
 public ModelSwitchData(ConfigNode node, Part owner, ModelSwitchGroup group)
 {
     name            = node.GetStringValue("name");
     modelName       = node.GetStringValue("modelName", name);
     groupName       = node.GetStringValue("group", groupName);
     containerIndex  = node.GetIntValue("containerIndex", 0);
     localPosition   = node.GetVector3("localPosition", Vector3.zero);
     localRotation   = node.GetVector3("localRotation", Vector3.zero);
     scale           = node.GetFloatValue("scale", scale);
     nodes           = ModelNodeData.load(node.GetStringValues("node"));
     suppressNode    = nodes.Length > 0;
     modelDefinition = SSTUModelData.getModelDefinition(modelName);
     if (modelDefinition == null)
     {
         throw new NullReferenceException("Could not locate model data for name: " + modelName + " :: " + name);
     }
     this.part  = owner;
     this.group = group;
     this.group.add(this);
 }
コード例 #5
0
 public void addChild(ModelSwitchGroup group)
 {
     children.Add(group);
 }
コード例 #6
0
 public ModelNode(string name, ModelSwitchGroup parent)
 {
     this.name   = name;
     this.parent = parent;
 }
コード例 #7
0
 private void addChild(ModelSwitchGroup group)
 {
     children.Add(group);
     nodeMap[group.parentNode].addChild(group);
 }
コード例 #8
0
        /// <summary>
        /// Initialize this module - load config data, restore persistent data, setup gui fields
        /// </summary>
        private void initialize()
        {
            ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData);
            if (node.HasValue("controlledNode"))
            {
                controlledNodes = node.GetStringValues("controlledNode");
            }
            //load model groups, initializing a default 'Main' group if none are defined
            ConfigNode[] groupNodes = node.GetNodes("GROUP");
            int len = groupNodes.Length;
            if (len == 0)//create default group
            {
                len = 1;
                groupNodes = new ConfigNode[1];
                groupNodes[0] = new ConfigNode("GROUP");
                groupNodes[0].AddValue("name", "Main");
            }
            modelGroups = new ModelSwitchGroup[len];
            ModelSwitchGroup group;
            for (int i = 0; i < len; i++)
            {
                group = new ModelSwitchGroup(groupNodes[i], this);
                modelGroups[i] = group;
                groupsByName.Add(group.name, group);
            }

            //load model definitions, initializing them with the model group
            ConfigNode[] modelNodes = node.GetNodes("MODEL");
            len = modelNodes.Length;
            modelData = new ModelSwitchData[len];
            string groupName;
            for (int i = 0; i < len; i++)
            {
                groupName = modelNodes[i].GetStringValue("group", "Main");
                modelData[i] = new ModelSwitchData(modelNodes[i], part, groupsByName[groupName]);
            }

            //pre-initialize model groups; this sets up their parent/children relations and loads default enabled/disabled status into the model definitions
            len = modelGroups.Length;
            for (int i = 0; i < len; i++)
            {
                modelGroups[i].preInitialize();
            }

            //load persistent data for groups; this will restore the settings for enabled/disabled for each model definition
            string data = persistentConfigData;
            if (!string.IsNullOrEmpty(data))
            {
                string[] split = data.Split(':');
                len = split.Length;
                for (int i = 0; i < len; i++)
                {
                    modelGroups[i].load(split[i]);
                }
            }

            //initialize root model groups; they will recursively enable children if they should be enabled
            len = modelGroups.Length;
            for (int i = 0; i < len; i++)
            {
                modelGroups[i].initializeRoot();
            }

            //update persistent data to the currently setup state; this updates the persistent data for a freshly-initialized part
            updatePersistentData();

            //mass, attach node, and drag cube updating
            updateMassAndCost();
            updateAttachNodes(false);
            updateDragCube();

            //initialize gui selection field to the first available group
            guiGroupSelection = Array.Find(modelGroups, m => m.isAvailable()).name;

            //update ui option arrays for the given group and its current model
            updateGui();

            //setup ui callbacks for group/model changed
            Fields["guiGroupSelection"].uiControlEditor.onFieldChanged = onGroupUpdated;
            Fields["guiModelSelection"].uiControlEditor.onFieldChanged = onModelUpdated;
        }
コード例 #9
0
        /// <summary>
        /// Initialize this module - load config data, restore persistent data, setup gui fields
        /// </summary>
        private void initialize()
        {
            ConfigNode node = SSTUStockInterop.getPartModuleConfig(this);

            if (node.HasValue("controlledNode"))
            {
                controlledNodes = node.GetStringValues("controlledNode");
            }
            //load model groups, initializing a default 'Main' group if none are defined
            ConfigNode[] groupNodes = node.GetNodes("GROUP");
            int          len        = groupNodes.Length;

            if (len == 0)//create default group
            {
                len           = 1;
                groupNodes    = new ConfigNode[1];
                groupNodes[0] = new ConfigNode("GROUP");
                groupNodes[0].AddValue("name", "Main");
            }
            modelGroups = new ModelSwitchGroup[len];
            ModelSwitchGroup group;

            for (int i = 0; i < len; i++)
            {
                group          = new ModelSwitchGroup(groupNodes[i], this);
                modelGroups[i] = group;
                groupsByName.Add(group.name, group);
            }

            //load model definitions, initializing them with the model group
            ConfigNode[] modelNodes = node.GetNodes("MODEL");
            len       = modelNodes.Length;
            modelData = new ModelSwitchData[len];
            string groupName;

            for (int i = 0; i < len; i++)
            {
                groupName    = modelNodes[i].GetStringValue("group", "Main");
                modelData[i] = new ModelSwitchData(modelNodes[i], part, groupsByName[groupName]);
            }

            //pre-initialize model groups; this sets up their parent/children relations and loads default enabled/disabled status into the model definitions
            len = modelGroups.Length;
            for (int i = 0; i < len; i++)
            {
                modelGroups[i].preInitialize();
            }

            //load persistent data for groups; this will restore the settings for enabled/disabled for each model definition
            string data = persistentConfigData;

            if (!string.IsNullOrEmpty(data))
            {
                string[] split = data.Split(':');
                len = split.Length;
                for (int i = 0; i < len; i++)
                {
                    modelGroups[i].load(split[i]);
                }
            }

            //initialize root model groups; they will recursively enable children if they should be enabled
            len = modelGroups.Length;
            for (int i = 0; i < len; i++)
            {
                modelGroups[i].initializeRoot();
            }

            //update persistent data to the currently setup state; this updates the persistent data for a freshly-initialized part
            updatePersistentData();

            //mass, attach node, and drag cube updating
            updateMassAndCost();
            updateAttachNodes(false);
            updateDragCube();

            //initialize gui selection field to the first available group
            guiGroupSelection = Array.Find(modelGroups, m => m.isAvailable()).name;

            //update ui option arrays for the given group and its current model
            updateGui();

            //setup ui callbacks for group/model changed
            Fields["guiGroupSelection"].uiControlEditor.onFieldChanged = onGroupUpdated;
            Fields["guiModelSelection"].uiControlEditor.onFieldChanged = onModelUpdated;
        }
コード例 #10
0
 private void addChild(ModelSwitchGroup group)
 {
     children.Add(group);
     nodeMap[group.parentNode].addChild(group);
 }
コード例 #11
0
 /// <summary>
 /// initialize the default values for model-data; this occurs prior to load()
 /// </summary>
 internal void preInitialize()
 {
     if (!string.IsNullOrEmpty(parentGroup))
     {
         parent = owner.findGroup(parentGroup);
         if (parent == null)
         {
             MonoBehaviour.print("ERROR: Specified parent was null!");
         }
         parent.addChild(this);
     }
 }
コード例 #12
0
 public void addChild(ModelSwitchGroup group)
 {
     children.Add(group);
 }
コード例 #13
0
 public ModelNode(string name, ModelSwitchGroup parent)
 {
     this.name = name;
     this.parent = parent;
 }
コード例 #14
0
 public ModelSwitchData(ConfigNode node, Part owner, ModelSwitchGroup group)
 {
     name = node.GetStringValue("name");
     modelName = node.GetStringValue("modelName", name);
     groupName = node.GetStringValue("group", groupName);
     containerIndex = node.GetIntValue("containerIndex", 0);
     moduleIDs = node.GetIntValues("managedModuleID", new int[] { });
     localPosition = node.GetVector3("localPosition", Vector3.zero);
     localRotation = node.GetVector3("localRotation", Vector3.zero);
     scale = node.GetFloatValue("scale", scale);
     nodes = ModelNodeData.load(node.GetStringValues("node"));
     suppressNode = nodes.Length > 0;
     modelDefinition = SSTUModelData.getModelDefinition(modelName);
     if (modelDefinition == null) { throw new NullReferenceException("Could not locate model data for name: " + modelName + " :: " + name); }
     this.part = owner;
     this.group = group;
     this.group.add(this);
 }