Esempio n. 1
0
        public override void LoadContent()
        {
            var menuBar = new UIPanel();

            menuBar.AddConstraint(Edge.Top, null, Edge.Top, 10);
            menuBar.AddConstraint(Edge.Left, null, Edge.Left, 50);
            menuBar.Alpha = 0f;

            var homeItem = new UIButton();

            homeItem.AddDecoration(new UILabel("Home Menu"));
            homeItem.AddConstraint(Edge.Left, menuBar, Edge.Left);
            homeItem.AddConstraint(Edge.CenterY, menuBar, Edge.CenterY);
            homeItem.InputReleased += HomeItem_InputReleased;
            menuBar.AddChild(homeItem);

            var debugCheckbox = new UILabelCheckBox("Draw UI Borders:");

            debugCheckbox.AddConstraint(Edge.Left, homeItem, Edge.Right, -20);
            debugCheckbox.AddConstraint(Edge.CenterY, menuBar, Edge.CenterY);
            debugCheckbox.CheckBox.InputReleased += DebugCheckbox_InputReleased;
            debugCheckbox.CheckBox.Checked        = UIManager.DrawDebug;
            menuBar.AddChild(debugCheckbox);

            testSceneUIManager = new UIManager();
            testSceneUIManager.Add(menuBar);
        }
Esempio n. 2
0
        public override void LoadContent()
        {
            base.LoadContent();

            cam       = new Camera(GraphicsDevice);
            uiManager = new UIManager();
            //uiManager.EnableProfilling = true;

            var menuPanel = new UIPanel();

            menuPanel.AddConstraint(Edge.CenterXY, null, Edge.CenterXY);
            menuPanel.Alpha = 0f;

            var testScenesButton = GetMenuEntry(menuPanel, "UI Test Scenes");

            testScenesButton.InputReleased += testScenes;
            menuPanel.AddChild(testScenesButton);

            var transitionScenesButton = GetMenuEntry(menuPanel, "Transition Test Scenes");

            transitionScenesButton.InputReleased += TransitionScenesButton_InputReleased;
            menuPanel.AddChild(transitionScenesButton);

            var exitButton = GetMenuEntry(menuPanel, "Exit");

            exitButton.InputReleased += ExitButton_InputReleased;
            menuPanel.AddChild(exitButton);

            uiManager.Add(menuPanel);
        }
Esempio n. 3
0
        public override void ProcessMouseEvent(Vector2 location, InputManager.LogicalButtonState buttons)
        {
            if (Math.Abs(buttons.WheelTick) > 0 && TextLabels.Count > 1)
            {
                SetSelectedIndex(SelectedIndex + buttons.WheelTick);
            }

            if (!buttons.PrimaryClick || ParentCanvas == null || ParentCanvas.PopupEnabled() || TextLabels.Count < 2)
            {
                return;
            }

            float width  = Rect.GetPixelSize().X;
            float height = Rect.GetPixelSize().Y;

            Vector2 origin = Rect.GetPixelOrigin();

            float availableDist = width - (height * 2);

            if (location.X < origin.X + height || location.X > origin.X + availableDist + height)
            {
                return;
            }

            Vector2 thisOrigin = GetScreenOrigin();

            float thisCenterY = thisOrigin.Y + (height * 0.5f);

            float totalheight = (MenuCommon.ButtonSpacing.Paramater + (height * 1)) * TextLabels.Count;

            totalheight += MenuCommon.ButtonSpacing.Paramater * 1;

            float halfHeight = totalheight * 0.5f;

            float screenHeight = ParentCanvas.BoundWindow.Height;

            // see where the popup will land on the screen.

            OriginLocation originAllignment = OriginLocation.LowerLeft;

            if (totalheight > screenHeight)  // it won't fit, center it
            {
                originAllignment = OriginLocation.MiddleLeft;
            }
            else
            {
                if (thisCenterY - halfHeight > 0 && thisCenterY + halfHeight <= screenHeight)
                {
                    originAllignment = OriginLocation.MiddleLeft; // it'll fit centered, that looks better
                }
                else
                {
                    // it won't fit centered, so put it on the other side of the screen from where the button is
                    if (thisCenterY > halfHeight)
                    {
                        originAllignment = OriginLocation.UpperLeft;
                    }
                    else
                    {
                        originAllignment = OriginLocation.LowerLeft;
                    }
                }
            }

            if (originAllignment == OriginLocation.UpperLeft)
            {
                thisOrigin.Y += height;
            }
            else if (originAllignment == OriginLocation.MiddleLeft)
            {
                thisOrigin.Y += height * 0.5f;
            }

            RelativeRect rect = new RelativeRect(new RelativeLoc(thisOrigin.X, RelativeLoc.Edge.Raw), new RelativeLoc(thisOrigin.Y, RelativeLoc.Edge.Raw), RelativeSize.FixedPixelSize(width), RelativeSize.FixedPixelSize(totalheight), originAllignment);

            var popup = new UIPanel(rect, ThemeManager.GetThemeAsset("ui/SelectorPopupBackground.png"));

            popup.FillMode    = UIFillModes.SmartStprite;
            popup.IgnoreMouse = false;

            VerticalLayoutGroup vertgroup = MenuCommon.SetupCommonColumn(new RelativeRect(RelativeLoc.XCenter, RelativeLoc.YCenter, RelativeSize.ThreeQuarterWidth, rect.Height, OriginLocation.Center));

            vertgroup.FirstElementHasSpacing = true;

            foreach (var label in TextLabels)
            {
                MenuButton button = new MenuButton(new RelativeRect(), label);
                button.Tag      = label;
                button.Clicked += PopupButton_Clicked;
                if (label == GetText())
                {
                    button.Check();
                }

                vertgroup.AddChild(button);
            }
            popup.AddChild(vertgroup);

            ParentCanvas.SetPopupElement(popup);
        }
Esempio n. 4
0
    public SettingsMenu()
    {
        masterPanel = new GameObject().AddComponent <UIMasterPanel>();
        masterPanel.SetRelativePosition(0, 0);
        masterPanel.SetRelativeSize(1, 1);
        masterPanel.ShowBox = false;

        waitingForInputPanel = new GameObject().AddComponent <UIPanel>();
        waitingForInputPanel.SetRelativePosition(0, 0);
        waitingForInputPanel.SetRelativeSize(1, 1);
        waitingForInputPanel.content = "Waiting for Input";
        waitingForInputPanel.ShowBox = false;

        inputPanel = new GameObject().AddComponent <UIPanel>();
        inputPanel.SetRelativePosition(0, 0);
        inputPanel.SetRelativeSize(1, 1);
        inputPanel.content = "Input Manager";

        masterPanel.AddChild(inputPanel);
        masterPanel.AddChild(waitingForInputPanel);

        UIButton backButton = new GameObject().AddComponent <UIButton>();

        backButton.SetAbsolutePosition(5, 5);
        backButton.SetAbsoluteSize(120, 25);

        backButton.HorizontalAnchor  = HorizontalAnchorPoint.LEFT;
        backButton.VerticalAnchor    = VerticalAnchorPoint.BOTTOM;
        backButton.VerticalAlignment = VerticalAnchorPoint.BOTTOM;

        backButton.Text = "Back";

        backButton.OnButtonClicked += OnBackButtonClicked;

        masterPanel.AddChild(backButton);

        float positionY = 30;

        UIButton inputButton;

        foreach (var item in InputController.Instance.InputInfos)
        {
            float PanelHeight = 50;

            UIPanel InputInfoHolderPanel = new GameObject().AddComponent <UIPanel>();
            InputInfoHolderPanel.SetAbsolutePosition(0, positionY);
            InputInfoHolderPanel.SetAbsoluteSize(250, PanelHeight);

            InputInfoHolderPanel.HorizontalAnchor    = HorizontalAnchorPoint.CENTER;
            InputInfoHolderPanel.HorizontalAlignment = HorizontalAnchorPoint.CENTER;

            InputInfoHolderPanel.content = item.Action.Replace("1_", "Player 1 ") + " : ";

            inputPanel.AddChild(InputInfoHolderPanel);

            //Label
            UIText inputLabel = new GameObject().AddComponent <UIText>();
            inputLabel.SetAbsoluteSize(100, 25);

            inputLabel.HorizontalAnchor    = HorizontalAnchorPoint.LEFT;
            inputLabel.VerticalAnchor      = VerticalAnchorPoint.BOTTOM;
            inputLabel.HorizontalAlignment = HorizontalAnchorPoint.LEFT;
            inputLabel.VerticalAlignment   = VerticalAnchorPoint.BOTTOM;

            //inputLabel.Text = item.Action.Replace("1_", "Player 1 ") + " : ";

            InputInfoHolderPanel.AddChild(inputLabel);


            inputButton = new GameObject().AddComponent <UIButton>();
            inputButton.SetAbsolutePosition(80, 0);
            inputButton.SetAbsoluteSize(120, 25);

            inputButton.HorizontalAnchor  = HorizontalAnchorPoint.LEFT;
            inputButton.VerticalAnchor    = VerticalAnchorPoint.BOTTOM;
            inputButton.VerticalAlignment = VerticalAnchorPoint.BOTTOM;

            inputButton.Text = item.GetInfo();

            inputButton.Callback = new InputButtonCallback(OnInputButtonClicked, inputButton, item);

            InputInfoHolderPanel.AddChild(inputButton);


            UIButton resetButton = new GameObject().AddComponent <UIButton>();
            resetButton.SetAbsoluteSize(25, 25);

            resetButton.HorizontalAnchor    = HorizontalAnchorPoint.RIGHT;
            resetButton.VerticalAnchor      = VerticalAnchorPoint.BOTTOM;
            resetButton.HorizontalAlignment = HorizontalAnchorPoint.RIGHT;
            resetButton.VerticalAlignment   = VerticalAnchorPoint.BOTTOM;

            resetButton.Text = "X";

            resetButton.Callback = new InputButtonCallback(OnDeleteInputButtonClicked, inputButton, item);

            InputInfoHolderPanel.AddChild(resetButton);

            positionY += PanelHeight;
        }
    }