Package net.risingworld.api.ui
Klasse UIElement
java.lang.Object
net.risingworld.api.ui.UIElement
- Alle implementierten Schnittstellen:
Serializable
- Bekannte direkte Unterklassen:
UILabel
,UIMesh
,UIPainter2D
,UIScrollView
,UITextField
Base UI element. It may act as container, button, panel etc. Other UI elements (like text fields or labels)
are derived from this class.
The visual appearance of the element is described by an
The visual appearance of the element is described by an
Style
object. There is also a separate
hover Style
to define a separate appearance whenever the element is hovered with the mouse.- Siehe auch:
-
Feldübersicht
-
Konstruktorübersicht
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoid
Attaches an UIElement as "child" to this element.void
addStyleSheet
(StyleSheetAsset styleSheetAsset) Adds an optional style sheet asset (USS).void
addToClassList
(String className) int
Gets the number of attached child elements on this element.Gets an unmodifiable list of all children of this element.int
getID()
Gets the unique ID of this element.Gets the current parent UI element, or null if this element has no parent.int
Gets the ID of the plugin which created this element.boolean
void
onClick
(PlayerUIElementClickEvent event) Override this method if you want to get the click event (when a player clicks on the element) directly, without having to register an event listener.void
Removes all children from this element.void
removeChild
(UIElement child) Removes a child from this element.void
removeFromClassList
(String className) void
Removes this element from its parent.void
removeStyleSheet
(StyleSheetAsset styleSheetAsset) void
Resets the pivot setting, i.e internally this resets the transformOrigin and translate style parameters.void
Resets the position, i.e internally this resets the left, bottom, top and right style parameters.void
setBackgroundColor
(float r, float g, float b, float a) Sets the background color of the element.void
setBackgroundColor
(int rgba) Sets the background color of the element.void
setBorder
(float thickness) Sets the border width/thickness of this element.void
setBorderColor
(float r, float g, float b, float a) Sets the color of the border.void
setBorderColor
(int rgba) Sets the color of the border.void
setBorderEdgeRadius
(float radius, boolean percent) Sets the radius of the element border corners.void
setClickable
(boolean clickable) Sets this element clickable, i.e the element listens for mouse clicks and triggers aPlayerUIElementClickEvent
event in this case (this also invokes theonClick(net.risingworld.api.events.player.ui.PlayerUIElementClickEvent)
method).void
setOpacity
(float opacity) Sets the opacity of this element.void
setPickable
(boolean pickable) Not to be confused withsetClickable(boolean)
! This flag determines if the UI element "has collision", i.e if it consumes or "blocks" mouse clicks.void
Changes the origin of this element.void
setPosition
(float x, float y, boolean percent) Sets the screen position of this element.void
setSize
(float width, float height, boolean percent) Sets the size (width and height) of this element.void
setVisible
(boolean visible) Changes visibility of this element.void
Synchronize pending style changes with all registered players.
-
Felddetails
-
style
The style of this element. After changing it, remember to callupdateStyle()
, so the changes are synced with the player -
hoverStyle
The hover style of this element. Becomes active when hovering this element with the cursor, but only ifsetClickable(boolean)
was set to true. After changing the style, remember to callupdateStyle()
, so the changes are synced with the player
-
-
Konstruktordetails
-
UIElement
public UIElement()
-
-
Methodendetails
-
getID
public int getID()Gets the unique ID of this element. Note that this ID is only valid during the session!- Gibt zurück:
- the unique ID of this element.
-
getPluginID
public int getPluginID()Gets the ID of the plugin which created this element.- Gibt zurück:
- the plugin ID.
-
updateStyle
public void updateStyle()Synchronize pending style changes with all registered players. Call this method if you've changed the style of the element directly -
addStyleSheet
Adds an optional style sheet asset (USS). They're similar to CSS and describe theStyle
of a UI element. Style Sheets can be created in Unitys UI Builder (UI Toolkit).
If you don't want to load a USS style sheet from file, you can ignore this method.- Parameter:
styleSheetAsset
- the style sheet asset.
-
removeStyleSheet
-
addToClassList
-
removeFromClassList
-
setPosition
public void setPosition(float x, float y, boolean percent) Sets the screen position of this element. By default, the position coordinate is at the upper left of the element.
Important: Absolute positions are always in relation to fullHD resolution (1920x1080), irrespective of the actual screen resolution. The game then automatically updates the element position depending on the screen resolution.
Note: This is just a helper method. Internally it only changes the style left, top and position values!- Parameter:
x
- the x (horizontal) position.y
- the y (vertical) position.percent
- set to false to use pixel values, or true to use percent values (0-100)
-
setPivot
Changes the origin of this element.
Note: This is just a helper method. Internally it only changes the style transformOrigin and translate values!- Parameter:
pivot
- the new pivot/origin you want to set.
-
resetPosition
public void resetPosition()Resets the position, i.e internally this resets the left, bottom, top and right style parameters. -
resetPivot
public void resetPivot()Resets the pivot setting, i.e internally this resets the transformOrigin and translate style parameters. -
setSize
public void setSize(float width, float height, boolean percent) Sets the size (width and height) of this element.
Important: Absolute positions are always in relation to fullHD resolution (1920x1080), irrespective of the actual screen resolution. The game then automatically updates the element position and size depending on the screen resolution.
Note: This is just a helper method. Internally it only changes the style width and height values!- Parameter:
width
- the horizontal width (x).height
- the vertial height (y).percent
- set to false to use pixel values, or true to use percent values (0-100)
-
setBorder
public void setBorder(float thickness) Sets the border width/thickness of this element. Please bear in mind that the border expands to the inner of the element, which also shifts/shrinks the content of the element.
Note: This is just a helper method. Internally it only changes the style borderLeftWidth, borderRightWidth, borderTopWidth and borderBottomWidth values!- Parameter:
thickness
- the new width/thickness of the border (in pixels).
-
setBorderColor
public void setBorderColor(float r, float g, float b, float a) Sets the color of the border. This is only relevant if the border has a thickness greater than 0.
Note: This is just a helper method. Internally it only changes the style borderLeftColor, borderRightColor, borderTopColor and borderBottomColor values!- Parameter:
r
- the new red value (0-1).g
- the new green value (0-1).b
- the new blue value (0-1).a
- the new alpha/opacity value (0-1).
-
setBorderColor
public void setBorderColor(int rgba) Sets the color of the border. This is only relevant if the border has a thickness greater than 0.
Note: This is just a helper method. Internally it only changes the style borderLeftColor, borderRightColor, borderTopColor and borderBottomColor values!- Parameter:
rgba
- the int RGBA color code (0xRRGGBBAA).
-
setBorderEdgeRadius
public void setBorderEdgeRadius(float radius, boolean percent) Sets the radius of the element border corners. Use this to create rounded edges. For example, if you set the radius to half the element width/height, you will get a fully round element. Set the radius to 0 to get sharp edges (default).
Note: This is just a helper method. Internally it only changes the style borderTopLeftRadius, borderTopRightRadius, borderBottomLeftRadius and borderBottomRightRadius values!- Parameter:
radius
- the radius of the edge.percent
- set to false to use pixel values, or true to use percent values (0-100).
-
setBackgroundColor
public void setBackgroundColor(float r, float g, float b, float a) Sets the background color of the element.
Note: This is just a helper method. Internally it only changes the style backgroundColor value!- Parameter:
r
- the new red value (0-1).g
- the new green value (0-1).b
- the new blue value (0-1).a
- the new alpha/opacity value (0-1).
-
setBackgroundColor
public void setBackgroundColor(int rgba) Sets the background color of the element.
Note: This is just a helper method. Internally it only changes the style backgroundColor value!- Parameter:
rgba
- the int RGBA color code (0xRRGGBBAA).
-
setOpacity
public void setOpacity(float opacity) Sets the opacity of this element. Set to 0 to make the element fully invisible, and 1 to make it fully opaque.
Note: This is just a helper method. Internally it only changes the style opacity value!- Parameter:
opacity
- the new opacity (0-1).
-
setVisible
public void setVisible(boolean visible) Changes visibility of this element. When setting to false, the element still takes up space in the parent layout. To prevent that, changeStyle.display
Note: This is just a helper method. Internally it only changes the style visibility value!- Parameter:
visible
- true to make the element visible (default), false to hide it.
-
setClickable
public void setClickable(boolean clickable) Sets this element clickable, i.e the element listens for mouse clicks and triggers aPlayerUIElementClickEvent
event in this case (this also invokes theonClick(net.risingworld.api.events.player.ui.PlayerUIElementClickEvent)
method).- Parameter:
clickable
- true to let this element listen for mouse clicks, false if not- Siehe auch:
-
isClickable
public boolean isClickable() -
setPickable
public void setPickable(boolean pickable) Not to be confused withsetClickable(boolean)
! This flag determines if the UI element "has collision", i.e if it consumes or "blocks" mouse clicks. By default, this is enabled. If you set it to false, mouse clicks will ignore this element, so you could click "through" this element (and click an element behind it, for example).- Parameter:
pickable
- true to block mouse clicks (default behaviour), false to let mouse clicks pass through
-
addChild
Attaches an UIElement as "child" to this element. The child position and style will then depend on the new parent. If you make any changes to the parent (i.e move it, resize it, change visibility), it will affect all childs automatically.
By default, elements have no parents. If an element has no parent, the screen is considered the parent.
Note: It's not necessary to add child elements to the player UI manually, because the game handles this automatically.- Parameter:
child
- the element you want to attach as child to this element.- Example: Create a label (as child) in front of a panel (parent)
-
removeChild
Removes a child from this element. It will also be detached from the player UI.- Parameter:
child
- the child element you want to remove.
-
removeAllChilds
public void removeAllChilds()Removes all children from this element. They will also be detached from the player UI. -
getParent
Gets the current parent UI element, or null if this element has no parent.- Gibt zurück:
- the parent element, or null if no parent is set.
-
removeFromParent
public void removeFromParent()Removes this element from its parent. Same as callingremoveChild(net.risingworld.api.ui.UIElement)
on the parent element. -
getChilds
Gets an unmodifiable list of all children of this element.- Gibt zurück:
- a new, unmodifiable list containing all child elements.
-
getChildCount
public int getChildCount()Gets the number of attached child elements on this element.- Gibt zurück:
- the amount of children this element has. 0 if this element has no child elements.
-
onClick
Override this method if you want to get the click event (when a player clicks on the element) directly, without having to register an event listener.- Parameter:
event
- the UI click event.- Example:
- Siehe auch:
-