Exemplo n.º 1
0
        public void UpdateButtonTabs()
        {
            SDrawbleView drawableView;

            //Get our part modules
            UpdateConverters();
            GetPartModules();

            this.views = new List <SDrawbleView>();

            //Custom views from other PartModules
            List <IOpsView> templateOpsViews = this.part.FindModulesImplementing <IOpsView>();
            int             totalCount       = templateOpsViews.Count;
            int             labelCount;
            string          label;
            IOpsView        templateOps;

            for (int index = 0; index < totalCount; index++)
            {
                templateOps = templateOpsViews[index];
                List <string> labels = templateOps.GetButtonLabels();
                labelCount = labels.Count;
                for (int labelIndex = 0; labelIndex < labelCount; labelIndex++)
                {
                    label                    = labels[labelIndex];
                    drawableView             = new SDrawbleView();
                    drawableView.buttonLabel = label;
                    drawableView.view        = templateOps;
                    templateOps.SetParentView(this);
                    templateOps.SetContextGUIVisible(false);
                    views.Add(drawableView);
                }
            }
        }
Exemplo n.º 2
0
        protected override void DrawWindowContents(int windowId)
        {
            GUILayout.BeginHorizontal();

            //View buttons
            _scrollPosViews = GUILayout.BeginScrollView(_scrollPosViews, new GUILayoutOption[] { GUILayout.Width(160) });
            int          totalViews = views.Count;
            SDrawbleView drawableView;

            for (int index = 0; index < totalViews; index++)
            {
                drawableView = views[index];

                if (GUILayout.Button(drawableView.buttonLabel))
                {
                    _scrollPosViews     = new Vector2();
                    currentDrawableView = drawableView;
                }
            }
            GUILayout.EndScrollView();

            //CurrentView
            currentDrawableView.view.DrawOpsWindow(currentDrawableView.buttonLabel);

            GUILayout.EndHorizontal();
        }
Exemplo n.º 3
0
        public override void SetVisible(bool newValue)
        {
            base.SetVisible(newValue);

            if (newValue)
            {
                UpdateButtonTabs();

                //Set initial view
                currentDrawableView = views[0];
            }
        }
Exemplo n.º 4
0
        protected override void DrawWindowContents(int windowId)
        {
            if (!this.isAssembled)
            {
                GUILayout.Label("<color=yellow><b>" + this.part.partInfo.title + " needs to be assembled before commencing operations. </b></color>");
                return;
            }

            //HACK! Recent version of KSP has broken something in the scripting. Even though WBIOpsManager tells the view to UpdateButtonTabs, and they DO update,
            //when we draw the window contents, it's as if the drawable views haven't been updated. It is VERY puzzling. The part itself has an updated
            //part module count though, and we can use that to determine if anything has changed. If so, then we can refresh our button tabs and such before drawing.
            if (this.part.Modules.Count != partModuleCount)
            {
                partModuleCount = this.part.Modules.Count;
                UpdateButtonTabs();
            }

            GUILayout.BeginHorizontal();

            //View buttons
            if (views.Count > 1)
            {
                _scrollPosViews = GUILayout.BeginScrollView(_scrollPosViews, new GUILayoutOption[] { GUILayout.Width(160) });
                int          totalViews = views.Count;
                SDrawbleView drawableView;
                for (int index = 0; index < totalViews; index++)
                {
                    drawableView = views[index];

                    if (GUILayout.Button(drawableView.buttonLabel))
                    {
                        _scrollPosViews     = new Vector2();
                        currentDrawableView = drawableView;
                    }
                }
                GUILayout.EndScrollView();
            }
            else
            {
                currentDrawableView = views[0];
            }

            //CurrentView
            currentDrawableView.view.DrawOpsWindow(currentDrawableView.buttonLabel);

            GUILayout.EndHorizontal();
        }
Exemplo n.º 5
0
 public void RebuildView()
 {
     UpdateButtonTabs();
     currentDrawableView = views[0];
 }
Exemplo n.º 6
0
        protected void reloadViews()
        {
            List <IOpsView> opsViews;
            List <string>   buttonLabels;
            SDrawbleView    drawableView;
            Vessel          vessel;
            IOpsView        opsView;
            string          label;
            int             totalVessels, totalViews, totalLabels;

            drawableViews.Clear();

            //Find all the loaded vessels in physics range
            totalVessels = FlightGlobals.VesselsLoaded.Count;
            for (int vesselIndex = 0; vesselIndex < totalVessels; vesselIndex++)
            {
                vessel = FlightGlobals.VesselsLoaded[vesselIndex];
                if (vessel.mainBody != FlightGlobals.ActiveVessel.mainBody)
                {
                    continue;
                }

                //Now find all part modules in the vessel that implement IOpsViews
                opsViews   = vessel.FindPartModulesImplementing <IOpsView>();
                totalViews = opsViews.Count;

                //Go through the list and get their drawable views
                for (int viewIndex = 0; viewIndex < totalViews; viewIndex++)
                {
                    opsView = opsViews[viewIndex];

                    //Set parent view
                    opsView.SetParentView(this);

                    if (opsView is WBIResourceSwitcher)
                    {
                        WBIResourceSwitcher switcher = (WBIResourceSwitcher)opsView;
                        switcher.onModuleRedecorated -= OnModuleRedecorated;
                        switcher.onModuleRedecorated += OnModuleRedecorated;
                    }

                    //Setup button labels
                    buttonLabels = opsView.GetButtonLabels();
                    totalLabels  = buttonLabels.Count;
                    for (int labelIndex = 0; labelIndex < totalLabels; labelIndex++)
                    {
                        label                    = buttonLabels[labelIndex];
                        drawableView             = new SDrawbleView();
                        drawableView.buttonLabel = label;
                        drawableView.view        = opsView;
                        drawableView.vessel      = vessel;
                        drawableView.partTitle   = opsView.GetPartTitle();

                        if (drawableViews.ContainsKey(label) == false)
                        {
                            drawableViews.Add(label, new List <SDrawbleView>());
                        }

                        drawableViews[label].Add(drawableView);
                    }
                }

                if (drawableViews.Count > 0)
                {
                    selectedButton = drawableViews.Keys.First <string>();
                    views          = drawableViews[selectedButton];
                }
            }
        }