MainAtterItem.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * 主属性节点
  3. */
  4. const {ccclass, property} = cc._decorator;
  5. @ccclass
  6. export default class MainAtterItem extends cc.Component {
  7. @property(cc.Label)
  8. mValue: cc.Label = null;
  9. @property(cc.Node)
  10. mContrast: cc.Node = null;//对比
  11. @property(cc.Label)
  12. mPCT: cc.Label = null;//百分比
  13. @property(cc.Sprite)
  14. mUpDown: cc.Sprite = null;
  15. @property(cc.SpriteFrame)
  16. mUp: cc.SpriteFrame = null;
  17. @property(cc.SpriteFrame)
  18. mDown: cc.SpriteFrame = null;
  19. public setValue(v1){
  20. this.mContrast.active = false;
  21. this.mValue.string = ''+v1
  22. this.mValue.node.color = cc.color(75,43,0)
  23. }
  24. public setContrase(v1:number,v2:number){
  25. this.mContrast.active = true
  26. this.mValue.string = ''+v1
  27. let color = cc.color();
  28. if(v1 >= v2){
  29. color.r = 75
  30. color.g = 43
  31. color.b = 0
  32. this.mValue.node.color = color
  33. this.mUpDown.spriteFrame = this.mUp
  34. }else{
  35. color.r = 255
  36. color.g = 24
  37. color.b = 24
  38. this.mValue.node.color = color
  39. this.mUpDown.spriteFrame = this.mDown
  40. }
  41. this.mPCT.string = Math.floor((v1-v2)*100/v1)+'%'
  42. this.mPCT.node.color = color
  43. }
  44. }