完善每日挑战逻辑
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { respath } from "./respath";
|
||||
|
||||
|
||||
|
||||
@@ -37,5 +38,20 @@ export const config = {
|
||||
MONTH_ABBRS: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
|
||||
MONTH_FULLNAMES: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
||||
|
||||
MONTH_LIST: [
|
||||
{year: 2025, month: 1, begin: 3, dayCount: 31, icon_res: respath.trophy_01},
|
||||
{year: 2025, month: 2, begin: 6, dayCount: 30, icon_res: respath.trophy_02},
|
||||
{year: 2025, month: 3, begin: 6, dayCount: 31, icon_res: respath.trophy_03},
|
||||
{year: 2025, month: 4, begin: 2, dayCount: 30, icon_res: respath.trophy_04},
|
||||
{year: 2025, month: 5, begin: 4, dayCount: 31, icon_res: respath.trophy_05},
|
||||
{year: 2025, month: 6, begin: 0, dayCount: 30, icon_res: respath.trophy_06},
|
||||
{year: 2025, month: 7, begin: 2, dayCount: 31, icon_res: respath.trophy_07},
|
||||
{year: 2025, month: 8, begin: 5, dayCount: 31, icon_res: respath.trophy_08},
|
||||
{year: 2025, month: 9, begin: 1, dayCount: 30, icon_res: respath.trophy_01},
|
||||
{year: 2025, month: 10, begin: 3, dayCount: 31, icon_res: respath.trophy_02},
|
||||
{year: 2025, month: 11, begin: 6, dayCount: 30, icon_res: respath.trophy_03},
|
||||
{year: 2025, month: 12, begin: 1, dayCount: 31, icon_res: respath.trophy_04},
|
||||
]
|
||||
|
||||
}
|
||||
|
||||
|
||||
3
src/constants/dc-config.ts.meta
Normal file
3
src/constants/dc-config.ts.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"uuid": "fb5508ba-9b4a-43b3-903e-1063df3deeb8"
|
||||
}
|
||||
@@ -17,5 +17,14 @@ export const respath = {
|
||||
dc_top_bg_normal: "atlas/images/img_dc_bg1.png",
|
||||
dc_top_bg_day_finish: "atlas/images/img_dc_bg2.png",
|
||||
dc_top_bg_month_finish: "atlas/images/img_dc_finished.png",
|
||||
|
||||
trophy_01: "atlas/trophys/trophy_01.png",
|
||||
trophy_02: "atlas/trophys/trophy_02.png",
|
||||
trophy_03: "atlas/trophys/trophy_03.png",
|
||||
trophy_04: "atlas/trophys/trophy_04.png",
|
||||
trophy_05: "atlas/trophys/trophy_05.png",
|
||||
trophy_06: "atlas/trophys/trophy_06.png",
|
||||
trophy_07: "atlas/trophys/trophy_07.png",
|
||||
trophy_08: "atlas/trophys/trophy_08.png",
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { respath } from "../constants/respath"
|
||||
import { StorageManager } from "./StorageManager"
|
||||
import { Stage } from "../views/Stage"
|
||||
import { DailyChallenge } from "../views/DailyChallenge"
|
||||
|
||||
|
||||
const { regClass, property } = Laya
|
||||
@@ -39,7 +40,8 @@ export class UIManager extends Laya.Script {
|
||||
public loadDCUI(): void {
|
||||
Laya.loader.load(respath.dc_ui_res).then((go)=>{
|
||||
var prefab = go.create()
|
||||
this.getUIRoot().addChild(prefab)
|
||||
var dc = this.getUIRoot().addChild(prefab).getComponent(DailyChallenge)
|
||||
dc.loadWithMonth()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -56,4 +56,4 @@ export interface DataProgress {
|
||||
export interface DataUser {
|
||||
dones: Array<StageProgress>,//关卡完成进度
|
||||
progresses: Array<DataProgress>,//主线各个难度进度
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,10 @@ const { regClass, property } = Laya;
|
||||
export class CalendarUnit extends Laya.Script {
|
||||
declare owner : Laya.Box;
|
||||
|
||||
@property(Number)
|
||||
public year: number = 0;
|
||||
@property(Number)
|
||||
public month: number = 0;
|
||||
@property(Number)
|
||||
public day: number = 0;
|
||||
@property(Boolean)
|
||||
@@ -38,11 +42,17 @@ export class CalendarUnit extends Laya.Script {
|
||||
|
||||
}
|
||||
|
||||
public onInit(day: number, open: boolean, progress: number, label_obj: Laya.Label, handler: any, func: any): void {
|
||||
this.day = day;
|
||||
public onInit(label_obj: Laya.Label): void {
|
||||
this.label_show = label_obj
|
||||
}
|
||||
|
||||
public setCalendarUnit(year: number, month: number, day: number, open: boolean, progress: number, handler: any, func: any): void {
|
||||
this.selected = false
|
||||
this.year = year
|
||||
this.month = month
|
||||
this.day = day
|
||||
this.open = open
|
||||
this.progress = progress
|
||||
this.label_show = label_obj
|
||||
if (open) {
|
||||
if (progress >= 1) {
|
||||
this.label_show.text = ""
|
||||
|
||||
@@ -6,8 +6,8 @@ import { LevelManager } from "../models/LevelManager";
|
||||
import { UIManager } from "../models/UIManager";
|
||||
import { respath } from "../constants/respath";
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
@regClass()
|
||||
export class DailyChallenge extends Laya.Script {
|
||||
declare owner : Laya.Box;
|
||||
@@ -16,6 +16,12 @@ export class DailyChallenge extends Laya.Script {
|
||||
public btn_back: Laya.Button
|
||||
@property(Laya.Image)
|
||||
public btn_trophy: Laya.Image
|
||||
@property(Laya.Image)
|
||||
public icon_trophy: Laya.Image
|
||||
@property(Laya.Image)
|
||||
public btn_left: Laya.Image
|
||||
@property(Laya.Image)
|
||||
public btn_right: Laya.Image
|
||||
|
||||
@property(Laya.Image)
|
||||
public bg_dc: Laya.Image;
|
||||
@@ -46,9 +52,11 @@ export class DailyChallenge extends Laya.Script {
|
||||
@property(Laya.Box)
|
||||
public obj_labels: Laya.Box;
|
||||
private units: Array<CalendarUnit> = new Array();
|
||||
private selectedUnit: CalendarUnit;
|
||||
|
||||
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
||||
private selectedUnit: CalendarUnit;
|
||||
private currentIndex: number
|
||||
private indexMax: number
|
||||
|
||||
onAwake(): void {
|
||||
this.btn_back.on(Laya.Event.CLICK, this, ()=>{
|
||||
UIManager.getInstance().loadHomeUI()
|
||||
@@ -57,64 +65,6 @@ export class DailyChallenge extends Laya.Script {
|
||||
this.btn_trophy.on(Laya.Event.CLICK, this, ()=>{
|
||||
UIManager.getInstance().loadTrophyUI()
|
||||
})
|
||||
var dayBegin = 4
|
||||
var dayCount = 31
|
||||
var user = StorageManager.getInstance().getUser()
|
||||
var now = new Date()
|
||||
var year = now.getFullYear()
|
||||
var month = now.getMonth() + 1
|
||||
var dayNow = new Date().getDate()
|
||||
var stageID = `${year}-${month}-${dayNow}`
|
||||
var starCount = user.get_doneCountBydate(year, month)
|
||||
if (starCount >= dayCount) {
|
||||
this.bg_dc.skin = respath.dc_top_bg_month_finish
|
||||
}
|
||||
else {
|
||||
var progress = user.get_done(stageID)
|
||||
console.log("progress >>>>>>>>>>>>>", stageID, progress)
|
||||
if (progress >= 1) {
|
||||
this.bg_dc.skin = respath.dc_top_bg_day_finish
|
||||
}
|
||||
else {
|
||||
this.bg_dc.skin = respath.dc_top_bg_normal
|
||||
}
|
||||
}
|
||||
this.label_year.text = year.toString()
|
||||
this.label_month.text = config.MONTH_FULLNAMES[month-1]
|
||||
this.label_star.text = `${starCount}/${dayCount}`
|
||||
|
||||
var day = 1
|
||||
var index = -1
|
||||
for (var i=0; i<this.obj_items.numChildren; i++) {
|
||||
var hbox = this.obj_items.getChildAt(i)
|
||||
var l_hbox = this.obj_labels.getChildAt(i)
|
||||
for (var j=0; j<hbox.numChildren; j++) {
|
||||
var obj = hbox.getChildAt(j) as Laya.Box
|
||||
var l_obj = l_hbox.getChildAt(j) as Laya.Label
|
||||
index ++
|
||||
if (index >= dayBegin && index < dayBegin+dayCount) {
|
||||
obj.visible = true
|
||||
l_obj.visible = true
|
||||
var unit = obj.getComponent(CalendarUnit)
|
||||
this.units.push(unit)
|
||||
var stageID = `${year}-${month}-${day}`
|
||||
var progress = user.get_done(stageID)
|
||||
unit.onInit(day, day<=dayNow, progress, l_obj, this, this.onClickUnit)
|
||||
if (day == dayNow) {
|
||||
this.selectedUnit = unit
|
||||
}
|
||||
day ++
|
||||
}
|
||||
else {
|
||||
obj.visible = false
|
||||
l_obj.visible = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.onApplyUnit(this.selectedUnit)
|
||||
|
||||
this.btn_play.on(Laya.Event.CLICK, this, (evt: Laya.Event)=>{
|
||||
// console.log(">>>>>>>>>>>>>>>>>>>>>>>", this.selectedUnit.day)
|
||||
var now = new Date()
|
||||
@@ -137,6 +87,132 @@ export class DailyChallenge extends Laya.Script {
|
||||
UIManager.getInstance().loadStageUI(stageID);
|
||||
this.owner.destroy()
|
||||
})
|
||||
|
||||
for (var i=0; i<this.obj_items.numChildren; i++) {
|
||||
var hbox = this.obj_items.getChildAt(i)
|
||||
var l_hbox = this.obj_labels.getChildAt(i)
|
||||
for (var j=0; j<hbox.numChildren; j++) {
|
||||
var unit = hbox.getChildAt(j).getComponent(CalendarUnit)
|
||||
var l_obj = l_hbox.getChildAt(j) as Laya.Label
|
||||
this.units.push(unit)
|
||||
unit.onInit(l_obj)
|
||||
}
|
||||
}
|
||||
|
||||
this.indexMax = config.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]
|
||||
if (nowYear == obj.year && nowMonth == obj.month) {
|
||||
this.indexMax = i;
|
||||
break
|
||||
}
|
||||
}
|
||||
this.btn_left.on(Laya.Event.CLICK, this, ()=>{
|
||||
if (this.currentIndex > 0) {
|
||||
this.currentIndex --
|
||||
this.loadWithIndex(this.currentIndex)
|
||||
}
|
||||
})
|
||||
this.btn_right.on(Laya.Event.CLICK, this, ()=>{
|
||||
if (this.currentIndex < this.indexMax) {
|
||||
this.currentIndex ++
|
||||
this.loadWithIndex(this.currentIndex)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
loadWithMonth(): void {
|
||||
var now = new Date()
|
||||
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]
|
||||
if (nowYear == obj.year && nowMonth == obj.month) {
|
||||
this.currentIndex = i;
|
||||
break
|
||||
}
|
||||
}
|
||||
console.log("DailyChallenge loadWithMonth >>>>>>>>>>>>>>>", nowYear, nowMonth, this.currentIndex)
|
||||
this.loadWithIndex(this.currentIndex)
|
||||
}
|
||||
|
||||
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 user = StorageManager.getInstance().getUser()
|
||||
var now = new Date()
|
||||
var nowYear = now.getFullYear()
|
||||
var nowMonth = now.getMonth() + 1
|
||||
var nowDay = new Date().getDate()
|
||||
|
||||
this.icon_trophy.skin = info.icon_res
|
||||
//设置背景
|
||||
var starCount = user.get_doneCountBydate(info.year, info.month)
|
||||
if (starCount >= info.dayCount) {
|
||||
this.bg_dc.skin = respath.dc_top_bg_month_finish
|
||||
}
|
||||
else {
|
||||
if (info.year == nowYear && info.month == nowMonth) {//当前月份
|
||||
var stageID = `${info.year}-${info.month}-${nowDay}`
|
||||
var progress = user.get_done(stageID)
|
||||
console.log("progress >>>>>>>>>>>>>", stageID, progress)
|
||||
if (progress >= 1) {
|
||||
this.bg_dc.skin = respath.dc_top_bg_day_finish
|
||||
}
|
||||
else {
|
||||
this.bg_dc.skin = respath.dc_top_bg_normal
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.bg_dc.skin = respath.dc_top_bg_normal
|
||||
}
|
||||
}
|
||||
this.label_year.text = info.year.toString()
|
||||
this.label_month.text = config.MONTH_FULLNAMES[info.month-1]
|
||||
this.label_star.text = `${starCount}/${info.dayCount}`
|
||||
|
||||
this.selectedUnit = null
|
||||
var day = 1
|
||||
for (var i=0; i<this.units.length; i++) {
|
||||
var unit = this.units[i]
|
||||
if (i >= info.begin && i < info.begin+info.dayCount) {
|
||||
unit.owner.visible = true
|
||||
unit.label_show.visible = true
|
||||
var open = true
|
||||
if (info.year > nowYear) {
|
||||
open = false
|
||||
}
|
||||
else if (info.year == nowYear) {
|
||||
if (info.month > nowMonth) {
|
||||
open = false
|
||||
}
|
||||
else if (info.month == nowMonth) {
|
||||
if (day > nowDay) {
|
||||
open = false
|
||||
}
|
||||
}
|
||||
}
|
||||
var stageID = `${info.year}-${info.month}-${day}`
|
||||
var progress = user.get_done(stageID)
|
||||
unit.setCalendarUnit(info.year, info.month, day, open, progress, this, this.onClickUnit)
|
||||
if (info.year == nowYear && info.month == nowMonth && day == nowDay) {
|
||||
this.selectedUnit = unit
|
||||
}
|
||||
day ++
|
||||
}
|
||||
else {
|
||||
unit.owner.visible = false
|
||||
unit.label_show.visible = false
|
||||
}
|
||||
}
|
||||
if (this.selectedUnit == null)
|
||||
this.selectedUnit = this.units[info.begin+info.dayCount-1]
|
||||
this.onApplyUnit(this.selectedUnit)
|
||||
}
|
||||
|
||||
public onApplyUnit(unit: CalendarUnit): void {
|
||||
@@ -144,12 +220,8 @@ export class DailyChallenge extends Laya.Script {
|
||||
this.selectedUnit = unit
|
||||
this.selectedUnit.setSelected(true)
|
||||
|
||||
var now = new Date()
|
||||
var year = now.getFullYear()
|
||||
var month = now.getMonth() + 1
|
||||
var dayNow = unit.day
|
||||
var stageID = `${year}-${month}-${dayNow}`
|
||||
this.label_date.text = `${config.MONTH_ABBRS[month-1]} ${dayNow},${year}`
|
||||
var stageID = `${unit.year}-${unit.month}-${unit.day}`
|
||||
this.label_date.text = `${config.MONTH_ABBRS[unit.month-1]} ${unit.day},${unit.year}`
|
||||
var user = StorageManager.getInstance().getUser()
|
||||
var progress = user.get_done(stageID)
|
||||
// console.log("onApplyUnit >>>>>", stageID, progress)
|
||||
|
||||
@@ -15,6 +15,8 @@ export class Home extends Laya.Script {
|
||||
|
||||
@property(Laya.Image)
|
||||
public bg_dc: Laya.Image;
|
||||
@property(Laya.Image)
|
||||
public icon_dc: Laya.Image;
|
||||
@property(Laya.Label)
|
||||
public label_dc_title: Laya.Label;
|
||||
@property(Laya.Label)
|
||||
@@ -40,15 +42,28 @@ export class Home extends Laya.Script {
|
||||
onAwake(): void {
|
||||
var user = StorageManager.getInstance().getUser()
|
||||
var now = new Date()
|
||||
var year = now.getFullYear()
|
||||
var month = now.getMonth() + 1
|
||||
var dayNow = new Date().getDate()
|
||||
var stageID = `${year}-${month}-${dayNow}`
|
||||
|
||||
if (user.get_doneCountBydate(year, month) >= 31) {
|
||||
this.bg_dc.skin = respath.home_top_dc_bg_finish
|
||||
this.label_dc_title.color = "#ffffff"
|
||||
this.label_dc_date.color = "#ffffff"
|
||||
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
|
||||
}
|
||||
}
|
||||
if (find) {
|
||||
this.icon_dc.skin = find.icon_res
|
||||
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"
|
||||
}
|
||||
else {
|
||||
this.bg_dc.skin = respath.home_top_dc_bg_normal
|
||||
this.label_dc_title.color = "#2d3138"
|
||||
this.label_dc_date.color = "#2d3138"
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.bg_dc.skin = respath.home_top_dc_bg_normal
|
||||
@@ -56,7 +71,9 @@ export class Home extends Laya.Script {
|
||||
this.label_dc_date.color = "#2d3138"
|
||||
}
|
||||
|
||||
this.label_dc_date.text = `${config.MONTH_ABBRS[month-1]} ${dayNow}`
|
||||
var nowDay = new Date().getDate()
|
||||
var stageID = `${nowYear}-${nowMonth}-${nowDay}`
|
||||
this.label_dc_date.text = `${config.MONTH_ABBRS[nowMonth-1]} ${nowDay}`
|
||||
|
||||
var progress = user.get_done(stageID)
|
||||
if (progress <= 0) {
|
||||
@@ -69,7 +86,7 @@ export class Home extends Laya.Script {
|
||||
var list = LevelManager.getInstance().getLevelList(value)
|
||||
random = Math.random()
|
||||
var index = Math.floor(random*list.length)
|
||||
var stageName = `${config.MONTH_ABBRS[month-1]} ${dayNow}`
|
||||
var stageName = `${config.MONTH_ABBRS[nowMonth-1]} ${nowDay}`
|
||||
console.log("随机一个关卡", value, index)
|
||||
StorageManager.getInstance().newStage(stageID, config.STAGE_TYPE.DC, stageName, value, index)
|
||||
UIManager.getInstance().loadStageUI(stageID);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
|
||||
|
||||
import { config } from "../constants/config";
|
||||
import { TrophyUnit } from "./TrophyUnit";
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
@@ -23,14 +24,32 @@ export class TrophyRoom extends Laya.Script {
|
||||
this.owner.destroy()
|
||||
})
|
||||
|
||||
var month = 5
|
||||
var list: Array<any> = new Array()
|
||||
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]
|
||||
list.push(obj)
|
||||
if (obj.year == nowYear && obj.month == nowMonth) {
|
||||
break
|
||||
}
|
||||
}
|
||||
list.reverse()
|
||||
|
||||
var index = -1
|
||||
for (var i=0; i<this.obj_items.numChildren; i++) {
|
||||
var hbox = this.obj_items.getChildAt(i).getChildByName("HBox")
|
||||
for (var j=0; j<hbox.numChildren; j++) {
|
||||
var obj = hbox.getChildAt(j).getComponent(TrophyUnit)
|
||||
this.items.push(obj)
|
||||
obj.onInit(2025, month)
|
||||
month ++
|
||||
var unit = hbox.getChildAt(j).getComponent(TrophyUnit)
|
||||
index ++
|
||||
if (index < list.length) {
|
||||
unit.owner.visible = true
|
||||
unit.onInit(list[index])
|
||||
}
|
||||
else {
|
||||
unit.owner.visible = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,19 @@ export class TrophyUnit extends Laya.Script {
|
||||
@property(Laya.Label)
|
||||
public label_month: Laya.Label;
|
||||
|
||||
public onInit(year: number, month: number): void {
|
||||
public onInit(info: any): void {
|
||||
var user = StorageManager.getInstance().getUser()
|
||||
var starCount = user.get_doneCountBydate(year, month)
|
||||
this.label_count.text = `${starCount}/31`
|
||||
this.label_month.text = config.MONTH_ABBRS[month-1]
|
||||
|
||||
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]
|
||||
if (starCount >= info.dayCount) {
|
||||
this.icon.gray = false
|
||||
this.label_month.color = "#2d3138"
|
||||
}
|
||||
else {
|
||||
this.icon.gray = true
|
||||
this.label_month.color = "#a7abb3"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user