new_frame.ts 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import { _decorator, Component, Director, director, EditBox, Label, Node, Sprite, SpriteFrame, UITransform } from 'cc';
  2. import { tools } from '../../tools';
  3. import { ani_frame, bag_item_data } from '../../../data/data';
  4. import { Attributes } from '../Attributes';
  5. import { frame_item } from './frame_item';
  6. import { control } from '../control';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('new_frame')
  9. export class new_frame extends Component {
  10. @property(Node) btn_sure:Node = null;
  11. @property(Node) btn_cancle:Node = null;
  12. @property(Node) next_time:Node = null;
  13. @property(Node) pos_x:Node = null;
  14. @property(Node) pos_y:Node = null;
  15. @property(Node) size_width:Node = null;
  16. @property(Node) size_height:Node = null;
  17. @property(Node) color:Node = null;
  18. @property(Node) transparent:Node = null;
  19. @property(Node) btn_select_res:Node = null;
  20. @property(Node) lab_origin_pos:Node = null;
  21. @property(Node) lab_origin_size:Node = null;
  22. @property(Node) btn_origin_res:Node = null;
  23. @property(Node) rotation:Node = null;
  24. @property(Node) hide_spr:Node = null;
  25. private m_up_frame:ani_frame = null;
  26. private m_create_call = null;
  27. private m_edit_call = null;
  28. private m_data:ani_frame = new ani_frame();
  29. private edit_status:boolean = false;
  30. private m_item:frame_item = null;
  31. public initView(create_call,edit_call){
  32. this.m_edit_call = edit_call;
  33. this.m_create_call = create_call;
  34. this.btn_cancle.on(Node.EventType.TOUCH_END,()=>{
  35. this.close()
  36. })
  37. this.btn_sure.on(Node.EventType.TOUCH_END,()=>{
  38. if(this.edit_status){
  39. this.edit_frame()
  40. }else{
  41. this.create_frame()
  42. }
  43. this.close()
  44. })
  45. this.btn_select_res.on(Node.EventType.TOUCH_END,()=>{
  46. tools.select_res_list((data:bag_item_data)=>{
  47. this.m_data.url = data.url;
  48. this.m_data.url_name = data.name;
  49. this.btn_select_res.getComponent(Sprite).spriteFrame = control.res_map.get(this.m_data.url_name)
  50. this.hide_spr.getComponent(Sprite).spriteFrame = this.btn_select_res.getComponent(Sprite).spriteFrame
  51. })
  52. })
  53. this.btn_origin_res.on(Node.EventType.TOUCH_END,()=>{
  54. let size = this.hide_spr.getComponent(UITransform).contentSize;
  55. this.m_data.size_width = size.width;
  56. this.m_data.size_height = size.height;
  57. this.size_width.getComponent(EditBox).string = this.m_data.size_width.toString()
  58. this.size_height.getComponent(EditBox).string = this.m_data.size_height.toString()
  59. })
  60. this.next_time.on('editing-did-ended', this.change, this);
  61. this.pos_x.on('editing-did-ended', this.change, this);
  62. this.pos_y.on('editing-did-ended', this.change, this);
  63. this.size_height.on('editing-did-ended', this.change, this);
  64. this.size_width.on('editing-did-ended', this.change, this);
  65. this.color.on('editing-did-ended', this.change, this);
  66. this.transparent.on('editing-did-ended', this.change, this);
  67. this.rotation.on('editing-did-ended', this.change, this);
  68. }
  69. close(){
  70. this.node.active = false;
  71. }
  72. edit_frame(){
  73. if(this.m_item!=null){
  74. this.m_item.setData(this.m_data)
  75. }
  76. if(this.m_edit_call!=null){
  77. this.m_edit_call()
  78. }
  79. }
  80. create_frame(){
  81. if(this.m_create_call!=null){
  82. this.updateData()
  83. let ani_frame_data = new ani_frame;
  84. ani_frame_data.next_time = this.m_data.next_time;
  85. ani_frame_data.pos_x = this.m_data.pos_x;
  86. ani_frame_data.pos_y = this.m_data.pos_y;
  87. ani_frame_data.size_width = this.m_data.size_width;
  88. ani_frame_data.size_height = this.m_data.size_height;
  89. ani_frame_data.color = this.m_data.color;
  90. ani_frame_data.transparent = this.m_data.transparent;
  91. ani_frame_data.url = this.m_data.url;
  92. ani_frame_data.url_name = this.m_data.url_name;
  93. ani_frame_data.rotation = this.m_data.rotation;
  94. console.log("ani_frame_data//",ani_frame_data)
  95. this.m_create_call(ani_frame_data)
  96. }
  97. }
  98. public show(up_frame:ani_frame=null){
  99. this.edit_status = false;
  100. this.m_up_frame = up_frame;
  101. this.node.active = true;
  102. let att = Attributes.Singleton.get_cur_att_data();
  103. let url_name = att.src_name
  104. let url = att.src;
  105. if(this.m_up_frame!=null){
  106. if(this.m_up_frame.url.length>0){
  107. url_name = this.m_up_frame.url_name
  108. url = this.m_up_frame.url;
  109. }
  110. }
  111. if(url_name.length>0){
  112. this.btn_select_res.getComponent(Sprite).spriteFrame = control.res_map.get(url_name)
  113. }
  114. let x = up_frame?up_frame.pos_x: Math.floor(att.x);
  115. let y = up_frame?up_frame.pos_y: Math.floor(att.y);
  116. this.m_data.url = url;
  117. this.m_data.pos_x =x;
  118. this.m_data.pos_y = y;
  119. this.m_data.size_width = up_frame?up_frame.size_width:att.width;
  120. this.m_data.size_height = up_frame?up_frame.size_height:att.height;
  121. this.m_data.url_name = up_frame?up_frame.url_name:att.src_name;
  122. if(this.m_data.rotation==undefined||this.m_data.rotation==null){
  123. this.m_data.rotation=0;
  124. }
  125. if(up_frame){
  126. if(up_frame.rotation==undefined||up_frame==null){
  127. up_frame.rotation = 0
  128. }
  129. }
  130. this.m_data.rotation = up_frame?up_frame.rotation:0;
  131. this.hide_spr.getComponent(Sprite).spriteFrame = this.btn_select_res.getComponent(Sprite).spriteFrame
  132. this.lab_origin_pos.getComponent(Label).string = `(x:${Math.floor(att.x)},y:${Math.floor(att.y)})`
  133. this.lab_origin_size.getComponent(Label).string = `(w:${att.width},h:${att.height})`
  134. this.initAtt()
  135. }
  136. public show_edit(item:frame_item,up_frame:ani_frame=null){
  137. this.m_up_frame = up_frame;
  138. this.node.active = true;
  139. this.m_data = item.getData();
  140. this.m_item = item;
  141. let url = this.m_data.url
  142. if(this.m_data.url.length>0){
  143. url = this.m_data.url;
  144. }else{
  145. if(this.m_up_frame!=null){
  146. if(this.m_up_frame.url.length>0){
  147. url = this.m_up_frame.url
  148. }
  149. }
  150. }
  151. this.edit_status = true;
  152. this.btn_select_res.getComponent(Sprite).spriteFrame = control.res_map.get(this.m_data.url_name)
  153. this.hide_spr.getComponent(Sprite).spriteFrame = this.btn_select_res.getComponent(Sprite).spriteFrame
  154. this.initAtt()
  155. }
  156. initAtt(){
  157. this.next_time.getComponent(EditBox).string = this.m_data.next_time.toString()
  158. this.pos_x.getComponent(EditBox).string = this.m_data.pos_x.toString()
  159. this.pos_y.getComponent(EditBox).string = this.m_data.pos_y.toString()
  160. this.size_width.getComponent(EditBox).string = this.m_data.size_width.toString()
  161. this.size_height.getComponent(EditBox).string = this.m_data.size_height.toString()
  162. this.color.getComponent(EditBox).string = this.m_data.color.toString()
  163. this.transparent.getComponent(EditBox).string = this.m_data.transparent.toString()
  164. this.rotation.getComponent(EditBox).string = this.m_data.rotation.toString()
  165. }
  166. change(){
  167. this.updateData()
  168. }
  169. updateData(){
  170. this.m_data.rotation = parseFloat(this.rotation.getComponent(EditBox).string)
  171. this.m_data.next_time = parseFloat(this.next_time.getComponent(EditBox).string)
  172. this.m_data.pos_x = parseInt(this.pos_x.getComponent(EditBox).string)
  173. this.m_data.pos_y = parseInt(this.pos_y.getComponent(EditBox).string)
  174. this.m_data.size_width = parseInt(this.size_width.getComponent(EditBox).string)
  175. this.m_data.size_height = parseInt(this.size_height.getComponent(EditBox).string)
  176. this.m_data.color = this.color.getComponent(EditBox).string
  177. this.m_data.transparent = parseInt(this.transparent.getComponent(EditBox).string)
  178. }
  179. }