base_view.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. import { _decorator, Component, instantiate, Label, Node, Prefab, ScrollView, UITransform, Vec3 } from 'cc';
  2. import { edit_scene } from './edit_scene';
  3. import { scene_select_list } from './scene_select_list';
  4. import { attributes_data, scene_item_data } from '../../data/data';
  5. import { config } from '../config';
  6. import { scroll_scene } from './scroll_scene';
  7. import { tools } from '../tools';
  8. import { cur_edit_scene } from './cur_edit_scene';
  9. import { widget_item } from './widget_item';
  10. import { ClientEvent } from '../clientEvent';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('base_view')
  13. export class base_view extends Component {
  14. @property(ScrollView) scroll_view:ScrollView = null;
  15. @property(Node) btn_left:Node = null;
  16. @property(Node) btn_right:Node = null;
  17. @property(Node) btn_up:Node = null;
  18. @property(Node) btn_down:Node = null;
  19. @property(Node) content:Node = null;
  20. @property(Node) temp_content:Node = null;
  21. @property(Node) btn_add_page:Node = null;
  22. @property(Node) btn_delete_page:Node = null;
  23. @property(Node) lab_cur_page:Node = null;
  24. @property(Prefab) widget_prefab:Prefab = null;
  25. private m_edit_scene:edit_scene = null;
  26. private m_data:scene_item_data = null;
  27. private m_cur_page:number = 0;
  28. public initView(_edit_scene:edit_scene){
  29. this.m_edit_scene = _edit_scene;
  30. this.btn_add_page.on(Node.EventType.TOUCH_END,()=>{
  31. this.add_page()
  32. })
  33. this.btn_delete_page.on(Node.EventType.TOUCH_END,()=>{
  34. this.delete_page()
  35. })
  36. let data = this.m_edit_scene.getCurSelectScene()
  37. if(data!=null){
  38. this.m_data = data;
  39. this.init()
  40. }
  41. this.btn_down.on(Node.EventType.TOUCH_END,()=>{
  42. this.next_page()
  43. })
  44. this.btn_up.on(Node.EventType.TOUCH_END,()=>{
  45. this.up_page()
  46. })
  47. this.btn_left.on(Node.EventType.TOUCH_END,()=>{
  48. this.up_page()
  49. })
  50. this.btn_right.on(Node.EventType.TOUCH_END,()=>{
  51. this.next_page()
  52. })
  53. this.updatePageNumber()
  54. ClientEvent.on(config.Event.ChangeSelectPage,this.ChangeSelectPage,this)
  55. }
  56. protected onDestroy(): void {
  57. ClientEvent.off(config.Event.ChangeSelectPage,this.ChangeSelectPage,this)
  58. }
  59. ChangeSelectPage(page:number){
  60. if(page!=this.m_cur_page){
  61. this.m_cur_page = page
  62. this.updatePageNumber()
  63. }
  64. }
  65. public getAtt(){
  66. }
  67. on_add_page(data:scene_item_data){
  68. this.m_data.page_list.push(data)
  69. this.addScenePage(data)
  70. this.updatePageNumber()
  71. }
  72. on_delete_page(){
  73. let view = this.getCurPageView()
  74. if(view!=null){
  75. view.removeFromParent()
  76. }
  77. this.updatePageNumber()
  78. this.up_page()
  79. }
  80. delete_page(){
  81. if(this.m_data.page_list.length<=0){
  82. return tools.showToast("当前无场景页删除!")
  83. }
  84. tools.show_dialog("是否确定删除当前的场景页",()=>{
  85. this.m_data.page_list.splice(this.m_cur_page,1)
  86. this.on_delete_page()
  87. })
  88. }
  89. add_page(){
  90. tools.add_scene_page(this.on_add_page.bind(this))
  91. }
  92. init(){
  93. if(this.m_data.page_list.length<=0||this.m_data.type===config.Scene_Type_List.single_screen){
  94. this.hideAllBtn()
  95. }else{
  96. }
  97. // console.log("this.m_data",this.m_data)
  98. if(this.m_data.type===config.Scene_Type_List.single_screen){
  99. this.btn_add_page.active = false;
  100. this.btn_delete_page.active = false;
  101. this.lab_cur_page.active = false;
  102. this.m_data.is_full_screen = true;
  103. if(this.m_data.page_list.length<=0){
  104. let n_s = new scene_item_data("",config.Scene_Type_List.single_screen,true)
  105. this.m_data.page_list.push(n_s)
  106. }
  107. this.addScenePage(this.m_data.page_list[0])
  108. }else{
  109. this.hideAllBtn()
  110. this.btn_add_page.active = true;
  111. this.btn_delete_page.active = true;
  112. this.lab_cur_page.active = true;
  113. if(this.m_data.type===config.Scene_Type_List.many_screen_switch_up_down){
  114. this.btn_down.active = true;
  115. this.btn_up.active = true;
  116. }else{
  117. this.btn_left.active = true;
  118. this.btn_right.active = true;
  119. }
  120. for (let index = 0; index < this.m_data.page_list.length; index++) {
  121. const data = this.m_data.page_list[index];
  122. this.addScenePage(data)
  123. }
  124. }
  125. }
  126. initWidgets(scene:scroll_scene,data:scene_item_data){
  127. for (let index = 0; index < data.page_widget_list.length; index++) {
  128. const widget_data = data.page_widget_list[index];
  129. let node = instantiate(this.widget_prefab)
  130. node.getComponent(widget_item).initWidgetByScene(widget_data,widget_data.att)
  131. scene.addWidget(node)
  132. }
  133. }
  134. up_page(){
  135. if(this.m_data.page_list.length<=0){
  136. tools.showToast("当前没有分页")
  137. return;
  138. }
  139. if((this.m_cur_page-1)<0){
  140. this.m_cur_page = this.m_data.page_list.length-1;
  141. }else{
  142. this.m_cur_page -=1;
  143. }
  144. this.updatePageNumber()
  145. }
  146. next_page(){
  147. if(this.m_data.page_list.length<=0){
  148. tools.showToast("当前没有分页")
  149. return;
  150. }
  151. if((this.m_cur_page+1)>=this.m_data.page_list.length){
  152. this.m_cur_page = 0;
  153. }else{
  154. this.m_cur_page +=1;
  155. }
  156. this.updatePageNumber()
  157. }
  158. public cur_page(){
  159. return this.m_cur_page
  160. }
  161. getCurPageData(){
  162. if(this.m_data.page_list.length<=0){
  163. return null;
  164. }
  165. return this.m_data.page_list[this.m_cur_page]
  166. }
  167. getCurPageView(){
  168. if(this.content.children.length<=0){
  169. return null;
  170. }
  171. return this.content.children[this.m_cur_page]
  172. }
  173. updatePageNumber(){
  174. this.lab_cur_page.getComponent(Label).string = `第${this.m_data.page_list.length>0?(this.m_cur_page+1):this.m_cur_page}页`
  175. this.updatePageView()
  176. this.m_edit_scene.cur_edit_scene_node.getComponent(cur_edit_scene).onClickScene()
  177. if(this.m_data.type == config.Scene_Type_List.many_screen_switch_up_down) {
  178. if(this.m_data.page_list.length == 0) {
  179. this.btn_up.active = true
  180. this.btn_down.active = true
  181. return
  182. }
  183. this.btn_up.active = true
  184. this.btn_down.active = true
  185. if(this.m_cur_page==0) {
  186. this.btn_up.active = false
  187. } else if(this.m_cur_page >= this.m_data.page_list.length - 1) {
  188. this.btn_down.active = false
  189. }
  190. } else if(this.m_data.type == config.Scene_Type_List.many_screen_switch_left_right) {
  191. if(this.m_data.page_list.length == 0) {
  192. this.btn_left.active = true
  193. this.btn_right.active = true
  194. return
  195. }
  196. this.btn_left.active = true
  197. this.btn_right.active = true
  198. if(this.m_cur_page==0) {
  199. this.btn_left.active = false
  200. } else if(this.m_cur_page >= this.m_data.page_list.length - 1) {
  201. this.btn_right.active = false
  202. }
  203. }
  204. }
  205. updatePageView(){
  206. for (let index = 0; index < this.content.children.length; index++) {
  207. const page_scene = this.content.children[index];
  208. if(this.m_cur_page===index){
  209. page_scene.active = true;
  210. }else{
  211. page_scene.active = false;
  212. }
  213. }
  214. // this.content.position = new Vec3(this.content.position.x - )
  215. }
  216. addScenePage(page_data:scene_item_data){
  217. let node:Node = null;
  218. if(page_data.is_full_screen){
  219. node = instantiate(this.temp_content);
  220. // if(page_data.page_list.length<=0){
  221. // let att = new attributes_data
  222. // page_data.page_list[0]
  223. // page_data.page_list[0].att.width = 1080;
  224. // page_data.page_list[0].att.height = 1920;
  225. // page_data.page_list[0].att.id = config.getNewId();
  226. // page_data.page_list[0].att.type = config.attributes_type.scene;
  227. // }
  228. if(page_data.att==null){
  229. page_data.att = new attributes_data
  230. page_data.att.width = 1080;
  231. page_data.att.height = 1920;
  232. page_data.att.id = config.getNewId();
  233. page_data.att.type = config.attributes_type.scene;
  234. }
  235. if(page_data.page_list[0]!=null){
  236. if(page_data.page_list[0].att===null){
  237. page_data.page_list[0].att = page_data.att;
  238. }
  239. // page_data.page_list[0] = page_data.att;
  240. }else{
  241. let n_scene_item = new scene_item_data(page_data.scene_diy_name,page_data.type,true);
  242. page_data.page_list.push(n_scene_item)
  243. page_data.page_list[0].att = page_data.att;
  244. }
  245. node.getComponent(scroll_scene).initFullView(page_data.att)
  246. node.parent = this.content;
  247. }else{
  248. node = instantiate(this.scroll_view.node);
  249. if(page_data.att==null){
  250. page_data.att = new attributes_data
  251. page_data.att.width = 1920;
  252. page_data.att.height = 1920;
  253. page_data.att.id = config.getNewId();
  254. page_data.att.type = config.attributes_type.scene;
  255. }
  256. node.getComponent(scroll_scene).initView(page_data.is_check_mask,page_data.att)
  257. node.parent = this.content;
  258. }
  259. node.getComponent(scroll_scene).setData(page_data)
  260. if(this.m_data.page_list.length>0){
  261. // let temp_data = this.m_data.page_list[this.m_cur_page];
  262. // console.log("page_data",page_data)
  263. this.initWidgets(node.getComponent(scroll_scene),page_data)
  264. }
  265. setTimeout(() => {
  266. this.m_edit_scene.cur_edit_scene_node.getComponent(cur_edit_scene).onClickScene()
  267. node.getComponent(scroll_scene).setCallBack(()=>{
  268. this.m_edit_scene.cur_edit_scene_node.getComponent(cur_edit_scene).onClickScene()
  269. })
  270. }, 0);
  271. }
  272. hideAllBtn(){
  273. this.btn_down.active = false;
  274. this.btn_up.active = false;
  275. this.btn_left.active = false;
  276. this.btn_right.active = false;
  277. }
  278. public getContenView(){
  279. }
  280. public getData():scene_item_data{
  281. return this.m_data;
  282. }
  283. }