补充UI细节 添加每日挑战

This commit is contained in:
2025-05-20 17:41:43 +08:00
parent b6c1e58f35
commit 18785e7387
53 changed files with 8836 additions and 212 deletions

View File

@@ -12,7 +12,8 @@
"_$comp": [
{
"_$type": "7bad1742-6eed-4d8d-81c0-501dc5bf03d6",
"scriptPath": "../src/Main.ts"
"scriptPath": "../src/Main.ts",
"debug": false
},
{
"_$type": "cd70cd5e-b4cd-4277-ac0a-2224cfbe89ac",

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 B

View File

@@ -0,0 +1,6 @@
{
"uuid": "19283ae3-c041-4a01-8fab-3c03add31bf8",
"importer": {
"textureType": 2
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -0,0 +1,6 @@
{
"uuid": "4458c7de-47ff-496e-a28f-be808c0823b3",
"importer": {
"textureType": 2
}
}

BIN
assets/atlas/comp/star.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -0,0 +1,6 @@
{
"uuid": "c5e80bd0-632f-4460-bce3-ebf9669359e3",
"importer": {
"textureType": 2
}
}

BIN
assets/atlas/comp/star1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@@ -0,0 +1,6 @@
{
"uuid": "71d84f8a-b8bc-46ae-b68b-bbb43fd588d7",
"importer": {
"textureType": 2
}
}

BIN
assets/atlas/comp/star2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

View File

@@ -0,0 +1,6 @@
{
"uuid": "902e1f3a-6f95-4796-8449-974ae5354d72",
"importer": {
"textureType": 2
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 KiB

View File

@@ -0,0 +1,6 @@
{
"uuid": "342d91e6-0434-4d52-b16c-3c536060f881",
"importer": {
"textureType": 2
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 KiB

View File

@@ -0,0 +1,6 @@
{
"uuid": "2b008659-862a-4155-b094-ee87ba692be1",
"importer": {
"textureType": 2
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 KiB

View File

@@ -0,0 +1,6 @@
{
"uuid": "ebbaa034-8dd8-4fb8-abd5-094cdd76f93a",
"importer": {
"textureType": 2
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@@ -0,0 +1,6 @@
{
"uuid": "14316514-e8bf-4d32-bf9c-ba375ea24798",
"importer": {
"textureType": 2
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 530 KiB

View File

@@ -0,0 +1,6 @@
{
"uuid": "3e483f58-04bc-4a60-8aaa-695dfe115668",
"importer": {
"textureType": 2
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 539 KiB

View File

@@ -0,0 +1,6 @@
{
"uuid": "56e0b9d3-d4ea-4e9d-9052-b67612598495",
"importer": {
"textureType": 2
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 KiB

View File

@@ -0,0 +1,6 @@
{
"uuid": "4182ef3f-6065-44dd-83c2-70490f02e9cb",
"importer": {
"textureType": 2
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

View File

@@ -0,0 +1,6 @@
{
"uuid": "0a33c495-5713-4f5d-bb30-d0021966cf7e",
"importer": {
"textureType": 2
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
{
"uuid": "ab0e47f1-b092-4e81-ac0c-ff02fc97c6a0"
}

View File

@@ -42,9 +42,8 @@
"width": 1080,
"height": 1360,
"_mouseState": 2,
"left": 0,
"right": 0,
"bottom": -2440,
"centerX": 0,
"_$child": [
{
"_$id": "bd1s5tvm",

View File

@@ -15,100 +15,501 @@
{
"_$type": "13e020d1-5ab8-4082-80ca-c0d208342103",
"scriptPath": "../src/views/GameDone.ts",
"obj_top": {
"_$ref": "0nnrx7a2"
},
"obj_stars": {
"_$ref": "6pifil84"
},
"obj_star": {
"_$ref": "sxp0g4z9"
},
"label_diffucuty": {
"_$ref": "53v8r278"
},
"label_time": {
"_$ref": "o3ljtnq3"
},
"label_score": {
"_$ref": "yd0d9s4h"
},
"btn_new": {
"_$ref": "ljwrbqm7"
"_$ref": "nad0pj6b"
},
"btn_home": {
"_$ref": "s80wwm91"
},
"btn_continue": {
"_$ref": "jowyx0fm"
}
}
],
"_$child": [
{
"_$id": "ocyocuk7",
"_$id": "z7eqmeuo",
"_$type": "Image",
"name": "bg",
"x": 90,
"y": 482,
"width": 900,
"height": 956,
"_mouseState": 2,
"name": "bg_done",
"width": 1080,
"height": 1920,
"left": 0,
"right": 0,
"top": 0,
"bottom": 0,
"skin": "res://2b008659-862a-4155-b094-ee87ba692be1",
"useSourceSize": true,
"color": "#ffffff"
},
{
"_$id": "0nnrx7a2",
"_$type": "Box",
"name": "top",
"x": 48,
"y": 456,
"width": 984,
"height": 846,
"centerX": 0,
"centerY": 0,
"skin": "res://6ad19646-ed7a-431c-a50e-65c2bcb40751",
"sizeGrid": "40,60,50,60,0",
"color": "#ffffff",
"_$child": [
{
"_$id": "52u6rl70",
"_$id": "v3amkm36",
"_$type": "Image",
"name": "Image",
"x": 322,
"y": 54,
"width": 128,
"height": 128,
"scaleX": 2,
"scaleY": 2,
"name": "light",
"x": -48,
"y": -680,
"width": 1080,
"height": 1920,
"centerX": 0,
"centerY": -296,
"skin": "res://120856c0-7081-4fde-8dca-ae0a78d684e2",
"useSourceSize": true,
"skin": "res://ebbaa034-8dd8-4fb8-abd5-094cdd76f93a",
"color": "#ffffff"
},
{
"_$id": "mqwo6k43",
"_$type": "Image",
"name": "bg",
"width": 984,
"height": 180,
"skin": "res://14316514-e8bf-4d32-bf9c-ba375ea24798",
"color": "#ffffff",
"_$child": [
{
"_$id": "qxb59msp",
"_$type": "Sprite",
"name": "Sprite",
"y": 180,
"width": 984,
"height": 666,
"_gcmds": [
{
"_$type": "DrawRoundRectCmd",
"x": 0,
"y": 0,
"width": 1,
"height": 1,
"lt": 0,
"rt": 0,
"lb": 30,
"rb": 30,
"percent": true,
"lineWidth": 1,
"fillColor": "#FFFFFF"
}
]
},
{
"_$id": "9w23n5lc",
"_$type": "Sprite",
"name": "Sprite(1)",
"x": 44,
"y": 400,
"width": 888,
"height": 372,
"_gcmds": [
{
"_$type": "DrawRoundRectCmd",
"x": 0,
"y": 0,
"width": 1,
"height": 1,
"lt": 0,
"rt": 0,
"lb": 30,
"rb": 30,
"percent": true,
"lineWidth": 1,
"fillColor": "rgba(245, 247, 251, 1)"
}
]
}
]
},
{
"_$id": "6pifil84",
"_$type": "Box",
"name": "stars",
"y": -148,
"width": 984,
"height": 300,
"visible": false,
"centerX": 0,
"_$child": [
{
"_$id": "qqrwgq7s",
"_$type": "Image",
"name": "check(1)",
"x": 69,
"y": 19,
"width": 308,
"height": 309,
"skin": "res://71d84f8a-b8bc-46ae-b68b-bbb43fd588d7",
"useSourceSize": true,
"color": "#ffffff"
},
{
"_$id": "ztzpvc3d",
"_$type": "Image",
"name": "check(2)",
"x": 339,
"width": 306,
"height": 307,
"centerX": 0,
"skin": "res://902e1f3a-6f95-4796-8449-974ae5354d72",
"useSourceSize": true,
"color": "#ffffff"
},
{
"_$id": "go8t9h1s",
"_$type": "Image",
"name": "check(3)",
"x": 696,
"y": -35,
"width": 308,
"height": 309,
"rotation": 26,
"gray": true,
"skin": "res://71d84f8a-b8bc-46ae-b68b-bbb43fd588d7",
"useSourceSize": true,
"color": "#ffffff"
}
]
},
{
"_$id": "sxp0g4z9",
"_$type": "Image",
"name": "star",
"x": 362,
"y": -120,
"width": 108,
"height": 108,
"scaleX": 2.4,
"scaleY": 2.4,
"centerX": 0,
"skin": "res://c5e80bd0-632f-4460-bce3-ebf9669359e3",
"color": "#ffffff"
},
{
"_$id": "t0v4lr20",
"_$type": "Label",
"name": "Label",
"y": 184,
"width": 984,
"height": 100,
"centerX": 0,
"centerY": -189,
"text": "Congratulations!",
"fontSize": 80,
"color": "rgba(0, 0, 0, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
},
{
"_$id": "4ku2eb3q",
"_$type": "VBox",
"name": "summary",
"x": 92,
"y": 453,
"width": 800,
"height": 300,
"centerX": 0,
"space": 0,
"_$child": [
{
"_$id": "1a0e2qp5",
"_$type": "Box",
"name": "Box(1)",
"width": 800,
"height": 100,
"_$child": [
{
"_$id": "sei6jyr4",
"_$type": "Label",
"name": "left",
"width": 400,
"height": 100,
"text": "Difficuty",
"fontSize": 50,
"color": "rgba(123, 129, 140, 1)",
"valign": "middle",
"padding": "0,0,0,0"
},
{
"_$id": "53v8r278",
"_$type": "Label",
"name": "right",
"x": 400,
"width": 400,
"height": 100,
"text": "Medium",
"fontSize": 50,
"color": "rgba(45, 49, 56, 1)",
"align": "right",
"valign": "middle",
"padding": "0,0,0,0"
}
]
},
{
"_$id": "vryuxz1k",
"_$type": "Box",
"name": "Box(2)",
"y": 100,
"width": 800,
"height": 100,
"_$child": [
{
"_$id": "tazeyyxv",
"_$type": "Label",
"name": "left",
"width": 400,
"height": 100,
"text": "Time",
"fontSize": 50,
"color": "rgba(123, 129, 140, 1)",
"valign": "middle",
"padding": "0,0,0,0"
},
{
"_$id": "o3ljtnq3",
"_$type": "Label",
"name": "right",
"x": 400,
"width": 400,
"height": 100,
"text": "Medium",
"fontSize": 50,
"color": "rgba(45, 49, 56, 1)",
"align": "right",
"valign": "middle",
"padding": "0,0,0,0"
}
]
},
{
"_$id": "8qj8gt9o",
"_$type": "Box",
"name": "Box(3)",
"y": 200,
"width": 800,
"height": 100,
"_$child": [
{
"_$id": "8ue5sakn",
"_$type": "Label",
"name": "left",
"width": 400,
"height": 100,
"text": "Score",
"fontSize": 50,
"color": "rgba(123, 129, 140, 1)",
"valign": "middle",
"padding": "0,0,0,0"
},
{
"_$id": "yd0d9s4h",
"_$type": "Label",
"name": "right",
"x": 400,
"width": 400,
"height": 100,
"text": "Medium",
"fontSize": 50,
"color": "rgba(45, 49, 56, 1)",
"align": "right",
"valign": "middle",
"padding": "0,0,0,0"
}
]
}
]
}
]
},
{
"_$id": "ljwrbqm7",
"_$type": "Button",
"name": "btn_new",
"x": 172,
"y": 1182,
"width": 736,
"height": 152,
"_mouseState": 2,
"centerX": 0,
"centerY": 298,
"stateNum": 1,
"skin": "res://2e8c9585-e650-4494-a329-807fd2d2a532",
"sizeGrid": "24,40,24,40,0",
"label": "新游戏",
"labelFont": "",
"labelSize": 60,
"labelBold": true,
"labelColors": "#1d5cdc,#1d5cdc,#1d5cdc",
"labelAlign": "center",
"labelVAlign": "middle"
},
{
"_$id": "t0v4lr20",
"_$type": "Label",
"name": "Label",
"x": 172,
"y": 795,
"width": 736,
"height": 100,
"centerX": 0,
"centerY": -115,
"text": "Well done",
"font": "",
"fontSize": 80,
"color": "rgba(0, 0, 0, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0",
"_$id": "2tsqczlh",
"_$type": "Box",
"name": "bottom",
"y": 1428,
"width": 1080,
"height": 492,
"left": 0,
"right": 0,
"bottom": 0,
"_$child": [
{
"_$id": "kx4e9y8p",
"_$type": "Text",
"name": "Text",
"y": 120,
"width": 736,
"_$id": "nad0pj6b",
"_$type": "Box",
"name": "btn_new",
"x": 168,
"y": 80,
"width": 744,
"height": 156,
"visible": false,
"centerX": 0,
"_$child": [
{
"_$id": "rryy0h1z",
"_$type": "Sprite",
"name": "Sprite",
"width": 744,
"height": 156,
"_gcmds": [
{
"_$type": "DrawRoundRectCmd",
"x": 0,
"y": 0,
"width": 1,
"height": 1,
"lt": 20,
"rt": 20,
"lb": 20,
"rb": 20,
"percent": true,
"lineWidth": 1,
"fillColor": "rgba(29, 92, 220, 1)"
}
]
},
{
"_$id": "t0l9qw7l",
"_$type": "Label",
"name": "Label",
"width": 744,
"height": 156,
"centerX": 0,
"centerY": 0,
"text": "New Game",
"fontSize": 72,
"color": "rgba(255, 255, 255, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
}
]
},
{
"_$id": "s80wwm91",
"_$type": "Box",
"name": "btn_home",
"x": 168,
"y": 274,
"width": 744,
"height": 156,
"visible": false,
"centerX": 0,
"_$child": [
{
"_$id": "xmj0kb6f",
"_$type": "Sprite",
"name": "Sprite",
"width": 744,
"height": 156,
"alpha": 0.18,
"_gcmds": [
{
"_$type": "DrawRoundRectCmd",
"x": 0,
"y": 0,
"width": 1,
"height": 1,
"lt": 20,
"rt": 20,
"lb": 20,
"rb": 20,
"percent": true,
"lineWidth": 1,
"fillColor": "rgba(29, 92, 220, 1)"
}
]
},
{
"_$id": "d003qixi",
"_$type": "Label",
"name": "Label",
"width": 744,
"height": 156,
"centerX": 0,
"centerY": 0,
"text": "Home",
"fontSize": 72,
"color": "rgba(29, 92, 220, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
}
]
},
{
"_$id": "jowyx0fm",
"_$type": "Box",
"name": "btn_continue",
"x": 168,
"y": 274,
"width": 200,
"height": 200,
"text": "[color=#7b818c]你击败了[color=#f1bf44]80%[/color]的玩家[/color]",
"font": "",
"fontSize": 60,
"color": "#FFFFFF",
"ubb": true,
"align": "center",
"leading": 2
"centerX": -272,
"_$child": [
{
"_$id": "0oc03day",
"_$type": "Sprite",
"name": "Sprite",
"width": 744,
"height": 156,
"_gcmds": [
{
"_$type": "DrawRoundRectCmd",
"x": 0,
"y": 0,
"width": 1,
"height": 1,
"lt": 20,
"rt": 20,
"lb": 20,
"rb": 20,
"percent": true,
"lineWidth": 1,
"fillColor": "rgba(29, 92, 220, 1)"
}
]
},
{
"_$id": "cwysgq4l",
"_$type": "Label",
"name": "Label",
"width": 744,
"height": 156,
"centerX": 272,
"centerY": -22,
"text": "Continue",
"fontSize": 72,
"color": "rgba(255, 255, 255, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
}
]
}
]
}

View File

@@ -21,8 +21,11 @@
"btn_restart": {
"_$ref": "y7aniaui"
},
"btn_new": {
"btn_newOrClose": {
"_$ref": "eepsaznr"
},
"label_newOrClose": {
"_$ref": "2r6iotpo"
}
}
],
@@ -181,7 +184,7 @@
{
"_$id": "eepsaznr",
"_$type": "Sprite",
"name": "btn_new",
"name": "btn_newOrClose",
"y": 408,
"width": 744,
"height": 156,

View File

@@ -14,10 +14,22 @@
{
"_$type": "f2970e4d-7a09-4a9b-aef3-45d330c86f4f",
"scriptPath": "../src/views/Home.ts",
"label_dc_title": {
"_$ref": "zbppj6k0"
},
"btn_play": {
"_$ref": "ttv6dk1v"
},
"btn_continue": {
"_$ref": "ofvmzh0x"
},
"btn_more": {
"_$ref": "8mgjn0da"
},
"btn_new_blue": {
"_$ref": "6irhm6t7"
},
"btn_continue": {
"btn_go": {
"_$ref": "9rcb0wtp"
},
"btn_new_white": {
@@ -43,22 +55,205 @@
"color": "#f5f7fb"
},
{
"_$id": "vxgd702p",
"_$type": "Label",
"name": "Label",
"x": 144,
"y": 760,
"width": 792,
"height": 400,
"_$id": "pnoy48ek",
"_$type": "Box",
"name": "dc",
"x": 72,
"y": 160,
"width": 936,
"height": 468,
"top": 160,
"centerX": 0,
"centerY": 0,
"text": "Classic\nSudoku",
"fontSize": 100,
"color": "rgba(123, 129, 140, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
"_$child": [
{
"_$id": "7270vjom",
"_$type": "Image",
"name": "bg",
"width": 936,
"height": 468,
"skin": "res://342d91e6-0434-4d52-b16c-3c536060f881",
"useSourceSize": true,
"color": "#ffffff"
},
{
"_$id": "5ubzcrtp",
"_$type": "Label",
"name": "Label",
"x": 85,
"y": 28,
"width": 767,
"height": 100,
"alpha": 0.6,
"centerX": 0,
"centerY": -156,
"text": "Daily Challenge",
"fontSize": 36,
"color": "rgba(45, 49, 56, 1)",
"bold": true,
"valign": "middle",
"padding": "0,0,0,0"
},
{
"_$id": "zbppj6k0",
"_$type": "Label",
"name": "title",
"x": 85,
"y": 107,
"width": 767,
"height": 100,
"centerX": 0,
"centerY": -77,
"text": "Mar 12",
"fontSize": 60,
"color": "rgba(45, 49, 56, 1)",
"bold": true,
"valign": "middle",
"padding": "0,0,0,0"
},
{
"_$id": "h6dakob0",
"_$type": "Image",
"name": "trophy",
"x": 468,
"width": 468,
"height": 468,
"right": 0,
"skin": "res://0a33c495-5713-4f5d-bb30-d0021966cf7e",
"useSourceSize": true,
"color": "#ffffff"
},
{
"_$id": "ttv6dk1v",
"_$type": "Sprite",
"name": "btn_play",
"x": 72,
"y": 318,
"width": 195,
"height": 96,
"_gcmds": [
{
"_$type": "DrawRoundRectCmd",
"x": 0,
"y": 0,
"width": 1,
"height": 1,
"lt": 10,
"rt": 10,
"lb": 10,
"rb": 10,
"percent": true,
"lineWidth": 1,
"fillColor": "#FFFFFF"
}
],
"_$child": [
{
"_$id": "8s2b3obv",
"_$type": "Label",
"name": "Label",
"width": 195,
"height": 96,
"centerX": 0,
"centerY": 0,
"text": "Play",
"fontSize": 48,
"color": "rgba(29, 92, 220, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
}
]
},
{
"_$id": "ofvmzh0x",
"_$type": "Sprite",
"name": "btn_continue",
"x": 72,
"y": 318,
"width": 309,
"height": 96,
"visible": false,
"_gcmds": [
{
"_$type": "DrawRoundRectCmd",
"x": 0,
"y": 0,
"width": 1,
"height": 1,
"lt": 10,
"rt": 10,
"lb": 10,
"rb": 10,
"percent": true,
"lineWidth": 1,
"fillColor": "#FFFFFF"
}
],
"_$child": [
{
"_$id": "2ou1bw71",
"_$type": "Label",
"name": "Label",
"width": 309,
"height": 96,
"centerX": 0,
"centerY": 0,
"text": "Continue",
"fontSize": 48,
"color": "rgba(29, 92, 220, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
}
]
},
{
"_$id": "8mgjn0da",
"_$type": "Sprite",
"name": "btn_more",
"x": 72,
"y": 318,
"width": 216,
"height": 96,
"visible": false,
"_gcmds": [
{
"_$type": "DrawRoundRectCmd",
"x": 0,
"y": 0,
"width": 1,
"height": 1,
"lt": 10,
"rt": 10,
"lb": 10,
"rb": 10,
"percent": true,
"lineWidth": 1,
"fillColor": "#FFFFFF"
}
],
"_$child": [
{
"_$id": "w132wbbv",
"_$type": "Label",
"name": "Label",
"width": 216,
"height": 96,
"centerX": 0,
"centerY": 0,
"text": "More",
"fontSize": 48,
"color": "rgba(29, 92, 220, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
}
]
}
]
},
{
"_$id": "6irhm6t7",
@@ -115,7 +310,7 @@
{
"_$id": "9rcb0wtp",
"_$type": "Box",
"name": "btn_continue",
"name": "btn_go",
"x": 144,
"y": 1376,
"width": 792,
@@ -276,6 +471,24 @@
"padding": "0,0,0,0"
}
]
},
{
"_$id": "vxgd702p",
"_$type": "Label",
"name": "Label",
"x": 144,
"y": 760,
"width": 792,
"height": 400,
"centerX": 0,
"centerY": 0,
"text": "Classic\nSudoku",
"fontSize": 100,
"color": "rgba(123, 129, 140, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
}
]
}

View File

@@ -23,7 +23,7 @@
"label_mistake": {
"_$ref": "azfx9pw2"
},
"label_diff": {
"label_name": {
"_$ref": "qxei5ih3"
},
"label_time": {
@@ -161,7 +161,7 @@
{
"_$id": "qxei5ih3",
"_$type": "Label",
"name": "label_diff",
"name": "label_name",
"x": 372,
"y": -58,
"width": 300,

View File

@@ -2,14 +2,18 @@
import { StorageManager } from "./models/StorageManager";
import { LevelManager } from "./models/LevelManager";
import { config } from "./constants/config";
const { regClass, property } = Laya;
@regClass()
export class Main extends Laya.Script {
onAwake() {
console.log("Game awake");
@property(Boolean)
public debug: boolean = false
onAwake() {
console.log("Game onAwake")
config.DEBUG = this.debug
LevelManager.getInstance().init()
StorageManager.getInstance().init()
}

View File

@@ -1,10 +1,11 @@
export const config = {
BREAK_POINT: 1, // 竖版和横版的分界宽度
DEBUG: true,
DEBUG: false,
OPEN_GUIDE: true,
MISTAKE_MAX: 3,//最大错误数
@@ -24,6 +25,7 @@ export const config = {
Expert: "Expert",
Extreme: "Extreme",
},
DIFFICULTY_LIST: ["Easy", "Medium", "Hard", "Expert", "Extreme"],
BLOCK_COLOR: {
WHITE: "#ffffff",
@@ -32,7 +34,7 @@ export const config = {
BLUE: "#2559c0",
},
MONTH_ABBRS: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
}

View File

@@ -2,6 +2,7 @@
export const respath = {
home_ui_res: "resources/Home.lh",
dc_ui_res: "resources/DailyChallenge.lh",
stage_ui_res: "resources/Stage.lh",
gameover_ui_res: "resources/GameOver.lh",
gamedone_ui_res: "resources/GameDone.lh",

View File

@@ -110,6 +110,14 @@ export class DOStage {
StorageManager.getInstance().onChanged()
}
public get_score(): number {
return this.data.score
}
public set_score(score: number): void {
this.data.score = score
StorageManager.getInstance().onChanged()
}
public get_duration(): number {
return this.data.duration
}

View File

@@ -1,4 +1,4 @@
import { DataProgress, DataUser } from "../types/global";
import { DataProgress, DataUser, StageProgress } from "../types/global";
import { StorageManager } from "./StorageManager"
@@ -15,22 +15,37 @@ export class DOUser {
}
//====================================持久化数据
public get_isCompletedMain(): boolean {
return this.data.isCompletedMain
}
public set_isCompletedMain(isCompletedMain: boolean): void {
this.data.isCompletedMain = isCompletedMain
StorageManager.getInstance().saveUser()
}
public get_dones(): Array<string> {
return this.data.dones
}
public add_done(stageID: string): void {
if (this.data.dones.indexOf(stageID) < 0) {
this.data.dones.push(stageID)
StorageManager.getInstance().saveUser()
public get_done(stageID: string): number {
var find: StageProgress
for (var i=0; i<this.data.dones.length; i++) {
var obj = this.data.dones[i]
if (obj.stageID == stageID) {
find = obj
break
}
}
if (find) {
return find.progress
}
return 0
}
public update_stage_done(stageID: string, progress: number): void {
var find: StageProgress
for (var i=0; i<this.data.dones.length; i++) {
var obj = this.data.dones[i]
if (obj.stageID == stageID) {
find = obj
break
}
}
if (find) {
find.progress = progress
}
else {
find = {stageID: stageID, progress: progress}
this.data.dones.push(find)
}
StorageManager.getInstance().saveUser()
}
public get_progress(difficulty: string): number {

View File

@@ -39,7 +39,7 @@ export class EventManager {
}
}
public DispatchEvent(eventID: string, arg: any): void {
public DispatchEvent(eventID: string, arg: any=null): void {
if (this.listeners.has(eventID)) {
var list: Array<any> = this.listeners.get(eventID)
for (var i=0; i<list.length; i++) {

View File

@@ -141,6 +141,11 @@ export class LevelManager {
})
}
public getLevelList(difficulty: string): Array<string> {
var list = this.levelMap.get(difficulty)
return list
}
public getLevelStr(difficulty: string, index: number): string {
var list = this.levelMap.get(difficulty)
if (list) {

View File

@@ -1,5 +1,6 @@
import { config } from "../constants/config"
import { DataStage, createDataStage } from "../types/global"
import { DOStage } from "./DOStage"
import { DOUser } from "./DOUser"
@@ -29,7 +30,7 @@ export class StorageManager {
this.user = new DOUser(JSON.parse(jsonStr))
}
else {
this.user = new DOUser({isCompletedMain: true, dones: new Array(), progresses: new Array()})
this.user = new DOUser({dones: new Array(), progresses: new Array()})
}
}
this.stageID = ""
@@ -48,14 +49,6 @@ export class StorageManager {
}
public cleanStage(stageID: string): void {
if (this.stageMap.has(stageID)) {
this.stageMap.delete(stageID)
}
Laya.LocalStorage.removeItem(stageID)
this.stageID = ""
this.stageChanged = false
}
public newStage(stageID: string, type: number, name: string, difficulty: string, index: number): DOStage {
this.stageID = stageID
this.stageChanged = false
@@ -82,6 +75,25 @@ export class StorageManager {
}
return null
}
public getStage(): DOStage {//获取当前关卡数据对象,注意判空
if (this.stageID && this.stageMap) {
return this.stageMap.get(this.stageID)
}
return null
}
public cleanStage(): void {//清空当前关卡数据对象,注意判空
this.user.update_stage_done(this.stageID, 0)
if (this.stageMap.has(this.stageID)) {
this.stageMap.delete(this.stageID)
}
Laya.LocalStorage.removeItem(this.stageID)
this.stageID = ""
this.stageChanged = false
}
public cleanMainStage(): void {//清空主线关卡数据
this.stageID = config.DEFAULT_STAGE_ID
this.cleanStage()
}
public saveStage(): void {
if (this.stageChanged) {
this.stageChanged = false
@@ -98,7 +110,7 @@ export class StorageManager {
public cleanAll(): void {
this.user = new DOUser({isCompletedMain: true, dones: new Array(), progresses: new Array()})
this.user = new DOUser({dones: new Array(), progresses: new Array()})
this.stageID = ""
this.stageChanged = false

View File

@@ -36,6 +36,13 @@ 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)
})
}
public loadStageUI(stageID: string): void {
if (this.stage) {
this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID))
@@ -48,7 +55,6 @@ export class UIManager extends Laya.Script {
})
}
}
public closeStageUI(): void {
if (this.stage) {
this.stage.owner.destroy()

View File

@@ -23,6 +23,7 @@ export interface DataStage {
difficulty: string,
index: number,
mistake?: number,
score?: number,
duration?: number,
note_open?: boolean,
hint?: number,
@@ -33,6 +34,7 @@ export interface DataStage {
export function createDataStage(id: string, type: number, name: string, difficulty: string, index: number): DataStage {
var data: DataStage = {id: id, type: type, name: name, difficulty: difficulty, index: index}
data.mistake = 0
data.score = 0
data.duration = 0
data.note_open = false
data.hint = 2
@@ -43,12 +45,15 @@ export function createDataStage(id: string, type: number, name: string, difficul
}
export interface StageProgress {//关卡完成进度
stageID: string,
progress: number,
}
export interface DataProgress {
difficulty: string,
index: number,
}
export interface DataUser {
isCompletedMain: boolean,//当前主线是否已完成 默认true
dones: Array<string>,//已完成关卡
progresses: Array<DataProgress>,//已经完成的进度
dones: Array<StageProgress>,//关卡完成进度
progresses: Array<DataProgress>,//主线各个难度进度
}

115
src/views/CalendarUnit.ts Normal file
View File

@@ -0,0 +1,115 @@
const { regClass, property } = Laya;
@regClass()
export class CalendarUnit extends Laya.Script {
declare owner : Laya.Box;
@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(day: number, open: boolean, progress: number, label_obj: Laya.Label, handler: any, func: any): void {
this.day = day;
this.open = open
this.progress = progress
this.label_show = label_obj
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"
}

161
src/views/DailyChallenge.ts Normal file
View File

@@ -0,0 +1,161 @@
import { config } from "../constants/config";
import { Utility_ConvertSecondToString } from "../utils/utility";
import { StorageManager } from "../models/StorageManager";
import { CalendarUnit } from "./CalendarUnit";
import { LevelManager } from "../models/LevelManager";
import { UIManager } from "../models/UIManager";
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.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;
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
this.btn_back.on(Laya.Event.CLICK, this, ()=>{
UIManager.getInstance().loadHomeUI()
this.owner.destroy()
})
var now = new Date()
var year = now.getFullYear()
var month = now.getMonth() + 1
var dayNow = new Date().getDate()
var stageID = `${year}-${month}-${day}`
this.label_year.text = year.toString()
this.label_month.text = config.MONTH_ABBRS[month-1]
var starCount = 0
var day = 1
var dayCount = 31
var begin = 4
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 >= begin && index < begin+dayCount) {
obj.visible = true
l_obj.visible = true
var unit = obj.getComponent(CalendarUnit)
this.units.push(unit)
var stageID = `${year}-${month}-${day}`
var progress = StorageManager.getInstance().getUser().get_done(stageID)
unit.onInit(day, day<=dayNow, progress, l_obj, this, this.onClickUnit)
if (day == dayNow) {
this.selectedUnit = unit
}
if (progress >= 1) {
starCount ++
}
day ++
}
else {
obj.visible = false
l_obj.visible = false
}
}
}
this.label_star.text = `${starCount}/${dayCount}`
this.onApplyUnit(this.selectedUnit)
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 random = Math.random()
var value = config.DIFFICULTY_LIST[Math.floor(random*config.DIFFICULTY_LIST.length)]
var list = LevelManager.getInstance().getLevelList(value)
random = Math.random()
var index = Math.floor(random*list.length)
var stageName = `${config.MONTH_ABBRS[month-1]} ${dayNow}`
console.log("随机一个关卡", value, index)
StorageManager.getInstance().newStage(stageID, config.STAGE_TYPE.DC, stageName, value, index)
}
UIManager.getInstance().loadStageUI(stageID);
this.owner.destroy()
})
}
public onApplyUnit(unit: CalendarUnit): void {
this.selectedUnit.setSelected(false)
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 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)
}
}

View File

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

View File

@@ -30,18 +30,12 @@ export class Difficulty extends Laya.Script {
}
public onInit(callback: any): void {
var list: Array<string> = new Array()
list.push(config.DIFFICULTY_TYPE.Easy)
list.push(config.DIFFICULTY_TYPE.Medium)
list.push(config.DIFFICULTY_TYPE.Hard)
list.push(config.DIFFICULTY_TYPE.Expert)
list.push(config.DIFFICULTY_TYPE.Extreme)
for (var i=0; i<list.length; i++) {
for (var i=0; i<config.DIFFICULTY_LIST.length; i++) {
var obj = this.obj_items.getChildAt(i)
var Label = obj.getChildByName("Label") as Laya.Label
Label.text = list[i]
Label.text = config.DIFFICULTY_LIST[i]
var data = obj.getComponent(CommonData)
data.strValue = list[i]
data.strValue = config.DIFFICULTY_LIST[i]
obj.on(Laya.Event.CLICK, this, (evt: Laya.Event)=>{
var data = evt.target.getComponent(CommonData)
if (callback) {

View File

@@ -1,5 +1,10 @@
import { UIManager } from "../models/UIManager";
import { StorageManager } from "../models/StorageManager";
import { Utility_ConvertSecondToString } from "../utils/utility";
import { respath } from "../constants/respath";
import { Difficulty } from "./Difficulty";
import { LevelManager } from "../models/LevelManager";
import { config } from "../constants/config";
const { regClass, property } = Laya;
@@ -7,15 +12,80 @@ const { regClass, property } = Laya;
export class GameDone extends Laya.Script {
declare owner : Laya.Box;
@property(Laya.Button)
public btn_new: Laya.Button
@property(Laya.Box)
public obj_top: Laya.Box
@property(Laya.Box)
public obj_stars: Laya.Box
@property(Laya.Image)
public obj_star: Laya.Image
@property(Laya.Label)
public label_diffucuty: Laya.Label
@property(Laya.Label)
public label_time: Laya.Label
@property(Laya.Label)
public label_score: Laya.Label
@property(Laya.Box)
public btn_new: Laya.Box
@property(Laya.Box)
public btn_home: Laya.Box
@property(Laya.Box)
public btn_continue: Laya.Box
onStart(): void {
var doStage = StorageManager.getInstance().getStage()
var type = doStage.get_stageType()
if (type == config.STAGE_TYPE.MAIN) {
this.obj_top.y = 356
this.obj_stars.visible = true
this.obj_star.visible = false
this.btn_new.visible = true
this.btn_home.visible = true
this.btn_continue.visible = false
}
else {
this.obj_top.y = 456
this.obj_stars.visible = false
this.obj_star.visible = true
this.btn_new.visible = false
this.btn_home.visible = false
this.btn_continue.visible = true
}
this.label_diffucuty.text = doStage.get_difficulty()
this.label_time.text = Utility_ConvertSecondToString(doStage.get_duration())
this.label_score.text = doStage.get_score().toString()
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
this.btn_new.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
UIManager.getInstance().closeStage();
UIManager.getInstance().loadHome();
StorageManager.getInstance().cleanStage()
Laya.loader.load(respath.difficulty_ui_res).then((go)=>{
var prefab = go.create()
var d = UIManager.getInstance().getUIRoot().addChild(prefab).getComponent(Difficulty)
d.onInit((value: string)=> {
console.log("选择难度", value)
StorageManager.getInstance().cleanStage()
var user = StorageManager.getInstance().getUser()
var index = user.get_progress(value)
var levelStr = LevelManager.getInstance().getLevelStr(value, index)
if (!levelStr || levelStr.length <= 0) {//说明当前难度已经打通了,所以给他从头开始
user.update_progress(value, 0)
}
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, value, user.get_progress(value))
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID);
this.owner.destroy()
})
})
})
this.btn_home.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
UIManager.getInstance().loadHomeUI()
UIManager.getInstance().closeStageUI();
this.owner.destroy()
})
this.btn_continue.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
UIManager.getInstance().loadDCUI()
UIManager.getInstance().closeStageUI();
this.owner.destroy()
})
}

View File

@@ -20,49 +20,65 @@ export class GameOver extends Laya.Script {
public btn_restart: Laya.Sprite
@property(Laya.Sprite)
public btn_new: Laya.Sprite
public btn_newOrClose: Laya.Sprite
@property(Laya.Label)
public label_newOrClose: Laya.Label
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
this.btn_second.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
var doStage = StorageManager.getInstance().loadStage(config.DEFAULT_STAGE_ID)
var doStage = StorageManager.getInstance().getStage()
doStage.set_mistake(doStage.get_mistake()-1)
EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE, "adsf")
EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE)
this.owner.destroy()
})
this.btn_restart.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
var doStage = StorageManager.getInstance().loadStage(config.DEFAULT_STAGE_ID)
var doStage = StorageManager.getInstance().getStage()
var stageID = doStage.get_stageID()
var type = doStage.get_stageType()
var difficulty = doStage.get_difficulty()
StorageManager.getInstance().cleanStage(config.DEFAULT_STAGE_ID)
StorageManager.getInstance().cleanStage()
var user = StorageManager.getInstance().getUser()
user.set_isCompletedMain(false)
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty, user.get_progress(difficulty))
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID);
StorageManager.getInstance().newStage(stageID, type, difficulty, difficulty, user.get_progress(difficulty))
UIManager.getInstance().loadStageUI(stageID);
this.owner.destroy()
})
this.btn_new.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
Laya.loader.load(respath.difficulty_ui_res).then((go)=>{
var prefab = go.create()
var d = UIManager.getInstance().getUIRoot().addChild(prefab).getComponent(Difficulty)
d.onInit((value: string)=> {
console.log("选择难度", value)
StorageManager.getInstance().cleanStage(config.DEFAULT_STAGE_ID)
var user = StorageManager.getInstance().getUser()
user.set_isCompletedMain(false)
var index = user.get_progress(value)
var levelStr = LevelManager.getInstance().getLevelStr(value, index)
if (!levelStr || levelStr.length <= 0) {//说明当前难度已经打通了,所以给他从头开始
user.update_progress(value, 0)
}
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, value, user.get_progress(value))
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID);
this.owner.destroy()
var doStage = StorageManager.getInstance().getStage()
var type = doStage.get_stageType()
if (type == config.STAGE_TYPE.MAIN) {
this.label_newOrClose.text = "New Game"
this.btn_newOrClose.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
Laya.loader.load(respath.difficulty_ui_res).then((go)=>{
var prefab = go.create()
var d = UIManager.getInstance().getUIRoot().addChild(prefab).getComponent(Difficulty)
d.onInit((value: string)=> {
console.log("选择难度", value)
StorageManager.getInstance().cleanStage()
var user = StorageManager.getInstance().getUser()
var index = user.get_progress(value)
var levelStr = LevelManager.getInstance().getLevelStr(value, index)
if (!levelStr || levelStr.length <= 0) {//说明当前难度已经打通了,所以给他从头开始
user.update_progress(value, 0)
}
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, value, user.get_progress(value))
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID);
this.owner.destroy()
})
})
})
})
}
else {
this.label_newOrClose.text = "Close"
this.btn_newOrClose.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
UIManager.getInstance().loadDCUI()
UIManager.getInstance().closeStageUI();
this.owner.destroy()
})
}
}
}

View File

@@ -13,11 +13,19 @@ const { regClass, property } = Laya
export class Home extends Laya.Script {
declare owner : Laya.Box;
@property(Laya.Box)
public btn_new_blue: Laya.Box;
@property(Laya.Label)
public label_dc_title: Laya.Label;
@property(Laya.Sprite)
public btn_play: Laya.Sprite;
@property(Laya.Sprite)
public btn_continue: Laya.Sprite;
@property(Laya.Sprite)
public btn_more: Laya.Sprite;
@property(Laya.Box)
public btn_continue: Laya.Box;
public btn_new_blue: Laya.Box;
@property(Laya.Box)
public btn_go: Laya.Box;
@property(Laya.Box)
public btn_new_white: Laya.Box;
@@ -26,34 +34,87 @@ 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()
this.label_dc_title.text = `${config.MONTH_ABBRS[month-1]} ${dayNow}`
var stageID = `${year}-${month}-${dayNow}`
var progress = user.get_done(stageID)
if (progress <= 0) {
this.btn_play.visible = true
this.btn_continue.visible = false
this.btn_more.visible = false
this.btn_play.on(Laya.Event.CLICK, this, ()=>{//Play
var random = Math.random()
var value = config.DIFFICULTY_LIST[Math.floor(random*config.DIFFICULTY_LIST.length)]
var list = LevelManager.getInstance().getLevelList(value)
random = Math.random()
var index = Math.floor(random*list.length)
var stageName = `${config.MONTH_ABBRS[month-1]} ${dayNow}`
console.log("随机一个关卡", value, index)
StorageManager.getInstance().newStage(stageID, config.STAGE_TYPE.DC, stageName, value, index)
UIManager.getInstance().loadStageUI(stageID);
this.owner.destroy()
})
}
else if (progress >= 1) {
this.btn_play.visible = false
this.btn_continue.visible = false
this.btn_more.visible = true
this.btn_more.on(Laya.Event.CLICK, this, ()=>{//更多
UIManager.getInstance().loadDCUI();
this.owner.destroy()
})
}
else {
this.btn_play.visible = false
this.btn_continue.visible = true
this.btn_more.visible = false
this.btn_continue.on(Laya.Event.CLICK, this, ()=>{//继续
UIManager.getInstance().loadStageUI(stageID);
this.owner.destroy()
})
}
this.btn_new_blue.on(Laya.Event.CLICK, this, this.onClickNew)
this.btn_new_white.on(Laya.Event.CLICK, this, this.onClickNew)
this.btn_continue.on(Laya.Event.CLICK, this, (evt: Laya.Event)=>{
UIManager.getInstance().closeStageUI()
this.btn_go.on(Laya.Event.CLICK, this, (evt: Laya.Event)=>{
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID);
this.owner.destroy()
})
var user = StorageManager.getInstance().getUser()
this.btn_new_blue.visible = user.get_isCompletedMain()
this.btn_new_white.visible = user.get_isCompletedMain() == false
this.btn_continue.visible = user.get_isCompletedMain() == false
if (user.get_isCompletedMain() == false) {
var label_time = this.btn_continue.getChildByName("time").getChildByName("label_time") as Laya.Label
var doStage = StorageManager.getInstance().loadStage(config.DEFAULT_STAGE_ID)
var duration = doStage.get_duration()
var timeStr = Utility_ConvertSecondToString(duration)
label_time.text = `${timeStr} - ${doStage.get_difficulty()}`
if (user.get_done(config.DEFAULT_STAGE_ID) >= 1) {
console.log("当前主线关卡完成")
this.btn_new_blue.visible = true
this.btn_new_white.visible = false
this.btn_go.visible = false
}
else {
var doStage = StorageManager.getInstance().loadStage(config.DEFAULT_STAGE_ID)
if (doStage) {
console.log("当前主线关卡进行中")
var label_time = this.btn_go.getChildByName("time").getChildByName("label_time") as Laya.Label
var duration = doStage.get_duration()
var timeStr = Utility_ConvertSecondToString(duration)
label_time.text = `${timeStr} - ${doStage.get_difficulty()}`
}
else {
console.log("当前主线关卡未开始")
this.btn_new_blue.visible = true
this.btn_new_white.visible = false
this.btn_go.visible = false
}
}
//测试逻辑
this.btn_clean.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
console.log("btn_clean=", evt);
StorageManager.getInstance().cleanAll()
user = StorageManager.getInstance().getUser()
this.btn_new_blue.visible = user.get_isCompletedMain()
this.btn_new_white.visible = user.get_isCompletedMain() == false
this.btn_continue.visible = user.get_isCompletedMain() == false
})
this.btn_clean.visible = config.DEBUG
//======
@@ -65,11 +126,8 @@ export class Home extends Laya.Script {
var d = UIManager.getInstance().getUIRoot().addChild(prefab).getComponent(Difficulty)
d.onInit((value: string)=> {
console.log("选择难度", value)
UIManager.getInstance().closeStageUI()
StorageManager.getInstance().cleanStage(config.DEFAULT_STAGE_ID)
StorageManager.getInstance().cleanMainStage()
var user = StorageManager.getInstance().getUser()
user.set_isCompletedMain(false)
var index = user.get_progress(value)
var levelStr = LevelManager.getInstance().getLevelStr(value, index)
if (!levelStr || levelStr.length <= 0) {//说明当前难度已经打通了,所以给他从头开始

View File

@@ -22,7 +22,7 @@ export class Stage extends Laya.Script {
@property(Laya.Label)
public label_mistake: Laya.Label;
@property(Laya.Label)
public label_diff: Laya.Label;
public label_name: Laya.Label;
@property(Laya.Label)
public label_time: Laya.Label;
@@ -59,8 +59,14 @@ export class Stage extends Laya.Script {
onAwake(): void {
Stage._instance = this
this.btn_back.on(Laya.Event.CLICK, this, ()=>{
UIManager.getInstance().loadHomeUI();
UIManager.getInstance().closeStageUI();
if (this.data.get_stageType() == config.STAGE_TYPE.MAIN) {
UIManager.getInstance().loadHomeUI();
UIManager.getInstance().closeStageUI();
}
else {
UIManager.getInstance().loadDCUI();
UIManager.getInstance().closeStageUI();
}
})
for (var i=0; i<this.obj_blocks.numChildren; i++) {
var hbox = this.obj_blocks.getChildAt(i);
@@ -116,7 +122,7 @@ export class Stage extends Laya.Script {
this.data = doStage
this.onUpdateScore()
this.label_diff.text = this.data.get_difficulty()
this.label_name.text = this.data.get_stageName()
this.onUpdateMistake()
var begin = Date.now()
Laya.timer.loop(1000, this, ()=>{
@@ -143,13 +149,14 @@ export class Stage extends Laya.Script {
this.onApplyBlock(this.selectedBlock)
}
onUpdateScore(): void {
onUpdateScore(): number {
var score = 0
var blocks = this.data.get_blocks()
for (var i=0; i<blocks.length; i++) {
score += blocks[i].get_score()
}
this.label_score.text = `Score: ${score}`
return score
}
onUpdateMistake(): void {
@@ -341,20 +348,28 @@ export class Stage extends Laya.Script {
}
else {
var b = this.selectedBlock.setShowNumber(showNumber)
this.onUpdateScore()
var score = this.onUpdateScore()
this.onSetBlock(this.selectedBlock, true)
if (b) {
var user = StorageManager.getInstance().getUser()
var all = 0
var finished = 0
var blocks = this.data.get_blocks()
for (var i=0; i<blocks.length; i++) {
if (blocks[i].get_preset() == false) {
all ++
if (blocks[i].get_checked()) {
finished ++
}
}
}
user.update_stage_done(this.data.get_stageID(), finished/all)//更新关卡完成进度
if (this.getIsComplete()) {
console.log("完成关卡")
StorageManager.getInstance().cleanStage(this.data.get_stageID())//完成关卡清除关卡数据
var user = StorageManager.getInstance().getUser()
if (this.data.get_stageType() == config.STAGE_TYPE.MAIN) {
user.set_isCompletedMain(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) {
user.add_done(this.data.get_stageID())
}
UIManager.getInstance().loadGameDoneUI()
}
}