修复部分资源丢失,提交奖励功能
This commit is contained in:
parent
cf4ebce13c
commit
9505ab139e
File diff suppressed because it is too large
Load Diff
|
@ -5,6 +5,7 @@ import { resLoader } from 'db://assets/core_tgx/base/utils/ResLoader';
|
|||
import { ModuleDef } from 'db://assets/scripts/ModuleDef';
|
||||
import { tgxUIAlert } from 'db://assets/core_tgx/tgx';
|
||||
import { AreanNetMgr } from '../../scripts/AreanNetMgr';
|
||||
import { RewardManager } from './RewardManager';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
enum GameState {
|
||||
|
@ -173,13 +174,21 @@ export class BallGame extends Component {
|
|||
|
||||
n.getChildByPath("settlementNode/btnOK/label").getComponent(Label).string = "Coming Soon";
|
||||
n.getChildByPath("settlementNode/btnOK").on(Node.EventType.TOUCH_START, () => {
|
||||
|
||||
if (isWin) {
|
||||
director.loadScene("lobby_arean");
|
||||
}
|
||||
else {
|
||||
director.loadScene("lobby_arean");
|
||||
}
|
||||
|
||||
director.loadScene("lobby_arean");
|
||||
|
||||
// 初始化奖励管理器
|
||||
|
||||
// RewardManager.instance.init(this.guiNode);
|
||||
// // 显示宝箱奖励
|
||||
// RewardManager.instance.showRewardChest(() => {
|
||||
// // 奖励界面关闭后切换场景
|
||||
// if (isWin) {
|
||||
// director.loadScene("lobby_arean");
|
||||
// } else {
|
||||
// director.loadScene("lobby_arean");
|
||||
// }
|
||||
// });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
import { _decorator, Component, Node, Label, Sprite, tween, Vec3, UIOpacity, SpriteFrame } from 'cc';
|
||||
import { resLoader } from 'db://assets/core_tgx/base/utils/ResLoader';
|
||||
import { ModuleDef } from 'db://assets/scripts/ModuleDef';
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('RewardCard')
|
||||
export class RewardCard extends Component {
|
||||
@property(Label)
|
||||
nameLabel: Label = null!;
|
||||
|
||||
@property(Label)
|
||||
descLabel: Label = null!;
|
||||
|
||||
@property(Sprite)
|
||||
iconSprite: Sprite = null!;
|
||||
|
||||
@property(Node)
|
||||
cardFront: Node = null!;
|
||||
|
||||
@property(Node)
|
||||
glowEffect: Node = null!;
|
||||
|
||||
@property(UIOpacity)
|
||||
cardOpacity: UIOpacity = null!;
|
||||
|
||||
start() {
|
||||
this.playAppearAnimation();
|
||||
}
|
||||
|
||||
setCardData(cardData: { name: string, desc: string, icon: string }) {
|
||||
if (this.nameLabel) {
|
||||
this.nameLabel.string = cardData.name;
|
||||
}
|
||||
if (this.descLabel) {
|
||||
this.descLabel.string = cardData.desc;
|
||||
}
|
||||
if (this.iconSprite) {
|
||||
resLoader.load(ModuleDef.Arean, `common/textures/${cardData.icon}`, (err: Error | null, spriteFrame: SpriteFrame) => {
|
||||
if (!err && spriteFrame) {
|
||||
this.iconSprite.spriteFrame = spriteFrame;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
playAppearAnimation() {
|
||||
// 卡牌初始状态
|
||||
if (this.cardFront) {
|
||||
this.cardFront.scale = new Vec3(0.1, 0.1, 0.1);
|
||||
}
|
||||
if (this.cardOpacity) {
|
||||
this.cardOpacity.opacity = 0;
|
||||
}
|
||||
if (this.glowEffect) {
|
||||
this.glowEffect.scale = new Vec3(0.5, 0.5, 0.5);
|
||||
}
|
||||
|
||||
// 卡牌出现动画序列
|
||||
if (this.cardOpacity) {
|
||||
tween(this.cardOpacity)
|
||||
.to(0.3, { opacity: 255 })
|
||||
.start();
|
||||
}
|
||||
|
||||
if (this.cardFront) {
|
||||
tween(this.cardFront)
|
||||
.to(0.5, { scale: new Vec3(1, 1, 1) }, {
|
||||
easing: 'backOut'
|
||||
})
|
||||
.call(() => {
|
||||
this.playGlowAnimation();
|
||||
})
|
||||
.start();
|
||||
}
|
||||
|
||||
// 文字渐入效果
|
||||
if (this.nameLabel && this.nameLabel.node.getComponent(UIOpacity)) {
|
||||
this.nameLabel.node.getComponent(UIOpacity).opacity = 0;
|
||||
tween(this.nameLabel.node.getComponent(UIOpacity))
|
||||
.delay(0.3)
|
||||
.to(0.3, { opacity: 255 })
|
||||
.start();
|
||||
}
|
||||
|
||||
if (this.descLabel && this.descLabel.node.getComponent(UIOpacity)) {
|
||||
this.descLabel.node.getComponent(UIOpacity).opacity = 0;
|
||||
tween(this.descLabel.node.getComponent(UIOpacity))
|
||||
.delay(0.4)
|
||||
.to(0.3, { opacity: 255 })
|
||||
.start();
|
||||
}
|
||||
}
|
||||
|
||||
playGlowAnimation() {
|
||||
if (this.glowEffect) {
|
||||
// 光效旋转动画
|
||||
tween(this.glowEffect)
|
||||
.by(3, { angle: 360 })
|
||||
.repeatForever()
|
||||
.start();
|
||||
|
||||
// 光效缩放动画
|
||||
tween(this.glowEffect)
|
||||
.to(1.5, { scale: new Vec3(1.2, 1.2, 1.2) })
|
||||
.to(1.5, { scale: new Vec3(1, 1, 1) })
|
||||
.repeatForever()
|
||||
.start();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "1c519b1a-044f-4cef-b0de-fab8ae3742f3",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
import { _decorator, Component, Node, Animation, UIOpacity, tween, Vec3 } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('RewardChest')
|
||||
export class RewardChest extends Component {
|
||||
@property(Node)
|
||||
chestNode: Node = null!;
|
||||
|
||||
@property(Node)
|
||||
lightEffect: Node = null!;
|
||||
|
||||
@property(UIOpacity)
|
||||
maskOpacity: UIOpacity = null!;
|
||||
|
||||
@property(Node)
|
||||
particles: Node = null!;
|
||||
|
||||
start() {
|
||||
// 初始化
|
||||
if (this.particles) {
|
||||
this.particles.active = false;
|
||||
}
|
||||
this.playAppearAnimation();
|
||||
}
|
||||
|
||||
playAppearAnimation() {
|
||||
// 背景遮罩渐入
|
||||
if (this.maskOpacity) {
|
||||
tween(this.maskOpacity)
|
||||
.to(0.3, { opacity: 180 })
|
||||
.start();
|
||||
}
|
||||
|
||||
// 宝箱从小变大
|
||||
if (this.chestNode) {
|
||||
this.chestNode.scale = new Vec3(0.1, 0.1, 0.1);
|
||||
tween(this.chestNode)
|
||||
.to(0.5, { scale: new Vec3(1, 1, 1) }, {
|
||||
easing: 'backOut'
|
||||
})
|
||||
.start();
|
||||
}
|
||||
|
||||
// 光效旋转
|
||||
if (this.lightEffect) {
|
||||
this.lightEffect.angle = 0;
|
||||
tween(this.lightEffect)
|
||||
.by(3, { angle: 360 })
|
||||
.repeatForever()
|
||||
.start();
|
||||
}
|
||||
}
|
||||
|
||||
playOpenAnimation() {
|
||||
if (this.chestNode) {
|
||||
tween(this.chestNode)
|
||||
.by(0.1, { position: new Vec3(0, 5, 0) })
|
||||
.by(0.1, { position: new Vec3(0, -5, 0) })
|
||||
.by(0.1, { scale: new Vec3(0.1, 0.1, 0.1) })
|
||||
.by(0.1, { scale: new Vec3(-0.1, -0.1, -0.1) })
|
||||
.call(() => {
|
||||
if (this.particles) {
|
||||
this.particles.active = true;
|
||||
}
|
||||
})
|
||||
.start();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "5d9d4f4c-aaf5-4b23-9fda-d25abcd77a7f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
import { _decorator, Component, Node, Prefab, instantiate, director } from 'cc';
|
||||
import { resLoader } from 'db://assets/core_tgx/base/utils/ResLoader';
|
||||
import { ModuleDef } from 'db://assets/scripts/ModuleDef';
|
||||
import { RewardChest } from './RewardChest';
|
||||
import { RewardCard } from './RewardCard';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
// 卡牌数据接口
|
||||
interface CardData {
|
||||
id: number;
|
||||
name: string;
|
||||
desc: string;
|
||||
icon: string;
|
||||
}
|
||||
|
||||
@ccclass('RewardManager')
|
||||
export class RewardManager {
|
||||
private static _instance: RewardManager = null;
|
||||
private guiNode: Node = null;
|
||||
|
||||
// 卡牌配置数据
|
||||
private readonly cardList: CardData[] = [
|
||||
{ id: 1, name: "加速卡", desc: "提升移动速度30%", icon: "card_speed" },
|
||||
{ id: 2, name: "力量卡", desc: "提升攻击力20%", icon: "card_power" },
|
||||
{ id: 3, name: "护盾卡", desc: "获得一个护盾", icon: "card_shield" },
|
||||
{ id: 4, name: "回复卡", desc: "恢复2颗弹珠", icon: "card_heal" }
|
||||
];
|
||||
|
||||
public static get instance(): RewardManager {
|
||||
if (!this._instance) {
|
||||
this._instance = new RewardManager();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
|
||||
// 初始化方法
|
||||
public init(guiNode: Node) {
|
||||
this.guiNode = guiNode;
|
||||
}
|
||||
|
||||
// 显示宝箱奖励
|
||||
public showRewardChest(callback?: () => void) {
|
||||
resLoader.load(ModuleDef.Arean, 'common/prefabs/reward_chest', (err: Error | null, prefab: Prefab) => {
|
||||
if (!err && prefab && this.guiNode) {
|
||||
const rewardNode = instantiate(prefab);
|
||||
this.guiNode.addChild(rewardNode);
|
||||
|
||||
// 点击宝箱显示卡牌
|
||||
const chestBtn = rewardNode.getChildByPath("chest_container/chest_img");
|
||||
if (chestBtn) {
|
||||
chestBtn.once(Node.EventType.TOUCH_START, () => {
|
||||
// 播放宝箱打开动画
|
||||
const chestComp = rewardNode.getComponent(RewardChest);
|
||||
if (chestComp) {
|
||||
chestComp.playOpenAnimation();
|
||||
}
|
||||
// 显示随机卡牌
|
||||
this.showRandomCard(rewardNode, callback);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 显示随机卡牌
|
||||
private showRandomCard(rewardNode: Node, callback?: () => void) {
|
||||
// 随机选择一张卡牌
|
||||
const randomCard = this.cardList[Math.floor(Math.random() * this.cardList.length)];
|
||||
|
||||
resLoader.load(ModuleDef.Arean, 'common/prefabs/reward_card', (err: Error | null, prefab: Prefab) => {
|
||||
if (!err && prefab) {
|
||||
const cardNode = instantiate(prefab);
|
||||
rewardNode.addChild(cardNode);
|
||||
|
||||
// 设置卡牌数据
|
||||
const cardComp = cardNode.getComponent(RewardCard);
|
||||
if (cardComp) {
|
||||
cardComp.setCardData(randomCard);
|
||||
}
|
||||
|
||||
// 点击任意位置关闭
|
||||
const maskNode = rewardNode.getChildByPath("mask");
|
||||
if (maskNode) {
|
||||
maskNode.once(Node.EventType.TOUCH_START, () => {
|
||||
rewardNode.destroy();
|
||||
if (callback) callback();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 保存获得的卡牌
|
||||
private saveCardReward(cardId: number) {
|
||||
// TODO: 实现卡牌保存逻辑
|
||||
console.log('获得卡牌:', cardId);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c9e20646-b019-4084-b305-e6b140329dcf",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -108,7 +108,7 @@ export class LobbyScene extends Component {
|
|||
}
|
||||
|
||||
private async _checkAccount(): Promise<void> {
|
||||
// localStorage.clear();
|
||||
localStorage.clear();
|
||||
let account = UserLocalCache.inst.account;
|
||||
let password = UserLocalCache.inst.password;
|
||||
if (account && password) {
|
||||
|
|
Loading…
Reference in New Issue