Example #1
0
        public void MergeFrom(PartGroup source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (!object.ReferenceEquals(this, source))
            {
                this.Parts.AddRange(source.Parts);
                source.Parts.Clear();
            }
        }
Example #2
0
        public void Add(PartGroup group, Color color, bool recursive)
        {
            if (!tracking)
            {
                throw new HighlightTrackerException("Highlight tracking must be started before adding part groups to track.");
            }

            if (group == null)
            {
                throw new ArgumentNullException("group");
            }

            foreach (Part part in group.Parts)
            {
                this.Add(part, color, recursive);
            }
        }
Example #3
0
        public void MoveTo(Part part, PartGroup destination)
        {
            if (part == null)
            {
                throw new ArgumentNullException("part");
            }

            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }

            if (!object.ReferenceEquals(this, destination))
            {
                this.Parts.Remove(part);
                destination.Parts.Add(part);
            }
        }
Example #4
0
        public void MoveTo(Part part, PartGroup destination)
        {
            if(part == null)
                throw new ArgumentNullException("part");

            if(destination == null)
                throw new ArgumentNullException("destination");

            if(!object.ReferenceEquals(this, destination))
            {
                this.Parts.Remove(part);
                destination.Parts.Add(part);
            }
        }
Example #5
0
        public void MergeFrom(PartGroup source)
        {
            if(source == null)
                throw new ArgumentNullException("source");

            if(!object.ReferenceEquals(this, source))
            {
                this.Parts.AddRange(source.Parts);
                source.Parts.Clear();
            }
        }
Example #6
0
        public override void OnRender()
        {
            try
            {
                GUILayout.BeginVertical();

                this.scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false);

                this.highlight.BeginTracking();

                if (this.mouseOver)
                {
                    this.highlight.Add(this.part, Configuration.HighlightColorSymmetryEditor, Configuration.HighlightColorSymmetryEditor);
                }

                for (int index = 0; index < this.symmetryGroups.Count; index++)
                {
                    PartGroup group = this.symmetryGroups[index];

                    GUIControls.BeginMouseOverVertical(GUIControls.PanelStyle);

                    GUILayout.BeginHorizontal();

                    GUILayout.Label(new GUIContent(string.Format(CultureInfo.CurrentCulture, Localized.GroupLabelText, index + 1)));

                    // Don't allow group removal if there is only one group.
                    GUI.enabled = (this.symmetryGroups.Count > 1);

                    if (GUILayout.Button(SymmetryEditorWindow.RemoveGroupButtonText))
                    {
                        // If there's a group above, use it. If not, then use the one below.
                        PartGroup destinationGroup = (index > 0) ? this.symmetryGroups[index - 1] : this.symmetryGroups[index + 1];

                        destinationGroup.MergeFrom(group);

                        this.symmetryGroups.Remove(group);

                        break;
                    }

                    GUILayout.EndHorizontal();

                    GUI.enabled = true;

                    bool mouseOverPart = false;

                    foreach (Part groupPart in group.Parts)
                    {
                        GUIControls.BeginMouseOverHorizontal();

                        GUILayout.Label(new GUIContent(groupPart.partInfo.title));

                        GUI.enabled = index < this.symmetryGroups.Count - 1;

                        if (GUILayout.Button(SymmetryEditorWindow.MoveDownButtonText, Configuration.PartActionButtonWidth))
                        {
                            PartGroup nextGroup = this.symmetryGroups[index + 1];

                            group.MoveTo(groupPart, nextGroup);

                            break;
                        }

                        GUI.enabled = index > 0;

                        if (GUILayout.Button(SymmetryEditorWindow.MoveUpButtonText, Configuration.PartActionButtonWidth))
                        {
                            PartGroup previousGroup = this.symmetryGroups[index - 1];

                            group.MoveTo(groupPart, previousGroup);

                            break;
                        }

                        GUI.enabled = true;

                        bool mouseOverPartArea = false;
                        GUIControls.EndMouseOverVertical(out mouseOverPartArea);

                        if (mouseOverPartArea)
                        {
                            // First add the group with the child part color, recursively.
                            this.highlight.Add(group, Configuration.HighlightColorEditableSymmetryChildParts, true);
                            // Next add the group with the counterparts highlighted, non-recursively.
                            this.highlight.Add(group, Configuration.HighlightColorCounterparts, false);
                            // Last add the specific part, non-recursively.
                            this.highlight.Add(groupPart, Configuration.HighlightColorSinglePart, false);

                            mouseOverPart = true;
                        }
                    }

                    bool groupMouseOver = false;
                    GUIControls.EndMouseOverVertical(out groupMouseOver);

                    if (!mouseOverPart && groupMouseOver)
                    {
                        this.highlight.Add(group, Configuration.HighlightColorEditableSymmetryCounterparts, true);
                    }
                }

                // Enable the Add Group button only if there is enough symmetrical parts to fill it.
                GUI.enabled = (this.symmetryGroups.Count < (this.part.symmetryCounterparts.Count + 1));

                if (GUILayout.Button(SymmetryEditorWindow.AddGroupButtonText))
                {
                    this.symmetryGroups.Add(new PartGroup());
                }

                GUI.enabled = true;

                GUILayout.EndScrollView();

                GUILayout.Space(4);

                GUILayout.BeginHorizontal();

                #region OK Button

                if (GUILayout.Button(Localized.OK))
                {
                    int symmetricGroupsCreated = 0;
                    int partsProcessed         = 0;

                    foreach (PartGroup group in this.symmetryGroups)
                    {
                        if (group.Parts.Count > 0)
                        {
                            partsProcessed += group.Count;

                            Part symmetricRoot = group.Extract(0);

                            PartWizard.CreateSymmetry(symmetricRoot, group.Parts);

                            symmetricGroupsCreated++;

#if DEBUG
                            Log.WriteSymmetryReport(symmetricRoot);
#endif
                        }
                    }

                    Log.Write("Modified symmetry for {0}, creating {1} symmetric group(s) from {2} parts.", part.name, symmetricGroupsCreated, partsProcessed);

                    this.Hide();
                }

                #endregion

                #region Cancel Button

                if (GUILayout.Button(Localized.Cancel))
                {
                    this.Hide();
                }

                #endregion

                GUILayout.EndHorizontal();

                GUILayout.EndVertical();
            }
            catch (Exception)
            {
                highlight.CancelTracking();

                throw;
            }
            finally
            {
                GUI.DragWindow();

                if (this.Visible && this.mouseOver)
                {
                    this.highlight.EndTracking();
                }
                else
                {
                    this.highlight.CancelTracking();
                }
            }
        }
Example #7
0
 public void Add(PartGroup group, Color color)
 {
     this.Add(group, color, false);
 }