Example #1
0
        public void Open(IUiWindow window, params WindowAnchor[] anchors)
        {
            openWindows.AddIfNotPresent(window);

            if (!((Element)window).HasParent())
            {
                var container = new Table();
                container.SetFillParent(true);
                container.Pad(15);

                foreach (var anchor in anchors)
                {
                    switch (anchor)
                    {
                    case WindowAnchor.Center: container.Center(); break;

                    case WindowAnchor.Left: container.Left(); break;

                    case WindowAnchor.Right: container.Right(); break;

                    case WindowAnchor.Top: container.Top(); break;

                    case WindowAnchor.Bottom: container.Bottom(); break;
                    }
                }

                container.Add((Element)window);
                Core.Scene.FindEntity("ui").GetComponent <UICanvas>().Stage.AddElement(container);
            }
            else
            {
                window.ToggleVisibility();
            }
        }
Example #2
0
 public static void CloseWindow(this IUiWindow window)
 {
     lock (Windows)
     {
         if (window.Id == _modalWindow)
         {
             _modalWindow = null;
         }
         Windows.Remove(window);
         SetActiveWindowProperty(null);
     }
 }
        public IEnumerable <ScreenSymbol> RenderLine(IUiWindow uiWindow)
        {
            var backgroundColor = uiWindow.BackgroundColor;
            var foregroundColor = uiWindow.ForegroundColor;
            var result          = new List <ScreenSymbol>();

            foreach (var action in _actions)
            {
                switch (action)
                {
                case ChangeBackgroundColorCommand cbc:
                    backgroundColor = cbc.Color;
                    continue;

                case ChangeForegroundColorCommand cfc:
                    foregroundColor = cfc.Color;
                    continue;

                case ResetColorCommand _:
                    backgroundColor = uiWindow.BackgroundColor;
                    foregroundColor = uiWindow.ForegroundColor;
                    break;

                case string str:
                {
                    foreach (var c in str)
                    {
                        result.Add(ScreenSymbol.Create(c, backgroundColor, foregroundColor));
                        if (result.Count >= uiWindow.Width)
                        {
                            return(result);
                        }
                    }

                    break;
                }
                }
            }


            ScreenSymbol sc = null;

            while (result.Count < uiWindow.Width)
            {
                if (sc == null)
                {
                    sc = ScreenSymbol.Create(' ', backgroundColor, foregroundColor);
                }
                result.Add(sc);
            }

            return(result);
        }
Example #4
0
        public static void ShowModalWindow(this IUiWindow window)
        {
            lock (Windows)
            {
                if (window.Id == null)
                {
                    window.Id = Guid.NewGuid().ToString();
                }

                _modalWindow = window.Id;
                ShowWindow(window);
            }
        }
Example #5
0
        public static void ShowWindow(this IUiWindow window)
        {
            lock (Windows)
            {
                if (window.Id == null)
                {
                    window.Id = Guid.NewGuid().ToString();
                }

                window.Resize(_width, _height);
                Windows.Add(window);

                SetActiveWindowProperty(window);
            }
        }
Example #6
0
        private static void SetActiveWindowProperty(IUiWindow activeWindow)
        {
            if (_modalWindow != null)
            {
                activeWindow = Windows.FirstOrDefault(itm => itm.Id == _modalWindow);
            }

            if (activeWindow == null)
            {
                activeWindow = Windows[Windows.Count - 1];
            }

            foreach (var window in Windows)
            {
                window.IsActive = window.Id == activeWindow.Id;
            }
        }
Example #7
0
        private static void RenderMenu(IUiWindow window, int width)
        {
            if (window.MenuLine == null)
            {
                Console.WriteLine(new string(' ', width));
                return;
            }


            foreach (var menuItem  in window.MenuLine)
            {
                Console.BackgroundColor = ConsoleColor.Cyan;
                Console.ForegroundColor = ConsoleColor.Black;
                Console.Write(menuItem.FuncKey);
                Console.BackgroundColor = ConsoleColor.DarkCyan;
                //        Console.ForegroundColor = ConsoleColor.White;
                Console.Write(menuItem.Value);
                Console.ResetColor();
                Console.Write(" ");

                width = width - menuItem.FuncKey.Length - menuItem.Value.Length - 1;
            }

            var notification = UiNotifications.GetItemToShow();

            if (notification != null)
            {
                RenderLineEngine.ChangeColor(notification.Background, notification.Foreground);
                Console.Write(notification.Text);
                width = width - notification.Text.Length;
            }

            if (width > 0)
            {
                Console.Write(new string(' ', width));
            }
        }
Example #8
0
 public void Close(IUiWindow window)
 {
     openWindows.Remove(window);
     window.Close();
 }
Example #9
0
 public void Open(IUiWindow window, Vector2 position)
 {
     Open(window, (int)position.X, (int)position.Y);
 }
Example #10
0
 public void Open(IUiWindow window, int x, int y)
 {
     window.SetPosition(x, y);
     Open(window);
 }
Example #11
0
 public void PopWindow(IUiWindow window)
 {
     windows.Remove(window);
 }
Example #12
0
 public void PushWindow(IUiWindow window)
 {
     windows.Push(window);
 }
        public static void WriteCentred(this RenderWindowLineEngine renderWindowLineEngine, IUiWindow window, string line)
        {
            var linePos = line.Length;

            linePos = window.Width / 2 - linePos / 2;

            renderWindowLineEngine.Write(new string(' ', linePos) + line);
        }