Browse Source

feat: 增加很多功能

dev
npmrun 9 months ago
parent
commit
ca7a2ef217
  1. 2
      index.html
  2. BIN
      public/assets/images/arrow_basic_e.png
  3. BIN
      public/assets/images/arrow_basic_e_small.png
  4. BIN
      public/assets/images/arrow_basic_n.png
  5. BIN
      public/assets/images/arrow_basic_n_small.png
  6. BIN
      public/assets/images/arrow_basic_s.png
  7. BIN
      public/assets/images/arrow_basic_s_small.png
  8. BIN
      public/assets/images/arrow_basic_w.png
  9. BIN
      public/assets/images/arrow_basic_w_small.png
  10. BIN
      public/assets/images/arrow_decorative_e.png
  11. BIN
      public/assets/images/arrow_decorative_e_small.png
  12. BIN
      public/assets/images/arrow_decorative_n.png
  13. BIN
      public/assets/images/arrow_decorative_n_small.png
  14. BIN
      public/assets/images/arrow_decorative_s.png
  15. BIN
      public/assets/images/arrow_decorative_s_small.png
  16. BIN
      public/assets/images/arrow_decorative_w.png
  17. BIN
      public/assets/images/arrow_decorative_w_small.png
  18. BIN
      public/assets/images/button_rectangle_border.png
  19. BIN
      public/assets/images/button_rectangle_depth_border.png
  20. BIN
      public/assets/images/button_rectangle_depth_flat.png
  21. BIN
      public/assets/images/button_rectangle_depth_gloss.png
  22. BIN
      public/assets/images/button_rectangle_depth_gradient.png
  23. BIN
      public/assets/images/button_rectangle_depth_line.png
  24. BIN
      public/assets/images/button_rectangle_flat.png
  25. BIN
      public/assets/images/button_rectangle_gloss.png
  26. BIN
      public/assets/images/button_rectangle_gradient.png
  27. BIN
      public/assets/images/button_rectangle_line.png
  28. BIN
      public/assets/images/button_round_border.png
  29. BIN
      public/assets/images/button_round_depth_border.png
  30. BIN
      public/assets/images/button_round_depth_flat.png
  31. BIN
      public/assets/images/button_round_depth_gloss.png
  32. BIN
      public/assets/images/button_round_depth_gradient.png
  33. BIN
      public/assets/images/button_round_depth_line.png
  34. BIN
      public/assets/images/button_round_flat.png
  35. BIN
      public/assets/images/button_round_gloss.png
  36. BIN
      public/assets/images/button_round_gradient.png
  37. BIN
      public/assets/images/button_round_line.png
  38. BIN
      public/assets/images/button_square_border.png
  39. BIN
      public/assets/images/button_square_depth_border.png
  40. BIN
      public/assets/images/button_square_depth_flat.png
  41. BIN
      public/assets/images/button_square_depth_gloss.png
  42. BIN
      public/assets/images/button_square_depth_gradient.png
  43. BIN
      public/assets/images/button_square_depth_line.png
  44. BIN
      public/assets/images/button_square_flat.png
  45. BIN
      public/assets/images/button_square_gloss.png
  46. BIN
      public/assets/images/button_square_gradient.png
  47. BIN
      public/assets/images/button_square_line.png
  48. BIN
      public/assets/images/check_round_color.png
  49. BIN
      public/assets/images/check_round_grey.png
  50. BIN
      public/assets/images/check_round_grey_circle.png
  51. BIN
      public/assets/images/check_round_round_circle.png
  52. BIN
      public/assets/images/check_square_color.png
  53. BIN
      public/assets/images/check_square_color_checkmark.png
  54. BIN
      public/assets/images/check_square_color_cross.png
  55. BIN
      public/assets/images/check_square_color_square.png
  56. BIN
      public/assets/images/check_square_grey.png
  57. BIN
      public/assets/images/check_square_grey_checkmark.png
  58. BIN
      public/assets/images/check_square_grey_cross.png
  59. BIN
      public/assets/images/check_square_grey_square.png
  60. BIN
      public/assets/images/icon_checkmark.png
  61. BIN
      public/assets/images/icon_circle.png
  62. BIN
      public/assets/images/icon_cross.png
  63. BIN
      public/assets/images/icon_outline_checkmark.png
  64. BIN
      public/assets/images/icon_outline_circle.png
  65. BIN
      public/assets/images/icon_outline_cross.png
  66. BIN
      public/assets/images/icon_outline_square.png
  67. BIN
      public/assets/images/icon_square.png
  68. BIN
      public/assets/images/slide_hangle.png
  69. BIN
      public/assets/images/slide_horizontal_color.png
  70. BIN
      public/assets/images/slide_horizontal_color_section.png
  71. BIN
      public/assets/images/slide_horizontal_color_section_wide.png
  72. BIN
      public/assets/images/slide_horizontal_grey.png
  73. BIN
      public/assets/images/slide_horizontal_grey_section.png
  74. BIN
      public/assets/images/slide_horizontal_grey_section_wide.png
  75. BIN
      public/assets/images/slide_vertical_color.png
  76. BIN
      public/assets/images/slide_vertical_color_section.png
  77. BIN
      public/assets/images/slide_vertical_color_section_wide.png
  78. BIN
      public/assets/images/slide_vertical_grey.png
  79. BIN
      public/assets/images/slide_vertical_grey_section.png
  80. BIN
      public/assets/images/slide_vertical_grey_section_wide.png
  81. BIN
      public/assets/images/star.png
  82. BIN
      public/assets/images/star_outline.png
  83. BIN
      public/assets/images/star_outline_depth.png
  84. 16
      src/Game/Game.ts
  85. 26
      src/Game/Position.ts
  86. 24
      src/Game/Stage.ts
  87. 55
      src/Game/index.ts
  88. 81
      src/components/Button.ts
  89. 10
      src/main.ts
  90. 24
      src/stages/_global/page_0global.ts
  91. 26
      src/stages/page_control.ts
  92. 37
      src/stages/page_init.ts
  93. 13
      src/stages/welcome/page_welcome.ts
  94. 18
      src/stages/welcome2/page_welcome2.ts

2
index.html

@ -5,6 +5,8 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title> <title>Document</title>
<script src="//cdn.bootcdn.net/ajax/libs/eruda/2.3.3/eruda.js"></script>
<script>eruda.init();</script>
<style> <style>
html,body{ html,body{
padding: 0; padding: 0;

BIN
public/assets/images/arrow_basic_e.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 422 B

BIN
public/assets/images/arrow_basic_e_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

BIN
public/assets/images/arrow_basic_n.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 391 B

BIN
public/assets/images/arrow_basic_n_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

BIN
public/assets/images/arrow_basic_s.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

BIN
public/assets/images/arrow_basic_s_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

BIN
public/assets/images/arrow_basic_w.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 B

BIN
public/assets/images/arrow_basic_w_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 B

BIN
public/assets/images/arrow_decorative_e.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 566 B

BIN
public/assets/images/arrow_decorative_e_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 B

BIN
public/assets/images/arrow_decorative_n.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 511 B

BIN
public/assets/images/arrow_decorative_n_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 404 B

BIN
public/assets/images/arrow_decorative_s.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 530 B

BIN
public/assets/images/arrow_decorative_s_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 424 B

BIN
public/assets/images/arrow_decorative_w.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 562 B

BIN
public/assets/images/arrow_decorative_w_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 483 B

BIN
public/assets/images/button_rectangle_border.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 B

BIN
public/assets/images/button_rectangle_depth_border.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 412 B

BIN
public/assets/images/button_rectangle_depth_flat.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

BIN
public/assets/images/button_rectangle_depth_gloss.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 B

BIN
public/assets/images/button_rectangle_depth_gradient.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 642 B

BIN
public/assets/images/button_rectangle_depth_line.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

BIN
public/assets/images/button_rectangle_flat.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 B

BIN
public/assets/images/button_rectangle_gloss.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

BIN
public/assets/images/button_rectangle_gradient.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 590 B

BIN
public/assets/images/button_rectangle_line.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 B

BIN
public/assets/images/button_round_border.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
public/assets/images/button_round_depth_border.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
public/assets/images/button_round_depth_flat.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
public/assets/images/button_round_depth_gloss.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
public/assets/images/button_round_depth_gradient.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
public/assets/images/button_round_depth_line.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
public/assets/images/button_round_flat.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1023 B

BIN
public/assets/images/button_round_gloss.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 958 B

BIN
public/assets/images/button_round_gradient.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
public/assets/images/button_round_line.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
public/assets/images/button_square_border.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

BIN
public/assets/images/button_square_depth_border.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 B

BIN
public/assets/images/button_square_depth_flat.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

BIN
public/assets/images/button_square_depth_gloss.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

BIN
public/assets/images/button_square_depth_gradient.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 615 B

BIN
public/assets/images/button_square_depth_line.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

BIN
public/assets/images/button_square_flat.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

BIN
public/assets/images/button_square_gloss.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 268 B

BIN
public/assets/images/button_square_gradient.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 532 B

BIN
public/assets/images/button_square_line.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

BIN
public/assets/images/check_round_color.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

BIN
public/assets/images/check_round_grey.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

BIN
public/assets/images/check_round_grey_circle.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

BIN
public/assets/images/check_round_round_circle.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 B

BIN
public/assets/images/check_square_color.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 B

BIN
public/assets/images/check_square_color_checkmark.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 498 B

BIN
public/assets/images/check_square_color_cross.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 501 B

BIN
public/assets/images/check_square_color_square.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

BIN
public/assets/images/check_square_grey.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 B

BIN
public/assets/images/check_square_grey_checkmark.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

BIN
public/assets/images/check_square_grey_cross.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 539 B

BIN
public/assets/images/check_square_grey_square.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

BIN
public/assets/images/icon_checkmark.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 B

BIN
public/assets/images/icon_circle.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

BIN
public/assets/images/icon_cross.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 B

BIN
public/assets/images/icon_outline_checkmark.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 B

BIN
public/assets/images/icon_outline_circle.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

BIN
public/assets/images/icon_outline_cross.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

BIN
public/assets/images/icon_outline_square.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

BIN
public/assets/images/icon_square.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

BIN
public/assets/images/slide_hangle.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

BIN
public/assets/images/slide_horizontal_color.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

BIN
public/assets/images/slide_horizontal_color_section.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

BIN
public/assets/images/slide_horizontal_color_section_wide.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 B

BIN
public/assets/images/slide_horizontal_grey.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

BIN
public/assets/images/slide_horizontal_grey_section.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

BIN
public/assets/images/slide_horizontal_grey_section_wide.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 B

BIN
public/assets/images/slide_vertical_color.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 B

BIN
public/assets/images/slide_vertical_color_section.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 B

BIN
public/assets/images/slide_vertical_color_section_wide.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 B

BIN
public/assets/images/slide_vertical_grey.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 B

BIN
public/assets/images/slide_vertical_grey_section.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 B

BIN
public/assets/images/slide_vertical_grey_section_wide.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 B

BIN
public/assets/images/star.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
public/assets/images/star_outline.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 955 B

BIN
public/assets/images/star_outline_depth.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

16
src/Game/Game.ts

@ -8,6 +8,7 @@ import {
} from "pixi.js"; } from "pixi.js";
import detectOrient from "./detectOrient"; import detectOrient from "./detectOrient";
import { EDirection } from "@/enmu"; import { EDirection } from "@/enmu";
import TWEEN from "@tweenjs/tween.js";
export default class Game { export default class Game {
constructor() { constructor() {
@ -23,6 +24,7 @@ export default class Game {
} }
private _stage: Container; private _stage: Container;
private _tween: typeof TWEEN;
private _renderer: AbstractRenderer; private _renderer: AbstractRenderer;
private _ticker: Ticker; private _ticker: Ticker;
private _loader: Loader; private _loader: Loader;
@ -34,6 +36,12 @@ export default class Game {
public get stage(): Container { public get stage(): Container {
return this._stage; return this._stage;
} }
public get tween(): typeof TWEEN {
if(!this._tween) {
this._tween = TWEEN
}
return this._tween;
}
public get ticker(): Ticker { public get ticker(): Ticker {
return this._ticker; return this._ticker;
@ -139,11 +147,12 @@ export default class Game {
const stage = new Container(); const stage = new Container();
stage.name = "root"; stage.name = "root";
let renderer = autoDetectRenderer({ let renderer = autoDetectRenderer({
autoDensity: true,
width: screenWidght, width: screenWidght,
height: screenHeight, height: screenHeight,
antialias: true, antialias: true,
backgroundAlpha: 255, backgroundAlpha: 255,
resolution: 1, resolution: 2,
backgroundColor: 0x1d9ce0, backgroundColor: 0x1d9ce0,
forceCanvas: true, forceCanvas: true,
}); });
@ -164,7 +173,12 @@ export default class Game {
} }
render() { render() {
// https://www.cnblogs.com/haqiao/p/12515775.html
this.renderer.render(this.stage); this.renderer.render(this.stage);
const screenInfo = this.screenInfo()
let screenWidght = screenInfo.widght;
let screenHeight = screenInfo.height;
this.renderer.resize(screenWidght, screenHeight)
} }
// init(): Application { // init(): Application {

26
src/Game/Position.ts

@ -0,0 +1,26 @@
import { gameManager } from "@/Game";
import { IPointData } from "pixi.js";
class Position {
static instance: Position = null
private constructor() { }
static getInstance() {
if (Position.instance == null) {
Position.instance = new Position
}
return Position.instance
}
get(xType: "center", yType: "center", offset: Partial<IPointData>): IPointData {
let x, y
if (xType === 'center') {
x = gameManager.getInfo().width / 2 + (offset.x ?? 0)
}
if (yType === 'center') {
y = gameManager.getInfo().height / 2 + (offset.y ?? 0)
}
return { x, y }
}
}
export default Position.getInstance()

24
src/Game/Stage.ts

@ -31,7 +31,7 @@ export default class Stage {
initStage(name: string){ initStage(name: string){
if(!this._stages[name]){ if(!this._stages[name]){
throw new Error("不存在该舞台") throw new Error("不存在该舞台: " + name)
} }
let curStage = this._stages[name]; let curStage = this._stages[name];
this.curStage = curStage this.curStage = curStage
@ -47,9 +47,9 @@ export default class Stage {
this._wscb.forEach(v=>v(curStage)) this._wscb.forEach(v=>v(curStage))
} }
changeStage(name: string){ changeStage(name: string, opts?: {isHolderLast?: boolean}){
if(!this._stages[name]){ if(!this._stages[name]){
throw new Error("不存在该舞台") throw new Error("不存在该舞台: " + name)
} }
if(!this.curStage){ if(!this.curStage){
console.warn("请先初始化一个场景") console.warn("请先初始化一个场景")
@ -57,26 +57,34 @@ export default class Stage {
} }
let lastStage = this.curStage let lastStage = this.curStage
if(lastStage&&lastStage.type === EP.Normal){ if(lastStage&&lastStage.type === EP.Normal){
this.gameManager.stage.removeChild(lastStage.stage) if(opts?.isHolderLast) {
lastStage.stage.visible = false
// @ts-ignore
lastStage.stage.$isHolderLast = opts.isHolderLast
} else this.gameManager.stage.removeChild(lastStage.stage)
}else if(lastStage&&lastStage.type === EP.Resident){ }else if(lastStage&&lastStage.type === EP.Resident){
lastStage.stage.visible = false lastStage.stage.visible = false
} }
let curStage = this._stages[name]; let curStage = this._stages[name];
if(curStage && typeof curStage === "string"){ if(curStage && typeof curStage === "string" && curStage === "已销毁"){
this.create(name, EP.Normal) this.create(name, EP.Normal)
curStage = this._stages[name] curStage = this._stages[name]
console.log(curStage); console.log(curStage);
} }
this.curStage = curStage this.curStage = curStage
if(curStage&&curStage.type === EP.Normal){ if(curStage&&curStage.type === EP.Normal){
this.gameManager.stage.addChild(curStage.stage) // @ts-ignore
if(curStage.stage.$isHolderLast) {
curStage.stage.visible = true
} else {
this.gameManager.stage.addChild(curStage.stage)
}
}else if(curStage&&curStage.type === EP.Resident){ }else if(curStage&&curStage.type === EP.Resident){
curStage.stage.visible = true curStage.stage.visible = true
} }
this._wscb.forEach(v=>v(curStage, lastStage)) this._wscb.forEach(v=>v(curStage, lastStage))
if(lastStage&&lastStage.type === EP.Normal){ if(lastStage&&lastStage.type === EP.Normal && !opts?.isHolderLast){
lastStage.stage.destroy() lastStage.stage.destroy()
this._stages[lastStage.name] = "已销毁" as any this._stages[lastStage.name] = "已销毁" as any
} }

55
src/Game/index.ts

@ -1,40 +1,52 @@
import Game from "./Game"; import Game from "./Game";
import Stage from "./Stage"; import Stage from "./Stage";
import { Container, LoaderResource, Loader } from "pixi.js"; import { Container, LoaderResource, Loader } from "pixi.js";
import * as PIXI from "pixi.js";
import { EP } from "@/enmu"; import { EP } from "@/enmu";
import TWEEN from "@tweenjs/tween.js";
const gameManager = Game.getInstance(); const gameManager = Game.getInstance();
const stageManager = Stage.getInstance(); const stageManager = Stage.getInstance();
const windows: Record<string, IWindow>= {} const windows: Record<string, IWindow> = {}
const residentList: IWindow[] = [] const residentList: IWindow[] = []
function defineLoadResource(resources: {name: string, url: string, callback?: LoaderResource.OnCompleteSignal}[]) { function defineLoadResource(resources: { name: string, url: string, callback?: LoaderResource.OnCompleteSignal }[]) {
return resources return resources
} }
function defineWindow(name: string, abstractClass: Constructor<IWindow>, type?: EP) { function defineWindow(name: string, abstractClass: Constructor<IWindow>, type?: EP): any
return { name, abstractClass, type} function defineWindow(abstractClass: Constructor<IWindow>, type?: EP): any
function defineWindow(name: string | Constructor<IWindow>, abstractClass?: Constructor<IWindow> | EP, type?: EP) {
if (typeof name === "string") {
return { name, abstractClass, type }
}
return { abstractClass: name, type: abstractClass }
} }
const t = import.meta.globEager("../stages/**/page_*.ts"); const t = import.meta.globEager("../stages/**/page_*.ts");
for (const tKey in t) { for (const tKey in t) {
const mod = t[tKey].default || t[tKey] const mod = t[tKey].default || t[tKey]
const {name, abstractClass, type} = mod as ReturnType<typeof defineWindow> const [_, tKeyName] = tKey.match(/page_(.*?)\.ts$/)
const stage = stageManager.getStage(name, type); const { name, abstractClass, type } = mod as ReturnType<typeof defineWindow>
const stage = stageManager.getStage(name || tKeyName, type);
const stageClass = new abstractClass(stage) const stageClass = new abstractClass(stage)
if(EP.Resident === type) { stageClass.bindStage(stage)
stageClass._init = false
stageClass.$name = name || tKeyName
if (EP.Resident === type) {
residentList.push(stageClass) residentList.push(stageClass)
} } else windows[name || tKeyName] = stageClass
windows[name] = stageClass
} }
// @ts-ignore
residentList.sort((a, b) => a.$name.localeCompare(b.$name, 'en'))
type Constructor<T> = new (...args: any[]) => T; type Constructor<T> = new (...args: any[]) => T;
interface IWindow { interface IWindow {
_init?: Boolean;
stage: Container; stage: Container;
loader?: Loader; loader?: Loader;
bindStage?(stage: Container): void;
layout?(): void;
onLoad?(): void; onLoad?(): void;
onUnLoad?(): void; onUnLoad?(): void;
lateUpdate?(dt: number, name: string): void; lateUpdate?(dt: number, name: string): void;
@ -50,24 +62,31 @@ function initGame() {
} }
if (stage && stage.type === EP.Normal) { if (stage && stage.type === EP.Normal) {
let curWindow = windows[stage.name]; let curWindow = windows[stage.name];
const isSameStage = curWindow.stage === stage.stage
!isSameStage && curWindow.bindStage(stage.stage)
curWindow.onLoad && curWindow.onLoad(); curWindow.onLoad && curWindow.onLoad();
if(!curWindow._init || !isSameStage) {
console.log("不同的舞台");
curWindow.layout?.()
curWindow._init = true
}
} }
}); });
residentList.forEach((v) => v.onLoad && v.onLoad()); residentList.forEach((v) => v.onLoad && v.onLoad());
gameManager.ticker.add((dt: number) => { gameManager.ticker.add((dt: number) => {
if (!stageManager.curStage) return; if (!stageManager.curStage) return;
let curWindow = windows[stageManager.curStage.name]; let curWindow = windows[stageManager.curStage.name];
TWEEN.update(); gameManager.tween.update();
residentList.forEach((v) => v.update && v.update(dt, v.stage.name)); residentList.forEach((v) => v.update && v.update(dt, v.stage.name));
stageManager.curStage && stageManager.curStage &&
curWindow && curWindow &&
curWindow.update && curWindow.update &&
curWindow.update(dt, curWindow.stage.name); curWindow.update(dt, curWindow.stage.name);
gameManager.render(); gameManager.render();
stageManager.curStage && stageManager.curStage &&
curWindow && curWindow &&
curWindow.lateUpdate && curWindow.lateUpdate &&
curWindow.lateUpdate(dt, curWindow.stage.name); curWindow.lateUpdate(dt, curWindow.stage.name);
residentList.forEach((v) => v.lateUpdate && v.lateUpdate(dt, v.stage.name)); residentList.forEach((v) => v.lateUpdate && v.lateUpdate(dt, v.stage.name));
}); });
} }

81
src/components/Button.ts

@ -1,28 +1,34 @@
import { Text, Graphics, Container, TextStyle } from "pixi.js"; import { Text, Graphics, Container, TextStyle, NineSlicePlane, Texture } from "pixi.js";
interface IOpts { interface IOpts {
text: string; text: string;
bg: string;
pressBg: string;
click(): void; click(): void;
} }
const defaultOpts: IOpts = { const defaultOpts: IOpts = {
text: "", text: "",
click() {}, bg: "",
pressBg: "",
click() { },
}; };
function getConfig() {
return Object.assign({}, defaultOpts)
}
export default function Button(opts: Partial<IOpts>) { export default function Button(opts: Partial<IOpts>) {
let curOpts: Partial<IOpts> = {}; let curOpts: IOpts = getConfig();
(Object.keys(defaultOpts) as (keyof IOpts)[]).forEach((key) => { ; (Object.keys(defaultOpts) as (keyof IOpts)[]).forEach((key) => {
if (opts[key] != undefined) { if (opts[key] != undefined) {
curOpts[key] = opts[key]; curOpts[key] = opts[key] as any;
} else {
curOpts[key] = defaultOpts[key];
} }
}); });
let textStyle = new TextStyle({ let textStyle = new TextStyle({
fontFamily: "Arial", fontFamily: "Arial",
fontSize: 50, fontSize: 30,
fill: 0xffffff, fill: 0xffffff,
align: "center", align: "center",
}); });
@ -33,34 +39,63 @@ export default function Button(opts: Partial<IOpts>) {
let button = new Container(); let button = new Container();
let width = textStr.width + xPadding; let width = textStr.width + xPadding;
let height = textStr.height + yPadding; let height = textStr.height + yPadding;
// https://www.cnblogs.com/ningmin/p/11412170.html
textStr.x = xPadding / 2; // https://blog.csdn.net/weixin_52919504/article/details/131854745
textStr.y = yPadding / 2; // https://blog.csdn.net/weixin_52919504/article/details/131854745
button.pivot.set(width / 2, height / 2)
const rect = new Graphics(); textStr.x = xPadding / 2;
rect.name = "rect"; textStr.y = yPadding / 2 - 2;
rect.beginFill(0xff0000);
rect.drawRect(0, 0, width, height);
rect.endFill();
rect.interactive = true;
rect.buttonMode = true;
button.addChild(rect); if (!curOpts.bg) {
const rect = new Graphics();
rect.name = "rect";
rect.beginFill(0xff0000);
rect.drawRect(0, 0, width, height);
rect.endFill();
rect.interactive = true;
rect.buttonMode = true;
button.addChild(rect);
} else {
const plane9 = new NineSlicePlane(Texture.from(curOpts.bg), 10, 10, 10, 10);
plane9.name = "plane9plane9"
plane9.width = width
plane9.height = height
plane9.interactive = true;
plane9.buttonMode = true;
button.addChild(plane9);
}
button.addChild(textStr); button.addChild(textStr);
button.x = 100; button.x = 100;
button.y = 50; button.y = 50;
button.interactive = true; button.interactive = true;
button.on("touchstart", () => { button.on("touchstart", () => {
button.alpha = 0.8; if (curOpts.pressBg) {
button.getChildByName<NineSlicePlane>("plane9plane9").texture = Texture.from(curOpts.pressBg)
} else {
button.alpha = 0.8;
button.scale = { x: .8, y: .8 }
}
}); });
button.on("touchend", () => { button.on("touchend", () => {
// 点击成功 // 点击成功
console.log("success"); console.log("touchend success");
if (curOpts.pressBg) {
button.getChildByName<NineSlicePlane>("plane9plane9").texture = Texture.from(curOpts.bg)
} else {
button.alpha = 1;
button.scale = { x: 1, y: 1 }
}
curOpts.click(); curOpts.click();
button.alpha = 1;
}); });
button.on("touchendoutside", () => { button.on("touchendoutside", () => {
button.alpha = 1; console.log("touchendoutside success");
if (curOpts.pressBg) {
button.getChildByName<NineSlicePlane>("plane9plane9").texture = Texture.from(curOpts.bg)
} else {
button.alpha = 1;
button.scale = { x: 1, y: 1 }
}
}); });
return button; return button;
} }

10
src/main.ts

@ -5,9 +5,12 @@ import { addSound } from "./Game/Sound";
console.log(); console.log();
gameManager.loader gameManager.loader
.add("my-sound", "/bg.mp3", (e) => addSound(e)) .add("my-sound", "/bg.mp3", (e) => addSound(e)) // 背景音乐
.add("bg", "/bg.png") .add("bg", "/bg.png") // 背景图片
.add("btn-bg", "/assets/images/button_square_depth_gloss.png") // 背景图片
.add("btn-bg-press", "/assets/images/button_square_depth_gradient.png") // 背景图片
.load(); .load();
gameManager.loader.onProgress.add((loader) => { gameManager.loader.onProgress.add((loader) => {
console.log(loader.progress); console.log(loader.progress);
}); });
@ -15,6 +18,5 @@ gameManager.loader.onComplete.once((loader) => {
console.log(loader.resources); console.log(loader.resources);
initGame(); initGame();
gameManager.setDirection(EDirection.Portrait); gameManager.setDirection(EDirection.Portrait);
stageManager.initStage("loading"); stageManager.initStage("init");
}); });

24
src/stages/_global/page_0global.ts

@ -0,0 +1,24 @@
import { EP } from "@/enmu";
import { defineWindow } from "@/Game";
import { Container } from "pixi.js";
export default defineWindow(
class {
stage: Container = null;
constructor(stage: Container) {
this.stage = stage;
}
bindStage(stage: Container){
this.stage = stage;
}
onLoad() {
console.log("global page loaded");
}
onUnLoad() {
}
},
EP.Resident
);

26
src/stages/page_control.ts

@ -1,26 +0,0 @@
import { EP } from "@/enmu";
import { defineWindow } from "@/Game";
import { Container, Loader } from "pixi.js";
import { addSound } from "@/Game/Sound";
const loader = new Loader().add("my-sound", "/bg.mp3", (e) => addSound(e));
export default defineWindow("control", class {
stage: Container = null;
loader: Loader = loader;
constructor(stage: Container) {
this.stage = stage;
}
onLoad() {
console.log("onLoad control");
}
onUnLoad() {
console.log("onUnLoad control");
}
update() {
}
}, EP.Resident);

37
src/stages/page_loading.ts → src/stages/page_init.ts

@ -1,8 +1,8 @@
import Button from "@/components/Button"; import Button from "@/components/Button";
import { gameManager, defineWindow, stageManager } from "@/Game"; import { gameManager, defineWindow, stageManager } from "@/Game";
import Position from "@/Game/Position";
import Sound from "@/Game/Sound"; import Sound from "@/Game/Sound";
import { Container, Sprite, Text, NineSlicePlane, Texture } from "pixi.js"; import { Container, Sprite, Text, NineSlicePlane, Texture } from "pixi.js";
import TWEEN from "@tweenjs/tween.js";
// defineLoadResource([ // defineLoadResource([
// { name: "my-sound", url: "/bg.mp3", callback: (e) => addSound(e) }, // { name: "my-sound", url: "/bg.mp3", callback: (e) => addSound(e) },
@ -10,45 +10,48 @@ import TWEEN from "@tweenjs/tween.js";
// ]) // ])
export default defineWindow( export default defineWindow(
"loading",
class { class {
stage: Container = null; stage: Container = null;
title: Text; // 标题 title: Text; // 标题
bindStage(stage: Container) {
constructor(stage: Container) {
this.stage = stage; this.stage = stage;
} }
layout() {
onLoad() {
console.log("onLoad loading");
this.title = new Text("时间魔法", { this.title = new Text("时间魔法", {
fontSize: 80, fontSize: 80,
fill: "red", fill: "red",
}); });
this.title.x = gameManager.getInfo().width / 2; this.title.x = gameManager.getInfo().width / 2;
this.title.y = gameManager.getInfo().height / 2 - 200; this.title.y = gameManager.getInfo().height / 2 - 200;
this.title.position = Position.get("center", "center", { y: -200, x: 0 })
this.title.anchor.set(0.5, 0.5); this.title.anchor.set(0.5, 0.5);
this.stage.addChild(this.title); this.stage.addChild(this.title);
const plane9 = new NineSlicePlane(Texture.from("bg"), 100, 100, 100, 100); const plane9 = new NineSlicePlane(Texture.from("btn-bg"), 10, 10, 10, 10);
plane9.width = 300 plane9.width = 100
plane9.height = 300 plane9.height = 50
this.stage.addChild(plane9); this.stage.addChild(plane9);
const btn = Button({ const btn = Button({
text: "开始游戏", text: "开始游戏",
bg: "btn-bg",
pressBg: "btn-bg-press",
click: () => { click: () => {
stageManager.changeStage("welcome")
// Sound.play("my-sound") // Sound.play("my-sound")
// new TWEEN.Tween(btn).interpolation( TWEEN.Interpolation.Bezier ) // new gameManager.tween.Tween(btn.position).interpolation(gameManager.tween.Interpolation.Bezier)
// .to({ alpha: .2,x:100, y:100 }, 1300) // .to({ alpha: .2, x: btn.width / 2, y: btn.height / 2 }, 1300)
// .start() // .onComplete(() => {
stageManager.changeStage("welcome", { isHolderLast: true })
// })
// .start()
}, },
}); });
btn.x = gameManager.getInfo().width / 2 - btn.width / 2; btn.position = Position.get("center", "center", { y: 200, x: 0 })
btn.y = gameManager.getInfo().height / 2 - btn.height / 2 + 200;
this.stage.addChild(btn); this.stage.addChild(btn);
console.log(this.stage);
}
onLoad() {
console.log("onLoad init");
} }
onUnLoad() { onUnLoad() {

13
src/stages/welcome/page_welcome.ts

@ -10,12 +10,10 @@ export default defineWindow("welcome", class{
stage:Container = null stage:Container = null
elements: Record<string, Graphics> = {} elements: Record<string, Graphics> = {}
text: any text: any
bindStage(stage: Container){
constructor(stage: Container){ this.stage = stage;
this.stage = stage
} }
onLoad(){ layout(){
console.log("onLoad 1");
const circle = Circle.render() const circle = Circle.render()
this.stage.addChild(circle) this.stage.addChild(circle)
circle.on("touchend", ()=>{ circle.on("touchend", ()=>{
@ -27,10 +25,13 @@ export default defineWindow("welcome", class{
const btn = Button({text: "修仙人生日常"}) const btn = Button({text: "修仙人生日常"})
btn.on("touchend", ()=>{ btn.on("touchend", ()=>{
// Sound.play('my-sound'); // Sound.play('my-sound');
stageManager.changeStage("loading") stageManager.changeStage("init")
}) })
this.stage.addChild(btn) this.stage.addChild(btn)
} }
onLoad(){
console.log("onLoad 1");
}
onUnLoad(){ onUnLoad(){
Sound.stop("my-sound") Sound.stop("my-sound")
console.log("onUnLoad 1"); console.log("onUnLoad 1");

18
src/stages/welcome2/page_welcome2.ts

@ -16,18 +16,20 @@ circle.on("touchend", () => {
stageManager.changeStage("welcome") stageManager.changeStage("welcome")
}) })
export default defineWindow("welcome2", class{ export default defineWindow("welcome2", class {
stage:Container = null stage: Container = null
constructor(stage: Container){ bindStage(stage: Container) {
this.stage = stage this.stage = stage;
} }
onLoad(){ layout() {
console.log("onLoad 2");
this.stage.addChild(circle) this.stage.addChild(circle)
} }
onUnLoad(){ onLoad() {
console.log("onLoad 2");
}
onUnLoad() {
console.log("onUnLoad 2"); console.log("onUnLoad 2");
} }
update(){ update() {
} }
}) })
Loading…
Cancel
Save