rule_view.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { _decorator, Component, Node, Sprite } from 'cc';
  2. import { ui_att_item } from '../../../data/data';
  3. import { gameManager } from '../gameManager';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('rule_view')
  6. export class rule_view extends Component {
  7. @property(Node) btn_rule_left:Node = null;
  8. @property(Node) btn_rule_right:Node = null;
  9. @property(Node) btn_rule_close:Node = null;
  10. @property(Node) icon:Node = null;
  11. private m_page = 0;
  12. private mData :ui_att_item[] = null;
  13. public initView(rule_list:ui_att_item[]){
  14. this.mData = rule_list;
  15. this.btn_rule_left.on(Node.EventType.TOUCH_END,()=>{
  16. if( (this.m_page-1)<0){
  17. }else{
  18. this.m_page-=1;
  19. }
  20. this.update_func()
  21. this.updateBtnStatus()
  22. gameManager.Singleton.sys_click_button_music()
  23. })
  24. this.btn_rule_right.on(Node.EventType.TOUCH_END,()=>{
  25. if( (this.m_page+1)>=this.mData.length){
  26. }else{
  27. this.m_page+=1;
  28. }
  29. this.update_func()
  30. this.updateBtnStatus()
  31. gameManager.Singleton.sys_click_button_music()
  32. })
  33. this.btn_rule_close.on(Node.EventType.TOUCH_END,()=>{
  34. this.close()
  35. gameManager.Singleton.sys_click_button_music()
  36. })
  37. if(this.mData.length<=0){
  38. this.m_page =0
  39. }else{
  40. this.m_page = this.mData.length-1;
  41. }
  42. this.update_func()
  43. this.updateBtnStatus()
  44. }
  45. show(){
  46. this.node.active = true;
  47. }
  48. close(){
  49. this.node.active = false;
  50. }
  51. updateBtnStatus(){
  52. if(this.mData.length<=1){
  53. this.btn_rule_right.active = false;
  54. this.btn_rule_left.active = false;
  55. }else{
  56. this.btn_rule_right.active = true;
  57. this.btn_rule_left.active = true;
  58. if(this.m_page>=this.mData.length-1){
  59. this.btn_rule_right.active = false;
  60. }
  61. if(this.m_page<=0){
  62. this.btn_rule_left.active = false;
  63. }
  64. }
  65. }
  66. update_func(){
  67. let curSelectItem = this.mData[this.m_page];
  68. this.icon.getComponent(Sprite).spriteFrame = gameManager.getCacheSpriteFrameByName(curSelectItem.res)
  69. }
  70. }