fix using spriteframe in atlas failed (#4073)

This commit is contained in:
JoneLau
2019-03-21 15:29:03 +08:00
committed by Weiliang Wang
parent b7a02bb21b
commit 351a7e5c82
6 changed files with 56 additions and 59 deletions
+11 -3
View File
@@ -79,6 +79,8 @@ export enum VerticalTextAlignment {
BOTTOM = 2,
}
ccenum(VerticalTextAlignment);
/**
* !#en Enum for Overflow.
* !#zh Overflow 类型
@@ -169,7 +171,9 @@ export class LabelComponent extends UIRenderComponent {
* !#zh 文本内容的水平对齐方式。
* @property {Label.HorizontalAlign} horizontalAlign
*/
@property()
@property({
type: HorizontalTextAlignment,
})
get horizontalAlign () {
return this._horizontalAlign;
}
@@ -188,7 +192,9 @@ export class LabelComponent extends UIRenderComponent {
* !#zh 文本内容的垂直对齐方式。
* @property {Label.VerticalAlign} VerticalTextAlignment
*/
@property()
@property({
type: VerticalTextAlignment,
})
get verticalAlign () {
return this._verticalAlign;
}
@@ -277,7 +283,9 @@ export class LabelComponent extends UIRenderComponent {
* !#zh 文字显示超出范围时的处理方式。
* @property {Overflow} overflow
*/
@property()
@property({
type: Overflow,
})
get overflow () {
return this._overflow;
}
+3 -3
View File
@@ -27,7 +27,7 @@ import { EventHandler as ComponentEventHandler } from '../../../components/compo
import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../../core/data/class-decorator';
import { ButtonComponent} from './button-component';
import { SpriteComponent} from './sprite-component';
import { ToggleGroupComponent} from './toggle-group-component';
import { ToggleContainerComponent} from './toggle-group-component';
/**
* !#en The toggle component is a CheckBox, when it used together with a ToggleGroup, it
@@ -70,7 +70,7 @@ export class ToggleComponent extends ButtonComponent {
* @property {ToggleGroup} toggleGroup
*/
@property({
type: ToggleGroupComponent,
type: ToggleContainerComponent,
})
get toggleGroup () {
return this._toggleGroup;
@@ -136,7 +136,7 @@ export class ToggleComponent extends ButtonComponent {
@property
private _isChecked: boolean = true;
@property
private _toggleGroup: ToggleGroupComponent | null = null;
private _toggleGroup: ToggleContainerComponent | null = null;
@property
private _checkMark: SpriteComponent | null = null;
@@ -37,11 +37,11 @@ import { ToggleComponent} from './toggle-component';
* @extends Component
*/
@ccclass('cc.ToggleGroupComponent')
@ccclass('cc.ToggleContainerComponent')
@executionOrder(100)
@menu('UI/ToggleGroup')
@executeInEditMode
export class ToggleGroupComponent extends Component {
export class ToggleContainerComponent extends Component {
@property({
type: ComponentEventHandler,
})
@@ -137,4 +137,4 @@ export class ToggleGroupComponent extends Component {
}
}
cc.ToggleGroupComponent = ToggleGroupComponent;
cc.ToggleContainerComponent = ToggleContainerComponent;
+6 -13
View File
@@ -512,7 +512,6 @@ export class WidgetComponent extends Component {
@property
private _alignFlags = 0;
private _wasAlignOnce = false;
@property
private _target: Node | null = null;
@property
@@ -568,16 +567,6 @@ export class WidgetComponent extends Component {
}
protected onLoad () {
// TODO:
// if (this._wasAlignOnce) {
// // migrate for old version
// this.alignMode = this._wasAlignOnce ? AlignMode.ONCE : AlignMode.ALWAYS;
// this._wasAlignOnce = false;
// }
if (this._alignMode === AlignMode.ONCE){
this._wasAlignOnce = true;
}
}
protected onEnable () {
@@ -604,6 +593,7 @@ export class WidgetComponent extends Component {
this._originalWidth = this.node.width!;
// test check conflict
if (CC_EDITOR /*&& !cc.engine.isPlaying*/) {
// TODO:
// _Scene.DetectConflict.checkConflict_Widget(this);
}
}
@@ -613,13 +603,14 @@ export class WidgetComponent extends Component {
// become stretch
this._originalHeight = this.node.height!;
// test check conflict
if (CC_EDITOR && !cc.engine.isPlaying) {
if (CC_EDITOR /*&& !cc.engine.isPlaying*/) {
// TODO:
// _Scene.DetectConflict.checkConflict_Widget(this);
}
}
}
if (CC_EDITOR && !cc.engine._isPlaying && this.node.parent) {
if (CC_EDITOR && this.node.parent) {
// adjust the offsets to keep the size and position unchanged after alignment chagned
cc._widgetManager.updateOffsetsToStayPut(this, flag);
}
@@ -641,6 +632,8 @@ export class WidgetComponent extends Component {
}
}
cc.WidgetComponent = WidgetComponent;
/**
* !#en
* When turned on, it will only be aligned once at the end of the onEnable frame,
+14 -24
View File
@@ -121,9 +121,9 @@ export class SpriteFrame extends EventTargetFactory(Texture2D) {
set insetTop (value) {
this._capInsets[INSET_TOP] = value;
// if (this._texture) {
this._calculateSlicedUV();
// }
if (this.image) {
this._calculateSlicedUV();
}
}
/**
@@ -139,9 +139,9 @@ export class SpriteFrame extends EventTargetFactory(Texture2D) {
set insetBottom (value) {
this._capInsets[INSET_BOTTOM] = value;
// if (this._texture) {
this._calculateSlicedUV();
// }
if (this.image) {
this._calculateSlicedUV();
}
}
/**
@@ -157,9 +157,9 @@ export class SpriteFrame extends EventTargetFactory(Texture2D) {
set insetLeft (value) {
this._capInsets[INSET_LEFT] = value;
// if (this._texture) {
this._calculateSlicedUV();
// }
if (this.image) {
this._calculateSlicedUV();
}
}
/**
@@ -175,9 +175,9 @@ export class SpriteFrame extends EventTargetFactory(Texture2D) {
set insetRight (value) {
this._capInsets[INSET_RIGHT] = value;
// if (this._texture) {
this._calculateSlicedUV();
// }
if (this.image) {
this._calculateSlicedUV();
}
}
get atlasUuid () {
@@ -188,14 +188,6 @@ export class SpriteFrame extends EventTargetFactory(Texture2D) {
this._atlasUuid = value;
}
get atlasSize () {
return this._atlasSize;
}
set atlasSize (value: Size) {
this._atlasSize = value;
}
public vertices: IVertices | null = null;
public uv: number[] = [];
@@ -216,12 +208,10 @@ export class SpriteFrame extends EventTargetFactory(Texture2D) {
private _capInsets = [0, 0, 0, 0];
// store original info before packed to dynamic atlas
private _original = null;
// private _original = null;
private _atlasUuid: string = '';
private _atlasSize = new Size();
/**
* !#en
* Constructor of SpriteFrame class.
@@ -436,10 +426,10 @@ export class SpriteFrame extends EventTargetFactory(Texture2D) {
* @method clone
* @return {SpriteFrame}
*/
public clone () {
const cloneSprite = new SpriteFrame();
cloneSprite.name = this.name;
cloneSprite.atlasUuid = this.atlasUuid;
cloneSprite.setOriginalSize(this._originalSize);
cloneSprite.setRect(this._rect);
const cap = this._capInsets;
+19 -13
View File
@@ -25,6 +25,7 @@
****************************************************************************/
import { ccclass, property } from '../core/data/class-decorator';
import * as js from '../core/utils/js';
import { Asset } from './asset';
import { SpriteFrame } from './CCSpriteFrame';
@@ -40,10 +41,14 @@ interface ISpriteAtlasSerializeData{
spriteFrames: string[];
}
interface ISpriteFrameList {
[key: string]: SpriteFrame | null;
}
@ccclass('cc.SpriteAtlas')
export class SpriteAtlas extends Asset {
@property
public spriteFrames: Map<string, SpriteFrame | null> = new Map<string, SpriteFrame | null>();
public spriteFrames: ISpriteFrameList = js.createMap();
/**
* Returns the texture of the sprite atlas
@@ -51,10 +56,10 @@ export class SpriteAtlas extends Asset {
* @returns {Texture2D}
*/
public getTexture () {
const values = this.spriteFrames.values;
if (values.length > 0) {
const spriteFrame = values[0];
return spriteFrame && spriteFrame.image ? spriteFrame.image : null;
const keys = Object.keys(this.spriteFrames);
if (keys.length > 0) {
const spriteFrame = this.spriteFrames[keys[0]];
return spriteFrame ? spriteFrame.image : null;
}
else {
return null;
@@ -85,8 +90,10 @@ export class SpriteAtlas extends Asset {
*/
public getSpriteFrames () {
const frames: Array<SpriteFrame | null> = [];
for (const spriteFrame of this.spriteFrames) {
frames.push(spriteFrame[1]);
const spriteFrames = this.spriteFrames;
for (const key of Object.keys(spriteFrames)) {
frames.push(spriteFrames[key]);
}
return frames;
@@ -94,9 +101,9 @@ export class SpriteAtlas extends Asset {
public _serialize () {
const frames: string[] = [];
for (const spriteFrame of this.spriteFrames) {
const id = spriteFrame[1] ? spriteFrame[1]._uuid : '';
frames.push(spriteFrame[0]);
for (const key of Object.keys(this.spriteFrames)) {
const spriteFrame = this.spriteFrames[key];
const id = spriteFrame ? spriteFrame._uuid : '';
frames.push(id);
}
@@ -110,10 +117,9 @@ export class SpriteAtlas extends Asset {
const data = serializeData as ISpriteAtlasSerializeData;
this._name = data.name;
const frames = data.spriteFrames;
this.spriteFrames.clear();
this.spriteFrames = js.createMap();
for (let i = 0; i < frames.length; i += 2) {
this.spriteFrames.set(frames[i], new SpriteFrame());
handle.result.push(this.spriteFrames, `${i}`, frames[i + 1]);
handle.result.push(this.spriteFrames, frames[i], frames[i + 1]);
}
}
}