Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

InteractiveDisplayModule

Contributed by Butanium.

The InteractiveDisplayModule allows you to display entities when the mouse is over an entity or when the user clicks an entity. If an entity is clicked, the associated entity will be displayed until the entity is clicked again. The user can hide all entities displayed by the module with ALT + LEFT CLICK.

Showcase

Here is an usage example

Setup

⚠ This module requires the GraphicEntityModule to work.

Add the dependency in the pom.xml of your project.


<dependency>
    <groupId>com.codingame.gameengine</groupId>
    <artifactId>module-interactivedisplay</artifactId>
    <version>${gamengine.version}</version> <!-- Must be higher than {todo : update the version once it's released} -->
</dependency>

Then setup the module in your config.js.

import {GraphicEntityModule} from './entity-module/GraphicEntityModule.js'
import {InteractiveDisplayModule} from './interactivedisplay-module/InteractiveDisplayModule.js'

// List of viewer modules that you want to use in your game
export const modules = [
    GraphicEntityModule,
    InteractiveDisplayModule
]

Optional arguments

You can modify the behavior of the module by adding some lines in the config.js (after export const modules = [...]) .

  • Add this line to disable displaying entities when the mouse hover it
InteractiveDisplayModule.enable_display_on_hover = false
  • Add this line to allow processing multiple entities if they are all hovered
InteractiveDisplayModule.allow_multiple_hover_display = true
  • Add this line if you want to disable permanent display when an entity is clicked
InteractiveDisplayModule.enable_display_on_click = false
  • Add this line if you want to limit the number of clicked entities. If the limit is exceeded, the oldest clicked entities will be hidden
InteractiveDisplayModule.max_clicked_entities = 3

Usage

Referee.java

@Inject
InteractiveDisplayModule interactiveDisplayModule;

@Override
public void init(){
        // Add enities to display when the mouse is over entity
        interactiveDisplayModule.addDisplay(entity, entitiesToDisplay);
        // You can use HOVER_ONLY and CLICK_ONLY options to display some entities only for a specific user action
        interactiveDisplayModule.addDisplay(entity, entitiesToDisplay, InteractiveDisplayModule.CLICK_ONLY);
        // You can also resize associatedEntities instead of displaying them
        interactiveDisplayModule.addResize(entity, entityToResize, factor);
        // You can use HOVER_ONLY and CLICK_ONLY options to resize some entities only for a specific user action
        interactiveDisplayModule.addResize(entity, entityToResize, factor, InteractiveDisplayModule.HOVER_ONLY);
        // If entity and entityToResize are the same you can use 
        interactiveDisplayModule.addResize(entity, factor);
        // When you hide an entity that is registered in the module, untrack it to avoid visual bugs
        interactiveDisplayModule.untrack(entity);
        // If you want to remove an associated entity
        interactiveDisplayModule.removeTransformation(entity, notTransformedAnymoreEntity);
        }
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content