JTP
Class Menu

java.lang.Object
  extended by JTP.Menu

public class Menu
extends Object

Defines function and rendering of the menu component.

Author:
V.Termanis

Field Summary
static int EDITOR_BACK
           
static int EDITOR_LOAD
           
static int EDITOR_NEW
           
static int MAIN_EDITOR
           
static int MAIN_EXIT
           
static int MAIN_HELP
           
static int MAIN_HIGHSCORES
           
static int MAIN_ONEP
           
static int MAIN_TWOP
           
static int MENU_CHANGED
           
static int MENU_EDITOR
          Editor submenu
static int MENU_MAIN
          Main menu
static int MENU_MOVED
           
static int MENU_ONEP
          One player submenu
static int MENU_TWOP
          Two player submenu
static int MENU_TWOP_COOP
          Two player cooperative submenu
static int MENU_TWOP_VS
          Two player versus submenu
static int NONE
           
static int ONEP_BACK
           
static int ONEP_CHALLENGE
           
static int ONEP_LOAD
           
static int ONEP_NORMAL
           
static int TWOP_BACK
           
static int TWOP_COOP
           
static int TWOP_COOP_BACK
           
static int TWOP_COOP_CHALLENGE
           
static int TWOP_COOP_LOAD
           
static int TWOP_COOP_NORMAL
           
static int TWOP_VS
           
static int TWOP_VS_ALT
           
static int TWOP_VS_BACK
           
static int TWOP_VS_LOAD
           
static int TWOP_VS_SIM
           
 
Constructor Summary
Menu(ScreenFrames frames, TilePainter tilePainter, int vOffset, int buttonSpacing)
          Constructs a new Menu instance with the given parameters.
 
Method Summary
 int clickResult(Point mouseLocation)
          Determine whether a menu button has been clicked (to be called after mousePressed()
 void drawAll(Graphics2D g)
           
 void drawUpdate(Graphics2D g)
           
 int keyResult(int keyCode)
           
 Rectangle keyUpdateUI()
           
 void mousePressed(int button, Point mouseLocation)
           
 void setEntryIndex(int i)
          Sets which menu entry is highlighted.
protected  void setLastUpdateAsKey()
          Use to make sure pressing a menu button via mouse/keyboard is handled exactly the same after the mouse leaves the screen.
 void setMenu(int menuIndex, int menuEntryIndex)
          Set active menu and entry.
 void setMenu(int menuIndex, Point mousePosition)
          Set active menu and highlight entry currently under mouse pointer.
 Rectangle updateUI(Point mouseLocation)
          Updates state of menu based on current mouse position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MENU_MOVED

public static final int MENU_MOVED
See Also:
Constant Field Values

MENU_CHANGED

public static final int MENU_CHANGED
See Also:
Constant Field Values

NONE

public static final int NONE
See Also:
Constant Field Values

MAIN_ONEP

public static final int MAIN_ONEP
See Also:
Constant Field Values

MAIN_TWOP

public static final int MAIN_TWOP
See Also:
Constant Field Values

MAIN_EDITOR

public static final int MAIN_EDITOR
See Also:
Constant Field Values

MAIN_HIGHSCORES

public static final int MAIN_HIGHSCORES
See Also:
Constant Field Values

MAIN_HELP

public static final int MAIN_HELP
See Also:
Constant Field Values

MAIN_EXIT

public static final int MAIN_EXIT
See Also:
Constant Field Values

ONEP_NORMAL

public static final int ONEP_NORMAL
See Also:
Constant Field Values

ONEP_CHALLENGE

public static final int ONEP_CHALLENGE
See Also:
Constant Field Values

ONEP_LOAD

public static final int ONEP_LOAD
See Also:
Constant Field Values

ONEP_BACK

public static final int ONEP_BACK
See Also:
Constant Field Values

TWOP_COOP

public static final int TWOP_COOP
See Also:
Constant Field Values

TWOP_VS

public static final int TWOP_VS
See Also:
Constant Field Values

TWOP_BACK

public static final int TWOP_BACK
See Also:
Constant Field Values

TWOP_COOP_NORMAL

public static final int TWOP_COOP_NORMAL
See Also:
Constant Field Values

TWOP_COOP_CHALLENGE

public static final int TWOP_COOP_CHALLENGE
See Also:
Constant Field Values

TWOP_COOP_LOAD

public static final int TWOP_COOP_LOAD
See Also:
Constant Field Values

TWOP_COOP_BACK

public static final int TWOP_COOP_BACK
See Also:
Constant Field Values

TWOP_VS_SIM

public static final int TWOP_VS_SIM
See Also:
Constant Field Values

TWOP_VS_ALT

public static final int TWOP_VS_ALT
See Also:
Constant Field Values

TWOP_VS_LOAD

public static final int TWOP_VS_LOAD
See Also:
Constant Field Values

TWOP_VS_BACK

public static final int TWOP_VS_BACK
See Also:
Constant Field Values

EDITOR_NEW

public static final int EDITOR_NEW
See Also:
Constant Field Values

EDITOR_LOAD

public static final int EDITOR_LOAD
See Also:
Constant Field Values

EDITOR_BACK

public static final int EDITOR_BACK
See Also:
Constant Field Values

MENU_MAIN

public static final int MENU_MAIN
Main menu

See Also:
Constant Field Values

MENU_ONEP

public static final int MENU_ONEP
One player submenu

See Also:
Constant Field Values

MENU_TWOP

public static final int MENU_TWOP
Two player submenu

See Also:
Constant Field Values

MENU_TWOP_COOP

public static final int MENU_TWOP_COOP
Two player cooperative submenu

See Also:
Constant Field Values

MENU_TWOP_VS

public static final int MENU_TWOP_VS
Two player versus submenu

See Also:
Constant Field Values

MENU_EDITOR

public static final int MENU_EDITOR
Editor submenu

See Also:
Constant Field Values
Constructor Detail

Menu

public Menu(ScreenFrames frames,
            TilePainter tilePainter,
            int vOffset,
            int buttonSpacing)
Constructs a new Menu instance with the given parameters.

Parameters:
frames - for drawing borders
tilePainter - for drawing individual menu entries
vOffset - vertical padding (from top of screen) for menu
buttonSpacing - space in between buttons (in pixels)
Method Detail

updateUI

public Rectangle updateUI(Point mouseLocation)
Updates state of menu based on current mouse position.

Parameters:
mouseLocation - current mouse position
Returns:
clipping rectangle for updating screen ir null if nothing has to be updated.

setLastUpdateAsKey

protected void setLastUpdateAsKey()
Use to make sure pressing a menu button via mouse/keyboard is handled exactly the same after the mouse leaves the screen.


clickResult

public int clickResult(Point mouseLocation)
Determine whether a menu button has been clicked (to be called after mousePressed()


mousePressed

public void mousePressed(int button,
                         Point mouseLocation)

keyResult

public int keyResult(int keyCode)

keyUpdateUI

public Rectangle keyUpdateUI()

drawUpdate

public void drawUpdate(Graphics2D g)

drawAll

public void drawAll(Graphics2D g)

setMenu

public void setMenu(int menuIndex,
                    Point mousePosition)
             throws IllegalArgumentException
Set active menu and highlight entry currently under mouse pointer.

Parameters:
menuIndex - submenu to switch to
mousePosition - current absolute mouse position
Throws:
IllegalArgumentException

setMenu

public void setMenu(int menuIndex,
                    int menuEntryIndex)
             throws IllegalArgumentException
Set active menu and entry.

Parameters:
menuIndex - submenu to switch to
menuEntryIndex - which option to highlight (choose NONE if highlighting not desired at start)
Throws:
IllegalArgumentException

setEntryIndex

public void setEntryIndex(int i)
                   throws IllegalArgumentException
Sets which menu entry is highlighted.

Parameters:
i - of the menu entry to highlight
Throws:
IllegalArgumentException - if i is outside the range of valid menu entries for the currently active menu.