Package com.starpoints.painter
Class PainterMenu
- java.lang.Object
-
- com.starpoints.painter.PainterBase
-
- com.starpoints.painter.PainterMenu
-
- All Implemented Interfaces:
InputController
,Painter
- Direct Known Subclasses:
PainterConfirmMenu
,PainterEditorMenu
,PainterEditorProps
,PainterGameMenu
,PainterGraphicSoundOptions
,PainterKeyboardOptions
,PainterLeagueBoard
,PainterLeagueOptions
,PainterLeaguePlayers
,PainterLevelSetsMenu
,PainterMainMenu
,PainterMenuHorizontal
,PainterNetworkMenu
,PainterOptions
,PainterSavedGamesMenu
,PainterShop
,PainterSkinSelection
,PainterTabbedMenu
public class PainterMenu extends PainterBase implements InputController
Painter for menu. Allows to add clickable and selectable Menu entries.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
active
Flag, if explicitely made acitve.protected java.lang.String
button
protected java.lang.String
button_clicked
protected int[]
buttonCounter
protected static java.lang.String
buttonLeft
Left scroll button.protected static java.lang.String
buttonRight
Right scroll button.protected java.util.Map<java.lang.Integer,MenuEntry>
entries
Map of menu entries.protected boolean
finished
Flag, if finished with entering.protected boolean
firstTimeOpt
Flag, if finished with entering.protected boolean
hideBackground
Flag, if background image should be shown.protected java.lang.String
image
Background image.protected java.util.List<MenuListener>
listeners
List of menu listenersprotected java.lang.String[]
numberEntries
Typical number entries.protected int[]
numbers
Typical numbers corresponding to the number entries.protected int
paintCount
Paint counter for cursor.protected boolean
showButtons
-
Fields inherited from class com.starpoints.painter.PainterBase
area, areas, bigFont, controller, gameInfo, medFont, mouseArea, offset, oldMouseArea, options, smallFont, state, verysmallFont, xfactor, yfactor
-
-
Constructor Summary
Constructors Constructor Description PainterMenu()
Creates a new menu painter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMenuEntry(MenuEntry me)
Adds a menu entry.void
addMenuListener(MenuListener listener)
Adds a menu listener.protected void
draw(Graphics g, java.lang.String s, int indent, int yPosition, int c, Font f, int offset)
Draws a string on a virtual 20*25 coordinate system.protected void
drawBackgroundImage(Graphics g)
Draws the background image.protected int
findIntegerIndex(int i, int[] numbers)
Finds the index of i in numbers.protected int
findIntegerIndex(int i, java.lang.String[] numbers)
Finds the index of i in numbers.protected void
fireEmptyClickEvent()
Fires a empty click event.protected void
fireMenuEntryMouseOverEvent(MenuEntry me)
Fires a menu entry mouse over event.protected void
fireMenuEntrySelectedEvent(MenuEntry me)
Fires a menu entry selected event.protected void
fireMenuEntrySelectionChangedEvent(SelectionMenuEntry me)
Fires a menu entry selection change event.protected void
focusFirst()
Focusses the first menu entry.protected double
getButtonScalingFactor(MenuEntry me)
Gets the scaling factor for the button image.protected int
getButtonXPos(MenuEntry me)
Gets the x center position for the button image.protected int
getButtonYPos(MenuEntry me)
Gets the y center position for the button image.protected MenuEntry
getFocussedEntry()
Gets the MenuEntry currently focussed.protected Font
getFontSize(MenuEntry me)
Gets the font for the menu entries fontsize.protected int
getLeftMouseBorder(MenuEntry me)
Gets the minimum mouse position to hit a menu entry.protected int
getRightMouseBorder(MenuEntry me)
Gets the maximum mouse position to hit a menu entry.boolean
handleEvent(int mouseMask)
Handles mouse clicksboolean
isActive()
Checks, if this painter is currently active and wants to handle events.protected boolean
isDownKey(KeyEvent e)
Checks if the key event is a down key.protected boolean
isEnterKey(KeyEvent e)
Checks if the key event is a enter key.boolean
isFinished()
Checks, if this menu has finsihed.protected boolean
isLeftKey(KeyEvent e)
Checks if the key event is a left key.protected boolean
isRightKey(KeyEvent e)
Checks if the key event is a right key.boolean
isShowingButtons()
protected boolean
isUpKey(KeyEvent e)
Checks if the key event is a up key.boolean
keyPressed(KeyEvent e)
Processes keys in menu.boolean
mouseClicked(MouseEvent e)
Handles mouse clicksboolean
mouseMoved(MouseEvent e)
Handles mouse moves.void
paint(Graphics g, GameState state)
Paints the menu.protected void
paintMenuEntry(Graphics g, MenuEntry me)
Paints a menu entry.void
removeMenuEntry(MenuEntry me)
Removes a menu entry.void
removeMenuListener(MenuListener listener)
Removes a menu listener.void
setActive(boolean active)
Sets the keyboard active or inactive.void
setFinished(boolean finished)
Sets this menu finished.protected void
setMouseArea(MouseEvent e)
Sets the current mouse over area.void
setShowButtons(boolean showButtons)
-
Methods inherited from class com.starpoints.painter.PainterBase
draw, drawShaded, drawShaded, getArea, getBaseHeight, getBaseWidth, getEditor, getHeight, getIndent, getRepaintFactor, getWidth, getXFactor, getYFactor, isInputController, onStartGame, setArea, setController, setFontSize, setLevel, setOptions, setState
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.starpoints.event.InputController
getArea, getXFactor, getYFactor, setController
-
-
-
-
Field Detail
-
numberEntries
protected java.lang.String[] numberEntries
Typical number entries.
-
numbers
protected int[] numbers
Typical numbers corresponding to the number entries.
-
buttonLeft
protected static java.lang.String buttonLeft
Left scroll button.
-
buttonRight
protected static java.lang.String buttonRight
Right scroll button.
-
image
protected java.lang.String image
Background image.
-
hideBackground
protected boolean hideBackground
Flag, if background image should be shown.
-
paintCount
protected int paintCount
Paint counter for cursor.
-
finished
protected boolean finished
Flag, if finished with entering.
-
firstTimeOpt
protected boolean firstTimeOpt
Flag, if finished with entering.
-
listeners
protected java.util.List<MenuListener> listeners
List of menu listeners
-
entries
protected java.util.Map<java.lang.Integer,MenuEntry> entries
Map of menu entries.
-
active
protected boolean active
Flag, if explicitely made acitve.
-
buttonCounter
protected int[] buttonCounter
-
button
protected java.lang.String button
-
button_clicked
protected java.lang.String button_clicked
-
showButtons
protected boolean showButtons
-
-
Method Detail
-
paint
public void paint(Graphics g, GameState state)
Paints the menu.- Specified by:
paint
in interfacePainter
- Specified by:
paint
in classPainterBase
- Parameters:
g
- The graphics.state
- The game state.
-
paintMenuEntry
protected void paintMenuEntry(Graphics g, MenuEntry me)
Paints a menu entry.- Parameters:
g
- The graphics.me
- The menu entry.
-
draw
protected void draw(Graphics g, java.lang.String s, int indent, int yPosition, int c, Font f, int offset)
Draws a string on a virtual 20*25 coordinate system.- Parameters:
g
- The Graphics to draw on.s
- The string.indent
- The x indent.yPosition
- The y Position.c
- The color.f
- The Font.
-
getButtonScalingFactor
protected double getButtonScalingFactor(MenuEntry me)
Gets the scaling factor for the button image.- Parameters:
me
- The MenuEntry.- Returns:
- The scaling factor.
-
getButtonXPos
protected int getButtonXPos(MenuEntry me)
Gets the x center position for the button image.- Parameters:
me
- The MenuEntry.- Returns:
- 0.62.
-
getButtonYPos
protected int getButtonYPos(MenuEntry me)
Gets the y center position for the button image.- Parameters:
me
- The MenuEntry.- Returns:
-
getFontSize
protected Font getFontSize(MenuEntry me)
Gets the font for the menu entries fontsize.- Parameters:
me
- The menu entry.- Returns:
- The font.
-
drawBackgroundImage
protected void drawBackgroundImage(Graphics g)
Draws the background image.- Parameters:
g
- The graphics.
-
keyPressed
public boolean keyPressed(KeyEvent e)
Processes keys in menu.- Specified by:
keyPressed
in interfaceInputController
- Parameters:
e
- The event.- Returns:
- true, if the event is handled by this InputController.
-
isDownKey
protected boolean isDownKey(KeyEvent e)
Checks if the key event is a down key.- Parameters:
e
- The event.- Returns:
- true, if code is VK_DOWN or "s" is pressed.
-
isUpKey
protected boolean isUpKey(KeyEvent e)
Checks if the key event is a up key.- Parameters:
e
- The event.- Returns:
- true, if code is VK_UP or "w" is pressed.
-
isLeftKey
protected boolean isLeftKey(KeyEvent e)
Checks if the key event is a left key.- Parameters:
e
- The event.- Returns:
- true, if code is VK_LEFT or "a" is pressed.
-
isRightKey
protected boolean isRightKey(KeyEvent e)
Checks if the key event is a right key.- Parameters:
e
- The event.- Returns:
- true, if code is VK_RIGHT or "d" is pressed.
-
isEnterKey
protected boolean isEnterKey(KeyEvent e)
Checks if the key event is a enter key.- Parameters:
e
- The event.- Returns:
- true, if code is VK_ENTER, VK_SPACE or "r" is pressed.
-
mouseClicked
public boolean mouseClicked(MouseEvent e)
Handles mouse clicks- Specified by:
mouseClicked
in interfaceInputController
- Parameters:
e
- The event.- Returns:
- true, if the event is handled by this InputController.
-
mouseMoved
public boolean mouseMoved(MouseEvent e)
Handles mouse moves.- Specified by:
mouseMoved
in interfaceInputController
- Parameters:
e
- The event.- Returns:
- true, if the event is handled by this InputController.
-
setMouseArea
protected void setMouseArea(MouseEvent e)
Sets the current mouse over area.- Parameters:
e
- The mouse event.
-
getRightMouseBorder
protected int getRightMouseBorder(MenuEntry me)
Gets the maximum mouse position to hit a menu entry.- Parameters:
me
-- Returns:
-
getLeftMouseBorder
protected int getLeftMouseBorder(MenuEntry me)
Gets the minimum mouse position to hit a menu entry.- Parameters:
me
-- Returns:
-
getFocussedEntry
protected MenuEntry getFocussedEntry()
Gets the MenuEntry currently focussed.- Returns:
- The MenuEntry.
-
handleEvent
public boolean handleEvent(int mouseMask)
Handles mouse clicks- Parameters:
mouseMask
- The MouseMask.- Returns:
- true, if a menu entry was klicked.
-
focusFirst
protected void focusFirst()
Focusses the first menu entry.
-
setFinished
public void setFinished(boolean finished)
Sets this menu finished.- Parameters:
finished
- the finished to set
-
addMenuEntry
public void addMenuEntry(MenuEntry me)
Adds a menu entry.- Parameters:
me
- The entry.
-
removeMenuEntry
public void removeMenuEntry(MenuEntry me)
Removes a menu entry.- Parameters:
me
- The entry.
-
addMenuListener
public void addMenuListener(MenuListener listener)
Adds a menu listener.- Parameters:
listener
- The listener.
-
removeMenuListener
public void removeMenuListener(MenuListener listener)
Removes a menu listener.- Parameters:
listener
- The listener.
-
fireMenuEntrySelectedEvent
protected void fireMenuEntrySelectedEvent(MenuEntry me)
Fires a menu entry selected event.- Parameters:
me
- The menu entry.
-
fireMenuEntryMouseOverEvent
protected void fireMenuEntryMouseOverEvent(MenuEntry me)
Fires a menu entry mouse over event.- Parameters:
me
- The menu entry.
-
fireMenuEntrySelectionChangedEvent
protected void fireMenuEntrySelectionChangedEvent(SelectionMenuEntry me)
Fires a menu entry selection change event.- Parameters:
me
- The menu entry.
-
fireEmptyClickEvent
protected void fireEmptyClickEvent()
Fires a empty click event.
-
isFinished
public boolean isFinished()
Checks, if this menu has finsihed.- Returns:
- true, if finished.
-
isActive
public boolean isActive()
Checks, if this painter is currently active and wants to handle events.- Specified by:
isActive
in interfacePainter
- Overrides:
isActive
in classPainterBase
- Returns:
- true, if no keyboard is supported.
-
setActive
public void setActive(boolean active)
Sets the keyboard active or inactive.- Parameters:
active
- true to set active.
-
findIntegerIndex
protected int findIntegerIndex(int i, java.lang.String[] numbers)
Finds the index of i in numbers. If i is not contained, the index of the next higher number is returned- Parameters:
i
- The int to search.numbers
- A sorted array of int strings.- Returns:
- The index.
-
findIntegerIndex
protected int findIntegerIndex(int i, int[] numbers)
Finds the index of i in numbers. If i is not contained, the index of the next higher number is returned- Parameters:
i
- The int to search.numbers
- A sorted array of int strings.- Returns:
- The index.
-
isShowingButtons
public boolean isShowingButtons()
- Returns:
- the showButtons
-
setShowButtons
public void setShowButtons(boolean showButtons)
- Parameters:
showButtons
- the showButtons to set
-
-