Exemplo n.º 1
0
        public void MonitorDefaultActions()
        {
            //print("2a");
            if (EditorActionGroups.Instance.GetSelectedParts() != null) //is a part selected?
            {
              
                if (EditorActionGroups.Instance.GetSelectedParts().Count > 0) //list can exist with no parts in it if you selected then unselect one
                {
                   
                    if(SelectedWithSym.Count == 0 || SelectedWithSym.First() != EditorActionGroups.Instance.GetSelectedParts().First()) //check if there is a previously selected part, if so check if its changed
                    {
                        //print("2b");
                        //parts are different
                        SelectedWithSym.Clear(); //reset lastpart list
                        SelectedWithSym.AddRange(EditorActionGroups.Instance.GetSelectedParts());
                        SelectedWithSym.AddRange(EditorActionGroups.Instance.GetSelectedParts().First().symmetryCounterparts);
                        SelectedWithSymActions.Clear(); //reset actions list
                        //print("2c");
                        foreach (Part prt in SelectedWithSym)
                        {
                          //  print("2d");
                            foreach (BaseAction bap in prt.Actions) //get part actions
                            {
                                SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bap, agrp = bap.actionGroup }); //add actiongroup separate otherwise it links and so have nothing to compare
                            }
                           
                            foreach (PartModule pm in prt.Modules) //add actions from all partmodules
                            {
                                foreach (BaseAction bapm in pm.Actions)
                                {
                                    SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bapm, agrp = bapm.actionGroup });
                                }
                            }
                        }

                       // print("2e");
                    }
                    else //selected part is the same a previously selected part
                    {
                       // print("2f");
                        List<Part> PartsThisFrame = new List<Part>(); //get list of parts this update frame
                        PartsThisFrame.AddRange(EditorActionGroups.Instance.GetSelectedParts());
                        PartsThisFrame.AddRange(EditorActionGroups.Instance.GetSelectedParts().First().symmetryCounterparts);
                       // print("2g");
                        List<BaseAction> ThisFrameActions = new List<BaseAction>(); //get actions fresh again this update frame
                        foreach (Part prt in PartsThisFrame)
                        {
                           // print("2h"); 
                            foreach (BaseAction bap in prt.Actions)
                            {
                                ThisFrameActions.Add(bap);
                            }
                            foreach (PartModule pm in prt.Modules)
                            {
                                foreach (BaseAction bapm in pm.Actions)
                                {
                                    ThisFrameActions.Add(bapm);
                                }
                            }
                        }
                        //print("2i");

                        foreach (BaseAction ba2 in ThisFrameActions) //check each action's actiongroup enum against last update frames actiongroup enum
                        {
                            //print("2j");
                            AGXDefaultCheck ActionLastFrame = new AGXDefaultCheck();
                            //print("2j1");
                            ActionLastFrame = SelectedWithSymActions.Find(a => a.ba == ba2);
                           // print("2j2");
                            if (ActionLastFrame.agrp != ba2.actionGroup) //actiongroup enum is different
                            {
                              //  print("2j3");
                                int NewGroup = 0; //which actiongroup changed?
                                if (KSPActionGroup.Custom01 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                {
                                    NewGroup = 1;
                                }
                                else if (KSPActionGroup.Custom02 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                {
                                    NewGroup = 2;
                                }
                                else if (KSPActionGroup.Custom03 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                {
                                    NewGroup = 3;
                                }
                                else if (KSPActionGroup.Custom04 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                {
                                    NewGroup = 4;
                                }
                                else if (KSPActionGroup.Custom05 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                {
                                    NewGroup = 5;
                                }
                                else if (KSPActionGroup.Custom06 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                {
                                    NewGroup = 6;
                                }
                                else if (KSPActionGroup.Custom07 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                {
                                    NewGroup = 7;
                                }
                                else if (KSPActionGroup.Custom08 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                {
                                    NewGroup = 8;
                                }
                                else if (KSPActionGroup.Custom09 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                {
                                    NewGroup = 9;
                                }
                                else if (KSPActionGroup.Custom10 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                {
                                    NewGroup = 10;
                                }

                               // print("2k");


                                if (NewGroup != 0) //if one of the other actiongroups (gear, lights) has changed, ignore it. newgroup will be the actiongroup if I want to process it.
                                {
                                        AGXAction ToAdd = new AGXAction() { prt = ba2.listParent.part, ba = ba2, group = NewGroup, activated = false };
                                        List<AGXAction> Checking = new List<AGXAction>();
                                        Checking.AddRange(CurrentVesselActions);
                                        Checking.RemoveAll(p => p.group != ToAdd.group);
                                        Checking.RemoveAll(p => p.prt != ToAdd.prt);
                                        Checking.RemoveAll(p => p.ba != ToAdd.ba);

                                        if (Checking.Count == 0)
                                        {
                                            CurrentVesselActions.Add(ToAdd);
                                            //SaveCurrentVesselActions();
                                        }
                                    
                                }
                                ActionLastFrame.agrp = KSPActionGroup.None;
                                ActionLastFrame.agrp = ActionLastFrame.agrp | ba2.actionGroup;
                               // print("2l");
                            }
                           
                        }
                        SelectedWithSymActions.Clear(); //reset actions list as one of the enums changed.
                      //  print("2k");
                        foreach (Part prt in SelectedWithSym)
                        {
                            
                            foreach (BaseAction bap in prt.Actions) //get part actions
                            {
                                SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bap, agrp = bap.actionGroup }); //add actiongroup separate otherwise it links and so have nothing to compare
                            }
                            foreach (PartModule pm in prt.Modules) //add actions from all partmodules
                            {
                                foreach (BaseAction bapm in pm.Actions)
                                {
                                    SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bapm, agrp = bapm.actionGroup });
                                }
                            }
                        }
                    }
                }
            }
           // print("2l");
        }
Exemplo n.º 2
0
        public void MonitorDefaultActions()
        {
            //print("AGX Monitor default start " + StaticData.CurrentVesselActions.Count());
            KSPActionGroup KSPDefaultActionGroupThisFrame = KSPActionGroup.Custom01;
            try //find which action group is selected in default ksp editor this pass
            {
                string grpText = "None";
                for (int i = 0; i < EditorActionGroups.Instance.actionGroupList.Count; i++)
                {
                    IUIListObject lObj = EditorActionGroups.Instance.actionGroupList.GetItem(i);
                    UIListItem LstItem = (UIListItem)lObj;
                    if (LstItem.controlState == UIButton.CONTROL_STATE.ACTIVE)
                    {
                        grpText = LstItem.Text;
                    }
                }

                KSPDefaultActionGroupThisFrame = (KSPActionGroup)Enum.Parse(typeof(KSPActionGroup), grpText);
                //print("Selected group " + KSPDefaultLastActionGroup);

            }
            catch
            {
                print("AGX Monitor default list fail");
            }
            string errLine = "1";
            try
            {
                errLine = "2";
                if (EditorActionGroups.Instance.GetSelectedParts() != null) //is a part selected?
                {
                    errLine = "3";
                    if (EditorActionGroups.Instance.GetSelectedParts().Count > 0) //list can exist with no parts in it if you selected then unselect one
                    {
                        errLine = "4";
                        if (SelectedWithSym.Count == 0 || SelectedWithSym.First() != EditorActionGroups.Instance.GetSelectedParts().First() || KSPDefaultActionGroupThisFrame != KSPDefaultLastActionGroup) //check if there is a previously selected part, if so check if its changed
                        {
                            errLine = "5";
                            //print("2b");
                            //parts are different
                            SelectedWithSym.Clear(); //reset lastpart list
                            SelectedWithSym.AddRange(EditorActionGroups.Instance.GetSelectedParts());
                            SelectedWithSym.AddRange(EditorActionGroups.Instance.GetSelectedParts().First().symmetryCounterparts);
                            SelectedWithSymActions.Clear(); //reset actions list
                            //print("2c");
                            errLine = "6";
                            foreach (Part prt in SelectedWithSym)
                            {
                                //  print("2d");
                                errLine = "7";
                                foreach (BaseAction bap in prt.Actions) //get part actions
                                {
                                    SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bap, agrp = bap.actionGroup }); //add actiongroup separate otherwise it links and so have nothing to compare
                                }
                                errLine = "8";
                                foreach (PartModule pm in prt.Modules) //add actions from all partmodules
                                {
                                    errLine = "9";
                                    foreach (BaseAction bapm in pm.Actions)
                                    {
                                        errLine = "10";
                                        SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bapm, agrp = bapm.actionGroup });
                                    }
                                }
                            }
                            errLine = "11";
                            int groupToAdd = 1;
                            switch (KSPDefaultActionGroupThisFrame)
                            {
                                case KSPActionGroup.Custom01:
                                    groupToAdd = 1;
                                    break;
                                case KSPActionGroup.Custom02:
                                    groupToAdd = 2;
                                    break;
                                case KSPActionGroup.Custom03:
                                    groupToAdd = 3;
                                    break;
                                case KSPActionGroup.Custom04:
                                    groupToAdd = 4;
                                    break;
                                case KSPActionGroup.Custom05:
                                    groupToAdd = 5;
                                    break;
                                case KSPActionGroup.Custom06:
                                    groupToAdd = 6;
                                    break;
                                case KSPActionGroup.Custom07:
                                    groupToAdd = 7;
                                    break;
                                case KSPActionGroup.Custom08:
                                    groupToAdd = 8;
                                    break;
                                case KSPActionGroup.Custom09:
                                    groupToAdd = 9;
                                    break;
                                case KSPActionGroup.Custom10:
                                    groupToAdd = 10;
                                    break;
                            }
                            errLine = "12";
                            foreach (AGXAction agact2 in StaticData.CurrentVesselActions.Where(ag => ag.group == groupToAdd))
                            {
                                SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = agact2.ba, agrp = agact2.ba.actionGroup });
                            }
                            errLine = "13";
                            KSPDefaultLastActionGroup = KSPDefaultActionGroupThisFrame;
                            //foreach (AGXDefaultCheck dC in SelectedWithSymActions)
                            //{
                            //    print("Acts " + dC.ba.name);
                            //}
                            // print("2e");
                        }
                        else //selected part is the same a previously selected part
                        {
                            errLine = "14";
                            //print("2f");
                            List<Part> PartsThisFrame = new List<Part>(); //get list of parts this update frame
                            PartsThisFrame.AddRange(EditorActionGroups.Instance.GetSelectedParts());
                            PartsThisFrame.AddRange(EditorActionGroups.Instance.GetSelectedParts().First().symmetryCounterparts);
                            // print("2g");
                            List<BaseAction> ThisFrameActions = new List<BaseAction>(); //get actions fresh again this update frame
                            foreach (Part prt in PartsThisFrame)
                            {
                                errLine = "15";
                                // print("2h");
                                foreach (BaseAction bap in prt.Actions)
                                {
                                    ThisFrameActions.Add(bap);
                                }
                                errLine = "16";
                                foreach (PartModule pm in prt.Modules)
                                {
                                    foreach (BaseAction bapm in pm.Actions)
                                    {
                                        ThisFrameActions.Add(bapm);
                                    }
                                }
                            }
                            errLine = "17";
                            int groupToAdd = 1;
                            switch (KSPDefaultActionGroupThisFrame)
                            {
                                case KSPActionGroup.Custom01:
                                    groupToAdd = 1;
                                    break;
                                case KSPActionGroup.Custom02:
                                    groupToAdd = 2;
                                    break;
                                case KSPActionGroup.Custom03:
                                    groupToAdd = 3;
                                    break;
                                case KSPActionGroup.Custom04:
                                    groupToAdd = 4;
                                    break;
                                case KSPActionGroup.Custom05:
                                    groupToAdd = 5;
                                    break;
                                case KSPActionGroup.Custom06:
                                    groupToAdd = 6;
                                    break;
                                case KSPActionGroup.Custom07:
                                    groupToAdd = 7;
                                    break;
                                case KSPActionGroup.Custom08:
                                    groupToAdd = 8;
                                    break;
                                case KSPActionGroup.Custom09:
                                    groupToAdd = 9;
                                    break;
                                case KSPActionGroup.Custom10:
                                    groupToAdd = 10;
                                    break;
                            }

                            foreach (AGXAction agact2 in StaticData.CurrentVesselActions.Where(ag => ag.group == groupToAdd))
                            {
                                ThisFrameActions.Add(agact2.ba);
                            }

                            errLine = "18";

                            //print("2i");

                            foreach (BaseAction ba2 in ThisFrameActions) //check each action's actiongroup enum against last update frames actiongroup enum, this adds/removes a group to default KSP when added/removed in agx
                            {
                                //print("2j");
                                errLine = "19";
                                AGXDefaultCheck ActionLastFrame = new AGXDefaultCheck();
                                //print("2j1");
                                ActionLastFrame = SelectedWithSymActions.Find(a => a.ba == ba2);
                                // print("2j2");
                                errLine = "20";
                                if (ActionLastFrame.agrp != ba2.actionGroup) //actiongroup enum is different
                                {
                                    //  print("2j3");
                                    int NewGroup = 0; //which actiongroup changed?
                                    if (KSPActionGroup.Custom01 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 1;
                                    }
                                    else if (KSPActionGroup.Custom02 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 2;
                                    }
                                    else if (KSPActionGroup.Custom03 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 3;
                                    }
                                    else if (KSPActionGroup.Custom04 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 4;
                                    }
                                    else if (KSPActionGroup.Custom05 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 5;
                                    }
                                    else if (KSPActionGroup.Custom06 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 6;
                                    }
                                    else if (KSPActionGroup.Custom07 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 7;
                                    }
                                    else if (KSPActionGroup.Custom08 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 8;
                                    }
                                    else if (KSPActionGroup.Custom09 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 9;
                                    }
                                    else if (KSPActionGroup.Custom10 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 10;
                                    }

                                    // print("2k");
                                    errLine = "21";

                                    if (NewGroup != 0) //if one of the other actiongroups (gear, lights) has changed, ignore it. newgroup will be the actiongroup if I want to process it.
                                    {
                                        // print("Newgroup called on " + NewGroup);
                                        errLine = "22";
                                        if (Mouse.screenPos.x >= 130 && Mouse.screenPos.x <= 280)
                                        {
                                            //print("remove actions");
                                            //AGXAction ToRemove = new AGXAction() { prt = ba2.listParent.part, ba = ba2, group = NewGroup, activated = false };
                                            StaticData.CurrentVesselActions.RemoveAll(ag3 => ag3.ba == ba2 && ag3.group == NewGroup);
                                        }
                                        else
                                        {
                                            errLine = "23";
                                            //print("add actions");
                                            AGXAction ToAdd = new AGXAction() { prt = ba2.listParent.part, ba = ba2, group = NewGroup, activated = false };
                                            List<AGXAction> Checking = new List<AGXAction>();
                                            Checking.AddRange(StaticData.CurrentVesselActions);
                                            Checking.RemoveAll(p => p.group != ToAdd.group);
                                            Checking.RemoveAll(p => p.prt != ToAdd.prt);
                                            Checking.RemoveAll(p => p.ba != ToAdd.ba);

                                            if (Checking.Count == 0)
                                            {
                                                StaticData.CurrentVesselActions.Add(ToAdd);
                                                //SaveCurrentVesselActions();
                                            }
                                        }

                                    }
                                    errLine = "24";
                                    ActionLastFrame.agrp = KSPActionGroup.None;
                                    ActionLastFrame.agrp = ActionLastFrame.agrp | ba2.actionGroup;
                                    //print("2l");
                                }

                            }
                            SelectedWithSymActions.Clear(); //reset actions list as one of the enums changed.
                            //print("2k");
                            errLine = "25";
                            foreach (Part prt in SelectedWithSym)
                            {
                                errLine = "26";
                                foreach (BaseAction bap in prt.Actions) //get part actions
                                {
                                    SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bap, agrp = bap.actionGroup }); //add actiongroup separate otherwise it links and so have nothing to compare
                                }
                                errLine = "27";
                                foreach (PartModule pm in prt.Modules) //add actions from all partmodules
                                {
                                    foreach (BaseAction bapm in pm.Actions)
                                    {
                                        SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bapm, agrp = bapm.actionGroup });
                                    }
                                }
                            }
                            errLine = "28";
                            foreach (AGXAction agact2 in StaticData.CurrentVesselActions.Where(ag => ag.group == groupToAdd))
                            {
                                SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = agact2.ba, agrp = agact2.ba.actionGroup });
                            }

                            errLine = "29";

                        }
                    }
                }
                //print("AGX Monitor default end " + StaticData.CurrentVesselActions.Count());
            }
            catch (Exception e)
            {
                Debug.Log("AGX Monitor Default Actions Error " + errLine + " " + e);
            }
            //print("2l " + Mouse.screenPos);
        }