attributes_scene_setting.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { _decorator, Component, EditBox, instantiate, Node, Prefab } from 'cc';
  2. import { scene_tips_rule_data, ui_att_item } from '../../../data/data';
  3. import { scene_tips_rule_item } from './scene_tips_rule_item';
  4. import { config } from '../../config';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('attributes_scene_setting')
  7. export class attributes_scene_setting extends Component {
  8. @property(Prefab) itemPb:Prefab = null;
  9. @property(Node) rule_content:Node = null;
  10. @property(Node) btn_add_rule:Node = null;
  11. @property(Node) rule_find_tips:Node = null;
  12. @property(Node) tips:Node = null;
  13. @property(Node) answer:Node = null;
  14. @property(EditBox) edit_des:EditBox = null;
  15. private call_back = null;
  16. private m_data:scene_tips_rule_data = null;
  17. public initView(call){
  18. this.call_back = call;
  19. this.btn_add_rule.on(Node.EventType.TOUCH_END,()=>{
  20. this.addRule()
  21. })
  22. this.edit_des.node.on(EditBox.EventType.EDITING_DID_ENDED,()=>{
  23. this.m_data.scene_des = this.edit_des.string;
  24. this.update_att(this.m_data)
  25. })
  26. }
  27. public update_att(data:scene_tips_rule_data){
  28. this.m_data = data;
  29. this.rule_content.removeAllChildren()
  30. this.rule_content.destroyAllChildren()
  31. // if(this.rule_content.children.length===this.m_data.rule_list.length){
  32. // for (let index = 0; index < this.rule_content.children.length; index++) {
  33. // const element = this.rule_content.children[index];
  34. // element.getComponent(scene_tips_rule_item).initView(this.m_data.rule_list[index],this.m_data.rule_list.length,this.onTipsDelete.bind(this),config.attributes_list_type.scene_rule_tips)
  35. // }
  36. // }else{
  37. for (let index = 0; index < this.m_data.rule_list.length; index++) {
  38. let item = instantiate(this.itemPb)
  39. item.parent = this.rule_content
  40. item.getComponent(scene_tips_rule_item).initView(this.m_data.rule_list[index],this.m_data.rule_list.length,this.onTipsDelete.bind(this),config.attributes_list_type.scene_rule_tips)
  41. }
  42. // }
  43. this.edit_des.string = this.m_data.scene_des==undefined?"":this.m_data.scene_des;
  44. this.rule_find_tips.getComponent(scene_tips_rule_item).initView(this.m_data.rule_find_tips,-1,null,config.attributes_list_type.scene_rule_tips)
  45. this.tips.getComponent(scene_tips_rule_item).initView(this.m_data.tips_data.tips_tips,-1,null,config.attributes_list_type.scene_rule_tips)
  46. this.answer.getComponent(scene_tips_rule_item).initView(this.m_data.tips_data.tips_answer,-1,null,config.attributes_list_type.scene_rule_tips)
  47. }
  48. onTipsDelete(index:number){
  49. this.m_data.rule_list.splice(index,1)
  50. }
  51. addRule(){
  52. let item = instantiate(this.itemPb)
  53. item.parent = this.rule_content;
  54. let data = new ui_att_item
  55. item.getComponent(scene_tips_rule_item).initView(data,this.m_data.rule_list.length,this.onTipsDelete.bind(this),config.attributes_list_type.scene_rule_tips)
  56. this.m_data.rule_list.push(data)
  57. }
  58. }