T
- The type of colors.public abstract class ButtonsPanel<T extends com.badlogic.gdx.graphics.Color> extends GroupCombinedPanel<T>
styles
.this
(if you want the handler to be called from the enclosing
Stage
).configured
, the handler also handles
key shortcuts. In that case this panel highlights the shortcuts in text
automatically.selectedButton(int)
.
The panel is configured via its public
fields. Configuration must
happen in-between creation and the call to putAll(boolean, boolean)
.
This class has two different behaviors w.r.t to the backing panels. They can
either be given at creation time or they can be created on the fly. If you're
doing a full screen menu, you should likely give the panels at creation time
(because you'll compute theirs sizes so that they fit the whole screen). If
you're doing an in-game menu, that is quickly dispatched, you should likely
let this class create the panels (it'll create panels as small as possible,
yet that suffice to display the buttons correctly). There is a dedicated
subtype for the first usage: ButtonsPanel.PreAllocatedPanels
.
Here's a full screen example of this class:
and this shows a non-full screen example (the Drink/Throw/Drop menu):
Modifier and Type | Class and Description |
---|---|
protected static class |
ButtonsPanel.FirstAndLastButtonIndex |
static class |
ButtonsPanel.PreAllocatedPanels<T extends com.badlogic.gdx.graphics.Color>
A convenience subclass for people that give preallocated
ISquidPanel s. |
protected static class |
ButtonsPanel.Rectangle |
Modifier and Type | Field and Description |
---|---|
T |
bgColor
The color to use to paint the background (outside buttons).
|
T |
borderColor
The color for the border around the whole panel, or
null to
disable painting. |
int |
borderMargin
The margin to use around the whole panel, in number of pixels.
|
UIUtil.CornerStyle |
borderStyle
The style of borders, around the panel.
|
int |
buttonMargin
The margin to show around each button, in number of pixels.
|
protected List<ButtonsPanel.Rectangle> |
buttons
The positions of buttons, set by
putAll(boolean, boolean) |
int[] |
buttonsAlignment
The alignment of buttons, -1 for left, 0 for center, 1 for right.
|
T |
buttonsMarginColor
The color for the margin around buttons, or
null to disable
painting. |
protected List<squidpony.panel.IColoredString<T>> |
buttonsTexts
Really, if you're muting this beyond
init(List) , you're doing
bad. |
UIUtil.CornerStyle |
cornerStyle
The style to use for the buttons' corners.
|
Set<Integer> |
doNotBind
Indexes of buttons that should not receive a shortcut, neither click
events.
|
boolean |
enableScrolling
Whether this panel supports scrolling.
|
protected ButtonsPanel.FirstAndLastButtonIndex |
firstLastButtonIndexes
The indexes of buttons displayed.
|
protected int |
hcells |
T |
insideButtonBGColor
The color to use to paint the background of the inside of buttons, or
null to disable painting. |
int |
interButtonMargin
The margin, in number of cells, in-between buttons.
|
String |
scrollText
The text of the buttons to scroll
|
T |
shortcutCharacterColor
The color to use to highlight shortcuts of buttons.
|
protected Map<Character,Integer> |
shortcuts
The shortcuts to select the buttons.
|
Set<Character> |
unbindable
If non-
null , this will avoid characters in this set to
bind keyboard presses to buttons. |
protected int |
vcells |
int |
xpadding
The x-padding in-between a button's text and its margin, in number of
cells.
|
int |
ypadding
The y-padding in-between a button's text and its margin, in number of
cells.
|
bg, fg
Constructor and Description |
---|
ButtonsPanel(squidpony.panel.ISquidPanel<T> bg,
squidpony.panel.ISquidPanel<T> fg,
List<squidpony.panel.IColoredString<T>> buttonTexts)
If you use this constructor, you can use
ButtonsPanel.PreAllocatedPanels to
avoid having to define buildPanel(int, int) . |
ButtonsPanel(List<squidpony.panel.IColoredString<T>> buttonTexts)
Constructor to use when you want the panels to be build using
buildPanel(int, int) . |
Modifier and Type | Method and Description |
---|---|
void |
addDoNotBind(int i)
Adds
i to the set of button indexes that should not be bound to
user input. |
protected com.badlogic.gdx.InputProcessor |
buildKeyInputProcessor() |
protected com.badlogic.gdx.InputProcessor |
buildMouseInputProcessor() |
protected abstract squidpony.panel.ISquidPanel<T> |
buildPanel(int width,
int height)
This method can be left unimplemented if you give the panels at
construction time (constructor
ButtonsPanel(ISquidPanel, ISquidPanel, List) . |
protected boolean |
canBeShortcut(char c) |
protected void |
displayMarginsAround(int botLeftX,
int botLeftY,
int width,
int height) |
int |
getHCells()
This method should only be called after
putAll(boolean, boolean)
. |
int |
getVCells()
This method should only be called after
putAll(boolean, boolean)
. |
protected boolean |
hasScrollDown() |
protected boolean |
hasScrollUp() |
ButtonsPanel<T> |
init(List<squidpony.panel.IColoredString<T>> buttonTexts)
Sets the buttons' text.
|
protected int |
pixelsHeight() |
protected int |
pixelsWidth() |
com.badlogic.gdx.InputProcessor |
putAll(boolean addListener,
boolean putBordersAndMargins)
Displays this panel.
|
protected void |
putBorder()
Paints the border
|
protected void |
putButtonInside(int xoff,
int yoff,
int width,
int height)
Method that paint's the background of a button's inside.
|
void |
putButtonsMarginsAndBorder()
Draws the margins around the buttons and the border around the panel.
|
protected void |
putHook()
Callback done when
this is reput, because of a scrolling request |
protected squidpony.panel.IColoredString<T> |
putShortcut(int buttonIndex,
squidpony.panel.IColoredString<T> text) |
protected boolean |
scrollDown(int keycode) |
protected int |
scrollDownButtonIndex() |
protected boolean |
scrollUp(int keycode) |
protected abstract void |
selectedButton(int i)
This method is called when the button at index
i is hit. |
protected boolean |
y_gdxToSquid()
smelC: when I plug
putAll(boolean, boolean) result directly into
Gdx.input (i.e. |
addActors, cellHeight, cellWidth, checkBG, checkFG, fill, getGridHeight, getGridWidth, hasActiveAnimations, put, put, put, putBG, putBottomLeft, putBottomRight, putFG, putFG, putFG, putFG, setColorCenter, setPanels, toString
act, addActor, addActorAfter, addActorAt, addActorBefore, applyTransform, applyTransform, childrenChanged, clear, clearChildren, computeTransform, debugAll, draw, drawChildren, drawDebug, drawDebugChildren, findActor, getChildren, getCullingArea, hasChildren, hit, isTransform, localToDescendantCoordinates, removeActor, removeActor, resetTransform, resetTransform, setCullingArea, setDebug, setStage, setTransform, swapActor, swapActor
addAction, addCaptureListener, addListener, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, debug, drawDebugBounds, fire, getActions, getCaptureListeners, getColor, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasActions, hasParent, isAscendantOf, isDescendantOf, isTouchable, isVisible, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, positionChanged, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, screenToLocalCoordinates, setBounds, setColor, setColor, setDebug, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setParent, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setWidth, setX, setY, setZIndex, sizeBy, sizeBy, sizeChanged, stageToLocalCoordinates, toBack, toFront
public int interButtonMargin
0
, this
will layout like:
button1 longer button button2If set to
1
, this
will layout like:
button1 longer button button2
public int borderMargin
As an example, this margin is in dark red in the Drink/Throw/Drop menu
in:
small example
public int xpadding
0
, this
will layout each button
like:
--------- |button1| --------If set to
2
, this
will layout like:
------------- | button1 | -------------
public int ypadding
0
, this
will layout each button
like:
--------- |button1| --------If set to
1
, this
will layout like:
------------- | | | button1 | | | -------------
public int buttonMargin
public UIUtil.CornerStyle cornerStyle
null
.public T extends com.badlogic.gdx.graphics.Color bgColor
null
to disable background coloring.public T extends com.badlogic.gdx.graphics.Color insideButtonBGColor
null
to disable painting.public T extends com.badlogic.gdx.graphics.Color buttonsMarginColor
null
to disable
painting.public T extends com.badlogic.gdx.graphics.Color borderColor
null
to
disable painting.public T extends com.badlogic.gdx.graphics.Color shortcutCharacterColor
null
to
disable shortcuts.public UIUtil.CornerStyle borderStyle
null
.public int[] buttonsAlignment
null
, this array's length must be the number of buttons.
The default is center.
public Set<Integer> doNotBind
shortcutCharacterColor
is null
.public Set<Character> unbindable
null
, this
will avoid characters in this set to
bind keyboard presses to buttons. Note that this class already rules out
characters that aren't Character.isLetter(char)
, so you don't
need it to fill this set with characters such as '#', '/', etc; but you
need to put 'é', 'à', etc. if you want to rule out "complex" letters.public boolean enableScrolling
buttonsTexts
. This is only supported if
interButtonMargin
is 0. This makes the InputProcessor
returned by putAll(boolean, boolean)
handle scrolling with arrow
down/arrow up/j/k ( the last two coming from vim) and with mouse clicks
on '...'. Don't use that if your panel isn't at least of height 3 (i.e.
supports:
... item_n ...)
This flag require SquidPanel
s to be preallocated (i.e. to be
given at creation time).
public String scrollText
protected List<squidpony.panel.IColoredString<T extends com.badlogic.gdx.graphics.Color>> buttonsTexts
init(List)
, you're doing
bad.protected List<ButtonsPanel.Rectangle> buttons
putAll(boolean, boolean)
protected Map<Character,Integer> shortcuts
buttonsTexts
. Or
null
if shortcuts are disabled.
Initialized and filled in putShortcut(int, IColoredString)
.
protected int hcells
protected int vcells
protected ButtonsPanel.FirstAndLastButtonIndex firstLastButtonIndexes
buttonsTexts
, if
scrolling is possible.public ButtonsPanel(squidpony.panel.ISquidPanel<T> bg, squidpony.panel.ISquidPanel<T> fg, List<squidpony.panel.IColoredString<T>> buttonTexts)
ButtonsPanel.PreAllocatedPanels
to
avoid having to define buildPanel(int, int)
.bg
- The backing background panel.fg
- The backing foreground panel.buttonTexts
- The text of buttons. It should not contain end of lines
(beware that this isn't checked). If null
, it MUST be
set later on with init(List)
.IllegalStateException
- In various cases of errors regarding sizes of panels.public ButtonsPanel(List<squidpony.panel.IColoredString<T>> buttonTexts)
buildPanel(int, int)
.buttonTexts
- The text of buttons. It should not contain end of lines
(beware that this isn't checked). If null
, it MUST be
set later on with init(List)
.IllegalStateException
- In various cases of errors regarding sizes of panels.public ButtonsPanel<T> init(List<squidpony.panel.IColoredString<T>> buttonTexts)
null
at
creation time. Beware that this method can be called from the
constructor.buttonTexts
- this
public void addDoNotBind(int i)
i
to the set of button indexes that should not be bound to
user input.i
- public com.badlogic.gdx.InputProcessor putAll(boolean addListener, boolean putBordersAndMargins)
putBordersAndMargins
- Whether to draw margins and the border. This should be
true
if this
's position (I mean, in terms of
Actor.setPosition(float, float)
) is set already. If that's
not the case (for example, because you need this method to be
called to compute the position from getHCells()
and
getVCells()
), give false
.InputProcessor
to plug if you want
selectedButton(int)
to be called.
See y_gdxToSquid()
to configure the processor's
behavior.
If this panel is behind a Stage
(i.e. you're not setting
the returned processor to Gdx.input
) and you want it to
receive keyboard events, don't forget to call
Stage.setKeyboardFocus(Actor)
by giving this
.
NullPointerException
- If the text of buttons wasn't given at creation time, and
init(List)
wasn't called since then.IllegalStateException
- If enableScrolling
is ON but GroupCombinedPanel.bg
isn't set.public void putButtonsMarginsAndBorder()
ShapeRenderer
, margins do not move if
this
is moved (such as with
Actions.moveTo(float, float, float)
). This method's purpose is to
draw margins in such a case.
Remember that, when using SquidPanel
s; margins (more generally:
anything done with ShapeRenderer
) should always be drawn after
everything else, so when sliding/moving, your code should be like:
stage.act() <- if the panel is moving
stage.draw(); <- of course, 'stage' is the Stage containing this
buttonsPanel.putMarginsAndBorder();
public int getHCells()
putAll(boolean, boolean)
.this
spans,
horizontally. Ignores margins, but not padding.IllegalStateException
- If putAll(boolean, boolean)
wasn't called yet.public int getVCells()
putAll(boolean, boolean)
.this
spans,
vertically. Ignores margins, but not padding.IllegalStateException
- If putAll(boolean, boolean)
wasn't called yet.protected com.badlogic.gdx.InputProcessor buildMouseInputProcessor()
protected com.badlogic.gdx.InputProcessor buildKeyInputProcessor()
protected abstract squidpony.panel.ISquidPanel<T> buildPanel(int width, int height)
ButtonsPanel(ISquidPanel, ISquidPanel, List)
.width
- The width that the panel must have.height
- The height that the panel must have.ISquidPanel
.protected abstract void selectedButton(int i)
i
is hit.i
- The index of a button (starts at 0).protected boolean y_gdxToSquid()
putAll(boolean, boolean)
result directly into
Gdx.input
(i.e. when I give false
as the first argument
to putAll
), I leave this definition. When I give putAll
true
, and the listener is plugged behind a Stage
, I
redefine this method to return true
.true
if the y-coordinate must be translated from libgdx
coordinates (0,0) at bottom left to squid coordinates (0,0) at
top left.protected void displayMarginsAround(int botLeftX, int botLeftY, int width, int height)
botLeftX
- The bottom left x cell of the button's inside, in squidlib's
coordinates ((0,0) is top left).botLeftY
- The bottom left y cell of the button's inside, in squidlib's
coordinates ((0,0) is top left).width
- The width of the button considered.height
- The width of the button considered.protected int pixelsWidth()
protected int pixelsHeight()
protected void putButtonInside(int xoff, int yoff, int width, int height)
xoff
- The x offsetyoff
- The y offsetwidth
- The inside's widthheight
- The inside's heightprotected void putBorder()
protected squidpony.panel.IColoredString<T> putShortcut(int buttonIndex, squidpony.panel.IColoredString<T> text)
buttonIndex
- The index of the button for which the text is being built.text
- protected void putHook()
this
is reput, because of a scrolling requestprotected boolean scrollDown(int keycode)
keycode
- protected boolean scrollUp(int keycode)
protected int scrollDownButtonIndex()
protected boolean hasScrollUp()
protected boolean hasScrollDown()
protected boolean canBeShortcut(char c)
Copyright © 2012–2016. All rights reserved.