GameSetting.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. cc.Class({
  2. extends: cc.BaseClass,
  3. properties: {
  4. m_SliderMusic: cc.Node,
  5. m_SliderSound: cc.Node,
  6. },
  7. ctor: function () {
  8. this.m_nNeedUpdate = 0;
  9. this.m_GameDef = null;
  10. },
  11. OnShowView: function () {
  12. try {
  13. if (!this.m_Ctrl) {
  14. this.m_Ctrl = new Object();
  15. this.m_Ctrl[window.SetKey_Music] = this.$('Page/0/Music@SettingMusic');
  16. this.m_Ctrl[window.SetKey_Sound] = this.$('Page/0/Sound@SettingSound');
  17. this.m_Ctrl[window.SetKey_Table_BG] = this.$('Page/0/TableBG@SettingTableBG');
  18. this.m_SelPageNode = this.$('ToggleContainer');
  19. if (this.m_SelPageNode) this.m_SelPageNode.active = false;
  20. }
  21. ShowO2I(this.node);
  22. } catch (e) {
  23. if (window.LOG_DEBUG) console.log(` GameSetting: OnShowView error => ${e}`);
  24. }
  25. },
  26. OnHideView: function () {
  27. HideI2O(this.node);
  28. },
  29. SetGame: function (GameDef) {
  30. this.m_GameDef = GameDef;
  31. for (var i in this.m_Ctrl) {
  32. if (this.m_Ctrl[i] && this.m_Ctrl[i].SetGame) this.m_Ctrl[i].SetGame(GameDef);
  33. }
  34. try {
  35. if (this.m_GameDef) {
  36. // 查找游戏设置
  37. var bExist = cc.gPreLoader.Exist_Prefab(`Setting_${this.m_GameDef.KIND_ID}`);
  38. if (bExist) {
  39. if (this.m_SelPageNode) this.m_SelPageNode.active = true;
  40. } else {
  41. if (this.m_SelPageNode) this.m_SelPageNode.active = false;
  42. }
  43. }
  44. } catch (e) {
  45. if (window.LOG_DEBUG) console.log(` GameSetting: SetGame error => ${e}`);
  46. }
  47. },
  48. OnChangePage: function (Index, PageNode) {
  49. try {
  50. if (Index == 0) {
  51. if (!this.m_GameDef) return;
  52. window.LoadSetting();
  53. window.LoadSetting(this.m_GameDef.KIND_ID);
  54. if (this.m_Ctrl[window.SetKey_Music].Load) this.m_Ctrl[window.SetKey_Music].Load();
  55. if (this.m_Ctrl[window.SetKey_Sound].Load) this.m_Ctrl[window.SetKey_Sound].Load();
  56. if (this.m_Ctrl[window.SetKey_Table_BG].Load) this.m_Ctrl[window.SetKey_Table_BG].Load();
  57. } else if (Index == 1) {
  58. if (!this.m_GameDef) return;
  59. window.LoadSetting();
  60. window.LoadSetting(this.m_GameDef.KIND_ID);
  61. this.ShowPrefabDLG(`Setting_${this.m_GameDef.KIND_ID}`, PageNode, function (Js) {
  62. this.m_Ctrl[this.m_GameDef.KIND_ID] = Js;
  63. if (this.m_Ctrl[this.m_GameDef.KIND_ID]) {
  64. if (this.m_Ctrl[this.m_GameDef.KIND_ID].SetGame) this.m_Ctrl[this.m_GameDef.KIND_ID].SetGame(this.m_GameDef);
  65. if (this.m_Ctrl[this.m_GameDef.KIND_ID].Load) this.m_Ctrl[this.m_GameDef.KIND_ID].Load();
  66. }
  67. }.bind(this));
  68. } else if (Index == 2) {
  69. window.LoadSetting();
  70. window.LoadSetting(this.m_GameDef.KIND_ID);
  71. }
  72. } catch (e) {
  73. if (window.LOG_DEBUG) console.log(` GameSetting: OnChangePage error => ${e}`);
  74. }
  75. },
  76. });