add trophy logic
This commit is contained in:
@@ -5,6 +5,7 @@ import { CalendarUnit } from "./CalendarUnit";
|
||||
import { LevelManager } from "../models/LevelManager";
|
||||
import { UIManager } from "../models/UIManager";
|
||||
import { respath } from "../constants/respath";
|
||||
import { MONTH_LIST } from "../models/DCManager";
|
||||
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
@@ -16,6 +17,8 @@ export class DailyChallenge extends Laya.Script {
|
||||
public btn_back: Laya.Button
|
||||
@property(Laya.Image)
|
||||
public btn_trophy: Laya.Image
|
||||
@property(Laya.Sprite)
|
||||
public btn_trophy_red: Laya.Sprite
|
||||
@property(Laya.Image)
|
||||
public icon_trophy: Laya.Image
|
||||
@property(Laya.Box)
|
||||
@@ -62,9 +65,15 @@ export class DailyChallenge extends Laya.Script {
|
||||
UIManager.getInstance().loadHomeUI()
|
||||
this.owner.destroy()
|
||||
})
|
||||
|
||||
var user = StorageManager.getInstance().getUser()
|
||||
this.btn_trophy_red.visible = user.get_trophyHasUnread()
|
||||
this.btn_trophy.on(Laya.Event.CLICK, this, ()=>{
|
||||
user.set_trophyAllread()
|
||||
this.btn_trophy_red.visible = false
|
||||
UIManager.getInstance().loadTrophyUI()
|
||||
})
|
||||
|
||||
this.btn_play.on(Laya.Event.CLICK, this, (evt: Laya.Event)=>{
|
||||
// console.log(">>>>>>>>>>>>>>>>>>>>>>>", this.selectedUnit.day)
|
||||
var now = new Date()
|
||||
@@ -99,12 +108,12 @@ export class DailyChallenge extends Laya.Script {
|
||||
}
|
||||
}
|
||||
|
||||
this.indexMax = config.MONTH_LIST.length - 1
|
||||
this.indexMax = MONTH_LIST.length - 1
|
||||
var now = new Date()
|
||||
var nowYear = now.getFullYear()
|
||||
var nowMonth = now.getMonth() + 1
|
||||
for (var i=0; i<config.MONTH_LIST.length; i++) {
|
||||
var obj = config.MONTH_LIST[i]
|
||||
for (var i=0; i<MONTH_LIST.length; i++) {
|
||||
var obj = MONTH_LIST[i]
|
||||
if (nowYear == obj.year && nowMonth == obj.month) {
|
||||
this.indexMax = i;
|
||||
break
|
||||
@@ -129,8 +138,8 @@ export class DailyChallenge extends Laya.Script {
|
||||
var nowYear = now.getFullYear()
|
||||
var nowMonth = now.getMonth() + 1
|
||||
this.currentIndex = 0
|
||||
for (var i=0; i<config.MONTH_LIST.length; i++) {
|
||||
var obj = config.MONTH_LIST[i]
|
||||
for (var i=0; i<MONTH_LIST.length; i++) {
|
||||
var obj = MONTH_LIST[i]
|
||||
if (nowYear == obj.year && nowMonth == obj.month) {
|
||||
this.currentIndex = i;
|
||||
break
|
||||
@@ -143,7 +152,7 @@ export class DailyChallenge extends Laya.Script {
|
||||
public loadWithIndex(index: number): void {
|
||||
this.btn_left.visible = this.currentIndex > 0
|
||||
this.btn_right.visible = this.currentIndex < this.indexMax
|
||||
var info = config.MONTH_LIST[index]
|
||||
var info = MONTH_LIST[index]
|
||||
var user = StorageManager.getInstance().getUser()
|
||||
var now = new Date()
|
||||
var nowYear = now.getFullYear()
|
||||
@@ -152,7 +161,7 @@ export class DailyChallenge extends Laya.Script {
|
||||
|
||||
this.icon_trophy.skin = info.icon_res
|
||||
//设置背景
|
||||
var starCount = user.get_doneCountBydate(info.year, info.month)
|
||||
var starCount = user.get_doneCountByDate(info.year, info.month)
|
||||
if (starCount >= info.dayCount) {
|
||||
this.bg_dc.skin = respath.dc_top_bg_month_finish
|
||||
}
|
||||
@@ -249,4 +258,13 @@ export class DailyChallenge extends Laya.Script {
|
||||
var unit = evt.target.getComponent(CalendarUnit)
|
||||
this.onApplyUnit(unit)
|
||||
}
|
||||
|
||||
onStart(): void {
|
||||
var user = StorageManager.getInstance().getUser()
|
||||
var find = user.get_trophyHasNew()
|
||||
if (find) {
|
||||
UIManager.getInstance().loadTrophyClaimUI(find)
|
||||
user.set_trophyNew(find, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { Difficulty } from "./Difficulty";
|
||||
import { LevelManager } from "../models/LevelManager";
|
||||
import { config } from "../constants/config";
|
||||
import { Utility_ConvertSecondToString } from "../utils/utility";
|
||||
import { G_getMonthInfo } from "../models/DCManager";
|
||||
|
||||
const { regClass, property } = Laya
|
||||
|
||||
@@ -44,17 +45,11 @@ export class Home extends Laya.Script {
|
||||
var now = new Date()
|
||||
var nowYear = now.getFullYear()
|
||||
var nowMonth = now.getMonth() + 1
|
||||
var find
|
||||
for (var i=0; i<config.MONTH_LIST.length; i++) {
|
||||
var obj = config.MONTH_LIST[i]
|
||||
if (obj.year == nowYear && obj.month == nowMonth) {
|
||||
find = obj
|
||||
break
|
||||
}
|
||||
}
|
||||
var nowDay = now.getDate()
|
||||
var find = G_getMonthInfo(nowYear, nowMonth)
|
||||
if (find) {
|
||||
this.icon_dc.skin = find.icon_res
|
||||
if (user.get_doneCountBydate(nowYear, nowMonth) >= find.dayCount) {
|
||||
if (user.get_doneCountByDate(nowYear, nowMonth) >= find.dayCount) {
|
||||
this.bg_dc.skin = respath.home_top_dc_bg_finish
|
||||
this.label_dc_title.color = "#ffffff"
|
||||
this.label_dc_date.color = "#ffffff"
|
||||
@@ -70,8 +65,7 @@ export class Home extends Laya.Script {
|
||||
this.label_dc_title.color = "#2d3138"
|
||||
this.label_dc_date.color = "#2d3138"
|
||||
}
|
||||
|
||||
var nowDay = new Date().getDate()
|
||||
|
||||
var stageID = `${nowYear}-${nowMonth}-${nowDay}`
|
||||
this.label_dc_date.text = `${config.MONTH_ABBRS[nowMonth-1]} ${nowDay}`
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import { config } from "../constants/config";
|
||||
import { StorageManager } from "../models/StorageManager";
|
||||
import { Utility_ConvertSecondToString } from "../utils/utility";
|
||||
import { EVENT_TYPES, EventManager } from "../models/EventManager";
|
||||
import { G_getMonthInfo } from "../models/DCManager";
|
||||
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
@@ -377,14 +378,31 @@ export class Stage extends Laya.Script {
|
||||
}
|
||||
}
|
||||
}
|
||||
user.update_stage_done(this.data.get_stageID(), finished/all)//更新关卡完成进度
|
||||
var progress = finished/all
|
||||
user.update_stage_done(this.data.get_stageID(), progress)//更新关卡完成进度
|
||||
if (this.getIsComplete()) {
|
||||
console.log("完成关卡")
|
||||
console.log("完成关卡", finished, all, progress)
|
||||
this.paused = true
|
||||
this.data.set_score(score)
|
||||
if (this.data.get_stageType() == config.STAGE_TYPE.MAIN) {//主线关卡更新难度进度
|
||||
user.update_progress(this.data.get_difficulty(), this.data.get_stageIndex()+1)
|
||||
}
|
||||
else if (this.data.get_stageType() == config.STAGE_TYPE.DC) {//dc
|
||||
if (progress >= 1) {//完成每日挑战关卡检查是否或者当月奖杯
|
||||
var now = new Date()
|
||||
var nowYear = now.getFullYear()
|
||||
var nowMonth = now.getMonth() + 1
|
||||
var doneCount = user.get_doneCountByDate(nowYear, nowMonth)
|
||||
var dayCount = 0
|
||||
var info = G_getMonthInfo(nowYear, nowMonth)
|
||||
if (info)
|
||||
dayCount = info.dayCount
|
||||
console.log("dc完成信息>>>>>>>>>>>>>>>", nowYear, nowMonth, doneCount, dayCount)
|
||||
if (doneCount >= dayCount) {//当月每日挑战全部完成
|
||||
user.add_trophy_record(nowYear, nowMonth, now.getDate())
|
||||
}
|
||||
}
|
||||
}
|
||||
UIManager.getInstance().loadGameDoneUI()
|
||||
}
|
||||
}
|
||||
|
||||
36
src/views/TrophyClaim.ts
Normal file
36
src/views/TrophyClaim.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { config } from "../constants/config";
|
||||
import { MONTH_LIST } from "../models/DCManager";
|
||||
import { TrophyRecord } from "../types/global";
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
|
||||
@regClass()
|
||||
export class TrophyClaim extends Laya.Script {
|
||||
declare owner : Laya.Box;
|
||||
|
||||
@property(Laya.Image)
|
||||
public icon: Laya.Image
|
||||
|
||||
@property(Laya.Label)
|
||||
public label_date: Laya.Label
|
||||
|
||||
@property(Laya.Box)
|
||||
public btn_close: Laya.Box
|
||||
|
||||
public onSetShow(record: TrophyRecord): void {
|
||||
for (var i=0; i<MONTH_LIST.length; i++) {
|
||||
var obj = MONTH_LIST[i]
|
||||
if (obj.year == record.year && obj.month == record.month) {
|
||||
this.icon.skin = obj.icon_res
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
this.label_date.text = `${config.MONTH_ABBRS[record.month-1]} ${record.day},${record.year}`
|
||||
|
||||
this.btn_close.on(Laya.Event.CLICK, this, ()=>{
|
||||
this.owner.destroy()
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
3
src/views/TrophyClaim.ts.meta
Normal file
3
src/views/TrophyClaim.ts.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"uuid": "0550b681-b602-49fe-900f-e30866ce922c"
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
|
||||
|
||||
import { config } from "../constants/config";
|
||||
|
||||
import { respath } from "../constants/respath";
|
||||
import { MONTH_LIST } from "../models/DCManager";
|
||||
import { TrophyUnit } from "./TrophyUnit";
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
@@ -28,8 +29,8 @@ export class TrophyRoom extends Laya.Script {
|
||||
var now = new Date()
|
||||
var nowYear = now.getFullYear()
|
||||
var nowMonth = now.getMonth() + 1
|
||||
for (var i=0; i<config.MONTH_LIST.length; i++) {
|
||||
var obj = config.MONTH_LIST[i]
|
||||
for (var i=0; i<MONTH_LIST.length; i++) {
|
||||
var obj = MONTH_LIST[i]
|
||||
infos.push(obj)
|
||||
if (obj.year == nowYear && obj.month == nowMonth) {
|
||||
break
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
|
||||
import { config } from "../constants/config";
|
||||
import { MONTH_LIST } from "../models/DCManager";
|
||||
import { TrophyRecord } from "../types/global";
|
||||
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
|
||||
@regClass()
|
||||
@@ -13,7 +19,19 @@ export class TrophyShow extends Laya.Script {
|
||||
@property(Laya.Box)
|
||||
public btn_close: Laya.Box
|
||||
|
||||
public onSetShow(): void {
|
||||
|
||||
public onSetShow(record: TrophyRecord): void {
|
||||
for (var i=0; i<MONTH_LIST.length; i++) {
|
||||
var obj = MONTH_LIST[i]
|
||||
if (obj.year == record.year && obj.month == record.month) {
|
||||
this.icon.skin = obj.icon_res
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
this.label_date.text = `${config.MONTH_ABBRS[record.month-1]} ${record.day},${record.year}`
|
||||
|
||||
this.btn_close.on(Laya.Event.CLICK, this, ()=>{
|
||||
this.owner.destroy()
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { config } from "../constants/config";
|
||||
import { respath } from "../constants/respath";
|
||||
import { StorageManager } from "../models/StorageManager";
|
||||
import { UIManager } from "../models/UIManager";
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
|
||||
@@ -19,7 +20,7 @@ export class TrophyUnit extends Laya.Script {
|
||||
|
||||
public onInit(info: any): void {
|
||||
var user = StorageManager.getInstance().getUser()
|
||||
var starCount = user.get_doneCountBydate(info.year, info.month)
|
||||
var starCount = user.get_doneCountByDate(info.year, info.month)
|
||||
this.icon.skin = info.icon_res
|
||||
this.label_count.text = `${starCount}/${info.dayCount}`
|
||||
this.label_month.text = config.MONTH_ABBRS[info.month-1]
|
||||
@@ -35,7 +36,10 @@ export class TrophyUnit extends Laya.Script {
|
||||
}
|
||||
|
||||
this.icon.on(Laya.Event.CLICK, this, ()=>{
|
||||
|
||||
var find = user.get_trophyRecord(info.year, info.month)
|
||||
if (find) {
|
||||
UIManager.getInstance().loadTrophyShowUI(find)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user