Ejemplo n.º 1
0
        public override void AttachTo(IColossalControl control)
        {
            control.AttachControl(Panel);

            if (HorizontalScrollbar != null)
            {
                HorizontalScrollbar.AttachTo(control);
            }

            if (VerticalScrollbar != null)
            {
                VerticalScrollbar.AttachTo(control);
            }
        }
Ejemplo n.º 2
0
        private void RemoveHorizontalScrollbar()
        {
            Panel.HorizontalScrollbar = null;

            if (HorizontalScrollbar != null)
            {
                Panel.Height += HorizontalScrollbar.Height;

                HorizontalScrollbar.Dispose();

                GameObject.DestroyImmediate(HorizontalScrollbar.Control.GameObject);
                HorizontalScrollbar = null;
            }
        }
Ejemplo n.º 3
0
        public override void AttachTo(GameObject gameObject)
        {
            Panel.GameObject.transform.parent = gameObject.transform;

            if (HorizontalScrollbar != null)
            {
                HorizontalScrollbar.AttachTo(gameObject);
            }

            if (VerticalScrollbar != null)
            {
                VerticalScrollbar.AttachTo(gameObject);
            }
        }
Ejemplo n.º 4
0
        public LogsExporterDrawer(EditorWindow window, List <Row> rows)
        {
            this.window       = window;
            this.rows         = rows;
            this.exporters    = Utility.CreateNGTInstancesOf <ILogExporter>();
            this.previewLabel = "Preview              (" + this.rows.Count + " element" + (this.rows.Count > 1 ? "s" : string.Empty) + ")";

            this.names = new string[this.exporters.Length];
            for (int i = 0; i < this.exporters.Length; i++)
            {
                this.names[i] = Utility.NicifyVariableName(this.exporters[i].GetType().Name);
            }

            string rawUsedOutputs = NGEditorPrefs.GetString(ExportLogsWindow.UsedOutputsKeyPref, null);

            if (string.IsNullOrEmpty(rawUsedOutputs) == false)
            {
                string[] splittedTypes = rawUsedOutputs.Split(ExportLogsWindow.UsedOutputsSeparator);

                for (int i = 0; i < splittedTypes.Length; i++)
                {
                    Type t = Type.GetType(splittedTypes[i]);

                    if (t != null)
                    {
                        this.usedOutputs.Add(Activator.CreateInstance(t) as ILogExportSource);
                    }
                }
            }

            if (this.usedOutputs.Count == 0)
            {
                for (int i = 0; i < LogsExporterDrawer.DefaultExportSources.Length; i++)
                {
                    this.usedOutputs.Add(Activator.CreateInstance(LogsExporterDrawer.DefaultExportSources[i]) as ILogExportSource);
                }
            }

            Utility.LoadEditorPref(this, NGEditorPrefs.GetPerProjectPrefix());

            for (int i = 0; i < this.exporters.Length; i++)
            {
                this.exporters[i].OnEnable();
            }

            this.horizontalScrollbar = new HorizontalScrollbar(0F, 18F, this.window.position.width, 4F);

            this.UpdatePreview();
        }
Ejemplo n.º 5
0
        protected virtual void  OnEnable()
        {
            Utility.RegisterWindow(this);
            Utility.RestoreIcon(this, NGStaticInspectorWindow.TitleColor);

            Metrics.UseTool(24);             // NGStaticInspector

            this.scrollPositionTabs = new HorizontalScrollbar(0F, 18F, 0F, 3F, 0F);
            this.scrollPositionTabs.interceiptEvent = false;
            this.scrollPositionTabs.hasCustomArea   = true;

            this.starIcon       = EditorGUIUtility.FindTexture("Favorite");
            this.wantsMouseMove = true;

            this.LoadinspectableStaticTypes();

            string[] rawTypes = (string[])Utility.LoadEditorPref(null, typeof(string[]), NGStaticInspectorWindow.TabsKeyPref);

            if (rawTypes != null)
            {
                this.tabTypes.Clear();
                this.tabTypes.Capacity = rawTypes.Length;

                for (int i = 0; i < rawTypes.Length; i++)
                {
                    Type type = Type.GetType(rawTypes[i]);

                    if (type != null)
                    {
                        for (int j = 0; j < NGStaticInspectorWindow.staticTypes.Length; j++)
                        {
                            if (NGStaticInspectorWindow.staticTypes[j] == type)
                            {
                                this.tabTypes.Add(j);
                                break;
                            }
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(this.searchKeywords) == false)
            {
                this.searchPatterns = Utility.SplitKeywords(this.searchKeywords, ' ');
                this.RefreshFilter();
            }
        }
        protected override void OnEnable()
        {
            base.OnEnable();

            this.scrollPositionTabs = new HorizontalScrollbar(0F, 18F, 0F, 3F, 0F);
            this.scrollPositionTabs.interceiptEvent = false;
            this.scrollPositionTabs.hasCustomArea   = true;

            this.starIcon       = EditorGUIUtility.FindTexture("Favorite");
            this.wantsMouseMove = true;

            if (string.IsNullOrEmpty(this.searchKeywords) == false)
            {
                this.searchPatterns = Utility.SplitKeywords(this.searchKeywords, ' ');
                this.RefreshFilter();
            }
        }
Ejemplo n.º 7
0
        public override void Init()
        {
            base.Init();

            buffer = ConsoleRenderer.ActiveBuffer;

            textBox = new TextBox(controlManager)
            {
                Width      = 34,
                Height     = 13,
                Text       = "Hello there",
                Attributes = CharAttribute.ForegroundWhite | CharAttribute.BackgroundDarkRed,
                WordBreak  = WordBreak.Hard,
                TextAlign  = TextAlign.Left
            };
            textBox.Text          = lorem;
            textBox.MousePressed += TextBox_MousePressed;
            textBox.Visible       = false;
            //textBox.MouseReleased += TextBox_MouseReleased;

            dataBox = new TextBox(controlManager)
            {
                Width      = 20,
                Height     = 2,
                Name       = "hello",
                Text       = textBox.Rectangle.Size.ToString(),
                Attributes = CharAttribute.ForegroundGreen
            };
            dataBox.Width   = dataBox.Text.Length;
            dataBox.Visible = false;


            vs = new VerticalScrollbar(controlManager)
            {
                Height = 5,
                Left   = 20,
                Top    = 4
            };

            hs = new HorizontalScrollbar(controlManager)
            {
                Width = 10,
                Left  = 3,
                Top   = Height - 1
            };

            new ScrollableTextBox(controlManager)
            {
                Width  = 20,
                Height = 5
            };


            colorfulString = new ColorfulString
            {
                Value      = new string(Enumerable.Repeat('A', Enum.GetValues(typeof(CharAttribute)).Length - 0).ToArray()),
                ColorThing = ColorSelectMode.Repeat,
                Attributes = (CharAttribute[])Enum.GetValues(typeof(CharAttribute))
            };


            strings = new string[]
            {
                "Haha",
                "Console",
                "Go",
                "Brrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"
            }.NormalizeLengths()
            .PadAround(2);

            int ratioX      = 2;
            int ratioY      = 1;
            int scale       = 2;
            int spacingX    = ratioX * scale;
            int spacingY    = ratioY * scale;
            int pieceWidth  = 2;
            int pieceHeight = 1;
            int tileWidth   = pieceWidth + spacingX * 2;
            int tileHeight  = pieceHeight + spacingY * 2;

            square = new CharInfo[8 * tileHeight, 8 * tileWidth];

            for (int y = 0; y < square.GetLength(0); y++)
            {
                for (int x = 0; x < square.GetLength(1); x++)
                {
                    square[y, x].Attributes |= ((x / tileWidth + y / tileHeight) % 2 == 0
                        ? CharAttribute.BackgroundGrey | CharAttribute.ForegroundBlack
                        : CharAttribute.BackgroundBlack | CharAttribute.ForegroundWhite);
                }
            }

            for (int y = 0; y < square.GetLength(0); y++)
            {
                for (int x = 0; x < square.GetLength(1); x++)
                {
                    if (x % tileWidth == 0 && y % tileHeight == 0)
                    {
                        int px = x + spacingX;
                        int py = y + spacingY;
                        square[py, px].UnicodeChar = '♕';
                        square[py, px].Attributes |= CharAttribute.LeadingByte;

                        var yellow = CharAttribute.BackgroundYellow | CharAttribute.ForegroundBlack;
                        var marker = new CharInfo
                        {
                            UnicodeChar = ShadingCharacter.Light,
                            Attributes  = yellow
                        };
                    }
                }
            }

            backface = new BufferArea(square.GetLength(1) + 4, square.GetLength(0) + 2);
            CharInfo backChar = new CharInfo
            {
                UnicodeChar = ShadingCharacter.Dark,
                Attributes  = CharAttribute.BackgroundDarkGrey
            };

            backface.Fill(backChar);


            //Draw();

            ConsoleInput.KeyPressed += ConsoleInput_KeyPressed;

            ConsoleInput.KeyHeld += ConsoleInput_KeyPressed;

            ConsoleInput.MouseReleased += TextBox_MouseReleased;

            ConsoleInput.MouseDragged += ConsoleInput_MouseDragged;

            ConsoleInput.Resized += ConsoleInput_Resized;
            //ConsoleInput.Resized += delegate
            //{
            //    Draw();
            //};
            Draw();
        }
Ejemplo n.º 8
0
        protected virtual void  OnGUI()
        {
            if (this.button == null)
            {
                this.button = new GUIStyle(GUI.skin.button);
                this.button.padding.left       = 16;
                this.scrollbar                 = new HorizontalScrollbar(0F, 18F, this.position.height);
                this.scrollbar.interceiptEvent = false;
            }

            float totalWidth = 0F;

            for (int i = 0; i < this.history.Count; i++)
            {
                totalWidth += GUI.skin.button.CalcSize(this.history[i].content).x + 20F + 4F;                 // Remove big texture width, because Button calculates using the whole height + Spacing
            }
            this.scrollbar.RealWidth = totalWidth;
            this.scrollbar.SetSize(this.position.width);
            this.scrollbar.OnGUI();

            EditorGUILayout.BeginHorizontal();
            {
                for (int i = 0; i < this.history.Count; i++)
                {
                    float w = GUI.skin.button.CalcSize(this.history[i].content).x + 20F;                       // Remove big texture width, because Button calculates using the whole height.
                    Rect  r = GUILayoutUtility.GetRect(0F, 0F, GUI.skin.button, GUILayoutOptionPool.Width(w), GUILayoutOptionPool.Height(Constants.SingleLineHeight));

                    r.x -= this.scrollbar.Offset;

                    if (GUI.Button(r, this.history[i].content, this.button) == true)
                    {
                        if (Event.current.button == 0)
                        {
                            this.master = i;
                        }
                        else
                        {
                            this.slave = i;
                        }
                    }

                    if (Event.current.type == EventType.Repaint)
                    {
                        r.x    += 5F;
                        r.width = r.height;
                        GUI.DrawTexture(r, this.history[i].icon);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(this.scrollbar.MaxHeight);

            Rect  r2   = GUILayoutUtility.GetLastRect();
            float half = this.position.width * .5F;

            EditorGUI.DrawRect(GUILayoutUtility.GetRect(this.position.width, 2F), Color.black);

            EditorGUILayout.BeginHorizontal();
            {
                this.scrollPositionMaster = GUILayout.BeginScrollView(this.scrollPositionMaster, GUILayoutOptionPool.Width(half));
                {
                    if (0 <= this.master && this.master < this.history.Count)
                    {
                        if (this.history[this.master].component == null)
                        {
                            this.history.RemoveAt(this.master);
                            this.master = -1;
                        }
                        else
                        {
                            this.DrawComponent(this.history[this.master]);
                        }
                    }
                    else
                    {
                        EditorGUILayout.LabelField("Add a Component here from a Component's context menu or left click on the history above.", GeneralStyles.BigCenterText);
                    }
                }
                GUILayout.EndScrollView();

                EditorGUI.DrawRect(GUILayoutUtility.GetRect(1F, 1F, 0F, float.MaxValue), Color.black);

                this.scrollPositionSlave = EditorGUILayout.BeginScrollView(this.scrollPositionSlave, GUILayoutOptionPool.Width(half));
                {
                    if (0 <= this.slave && this.slave < this.history.Count)
                    {
                        if (this.history[this.slave].component == null)
                        {
                            this.history.RemoveAt(this.slave);
                            this.slave = -1;
                        }
                        else
                        {
                            this.DrawComponent(this.history[this.slave]);
                        }
                    }
                    else
                    {
                        EditorGUILayout.LabelField("Add a Component here from a Component's context menu or right click on the history above.", GeneralStyles.BigCenterText);
                    }
                }
                EditorGUILayout.EndScrollView();

                r2.height = 48F;
                r2.width  = this.position.width;

                if (Event.current.type == EventType.DragUpdated &&
                    r2.Contains(Event.current.mousePosition) == true)
                {
                    if (typeof(Component).IsAssignableFrom(DragAndDrop.objectReferences[0].GetType()) == true)
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                    }
                    else
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                    }
                    Event.current.Use();
                }
                else if (Event.current.type == EventType.DragPerform &&
                         r2.Contains(Event.current.mousePosition) == true)
                {
                    DragAndDrop.AcceptDrag();

                    ComponentContainer container = new ComponentContainer(DragAndDrop.objectReferences[0] as Component);

                    this.history.Add(container);

                    if (Event.current.mousePosition.x < half)
                    {
                        this.master = this.history.Count - 1;
                    }
                    else
                    {
                        this.slave = this.history.Count - 1;
                    }

                    DragAndDrop.PrepareStartDrag();
                    Event.current.Use();
                }

                if (Event.current.type == EventType.Repaint &&
                    DragAndDrop.objectReferences.Length > 0)
                {
                    r2.width = half;
                    Utility.DropZone(r2, "Drop here");

                    r2.x = r2.width;
                    Utility.DropZone(r2, "Drop here");
                }
            }
            EditorGUILayout.EndHorizontal();
        }