Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Binding

A Binding is an association between a UI control and part of a game component's state, usually one of the game component's private settings. When the UI control is activated by the user, calling Binding.update() will convert the state of the control into a game component setting and use this to update the game component so that it matches the state of the UI control. When the game component is loaded from a file, calling Binding.initComponent() will read the game component's state and update the state of the UI control to match it.

The Binding Process

When update method is called, it calls controlToSetting to convert the state of the UI component into a setting value (a string). It will then look in the private settings of the game component for a setting with the provided key name. If the setting does not exist or is different from the the setting returned from controlToSetting, then it will copy the new value into the game component's private settings and mark the sheets listed in the list of card faces as being out of date.

update returns true if it updated the component.

When initComponent method is called, it will first fetch the named setting from the game component's private settings and then call settingToControl to modify the state of the control to reflect the setting value.

Writing Binding Classes
The Binding base class will copy the text that a user writes in a text component to a private setting (for update()) and will set the text in the component to the value of the private setting (for initComponent(). For other kinds of components, you need to create an appropriate subclass that knows about the specific kind of control it is binding the game component state to. To create a subclass you only need to override the controlToSetting() and settingToControl() methods to handle the new type of control. For example, the following binding will bind a checkbox to a yes/no setting value in the game component:

function CheckboxBinding( name, uiControl, gameComponent, sheetsToUpdate ) {
    // call superclass constructor
    Binding.call( this, name, uiControl, gameComponent, sheetsToUpdate );
}

CheckboxBinding.subclass( Binding );

CheckboxBinding.prototype.toSetting = function controlToSetting( control ) {
    if( control.selected )
        return 'yes';
    else
        return 'no';
}

CheckboxBinding.prototype.settingToControl = function settingToControl( control, value ) {
    control.selected = value != null && value.equals( 'yes' );
}

If you wish to create more advanced binding behaviours, such as calling methods on the game component instead of changing private settings, override update and initComponent. It is critical that update method returns true if and only if the setting is updated with a different value.

Hierarchy

Index

Constructors

constructor

  • Creates a Binding instance. When you create a binding, you provide a key name, a UI control, a game component, and an array of numbers. The array of numbers is a list of card faces (0 for front, 1 for back, and so on) that need to be updated when the bound state changes. For example, if the bound state represented content that is drawn only on the component's back face, then you would use [1].

    Parameters

    • keyName: string

      the setting key that the control is bound to; if it starts with $, the $ will be removed and any underscores (_) replaced with dashes (-)

    • uiControl: JavaObject<"java.awt.Component">

      the UI component that will take part in the binding

    • gameComponent: JavaObject<"arkham.component.GameComponent">

      the game component that will take part in the binding

    • sheetsToUpdate: number[]

      an array of the indices of the game component's sheets which should be repainted when the bound setting changes

    Returns Binding

Methods

controlToSetting

  • Converts the state of the control to a setting string. Subclasses override this to customize how the control's state is represented in the game component's private settings.

    Parameters

    Returns string

    the string representing the state of the control

initComponent

  • initComponent(): void
  • Updates the UI component using the current setting value.

    Returns void

settingToControl

  • Changes the state of the control to reflect the provided setting value. Subclasses override this to customize how the control's state is represented in the game component's private settings.

    Parameters

    Returns void

update

  • update(): boolean
  • Updates the UI component setting using the current value of the control.

    Returns boolean

    true if the setting has changed