public class MapWidget extends Object implements MapDisplayEvents
Modifier and Type | Field and Description |
---|---|
protected MapDisplay |
display |
protected MapDisplay.Layer |
layer |
protected MapWidget |
parent |
protected MapWidgetRoot |
root |
protected MapCanvas |
view |
Constructor and Description |
---|
MapWidget() |
Modifier and Type | Method and Description |
---|---|
void |
activate()
Activates this widget, but only when the widget is enabled.
|
<T extends MapWidget> |
addWidget(T widget)
Adds a new child widget to this widget
|
MapWidget |
clear()
Removes all the displayed contents of this widget
|
void |
clearWidgets()
Removes all previously added widgets
|
void |
deactivate()
If this widget or a child thereof is activated, this method de-activates that widget.
|
void |
focus()
Gives this widget the focus.
|
int |
getAbsoluteX()
Gets the x-position of this widget as drawn onto the map display
|
int |
getAbsoluteY()
Gets the y-position of this widget as drawn onto the map display
|
MapDisplay |
getDisplay()
Gets the map display this widget is attached to.
|
int |
getHeight()
Gets the height of this widget
|
MapWidget |
getNextInputWidget()
Gets the child widget to which keyboard/mouse input and events are redirected
|
MapWidget |
getParent()
Gets the parent node of this widget
|
MapWidget |
getWidget(int index)
Gets a widget stored at a particular index in the list of child widgets.
|
int |
getWidgetCount()
Gets the number of child widgets
|
List<MapWidget> |
getWidgets()
Gets an immutable list of children of this widget.
|
int |
getWidth()
Gets the width of this widget
|
int |
getX()
Gets the x-position of this widget relative to the parent
|
int |
getY()
Gets the y-position of this widget relative to the parent
|
protected void |
handleNavigation(MapKeyEvent event)
Handles key navigation of the widgets, changing which widgets are focused and activated.
|
void |
invalidate()
Invalidates the widget, causing it to be redrawn in the future
|
boolean |
isActivated()
Gets whether this widget has been activated.
|
boolean |
isEnabled()
Gets whether this widget is currently enabled using
#setEnabled(enabled) . |
boolean |
isFocusable()
Gets whether or not it is possible for this widget to be focused
|
boolean |
isFocused()
Gets whether this widget currently has focus.
|
boolean |
isNavigableFocus()
Gets whether this map widget is a potential widget that can be focused
by navigating using W/A/S/D.
|
boolean |
isVisible()
Gets whether this widget is visible
|
protected MapWidget |
navigateNextWidget(List<MapWidget> widgets,
MapPlayerInput.Key key)
Selects the next widget to give focus to after receiving player input to navigate around.
|
void |
onActivate()
Called right after the user presses spacebar to 'enter' this widget.
|
void |
onAttached()
Called when the widget is attached to a map display
|
void |
onBlur()
Called right before this item loses the focus
|
void |
onBoundsChanged()
Called when the bounding box area of this widget was changed
|
void |
onDeactivate()
Called right before a new widget becomes activated when this widget was previously
activated.
|
void |
onDetached()
Called when a widget is removed from a map display
|
void |
onDraw()
Called when the widget should be re-drawn onto the map display.
|
void |
onFocus()
Called right after this item is focused using W/A/S/D navigation controls
|
void |
onKey(MapKeyEvent event)
Callback function called every tick while a key is pressed down.
|
void |
onKeyPressed(MapKeyEvent event)
Callback function called when a key changed from not-pressed to pressed down
These callbacks are called before
MapDisplayEvents.onTick() . |
void |
onKeyReleased(MapKeyEvent event)
Callback function called when a key changed from pressed to not pressed down
These callbacks are called before
MapDisplayEvents.onTick() . |
void |
onLeftClick(MapClickEvent event)
Callback function called when a player left-clicks the map held in an item frame
showing this Map Display.
|
void |
onMapItemChanged()
Callback function called when the map item of this Map Display changed
|
void |
onRightClick(MapClickEvent event)
Callback function called when a player right-clicks the map held in an item frame
showing this Map Display.
|
void |
onStatusChanged(MapStatusEvent event)
Callback function called when a widget in the map display wishes to broadcast
a status change.
|
void |
onTick()
Called every tick to refresh this widget.
|
void |
performTickUpdates()
|
void |
removeWidget()
Removes this widget from its parent.
|
boolean |
removeWidget(MapWidget widget)
Removes a child widget from this widget.
|
void |
sendStatusChange(MapEventPropagation propagationMode,
String name)
Sends a status change to all widgets, the propagation mode defining who receives the status change
and in what order.
|
void |
sendStatusChange(MapEventPropagation propagationMode,
String name,
Object argument)
Sends a status change to all widgets, the propagation mode defining who receives the status change
and in what order.
|
void |
sendStatusChange(String name)
Broadcasts a status change to all widgets of the display this widget is attached to
|
void |
sendStatusChange(String name,
Object argument)
Broadcasts a status change to all widgets of the display this widget is attached to
|
MapWidget |
setBounds(int x,
int y,
int width,
int height)
Changes the bounds of this widget
|
void |
setDepthOffset(int z)
Changes the depth offset of this widget relative to the parent.
|
MapWidget |
setEnabled(boolean enabled)
Sets whether this widget is currently enabled.
|
void |
setFocusable(boolean focusable)
Sets whether or not it is possible for this widget to be focused
|
MapWidget |
setPosition(int x,
int y)
Changes the position of this widget relative to the parent
|
MapWidget |
setRetainChildWidgets(boolean retain)
Sets whether child widgets are retained when this widget is removed from a parent.
|
MapWidget |
setSize(Dimension dimension)
Changes the size of this widget
|
MapWidget |
setSize(int width,
int height)
Changes the size of this widget
|
MapWidget |
setVisible(boolean visible)
Sets whether this widget is visible
|
<T extends MapWidget> |
swapWidget(MapWidget oldWidget,
T newWidget)
Replaces a widget with a new widget at the exact same index.
|
protected MapWidgetRoot root
protected MapWidget parent
protected MapDisplay display
protected MapDisplay.Layer layer
protected MapCanvas view
public void onAttached()
onAttached
in interface MapDisplayEvents
public void onDetached()
onDetached
in interface MapDisplayEvents
public void onActivate()
setFocusable(boolean)
is set to true.
By default this function will activate and enter the element, allowing input
to be handled by this widget. By overriding this base functionality can be disabled.public void onDeactivate()
onActivate()
is called.public void onFocus()
public void onBlur()
public void onTick()
#update()
automatically calls onDraw() when the widget is invalidated.onTick
in interface Tickable
onTick
in interface MapDisplayEvents
public void onDraw()
public void onBoundsChanged()
public final MapWidget getParent()
public final MapWidget getNextInputWidget()
public final void setDepthOffset(int z)
z
- depth offsetpublic final int getX()
public final int getY()
public final int getWidth()
public final int getHeight()
public final int getAbsoluteX()
public final int getAbsoluteY()
public final MapDisplay getDisplay()
public final boolean isVisible()
public final MapWidget setVisible(boolean visible)
visible
- public final boolean isFocusable()
public final void setFocusable(boolean focusable)
focusable
- to set topublic final boolean isFocused()
public final void focus()
public final boolean isActivated()
public final void activate()
onActivate()
directly.public final void deactivate()
public final boolean isNavigableFocus()
isFocusable()
this always returns false.public final boolean isEnabled()
#setEnabled(enabled)
.
If the parent of this widget is not enabled, this method returns false as well.public final MapWidget setEnabled(boolean enabled)
isEnabled()
will continue to return false.enabled
- public final List<MapWidget> getWidgets()
public final MapWidget getWidget(int index)
index
- public final int getWidgetCount()
public final void removeWidget()
widget.getParent().removeWidget(widget);
public void clearWidgets()
public final <T extends MapWidget> T addWidget(T widget)
widget
- to addpublic final <T extends MapWidget> T swapWidget(MapWidget oldWidget, T newWidget)
oldWidget
- to replacenewWidget
- to replace oldWidget withpublic final boolean removeWidget(MapWidget widget)
child
- to removepublic final MapWidget clear()
public final void invalidate()
public final MapWidget setRetainChildWidgets(boolean retain)
retain
- whether to retain the widgetspublic final void sendStatusChange(String name)
name
- of the status changepublic final void sendStatusChange(String name, Object argument)
name
- of the status changeargument
- for the status changepublic final void sendStatusChange(MapEventPropagation propagationMode, String name)
propagationMode
- of sending the status changename
- of the status changepublic final void sendStatusChange(MapEventPropagation propagationMode, String name, Object argument)
propagationMode
- of sending the status changename
- of the status changeargument
- for the status changepublic final void performTickUpdates()
public final MapWidget setPosition(int x, int y)
x
- - positiony
- - positionpublic final MapWidget setSize(int width, int height)
width
- height
- public final MapWidget setSize(Dimension dimension)
dimension
- public final MapWidget setBounds(int x, int y, int width, int height)
x
- - position relative to the parenty
- - position relative to the parentwidth
- height
- protected void handleNavigation(MapKeyEvent event)
event
- protected MapWidget navigateNextWidget(List<MapWidget> widgets, MapPlayerInput.Key key)
widgets
- that can be focused nextkey
- that was pressedpublic void onKey(MapKeyEvent event)
MapDisplayEvents
MapDisplayEvents.onTick()
.onKey
in interface MapDisplayEvents
public void onKeyPressed(MapKeyEvent event)
MapDisplayEvents
MapDisplayEvents.onTick()
.onKeyPressed
in interface MapDisplayEvents
public void onKeyReleased(MapKeyEvent event)
MapDisplayEvents
MapDisplayEvents.onTick()
.onKeyReleased
in interface MapDisplayEvents
public void onLeftClick(MapClickEvent event)
MapDisplayEvents
onLeftClick
in interface MapDisplayEvents
public void onRightClick(MapClickEvent event)
MapDisplayEvents
onRightClick
in interface MapDisplayEvents
public void onStatusChanged(MapStatusEvent event)
MapDisplayEvents
onStatusChanged
in interface MapDisplayEvents
event
- of the status changepublic void onMapItemChanged()
MapDisplayEvents
onMapItemChanged
in interface MapDisplayEvents
Copyright © 2019. All rights reserved.