Example #1
0
        public static void remove_servo(MuMechToggle servo)
        {
            if (!gui)
            {
                return;
            }
            if (gui.servo_groups == null)
            {
                return;
            }
            int num = 0;

            foreach (var group in gui.servo_groups)
            {
                if (group.name == servo.groupName)
                {
                    group.servos.Remove(servo);

                    if (useEC)
                    {
                        updateGroupECRequirement(group);
                    }
                }
                num += group.servos.Count;
            }
            gui.enabled = num > 0;
        }
Example #2
0
 static void move_servo(Group from, Group to, MuMechToggle servo)
 {
     to.servos.Add(servo);
     from.servos.Remove(servo);
     servo.groupName  = to.name;
     servo.forwardKey = to.forwardKey;
     servo.reverseKey = to.reverseKey;
 }
Example #3
0
        public static void add_servo(MuMechToggle servo)
        {
            if (!gui)
            {
                return;
            }
            gui.enabled = true;
            if (servo.part.customPartData != null &&
                servo.part.customPartData != "")
            {
                servo.ParseCData();
            }
            if (gui.servo_groups == null)
            {
                gui.servo_groups = new List <Group>();
            }
            Group group = null;

            if (servo.groupName != null && servo.groupName != "")
            {
                for (int i = 0; i < gui.servo_groups.Count; i++)
                {
                    if (servo.groupName == gui.servo_groups[i].name)
                    {
                        group = gui.servo_groups[i];
                        break;
                    }
                }
                if (group == null)
                {
                    var newGroup = new Group(servo);
                    if (useEC)
                    {
                        updateGroupECRequirement(newGroup);
                    }
                    gui.servo_groups.Add(newGroup);
                    return;
                }
            }
            if (group == null)
            {
                if (gui.servo_groups.Count < 1)
                {
                    gui.servo_groups.Add(new Group());
                }
                group = gui.servo_groups[gui.servo_groups.Count - 1];
            }

            group.servos.Add(servo);
            servo.groupName  = group.name;
            servo.forwardKey = group.forwardKey;
            servo.reverseKey = group.reverseKey;

            if (useEC)
            {
                updateGroupECRequirement(group);
            }
        }
Example #4
0
 public Group(MuMechToggle servo)
 {
     this.name  = servo.groupName;
     forwardKey = servo.forwardKey;
     reverseKey = servo.reverseKey;
     speed      = servo.customSpeed.ToString("g");
     servos     = new List <MuMechToggle>();
     showGUI    = servo.showGUI;
     servos.Add(servo);
 }
Example #5
0
        public static void add_servo(MuMechToggle servo)
        {
            if (!gui)
                return;
            gui.enabled = true;
            if (servo.part.customPartData != null
                && servo.part.customPartData != "")
            {
                servo.ParseCData();
            }
            if (gui.servo_groups == null)
                gui.servo_groups = new List<Group>();
            Group group = null;
            if (servo.groupName != null && servo.groupName != "")
            {
                for (int i = 0; i < gui.servo_groups.Count; i++)
                {
                    if (servo.groupName == gui.servo_groups[i].name)
                    {
                        group = gui.servo_groups[i];
                        break;
                    }
                }
                if (group == null)
                {
                    var newGroup = new Group(servo);
                    if (useEC)
                    {
                        updateGroupECRequirement(newGroup);
                    }
                    gui.servo_groups.Add(newGroup);
                    return;
                }
            }
            if (group == null)
            {
                if (gui.servo_groups.Count < 1)
                {
                    gui.servo_groups.Add(new Group());
                }
                group = gui.servo_groups[gui.servo_groups.Count - 1];
            }

            group.servos.Add(servo);
            servo.groupName = group.name;
            servo.forwardKey = group.forwardKey;
            servo.reverseKey = group.reverseKey;

            if (useEC)
            {
                updateGroupECRequirement(group);
            }
        }
Example #6
0
        static void move_servo(Group from, Group to, MuMechToggle servo)
        {
            to.servos.Add(servo);
            from.servos.Remove(servo);
            servo.groupName  = to.name;
            servo.forwardKey = to.forwardKey;
            servo.reverseKey = to.reverseKey;

            if (useEC)
            {
                updateGroupECRequirement(from);
                updateGroupECRequirement(to);
            }
        }
Example #7
0
        public Servo(MuMechToggle rawServo)
        {
            this.rawServo = rawServo;
            controlGroup  = new ControlGroup(rawServo);
            input         = new ServoInput(rawServo);

            if (rawServo.rotateJoint)
            {
                mechanism = new RotatingMechanism(rawServo);
            }
            else
            {
                mechanism = new TranslateMechanism(rawServo);
            }
            preset = new ServoPreset(rawServo, this);
        }
Example #8
0
        internal static void WindowEnd()
        {
            if (Disabled)
            {
                return;                 //If the Drag and Drop is Disabled then just go back
            }
            // Draw the Yellow insertion strip
            Rect InsertRect;

            if (draggingItem && ServoDragging != null && ServoOver != null)
            {
                //What is the insert position of the dragged servo
                Int32 InsertIndex = ServoOver.ID + (ServoOverUpper?0:1);
                if ((ServoDragging.groupID != ServoOver.groupID) ||
                    (ServoDragging.ID != InsertIndex && (ServoDragging.ID + 1) != InsertIndex))
                {
                    //Only in here if the drop will cause the list to change
                    Single rectResMoveY;
                    //is it dropping in the list or at the end
                    if (InsertIndex < lstServos.Where(x => x.groupID == ServoOver.groupID).ToList().Count)
                    {
                        rectResMoveY = lstServos.Where(x => x.groupID == ServoOver.groupID).ToList()[InsertIndex].ServoRect.y;
                    }
                    else
                    {
                        rectResMoveY = lstServos.Where(x => x.groupID == ServoOver.groupID).ToList().Last().ServoRect.y + lstServos.Where(x => x.groupID == ServoOver.groupID).ToList().Last().ServoRect.height;
                    }

                    //calculate and draw the graphic
                    InsertRect = new Rect(12,
                                          rectResMoveY + 26 - ScrollPosition.y,
                                          WindowRect.width - 34, 9);
                    GUI.Box(InsertRect, "", styleDragInsert);
                }
            }
            else if (draggingItem && GroupDragging != null && GroupOver != null)
            {
                //What is the insert position of the dragged group
                Int32 InsertIndex = GroupOver.ID + (GroupOverUpper ? 0 : 1);
                if (GroupDragging.ID != InsertIndex && (GroupDragging.ID + 1) != InsertIndex)
                {
                    //Only in here if the drop will cause the list to change
                    Single rectResMoveY;
                    //is it dropping in the list or at the end
                    if (InsertIndex < lstGroups.Count)
                    {
                        rectResMoveY = lstGroups[InsertIndex].GroupRect.y;
                    }
                    else
                    {
                        rectResMoveY = lstGroups.Last().GroupRect.y + lstGroups.Last().GroupRect.height;
                    }

                    //calculate and draw the graphic
                    InsertRect = new Rect(12,
                                          rectResMoveY + 26 - ScrollPosition.y,
                                          WindowRect.width - 34, 9);
                    GUI.Box(InsertRect, "", styleDragInsert);
                }
            }
            else if (draggingItem && ServoDragging != null && GroupOver != null && !lstServos.Any(x => x.groupID == GroupOver.ID))
            {
                //This is the case for an empty Group
                Single rectResMoveY;
                //is it dropping in the list or at the end
                rectResMoveY = GroupOver.GroupRect.y + GroupOver.GroupRect.height;

                //calculate and draw the graphic
                InsertRect = new Rect(12,
                                      rectResMoveY + 26 - ScrollPosition.y,
                                      WindowRect.width - 34, 9);
                GUI.Box(InsertRect, "", styleDragInsert);
            }


            //What is the mouse over
            if (MousePosition.y > 32 && MousePosition.y < WindowRect.height - 8)
            {
                //inside the scrollview
                //check what group
                GroupOver     = lstGroups.FirstOrDefault(x => x.GroupRect.Contains(MousePosition + ScrollPosition - new Vector2(8, 29)));
                GroupIconOver = lstGroups.FirstOrDefault(x => x.IconRect.Contains(MousePosition + ScrollPosition - new Vector2(8, 29)));
                if (GroupOver != null)
                {
                    GroupOverUpper = ((MousePosition + ScrollPosition - new Vector2(8, 29)).y - GroupOver.GroupRect.y) < GroupOver.GroupRect.height / 2;
                }

                //or servo
                ServoOver     = lstServos.FirstOrDefault(x => x.ServoRect.Contains(MousePosition + ScrollPosition - new Vector2(8, 29)));
                ServoIconOver = lstServos.FirstOrDefault(x => x.IconRect.Contains(MousePosition + ScrollPosition - new Vector2(8, 29)));
                if (ServoOver != null)
                {
                    ServoOverUpper = ((MousePosition + ScrollPosition - new Vector2(8, 29)).y - ServoOver.ServoRect.y) < ServoOver.ServoRect.height / 2;
                }
            }
            else
            {
                //Otherwise empty the variables
                GroupOver = null; ServoOver = null; GroupIconOver = null; ServoIconOver = null;
            }

            //MouseDown - left mouse button
            if (Event.current.type == EventType.mouseDown &&
                Event.current.button == 0)
            {
                if (GroupIconOver != null)
                {
                    //If we click on the drag icon then start the drag
                    GroupDragging = GroupOver;
                    draggingItem  = true;
                }
                else if (ServoIconOver != null)
                {
                    //If we click on the drag icon then start the drag
                    ServoDragging = ServoOver;
                    draggingItem  = true;
                }
            }

            //did we release the mouse
            if (Event.current.type == EventType.mouseUp &&
                Event.current.button == 0)
            {
                if (GroupDragging != null && GroupOver != null)
                {
                    //were we dragging a group
                    if (GroupDragging.ID != (GroupOver.ID + (GroupOverUpper ? 0 : 1)))
                    {
                        //And it will cause a reorder
                        Debug.Log(String.Format("Reordering:{0}-{1}", GroupDragging.ID, (GroupOver.ID - (GroupOverUpper ? 1 : 0))));

                        //where are we inserting the dragged item
                        Int32 InsertAt = (GroupOver.ID - (GroupOverUpper ? 1 : 0));
                        if (GroupOver.ID < GroupDragging.ID)
                        {
                            InsertAt += 1;
                        }

                        //move em around
                        MuMechGUI.Group g = MuMechGUI.gui.servo_groups[GroupDragging.ID];
                        MuMechGUI.gui.servo_groups.RemoveAt(GroupDragging.ID);
                        MuMechGUI.gui.servo_groups.Insert(InsertAt, g);
                    }
                }
                else if (ServoDragging != null && ServoOver != null)
                {
                    //were we dragging a servo
                    //where are we inserting the dragged item
                    Int32 InsertAt = (ServoOver.ID + (ServoOverUpper ? 0 : 1));
                    if (ServoOver.groupID == ServoDragging.groupID && ServoDragging.ID < ServoOver.ID)
                    {
                        InsertAt -= 1;
                    }

                    Debug.Log(String.Format("Reordering:({0}-{1})->({2}-{3})", ServoDragging.groupID, ServoDragging.ID, ServoOver.groupID, InsertAt));

                    //move em around
                    MuMechToggle s = MuMechGUI.gui.servo_groups[ServoDragging.groupID].servos[ServoDragging.ID];
                    MuMechGUI.gui.servo_groups[ServoDragging.groupID].servos.RemoveAt(ServoDragging.ID);
                    MuMechGUI.gui.servo_groups[ServoOver.groupID].servos.Insert(InsertAt, s);
                }
                else if (ServoDragging != null && GroupOver != null && !lstServos.Any(x => x.groupID == GroupOver.ID))
                {
                    //dragging a servo to an empty group
                    Int32        InsertAt = 0;
                    MuMechToggle s        = MuMechGUI.gui.servo_groups[ServoDragging.groupID].servos[ServoDragging.ID];
                    MuMechGUI.gui.servo_groups[ServoDragging.groupID].servos.RemoveAt(ServoDragging.ID);
                    MuMechGUI.gui.servo_groups[GroupOver.ID].servos.Insert(InsertAt, s);
                }

                //reset the dragging stuff
                draggingItem  = false;
                GroupDragging = null;
                ServoDragging = null;
            }

            //If we are dragging and in the bottom or top area then scrtoll the list
            if (draggingItem && rectScrollBottom.Contains(MousePosition))
            {
                MuMechGUI.SetEditorScrollYPosition(ScrollPosition.y + (Time.deltaTime * 40));
            }
            if (draggingItem && rectScrollTop.Contains(MousePosition))
            {
                MuMechGUI.SetEditorScrollYPosition(ScrollPosition.y - (Time.deltaTime * 40));
            }
        }
Example #9
0
 protected MechanismBase(MuMechToggle rawServo)
 {
     this.rawServo = rawServo;
 }
Example #10
0
 public RotatingMechanism(MuMechToggle rawServo)
     : base(rawServo)
 {
 }
Example #11
0
        public static void remove_servo(MuMechToggle servo)
        {
            if (!gui)
                return;
            if (gui.servo_groups == null)
                return;
            int num = 0;
            foreach (var group in gui.servo_groups)
            {
                if (group.name == servo.groupName)
                {
                    group.servos.Remove(servo);

                    if (useEC)
                    {
                        updateGroupECRequirement(group);
                    }
                }
                num += group.servos.Count;
            }
            gui.enabled = num > 0;
        }
Example #12
0
 public ControlGroup(MuMechToggle rawServo)
 {
     this.rawServo = rawServo;
 }
Example #13
0
        void GroupEditorWindow(int windowID)
        {
            var expand = GUILayout.ExpandWidth(true);
            var width20 = GUILayout.Width(20);
            var width40 = GUILayout.Width(40);
            var width60 = GUILayout.Width(60);
            var maxHeight = GUILayout.MaxHeight(Screen.height / 2);

            Vector2 mousePos = Input.mousePosition;
            mousePos.y = Screen.height - mousePos.y;

            editorScroll = GUILayout.BeginScrollView(editorScroll, false,
                                                     false, maxHeight);

            //Kick off the window code
            GUIDragAndDrop.WindowBegin(groupEditorWinPos, editorScroll);

            GUILayout.BeginVertical();
            if (ToolbarManager.ToolbarAvailable)
            {
                if (GUILayout.Button("Close"))
                {
                    saveConfigXML();
                    groupEditorEnabled = false;
                }
            }
            GUILayout.BeginHorizontal();

            //if we are showing the group handles then Pad the text so it still aligns with the text box
            if (GUIDragAndDrop.ShowGroupHandles)
                GUIDragAndDrop.PadText();
            GUILayout.Label("Group Name", expand);
            GUILayout.Label("Keys", width40);

            if (servo_groups.Count > 1)
            {
                GUILayout.Space(60);
            }
            GUILayout.EndHorizontal();

            for (int i = 0; i < servo_groups.Count; i++)
            {
                Group grp = servo_groups[i];

                GUILayout.BeginHorizontal();

                //Call the Add Group Handle code
                GUIDragAndDrop.DrawGroupHandle(grp.name, i);

                string tmp = GUILayout.TextField(grp.name, expand);

                if (grp.name != tmp)
                {
                    grp.name = tmp;
                }

                tmp = GUILayout.TextField(grp.forwardKey, width20);
                if (grp.forwardKey != tmp)
                {
                    grp.forwardKey = tmp;
                }
                tmp = GUILayout.TextField(grp.reverseKey, width20);
                if (grp.reverseKey != tmp)
                {
                    grp.reverseKey = tmp;
                }

                if (i > 0)
                {
                    //set a smaller height to align with text boxes
                    if (GUILayout.Button("Remove", width60, GUILayout.Height(EditorButtonHeights)))
                    {
                        foreach (var servo in grp.servos)
                        {
                            move_servo(grp, servo_groups[i - 1], servo);
                        }
                        servo_groups.RemoveAt(i);
                        resetWin = true;
                        return;
                    }
                }
                else
                {
                    if (servo_groups.Count > 1)
                    {
                        GUILayout.Space(60);
                    }
                }
                GUILayout.EndHorizontal();

                if (useEC)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(20);
                    GUILayout.Label(string.Format("Estimated Power Draw: {0:#0.##} Ec/s", grp.groupTotalECRequirement), expand);
                    GUILayout.EndHorizontal();
                }

                GUILayout.BeginHorizontal();

                GUILayout.Space(20);

                GUILayout.BeginVertical();

                GUILayout.BeginHorizontal();

                //Pad the text so it still aligns with the text box
                GUIDragAndDrop.PadText();
                GUILayout.Label("Servo Name", expand);
                if (update14to15)
                    GUILayout.Label("Rotation", expand);

                if (servo_groups.Count > 1)
                {
                    GUILayout.Label("Group", width40);
                }
                GUILayout.EndHorizontal();

                //foreach (var servo in grp.servos)
                for (int iS = 0; iS < grp.servos.Count; iS++)
                {
                    var servo = grp.servos[iS];
                    if (!servo.freeMoving)
                    {
                        GUILayout.BeginHorizontal();

                        //Call the Add Servo Handle code
                        GUIDragAndDrop.DrawServoHandle(servo.servoName, i, iS);

                        //set a smaller height to align with text boxes
                        if (GUILayout.Button("[]", GUILayout.Width(30), GUILayout.Height(EditorButtonHeights)))
                        {
                            tmpMin = servo.minTweak.ToString();
                            tmpMax = servo.maxTweak.ToString();
                            servoTweak = servo;
                            guiTweakEnabled = true;
                        }

                        servo.servoName = GUILayout.TextField(servo.servoName,
                                                              expand);
                        //0.14 to 0.15 fix
                        if (update14to15)
                        {
                            string tempRot = GUILayout.TextField(servo.rotation.ToString(),
                                                                  expand);
                            servo.rotation = float.Parse(tempRot);
                        }
                        //0.14 to 0.15 fix
                        servo.groupName = grp.name;
                        servo.reverseKey = grp.reverseKey;
                        servo.forwardKey = grp.forwardKey;

                        if (groupEditorWinPos.Contains(mousePos))
                        {
                            var last = GUILayoutUtility.GetLastRect();
                            var pos = Event.current.mousePosition;
                            bool highlight = last.Contains(pos);
                            servo.part.SetHighlight(highlight,false);
                        }

                        if (servo_groups.Count > 1)
                        {
                            if (i > 0)
                            {
                                //Changed these to actual arrows - and set a smaller height to align with text boxes
                                if (GUILayout.Button("↑", width20, GUILayout.Height(EditorButtonHeights)))
                                {
                                    move_servo(grp, servo_groups[i - 1], servo);
                                }
                            }
                            else
                            {
                                GUILayout.Space(20);
                            }
                            if (i < (servo_groups.Count - 1))
                            {
                                //Changed these to actual arrows - and set a smaller height to align with text boxes
                                if (GUILayout.Button("↓", width20, GUILayout.Height(EditorButtonHeights)))
                                {
                                    move_servo(grp, servo_groups[i + 1], servo);
                                }
                            }
                            else
                            {
                                GUILayout.Space(20);
                            }
                        }
                        GUILayout.EndHorizontal();
                    }
                }
                GUIDragAndDrop.EndDrawGroup(i);

                GUILayout.EndVertical();

                GUILayout.EndHorizontal();
            }

            if (GUILayout.Button("Add new Group"))
            {
                Group temp = new Group();
                temp.name = "New Group" + (servo_groups.Count + 1).ToString();
                servo_groups.Add(temp);
            }

            GUILayout.EndVertical();

            GUILayout.EndScrollView();

            //Was gonna add a footer so you can drag resize the window and have the option to turn on dragging control
            //GUILayout.BeginHorizontal();
            //zTriggerTweaks.DragOn = GUILayout.Toggle(zTriggerTweaks.DragOn,new GUIContent(GameDatabase.Instance.GetTexture("MagicSmokeIndustries/Textures/icon_drag",false)));
            //GUILayout.EndHorizontal();

            //Do the End of window Code for DragAnd Drop
            GUIDragAndDrop.WindowEnd();

            //If we are dragging an item disable the windowdrag
            if (!GUIDragAndDrop.draggingItem)
                GUI.DragWindow();
        }
Example #14
0
        static void move_servo(Group from, Group to, MuMechToggle servo)
        {
            to.servos.Add(servo);
            from.servos.Remove(servo);
            servo.groupName = to.name;
            servo.forwardKey = to.forwardKey;
            servo.reverseKey = to.reverseKey;

            if (useEC)
            {
                updateGroupECRequirement(from);
                updateGroupECRequirement(to);
            }
        }
Example #15
0
 public Group(MuMechToggle servo)
 {
     this.name = servo.groupName;
     forwardKey = servo.forwardKey;
     reverseKey = servo.reverseKey;
     speed = servo.customSpeed.ToString("g");
     servos = new List<MuMechToggle>();
     showGUI = servo.showGUI;
     servos.Add(servo);
 }
Example #16
0
 public TranslateMechanism(MuMechToggle rawServo)
     : base(rawServo)
 {
 }
Example #17
0
 public ServoPreset(MuMechToggle rawServo, IServo servo)
 {
     this.rawServo = rawServo;
     this.servo    = servo;
 }
Example #18
0
 public ServoInput(MuMechToggle rawServo)
 {
     this.rawServo = rawServo;
 }