tip_layer.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
  2. import { ddz_tip_item } from './ddz_tip_item';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('tip_layer')
  5. export class tip_layer extends Component {
  6. @property(Prefab) itemPrefab:Prefab;
  7. @property(Node) content:Node;
  8. @property(Node) btn_close:Node;
  9. private card_list = {3: '3', 4: '4', 5: '5', 6: '6', 7: '7',
  10. 8: '8', 9: '9', 10: '10', 11: 'J', 12: 'Q',
  11. 13: 'K', 14: 'A', 17: '2', 20: '小王', 30: '大王','P':"过"};
  12. public initView(answer_content){
  13. let list = answer_content.split(';')
  14. this.content.removeAllChildren()
  15. for (let index = 0; index < list.length; index++) {
  16. const str = `第${index+1}步:${this.getCardStr(list[index])}`;
  17. let item = instantiate(this.itemPrefab)
  18. item.parent = this.content;
  19. item.getComponent(ddz_tip_item).initView(str)
  20. }
  21. this.btn_close.off(Node.EventType.TOUCH_END)
  22. this.btn_close.on(Node.EventType.TOUCH_END,()=>{
  23. this.node.active = false;
  24. })
  25. }
  26. getCardStr(str_list){
  27. let list = str_list.split(',')
  28. let temp = []
  29. for (let index = 0; index < list.length; index++) {
  30. const element = list[index];
  31. if(element==="P"){
  32. temp.push(this.card_list[element])
  33. }else{
  34. temp.push(this.card_list[parseInt(element)])
  35. }
  36. }
  37. return temp.toString()
  38. }
  39. }