mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-04-11 15:47:06 +08:00
fix: 元素的根元素
This commit is contained in:
parent
4b2d94e422
commit
48cc34aa2d
@ -78,6 +78,29 @@ export class Container<E extends EContainerEvent = EContainerEvent>
|
|||||||
this.update(this);
|
this.update(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
append(parent: RenderItem): void {
|
||||||
|
super.append(parent);
|
||||||
|
if (this.root) {
|
||||||
|
this.forEachChild(ele => {
|
||||||
|
ele.checkRoot();
|
||||||
|
this.root?.connect(ele);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 遍历这个元素中的每个子元素,并执行传入的函数
|
||||||
|
* @param fn 对每个元素执行的函数
|
||||||
|
*/
|
||||||
|
forEachChild(fn: (ele: RenderItem) => void) {
|
||||||
|
const stack: RenderItem[] = [this];
|
||||||
|
while (stack.length > 0) {
|
||||||
|
const ele = stack.pop()!;
|
||||||
|
stack.push(...ele.children);
|
||||||
|
fn(ele);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private sortChildren() {
|
private sortChildren() {
|
||||||
this.sortedChildren = [...this.children].sort(
|
this.sortedChildren = [...this.children].sort(
|
||||||
(a, b) => a.zIndex - b.zIndex
|
(a, b) => a.zIndex - b.zIndex
|
||||||
|
@ -278,15 +278,6 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
|
|||||||
return this._transform;
|
return this._transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _cursor: string = 'auto';
|
|
||||||
/** 鼠标覆盖在该元素上时的指针样式 */
|
|
||||||
set cursor(v: string) {
|
|
||||||
this.setCursor(v);
|
|
||||||
}
|
|
||||||
get cursor() {
|
|
||||||
return this._cursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region 父子关系
|
//#region 父子关系
|
||||||
@ -486,19 +477,6 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
|
|||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置鼠标放在该元素上时的指针样式
|
|
||||||
* @param cursor 要设置成的指针样式
|
|
||||||
*/
|
|
||||||
setCursor(cursor: string = 'auto') {
|
|
||||||
const canvas = this._root?.getCanvas();
|
|
||||||
if (!canvas) return;
|
|
||||||
if (this.hovered) {
|
|
||||||
canvas.style.cursor = cursor;
|
|
||||||
}
|
|
||||||
this._cursor = cursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 隐藏这个元素
|
* 隐藏这个元素
|
||||||
*/
|
*/
|
||||||
@ -591,14 +569,19 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
|
|||||||
|
|
||||||
//#region 父子关系
|
//#region 父子关系
|
||||||
|
|
||||||
protected checkRoot() {
|
checkRoot() {
|
||||||
if (this._root || this.isRoot) return this._root;
|
if (this._root) return this._root;
|
||||||
|
if (this.isRoot) return this;
|
||||||
let ele: RenderItem = this;
|
let ele: RenderItem = this;
|
||||||
while (!ele.isRoot) {
|
while (!ele.isRoot) {
|
||||||
if (!ele.parent) {
|
if (ele._root) {
|
||||||
|
this._root = ele._root;
|
||||||
|
return this._root;
|
||||||
|
}
|
||||||
|
if (!ele._parent) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
ele = ele.parent;
|
ele = ele._parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._root = ele as RenderItem & IRenderTreeRoot;
|
this._root = ele as RenderItem & IRenderTreeRoot;
|
||||||
@ -631,10 +614,8 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
|
|||||||
this._parent = parent;
|
this._parent = parent;
|
||||||
parent.requestSort();
|
parent.requestSort();
|
||||||
this.update();
|
this.update();
|
||||||
if (this._id !== '') {
|
this.checkRoot();
|
||||||
this.checkRoot();
|
this._root?.connect(this);
|
||||||
this._root?.connect(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -846,11 +827,6 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ActionType.Enter: {
|
|
||||||
const canvas = this._root?.getCanvas();
|
|
||||||
if (!canvas) return true;
|
|
||||||
canvas.style.cursor = this._cursor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return inElement;
|
return inElement;
|
||||||
|
@ -31,6 +31,7 @@ export interface BaseProps {
|
|||||||
id?: string;
|
id?: string;
|
||||||
alpha?: number;
|
alpha?: number;
|
||||||
composite?: GlobalCompositeOperation;
|
composite?: GlobalCompositeOperation;
|
||||||
|
cursor?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SpriteProps extends BaseProps {
|
export interface SpriteProps extends BaseProps {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { FloorItemDetail } from '@/plugin/fx/itemDetail';
|
import { FloorItemDetail } from '@/plugin/fx/itemDetail';
|
||||||
import { FloorDamageExtends, LayerGroup } from '@/core/render';
|
import { FloorDamageExtends, LayerGroup, Transform } from '@/core/render';
|
||||||
import { LayerDoorAnimate } from '@/core/render';
|
import { LayerDoorAnimate } from '@/core/render';
|
||||||
import { HeroRenderer } from '@/core/render';
|
import { HeroRenderer } from '@/core/render';
|
||||||
import { MotaRenderer } from '@/core/render';
|
import { MotaRenderer } from '@/core/render';
|
||||||
@ -64,8 +64,21 @@ export function create() {
|
|||||||
weather.bind(map.value);
|
weather.bind(map.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const test = (msg: string) => {
|
||||||
|
return (ev: IActionEvent) => {
|
||||||
|
console.log(msg, ev);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
return () => (
|
return () => (
|
||||||
<container id="map-draw" {...mapDrawProps}>
|
<container id="map-draw" {...mapDrawProps}>
|
||||||
|
<icon
|
||||||
|
icon={50}
|
||||||
|
zIndex={100}
|
||||||
|
width={240}
|
||||||
|
height={240}
|
||||||
|
cursor="pointer"
|
||||||
|
></icon>
|
||||||
<layer-group id="layer-main" ex={layerGroupExtends} ref={map}>
|
<layer-group id="layer-main" ex={layerGroupExtends} ref={map}>
|
||||||
<layer layer="bg" zIndex={10}></layer>
|
<layer layer="bg" zIndex={10}></layer>
|
||||||
<layer layer="bg2" zIndex={20}></layer>
|
<layer layer="bg2" zIndex={20}></layer>
|
||||||
|
Loading…
Reference in New Issue
Block a user