_raptorBase - coldrockgames/gml-raptor GitHub Wiki

This is the "mother of all objects" in the raptor platform.

As mentioned in raptor's object model, it covers a very powerful feature, I call click-through, and it also is the base for UI Skins as those are applied on this mother-of-all raptor-objects.

Let's find out, what this means.
_raptorBase delivers only a handful of variable definitions:

is_touchable and is_enabled (click-through)

You may be familiar with the concept of enabled/disabled controls from web- or desktop-development. Those controls are normally greyed out, when disabled, and don't react on clicks.

These two variables are similar.

  • is_enabled is the "master switch". If you turn this off, the object will not receive any mouse events or clicks. In case you own the raptor-pro edition and you disable a control object, like a Button, it will be rendered through a GrayScaleShader as soon as it is disabled.
  • is_touchable has no impact on the rendering of an object. As long as it is_enabled, it will still receive mouse events (enter/leave/click/etc..) but it can never be the topmost item in the scene. is_touchable influences what raptor considers the "top item" (the one closest to the viewer) at any specific coordinate. This is useful for instance in any drag&drop scenario, where such an item can not be the target of a drop, like a Healthbar, the Mouse Cursor or any invisible control you might have on screen. Raptor will just never return "true" on the question "is this the topmost item at position x/y" if it is not touchable.

There is a group of #macros available in raptor, which let you react on these (and many other) flags, to decide, whether a mouse-event or any other event shall be processed or not.

Read more about those macros in Utility-and-Helper-#macros.

on_enabled_changed

Set this to any function to receive a callback, when the is_enabled state of an object changes.

[!NOTE] To ensure, the callback is launched, when you change the is_enabled value, do NOT simply change the bool value in code, instead invoke the method set_enabled(...) on the object! This function checks, whether the state has changed, and if it has, it invokes the callback, if one is set.

skin_flavor

The [UI Subsystem]] and the [Skin/Theme system of raptor pro allow you styling of all objects in raptor. UI, Bullets, Heroes, everything can be skinned and together with the RichJson system, this is one of the most powerful abilities in this framework,

The is_topmost(...) Function in _raptorBase

This function in _raptorBase is another good reason, to use it as base for your objects.

By invoking is_topmost(x,y), you can check any position, whether the object is closest to the user (has the smallest depth), but it does not simply use any of the *_meeting functions alone, it also checks the is_enabled and is_touchable state of all objects at that position and it checks, whether there's a popup open, the layer is visible at all and other things.

[!TIP] Long story short: This function checks, whether the object is the topmost clickable, reachable, visible and enabled object at this position! And, as if that would not be enough, this check is performed in the room and the UI layer! So, if you get a true return value from this function, you can be sure, it is visible for the user and ready for interaction (from an event point-of-view)

image _raptorTooltipBase

In raptor-pro, there is another super base object available.

Most objects in raptor-pro derive from the _raptorTooltipBase which enriches the _raptorBase by tooltip functionality without being a UI control. This means, every object in your game can display a tooltip if you want!

For this, some more variable definitions are added:

Variable Type Default Description
tooltip_text string "" The text to be displayed. This is a fully LG Localization compatible text and will be resolved when the tooltip gets shown
tooltip_object type Tooltip The object to instantiate when displaying a tooltip. This must be a child of the Tooltip object
auto_show_tooltip bool true Automatically show the tooltip after TOOLTIP_DELAY_FRAMES frames. This value can be changed in the UI_Configuration script

onTooltipShowing

There's also a callback defined which you may override in your Create event. It allows you to manipulate the tooltip text right before it gets rendered on screen.

[!TIP] Return an empty string "" or undefined from this callback to suppress the display of the tooltip!

/// @func	onTooltipShowing(_tooltip_text)
/// @desc	Invoked before the tooltip gets rendered.
///		Return the text that shall be displayed for the tooltip.
///		The default is to simply return the provided _tooltip_text.
///		NOTE: If you return an empty string or undefined here,
///		no tooltip will be shown.
onTooltipShowing = function(_tooltip_text) {
    return _tooltip_text;
}

Next read: Macros