Beispiel #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);
        }