question_btn_info.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { _decorator, Component, EditBox, Node } from 'cc';
  2. import { ui_att_item } from '../../../data/data';
  3. import { receive_res_item } from '../uiWidget/receive_res_item';
  4. import { receive_widget_item } from '../uiWidget/receive_widget_item';
  5. import { tools } from '../../tools';
  6. import { config } from '../../config';
  7. import { ClientEvent } from '../../clientEvent';
  8. import { Attributes } from '../Attributes';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('question_btn_info')
  11. export class question_btn_info extends Component {
  12. @property(Node) res_node:Node = null;
  13. @property(Node) att_node:Node = null;
  14. @property(Node) score_node:Node = null;
  15. @property(EditBox) score_editBox:EditBox = null
  16. @property(Node) btn_original_size:Node = null
  17. @property(Node) btn_delete:Node = null;
  18. private m_data:ui_att_item = null;
  19. private m_index:number = 0;
  20. private m_type:string = config.attributes_list_type.top;
  21. private m_call_back = null;
  22. protected start(): void {
  23. this.score_editBox.node.on(EditBox.EventType.EDITING_DID_ENDED, ()=>{
  24. if(this.score_editBox.string.length<=0) {
  25. this.score_editBox.string = '0'
  26. }
  27. this.m_data.score = parseInt(this.score_editBox.string)
  28. this.updateScoreStatus()
  29. })
  30. this.btn_original_size.on(Node.EventType.TOUCH_END, ()=>{
  31. tools.show_dialog('设置原尺寸?',()=>{
  32. tools.loadSceneImg(this.m_data.res, (r)=>{
  33. this.m_data.width = r.sf.originalSize.width
  34. this.m_data.height = r.sf.originalSize.height
  35. this.att_node.getComponent(receive_widget_item).updateView(this.m_data,this.m_type)
  36. ClientEvent.dispatchEvent(config.Event.UpdateAttributesToView,Attributes.Singleton.get_cur_att_data(),this.m_type)
  37. })
  38. })
  39. })
  40. }
  41. public initView(data:ui_att_item,index:number,call,type){
  42. this.m_data =data;
  43. this.m_call_back = call;
  44. this.m_index = index;
  45. this.m_type = type
  46. if(type===config.attributes_list_type.question_select){
  47. this.btn_delete.active = true;
  48. }else{
  49. this.btn_delete.active = false;
  50. }
  51. this.res_node.getComponent(receive_res_item).initView(this.m_data,type)
  52. this.att_node.getComponent(receive_widget_item).updateView(this.m_data,type)
  53. this.btn_delete.off(Node.EventType.TOUCH_END)
  54. this.btn_delete.on(Node.EventType.TOUCH_END,()=>{
  55. if(this.m_call_back!=null){
  56. tools.show_dialog("确定删除此按钮?",()=>{
  57. this.m_call_back(this.m_index)
  58. this.node.destroy()
  59. this.node.removeFromParent()
  60. })
  61. }
  62. })
  63. this.updateScoreStatus()
  64. }
  65. updateScoreStatus() {
  66. if(this.score_editBox) {
  67. if(this.m_data.score==undefined||this.m_data.score==null) {
  68. this.m_data.score = 0
  69. }
  70. this.score_editBox.string = this.m_data.score.toString()
  71. }
  72. }
  73. protected onDestroy(): void {
  74. this.res_node.destroy()
  75. this.att_node.destroy()
  76. this.score_node.destroy()
  77. }
  78. }