ShenNong_Simple/assets/Script/GuideManager.ts
2024-10-30 15:28:42 +08:00

299 lines
9.7 KiB
TypeScript

import AudioManager from "./module/Music/AudioManager";
// 主游戏控制类
const {ccclass, property} = cc._decorator;
@ccclass
export default class GuideManager extends cc.Component {
@property(cc.Node)
Tip: cc.Node = null;
@property(cc.SpriteAtlas)
FoodPlist: cc.SpriteAtlas = null;
@property(cc.Node)
Btn_New: cc.Node = null;
@property(cc.Node)
Btn_Old: cc.Node = null;
@property(cc.Node)
Plant: cc.Node = null;
voiceSpriteFrame: cc.SpriteFrame; //是否可点击
needleTween: cc.Tween<cc.Sprite>;
func: () => void;
custom:number;
now_Food: string; //当前关卡名字信息
customData: { item: string; type: number; right: number; }[];
choice: number;
onLoad () {
this.custom = 1;
}
start () {
this.fit();
}
fit(){
var jg = cc.fx.GameTool.setFit();
if(!jg){
}
}
//初始化数据
init(){
this.voiceSpriteFrame = this.Plant.getChildByName("icon").getComponent(cc.Sprite).spriteFrame;``
this.node.getChildByName("nextBtn").active = false;
let name = cc.fx.GameConfig.GM_INFO.gameId + "_guide";
if(cc.fx.StorageMessage.getStorage(name) != null)
cc.fx.GameConfig.GM_INFO.guide = cc.fx.StorageMessage.getStorage(name);
if(cc.fx.GameConfig.GM_INFO.guide == false){
this.node.getChildByName("jumpBtn").active = true;
cc.tween(this.node.getChildByName("jumpBtn"))
.to(0.35,{opacity:255})
.start();
}
let tip = cc.fx.tipType.tipOne;
let label = this.node.getChildByName("tip1").getComponent(cc.Label);
cc.fx.GameTool.typingAni(label,tip,this.startGame.bind(this),this);
this.initData();
}
initData(){
this.customData = [
{
"item": "putao",
"type": 1,
"right":1,
},
{
"item": "taozi",
"type": 2,
"right":1,
},
{
"item": "putao",
"type": 2,
"right":2,
},
{
"item": "taozi",
"type": 1,
"right":2,
}
]
}
passVoice(){
// cc.fx.AudioManager._instance.playMusicGame();
let voice = this.node.getChildByName("voiceTip");
voice.getChildByName("startBtn").getComponent(cc.Button).interactable = false;
voice.getChildByName("playBtn").getComponent(cc.Button).interactable = false;
cc.tween(voice)
.to(0.5,{opacity:0})
.call(()=>{
voice.active = false;
})
.start();
setTimeout(() => {
this.init();
}, 1000);
}
playVoice(){
cc.fx.AudioManager._instance.playEffect("taozi_audio",null);
}
jumpClick(){
cc.director.loadScene("GameScene");
}
nextClick(){
//第一步
this.node.getChildByName("nextBtn").active = false;
let label = this.node.getChildByName("tip1").getComponent(cc.Label);
if(this.custom == 0){
cc.tween(this.node.getChildByName("tip1"))
.to(0.2,{opacity:0})
.call(() =>{
label.string = "";
})
.to(0.1,{opacity:255})
.call(() =>{
let tip = cc.fx.tipType.tipTwo;
cc.fx.GameTool.typingAni(label,tip,this.startGame.bind(this),this);
})
.start();
}
else if(this.custom == 1){
this.node.getChildByName("nextBtn").active = false;
this.node.getChildByName("jumpBtn").active = false;
cc.tween(this.node.getChildByName("tip1"))
.to(0.2,{opacity:0})
.call(() =>{
label.string = "";
this.nextLevel();
})
.start();
}
this.custom += 1;
}
nextLevel(){
this.choice = 0;
this.Btn_Old.active = true;
this.Btn_New.active = true;
this.Btn_Old.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = false;
let name = this.customData[this.custom-2].item;
if(this.customData[this.custom-2].type == 1){
this.Plant.getChildByName("name").getComponent(cc.Label).string = cc.fx.GameTool.getFoodName(name);
name = "prop_"+name;
this.Plant.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = this.FoodPlist["_spriteFrames"][name];
this.now_Food = name;
cc.tween(this.Plant)
.to(0.2,{opacity:255})
.call(()=>{
this.Btn_Old.getChildByName("nomal").getComponent(cc.Button).interactable = true;
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = true;
})
.start();
}
else{
this.Plant.getChildByName("name").getComponent(cc.Label).string = ""
this.Plant.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = this.voiceSpriteFrame;
let audioName = name + "_audio";
name = "audio"+ name;
this.now_Food = name;
cc.fx.AudioManager._instance.playEffect(audioName,null);
cc.tween(this.Plant)
.to(0.2,{opacity:255})
.call(()=>{
this.Btn_Old.getChildByName("nomal").getComponent(cc.Button).interactable = true;
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = true;
})
.start();
}
//关卡+1
}
//新植物按钮
click_Btn(customData,data){
//关掉计时器 处理逻辑之前,先行关掉按钮开关
if(data == "Btn_New"){
this.choice = 1;
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = false;
}
else if(data == "Btn_Old"){
this.choice = 2;
this.Btn_Old.getChildByName("nomal").getComponent(cc.Button).interactable = false;
}
let target = this[data];
var label = this.Tip.getChildByName("content").getComponent(cc.Label);
//正确
if(this.choice == this.customData[this.custom-2].right){
cc.fx.AudioManager._instance.playEffect("yes",null);
this.Tip.stopAllActions();
this.Tip.active = false;
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.Btn_Old.getChildByName("nomal").getComponent(cc.Button).interactable = false;
target.getChildByName("err").active = false;
target.getChildByName("correct").active = true;
setTimeout(() => {
this.Btn_New.getChildByName("nomal").active = true;
this.Btn_New.getChildByName("err").active = false;
this.Btn_New.getChildByName("correct").active = false;
this.Btn_Old.getChildByName("nomal").active = true;
this.Btn_Old.getChildByName("err").active = false;
this.Btn_Old.getChildByName("correct").active = false;
this.Btn_Old.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.custom += 1;
if(this.custom >= 6){
this.node.getChildByName("againBtn").active = true;
this.node.getChildByName("startBtn").active = true;
this.Btn_Old.active = false;
this.Btn_New.active = false;
cc.fx.GameConfig.GM_INFO.guide = false;
let name = cc.fx.GameConfig.GM_INFO.gameId + "_guide";
cc.fx.StorageMessage.setStorage(name,cc.fx.GameConfig.GM_INFO.guide);
}
else this.nextLevel();
}, 1000);
}
else{
cc.fx.AudioManager._instance.playEffect("yes",null);
var tipTemp = '葡萄刚才出现过呢'
this.Tip.active = true;
target.getChildByName("err").active = true;
target.getChildByName("correct").active = false;
switch((this.custom-2)){
case 0:
tipTemp = "这是这局游戏第一次出现葡萄";
break;
case 1:
tipTemp = "这是这局游戏第一次出现桃子";
break;
case 2:
tipTemp = '这不是这局游戏第一次出现葡萄';
break;
case 3:
tipTemp = "这不是这局游戏第一次出现桃子";
break;
}
label.string = tipTemp;
this.Tip.opacity = 255;
this.Tip.stopAllActions();
var self = this;
var action = cc.callFunc(function(){
self.Tip.active = false;
})
this.Tip.runAction(cc.sequence(cc.delayTime(2),cc.fadeIn(0.5),action))
}
}
//开始游戏
startGame(){
this.node.getChildByName("nextBtn").active = true;
cc.tween(this.node.getChildByName("nextBtn"))
.to(0.35,{opacity:255})
.start();
}
againClick(){
cc.director.loadScene("GuideScene");
}
onEnable () {
// cc.fx.Notifications.on("clickSun", this.clickSun, this);
}
onDisable () {
// cc.fx.Notifications.off("clickSun", this.clickSun);
}
update (dt) {
}
}