base_view.ts 11 KB

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