mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-17 00:56:07 +09:00
added sources for Slick
Former-commit-id: 1647fa32ef6894bd7db44f741f07c2f4dcdf9054 Former-commit-id: 0e5810dcfbe1fd59b13e7cabe9f1e93c5542da2d
This commit is contained in:
54
lib/slick-source/org/newdawn/slick/command/BasicCommand.java
Normal file
54
lib/slick-source/org/newdawn/slick/command/BasicCommand.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package org.newdawn.slick.command;
|
||||
|
||||
/**
|
||||
* A simple named command
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class BasicCommand implements Command {
|
||||
/** The name of the command */
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Create a new basic command
|
||||
*
|
||||
* @param name The name to give this command
|
||||
*/
|
||||
public BasicCommand(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name given for this basic command
|
||||
*
|
||||
* @return The name given for this basic command
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof BasicCommand) {
|
||||
return ((BasicCommand) other).name.equals(name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return "[Command="+name+"]";
|
||||
}
|
||||
}
|
||||
12
lib/slick-source/org/newdawn/slick/command/Command.java
Normal file
12
lib/slick-source/org/newdawn/slick/command/Command.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package org.newdawn.slick.command;
|
||||
|
||||
/**
|
||||
* The description of a action feedback from the abstract input system. This marker allows the
|
||||
* creation of action objects that can contain useful state. If you don't need state and just
|
||||
* a name use <code>BasicCommand</code.
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public interface Command {
|
||||
|
||||
}
|
||||
9
lib/slick-source/org/newdawn/slick/command/Control.java
Normal file
9
lib/slick-source/org/newdawn/slick/command/Control.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package org.newdawn.slick.command;
|
||||
|
||||
/**
|
||||
* Marker class for abstract input controls
|
||||
*
|
||||
* @author joverton
|
||||
*/
|
||||
public interface Control {
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.newdawn.slick.command;
|
||||
|
||||
/**
|
||||
* A control indicating that a gamepad/joystick button must be pressed
|
||||
* or released to invoke an command.
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class ControllerButtonControl extends ControllerControl {
|
||||
|
||||
/**
|
||||
* Create a new control based on a controller input
|
||||
*
|
||||
* @param controllerIndex The index of the controller to listen to
|
||||
* @param button The index of the button that causes the command
|
||||
*/
|
||||
public ControllerButtonControl(int controllerIndex, int button) {
|
||||
super(controllerIndex, BUTTON_EVENT, button);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package org.newdawn.slick.command;
|
||||
|
||||
/**
|
||||
* A control describing input provided from a controller. This allows controls to be
|
||||
* mapped to game pad inputs.
|
||||
*
|
||||
* @author joverton
|
||||
*/
|
||||
abstract class ControllerControl implements Control {
|
||||
/** Indicates a button was pressed */
|
||||
protected static final int BUTTON_EVENT = 0;
|
||||
/** Indicates left was pressed */
|
||||
protected static final int LEFT_EVENT = 1;
|
||||
/** Indicates right was pressed */
|
||||
protected static final int RIGHT_EVENT = 2;
|
||||
/** Indicates up was pressed */
|
||||
protected static final int UP_EVENT = 3;
|
||||
/** Indicates down was pressed */
|
||||
protected static final int DOWN_EVENT = 4;
|
||||
|
||||
/** The type of event we're looking for */
|
||||
private int event;
|
||||
/** The index of the button we're waiting for */
|
||||
private int button;
|
||||
/** The index of the controller we're waiting on */
|
||||
private int controllerNumber;
|
||||
|
||||
/**
|
||||
* Create a new controller control
|
||||
*
|
||||
* @param controllerNumber The index of the controller to react to
|
||||
* @param event The event to react to
|
||||
* @param button The button index to react to on a BUTTON event
|
||||
*/
|
||||
protected ControllerControl(int controllerNumber, int event, int button) {
|
||||
this.event = event;
|
||||
this.button = button;
|
||||
this.controllerNumber = controllerNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object o) {
|
||||
if(o == null)
|
||||
return false;
|
||||
if(!(o instanceof ControllerControl))
|
||||
return false;
|
||||
|
||||
ControllerControl c = (ControllerControl)o;
|
||||
|
||||
return c.controllerNumber == controllerNumber && c.event == event && c.button == button;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public int hashCode() {
|
||||
return event + button + controllerNumber;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.newdawn.slick.command;
|
||||
|
||||
/**
|
||||
* A control indicating that a particular direction must be pressed or released
|
||||
* on a controller to cause the command to fire
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class ControllerDirectionControl extends ControllerControl {
|
||||
/** The direction indicating we're waiting for the user to press left */
|
||||
public static final Direction LEFT = new Direction(LEFT_EVENT);
|
||||
/** The direction indicating we're waiting for the user to press up */
|
||||
public static final Direction UP = new Direction(UP_EVENT);
|
||||
/** The direction indicating we're waiting for the user to press down */
|
||||
public static final Direction DOWN = new Direction(DOWN_EVENT);
|
||||
/** The direction indicating we're waiting for the user to press right */
|
||||
public static final Direction RIGHT = new Direction(RIGHT_EVENT);
|
||||
|
||||
/**
|
||||
* Create a new input that indicates a direcitonal control must be pressed
|
||||
*
|
||||
* @param controllerIndex The index of the controller to listen to
|
||||
* @param dir The direction to wait for
|
||||
*/
|
||||
public ControllerDirectionControl(int controllerIndex, Direction dir) {
|
||||
super(controllerIndex, dir.event, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum pretender
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
private static class Direction {
|
||||
/** The event to be fired for this direction */
|
||||
private int event;
|
||||
|
||||
/**
|
||||
* Create a new direction indicator/enum value
|
||||
*
|
||||
* @param event The event to fire when this direction is used
|
||||
*/
|
||||
public Direction(int event) {
|
||||
this.event = event;
|
||||
}
|
||||
}
|
||||
}
|
||||
464
lib/slick-source/org/newdawn/slick/command/InputProvider.java
Normal file
464
lib/slick-source/org/newdawn/slick/command/InputProvider.java
Normal file
@@ -0,0 +1,464 @@
|
||||
package org.newdawn.slick.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.util.InputAdapter;
|
||||
|
||||
/**
|
||||
* The central provider that maps real device input into abstract commands
|
||||
* defined by the developer. Registering a control against an command with this
|
||||
* class will cause the provider to produce an event for the command when the
|
||||
* input is pressed and released.
|
||||
*
|
||||
* @author joverton
|
||||
*/
|
||||
public class InputProvider {
|
||||
/** The commands that have been defined */
|
||||
private HashMap commands;
|
||||
|
||||
/** The list of listeners that may be listening */
|
||||
private ArrayList listeners = new ArrayList();
|
||||
|
||||
/** The input context we're responding to */
|
||||
private Input input;
|
||||
|
||||
/** The command input states */
|
||||
private HashMap commandState = new HashMap();
|
||||
|
||||
/** True if this provider is actively sending events */
|
||||
private boolean active = true;
|
||||
|
||||
/**
|
||||
* Create a new input proider which will provide abstract input descriptions
|
||||
* based on the input from the supplied context.
|
||||
*
|
||||
* @param input
|
||||
* The input from which this provider will receive events
|
||||
*/
|
||||
public InputProvider(Input input) {
|
||||
this.input = input;
|
||||
|
||||
input.addListener(new InputListenerImpl());
|
||||
commands = new HashMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of commands that have been registered with the provider,
|
||||
* i.e. the commands that can be issued to the listeners
|
||||
*
|
||||
* @return The list of commands (@see Command) that can be issued from this
|
||||
* provider
|
||||
*/
|
||||
public List getUniqueCommands() {
|
||||
List uniqueCommands = new ArrayList();
|
||||
|
||||
for (Iterator it = commands.values().iterator(); it.hasNext();) {
|
||||
Command command = (Command) it.next();
|
||||
|
||||
if (!uniqueCommands.contains(command)) {
|
||||
uniqueCommands.add(command);
|
||||
}
|
||||
}
|
||||
|
||||
return uniqueCommands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of the registered controls (@see Control) that can cause a
|
||||
* particular command to be invoked
|
||||
*
|
||||
* @param command
|
||||
* The command to be invoked
|
||||
* @return The list of controls that can cause the command (@see Control)
|
||||
*/
|
||||
public List getControlsFor(Command command) {
|
||||
List controlsForCommand = new ArrayList();
|
||||
|
||||
for (Iterator it = commands.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
Control key = (Control) entry.getKey();
|
||||
Command value = (Command) entry.getValue();
|
||||
|
||||
if (value == command) {
|
||||
controlsForCommand.add(key);
|
||||
}
|
||||
}
|
||||
return controlsForCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate whether this provider should be sending events
|
||||
*
|
||||
* @param active
|
||||
* True if this provider should be sending events
|
||||
*/
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this provider should be sending events
|
||||
*
|
||||
* @return True if this provider should be sending events
|
||||
*/
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a listener to the provider. This listener will be notified of
|
||||
* commands detected from the input.
|
||||
*
|
||||
* @param listener
|
||||
* The listener to be added
|
||||
*/
|
||||
public void addListener(InputProviderListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a listener from this provider. The listener will no longer be
|
||||
* provided with notification of commands performe.
|
||||
*
|
||||
* @param listener
|
||||
* The listener to be removed
|
||||
*/
|
||||
public void removeListener(InputProviderListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind an command to a control.
|
||||
*
|
||||
* @param command
|
||||
* The command to bind to
|
||||
* @param control
|
||||
* The control that is pressed/released to represent the command
|
||||
*/
|
||||
public void bindCommand(Control control, Command command) {
|
||||
commands.put(control, command);
|
||||
|
||||
if (commandState.get(command) == null) {
|
||||
commandState.put(command, new CommandState());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all the controls that have been configured for a given command
|
||||
*
|
||||
* @param command The command whose controls should be unbound
|
||||
*/
|
||||
public void clearCommand(Command command) {
|
||||
List controls = getControlsFor(command);
|
||||
|
||||
for (int i=0;i<controls.size();i++) {
|
||||
unbindCommand((Control) controls.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbinds the command associated with this control
|
||||
*
|
||||
* @param control
|
||||
* The control to remove
|
||||
*/
|
||||
public void unbindCommand(Control control) {
|
||||
Command command = (Command) commands.remove(control);
|
||||
if (command != null) {
|
||||
if (!commands.keySet().contains(command)) {
|
||||
commandState.remove(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the recorded state for a given command
|
||||
*
|
||||
* @param command
|
||||
* The command to get the state for
|
||||
* @return The given command state
|
||||
*/
|
||||
private CommandState getState(Command command) {
|
||||
return (CommandState) commandState.get(command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the last control event we recieved related to the given command
|
||||
* indicated that a control was down
|
||||
*
|
||||
* @param command
|
||||
* The command to check
|
||||
* @return True if the last event indicated a button down
|
||||
*/
|
||||
public boolean isCommandControlDown(Command command) {
|
||||
return getState(command).isDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if one of the controls related to the command specified has been
|
||||
* pressed since we last called this method
|
||||
*
|
||||
* @param command
|
||||
* The command to check
|
||||
* @return True if one of the controls has been pressed
|
||||
*/
|
||||
public boolean isCommandControlPressed(Command command) {
|
||||
return getState(command).isPressed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire notification to any interested listeners that a control has been
|
||||
* pressed indication an particular command
|
||||
*
|
||||
* @param command
|
||||
* The command that has been pressed
|
||||
*/
|
||||
protected void firePressed(Command command) {
|
||||
getState(command).down = true;
|
||||
getState(command).pressed = true;
|
||||
|
||||
if (!isActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < listeners.size(); i++) {
|
||||
((InputProviderListener) listeners.get(i)).controlPressed(command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire notification to any interested listeners that a control has been
|
||||
* released indication an particular command should be stopped
|
||||
*
|
||||
* @param command
|
||||
* The command that has been pressed
|
||||
*/
|
||||
protected void fireReleased(Command command) {
|
||||
getState(command).down = false;
|
||||
|
||||
if (!isActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < listeners.size(); i++) {
|
||||
((InputProviderListener) listeners.get(i)).controlReleased(command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A token representing the state of all the controls causing an command to
|
||||
* be invoked
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
private class CommandState {
|
||||
/** True if one of the controls for this command is down */
|
||||
private boolean down;
|
||||
|
||||
/** True if one of the controls for this command is pressed */
|
||||
private boolean pressed;
|
||||
|
||||
/**
|
||||
* Check if a control for the command has been pressed since last call.
|
||||
*
|
||||
* @return True if the command has been pressed
|
||||
*/
|
||||
public boolean isPressed() {
|
||||
if (pressed) {
|
||||
pressed = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the last event we had indicated the control was pressed
|
||||
*
|
||||
* @return True if the control was pressed
|
||||
*/
|
||||
public boolean isDown() {
|
||||
return down;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple listener to respond to input and look up any required commands
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
private class InputListenerImpl extends InputAdapter {
|
||||
/**
|
||||
* @see org.newdawn.slick.util.InputAdapter#isAcceptingInput()
|
||||
*/
|
||||
public boolean isAcceptingInput() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.util.InputAdapter#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
Command command = (Command) commands.get(new KeyControl(key));
|
||||
if (command != null) {
|
||||
firePressed(command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.util.InputAdapter#keyReleased(int, char)
|
||||
*/
|
||||
public void keyReleased(int key, char c) {
|
||||
Command command = (Command) commands.get(new KeyControl(key));
|
||||
if (command != null) {
|
||||
fireReleased(command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.util.InputAdapter#mousePressed(int, int, int)
|
||||
*/
|
||||
public void mousePressed(int button, int x, int y) {
|
||||
Command command = (Command) commands.get(new MouseButtonControl(
|
||||
button));
|
||||
if (command != null) {
|
||||
firePressed(command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.util.InputAdapter#mouseReleased(int, int, int)
|
||||
*/
|
||||
public void mouseReleased(int button, int x, int y) {
|
||||
Command command = (Command) commands.get(new MouseButtonControl(
|
||||
button));
|
||||
if (command != null) {
|
||||
fireReleased(command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.util.InputAdapter#controllerLeftPressed(int)
|
||||
*/
|
||||
public void controllerLeftPressed(int controller) {
|
||||
Command command = (Command) commands
|
||||
.get(new ControllerDirectionControl(controller,
|
||||
ControllerDirectionControl.LEFT));
|
||||
if (command != null) {
|
||||
firePressed(command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.util.InputAdapter#controllerLeftReleased(int)
|
||||
*/
|
||||
public void controllerLeftReleased(int controller) {
|
||||
Command command = (Command) commands
|
||||
.get(new ControllerDirectionControl(controller,
|
||||
ControllerDirectionControl.LEFT));
|
||||
if (command != null) {
|
||||
fireReleased(command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.util.InputAdapter#controllerRightPressed(int)
|
||||
*/
|
||||
public void controllerRightPressed(int controller) {
|
||||
Command command = (Command) commands
|
||||
.get(new ControllerDirectionControl(controller,
|
||||
ControllerDirectionControl.RIGHT));
|
||||
if (command != null) {
|
||||
firePressed(command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.util.InputAdapter#controllerRightReleased(int)
|
||||
*/
|
||||
public void controllerRightReleased(int controller) {
|
||||
Command command = (Command) commands
|
||||
.get(new ControllerDirectionControl(controller,
|
||||
ControllerDirectionControl.RIGHT));
|
||||
if (command != null) {
|
||||
fireReleased(command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.util.InputAdapter#controllerUpPressed(int)
|
||||
*/
|
||||
public void controllerUpPressed(int controller) {
|
||||
Command command = (Command) commands
|
||||
.get(new ControllerDirectionControl(controller,
|
||||
ControllerDirectionControl.UP));
|
||||
if (command != null)
|
||||
firePressed(command);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.util.InputAdapter#controllerUpReleased(int)
|
||||
*/
|
||||
public void controllerUpReleased(int controller) {
|
||||
Command command = (Command) commands
|
||||
.get(new ControllerDirectionControl(controller,
|
||||
ControllerDirectionControl.UP));
|
||||
if (command != null) {
|
||||
fireReleased(command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.util.InputAdapter#controllerDownPressed(int)
|
||||
*/
|
||||
public void controllerDownPressed(int controller) {
|
||||
Command command = (Command) commands
|
||||
.get(new ControllerDirectionControl(controller,
|
||||
ControllerDirectionControl.DOWN));
|
||||
if (command != null) {
|
||||
firePressed(command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.util.InputAdapter#controllerDownReleased(int)
|
||||
*/
|
||||
public void controllerDownReleased(int controller) {
|
||||
Command command = (Command) commands
|
||||
.get(new ControllerDirectionControl(controller,
|
||||
ControllerDirectionControl.DOWN));
|
||||
if (command != null) {
|
||||
fireReleased(command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.util.InputAdapter#controllerButtonPressed(int,
|
||||
* int)
|
||||
*/
|
||||
public void controllerButtonPressed(int controller, int button) {
|
||||
Command command = (Command) commands
|
||||
.get(new ControllerButtonControl(controller, button));
|
||||
if (command != null) {
|
||||
firePressed(command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.util.InputAdapter#controllerButtonReleased(int,
|
||||
* int)
|
||||
*/
|
||||
public void controllerButtonReleased(int controller, int button) {
|
||||
Command command = (Command) commands
|
||||
.get(new ControllerButtonControl(controller, button));
|
||||
if (command != null) {
|
||||
fireReleased(command);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.newdawn.slick.command;
|
||||
|
||||
/**
|
||||
* Description of any class wishing to recieve notifications of command invocations. Implementations
|
||||
* should be added to an appropriate input provider to recieve input notification
|
||||
*
|
||||
* @author joverton
|
||||
*/
|
||||
public interface InputProviderListener {
|
||||
|
||||
/**
|
||||
* A control representing an control was pressed relating to a given command.
|
||||
*
|
||||
* @param command The command that the control related to
|
||||
*/
|
||||
public void controlPressed(Command command);
|
||||
|
||||
/**
|
||||
* A control representing an control was released relating to a given command.
|
||||
*
|
||||
* @param command The command that the control related to
|
||||
*/
|
||||
public void controlReleased(Command command);
|
||||
}
|
||||
39
lib/slick-source/org/newdawn/slick/command/KeyControl.java
Normal file
39
lib/slick-source/org/newdawn/slick/command/KeyControl.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package org.newdawn.slick.command;
|
||||
|
||||
/**
|
||||
* A control relating to a command indicate that it should be fired when a specific key is pressed
|
||||
* or released.
|
||||
*
|
||||
* @author joverton
|
||||
*/
|
||||
public class KeyControl implements Control {
|
||||
/** The key code that needs to be pressed */
|
||||
private int keycode;
|
||||
|
||||
/**
|
||||
* Create a new control that caused an command to be fired on a key pressed/released
|
||||
*
|
||||
* @param keycode The code of the key that causes the command
|
||||
*/
|
||||
public KeyControl(int keycode) {
|
||||
this.keycode = keycode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof KeyControl) {
|
||||
return ((KeyControl)o).keycode == keycode;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public int hashCode() {
|
||||
return keycode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.newdawn.slick.command;
|
||||
|
||||
/**
|
||||
* A control indicating that a mouse button must be pressed or released to cause an command
|
||||
*
|
||||
* @author joverton
|
||||
*/
|
||||
public class MouseButtonControl implements Control {
|
||||
/** The button to be pressed */
|
||||
private int button;
|
||||
|
||||
/**
|
||||
* Create a new control that indicates a mouse button to be pressed or released
|
||||
*
|
||||
* @param button The button that should be pressed to cause the command
|
||||
*/
|
||||
public MouseButtonControl(int button) {
|
||||
this.button = button;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof MouseButtonControl)
|
||||
{
|
||||
return ((MouseButtonControl)o).button == button;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public int hashCode() {
|
||||
return button;
|
||||
}
|
||||
}
|
||||
4
lib/slick-source/org/newdawn/slick/command/package.html
Normal file
4
lib/slick-source/org/newdawn/slick/command/package.html
Normal file
@@ -0,0 +1,4 @@
|
||||
<BODY>
|
||||
Provides abstract input by mapping physical device inputs (mouse, keyboard and controllers) to abstract
|
||||
commands that are relevant to a particular game.
|
||||
</BODY>
|
||||
Reference in New Issue
Block a user