xx 1 year ago
parent
commit
b406ff2355

+ 9 - 0
assets/data/data.ts

@@ -481,4 +481,13 @@ export class LevelItemData{
     public ads_unlock:number = 0;//解锁广告数量
     public category_id:number = 0;//"0=>"无","1"=>"恐怖","2"=>"剧情","3"=>"怀旧","4"=>"脑洞","5"=>"推理"
     public label_id:number = 0; // "0"=>"无","1"=>"新","2"=>"热"
+}
+export class sysMessage extends Message{
+    public content :sys_config = null;
+}
+export class sys_config {
+    public sys_piped_music:string = null; //系统背景音乐
+    public sys_sound_music:string = null; //系统音效
+    public unlock_time:number = 0; //全部解锁时长 单位秒
+    public unlock_ads:number = 0; //	全部解锁 广告数量
 }

+ 1 - 0
assets/script/config.ts

@@ -279,6 +279,7 @@ export class config {
         ON_BOSS_HURT:"ON_BOSS_HURT",  //boss被攻击
         ON_WIN:"ON_WIN",  //胜利
         SHOW_TIPS:"SHOW_TIPS",  //显示一个提示
+        TOGGLE_YIN_YUE:"TOGGLE_YIN_YUE",  //开关音乐
     }
     static MSG_CODE = {
         SUCCESS: 10000,

+ 4 - 0
assets/script/http.ts

@@ -67,6 +67,10 @@ export class http  {
         return `/note/user/login`
     }
 
+    public static get_sys_config():string{
+        return `/smistatic/sys_config.json`
+    }
+
     public static get_level_info(id:number):string{
         return `/smistatic/level_info/${id}.json`
     }

+ 26 - 8
assets/script/run/gameManager.ts

@@ -1,6 +1,6 @@
 import { _decorator, AudioClip, AudioSource, Component, Node, Size, Sprite, SpriteFrame, sys, UITransform, Vec3 } from 'cc';
 import { game_run } from './game_run';
-import { attributes_data, LevelItemData, scene_item_data, task_data, ui_att_item, UserData, widget_item_data } from '../../data/data';
+import { attributes_data, LevelItemData, scene_item_data, sysMessage, task_data, ui_att_item, UserData, widget_item_data } from '../../data/data';
 import { config } from '../config';
 import { sceneManager } from './sceneManager';
 import { control } from '../edit/control';
@@ -21,6 +21,7 @@ export class gameManager extends Component {
     public static res_map:Map<string,SpriteFrame> = new Map()
     public static mp3_cache:Map<string,AudioClip> = new Map()
     private mLevelData:LevelItemData = null;
+    private static sys_data:sysMessage = null;
     @property(sceneManager) mSceneManager:sceneManager = null;
     protected start(): void {
         gameManager.Singleton  = this;
@@ -94,6 +95,15 @@ export class gameManager extends Component {
     public getLevelData(){
         return this.mLevelData;
     }
+
+    public  static setSysData(data:sysMessage){
+        gameManager.sys_data = data;
+    }
+
+    public static getSysData(){
+        return gameManager.sys_data;
+    }
+
     public static loadSceneMp3(){
 
     }
@@ -134,15 +144,20 @@ export class gameManager extends Component {
         this.onLaunch(()=>{
             this.mCurSceneIndex++;
             let not_scene = false;
-            while(this.mGameData[this.mCurSceneIndex].is_child_scene){
-                if(this.mCurSceneIndex<this.mGameData.length){
-                    this.mCurSceneIndex++;
-                }else{
-                    not_scene = true;
-                    break;
+            if(this.mCurSceneIndex>=this.mGameData.length){
+                not_scene = true;
+            }else{
+                while(this.mGameData[this.mCurSceneIndex].is_child_scene){
+                    if(this.mCurSceneIndex<this.mGameData.length){
+                        this.mCurSceneIndex++;
+                    }else{
+                        not_scene = true;
+                        break;
+                    }
+                 
                 }
-             
             }
+ 
            if(!not_scene){
                 this.startLevelGame()
            }else{
@@ -246,6 +261,9 @@ export class gameManager extends Component {
         this.scheduleOnce(()=>{
             this.startGame()
         },0.5)
+        if(gameManager.Singleton.getLevelData()){
+            this.mSceneManager.playMusic(this.mLevelData.piped_music,true)
+        }
     }
 
     public loadScene(pages: scene_item_data[],type:number){

+ 0 - 1
assets/script/run/game_list_view/game_list.ts

@@ -55,7 +55,6 @@ export class game_list extends Component {
             item.parent = this.content;
             item.getComponent(level_list_item).initView(this.onItemClick.bind(this),element)
         }
-
         // if(gameManager.getUserData().select_page*6>this.m_data.content.tool_number){
 
         // }

+ 11 - 1
assets/script/run/loading_view/loading_view.ts

@@ -1,5 +1,5 @@
 import { _decorator, Component, Node, ProgressBar, sys } from 'cc';
-import { UserData } from '../../../data/data';
+import { sysMessage, UserData } from '../../../data/data';
 import { gameManager } from '../gameManager';
 import { http } from '../../http';
 import { config } from '../../config';
@@ -22,6 +22,16 @@ export class loading_view extends Component {
             this.loading_bar.getComponent(ProgressBar).progress +=0.1;
             let progress = this.loading_bar.getComponent(ProgressBar).progress
             switch(progress){
+                case 0.2:
+                    this.m_pause_status = true;
+                    http.run_get(http.get_sys_config(),(err,data)=>{
+                        if(!err){
+                            let sys_data:sysMessage = JSON.parse(data)
+                            gameManager.setSysData(sys_data)
+                            this.m_pause_status = false;
+                        }
+                    })
+                break;
                 case 0.5:
                     this.m_pause_status = true;
                     let user_data = gameManager.getUserData()

+ 2 - 0
assets/script/run/login_view/login_view.ts

@@ -2,6 +2,7 @@ import { _decorator, Component, Node } from 'cc';
 import { yinyue } from './yinyue';
 import { yinxiao } from './yinxiao';
 import { peiyin } from './peiyin';
+import { gameManager } from '../gameManager';
 const { ccclass, property } = _decorator;
 
 @ccclass('login_view')
@@ -19,6 +20,7 @@ export class login_view extends Component {
                 this.m_start_game_call()
             }
         })
+        gameManager.Singleton.getSceneManager().playMusic(gameManager.getSysData().content.sys_piped_music,true)
         this.yinyue.getComponent(yinyue).initView()
         this.yinxiao.getComponent(yinxiao).initView()
         this.peiyin.getComponent(peiyin).initView()

+ 3 - 0
assets/script/run/login_view/yinyue.ts

@@ -1,5 +1,7 @@
 import { _decorator, Component, Node } from 'cc';
 import { gameManager } from '../gameManager';
+import { ClientEvent } from '../../clientEvent';
+import { config } from '../../config';
 const { ccclass, property } = _decorator;
 
 @ccclass('yinyue')
@@ -29,6 +31,7 @@ export class yinyue extends Component {
         }
         gameManager.getStaticUserData().isOpenYinYue = this.isOpen;
         gameManager.saveUserData()
+        ClientEvent.dispatchEvent(config.EventRun.TOGGLE_YIN_YUE)
     }
 }
 

+ 15 - 0
assets/script/run/sceneManager.ts

@@ -4,6 +4,7 @@ import { config } from '../config';
 import { game_run } from './game_run';
 import { gameManager } from './gameManager';
 import { tools } from '../tools';
+import { ClientEvent } from '../clientEvent';
 const { ccclass, property } = _decorator;
 
 @ccclass('sceneManager')
@@ -15,6 +16,17 @@ export class sceneManager extends Component {
     private mSceneData: scene_item_data = null;
     public init(gm:gameManager){
         this.mGameManager = gm;
+        ClientEvent.off(config.EventRun.TOGGLE_YIN_YUE,this.updateStatus.bind(this),this)
+        ClientEvent.on(config.EventRun.TOGGLE_YIN_YUE,this.updateStatus.bind(this),this)
+    }
+
+    public updateStatus(){
+        if(!gameManager.getUserData().isOpenYinYue){
+            this.getSound().stop()
+        }else{
+            this.getSound().loop = true;
+            this.getSound().play()
+        }
     }
 
     public getSceneTask(){
@@ -22,6 +34,9 @@ export class sceneManager extends Component {
     }
 
     public playMusic(path:string, loop: boolean){
+        if(!gameManager.getUserData().isOpenYinYue){
+            return
+        }
         let call_back = (err: any, clip: AudioClip)=> {
             if(!err){
                 gameManager.mp3_cache.set(path,clip)

+ 15 - 4
assets/script/run/scene_layer.ts

@@ -32,11 +32,22 @@ export class scene_layer extends Component {
     }
     beActive(widgetId:number,event:event_item){
         if(event.type===config.event_type.play_sound){
-            if(event.event_item_play_sound_data!=null){
-                this.getAudioSource().clip = gameManager.getCacheSoundByName(event.event_item_play_sound_data.sound_res.url);
-                this.getAudioSource().play();
-                this.getAudioSource().volume = 1;
+            let is_can_play = true;
+            if(gameManager.Singleton.getLevelData()){
+                if(gameManager.getUserData().isOpenPeiYin){
+                    is_can_play = true;
+                }else{
+                    is_can_play = false;
+                }
             }
+            if(is_can_play){
+                if(event.event_item_play_sound_data!=null){
+                    this.getAudioSource().clip = gameManager.getCacheSoundByName(event.event_item_play_sound_data.sound_res.url);
+                    this.getAudioSource().play();
+                    this.getAudioSource().volume = 1;
+                }
+            }
+   
         }
     }
     changePage(page:number){

+ 0 - 1
assets/script/run/top_layer.ts

@@ -148,7 +148,6 @@ export class top_layer extends Component {
         }else{
             this.rule_view.getComponent(rule_view).initView(scene_data.att.scene_rule_tips_data.rule_list)
         }
-       
 
     }
 }

+ 8 - 1
assets/script/run/ui/sound_text_content.ts

@@ -26,7 +26,14 @@ export class sound_text_content extends Component {
         this.m_audio_clip = ac;
         this.lab_text.getComponent(Label).string = this.mData.text;
         this.item_node.position = new Vec3(this.item_node.position.x,this.mData.pos_y)
-        this.onPlaySound()
+        if(gameManager.Singleton.getLevelData()){
+            if(gameManager.getUserData().isOpenPeiYin){
+                this.onPlaySound()
+            }
+        }else{
+            this.onPlaySound()
+        }
+   
     }
 
     getAudioSource(){