GlobalLiquidity

TransactionSettingListItem

Nov 11th, 2022
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import * as bjs from 'babylonjs'
  2. import * as bjsgui from 'babylonjs-gui'
  3. import { HorizontalAlignment, VerticalAlignment, GLSGColor } from '@/modules/SceneGraph/Enums'
  4. import { TextMeshString } from '@/modules/SceneGraph/TextMeshString'
  5. import { Scene } from '@/modules/SceneGraph/Scene'
  6. import { SceneElement } from '@/modules/SceneGraph/SceneElement'
  7. import { SimpleEventDispatcher } from 'strongly-typed-events'
  8. import { TransactionSetting } from '../../TransactionSettingRepository'
  9.  
  10. export class TransactionSettingListItem extends SceneElement
  11. {
  12.   private imagePlane : bjs.Mesh;
  13.   private imageMaterial : bjs.StandardMaterial = new bjs.StandardMaterial("Item Image");
  14.   private imageTexture : bjs.Texture = new bjs.Texture("")
  15.  
  16.   label : TextMeshString
  17.  
  18.   private buttonPlane : bjs.Mesh
  19.   private buttonTexture : bjsgui.AdvancedDynamicTexture;
  20.   private button : bjsgui.Button;
  21.  
  22.   protected _onItemClicked = new SimpleEventDispatcher<TransactionSettingListItem>()
  23.   public get onItemClicked() {
  24.     return this._onItemClicked.asEvent()
  25.   }
  26.  
  27.   constructor(public name: string,
  28.     public x: number,
  29.     public y: number,
  30.     public z: number,
  31.     public scene: Scene,
  32.     public transactionSetting : TransactionSetting
  33.   ) {
  34.     super(name, x, y, z, scene)
  35.     this.create()
  36.   }
  37.  
  38.   async onCreate()
  39.   {
  40.     this.imagePlane = bjs.MeshBuilder.CreatePlane("Asset Logo", {width : 1.5, height:1.5  })
  41.     this.imagePlane.position.x = -3
  42.     this.imagePlane.position.y = 0
  43.     this.imagePlane.position.z = -0.5
  44.     this.imagePlane.parent = this;
  45.     this.imageTexture = new bjs.Texture(this.transactionSetting.logoUrl);
  46.     this.imageMaterial.diffuseTexture = this.imageTexture;
  47.     this.imageMaterial.opacityTexture = this.imageTexture
  48.     this.imageMaterial.emissiveTexture = this.imageTexture;
  49.     this.imageMaterial.useAlphaFromDiffuseTexture
  50.     this.imagePlane.hasVertexAlpha = true;
  51.     this.imagePlane.material = this.imageMaterial
  52.     this.imagePlane.isPickable = false
  53.    
  54.     this.label = new TextMeshString("Label",
  55.     -2,
  56.     0,
  57.     -0.15,
  58.     this.scene,
  59.     this.transactionSetting.name.toUpperCase(),
  60.     0.7,
  61.     HorizontalAlignment.Left,
  62.     VerticalAlignment.Middle,
  63.     bjs.Mesh.BILLBOARDMODE_NONE,
  64.     false);
  65.  
  66.     this.addChild(this.label);
  67.     this.label.parent = this;
  68.     this.label.scaling = new bjs.Vector3(0.8,1,1);
  69.     this.label.setColor(GLSGColor.Complementary);
  70.  
  71.      //Add Button
  72.      this.buttonPlane = bjs.MeshBuilder.CreatePlane("Button Plane", {height:2,width:8})
  73.      this.buttonPlane.parent = this
  74.      this.buttonPlane.position = new bjs.Vector3(-0.26,0,-0.1)
  75.      this.buttonTexture = bjsgui.AdvancedDynamicTexture.CreateForMesh(this.buttonPlane);
  76.      this.button = bjsgui.Button.CreateSimpleButton("Button", "");
  77.      this.button.color = GLSGColor.FirstPrimary
  78.      this.button.cornerRadius = 25
  79.      this.button.background = GLSGColor.FirstPrimary
  80.      this.button.highlightColor = GLSGColor.Complementary
  81.      this.button.top = 0
  82.      this.button.fontFamily = "Conthrax Sb"
  83.      this.button.shadowOffsetX = 20
  84.      this.button.shadowOffsetY = 40
  85.      this.button.shadowBlur = 20
  86.      this.button.shadowColor = 'white'
  87.      this.button.alpha = 1
  88.      this.button.isHitTestVisible = true
  89.  
  90.      this.button.onPointerEnterObservable.add(()=>{
  91.  
  92.  
  93.      })
  94.  
  95.      this.button.onPointerOutObservable.add(()=>{
  96.  
  97.      })
  98.  
  99.      this.button.onPointerDownObservable.add(()=>{
  100.        this._onItemClicked.dispatch(this)
  101.      
  102.      })
  103.  
  104.      this.button.onPointerUpObservable.add(()=>{
  105.      })
  106.  
  107.      this.button.onPointerClickObservable.add(()=>{
  108.      
  109.  
  110.      })
  111.  
  112.      this.buttonTexture.addControl(this.button)
  113.  
  114.  
  115.   }
  116.  
  117.   public destroy(): void {
  118.     this.imagePlane.dispose()
  119.     this.buttonPlane.dispose()
  120.     this.label.destroy()
  121.     this.imageTexture.dispose()
  122.     this.dispose()
  123.   }
  124. }
Add Comment
Please, Sign In to add comment