Ejemplo n.º 1
0
        public void Initialize()
        {
            RootControl = new Control {
                MouseFilter = Control.MouseFilterMode.Ignore
            };

            RootControl.SetAnchorPreset(Control.LayoutPreset.Wide);

            var escapeTexture    = _resourceCache.GetTexture("/Textures/UserInterface/hamburger.svg.96dpi.png");
            var characterTexture = _resourceCache.GetTexture("/Textures/UserInterface/character.svg.96dpi.png");
            var inventoryTexture = _resourceCache.GetTexture("/Textures/UserInterface/inventory.svg.96dpi.png");
            var craftingTexture  = _resourceCache.GetTexture("/Textures/UserInterface/hammer.svg.96dpi.png");
            var tutorialTexture  = _resourceCache.GetTexture("/Textures/UserInterface/students-cap.svg.96dpi.png");
            var sandboxTexture   = _resourceCache.GetTexture("/Textures/UserInterface/sandbox.svg.96dpi.png");

            _topButtonsContainer = new HBoxContainer
            {
                SeparationOverride = 4
            };

            RootControl.AddChild(_topButtonsContainer);
            _topButtonsContainer.SetAnchorAndMarginPreset(Control.LayoutPreset.TopLeft, margin: 10);

            // TODO: Pull key names here from the actual key binding config.
            // Escape
            _buttonEscapeMenu = new TopButton(escapeTexture, "Esc")
            {
                ToolTip = _loc.GetString("Open escape menu.")
            };

            _topButtonsContainer.AddChild(_buttonEscapeMenu);

            _buttonEscapeMenu.OnToggled += args => EscapeButtonToggled?.Invoke(args.Pressed);

            // Tutorial
            _buttonTutorial = new TopButton(tutorialTexture, "F1")
            {
                ToolTip = _loc.GetString("Open tutorial.")
            };

            _topButtonsContainer.AddChild(_buttonTutorial);

            _buttonTutorial.OnToggled += a => ButtonTutorialOnOnToggled();

            // Character
            _buttonCharacterMenu = new TopButton(characterTexture, "C")
            {
                ToolTip = _loc.GetString("Open character menu."),
                Visible = false
            };

            _topButtonsContainer.AddChild(_buttonCharacterMenu);

            _buttonCharacterMenu.OnToggled += args => CharacterButtonToggled?.Invoke(args.Pressed);

            // Inventory
            _buttonInventoryMenu = new TopButton(inventoryTexture, "I")
            {
                ToolTip = _loc.GetString("Open inventory menu."),
                Visible = false
            };

            _topButtonsContainer.AddChild(_buttonInventoryMenu);

            _buttonInventoryMenu.OnToggled += args => InventoryButtonToggled?.Invoke(args.Pressed);

            // Crafting
            _buttonCraftingMenu = new TopButton(craftingTexture, "G")
            {
                ToolTip = _loc.GetString("Open crafting menu."),
                Visible = false
            };

            _topButtonsContainer.AddChild(_buttonCraftingMenu);

            _buttonCraftingMenu.OnToggled += args => CraftingButtonToggled?.Invoke(args.Pressed);

            // Sandbox
            _buttonSandboxMenu = new TopButton(sandboxTexture, "B")
            {
                ToolTip = _loc.GetString("Open sandbox menu."),
                Visible = true
            };

            _topButtonsContainer.AddChild(_buttonSandboxMenu);

            _buttonSandboxMenu.OnToggled += args => SandboxButtonToggled?.Invoke(args.Pressed);

            _tutorialWindow = new TutorialWindow();

            _tutorialWindow.OnClose += () => _buttonTutorial.Pressed = false;

            _inputManager.SetInputCommand(ContentKeyFunctions.OpenTutorial,
                                          InputCmdHandler.FromDelegate(s => ButtonTutorialOnOnToggled()));

            var inventoryContainer = new HBoxContainer
            {
                GrowHorizontal     = Control.GrowDirection.Begin,
                GrowVertical       = Control.GrowDirection.Begin,
                SeparationOverride = 10
            };

            RootControl.AddChild(inventoryContainer);
            inventoryContainer.SetAnchorAndMarginPreset(Control.LayoutPreset.BottomRight);

            InventoryQuickButtonContainer = new MarginContainer
            {
                GrowHorizontal = Control.GrowDirection.Begin,
                GrowVertical   = Control.GrowDirection.Begin,
            };

            HandsContainer = new MarginContainer
            {
                GrowHorizontal = Control.GrowDirection.Both,
                GrowVertical   = Control.GrowDirection.Begin
            };

            inventoryContainer.Children.Add(HandsContainer);
            inventoryContainer.Children.Add(InventoryQuickButtonContainer);
        }
Ejemplo n.º 2
0
    private BoxContainer GenerateButtonBar(IResourceCache resourceCache, IInputManager inputManager)
    {
        var topButtonsContainer = new BoxContainer
        {
            Orientation        = BoxContainer.LayoutOrientation.Horizontal,
            SeparationOverride = 8
        };

        LayoutContainer.SetAnchorAndMarginPreset(topButtonsContainer, LayoutContainer.LayoutPreset.TopLeft, margin: 10);

        // the icon textures here should all have the same image height (32) but different widths, so in order to ensure
        // the buttons themselves are consistent widths we set a common custom min size
        Vector2 topMinSize = (42, 64);

        // Escape
        {
            _buttonEscapeMenu = new TopButton(resourceCache.GetTexture("/Textures/Interface/hamburger.svg.192dpi.png"),
                                              EngineKeyFunctions.EscapeMenu, inputManager)
            {
                ToolTip      = Loc.GetString("game-hud-open-escape-menu-button-tooltip"),
                MinSize      = (70, 64),
                StyleClasses = { StyleBase.ButtonOpenRight }
            };

            topButtonsContainer.AddChild(_buttonEscapeMenu);

            _buttonEscapeMenu.OnToggled += args => EscapeButtonToggled?.Invoke(args.Pressed);
        }

        // Character
        {
            _buttonCharacterMenu = new TopButton(resourceCache.GetTexture("/Textures/Interface/character.svg.192dpi.png"),
                                                 ContentKeyFunctions.OpenCharacterMenu, inputManager)
            {
                ToolTip      = Loc.GetString("game-hud-open-character-menu-button-tooltip"),
                MinSize      = topMinSize,
                Visible      = false,
                StyleClasses = { StyleBase.ButtonSquare }
            };

            topButtonsContainer.AddChild(_buttonCharacterMenu);

            _buttonCharacterMenu.OnToggled += args => CharacterButtonToggled?.Invoke(args.Pressed);
        }

        // Inventory
        {
            _buttonInventoryMenu = new TopButton(resourceCache.GetTexture("/Textures/Interface/inventory.svg.192dpi.png"),
                                                 ContentKeyFunctions.OpenInventoryMenu, inputManager)
            {
                ToolTip      = Loc.GetString("game-hud-open-inventory-menu-button-tooltip"),
                MinSize      = topMinSize,
                Visible      = false,
                StyleClasses = { StyleBase.ButtonSquare }
            };

            topButtonsContainer.AddChild(_buttonInventoryMenu);

            _buttonInventoryMenu.OnToggled += args => InventoryButtonToggled?.Invoke(args.Pressed);
        }

        // Crafting
        {
            _buttonCraftingMenu = new TopButton(resourceCache.GetTexture("/Textures/Interface/hammer.svg.192dpi.png"),
                                                ContentKeyFunctions.OpenCraftingMenu, inputManager)
            {
                ToolTip      = Loc.GetString("game-hud-open-crafting-menu-button-tooltip"),
                MinSize      = topMinSize,
                Visible      = false,
                StyleClasses = { StyleBase.ButtonSquare }
            };

            topButtonsContainer.AddChild(_buttonCraftingMenu);

            _buttonCraftingMenu.OnToggled += args => CraftingButtonToggled?.Invoke(args.Pressed);
        }

        // Actions
        {
            _buttonActionsMenu = new TopButton(resourceCache.GetTexture("/Textures/Interface/fist.svg.192dpi.png"),
                                               ContentKeyFunctions.OpenActionsMenu, inputManager)
            {
                ToolTip      = Loc.GetString("game-hud-open-actions-menu-button-tooltip"),
                MinSize      = topMinSize,
                Visible      = false,
                StyleClasses = { StyleBase.ButtonSquare }
            };

            topButtonsContainer.AddChild(_buttonActionsMenu);

            _buttonActionsMenu.OnToggled += args => ActionsButtonToggled?.Invoke(args.Pressed);
        }

        // Admin
        {
            _buttonAdminMenu = new TopButton(resourceCache.GetTexture("/Textures/Interface/gavel.svg.192dpi.png"),
                                             ContentKeyFunctions.OpenAdminMenu, inputManager)
            {
                ToolTip      = Loc.GetString("game-hud-open-admin-menu-button-tooltip"),
                MinSize      = topMinSize,
                Visible      = false,
                StyleClasses = { StyleBase.ButtonSquare }
            };

            topButtonsContainer.AddChild(_buttonAdminMenu);

            _buttonAdminMenu.OnToggled += args => AdminButtonToggled?.Invoke(args.Pressed);
        }

        // Sandbox
        {
            _buttonSandboxMenu = new TopButton(resourceCache.GetTexture("/Textures/Interface/sandbox.svg.192dpi.png"),
                                               ContentKeyFunctions.OpenSandboxWindow, inputManager)
            {
                ToolTip      = Loc.GetString("game-hud-open-sandbox-menu-button-tooltip"),
                MinSize      = topMinSize,
                Visible      = false,
                StyleClasses = { StyleBase.ButtonSquare }
            };

            topButtonsContainer.AddChild(_buttonSandboxMenu);

            _buttonSandboxMenu.OnToggled += args => SandboxButtonToggled?.Invoke(args.Pressed);
        }

        // Info Window
        {
            _buttonInfo = new TopButton(resourceCache.GetTexture("/Textures/Interface/info.svg.192dpi.png"),
                                        ContentKeyFunctions.OpenInfo, inputManager)
            {
                ToolTip      = Loc.GetString("ui-options-function-open-info"),
                MinSize      = topMinSize,
                StyleClasses = { StyleBase.ButtonOpenLeft, TopButton.StyleClassRedTopButton },
            };

            topButtonsContainer.AddChild(_buttonInfo);

            _buttonInfo.OnToggled += args => InfoButtonToggled?.Invoke(args.Pressed);
            _buttonInfo.OnToggled += ButtonInfoToggledHandler;
        }

        return(topButtonsContainer);
    }