开始添加横屏UI

This commit is contained in:
2025-05-23 20:47:03 +08:00
parent e0d25affa3
commit 354194358b
31 changed files with 58237 additions and 14257 deletions

View File

@@ -0,0 +1,125 @@
const { regClass, property } = Laya;
@regClass()
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)
public open: boolean = false;
@property(Number)
public progress: number = 0;
private selected: boolean = false
@property(Laya.Sprite)
public obj_selected: Laya.Sprite;
@property(Laya.Box)
public obj_pie: Laya.Box;
@property(Laya.Sprite)
public sprite_pie: Laya.Sprite;
@property(Laya.Sprite)
public obj_mask: Laya.Sprite;
@property(Laya.Sprite)
public sprite_mask: Laya.Sprite;
@property(Laya.Image)
public obj_star: Laya.Image;
@property(Laya.Label)
public label_show: Laya.Label;
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
}
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
if (open) {
if (progress >= 1) {
this.label_show.text = ""
}
else {
this.label_show.text = this.day.toString()
}
this.label_show.color = "#2d3138"
this.owner.on(Laya.Event.CLICK, handler, func)
this.updateUnit()
}
else {
this.label_show.text = this.day.toString()
this.label_show.color = "#d3d5db"
this.owner.on(Laya.Event.CLICK, this, (evt: Laya.Event)=>{
})
this.obj_selected.visible = false
this.obj_pie.visible = false
this.obj_mask.visible = false
this.obj_star.visible = false
}
}
public setSelected(selected: boolean): void {
this.selected = selected
this.updateUnit()
}
updateUnit(): void {
if (this.open == false) {
return
}
this.obj_star.visible = this.progress >= 1
if (this.selected) {
this.label_show.color = "#ffffff"
this.obj_selected.visible = true
if (this.progress > 0) {
this.obj_pie.visible = true
this.obj_mask.visible = true
this.sprite_pie.graphics.clear()
this.sprite_pie.graphics.drawPie(48, 48, 48, 0, 360*this.progress, "#ffffff")
this.sprite_mask.graphics.clear()
this.sprite_mask.graphics.drawCircle(0.5, 0.5, 0.5, "#1d5cdc")
}
else {
this.obj_pie.visible = false
this.obj_mask.visible = false
}
}
else {
this.label_show.color = "#2d3138"
this.obj_selected.visible = false
if (this.progress > 0 && this.progress < 1) {
this.obj_pie.visible = true
this.obj_mask.visible = true
this.sprite_pie.graphics.clear()
this.sprite_pie.graphics.drawPie(48, 48, 48, 0, 360*this.progress, "#2d3138")
this.sprite_mask.graphics.clear()
this.sprite_mask.graphics.drawCircle(0.5, 0.5, 0.5, "#ffffff")
}
else {
this.obj_pie.visible = false
this.obj_mask.visible = false
}
}
}
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "04c54914-715e-4e07-8a45-770f2a2c05a6"
}

View File

@@ -0,0 +1,250 @@
import { config } from "../../constants/config";
import { Utility_ConvertSecondToString } from "../../utils/utility";
import { StorageManager } from "../../models/StorageManager";
import { CalendarUnit } from "./CalendarUnit";
import { UIManager } from "../../models/UIManager";
import { respath } from "../../constants/respath";
import { MONTH_LIST } from "../../models/DCManager";
const { regClass, property } = Laya;
@regClass()
export class DailyChallenge extends Laya.Script {
declare owner : Laya.Box;
@property(Laya.Button)
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)
public btn_left: Laya.Box
@property(Laya.Box)
public btn_right: Laya.Box
@property(Laya.Image)
public bg_dc: Laya.Image;
@property(Laya.Label)
public label_year: Laya.Label;
@property(Laya.Label)
public label_month: Laya.Label;
@property(Laya.Label)
public label_star: Laya.Label;
@property(Laya.Box)
public btn_play: Laya.Box
@property(Laya.Label)
public label_play: Laya.Label
@property(Laya.Box)
public obj_summary: Laya.Box
@property(Laya.Label)
public label_date: Laya.Label;
@property(Laya.Label)
public label_diffucuty: Laya.Label
@property(Laya.Label)
public label_score: Laya.Label
@property(Laya.Label)
public label_time: Laya.Label
@property(Laya.Box)
public obj_items: Laya.Box;
@property(Laya.Box)
public obj_labels: Laya.Box;
private units: Array<CalendarUnit> = new Array();
private selectedUnit: CalendarUnit;
private currentIndex: number
private indexMax: number
onAwake(): void {
this.btn_back.on(Laya.Event.CLICK, this, ()=>{
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()
var year = now.getFullYear()
var month = now.getMonth() + 1
var dayNow = this.selectedUnit.day
var stageID = `${year}-${month}-${dayNow}`
var doStage = StorageManager.getInstance().loadStage(stageID)
console.log("play >>>>>>>>>>>>>>>>>>>>>>>", stageID, doStage)
if (!doStage) {
var stageName = `${config.MONTH_ABBRS[month-1]} ${dayNow}`
StorageManager.getInstance().newStage(stageID, config.STAGE_TYPE.DC, stageName)
}
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 = MONTH_LIST.length - 1
var now = new Date()
var nowYear = now.getFullYear()
var nowMonth = now.getMonth() + 1
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
}
}
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<MONTH_LIST.length; i++) {
var obj = 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 = 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 {
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 {
this.selectedUnit.setSelected(false)
this.selectedUnit = unit
this.selectedUnit.setSelected(true)
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)
if (progress >= 1) {
this.btn_play.visible = false
this.obj_summary.visible = true
var doStage = StorageManager.getInstance().loadStage(stageID)
this.label_diffucuty.text = doStage.get_difficulty()
this.label_score.text = doStage.get_score().toString()
this.label_time.text = Utility_ConvertSecondToString(doStage.get_duration())
}
else {
this.btn_play.visible = true
this.obj_summary.visible = false
var doStage = StorageManager.getInstance().loadStage(stageID)
if (doStage) {
this.label_play.text = "Continue"
}
else {
this.label_play.text = "Play"
}
}
}
public onClickUnit(evt: Laya.Event): void {
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)
}
}
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "3f68d98d-3867-41a7-b277-a24d279a22fa"
}

View 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()
})
}
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "0550b681-b602-49fe-900f-e30866ce922c"
}

104
src/views/dc/TrophyRoom.ts Normal file
View File

@@ -0,0 +1,104 @@
import { respath } from "../../constants/respath";
import { MONTH_LIST } from "../../models/DCManager";
import { TrophyUnit } from "./TrophyUnit";
const { regClass, property } = Laya;
@regClass()
export class TrophyRoom extends Laya.Script {
declare owner : Laya.Box;
@property(Laya.Button)
public btn_back: Laya.Button;
@property(Laya.Box)
public obj_items: Laya.Box;
//第一次执行update之前执行只会执行一次
onStart(): void {
this.btn_back.on(Laya.Event.CLICK, this, ()=>{
this.owner.destroy()
})
var infos: Array<any> = new Array()
var now = new Date()
var nowYear = now.getFullYear()
var nowMonth = now.getMonth() + 1
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
}
}
infos.reverse()
var years: Array<number> = new Array()
var monthMap: Map<number, Array<any>> = new Map()
for (var i=0; i<infos.length; i++) {
obj = infos[i]
if (years.indexOf(obj.year) < 0) {
years.push(obj.year)
}
if (monthMap.has(obj.year)== false) {
monthMap.set(obj.year, new Array())
}
var list = monthMap.get(obj.year)
list.push(obj)
}
console.log(">>>>>>>>>>>>years=", years)
Laya.loader.load(respath.trophy_year_ui_res).then((go)=>{
for (var i=1; i<years.length; i++) {
var obj_year = this.obj_items.getChildAt(i)
if (!obj_year) {
var prefab = go.create()
this.obj_items.addChild(prefab)
}
}
Laya.loader.load(respath.trophy_cell_ui_res).then((go)=>{
var itemsHeight = 0
for (var i=0; i<years.length; i++) {
var list = monthMap.get(years[i])
var cellCount = Math.ceil(list.length/3)
var yearHeight = 120 + cellCount * 444
itemsHeight += yearHeight
var obj_year = this.obj_items.getChildAt(i) as Laya.Box
obj_year.height = yearHeight
var label = obj_year.getChildByName("year").getChildByName("Label") as Laya.Label
label.text = years[i].toString()
var index = -1
for (var j=1; j<cellCount+1; j++) {
var obj_cell = obj_year.getChildAt(j)
if (!obj_cell) {
var prefab = go.create()
obj_cell = obj_year.addChild(prefab)
}
var hbox = obj_cell.getChildByName("HBox")
for (var k=0; k<hbox.numChildren; k++) {
var unit = hbox.getChildAt(k).getComponent(TrophyUnit)
index ++
if (index < list.length) {
unit.owner.visible = true
unit.onInit(list[index])
}
else {
unit.owner.visible = false
}
}
}
}
this.obj_items.height = itemsHeight
})
})
}
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "554595b0-0dd8-4e4b-8073-8d775219659c"
}

View File

@@ -0,0 +1,37 @@
import { config } from "../../constants/config";
import { MONTH_LIST } from "../../models/DCManager";
import { TrophyRecord } from "../../types/global";
const { regClass, property } = Laya;
@regClass()
export class TrophyShow 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()
})
}
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "42f2370b-c65c-4119-8725-6d4520582431"
}

View File

@@ -0,0 +1,45 @@
import { config } from "../../constants/config";
import { respath } from "../../constants/respath";
import { StorageManager } from "../../models/StorageManager";
import { UIManager } from "../../models/UIManager";
const { regClass, property } = Laya;
@regClass()
export class TrophyUnit extends Laya.Script {
declare owner : Laya.Box;
@property(Laya.Image)
public bg_light: Laya.Image;
@property(Laya.Image)
public icon: Laya.Image;
@property(Laya.Label)
public label_count: Laya.Label;
@property(Laya.Label)
public label_month: Laya.Label;
public onInit(info: any): void {
var user = StorageManager.getInstance().getUser()
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.bg_light.skin = respath.trophy_bg_light_gold
this.icon.gray = false
this.label_month.color = "#2d3138"
}
else {
this.bg_light.skin = respath.trophy_bg_light_grey
this.icon.gray = true
this.label_month.color = "#a7abb3"
}
this.icon.on(Laya.Event.CLICK, this, ()=>{
var find = user.get_trophyRecord(info.year, info.month)
if (find) {
UIManager.getInstance().loadTrophyShowUI(find)
}
})
}
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "79064920-30a6-4b11-a82e-bbdd4112c4e1"
}