@eva/plugin-renderer-nine-patch 2.0.1-beta.9 → 2.0.2-beta.0
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/dist/EVA.plugin.renderer.ninePatch.min.js +1 -1
- package/dist/plugin-renderer-nine-patch.cjs.js +85 -14
- package/dist/plugin-renderer-nine-patch.cjs.prod.js +1 -16
- package/dist/plugin-renderer-nine-patch.d.ts +65 -0
- package/dist/plugin-renderer-nine-patch.esm.js +85 -14
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
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))(
|
|
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;
|
|
@@ -7,19 +7,19 @@ var inspectorDecorator = require('@eva/inspector-decorator');
|
|
|
7
7
|
var pluginRenderer = require('@eva/plugin-renderer');
|
|
8
8
|
var rendererAdapter = require('@eva/renderer-adapter');
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
Copyright (c) Microsoft Corporation.
|
|
12
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
13
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
14
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
/******************************************************************************
|
|
11
|
+
Copyright (c) Microsoft Corporation.
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
19
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
13
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
14
|
+
purpose with or without fee is hereby granted.
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
17
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
18
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
19
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
20
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
21
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
22
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
23
23
|
***************************************************************************** */
|
|
24
24
|
|
|
25
25
|
function __decorate(decorators, target, key, desc) {
|
|
@@ -30,24 +30,93 @@ function __decorate(decorators, target, key, desc) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
33
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
33
34
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
34
35
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
35
36
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
36
|
-
function step(result) { result.done ? resolve(result.value) :
|
|
37
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
37
38
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
38
39
|
});
|
|
39
|
-
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
43
|
+
var e = new Error(message);
|
|
44
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
45
|
+
};
|
|
40
46
|
|
|
47
|
+
/**
|
|
48
|
+
* 九宫格组件
|
|
49
|
+
*
|
|
50
|
+
* NinePatch 组件用于实现可拉伸的图片,保持边角不变形。
|
|
51
|
+
* 将图片分为 9 个区域,拉伸时只拉伸中间区域,边角保持原始比例,
|
|
52
|
+
* 适用于按钮、对话框、面板等需要自适应尺寸的 UI 元素。
|
|
53
|
+
*
|
|
54
|
+
* 九宫格原理:
|
|
55
|
+
* ```
|
|
56
|
+
* +-------+-------+-------+
|
|
57
|
+
* | 左上 | 上 | 右上 |
|
|
58
|
+
* +-------+-------+-------+
|
|
59
|
+
* | 左 | 中间 | 右 |
|
|
60
|
+
* +-------+-------+-------+
|
|
61
|
+
* | 左下 | 下 | 右下 |
|
|
62
|
+
* +-------+-------+-------+
|
|
63
|
+
* ```
|
|
64
|
+
* 拉伸时,四个角保持不变,四条边单向拉伸,中间区域双向拉伸。
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // 创建可拉伸的按钮背景
|
|
69
|
+
* const button = new GameObject('button');
|
|
70
|
+
* button.addComponent(new NinePatch({
|
|
71
|
+
* resource: 'buttonBg', // 按钮背景资源
|
|
72
|
+
* spriteName: 'btn_normal.png',
|
|
73
|
+
* leftWidth: 20, // 左边不拉伸区域宽度
|
|
74
|
+
* topHeight: 20, // 顶部不拉伸区域高度
|
|
75
|
+
* rightWidth: 20, // 右边不拉伸区域宽度
|
|
76
|
+
* bottomHeight: 20 // 底部不拉伸区域高度
|
|
77
|
+
* }));
|
|
78
|
+
*
|
|
79
|
+
* // 设置按钮尺寸(自动拉伸)
|
|
80
|
+
* button.transform.size = { width: 200, height: 60 };
|
|
81
|
+
*
|
|
82
|
+
* // 创建对话框背景
|
|
83
|
+
* const dialog = new GameObject('dialog');
|
|
84
|
+
* dialog.addComponent(new NinePatch({
|
|
85
|
+
* resource: 'dialogBg',
|
|
86
|
+
* leftWidth: 30,
|
|
87
|
+
* topHeight: 30,
|
|
88
|
+
* rightWidth: 30,
|
|
89
|
+
* bottomHeight: 30
|
|
90
|
+
* }));
|
|
91
|
+
* dialog.transform.size = { width: 400, height: 300 };
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
41
94
|
class NinePatch$2 extends eva_js.Component {
|
|
42
95
|
constructor() {
|
|
43
96
|
super(...arguments);
|
|
97
|
+
/** 图片资源名称 */
|
|
44
98
|
this.resource = '';
|
|
99
|
+
/** 精灵图集中的图片名称 */
|
|
45
100
|
this.spriteName = '';
|
|
101
|
+
/** 左边不拉伸区域的宽度 */
|
|
46
102
|
this.leftWidth = 0;
|
|
103
|
+
/** 顶部不拉伸区域的高度 */
|
|
47
104
|
this.topHeight = 0;
|
|
105
|
+
/** 右边不拉伸区域的宽度 */
|
|
48
106
|
this.rightWidth = 0;
|
|
107
|
+
/** 底部不拉伸区域的高度 */
|
|
49
108
|
this.bottomHeight = 0;
|
|
50
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* 初始化组件
|
|
112
|
+
* @param obj - 初始化参数
|
|
113
|
+
* @param obj.resource - 资源名称
|
|
114
|
+
* @param obj.spriteName - 精灵名称
|
|
115
|
+
* @param obj.leftWidth - 左边固定宽度
|
|
116
|
+
* @param obj.topHeight - 顶部固定高度
|
|
117
|
+
* @param obj.rightWidth - 右边固定宽度
|
|
118
|
+
* @param obj.bottomHeight - 底部固定高度
|
|
119
|
+
*/
|
|
51
120
|
init(obj) {
|
|
52
121
|
this.resource = obj.resource;
|
|
53
122
|
this.spriteName = obj.spriteName;
|
|
@@ -57,6 +126,7 @@ class NinePatch$2 extends eva_js.Component {
|
|
|
57
126
|
this.bottomHeight = obj.bottomHeight;
|
|
58
127
|
}
|
|
59
128
|
}
|
|
129
|
+
/** 组件名称 */
|
|
60
130
|
NinePatch$2.componentName = 'NinePatch';
|
|
61
131
|
__decorate([
|
|
62
132
|
inspectorDecorator.type('string')
|
|
@@ -81,7 +151,7 @@ __decorate([
|
|
|
81
151
|
inspectorDecorator.step(1)
|
|
82
152
|
], NinePatch$2.prototype, "bottomHeight", void 0);
|
|
83
153
|
|
|
84
|
-
const resourceKeySplit = '_s|r|c_';
|
|
154
|
+
const resourceKeySplit = '_s|r|c_'; // Notice: This key be created by sprite system.
|
|
85
155
|
let NinePatch = class NinePatch extends pluginRenderer.Renderer {
|
|
86
156
|
constructor() {
|
|
87
157
|
super(...arguments);
|
|
@@ -144,6 +214,7 @@ let NinePatch = class NinePatch extends pluginRenderer.Renderer {
|
|
|
144
214
|
component.ninePatch = np;
|
|
145
215
|
this.containerManager
|
|
146
216
|
.getContainer(changed.gameObject.id)
|
|
217
|
+
// @ts-ignore
|
|
147
218
|
.addChildAt(np, 0);
|
|
148
219
|
});
|
|
149
220
|
}
|
|
@@ -1,16 +1 @@
|
|
|
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
|
+
"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");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){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(s,h)}c((r=r.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;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;
|
|
@@ -7,15 +7,80 @@ import { Renderer } from '@eva/plugin-renderer';
|
|
|
7
7
|
import { RendererManager } from '@eva/plugin-renderer';
|
|
8
8
|
import { RendererSystem } from '@eva/plugin-renderer';
|
|
9
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
|
+
*/
|
|
10
57
|
export declare class NinePatch extends Component<NinePatchParams> {
|
|
58
|
+
/** 组件名称 */
|
|
11
59
|
static componentName: string;
|
|
60
|
+
/** 九宫格精灵实例 */
|
|
12
61
|
ninePatch: NinePatch_2;
|
|
62
|
+
/** 图片资源名称 */
|
|
13
63
|
resource: string;
|
|
64
|
+
/** 精灵图集中的图片名称 */
|
|
14
65
|
spriteName: string;
|
|
66
|
+
/** 左边不拉伸区域的宽度 */
|
|
15
67
|
leftWidth: number;
|
|
68
|
+
/** 顶部不拉伸区域的高度 */
|
|
16
69
|
topHeight: number;
|
|
70
|
+
/** 右边不拉伸区域的宽度 */
|
|
17
71
|
rightWidth: number;
|
|
72
|
+
/** 底部不拉伸区域的高度 */
|
|
18
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
|
+
*/
|
|
19
84
|
init(obj?: NinePatchParams): void;
|
|
20
85
|
}
|
|
21
86
|
|
|
@@ -3,19 +3,19 @@ import { type, step } from '@eva/inspector-decorator';
|
|
|
3
3
|
import { Renderer, RendererSystem } from '@eva/plugin-renderer';
|
|
4
4
|
import { NinePatch as NinePatch$3 } from '@eva/renderer-adapter';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
Copyright (c) Microsoft Corporation.
|
|
8
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
9
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
10
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
/******************************************************************************
|
|
7
|
+
Copyright (c) Microsoft Corporation.
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
15
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
9
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
+
purpose with or without fee is hereby granted.
|
|
16
11
|
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
19
19
|
***************************************************************************** */
|
|
20
20
|
|
|
21
21
|
function __decorate(decorators, target, key, desc) {
|
|
@@ -26,24 +26,93 @@ function __decorate(decorators, target, key, desc) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
29
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
29
30
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
30
31
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
31
32
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
32
|
-
function step(result) { result.done ? resolve(result.value) :
|
|
33
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
33
34
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
34
35
|
});
|
|
35
|
-
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
39
|
+
var e = new Error(message);
|
|
40
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
41
|
+
};
|
|
36
42
|
|
|
43
|
+
/**
|
|
44
|
+
* 九宫格组件
|
|
45
|
+
*
|
|
46
|
+
* NinePatch 组件用于实现可拉伸的图片,保持边角不变形。
|
|
47
|
+
* 将图片分为 9 个区域,拉伸时只拉伸中间区域,边角保持原始比例,
|
|
48
|
+
* 适用于按钮、对话框、面板等需要自适应尺寸的 UI 元素。
|
|
49
|
+
*
|
|
50
|
+
* 九宫格原理:
|
|
51
|
+
* ```
|
|
52
|
+
* +-------+-------+-------+
|
|
53
|
+
* | 左上 | 上 | 右上 |
|
|
54
|
+
* +-------+-------+-------+
|
|
55
|
+
* | 左 | 中间 | 右 |
|
|
56
|
+
* +-------+-------+-------+
|
|
57
|
+
* | 左下 | 下 | 右下 |
|
|
58
|
+
* +-------+-------+-------+
|
|
59
|
+
* ```
|
|
60
|
+
* 拉伸时,四个角保持不变,四条边单向拉伸,中间区域双向拉伸。
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* // 创建可拉伸的按钮背景
|
|
65
|
+
* const button = new GameObject('button');
|
|
66
|
+
* button.addComponent(new NinePatch({
|
|
67
|
+
* resource: 'buttonBg', // 按钮背景资源
|
|
68
|
+
* spriteName: 'btn_normal.png',
|
|
69
|
+
* leftWidth: 20, // 左边不拉伸区域宽度
|
|
70
|
+
* topHeight: 20, // 顶部不拉伸区域高度
|
|
71
|
+
* rightWidth: 20, // 右边不拉伸区域宽度
|
|
72
|
+
* bottomHeight: 20 // 底部不拉伸区域高度
|
|
73
|
+
* }));
|
|
74
|
+
*
|
|
75
|
+
* // 设置按钮尺寸(自动拉伸)
|
|
76
|
+
* button.transform.size = { width: 200, height: 60 };
|
|
77
|
+
*
|
|
78
|
+
* // 创建对话框背景
|
|
79
|
+
* const dialog = new GameObject('dialog');
|
|
80
|
+
* dialog.addComponent(new NinePatch({
|
|
81
|
+
* resource: 'dialogBg',
|
|
82
|
+
* leftWidth: 30,
|
|
83
|
+
* topHeight: 30,
|
|
84
|
+
* rightWidth: 30,
|
|
85
|
+
* bottomHeight: 30
|
|
86
|
+
* }));
|
|
87
|
+
* dialog.transform.size = { width: 400, height: 300 };
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
37
90
|
class NinePatch$2 extends Component {
|
|
38
91
|
constructor() {
|
|
39
92
|
super(...arguments);
|
|
93
|
+
/** 图片资源名称 */
|
|
40
94
|
this.resource = '';
|
|
95
|
+
/** 精灵图集中的图片名称 */
|
|
41
96
|
this.spriteName = '';
|
|
97
|
+
/** 左边不拉伸区域的宽度 */
|
|
42
98
|
this.leftWidth = 0;
|
|
99
|
+
/** 顶部不拉伸区域的高度 */
|
|
43
100
|
this.topHeight = 0;
|
|
101
|
+
/** 右边不拉伸区域的宽度 */
|
|
44
102
|
this.rightWidth = 0;
|
|
103
|
+
/** 底部不拉伸区域的高度 */
|
|
45
104
|
this.bottomHeight = 0;
|
|
46
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* 初始化组件
|
|
108
|
+
* @param obj - 初始化参数
|
|
109
|
+
* @param obj.resource - 资源名称
|
|
110
|
+
* @param obj.spriteName - 精灵名称
|
|
111
|
+
* @param obj.leftWidth - 左边固定宽度
|
|
112
|
+
* @param obj.topHeight - 顶部固定高度
|
|
113
|
+
* @param obj.rightWidth - 右边固定宽度
|
|
114
|
+
* @param obj.bottomHeight - 底部固定高度
|
|
115
|
+
*/
|
|
47
116
|
init(obj) {
|
|
48
117
|
this.resource = obj.resource;
|
|
49
118
|
this.spriteName = obj.spriteName;
|
|
@@ -53,6 +122,7 @@ class NinePatch$2 extends Component {
|
|
|
53
122
|
this.bottomHeight = obj.bottomHeight;
|
|
54
123
|
}
|
|
55
124
|
}
|
|
125
|
+
/** 组件名称 */
|
|
56
126
|
NinePatch$2.componentName = 'NinePatch';
|
|
57
127
|
__decorate([
|
|
58
128
|
type('string')
|
|
@@ -77,7 +147,7 @@ __decorate([
|
|
|
77
147
|
step(1)
|
|
78
148
|
], NinePatch$2.prototype, "bottomHeight", void 0);
|
|
79
149
|
|
|
80
|
-
const resourceKeySplit = '_s|r|c_';
|
|
150
|
+
const resourceKeySplit = '_s|r|c_'; // Notice: This key be created by sprite system.
|
|
81
151
|
let NinePatch = class NinePatch extends Renderer {
|
|
82
152
|
constructor() {
|
|
83
153
|
super(...arguments);
|
|
@@ -140,6 +210,7 @@ let NinePatch = class NinePatch extends Renderer {
|
|
|
140
210
|
component.ninePatch = np;
|
|
141
211
|
this.containerManager
|
|
142
212
|
.getContainer(changed.gameObject.id)
|
|
213
|
+
// @ts-ignore
|
|
143
214
|
.addChildAt(np, 0);
|
|
144
215
|
});
|
|
145
216
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-nine-patch",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2-beta.0",
|
|
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.
|
|
23
|
-
"@eva/renderer-adapter": "2.0.
|
|
24
|
-
"@eva/eva.js": "2.0.
|
|
22
|
+
"@eva/plugin-renderer": "2.0.2-beta.0",
|
|
23
|
+
"@eva/renderer-adapter": "2.0.2-beta.0",
|
|
24
|
+
"@eva/eva.js": "2.0.2-beta.0"
|
|
25
25
|
}
|
|
26
26
|
}
|