Exemple #1
0
        /// <summary>
        /// Disable this model group; recurse through children and disable them, delete all models, delete all model nodes
        /// </summary>
        internal void disableGroup()
        {
            int len = children.Count;

            for (int i = 0; i < len; i++)
            {
                children[i].disableGroup();
            }
            len = modelData.Count;
            for (int i = 0; i < len; i++)
            {
                modelData[i].disable();
            }
            len = modelNodes.Length;
            for (int i = 0; i < len; i++)
            {
                modelNodes[i].disableNode();
            }
            if (modelRoot != null)
            {
                GameObject.DestroyImmediate(modelRoot);
                modelRoot = null;
            }
            enabled             = false;
            currentEnabledModel = null;
        }
Exemple #2
0
 /// <summary>
 /// Enable this model group; enable on default model, links up models to nodes, upwards-recurse enable children groups
 /// </summary>
 internal void enableGroup()
 {
     if (enabled)
     {
         return;
     }
     enabled   = true;
     modelRoot = new GameObject("Root-" + name);
     if (parent == null)
     {
         MonoBehaviour.print("ERROR: Attempt to enable a group at runtime with no parent defined.  This should never happen.  Bad things are likely to occur soon.");
         //TODO -- yah.. this should be unpossible
     }
     else
     {
         ModelSwitchData model = modelData.Find(m => m.enabled == true);//for cases where data was loaded from persistence
         if (model == null)
         {
             model = enableDefaultModel();//otherwise just enable the default from the config
         }
         ModelNode node = parent.findNode(parentNode);
         if (node == null)
         {
             MonoBehaviour.print("ERROR: Node was null for name: " + parentNode + " for group: " + name);
         }
         modelRoot.transform.NestToParent(node.transform);
         setupNodesForModel(model);
         initializeModels();
     }
 }
Exemple #3
0
        /// <summary>
        /// Update the enabled/disabled status for all models, setting the default model to enabled==true<para/>
        /// Does not create the actual models, merely updates their status; models are created with the initializeModels() call
        /// </summary>
        private ModelSwitchData enableDefaultModel()
        {
            int             len  = modelData.Count;
            ModelSwitchData data = null;

            for (int i = 0; i < len; i++)
            {
                modelData[i].enabled = modelData[i].name == defaultModel;
                if (modelData[i].enabled)
                {
                    data = modelData[i];
                }
            }
            return(data);
        }
Exemple #4
0
 internal void enable(ModelSwitchData data)
 {
     if (!enabled)
     {
         MonoBehaviour.print("ERROR: Attempt to enable a model on a disabled model group.  Model will not be enabled.");
         return;
     }
     foreach (ModelSwitchData d in this.modelData)
     {
         if (d != data)
         {
             d.disable();
         }
     }
     currentEnabledModel = data;
     currentEnabledModel.enable();
     setupNodesForModel(currentEnabledModel);
 }
Exemple #5
0
 /// <summary>
 /// To be called on all model groups.<para/>
 /// If it is a root model group it will initialize itself and any children as needed.<para/>
 /// Build model root GO, initialize model for current selection, and initialize any children that need it.
 /// </summary>
 internal void initializeRoot()
 {
     if (!string.IsNullOrEmpty(parentGroup))
     {
         return;
     }                                //early return if not a root group
     currentEnabledModel = modelData.Find(m => m.enabled);
     if (currentEnabledModel == null) //initialize default
     {
         currentEnabledModel = modelData.Find(m => m.name == defaultModel);
         if (currentEnabledModel == null)
         {
             //if it is still null... that is a config error and needs to be corrected
             MonoBehaviour.print("ERROR: Could not locate default model for group: " + name + " model: " + defaultModel);
         }
         currentEnabledModel.enabled = true;
     }
     enabled   = true;
     modelRoot = new GameObject("Root-" + name);
     modelRoot.transform.NestToParent(owner.transform.FindRecursive("model"));
     setupNodesForModel(currentEnabledModel);
     initializeModels();
 }
Exemple #6
0
        /// <summary>
        /// enable/disable nodes depending on if they are enabled/disabled for the currently enabled model
        /// </summary>
        /// <param name="data"></param>
        private void setupNodesForModel(ModelSwitchData data)
        {
            //first check existing nodes and remove any that are not present in new model
            int len = modelNodes.Length;

            for (int i = 0; i < len; i++)
            {
                if (Array.Find(data.nodes, m => m.name == modelNodes[i].name) == null)//model data contains no def for node; disable it
                {
                    modelNodes[i].disableNode();
                }
            }
            //position all active nodes
            len = data.nodes.Length;
            ModelNode     node;
            ModelNodeData nodeData;

            for (int i = 0; i < len; i++)
            {
                nodeData = data.nodes[i];
                node     = Array.Find(modelNodes, m => m.name == nodeData.name);
                node.enableNode(nodeData, modelRoot);
            }
        }
Exemple #7
0
 internal void add(ModelSwitchData data)
 {
     this.modelData.Add(data); this.modelDataMap.Add(data.name, data);
 }
Exemple #8
0
 private void updateAttachNodesForModel(ModelSwitchData modelData)
 {
 }
Exemple #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;
        }
        /// <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;
        }
 private void updateAttachNodesForModel(ModelSwitchData modelData)
 {
 }
 /// <summary>
 /// enable/disable nodes depending on if they are enabled/disabled for the currently enabled model
 /// </summary>
 /// <param name="data"></param>
 private void setupNodesForModel(ModelSwitchData data)
 {
     //first check existing nodes and remove any that are not present in new model
     int len = modelNodes.Length;
     for (int i = 0; i < len; i++)
     {
         if (Array.Find(data.nodes, m => m.name == modelNodes[i].name) == null)//model data contains no def for node; disable it
         {
             modelNodes[i].disableNode();
         }
     }
     //position all active nodes
     len = data.nodes.Length;
     ModelNode node;
     ModelNodeData nodeData;
     for (int i = 0; i < len; i++)
     {
         nodeData = data.nodes[i];
         node = Array.Find(modelNodes, m => m.name == nodeData.name);
         node.enableNode(nodeData, modelRoot);
     }
 }
 /// <summary>
 /// To be called on all model groups.<para/>
 /// If it is a root model group it will initialize itself and any children as needed.<para/>
 /// Build model root GO, initialize model for current selection, and initialize any children that need it.
 /// </summary>
 internal void initializeRoot()
 {
     if (!string.IsNullOrEmpty(parentGroup)) { return; }//early return if not a root group
     currentEnabledModel = modelData.Find(m => m.enabled);
     if (currentEnabledModel == null)//initialize default
     {
         currentEnabledModel = modelData.Find(m => m.name == defaultModel);
         if (currentEnabledModel == null)
         {
             //if it is still null... that is a config error and needs to be corrected
             MonoBehaviour.print("ERROR: Could not locate default model for group: " + name + " model: " + defaultModel);
         }
         currentEnabledModel.enabled = true;
     }
     enabled = true;
     modelRoot = new GameObject("Root-" + name);
     modelRoot.transform.NestToParent(owner.transform.FindRecursive("model"));
     setupNodesForModel(currentEnabledModel);
     initializeModels();
 }
 internal void enable(ModelSwitchData data)
 {
     if (!enabled)
     {
         MonoBehaviour.print("ERROR: Attempt to enable a model on a disabled model group.  Model will not be enabled.");
         return;
     }
     foreach (ModelSwitchData d in this.modelData)
     {
         if (d != data)
         {
             d.disable();
         }
     }
     currentEnabledModel = data;
     currentEnabledModel.enable();
     setupNodesForModel(currentEnabledModel);
 }
 /// <summary>
 /// Disable this model group; recurse through children and disable them, delete all models, delete all model nodes
 /// </summary>
 internal void disableGroup()
 {
     int len = children.Count;
     for (int i = 0; i < len; i++)
     {
         children[i].disableGroup();
     }
     len = modelData.Count;
     for (int i = 0; i < len; i++)
     {
         modelData[i].disable();
     }
     len = modelNodes.Length;
     for (int i = 0; i < len; i++)
     {
         modelNodes[i].disableNode();
     }
     if (modelRoot != null)
     {
         GameObject.DestroyImmediate(modelRoot);
         modelRoot = null;
     }
     enabled = false;
     currentEnabledModel = null;
 }
 internal void add(ModelSwitchData data)
 {
     this.modelData.Add(data); this.modelDataMap.Add(data.name, data);
 }