예제 #1
0
파일: Servo.cs 프로젝트: lukedupin/hackjeb
 protected override void onPartStart()
 {
     allServos.Add(this);
     if (customPartData != "")
     {
         Dictionary <string, object> settings = (Dictionary <string, object>)KSP.IO.IOUtils.DeserializeFromBinary(Convert.FromBase64String(customPartData.Replace("*", "=").Replace("|", "/")));
         servoName = (string)settings["name"];
         string groupName = (string)settings["group"];
         if (groupName != "")
         {
             bool found = false;
             for (int i = 0; i < groups.Count; i++)
             {
                 if (groups[i].name == groupName)
                 {
                     found = true;
                     group = i;
                     break;
                 }
             }
             if (!found)
             {
                 MuMech.ServoGroup newGroup = new MuMech.ServoGroup();
                 newGroup.name   = groupName;
                 newGroup.key    = (string)settings["key"];
                 newGroup.revKey = (string)settings["revkey"];
                 groups.Add(newGroup);
                 group = groups.Count - 1;
             }
         }
         if (group >= 0)
         {
             rotateKey    = translateKey = groups[group].key;
             revRotateKey = revTranslateKey = groups[group].revKey;
         }
         if (!loadFromSFS)
         {
             rotation    = (float)settings["rot"];
             translation = (float)settings["trans"];
         }
     }
     configsLoaded = true;
     base.onPartStart();
 }
예제 #2
0
    private void editorWindowGUI(int windowID)
    {
        Vector2 mousePos = Input.mousePosition;

        mousePos.y = Screen.height - mousePos.y;

        editorScroll = GUILayout.BeginScrollView(editorScroll, false, false, GUILayout.MaxHeight(Screen.height / 2));

        GUILayout.BeginVertical();

        GUILayout.BeginHorizontal();

        GUILayout.Label("Group Name", GUILayout.ExpandWidth(true));
        GUILayout.Label("Keys", GUILayout.Width(40));
        if (groups.Count > 1)
        {
            GUILayout.Space(60);
        }
        GUILayout.EndHorizontal();

        for (int i = 0; i < groups.Count; i++)
        {
            MuMech.ServoGroup grp = groups[i];

            GUILayout.BeginHorizontal();
            string tmp = GUILayout.TextField(grp.name, GUILayout.ExpandWidth(true));
            if (grp.name != tmp)
            {
                grp.name      = tmp;
                configsLoaded = true;
            }
            tmp = GUILayout.TextField(grp.key, GUILayout.Width(20));
            if (grp.key != tmp)
            {
                grp.key       = tmp;
                configsLoaded = true;
            }
            tmp = GUILayout.TextField(grp.revKey, GUILayout.Width(20));
            if (grp.revKey != tmp)
            {
                grp.revKey    = tmp;
                configsLoaded = true;
            }
            if (i > 0)
            {
                if (GUILayout.Button("Remove", GUILayout.Width(60)))
                {
                    foreach (MuMechServo servo in allServos)
                    {
                        if (servo.group >= i)
                        {
                            servo.group--;
                        }
                    }
                    groups.RemoveAt(i);
                    resetWin = true;
                    return;
                }
            }
            else
            {
                if (groups.Count > 1)
                {
                    GUILayout.Space(60);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            GUILayout.Space(20);

            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Servo Name", GUILayout.ExpandWidth(true));
            GUILayout.Label("Rotate", GUILayout.Width(40));

            // mrblaq - some new things
            GUILayout.Label("Inv", GUILayout.Width(20));
            GUILayout.Label("Min", GUILayout.Width(35));
            GUILayout.Label("Max", GUILayout.Width(35));
            //mrblaq

            if (groups.Count > 1)
            {
                GUILayout.Label("Group", GUILayout.Width(40));
            }
            GUILayout.EndHorizontal();

            foreach (MuMechServo servo in allServos)
            {
                if (servo.group == i)
                {
                    GUILayout.BeginHorizontal();
                    servo.servoName = GUILayout.TextField(servo.servoName, GUILayout.ExpandWidth(true));
                    if (editorWinPos.Contains(mousePos))
                    {
                        servo.SetHighlight(GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition));
                    }
                    if (GUILayout.Button("<", GUILayout.Width(20)))
                    {
                        //servo.transform.RotateAround(servo.transform.up, Mathf.PI / 4);
                        //servo.transform.Rotate(servo.transform.up, Mathf.PI / 4);

                        //mrblaq
                        servo.transform.Rotate(servo.transform.up, rotateRate);
                    }
                    if (GUILayout.Button(">", GUILayout.Width(20)))
                    {
                        //servo.transform.RotateAround(servo.transform.up, -Mathf.PI / 4);
                        //servo.transform.Rotate(servo.transform.up, -Mathf.PI / 4);

                        //mrblaq
                        servo.transform.Rotate(servo.transform.up, -rotateRate);
                    }

                    // mrblaq - checkbox to invert direction
                    servo.invertAxis = GUILayout.Toggle(servo.invertAxis, "", GUILayout.Width(20));

                    // mrblaq: I dont' have limits for translation yet. So, either show limits input for rotation objects or don't.
                    if (servo.rotateJoint)
                    {
                        servo.minRange = GUILayout.TextField(servo.minRange, 4, GUILayout.Width(35));
                        servo.maxRange = GUILayout.TextField(servo.maxRange, 4, GUILayout.Width(35));
                    }
                    else
                    {
                        // mrblaq: I thought this would be 70 but looks like an input adds 2 px to each side from an inner width.
                        GUILayout.Space(78);
                    }
                    //mrblaq end



                    if (groups.Count > 1)
                    {
                        if (i > 0)
                        {
                            if (GUILayout.Button("/\\", GUILayout.Width(20)))
                            {
                                servo.group--;
                                configsLoaded = true;
                            }
                        }
                        else
                        {
                            GUILayout.Space(20);
                        }
                        if (i < (groups.Count - 1))
                        {
                            if (GUILayout.Button("\\/", GUILayout.Width(20)))
                            {
                                servo.group++;
                                configsLoaded = true;
                            }
                        }
                        else
                        {
                            GUILayout.Space(20);
                        }
                    }
                    GUILayout.EndHorizontal();
                }
            }

            GUILayout.EndVertical();

            GUILayout.EndHorizontal();
        }

        if (GUILayout.Button("Add new Group"))
        {
            MuMech.ServoGroup servo = new MuMech.ServoGroup();
            servo.name = "New Group" + (groups.Count + 1).ToString();     //add 1 to count name for grouping increment
            groups.Add(servo);
        }


        GUILayout.EndVertical();

        GUILayout.EndScrollView();

        GUI.DragWindow();
    }
예제 #3
0
파일: Servo.cs 프로젝트: lukedupin/hackjeb
    private void editorWindowGUI(int windowID)
    {
        Vector2 mousePos = Input.mousePosition;

        mousePos.y = Screen.height - mousePos.y;

        editorScroll = GUILayout.BeginScrollView(editorScroll, false, false, GUILayout.MaxHeight(Screen.height / 2));

        GUILayout.BeginVertical();

        GUILayout.BeginHorizontal();
        GUILayout.Label("Group Name", GUILayout.ExpandWidth(true));
        GUILayout.Label("Keys", GUILayout.Width(40));
        if (groups.Count > 1)
        {
            GUILayout.Space(60);
        }
        GUILayout.EndHorizontal();

        for (int i = 0; i < groups.Count; i++)
        {
            MuMech.ServoGroup grp = groups[i];

            GUILayout.BeginHorizontal();
            string tmp = GUILayout.TextField(grp.name, GUILayout.ExpandWidth(true));
            if (grp.name != tmp)
            {
                grp.name      = tmp;
                configsLoaded = true;
            }
            tmp = GUILayout.TextField(grp.key, GUILayout.Width(20));
            if (grp.key != tmp)
            {
                grp.key       = tmp;
                configsLoaded = true;
            }
            tmp = GUILayout.TextField(grp.revKey, GUILayout.Width(20));
            if (grp.revKey != tmp)
            {
                grp.revKey    = tmp;
                configsLoaded = true;
            }
            if (i > 0)
            {
                if (GUILayout.Button("Remove", GUILayout.Width(60)))
                {
                    foreach (MuMechServo servo in allServos)
                    {
                        if (servo.group >= i)
                        {
                            servo.group--;
                        }
                    }
                    groups.RemoveAt(i);
                    resetWin = true;
                    return;
                }
            }
            else
            {
                if (groups.Count > 1)
                {
                    GUILayout.Space(60);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            GUILayout.Space(20);

            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Servo Name", GUILayout.ExpandWidth(true));
            GUILayout.Label("Rotate", GUILayout.Width(40));
            if (groups.Count > 1)
            {
                GUILayout.Label("Group", GUILayout.Width(40));
            }
            GUILayout.EndHorizontal();

            foreach (MuMechServo servo in allServos)
            {
                if (servo.group == i)
                {
                    GUILayout.BeginHorizontal();
                    servo.servoName = GUILayout.TextField(servo.servoName, GUILayout.ExpandWidth(true));
                    if (editorWinPos.Contains(mousePos))
                    {
                        servo.SetHighlight(GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition));
                    }
                    if (GUILayout.Button("<", GUILayout.Width(20)))
                    {
                        servo.transform.RotateAround(servo.transform.up, Mathf.PI / 4);
                    }
                    if (GUILayout.Button(">", GUILayout.Width(20)))
                    {
                        servo.transform.RotateAround(servo.transform.up, -Mathf.PI / 4);
                    }
                    if (groups.Count > 1)
                    {
                        if (i > 0)
                        {
                            if (GUILayout.Button("/\\", GUILayout.Width(20)))
                            {
                                servo.group--;
                                configsLoaded = true;
                            }
                        }
                        else
                        {
                            GUILayout.Space(20);
                        }
                        if (i < (groups.Count - 1))
                        {
                            if (GUILayout.Button("\\/", GUILayout.Width(20)))
                            {
                                servo.group++;
                                configsLoaded = true;
                            }
                        }
                        else
                        {
                            GUILayout.Space(20);
                        }
                    }
                    GUILayout.EndHorizontal();
                }
            }

            GUILayout.EndVertical();

            GUILayout.EndHorizontal();
        }

        if (GUILayout.Button("Add new Group"))
        {
            groups.Add(new MuMech.ServoGroup());
        }

        GUILayout.EndVertical();

        GUILayout.EndScrollView();

        GUI.DragWindow();
    }
예제 #4
0
    protected override void onPartStart()
    {
        allServos.Add(this);
        if (customPartData != "")
        {
            Dictionary <string, object> settings = (Dictionary <string, object>)KSP.IO.IOUtils.DeserializeFromBinary(Convert.FromBase64String(customPartData.Replace("*", "=").Replace("|", "/")));
            servoName = (string)settings["name"];
            string groupName = (string)settings["group"];
            if (groupName != "")
            {
                bool found = false;
                for (int i = 0; i < groups.Count; i++)
                {
                    if (groups[i].name == groupName)
                    {
                        found = true;
                        group = i;
                        break;
                    }
                }
                if (!found)
                {
                    MuMech.ServoGroup newGroup = new MuMech.ServoGroup();
                    newGroup.name   = groupName;
                    newGroup.key    = (string)settings["key"];
                    newGroup.revKey = (string)settings["revkey"];
                    groups.Add(newGroup);
                    group = groups.Count - 1;
                }
            }
            if (group >= 0)
            {
                rotateKey    = translateKey = groups[group].key;
                revRotateKey = revTranslateKey = groups[group].revKey;
            }
            if (!loadFromSFS)
            {
                rotation    = (float)settings["rot"];
                translation = (float)settings["trans"];

                // mrblaq - gracefully check for existing values. Otherwise, continues to use class var defined values.
                if (settings.ContainsKey("invertAxis"))
                {
                    invertAxis = (bool)settings["invertAxis"];
                }
                if (settings.ContainsKey("minRange"))
                {
                    minRange = (string)settings["minRange"];
                }
                if (settings.ContainsKey("maxRange"))
                {
                    maxRange = (string)settings["maxRange"];
                }
                // convert limit strings to float.
                parseMinMax();
                // mrblaq
            }
        }
        configsLoaded = true;
        base.onPartStart();
    }