wyvern.lib.commands
Class MouseCommand

java.lang.Object
  extended bywyvern.lib.commands.MouseCommand
All Implemented Interfaces:
BuiltInCommand, Command

public class MouseCommand
extends java.lang.Object
implements BuiltInCommand

This is the default handler for mouse commands. It does various semi-intelligent things based on the button & modifiers:

Version:
1.0, May 24, 1998
Author:
Steve Yegge

Method Summary
 void addCommands(java.util.Map commands, CommandList list)
          Construct the command with the specified player.
 boolean attemptExamine(MouseCommandEvent event, Commandable agent)
          Attempts to examine whatever was clicked.
 boolean attemptFire(MouseCommandEvent event, Commandable agent)
          Attempts to "fire" the player's readied object.
 boolean attemptMove(MouseCommandEvent event, Commandable agent)
          Tries to move the player to where they clicked.
 CommandEvent createEvent(CommandEvent initial)
          Implements Command.createEvent()
 CommandEvent createSelectEvent(CommandEvent event)
          Parses the arguments to a ground/inv selection.
 boolean doShiftClick(GameObject obj, Commandable agent)
          Decides what to do with an object on shift-click.
 boolean execute(CommandEvent e)
          Implements Command.execute()
 boolean executeSelect(CommandEvent event)
          Handles a mouse event in the ground/inventory lists.
static MouseCommand getImpl()
           
 GameObject getInvRef(int index, CommandEvent event)
          Returns the object in inventory at the specified index, or null if not found.
 boolean handleGroundDisplay(int index, int mods, java.lang.String button, CommandEvent event)
          Handles mouse-click in ground display.
 boolean handlePopupCommand(int index, java.lang.String display, java.lang.String command, CommandEvent event)
          Handles user choosing a popup menu command for an item on the ground or in inventory.
 boolean knowsCommand(java.lang.String command)
          We don't have any way of determining that we don't know how to handle the command based just on its arguments.
static void main(java.lang.String[] args)
          Prints event modifiers.
 boolean mousebind(CommandEvent event)
          Turns on or off the old-style mouse left-button behavior of dropping or picking up the item.
 void moveOneStep(Point start, Point end, Commandable agent, CommandEvent event)
          This is the old way we handled mouse clicks - the agent would take one step in the direction of the click.
 boolean readyObject(GameObject obj, Commandable agent)
          Readies or unreadies the selected obj.
 void translateModifiers(int mods, CommandEvent event)
          Sets a property in the event called "button", where the value is one of "left", "middle" or "right".
static void translateToPlayer(Point p, Commandable agent)
          Translates a point from a viewport coordinate to a coordinate relative to the passed player.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getImpl

public static MouseCommand getImpl()

addCommands

public void addCommands(java.util.Map commands,
                        CommandList list)
Construct the command with the specified player.

Specified by:
addCommands in interface BuiltInCommand
Parameters:
commands - the map to add commands to
list - the player getting the commands

knowsCommand

public boolean knowsCommand(java.lang.String command)
We don't have any way of determining that we don't know how to handle the command based just on its arguments.

Specified by:
knowsCommand in interface Command
Parameters:
command - the entire command string, including arguments
Returns:
true if we know the command (built-ins always do)

createEvent

public CommandEvent createEvent(CommandEvent initial)
Implements Command.createEvent()

Specified by:
createEvent in interface Command
Parameters:
initial - a "blank" CommandEvent containing only the command text and the agent who's performing the command. This initial event is created by the originator of the event (e.g. the AI or player's command preprocessor).
Returns:
a CommandEvent subclass encapsulating this command's execution parameters and state. It should copy in the fields from the passed-in event.
See Also:
Command.createEvent(wyvern.lib.CommandEvent)

translateToPlayer

public static void translateToPlayer(Point p,
                                     Commandable agent)
Translates a point from a viewport coordinate to a coordinate relative to the passed player.

Parameters:
p - the point to translate
agent - the agent to translate to

createSelectEvent

public CommandEvent createSelectEvent(CommandEvent event)
Parses the arguments to a ground/inv selection.

Parameters:
event - the initial "sel" event

execute

public boolean execute(CommandEvent e)
Implements Command.execute()

Specified by:
execute in interface Command
Parameters:
e - the CommandEvent to execute
Returns:
true if the event completed successfully, else false.
See Also:
Command.execute(wyvern.lib.CommandEvent)

translateModifiers

public void translateModifiers(int mods,
                               CommandEvent event)
Sets a property in the event called "button", where the value is one of "left", "middle" or "right". Adds properties called "shift", "ctrl" and "alt" if the corresponding modifier keys are down.

Parameters:
mods - the java.awt.event.MouseEvent modifiers
event - the event to set the button in (from the modifiers)

executeSelect

public boolean executeSelect(CommandEvent event)
Handles a mouse event in the ground/inventory lists.

Parameters:
event - the event

handleGroundDisplay

public boolean handleGroundDisplay(int index,
                                   int mods,
                                   java.lang.String button,
                                   CommandEvent event)
Handles mouse-click in ground display.

Parameters:
index - the index of the object to examine
mods - the java.awt.event.MouseEvent.getModifiers()
button - "left", "right" or "middle"
event - the event we're executing

getInvRef

public GameObject getInvRef(int index,
                            CommandEvent event)
Returns the object in inventory at the specified index, or null if not found.


doShiftClick

public boolean doShiftClick(GameObject obj,
                            Commandable agent)
Decides what to do with an object on shift-click.


readyObject

public boolean readyObject(GameObject obj,
                           Commandable agent)
Readies or unreadies the selected obj.


handlePopupCommand

public boolean handlePopupCommand(int index,
                                  java.lang.String display,
                                  java.lang.String command,
                                  CommandEvent event)
Handles user choosing a popup menu command for an item on the ground or in inventory.


attemptMove

public boolean attemptMove(MouseCommandEvent event,
                           Commandable agent)
Tries to move the player to where they clicked.

Parameters:
event - the MouseCommandEvent containing the event params
agent - the agent who clicked the mouse

moveOneStep

public void moveOneStep(Point start,
                        Point end,
                        Commandable agent,
                        CommandEvent event)
This is the old way we handled mouse clicks - the agent would take one step in the direction of the click.


attemptExamine

public boolean attemptExamine(MouseCommandEvent event,
                              Commandable agent)
Attempts to examine whatever was clicked.

Parameters:
event - the mouse command event
agent - the agent who clicked the mouse
Returns:
true if we succeeded

attemptFire

public boolean attemptFire(MouseCommandEvent event,
                           Commandable agent)
Attempts to "fire" the player's readied object. This could be a range weapon, a wand, spell, or in fact any Readyable.

Parameters:
event - event
agent - the player
Returns:
true if the event was successful

mousebind

public boolean mousebind(CommandEvent event)
Turns on or off the old-style mouse left-button behavior of dropping or picking up the item.


main

public static void main(java.lang.String[] args)
Prints event modifiers.