new_frame.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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) rotation_x:Node = null;
  25. @property(Node) rotation_y:Node = null;
  26. @property(Node) btn_rotation_center:Node = null;
  27. @property(Node) hide_spr:Node = null;
  28. private m_up_frame:ani_frame = null;
  29. private m_create_call = null;
  30. private m_edit_call = null;
  31. private m_data:ani_frame = new ani_frame();
  32. private edit_status:boolean = false;
  33. private m_item:frame_item = null;
  34. public initView(create_call,edit_call){
  35. this.m_edit_call = edit_call;
  36. this.m_create_call = create_call;
  37. this.btn_cancle.on(Node.EventType.TOUCH_END,()=>{
  38. this.close()
  39. })
  40. this.btn_sure.on(Node.EventType.TOUCH_END,()=>{
  41. if(this.edit_status){
  42. this.edit_frame()
  43. }else{
  44. this.create_frame()
  45. }
  46. this.close()
  47. })
  48. this.btn_select_res.on(Node.EventType.TOUCH_END,()=>{
  49. tools.select_res_list((data:bag_item_data)=>{
  50. this.m_data.url = data.url;
  51. this.m_data.url_name = data.name;
  52. // this.btn_select_res.getComponent(Sprite).spriteFrame = control.res_map.get(this.m_data.url_name)
  53. // this.hide_spr.getComponent(Sprite).spriteFrame = this.btn_select_res.getComponent(Sprite).spriteFrame
  54. this.hide_spr.getComponent(Sprite).spriteFrame = control.res_map.get(this.m_data.url_name)
  55. this.setupInitRotationX_Y()
  56. this.setupSprRatationAction()
  57. })
  58. })
  59. this.btn_origin_res.on(Node.EventType.TOUCH_END,()=>{
  60. let size = this.hide_spr.getComponent(UITransform).contentSize;
  61. this.m_data.size_width = size.width;
  62. this.m_data.size_height = size.height;
  63. this.size_width.getComponent(EditBox).string = this.m_data.size_width.toString()
  64. this.size_height.getComponent(EditBox).string = this.m_data.size_height.toString()
  65. })
  66. this.btn_rotation_center.on(Node.EventType.TOUCH_END, ()=> {
  67. this.setupInitRotationX_Y()
  68. },this)
  69. this.next_time.on('editing-did-ended', this.change, this);
  70. this.pos_x.on('editing-did-ended', this.change, this);
  71. this.pos_y.on('editing-did-ended', this.change, this);
  72. this.size_height.on('editing-did-ended', this.change, this);
  73. this.size_width.on('editing-did-ended', this.change, this);
  74. this.color.on('editing-did-ended', this.change, this);
  75. this.transparent.on('editing-did-ended', this.change, this);
  76. this.rotation.on('editing-did-ended', this.change, this);
  77. this.rotation_x.on('editing-did-ended', this.change, this);
  78. this.rotation_y.on('editing-did-ended', this.change, this);
  79. }
  80. close(){
  81. this.node.active = false;
  82. }
  83. edit_frame(){
  84. if(this.m_item!=null){
  85. this.m_item.setData(this.m_data)
  86. }
  87. if(this.m_edit_call!=null){
  88. this.m_edit_call()
  89. }
  90. }
  91. create_frame(){
  92. if(this.m_create_call!=null){
  93. this.updateData()
  94. let ani_frame_data = new ani_frame;
  95. ani_frame_data.next_time = this.m_data.next_time;
  96. ani_frame_data.pos_x = this.m_data.pos_x;
  97. ani_frame_data.pos_y = this.m_data.pos_y;
  98. ani_frame_data.size_width = this.m_data.size_width;
  99. ani_frame_data.size_height = this.m_data.size_height;
  100. ani_frame_data.color = this.m_data.color;
  101. ani_frame_data.transparent = this.m_data.transparent;
  102. ani_frame_data.url = this.m_data.url;
  103. ani_frame_data.url_name = this.m_data.url_name;
  104. ani_frame_data.rotation = this.m_data.rotation;
  105. // console.log('x=',this.m_data.rotation_x, 'y=',this.m_data.rotation_y)
  106. ani_frame_data.rotation_x = this.m_data.rotation_x;
  107. ani_frame_data.rotation_y = this.m_data.rotation_y;
  108. console.log("ani_frame_data//",ani_frame_data)
  109. this.m_create_call(ani_frame_data)
  110. }
  111. }
  112. public show(up_frame:ani_frame=null){
  113. console.log("show show show show show")
  114. this.edit_status = false;
  115. this.m_up_frame = up_frame;
  116. this.node.active = true;
  117. let att = Attributes.Singleton.get_cur_att_data();
  118. let url_name = att.src_name
  119. let url = att.src;
  120. if(this.m_up_frame!=null){
  121. if(this.m_up_frame.url.length>0){
  122. url_name = this.m_up_frame.url_name
  123. url = this.m_up_frame.url;
  124. }
  125. }
  126. // if(url_name.length>0){
  127. // this.btn_select_res.getComponent(Sprite).spriteFrame = control.res_map.get(url_name)
  128. // }
  129. // this.hide_spr.getComponent(Sprite).spriteFrame = this.btn_select_res.getComponent(Sprite).spriteFrame
  130. if(url_name.length>0){
  131. this.hide_spr.getComponent(Sprite).spriteFrame = control.res_map.get(url_name)
  132. }
  133. let x = up_frame?up_frame.pos_x: Math.floor(att.x);
  134. let y = up_frame?up_frame.pos_y: Math.floor(att.y);
  135. this.m_data.url = url;
  136. this.m_data.pos_x =x;
  137. this.m_data.pos_y = y;
  138. this.m_data.size_width = up_frame?up_frame.size_width:att.width;
  139. this.m_data.size_height = up_frame?up_frame.size_height:att.height;
  140. this.m_data.url_name = up_frame?up_frame.url_name:att.src_name;
  141. if(this.m_data.rotation==undefined||this.m_data.rotation==null){
  142. this.m_data.rotation=0;
  143. }
  144. if(up_frame){
  145. if(up_frame.rotation==undefined||up_frame==null){
  146. up_frame.rotation = 0
  147. }
  148. }
  149. this.m_data.rotation = up_frame?up_frame.rotation:0;
  150. this.lab_origin_pos.getComponent(Label).string = `(x:${Math.floor(att.x)},y:${Math.floor(att.y)})`
  151. this.lab_origin_size.getComponent(Label).string = `(w:${att.width},h:${att.height})`
  152. this.initAtt()
  153. }
  154. public show_edit(item:frame_item,up_frame:ani_frame=null){
  155. console.log("show_edit show_edit show_edit show_edit show_edit")
  156. this.m_up_frame = up_frame;
  157. this.node.active = true;
  158. this.m_data = item.getData();
  159. this.m_item = item;
  160. let url = this.m_data.url
  161. if(this.m_data.url.length>0){
  162. url = this.m_data.url;
  163. }else{
  164. if(this.m_up_frame!=null){
  165. if(this.m_up_frame.url.length>0){
  166. url = this.m_up_frame.url
  167. }
  168. }
  169. }
  170. this.edit_status = true;
  171. // this.btn_select_res.getComponent(Sprite).spriteFrame = control.res_map.get(this.m_data.url_name)
  172. // this.hide_spr.getComponent(Sprite).spriteFrame = this.btn_select_res.getComponent(Sprite).spriteFrame
  173. this.hide_spr.getComponent(Sprite).spriteFrame = control.res_map.get(this.m_data.url_name)
  174. this.initAtt()
  175. this.setupSprRatationAction()
  176. }
  177. initAtt(){
  178. this.next_time.getComponent(EditBox).string = this.m_data.next_time.toString()
  179. this.pos_x.getComponent(EditBox).string = this.m_data.pos_x.toString()
  180. this.pos_y.getComponent(EditBox).string = this.m_data.pos_y.toString()
  181. this.size_width.getComponent(EditBox).string = this.m_data.size_width.toString()
  182. this.size_height.getComponent(EditBox).string = this.m_data.size_height.toString()
  183. this.color.getComponent(EditBox).string = this.m_data.color.toString()
  184. this.transparent.getComponent(EditBox).string = this.m_data.transparent.toString()
  185. if(this.m_data.rotation==undefined){
  186. this.m_data.rotation = 0;
  187. }
  188. if(this.m_data.rotation_x==undefined) {
  189. this.m_data.rotation_x = 0;
  190. }
  191. if(this.m_data.rotation_y==undefined) {
  192. this.m_data.rotation_y = 0;
  193. }
  194. this.rotation.getComponent(EditBox).string = this.m_data.rotation.toString()
  195. if(this.edit_status) {
  196. this.rotation_x.getComponent(EditBox).string = this.m_data.rotation_x.toString()
  197. this.rotation_y.getComponent(EditBox).string = this.m_data.rotation_y.toString()
  198. } else {
  199. this.setupInitRotationX_Y()
  200. }
  201. }
  202. change(){
  203. this.setupSprRatationAction()
  204. this.updateData()
  205. }
  206. updateData(){
  207. this.m_data.rotation = parseFloat(this.rotation.getComponent(EditBox).string)
  208. this.m_data.rotation_x = parseFloat(this.rotation_x.getComponent(EditBox).string)
  209. this.m_data.rotation_y = parseFloat(this.rotation_y.getComponent(EditBox).string)
  210. this.m_data.next_time = parseFloat(this.next_time.getComponent(EditBox).string)
  211. this.m_data.pos_x = parseInt(this.pos_x.getComponent(EditBox).string)
  212. this.m_data.pos_y = parseInt(this.pos_y.getComponent(EditBox).string)
  213. this.m_data.size_width = parseInt(this.size_width.getComponent(EditBox).string)
  214. this.m_data.size_height = parseInt(this.size_height.getComponent(EditBox).string)
  215. this.m_data.color = this.color.getComponent(EditBox).string
  216. this.m_data.transparent = parseInt(this.transparent.getComponent(EditBox).string)
  217. }
  218. setupInitRotationX_Y() {
  219. this.m_data.rotation_x = this.m_data.size_width / 2
  220. this.m_data.rotation_y = this.m_data.size_height / 2
  221. this.rotation_x.getComponent(EditBox).string = this.m_data.rotation_x.toString()
  222. this.rotation_y.getComponent(EditBox).string = this.m_data.rotation_y.toString()
  223. }
  224. setupSprRatationAction() {
  225. this.hide_spr.angle = parseFloat(this.rotation.getComponent(EditBox).string)
  226. }
  227. }