RemoteTech.UI.AntennaFragment.Draw C# (CSharp) Method

Draw() public method

public Draw ( ) : void
return void
        public void Draw()
        {
            // Allow update for non-triggering changes (e.g., changing map view filters or changing a vessel's type)
            // This is the best way I could find to do periodic refreshes;
            //  RTCore.Instance.InvokeRepeating() would require a search for instances
            //  of AntennaFragment, and would keep running after all target windows
            //  closed. Replace with something less clunky later! -- Starstrider42
            if (++refreshCounter >= 100) {
                Refresh();
                refreshCounter = 0;
            }

            mScrollPosition = GUILayout.BeginScrollView(mScrollPosition);
            Color pushColor = GUI.backgroundColor;
            // starstriders changes
            //Color pushCtColor = GUI.contentColor;
            //Color pushBgColor = GUI.backgroundColor;
            TextAnchor pushAlign = GUI.skin.button.alignment;
            try {
                GUI.skin.button.alignment = TextAnchor.MiddleLeft;
                // Depth-first tree traversal.
                Stack<Entry> dfs = new Stack<Entry>();
                foreach (Entry child in mRootEntry.SubEntries)
                {
                    dfs.Push(child);
                }

                // Set the inital mouseover to the selected entry
                mouseOverEntry = mSelection;

                while (dfs.Count > 0)
                {
                    Entry current = dfs.Pop();
                    GUI.backgroundColor = current.Color;

                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Space(current.Depth * (GUI.skin.button.margin.left + 24));
                        if (current.SubEntries.Count > 0)
                        {
                            RTUtil.Button(current.Expanded ? " <" : " >",
                                () =>
                                {
                                    current.Expanded = !current.Expanded;
                                }, GUILayout.Width(24));
                        }

                        RTUtil.StateButton(current.Text, mSelection == current ? 1 : 0, 1,
                            (s) =>
                            {
                                mSelection = current;
                                Antenna.Target = mSelection.Guid;
                            });

                        // Mouse is over the button
                        if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) && triggerMouseOverListEntry)
                        {
                            // reset current entry
                            mouseOverEntry = null;
                            if (current.Text.ToLower() != "active vessel" && current.Text.ToLower() != "no target")
                            {
                                mouseOverEntry = current;
                            }
                            onMouseOverListEntry.Invoke();
                        }

                    }
                    GUILayout.EndHorizontal();

                    if (current.Expanded)
                    {
                        foreach (Entry child in current.SubEntries)
                        {
                            dfs.Push(child);
                        }
                    }
                }

            } finally {
                GUILayout.EndScrollView();
                GUI.skin.button.alignment = pushAlign;
                GUI.backgroundColor = pushColor;
            }
        }

Usage Example

Beispiel #1
0
        public override void Window(int uid)
        {
            if (mAntennaFragment.Antenna == null)
            {
                Hide(); return;
            }
            GUI.skin = HighLogic.Skin;

            // check the mouse position on every draw call
            mouseOverAntennaWindow();

            GUILayout.BeginVertical(GUILayout.Width(300), GUILayout.Height(500));
            {
                mAntennaFragment.Draw();
            }
            GUILayout.EndVertical();

            base.Window(uid);
        }
All Usage Examples Of RemoteTech.UI.AntennaFragment::Draw