View Javadoc
1   package org.newdawn.slick.command;
2   
3   /**
4    * A control describing input provided from a controller. This allows controls to be
5    * mapped to game pad inputs.
6    * 
7    * @author joverton
8    */
9   abstract class ControllerControl implements Control {
10      /** Indicates a button was pressed. */
11      static final int BUTTON_EVENT = 0;
12      /** Indicates left was pressed. */
13      static final int LEFT_EVENT = 1;
14      /** Indicates right was pressed. */
15      static final int RIGHT_EVENT = 2;
16      /** Indicates up was pressed. */
17      static final int UP_EVENT = 3;
18      /** Indicates down was pressed. */
19      static final int DOWN_EVENT = 4;
20      
21      /** The type of event we're looking for. */
22      private final int event;
23      /** The index of the button we're waiting for. */
24      private final int button;
25      /** The index of the controller we're waiting on. */
26      private final int controllerNumber;
27      
28      /**
29       * Create a new controller control.
30       * 
31       * @param controllerNumber The index of the controller to react to
32       * @param event The event to react to
33       * @param button The button index to react to on a BUTTON event
34       */
35      ControllerControl(int controllerNumber, int event, int button) {
36          this.event = event;
37          this.button = button;
38          this.controllerNumber = controllerNumber;
39      }
40  
41      /* (non-Javadoc)
42       * @see java.lang.Object#hashCode()
43       */
44      @Override
45      public int hashCode() {
46          final int prime = 31;
47          int result = 1;
48          result = prime * result + button;
49          result = prime * result + controllerNumber;
50          result = prime * result + event;
51          return result;
52      }
53  
54      /* (non-Javadoc)
55       * @see java.lang.Object#equals(java.lang.Object)
56       */
57      @Override
58      public boolean equals(Object obj) {
59          if (this == obj) {
60              return true;
61          }
62          if (obj == null) {
63              return false;
64          }
65          if (!(obj instanceof ControllerControl)) {
66              return false;
67          }
68          ControllerControl other = (ControllerControl) obj;
69          if (button != other.button) {
70              return false;
71          }
72          if (controllerNumber != other.controllerNumber) {
73              return false;
74          }
75          if (event != other.event) {
76              return false;
77          }
78          return true;
79      }
80      
81      
82  }