mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
fix some bug and adjust code (#4284)
This commit is contained in:
@@ -160,7 +160,7 @@ export const bmfontUtils = {
|
||||
this._updateProperties();
|
||||
this._updateContent();
|
||||
|
||||
// _comp._actualFontSize = _fontSize;
|
||||
_comp.actualFontSize = _fontSize;
|
||||
_comp.node.setContentSize(_contentSize);
|
||||
|
||||
_comp.renderData!.vertDirty = _comp.renderData!.uvDirty = false;
|
||||
|
||||
@@ -490,7 +490,7 @@ export const letterFont = {
|
||||
|
||||
this._updateContent();
|
||||
|
||||
// _comp._actualFontSize = _fontSize;
|
||||
_comp.actualFontSize = _fontSize;
|
||||
_comp.node.setContentSize(_contentSize);
|
||||
|
||||
_comp.renderData!.vertDirty = _comp.renderData!.uvDirty = false;
|
||||
|
||||
@@ -30,6 +30,7 @@ import { Color, Size } from '../../../../core/value-types';
|
||||
import { HorizontalTextAlignment, LabelComponent, VerticalTextAlignment } from '../../components/label-component';
|
||||
import { LabelOutlineComponent } from '../../components/label-outline-component';
|
||||
import { CanvasPool, ISharedLabelData } from './font-utils';
|
||||
import { LetterRenderTexture } from './letter-font';
|
||||
|
||||
const Overflow = LabelComponent.Overflow;
|
||||
const WHITE = Color.WHITE;
|
||||
@@ -37,7 +38,7 @@ const OUTLINE_SUPPORTED = cc.js.isChildClassOf(LabelOutlineComponent, Component)
|
||||
|
||||
let _context: CanvasRenderingContext2D | null = null;
|
||||
let _canvas: HTMLCanvasElement | null = null;
|
||||
let _texture: SpriteFrame | null = null;
|
||||
let _texture: SpriteFrame | LetterRenderTexture | null = null;
|
||||
|
||||
let _fontDesc = '';
|
||||
let _string = '';
|
||||
@@ -102,7 +103,7 @@ export const ttfUtils = {
|
||||
this._calculateTextBaseline();
|
||||
this._updateTexture();
|
||||
|
||||
// comp._actualFontSize = _fontSize;
|
||||
comp.actualFontSize = _fontSize;
|
||||
comp.node.setContentSize(_canvasSize);
|
||||
|
||||
this.updateVerts(comp);
|
||||
|
||||
@@ -150,6 +150,7 @@ export class CanvasComponent extends Component {
|
||||
protected _thisOnResized: () => void;
|
||||
|
||||
protected _camera: Camera | null = null;
|
||||
private _pos = new Vec3();
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
@@ -218,10 +219,14 @@ export class CanvasComponent extends Component {
|
||||
public alignWithScreen () {
|
||||
let nodeSize;
|
||||
let designSize;
|
||||
this.node.getPosition(this._pos);
|
||||
if (CC_EDITOR) {
|
||||
// nodeSize = designSize = cc.engine.getDesignResolutionSize();
|
||||
nodeSize = designSize = this._designResolution;
|
||||
this.node.setPosition(designSize.width * 0.5, designSize.height * 0.5, 1);
|
||||
_tempPos.x = designSize.width * 0.5;
|
||||
_tempPos.y = designSize.height * 0.5;
|
||||
_tempPos.z = 0;
|
||||
|
||||
}
|
||||
else {
|
||||
const canvasSize = cc.visibleRect;
|
||||
@@ -235,7 +240,14 @@ export class CanvasComponent extends Component {
|
||||
offsetX = (designSize.width - canvasSize.width) * 0.5;
|
||||
offsetY = (designSize.height - canvasSize.height) * 0.5;
|
||||
}
|
||||
this.node.setPosition(canvasSize.width * 0.5 + offsetX, canvasSize.height * 0.5 + offsetY, 1);
|
||||
|
||||
_tempPos.x = canvasSize.width * 0.5 + offsetX;
|
||||
_tempPos.y = canvasSize.height * 0.5 + offsetY;
|
||||
_tempPos.z = 0;
|
||||
}
|
||||
|
||||
if (this._pos.equals(_tempPos)) {
|
||||
this.node.setPosition(_tempPos);
|
||||
}
|
||||
|
||||
if (this.node.width !== nodeSize.width) {
|
||||
|
||||
@@ -209,7 +209,7 @@ export class GraphicsComponent extends UIRenderComponent {
|
||||
super.__preload();
|
||||
}
|
||||
|
||||
this._flushAssembler();
|
||||
// this._flushAssembler();
|
||||
this.impl = this._assembler && (this._assembler as IAssembler).createImpl!(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -238,12 +238,15 @@ export class LabelComponent extends UIRenderComponent {
|
||||
@property({
|
||||
readonly: true,
|
||||
displayName: 'Actual Font Size',
|
||||
visible: false,
|
||||
})
|
||||
get actualFontSize () {
|
||||
return this._actualFontSize;
|
||||
}
|
||||
|
||||
set actualFontSize (value) {
|
||||
this._actualFontSize = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* !#en Font size of label.
|
||||
* !#zh 文本字体大小。
|
||||
@@ -672,7 +675,7 @@ export class LabelComponent extends UIRenderComponent {
|
||||
}
|
||||
|
||||
protected _canRender () {
|
||||
if (!super._canRender){
|
||||
if (!super._canRender()){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -251,7 +251,7 @@ export class MaskComponent extends UIRenderComponent {
|
||||
}
|
||||
|
||||
public onLoad (){
|
||||
this._flushAssembler();
|
||||
// this._flushAssembler();
|
||||
this._createGraphics();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import { clampf } from '../../../core/utils/misc';
|
||||
import { Vec2 } from '../../../core/value-types';
|
||||
import { ccenum } from '../../../core/value-types/enum';
|
||||
import { UI } from '../../../renderer/ui/ui';
|
||||
import { InstanceMaterialType, UIRenderComponent } from './ui-render-component';
|
||||
import { UIRenderComponent } from './ui-render-component';
|
||||
|
||||
/**
|
||||
* !#en Enum for sprite type.
|
||||
@@ -431,7 +431,7 @@ export class SpriteComponent extends UIRenderComponent {
|
||||
}
|
||||
}
|
||||
|
||||
this._flushAssembler();
|
||||
// this._flushAssembler();
|
||||
this._activateMaterial();
|
||||
}
|
||||
|
||||
|
||||
@@ -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 { ToggleContainerComponent} from './toggle-group-component';
|
||||
import { ToggleContainerComponent} from './toggle-container-component';
|
||||
|
||||
/**
|
||||
* !#en The toggle component is a CheckBox, when it used together with a ToggleGroup, it
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ import { ToggleComponent} from './toggle-component';
|
||||
|
||||
@ccclass('cc.ToggleContainerComponent')
|
||||
@executionOrder(100)
|
||||
@menu('UI/ToggleGroup')
|
||||
@menu('UI/ToggleContainer')
|
||||
@executeInEditMode
|
||||
export class ToggleContainerComponent extends Component {
|
||||
@property({
|
||||
@@ -12,12 +12,12 @@ import { UIComponent } from './ui-component';
|
||||
@menu('UI/Model')
|
||||
export class UIModelComponent extends UIComponent {
|
||||
|
||||
private _modelComponent: RenderableComponent | null = null;
|
||||
|
||||
public get modelComponent () {
|
||||
return this._modelComponent;
|
||||
}
|
||||
|
||||
private _modelComponent: RenderableComponent | null = null;
|
||||
|
||||
public onLoad () {
|
||||
this._modelComponent = this.getComponent(cc.RenderableComponent) as RenderableComponent;
|
||||
(this._modelComponent as any)._sceneGetter = cc.director.root.ui.getRenderSceneGetter();
|
||||
@@ -27,6 +27,19 @@ export class UIModelComponent extends UIComponent {
|
||||
this._fitUIRenderQueue();
|
||||
}
|
||||
|
||||
public updateAssembler (render: UI) {
|
||||
if (this._modelComponent) {
|
||||
render.commitComp.call(render, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public update () {
|
||||
this._fitUIRenderQueue();
|
||||
}
|
||||
|
||||
private _fitUIRenderQueue () {
|
||||
if (!this._modelComponent) {
|
||||
return;
|
||||
@@ -58,17 +71,4 @@ export class UIModelComponent extends UIComponent {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public updateAssembler (render: UI) {
|
||||
if (this._modelComponent) {
|
||||
render.commitComp.call(render, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public update () {
|
||||
this._fitUIRenderQueue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,6 +207,9 @@ export class UIRenderComponent extends UIComponent {
|
||||
|
||||
public __preload (){
|
||||
this._instanceMaterial();
|
||||
if (this._flushAssembler){
|
||||
this._flushAssembler();
|
||||
}
|
||||
}
|
||||
|
||||
public onEnable () {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { EventType } from '../../../core/platform/event-manager/event-enum';
|
||||
import { EventListener, ILinstenerMask } from '../../../core/platform/event-manager/event-listener';
|
||||
import { Mat4, Rect, Size, Vec2, Vec3 } from '../../../core/value-types';
|
||||
import * as vmath from '../../../core/vmath';
|
||||
import { CanvasComponent } from './canvas-component';
|
||||
|
||||
const _vec2a = new Vec2();
|
||||
const _vec2b = new Vec2();
|
||||
@@ -379,7 +380,7 @@ export class UITransformComponent extends Component {
|
||||
// 获取被渲染相机的 visibility
|
||||
while (parent) {
|
||||
if (parent) {
|
||||
const canvasComp = parent.getComponent(cc.CanvasComponent);
|
||||
const canvasComp = parent.getComponent('cc.CanvasComponent') as CanvasComponent;
|
||||
if (canvasComp) {
|
||||
visibility = canvasComp.visibility;
|
||||
break;
|
||||
|
||||
@@ -13,7 +13,7 @@ export { ScrollViewComponent } from './components/scroll-view-component';
|
||||
export { SliderComponent } from './components/slider-component';
|
||||
export { SpriteComponent } from './components/sprite-component';
|
||||
export { ToggleComponent } from './components/toggle-component';
|
||||
export { ToggleContainerComponent } from './components/toggle-group-component';
|
||||
export { ToggleContainerComponent } from './components/toggle-container-component';
|
||||
export { UIModelComponent } from './components/ui-model-component';
|
||||
export { UIRenderComponent } from './components/ui-render-component';
|
||||
export { UITransformComponent } from './components/ui-transfrom-component';
|
||||
|
||||
@@ -214,7 +214,7 @@ function generateNode () {
|
||||
rightLabel.horizontalAlign = cc.LabelComponent.HorizontalAlign.RIGHT;
|
||||
rightLabel.font = _atlas;
|
||||
rightLabel.fontSize = _fontSize;
|
||||
rightLabel.lineHeight = _fontSize;
|
||||
rightLabel.lineHeight = _fontSize + 1;
|
||||
}
|
||||
|
||||
_label[stringLeft] = leftLabel;
|
||||
|
||||
@@ -181,9 +181,11 @@ export class UI {
|
||||
|
||||
public addScreen (comp: CanvasComponent) {
|
||||
this._screens.push(comp);
|
||||
|
||||
if (comp.camera) {
|
||||
comp.camera.view.visibility = this._screens.length;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public getScreen (visibility: number) {
|
||||
@@ -274,7 +276,7 @@ export class UI {
|
||||
}
|
||||
}
|
||||
|
||||
public commitComp (comp: UIComponent, frame: GFXTextureView | null, assembler: IAssembler) {
|
||||
public commitComp (comp: UIComponent, frame: GFXTextureView | null = null, assembler?: IAssembler) {
|
||||
if (comp instanceof UIRenderComponent) {
|
||||
const renderComp = comp as UIRenderComponent;
|
||||
const texView = frame;
|
||||
@@ -288,7 +290,9 @@ export class UI {
|
||||
this._currCanvas = renderComp.visibility;
|
||||
}
|
||||
|
||||
assembler.fillBuffers(renderComp, this);
|
||||
if (assembler) {
|
||||
assembler.fillBuffers(renderComp, this);
|
||||
}
|
||||
} else {
|
||||
// if the last comp is spriteComp, previous comps should be batched.
|
||||
if (this._currMaterial !== this._emptyMaterial) {
|
||||
|
||||
Reference in New Issue
Block a user