Exemple #1
0
        private void InitializeShapes()
        {
            List <string> shapeNames = new List <string>();

            availableShapes.Clear();
            foreach (ProceduralAbstractShape compShape in GetComponents <ProceduralAbstractShape>())
            {
                if (!string.IsNullOrEmpty(compShape.techRequired) && ResearchAndDevelopment.GetTechnologyState(compShape.techRequired) != RDTech.State.Available)
                {
                    goto disableShape;
                }
                if (!string.IsNullOrEmpty(compShape.techObsolete) && ResearchAndDevelopment.GetTechnologyState(compShape.techObsolete) == RDTech.State.Available)
                {
                    goto disableShape;
                }

                availableShapes.Add(compShape.displayName, compShape);
                shapeNames.Add(compShape.displayName);

                if (string.IsNullOrEmpty(shapeName) ? (availableShapes.Count == 1) : compShape.displayName == shapeName)
                {
                    shape           = compShape;
                    oldShapeName    = shapeName = shape.displayName;
                    shape.isEnabled = shape.enabled = true;
                    continue;
                }

disableShape:
                compShape.isEnabled = compShape.enabled = false;
            }

            BaseField field = Fields["shapeName"];

            switch (availableShapes.Count)
            {
            case 0:
                throw new InvalidProgramException("No shapes available");

            case 1:
                field.guiActiveEditor = false;
                break;

            default:
                field.guiActiveEditor = true;
                UI_ChooseOption range = (UI_ChooseOption)field.uiControlEditor;
                range.options = shapeNames.ToArray();
                break;
            }

            if (string.IsNullOrEmpty(shapeName) || !availableShapes.ContainsKey(shapeName))
            {
                oldShapeName    = shapeName = shapeNames[0];
                shape           = availableShapes[shapeName];
                shape.isEnabled = shape.enabled = true;
            }
        }
        private void UpdateShape()
        {
            if (shapeName == oldShapeName)
            {
                return;
            }

            ProceduralAbstractShape newShape;

            if (!availableShapes.TryGetValue(shapeName, out newShape))
            {
                Debug.LogError("*ST* Unable to find compShape: " + shapeName);
                shapeName = oldShapeName;
                return;
            }

            if (shape != null)
            {
                shape.isEnabled = shape.enabled = false;

                // Pull off all the attachments, resetting them to standard offset, then reattach in the new shape.
                for (int i = 0; i < nodeAttachments.Count; ++i)
                {
                    TransformFollower follower = shape.RemoveAttachment(nodeAttachments[i], true);
                    nodeAttachments[i] = newShape.AddAttachment(follower, true);
                }
                if (parentAttachment != null)
                {
                    shape.RemoveAttachment(parentAttachment.data, true);
                    parentAttachment.data = newShape.AddAttachment(parentAttachment.follower, true);
                }
                foreach (PartAttachment childAttachment in childAttachments)
                {
                    shape.RemoveAttachment(childAttachment.data, true);
                    childAttachment.data = newShape.AddAttachment(childAttachment.follower, true);
                }
                foreach (ModelAttachment attach in attachments)
                {
                    TransformFollower follower = shape.RemoveAttachment(attach.data, true);
                    attach.data = newShape.AddAttachment(follower, true);
                }
            }

            shape           = newShape;
            shape.isEnabled = shape.enabled = true;

            oldShapeName = shapeName;

            if (HighLogic.LoadedSceneIsEditor)
            {
                GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
            }
        }
        private void UpdateShape()
        {
            if (shapeName == oldShapeName)
                return;

            ProceduralAbstractShape newShape;
            if (!availableShapes.TryGetValue(shapeName, out newShape))
            {
                Debug.LogError("*ST* Unable to find compShape: " + shapeName);
                shapeName = oldShapeName;
                return;
            }

            if (shape != null)
            {
                shape.isEnabled = shape.enabled = false;

                // Pull off all the attachments, resetting them to standard offset, then reattach in the new shape.
                for (int i = 0; i < nodeAttachments.Count; ++i)
                {
                    TransformFollower follower = shape.RemoveAttachment(nodeAttachments[i], true);
                    nodeAttachments[i] = newShape.AddAttachment(follower, true);
                }
                if (parentAttachment != null)
                {
                    shape.RemoveAttachment(parentAttachment.data, true);
                    parentAttachment.data = newShape.AddAttachment(parentAttachment.follower, true);
                }
                foreach (PartAttachment childAttachment in childAttachments)
                {
                    shape.RemoveAttachment(childAttachment.data, true);
                    childAttachment.data = newShape.AddAttachment(childAttachment.follower, true);
                }
                foreach (ModelAttachment attach in attachments)
                {
                    TransformFollower follower = shape.RemoveAttachment(attach.data, true);
                    attach.data = newShape.AddAttachment(follower, true);
                }
            }

            shape = newShape;
            shape.isEnabled = shape.enabled = true;

            oldShapeName = shapeName;

            if (HighLogic.LoadedSceneIsEditor)
                GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);

            UpdateTFInterops();
        }
        private void InitializeShapes()
        {
            List<string> shapeNames = new List<string>();
            availableShapes.Clear();
            foreach (ProceduralAbstractShape compShape in GetComponents<ProceduralAbstractShape>())
            {
                if (!string.IsNullOrEmpty(compShape.techRequired) && ResearchAndDevelopment.GetTechnologyState(compShape.techRequired) != RDTech.State.Available)
                    goto disableShape;
                if (!string.IsNullOrEmpty(compShape.techObsolete) && ResearchAndDevelopment.GetTechnologyState(compShape.techObsolete) == RDTech.State.Available)
                    goto disableShape;

                availableShapes.Add(compShape.displayName, compShape);
                shapeNames.Add(compShape.displayName);

                if (string.IsNullOrEmpty(shapeName) ? (availableShapes.Count == 1) : compShape.displayName == shapeName)
                {
                    shape = compShape;
                    oldShapeName = shapeName = shape.displayName;
                    shape.isEnabled = shape.enabled = true;
                    continue;
                }

            disableShape:
                compShape.isEnabled = compShape.enabled = false;
            }

            BaseField field = Fields["shapeName"];
            switch (availableShapes.Count)
            {
                case 0:
                    throw new InvalidProgramException("No shapes available");
                case 1:
                    field.guiActiveEditor = false;
                    break;
                default:
                    field.guiActiveEditor = true;
                    UI_ChooseOption range = (UI_ChooseOption)field.uiControlEditor;
                    range.options = shapeNames.ToArray();
                    break;
            }

            if (string.IsNullOrEmpty(shapeName) || !availableShapes.ContainsKey(shapeName))
            {
                oldShapeName = shapeName = shapeNames[0];
                shape = availableShapes[shapeName];
                shape.isEnabled = shape.enabled = true;
            }
        }