feat: group 1.0.0
This commit is contained in:
@@ -1,7 +1,17 @@
|
||||
import { _decorator, Component, Node, tween, UITransform, Vec3 } from "cc";
|
||||
import {
|
||||
_decorator,
|
||||
Color,
|
||||
Component,
|
||||
Node,
|
||||
Sprite,
|
||||
tween,
|
||||
UITransform,
|
||||
Vec3,
|
||||
} from "cc";
|
||||
import { EventDispatcher } from "../libs/EventDispatcher";
|
||||
import { GlobalData } from "../config/GlobalData";
|
||||
import { GameState } from "../config/Config";
|
||||
import Common from "../libs/Common";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("ContonueModal")
|
||||
@@ -37,6 +47,8 @@ export class ContonueModal extends Component {
|
||||
showModal() {
|
||||
// 游戏暂停
|
||||
GlobalData.gameState = GameState.PAUSED;
|
||||
// 设置 页面 背景色
|
||||
Common.setPageBackgroundColorAsDino(this.node);
|
||||
// 显示继续游戏弹窗
|
||||
this.node.active = true;
|
||||
// 操作提示动画
|
||||
@@ -76,6 +88,11 @@ export class ContonueModal extends Component {
|
||||
|
||||
// 播放提示1的动画
|
||||
playTipAnimation(tNode: Node) {
|
||||
// 设置小恐龙颜色
|
||||
tNode.getChildByName("dino").getComponent(Sprite).color = new Color(
|
||||
GlobalData.currentDinoInfo.dinoColor,
|
||||
);
|
||||
|
||||
// 显示提示1
|
||||
tNode.active = true;
|
||||
// 获取提示节点的位置
|
||||
|
||||
163
assets/seripts/ui/MoodListItem.ts
Normal file
163
assets/seripts/ui/MoodListItem.ts
Normal file
@@ -0,0 +1,163 @@
|
||||
import {
|
||||
_decorator,
|
||||
Color,
|
||||
Component,
|
||||
Label,
|
||||
Node,
|
||||
Sprite,
|
||||
tween,
|
||||
UIOpacity,
|
||||
Vec3,
|
||||
} from "cc";
|
||||
import { GlobalData } from "../config/GlobalData";
|
||||
import AudioEffect from "../libs/AudioEffect";
|
||||
import { EventDispatcher } from "../libs/EventDispatcher";
|
||||
import Common from "../libs/Common";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
interface MoodItem {
|
||||
id: number;
|
||||
title: string;
|
||||
bestScore: number;
|
||||
isLocked: number;
|
||||
unlockGold: number;
|
||||
}
|
||||
|
||||
@ccclass("MoodListItem")
|
||||
export class MoodListItem extends Component {
|
||||
// 保存当前列表项数据对象
|
||||
private itemObj: MoodItem = null;
|
||||
|
||||
start() {
|
||||
// 监听当前节点的点击事件
|
||||
this.node.on(Node.EventType.TOUCH_END, this.onClickMusicItem, this);
|
||||
// 监听选中音乐列表某一个 item 事件
|
||||
EventDispatcher.getTarget().on(
|
||||
EventDispatcher.SELECT_MOOD_ITEM,
|
||||
this.onSelectMusicItem,
|
||||
this,
|
||||
);
|
||||
// 监听解锁音乐列表某一个 item 事件
|
||||
EventDispatcher.getTarget().on(
|
||||
EventDispatcher.UNLOCK_MOOD_ITEM,
|
||||
this.onUnlockMusicItem,
|
||||
this,
|
||||
);
|
||||
// 设置小恐龙颜色
|
||||
this.setDionColor();
|
||||
}
|
||||
|
||||
onClickMusicItem() {
|
||||
// 播放点击音效
|
||||
AudioEffect.playClickAudio();
|
||||
// 选中当前列表项
|
||||
this.setSelected();
|
||||
// 设置动画 先缩小到 0.9 再还原到 1
|
||||
tween(this.node)
|
||||
.to(0.1, { scale: new Vec3(0.9, 0.9, 1) })
|
||||
.to(0.1, { scale: new Vec3(1, 1, 1) })
|
||||
.start();
|
||||
}
|
||||
|
||||
onUnlockMusicItem(id: number) {
|
||||
// 如果当前列表项的 id 与不是解锁的音乐 id 不处理
|
||||
if (this.itemObj?.id != id) return;
|
||||
// 设置当前音乐项未解锁状态
|
||||
this.itemObj.isLocked = 0;
|
||||
// 刷新有无锁定状态显示
|
||||
this.setLockState(this.itemObj);
|
||||
// 设置选中状态
|
||||
this.setSelected();
|
||||
// 存储解锁状态
|
||||
Common.unlockMusic(id);
|
||||
}
|
||||
|
||||
// 选中音乐列表某一个 item 事件
|
||||
onSelectMusicItem(id: number) {
|
||||
if (this.itemObj.id == id) return;
|
||||
// 设置未选中状态
|
||||
this.setUnSelected();
|
||||
}
|
||||
|
||||
// 初始化列表项节点
|
||||
init(item: MoodItem) {
|
||||
// 保存当前列表项数据对象
|
||||
this.itemObj = item;
|
||||
|
||||
// 设置列表项的标题
|
||||
this.node.getChildByName("music_title").getComponent(Label).string =
|
||||
item.title;
|
||||
// 设置有无锁定状态显示
|
||||
this.setLockState(item);
|
||||
// 如果当前列表项是默认选中项 则设置选中状态
|
||||
if (item.id == GlobalData.selectedMusicID) {
|
||||
this.setSelected();
|
||||
}
|
||||
// // 设置列表项的金币数;
|
||||
// this.node.getChildByName("gold").getComponent(Label).string =
|
||||
// this.itemObj.unlockGold.toString();
|
||||
// 监听点击事件
|
||||
// moodItem.on(Node.EventType.TOUCH_END, this.onClickMusicItem, this);
|
||||
}
|
||||
|
||||
// 设置有无锁定状态显示
|
||||
setLockState(item: MoodItem) {
|
||||
if (item.isLocked == 0) {
|
||||
// 解锁状态
|
||||
this.node.getChildByName("best_score").active = true;
|
||||
this.node.getChildByName("locked").active = false;
|
||||
this.node
|
||||
.getChildByName("best_score")
|
||||
.getChildByName("score_num")
|
||||
.getComponent(Label).string = this.itemObj.bestScore.toString();
|
||||
} else {
|
||||
// 锁定状态
|
||||
this.node.getChildByName("best_score").active = false;
|
||||
this.node.getChildByName("locked").active = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 设置选中状态
|
||||
setSelected() {
|
||||
// 获取透明度组件
|
||||
const opacity = this.node
|
||||
.getChildByName("list_item_bg")
|
||||
.getComponent(UIOpacity);
|
||||
// 设置透明度为255
|
||||
opacity.opacity = 200;
|
||||
// 获取选中图标节点
|
||||
const selectNode = this.node.getChildByName("dino");
|
||||
|
||||
selectNode.active = true;
|
||||
// 派发选中某一个 item 事件
|
||||
EventDispatcher.getTarget().emit(
|
||||
EventDispatcher.SELECT_MOOD_ITEM,
|
||||
this.itemObj.id,
|
||||
);
|
||||
}
|
||||
|
||||
// 设置未选中状态
|
||||
setUnSelected() {
|
||||
// 获取透明度组件
|
||||
const opacity = this.node
|
||||
.getChildByName("list_item_bg")
|
||||
.getComponent(UIOpacity);
|
||||
// 设置透明度为255
|
||||
opacity.opacity = 255;
|
||||
// 获取选中图标节点
|
||||
const selectNode = this.node.getChildByName("dino");
|
||||
selectNode.active = false;
|
||||
}
|
||||
|
||||
// 设置小恐龙颜色
|
||||
setDionColor() {
|
||||
// 获取选中图标节点
|
||||
const selectNode = this.node.getChildByName("dino");
|
||||
// 设置选中图标节点的颜色为小恐龙颜色
|
||||
selectNode.getComponent(Sprite).color = new Color(
|
||||
GlobalData.currentDinoInfo.dinoColor,
|
||||
);
|
||||
}
|
||||
|
||||
update(deltaTime: number) {}
|
||||
}
|
||||
9
assets/seripts/ui/MoodListItem.ts.meta
Normal file
9
assets/seripts/ui/MoodListItem.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "bca91580-94ca-4df5-9706-eb1184b1846d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { _decorator, Component, director, Node } from "cc";
|
||||
import { EventDispatcher } from "../libs/EventDispatcher";
|
||||
import Common from "../libs/Common";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("PauseModal")
|
||||
@@ -20,6 +21,8 @@ export class PauseModal extends Component {
|
||||
// 显示弹窗
|
||||
showModal() {
|
||||
this.node.active = true;
|
||||
// 设置暂停游戏背景色
|
||||
Common.setPageBackgroundColorAsDino(this.node);
|
||||
// 暂停游戏
|
||||
director.pause();
|
||||
// 发送暂停游戏事件
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import {
|
||||
_decorator,
|
||||
Color,
|
||||
Component,
|
||||
director,
|
||||
Label,
|
||||
Node,
|
||||
Sprite,
|
||||
tween,
|
||||
UITransform,
|
||||
Vec3,
|
||||
@@ -157,6 +159,12 @@ export class ResultModal extends Component {
|
||||
|
||||
// 执行提示动画
|
||||
playTipAni() {
|
||||
// 设置提示 dino 颜色
|
||||
const dinoInfo = GlobalData.currentDinoInfo;
|
||||
const dinoColor = new Color(dinoInfo.dinoColor);
|
||||
// 设置提示 dino 颜色
|
||||
this.tipNode.getChildByName("dino").getComponent(Sprite).color = dinoColor;
|
||||
|
||||
// 开启提示
|
||||
this.tipNode.active = true;
|
||||
// 获取提示的位置
|
||||
|
||||
35
assets/seripts/ui/Tipcontrol.ts
Normal file
35
assets/seripts/ui/Tipcontrol.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { _decorator, Component, Label, Node, tween, Vec3 } from "cc";
|
||||
import { EventDispatcher } from "../libs/EventDispatcher";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("TipControl")
|
||||
export class TipControl extends Component {
|
||||
//提示标签
|
||||
@property(Label)
|
||||
tipLabel: Label | null = null;
|
||||
start() {
|
||||
//默认位置,屏幕外
|
||||
this.node.setPosition(0, -1000);
|
||||
//监听tips msg事件
|
||||
EventDispatcher.getTarget().on(
|
||||
EventDispatcher.TIP_MSG,
|
||||
this.showTips,
|
||||
this,
|
||||
);
|
||||
}
|
||||
|
||||
//显示提示
|
||||
showTips(msg: string) {
|
||||
this.tipLabel.string = msg;
|
||||
tween(this.node)
|
||||
.to(0.2, { position: new Vec3(0, 0, 0) })
|
||||
.delay(1)
|
||||
.to(0.2, { position: new Vec3(0, 1000, 0) })
|
||||
.call(() => {
|
||||
this.node.setPosition(0, -1000);
|
||||
})
|
||||
.start();
|
||||
}
|
||||
|
||||
update(deltaTime: number) {}
|
||||
}
|
||||
9
assets/seripts/ui/Tipcontrol.ts.meta
Normal file
9
assets/seripts/ui/Tipcontrol.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "2e7b5643-5827-4d57-b89e-580c05c3e847",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user