修改版本

This commit is contained in:
2026-03-30 18:01:27 +08:00
parent e58bf3670a
commit 0ea158133b
56 changed files with 18245 additions and 17713 deletions

View File

@@ -1,4 +1,4 @@
import { _decorator, Node, tween, Vec3, Sprite, Asset, ImageAsset, SpriteFrame, Texture2D, Label, UIOpacity, Animation, math, VideoPlayer, UITransform, VideoClip } from 'cc';
import { _decorator, Node, tween, Vec3, Sprite, Asset, ImageAsset, SpriteFrame, Texture2D, Label, UIOpacity, Animation, math, VideoPlayer, UITransform, VideoClip, Color, Button } from 'cc';
import BaseView from '../../../../../../extensions/app/assets/base/BaseView';
import { PageTips } from '../../tips/native/PageTips';
import { app } from 'db://assets/app/app';
@@ -14,6 +14,9 @@ const enum M_DIR {
COUNTER_CLOCKWISE = 1, /** 逆时针 */
}
/** 默认消耗 */
const DEFAULT_COST = 100
@ccclass('PageMain')
export class PageMain extends BaseView {
/** 声音按钮 */
@@ -22,26 +25,24 @@ export class PageMain extends BaseView {
@property(Label) lab_gold: Label = null!;
/** 姓名 */
@property(Label) lab_name: Label = null!;
/** 当前剩余抽奖次数 */
@property(Label) remain: Label = null!;
/** 中奖提示 */
@property(Label) lab_earn: Label = null!;
/** 倍率显示 */
@property(Label) lab_ante: Label = null!;
/** 方向选择 */
@property(Node) n_dir: Node[] = [];
/** 标签 */
@property(Node) sign: Node = null!;
/** 方块 */
@property(Node) blocks: Node = null!;
@property(Node) blocks: Node[] = [];
/** 骰子 */
@property(Node) dices: Node[] = [];
/** 中奖 */
@property(Node) rw: Node = null!;
/** 未中奖 */
@property(Node) norw: Node = null!;
/** 购买次数按钮 */
@property(Node) btns_buy: Node = null!;
/** 开始游戏按钮 */
@property(Node) btn_play: Node = null!;
/** 开始游戏按钮 */
@property(Node) btn_auto: Node = null!;
/** 胜利数字 */
@property(Node) lab_add: Node = null!;
/** 失败数字 */
@@ -58,6 +59,9 @@ export class PageMain extends BaseView {
@property(Node) ani_dice: Node = null!;
/** 骰子总点数 */
@property(Node) dice_all: Node = null!;
/** 倍数减按钮 */
@property(Node) btn_ante_sub: Node = null!;
@property(Node) btn_ante_add: Node = null!;
/** 失败视频资源 */
@property(VideoClip) video_win: VideoClip = null!;
@property(VideoClip) video_lose: VideoClip = null!;
@@ -71,11 +75,13 @@ export class PageMain extends BaseView {
private _game_data: any = null;
/** 是否正在连续 */
private _is_continuous : boolean = true
/** 棋盘数据 */
private _board_data: any[] = []
/** 消耗倍数索引 */
private _ante_index : number = 0
/** 倍数数据 */
private _ante_data : any[] = null
/** 方块顺时针顺序,从顶端开始 */
private _b_sequence : string[] = [
"20","27","24","10","5","15","8","22","30","23","16","12","13","7","17","9","21","26","6","29","19","11","25","14","28","18"
];
/** 标签位置 */
private _sign_position: Vec3[] =[
@@ -120,11 +126,10 @@ export class PageMain extends BaseView {
// 界面打开时的相关逻辑写在这(onShow可被多次调用-它与onHide不成对)
onShow(params: any) {
this.initUserData()
this.swichBuyAndPlay()
this.initDir()
this.getRwData()
this.onClickTips()
this.bindVideoEvents()
this.getConfig()
this._canvas = document.createElement('canvas');
this._canvas.width = this.video_sprite.getComponent(UITransform).width;
@@ -160,15 +165,6 @@ export class PageMain extends BaseView {
initUserData(){
this.lab_gold.string = USERDATA.coin.toString()
this.lab_name.string = USERDATA.name
this.remain.string = USERDATA.total_ticket_count.toString()
//this.remain.node.active = USERDATA.total_ticket_count > 0
Tools.ActChild(this.btn_auto, "auto", this._is_continuous)
Tools.ActChild(this.btn_auto, "no_auto", !this._is_continuous)
}
swichBuyAndPlay(){
this.btns_buy.active = USERDATA.total_ticket_count <= 0
this.btn_play.active = USERDATA.total_ticket_count > 0
}
bindVideoEvents() {
@@ -188,23 +184,59 @@ export class PageMain extends BaseView {
}
}
getRwData(){
Tools.httpReq("game/lotteryPool", {}, (res:any) => {
getConfig(){
Tools.httpReq("game/anteConfig", {}, (res:any) => {
this._ante_data = res
// 默认倍数
for (let index = 0; index < res.length; index++) {
const d = res[index];
Tools.SetChildText(this.blocks, String(d.grid_number) + "/num", d.ui_text)
const element = res[index];
if (element.is_default == 1){
this._ante_index = index
break
}
}
this.initAnteSet()
Tools.httpReq("game/lotteryPool", {}, (res:any) => {
this._board_data = res
this.initBoradData()
})
})
}
/** 购买游戏次数 */
buyTimes(a : any, d : any){
Tools.httpReq("game/buyLotteryTickets", { "count" : d }, (res:any) => {
USERDATA.coin = res.coin
USERDATA.total_ticket_count = res.total_ticket_count
this.swichBuyAndPlay()
this.initUserData()
})
initAnteSet(){
let d = this._ante_data[this._ante_index]
this.lab_ante.string = d.name
this.btn_ante_sub.getComponent(Sprite).grayscale = this._ante_index == 0
this.btn_ante_add.getComponent(Sprite).grayscale = this._ante_index == this._ante_data.length - 1
}
btnAnteAdd(){
if (this._ante_index < this._ante_data.length - 1) {
this._ante_index++
this.initAnteSet()
this.initBoradData()
}
}
btnAnteSub(){
if (this._ante_index > 0) {
this._ante_index--
this.initAnteSet()
this.initBoradData()
}
}
initBoradData(){
for (let index = 0; index < this._board_data.length; index++) {
const d = this._board_data[index];
let num = parseInt(d.ui_text) ? parseInt(d.ui_text) * this._ante_data[this._ante_index].mult : d.ui_text
Tools.SetChildText(this.blocks[index], "num", num)
Tools.SetChildText(this.blocks[index], "light/num", num)
Tools.SetChildText(this.blocks[index], "point", d.grid_number)
Tools.SetChildText(this.blocks[index], "light/point", d.grid_number)
}
}
chooseDir(d:any, dir: number){
@@ -235,37 +267,21 @@ export class PageMain extends BaseView {
app.manager.ui.show<PageRewardhistory>({name: 'PageRewardhistory'})
}
btnGameAuto(){
this._is_continuous = !this._is_continuous
this.initUserData()
}
btnPlayGary(){
this.btn_play.getComponent(Sprite).grayscale = true
Tools.GetChildComp(this.btn_play, "lab", Sprite).grayscale = true
}
btnPlayWhite(){
this.btn_play.getComponent(Sprite).grayscale = false
Tools.GetChildComp(this.btn_play, "lab", Sprite).grayscale = false
}
/** 开始游戏 */
btnGameStart(){
if (this._b_sequence.length != this._sign_position.length) {
return app.manager.ui.showToast(Tools.GetLocalized("数据错误"))
}
if (this._is_playing) return
this._is_playing = true
this.btnPlayGary()
this.lab_earn.string = ""
Tools.httpReq("game/playStart", {
"direction" : this._move_dir
"direction" : this._move_dir,
"ante" : this._ante_data[this._ante_index].mult
}, (res:any) => {
this._game_data = res
this._move_dir = res.direction
USERDATA.total_ticket_count--
USERDATA.coin -= this._ante_data[this._ante_index].mult * DEFAULT_COST
this.initUserData()
let steps = 0
@@ -273,8 +289,9 @@ export class PageMain extends BaseView {
const element = res.roll_array[i];
steps += element
}
let index:any = this._b_sequence.findIndex(v => v == steps.toString())
let b = this.blocks.getChildByName(steps.toString())
let index:any = this._board_data.findIndex(v => v.grid_number == steps.toString())
console.log("steps", steps, index)
let b = this.blocks[index]
// 计算移动路径
let path = this.calculatePath(index, steps);
@@ -316,8 +333,6 @@ export class PageMain extends BaseView {
USERDATA.total_ticket_count = this._game_data.total_ticket_count
this._is_playing = false
this.initUserData()
this.swichBuyAndPlay()
this.btnPlayWhite()
}, 1)
}, 1.2)
}else {
@@ -395,8 +410,7 @@ export class PageMain extends BaseView {
/** 跟随闪烁 */
this.scheduleOnce(() => {
let n = this._sign_position.findIndex(v => v == targetPos)
let nowPoint = this._b_sequence[n]
let light = this.blocks.getChildByName(nowPoint).getChildByName("light")
let light = this.blocks[n].getChildByName("light")
light.active = true
let opc = light.getComponent(UIOpacity)
opc.opacity = 0
@@ -416,13 +430,13 @@ export class PageMain extends BaseView {
if (index + 1 >= path.length) {
this.scheduleOnce(() => {
this.sign.active = false;
let b = this._b_sequence[lastIndex]
let b = this.blocks[lastIndex]
if (this._game_data.win_coin >= 0){
app.manager.sound.playEffect({name : "effect/eff_start"})
}else{
app.manager.sound.playEffect({name : "effect/eff_finish", volume: 0.5})
}
this.blinkLightWithTween(this.blocks.getChildByName(b).getChildByName("light"), 1, 2)
this.blinkLightWithTween(this.blocks[lastIndex].getChildByName("light"), 1, 2)
}, 0.5);
return;
}
@@ -453,6 +467,10 @@ export class PageMain extends BaseView {
this.video_bg.clip = this.video_normal
}, 3.2);
let earn_str = this._game_data.win_coin > 0 ? "+" + this._game_data.win_coin : this._game_data.win_coin
this.lab_earn.string = earn_str
this.lab_earn.color = this._game_data.win_coin > 0 ? new Color(255, 91, 69) : new Color(96, 255, 38)
let blinkCount = 0;
const blink = () => {
tween(opc)
@@ -473,13 +491,9 @@ export class PageMain extends BaseView {
let cb = () => {
lab.destroy()
USERDATA.coin = this._game_data.coin
USERDATA.total_ticket_count = this._game_data.total_ticket_count
this.initUserData()
this.swichBuyAndPlay()
if (USERDATA.total_ticket_count > 0){
if (USERDATA.coin >= this._ante_data[this._ante_index].mult * DEFAULT_COST){
this.btnGameStart()
}else{
this.btnPlayWhite()
}
}
// T5是再来一次不需要飘字
@@ -487,7 +501,8 @@ export class PageMain extends BaseView {
let pos = new Vec3(node.parent.position.x, node.parent.position.y + 80, 0 )
lab.setPosition(pos)
lab.active = true
Tools.SetText(lab, this._game_data.win_coin > 0 ? "+" + this._game_data.win_coin : this._game_data.win_coin)
let earn_str = this._game_data.win_coin > 0 ? "+" + this._game_data.win_coin : this._game_data.win_coin
Tools.SetText(lab, earn_str)
app.manager.sound.playEffect({name : this._game_data.win_coin > 0 ? "effect/eff_win" : "effect/eff_lose"})
tween(lab)
.by(1, { position: new Vec3(0, 200, 0) })
@@ -512,9 +527,7 @@ export class PageMain extends BaseView {
}
USERDATA.coin = this._game_data.coin
USERDATA.total_ticket_count = this._game_data.total_ticket_count
this.swichBuyAndPlay()
this.initUserData()
this.btnPlayWhite()
}
}
})