JakeBungarrra
Topic Author
Posts: 9
Joined: 11 Jul 2019, 03:32

Gamepad_Accept not calling click events

24 Jul 2019, 08:39

Im trying to do a very basic click a button and run a function, the function works with the mouse and has no problem. but every time i try to use a gamepad it does not pick up the input, im not to sure what I am doing wrong.

I have a simple button
<Button x:Name="SPP_FreeSurfButton" Content="Button" Width="524" FontSize="72" Click="SPP_FreeSurfButton"/>
Which simple calls the click event.

The button also has a style for triggers
    <Style x:Key="MainButtonStyle" TargetType="{x:Type Button}">
        <Setter Property="Background" Value="{StaticResource Menu.Button.Static.Background}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Padding" Value="1"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
                        <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Background" TargetName="border" Value="{StaticResource Menu.Button.MouseOver.Background}"/>
                        </Trigger>
                        <Trigger Property="IsPressed" Value="true">
                            <Setter Property="Background" TargetName="border" Value="{StaticResource Menu.Button.Pressed.Background}"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Background" TargetName="border" Value="{StaticResource Menu.Button.Disabled.Background}"/>
                        </Trigger>
                        <Trigger Property="IsFocused" Value="true">
                            <Setter Property="Background" TargetName="border" Value="{StaticResource Menu.Button.MouseOver.Background}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
public partial class MenuMain : UserControl
    {
        //Headers---------------------------------------------------------
        Viewbox root;
        //----------------------------------------------------------------
        public MenuMain()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            Noesis.GUI.LoadComponent(this, "Assets/UI/MainMenu/MenuMain.xaml");

            this.root = (Viewbox)FindName("MenuViewBox");
        }

        protected override bool ConnectEvent(object source, string eventName, string handlerName)
        {
            if (eventName == "Click" && handlerName == "SPP_FreeSurfButton")
            {
                ((Button)source).Click += this.toFreeSurfPanel;
                return true;
            }

            return false;
        }
        
        private void toFreeSurfPanel(object sender, RoutedEventArgs e)
        {
        //DO CLICK EVENT MAGIC
        }
}
        
This is the code that handles the click event and runs the function, within that function I get it run code (its a comment here, but I throw an exception every time to make sure it is working)

I also use the input mapper from the official documentation.
https://www.noesisengine.com/docs/2.2/G ... ml#gamepad

I would like to know if there is a reason behind this, or rather do I have to use certain event names, or certain triggers to get the A button on an Xbox controller calling the same as a mouse click.

Tags:
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Gamepad_Accept not calling click events

25 Jul 2019, 00:49

Does our Buttons sample work for you?

Note: make sure to use our input mappings.
 
JakeBungarrra
Topic Author
Posts: 9
Joined: 11 Jul 2019, 03:32

Re: Gamepad_Accept not calling click events

25 Jul 2019, 02:38

The buttons work with a gamepad on the samples, but I have the same error of it not clicking the accept function, the buttons are getting called on the gamepad, just the click event is not.

I am using your input mapping system.
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Gamepad_Accept not calling click events

25 Jul 2019, 14:25

Is the MenuMain.ConnectEvent() function being called? That is the point where the Click event is connected to the callback function.
If ConnectEvent is not being called make sure that your xaml root has the correct x:Class attribute.

Also remark that Button must have keyboard focus in order to react to the Gamepad_Accept input.
 
JakeBungarrra
Topic Author
Posts: 9
Joined: 11 Jul 2019, 03:32

Re: Gamepad_Accept not calling click events

26 Jul 2019, 02:46

        protected override bool ConnectEvent(object source, string eventName, string handlerName)
        {
            if (eventName == "Click" && handlerName == "SPP_FreeSurfButton")
            {
                ((Button)source).Click += this.toFreeSurfPanel;
                return true;
            }

            return false;
        }
Here is the above code that handles the button clicking event, works with a mouse and keyboard but not the controller.

The button is being called on the input as well, I simply use unity update function to do so.
        if (Input.GetButtonDown("Noesis_Accept"))
        {
            throw new System.Exception("Button Clicked");
        }
this calls an expectation every time on the controller that the A button is clicked.

what do you mean to have a keyboard focus? im assuming that when a button is focused on the button, is it what you mean by that?

X:class is correct and works.
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Gamepad_Accept not calling click events

01 Aug 2019, 11:16

A workaround until next release is found here: #1524

Who is online

Users browsing this forum: No registered users and 1 guest