show_question_select_item.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { _decorator, assetManager, Component, ImageAsset, Label, Node, Sprite, SpriteFrame, Texture2D, Toggle } from 'cc';
  2. import { event_item, event_item_show_question_select_item, ui_att_item } from '../../../data/data';
  3. import { tools } from '../../tools';
  4. import { Attributes } from '../Attributes';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('show_question_select_item')
  7. export class show_question_select_item extends Component {
  8. private m_data:ui_att_item = null;
  9. @property(Node) img_icon:Node = null;
  10. @property(Node) btn_add_event:Node = null;
  11. @property(Node) lab_cur_event_id:Node = null;
  12. @property(Node) toggle_is_right:Node = null;
  13. private m_event_item_show_question_select_item:event_item_show_question_select_item = null;
  14. public initView(data:ui_att_item,event_data:event_item_show_question_select_item){
  15. this.m_data = data;
  16. this.m_event_item_show_question_select_item = event_data;
  17. if(this.m_data.res.length>0){
  18. assetManager.loadRemote<ImageAsset>(this.m_data.res, (err, imageAsset2)=>{
  19. if (!err && imageAsset2) {
  20. const texture = new Texture2D();
  21. texture.image = imageAsset2;
  22. let spFrame2 = new SpriteFrame();
  23. spFrame2.texture = texture;
  24. this.img_icon.getComponent(Sprite).spriteFrame = spFrame2
  25. }
  26. });
  27. }
  28. this.btn_add_event.on(Node.EventType.TOUCH_END,()=>{
  29. let list = Attributes.Singleton.getEventList()
  30. tools.show_select_evele_list(list,(data:event_item)=>{
  31. this.m_event_item_show_question_select_item.binding_event_id = data.event_id;
  32. this.updateStatus()
  33. })
  34. })
  35. // this.toggle_is_right.on(Node.EventType.TOUCH_END,()=>{
  36. // this.m_event_item_show_question_select_item.isRight = this.toggle_is_right.getComponent(Toggle).isChecked
  37. // })
  38. this.updateStatus()
  39. }
  40. updateStatus(){
  41. // this.toggle_is_right.getComponent(Toggle).isChecked = this.m_event_item_show_question_select_item.isRight
  42. if(this.m_event_item_show_question_select_item.binding_event_id==-1){
  43. this.lab_cur_event_id.getComponent(Label).string = "添加事件"
  44. }else{
  45. this.lab_cur_event_id.getComponent(Label).string = `事件ID:${this.m_event_item_show_question_select_item.binding_event_id}`
  46. }
  47. }
  48. }