@eva/plugin-renderer-nine-patch 2.0.1-beta.39 → 2.0.1-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-nine-patch",
|
|
3
|
-
"version": "2.0.1-beta.
|
|
3
|
+
"version": "2.0.1-beta.40",
|
|
4
4
|
"description": "@eva/plugin-renderer-nine-patch",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-renderer-nine-patch.esm.js",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@eva/inspector-decorator": "^0.0.5",
|
|
22
|
-
"@eva/plugin-renderer": "2.0.1-beta.
|
|
23
|
-
"@eva/renderer-adapter": "2.0.1-beta.
|
|
24
|
-
"@eva/eva.js": "2.0.1-beta.
|
|
22
|
+
"@eva/plugin-renderer": "2.0.1-beta.40",
|
|
23
|
+
"@eva/renderer-adapter": "2.0.1-beta.40",
|
|
24
|
+
"@eva/eva.js": "2.0.1-beta.40"
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{};var _EVA_IIFE_ninePatch=function(e,t,i,r){"use strict";function n(e,t,i,r){var n,o=arguments.length,s=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,r);else for(var c=e.length-1;c>=0;c--)(n=e[c])&&(s=(o<3?n(s):o>3?n(t,i,s):n(t,i))||s);return o>3&&s&&Object.defineProperty(t,i,s),s}function o(e,t,i,r){return new(i||(i=Promise))((function(n,o){function s(e){try{h(r.next(e))}catch(e){o(e)}}function c(e){try{h(r.throw(e))}catch(e){o(e)}}function h(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}h((r=r.apply(e,t||[])).next())}))}function s(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}function c(e){return function(t,i){var r=s(t,i);r.key=i,r.type=e}}function h(e){return function(t,i){s(t,i).step=e}}class a extends t.Component{constructor(){super(...arguments),this.resource="",this.spriteName="",this.leftWidth=0,this.topHeight=0,this.rightWidth=0,this.bottomHeight=0}init(e){this.resource=e.resource,this.spriteName=e.spriteName,this.leftWidth=e.leftWidth,this.topHeight=e.topHeight,this.rightWidth=e.rightWidth,this.bottomHeight=e.bottomHeight}}a.componentName="NinePatch",n([c("string")],a.prototype,"resource",void 0),n([c("string")],a.prototype,"spriteName",void 0),n([c("number"),h(1)],a.prototype,"leftWidth",void 0),n([c("number"),h(1)],a.prototype,"topHeight",void 0),n([c("number"),h(1)],a.prototype,"rightWidth",void 0),n([c("number"),h(1)],a.prototype,"bottomHeight",void 0);let d=class extends i.Renderer{constructor(){super(...arguments),this.name="NinePatch",this.ninePatch={}}init(){this.renderSystem=this.game.getSystem(i.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const{width:t,height:i}=e.transform.size;this.ninePatch[e.id]&&(this.ninePatch[e.id].width=t,this.ninePatch[e.id].height=i)}componentChanged(e){return o(this,void 0,void 0,(function*(){"NinePatch"===e.componentName&&(e.type===t.OBSERVER_TYPE.ADD?this.add(e):e.type===t.OBSERVER_TYPE.REMOVE?this.remove(e):(this.remove(e),this.add(e)))}))}add(e){return o(this,void 0,void 0,(function*(){const i=e.component,n=e.gameObject.id,o=this.increaseAsyncId(n),{type:s,data:c,instance:h}=yield t.resource.getResource(i.resource);if(!this.validateAsyncId(n,o))return;if(!c)return void console.error(`GameObject:${e.gameObject.name}'s NinePatch resource load error`);let a;if(s===t.RESOURCE_TYPE.SPRITE&&i.spriteName){if(!h)return void console.error("GameObjectNinePatch Sprite resource rely on the Sprite system");a=h[i.resource+"_s|r|c_"+i.spriteName]}else a=c.image;const{leftWidth:d,topHeight:u,rightWidth:p,bottomHeight:g}=i,l=new r.NinePatch(a,d,u,p,g);this.ninePatch[e.gameObject.id]=l,i.ninePatch=l,this.containerManager.getContainer(e.gameObject.id).addChildAt(l,0)}))}remove(e){const t=e.gameObject.id;this.increaseAsyncId(t);const i=this.ninePatch[t];i&&(this.containerManager.getContainer(e.gameObject.id).removeChild(i),delete this.ninePatch[e.gameObject.id],i.destroy({children:!0}))}};d.systemName="NinePatch",d=n([t.decorators.componentObserver({NinePatch:["resource","spriteName","leftWidth","topHeight","rightWidth","bottomHeight"]})],d);var u=d;return e.NinePatch=a,e.NinePatchSystem=u,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter);globalThis.EVA.plugin.renderer.ninePatch=globalThis.EVA.plugin.renderer.ninePatch||_EVA_IIFE_ninePatch;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),i=require("@eva/plugin-renderer"),r=require("@eva/renderer-adapter");
|
|
2
|
-
/*! *****************************************************************************
|
|
3
|
-
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
5
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
6
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
|
|
8
|
-
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
9
|
-
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
10
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
11
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
12
|
-
|
|
13
|
-
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
|
-
and limitations under the License.
|
|
15
|
-
***************************************************************************** */
|
|
16
|
-
function n(e,t,i,r){var n,o=arguments.length,s=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,r);else for(var h=e.length-1;h>=0;h--)(n=e[h])&&(s=(o<3?n(s):o>3?n(t,i,s):n(t,i))||s);return o>3&&s&&Object.defineProperty(t,i,s),s}function o(e,t,i,r){return new(i||(i=Promise))((function(n,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function h(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){e.done?n(e.value):new i((function(t){t(e.value)})).then(s,h)}c((r=r.apply(e,t||[])).next())}))}class s extends e.Component{constructor(){super(...arguments),this.resource="",this.spriteName="",this.leftWidth=0,this.topHeight=0,this.rightWidth=0,this.bottomHeight=0}init(e){this.resource=e.resource,this.spriteName=e.spriteName,this.leftWidth=e.leftWidth,this.topHeight=e.topHeight,this.rightWidth=e.rightWidth,this.bottomHeight=e.bottomHeight}}s.componentName="NinePatch",n([t.type("string")],s.prototype,"resource",void 0),n([t.type("string")],s.prototype,"spriteName",void 0),n([t.type("number"),t.step(1)],s.prototype,"leftWidth",void 0),n([t.type("number"),t.step(1)],s.prototype,"topHeight",void 0),n([t.type("number"),t.step(1)],s.prototype,"rightWidth",void 0),n([t.type("number"),t.step(1)],s.prototype,"bottomHeight",void 0);let h=class extends i.Renderer{constructor(){super(...arguments),this.name="NinePatch",this.ninePatch={}}init(){this.renderSystem=this.game.getSystem(i.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const{width:t,height:i}=e.transform.size;this.ninePatch[e.id]&&(this.ninePatch[e.id].width=t,this.ninePatch[e.id].height=i)}componentChanged(t){return o(this,void 0,void 0,(function*(){"NinePatch"===t.componentName&&(t.type===e.OBSERVER_TYPE.ADD?this.add(t):t.type===e.OBSERVER_TYPE.REMOVE?this.remove(t):(this.remove(t),this.add(t)))}))}add(t){return o(this,void 0,void 0,(function*(){const i=t.component,n=t.gameObject.id,o=this.increaseAsyncId(n),{type:s,data:h,instance:c}=yield e.resource.getResource(i.resource);if(!this.validateAsyncId(n,o))return;if(!h)return void console.error(`GameObject:${t.gameObject.name}'s NinePatch resource load error`);let a;if(s===e.RESOURCE_TYPE.SPRITE&&i.spriteName){if(!c)return void console.error("GameObjectNinePatch Sprite resource rely on the Sprite system");a=c[i.resource+"_s|r|c_"+i.spriteName]}else a=h.image;const{leftWidth:d,topHeight:p,rightWidth:m,bottomHeight:u}=i,g=new r.NinePatch(a,d,p,m,u);this.ninePatch[t.gameObject.id]=g,i.ninePatch=g,this.containerManager.getContainer(t.gameObject.id).addChildAt(g,0)}))}remove(e){const t=e.gameObject.id;this.increaseAsyncId(t);const i=this.ninePatch[t];i&&(this.containerManager.getContainer(e.gameObject.id).removeChild(i),delete this.ninePatch[e.gameObject.id],i.destroy({children:!0}))}};h.systemName="NinePatch",h=n([e.decorators.componentObserver({NinePatch:["resource","spriteName","leftWidth","topHeight","rightWidth","bottomHeight"]})],h);var c=h;exports.NinePatch=s,exports.NinePatchSystem=c;
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { Component } from '@eva/eva.js';
|
|
2
|
-
import { ComponentChanged } from '@eva/eva.js';
|
|
3
|
-
import { ContainerManager } from '@eva/plugin-renderer';
|
|
4
|
-
import { GameObject } from '@eva/eva.js';
|
|
5
|
-
import { NinePatch as NinePatch_2 } from '@eva/renderer-adapter';
|
|
6
|
-
import { Renderer } from '@eva/plugin-renderer';
|
|
7
|
-
import { RendererManager } from '@eva/plugin-renderer';
|
|
8
|
-
import { RendererSystem } from '@eva/plugin-renderer';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 九宫格组件
|
|
12
|
-
*
|
|
13
|
-
* NinePatch 组件用于实现可拉伸的图片,保持边角不变形。
|
|
14
|
-
* 将图片分为 9 个区域,拉伸时只拉伸中间区域,边角保持原始比例,
|
|
15
|
-
* 适用于按钮、对话框、面板等需要自适应尺寸的 UI 元素。
|
|
16
|
-
*
|
|
17
|
-
* 九宫格原理:
|
|
18
|
-
* ```
|
|
19
|
-
* +-------+-------+-------+
|
|
20
|
-
* | 左上 | 上 | 右上 |
|
|
21
|
-
* +-------+-------+-------+
|
|
22
|
-
* | 左 | 中间 | 右 |
|
|
23
|
-
* +-------+-------+-------+
|
|
24
|
-
* | 左下 | 下 | 右下 |
|
|
25
|
-
* +-------+-------+-------+
|
|
26
|
-
* ```
|
|
27
|
-
* 拉伸时,四个角保持不变,四条边单向拉伸,中间区域双向拉伸。
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* // 创建可拉伸的按钮背景
|
|
32
|
-
* const button = new GameObject('button');
|
|
33
|
-
* button.addComponent(new NinePatch({
|
|
34
|
-
* resource: 'buttonBg', // 按钮背景资源
|
|
35
|
-
* spriteName: 'btn_normal.png',
|
|
36
|
-
* leftWidth: 20, // 左边不拉伸区域宽度
|
|
37
|
-
* topHeight: 20, // 顶部不拉伸区域高度
|
|
38
|
-
* rightWidth: 20, // 右边不拉伸区域宽度
|
|
39
|
-
* bottomHeight: 20 // 底部不拉伸区域高度
|
|
40
|
-
* }));
|
|
41
|
-
*
|
|
42
|
-
* // 设置按钮尺寸(自动拉伸)
|
|
43
|
-
* button.transform.size = { width: 200, height: 60 };
|
|
44
|
-
*
|
|
45
|
-
* // 创建对话框背景
|
|
46
|
-
* const dialog = new GameObject('dialog');
|
|
47
|
-
* dialog.addComponent(new NinePatch({
|
|
48
|
-
* resource: 'dialogBg',
|
|
49
|
-
* leftWidth: 30,
|
|
50
|
-
* topHeight: 30,
|
|
51
|
-
* rightWidth: 30,
|
|
52
|
-
* bottomHeight: 30
|
|
53
|
-
* }));
|
|
54
|
-
* dialog.transform.size = { width: 400, height: 300 };
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
export declare class NinePatch extends Component<NinePatchParams> {
|
|
58
|
-
/** 组件名称 */
|
|
59
|
-
static componentName: string;
|
|
60
|
-
/** 九宫格精灵实例 */
|
|
61
|
-
ninePatch: NinePatch_2;
|
|
62
|
-
/** 图片资源名称 */
|
|
63
|
-
resource: string;
|
|
64
|
-
/** 精灵图集中的图片名称 */
|
|
65
|
-
spriteName: string;
|
|
66
|
-
/** 左边不拉伸区域的宽度 */
|
|
67
|
-
leftWidth: number;
|
|
68
|
-
/** 顶部不拉伸区域的高度 */
|
|
69
|
-
topHeight: number;
|
|
70
|
-
/** 右边不拉伸区域的宽度 */
|
|
71
|
-
rightWidth: number;
|
|
72
|
-
/** 底部不拉伸区域的高度 */
|
|
73
|
-
bottomHeight: number;
|
|
74
|
-
/**
|
|
75
|
-
* 初始化组件
|
|
76
|
-
* @param obj - 初始化参数
|
|
77
|
-
* @param obj.resource - 资源名称
|
|
78
|
-
* @param obj.spriteName - 精灵名称
|
|
79
|
-
* @param obj.leftWidth - 左边固定宽度
|
|
80
|
-
* @param obj.topHeight - 顶部固定高度
|
|
81
|
-
* @param obj.rightWidth - 右边固定宽度
|
|
82
|
-
* @param obj.bottomHeight - 底部固定高度
|
|
83
|
-
*/
|
|
84
|
-
init(obj?: NinePatchParams): void;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export declare interface NinePatchParams {
|
|
88
|
-
resource: string;
|
|
89
|
-
spriteName?: string;
|
|
90
|
-
leftWidth?: number;
|
|
91
|
-
topHeight?: number;
|
|
92
|
-
rightWidth?: number;
|
|
93
|
-
bottomHeight?: number;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export declare class NinePatchSystem extends Renderer {
|
|
97
|
-
static systemName: string;
|
|
98
|
-
name: string;
|
|
99
|
-
ninePatch: {
|
|
100
|
-
[propName: number]: NinePatch_2;
|
|
101
|
-
};
|
|
102
|
-
renderSystem: RendererSystem;
|
|
103
|
-
rendererManager: RendererManager;
|
|
104
|
-
containerManager: ContainerManager;
|
|
105
|
-
init(): void;
|
|
106
|
-
rendererUpdate(gameObject: GameObject): void;
|
|
107
|
-
componentChanged(changed: ComponentChanged): Promise<void>;
|
|
108
|
-
add(changed: ComponentChanged): Promise<void>;
|
|
109
|
-
remove(changed: ComponentChanged): void;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export { }
|