UNPKG

seed-engine

Version:

A Lightweight 2D game engine using WebGL2. The engine is designed on the focus of creating a bridge between creating and publishing games to the Seed Network as modules.

54 lines (47 loc) 2.1 kB
import { ClickController, Point, SceneObject, Renderable2D, UIManager, UIPanel } from '../../entry'; export default class UIIconButton extends UIPanel { constructor(viewport, x, y, w, h, text, onLeft, onRight = () => {}) { super(viewport, x + (w * .1), y + (h * .1), w, h * .8, text); this.buttonObject = new UIPanel(viewport, x, y, w, h, this.uiStyle.buttonTexture); this.buttonObject.setSubIndex(this.uiStyle.buttonSubImage); this.buttonObject.setDepth(1000); this.viewport = viewport; this.onLeftClick = onLeft; this.onRightClick = onRight; this.buttonObject.clickController = new ClickController(this.viewport, () => { if (this.buttonObject.clickController.leftPressed) { this.buttonObject.setSubIndex(this.uiStyle.buttonReleasedSubImage); this.onLeftClick(); this.buttonObject.clickController.leftPressed = false; } }, () => { if (this.buttonObject.clickController.rightPressed) { this.buttonObject.setSubIndex(this.uiStyle.buttonReleasedSubImage); this.onRightClick(); this.buttonObject.clickController.rightPressed = false; } }, () => { this.buttonObject.setSubIndex(this.uiStyle.buttonPressedSubImage); }, () => { this.buttonObject.setSubIndex(this.uiStyle.buttonPressedSubImage); }); this.buttonObject.addComponent(this.buttonObject.clickController); } onPause() { this.textObject.pause(); this.textObject.renderableText.pause(); this.buttonObject.pause(); this.buttonObject.clickController.pause(); } onUnpause() { this.textObject.unpause(); this.textObject.renderableText.unpause(); this.buttonObject.unpause(); this.buttonObject.clickController.unpause(); this.setText(this.text); } setDepth(depth) { this.textObject.renderableText.setDepth(depth); this.buttonObject.setDepth(depth); } }