base_view.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. let cur_page = `第${this.m_data.page_list.length>0?(this.m_cur_page+1):this.m_cur_page}页`
  190. let total_page = `共${this.m_data.page_list.length>0?this.m_data.page_list.length:0}页`
  191. this.lab_cur_page.getComponent(Label).string = `${cur_page}/${total_page}`
  192. this.updatePageView()
  193. this.m_edit_scene.cur_edit_scene_node.getComponent(cur_edit_scene).onClickScene()
  194. this.showBtn()
  195. }
  196. updatePageView(){
  197. for (let index = 0; index < this.content.children.length; index++) {
  198. const page_scene = this.content.children[index];
  199. if(this.m_cur_page===index){
  200. page_scene.active = true;
  201. }else{
  202. page_scene.active = false;
  203. }
  204. }
  205. // this.content.position = new Vec3(this.content.position.x - )
  206. }
  207. addScenePage(page_data:scene_item_data){
  208. let node:Node = null;
  209. if(page_data.is_full_screen){
  210. node = instantiate(this.temp_content);
  211. // if(page_data.page_list.length<=0){
  212. // let att = new attributes_data
  213. // page_data.page_list[0]
  214. // page_data.page_list[0].att.width = 1080;
  215. // page_data.page_list[0].att.height = 1920;
  216. // page_data.page_list[0].att.id = config.getNewId();
  217. // page_data.page_list[0].att.type = config.attributes_type.scene;
  218. // }
  219. if(page_data.att==null){
  220. page_data.att = new attributes_data
  221. page_data.att.width = 1080;
  222. page_data.att.height = 1920;
  223. page_data.att.id = config.getNewId();
  224. page_data.att.type = config.attributes_type.scene;
  225. }
  226. if(page_data.page_list[0]!=null){
  227. if(page_data.page_list[0].att===null){
  228. page_data.page_list[0].att = page_data.att;
  229. }
  230. // page_data.page_list[0] = page_data.att;
  231. }else{
  232. let n_scene_item = new scene_item_data(page_data.scene_diy_name,page_data.type,true);
  233. page_data.page_list.push(n_scene_item)
  234. page_data.page_list[0].att = page_data.att;
  235. }
  236. node.getComponent(scroll_scene).initFullView(page_data.att)
  237. node.parent = this.content;
  238. }else{
  239. node = instantiate(this.scroll_view.node);
  240. if(page_data.att==null){
  241. page_data.att = new attributes_data
  242. page_data.att.width = 1920;
  243. page_data.att.height = 1920;
  244. page_data.att.id = config.getNewId();
  245. page_data.att.type = config.attributes_type.scene;
  246. }
  247. node.getComponent(scroll_scene).initView(page_data.is_check_mask,page_data.att)
  248. node.parent = this.content;
  249. }
  250. node.getComponent(scroll_scene).setData(page_data)
  251. if(this.m_data.page_list.length>0){
  252. // let temp_data = this.m_data.page_list[this.m_cur_page];
  253. // console.log("page_data",page_data)
  254. this.initWidgets(node.getComponent(scroll_scene),page_data)
  255. }
  256. setTimeout(() => {
  257. this.m_edit_scene.cur_edit_scene_node.getComponent(cur_edit_scene).onClickScene()
  258. node.getComponent(scroll_scene).setCallBack(()=>{
  259. this.m_edit_scene.cur_edit_scene_node.getComponent(cur_edit_scene).onClickScene()
  260. })
  261. }, 0);
  262. }
  263. showBtn() {
  264. if(Attributes.is_show_more_scene_arrow==false) {
  265. return
  266. }
  267. if(this.m_data.type == config.Scene_Type_List.many_screen_switch_up_down) {
  268. if(this.m_data.page_list.length == 0) {
  269. this.btn_up.active = true
  270. this.btn_down.active = true
  271. return
  272. }
  273. this.btn_up.active = true
  274. this.btn_down.active = true
  275. if(this.m_cur_page==0) {
  276. this.btn_up.active = false
  277. } else if(this.m_cur_page >= this.m_data.page_list.length - 1) {
  278. this.btn_down.active = false
  279. }
  280. } else if(this.m_data.type == config.Scene_Type_List.many_screen_switch_left_right) {
  281. if(this.m_data.page_list.length == 0) {
  282. this.btn_left.active = true
  283. this.btn_right.active = true
  284. return
  285. }
  286. this.btn_left.active = true
  287. this.btn_right.active = true
  288. if(this.m_cur_page==0) {
  289. this.btn_left.active = false
  290. } else if(this.m_cur_page >= this.m_data.page_list.length - 1) {
  291. this.btn_right.active = false
  292. }
  293. }
  294. }
  295. hideAllBtn(){
  296. this.btn_down.active = false;
  297. this.btn_up.active = false;
  298. this.btn_left.active = false;
  299. this.btn_right.active = false;
  300. }
  301. public getContenView(){
  302. }
  303. public getData():scene_item_data{
  304. return this.m_data;
  305. }
  306. }