Commit 1f78adb8 authored by Chen Jiping's avatar Chen Jiping

fix:修复各种问题

parent 1c024b1d
......@@ -5,7 +5,8 @@ import {
tweenChange,
ShapeRect,
Lable2,
LableText
LableText,
setFontSize
} from './Unit';
import {
......@@ -96,7 +97,7 @@ export class Exercises {
this.cardBg = cardBg;
const bigCard1 = new ShapeRectNew();
bigCard1.setOutLine(outLineColor, 25 * scaleY);
bigCard1.setOutLine(outLineColor, 20 * scaleY);
bigCard1.setSize(width, height, 25 * scaleY);
bigCard1.x = -width / 2;
bigCard1.y = -height / 2;
......@@ -185,7 +186,7 @@ export class Exercises {
fontColor = "#cc2a2e";
}
maxWidth = bg.width - 110 * (this.scaleX > 1 ? 1 : this.scaleX);
maxWidth = 487 * this.scaleX;
}
else {
......@@ -196,7 +197,7 @@ export class Exercises {
fontColor = "#cc2a2e";
}
maxWidth = bg.width - 190 * (this.scaleX > 1 ? 1 : this.scaleX);
maxWidth = 420 * this.scaleX;
}
labelText.fontColor = fontColor;
......@@ -209,8 +210,8 @@ export class Exercises {
text.y = bg.height / 2;
bg.addChild(text);
console.log('bg.width', bg.width, 'maxWidth', maxWidth, 'scaleX', this.scaleX);
text.setMaxSize(maxWidth);
setFontSize(maxWidth, text);
text.refreshSize();
totalWidth = text.getBoundingBox().width;
this.textLabel = text;
......@@ -436,7 +437,7 @@ export class Exercises {
textArr.push(labelText);
}
text.setScaleXY(this.scaleX);
text.setMaxSize((960 - 90) * this.scaleX);
text.setMaxSize(800 * this.scaleX);
text.refreshSize();
text.y = bg.height - text.getBoundingBox().height / 2 - 17 * this.scaleY;
let totalWidth = text.getBoundingBox().width;
......@@ -484,8 +485,8 @@ export class Exercises {
private getColsePic(parent) {
const closePic = new MySprite();
closePic.init(this.images.get('close'));
closePic.scaleX = parent.scaleX;
closePic.scaleY = parent.scaleY;
closePic.scaleX = this.scaleX;
closePic.scaleY = this.scaleY;
closePic.x = parent.width - 5 * this.scaleX;
......@@ -498,12 +499,12 @@ export class Exercises {
private getOverturnPic(parent) {
const overturnPic = new MySprite();
overturnPic.init(this.images.get('overturn'));
overturnPic.scaleX = parent.scaleX;
overturnPic.scaleY = parent.scaleY;
overturnPic.scaleX = this.scaleX;
overturnPic.scaleY = this.scaleY;
overturnPic.x = parent.width - 28 * parent.scaleX - overturnPic.getBoundingBox().width / 2;
overturnPic.x = parent.width - 18 * this.scaleX - overturnPic.getBoundingBox().width / 2;
overturnPic.y = parent.height - 15 * parent.scaleY - overturnPic.getBoundingBox().height / 2;
overturnPic.y = parent.height - 15 * this.scaleY - overturnPic.getBoundingBox().height / 2;
parent.addChild(overturnPic);
return overturnPic;
......@@ -625,13 +626,12 @@ export class Exercises {
}
resetText(scale, skin = 'A') {
resetText(fontSize, skin = 'A') {
var totalWidth = 0
this.textLabel.setScaleXY(1);
this.textLabel.setScaleXY(scale);
this.textLabel.fontSize = fontSize;
this.textLabel.refreshSize();
totalWidth = this.textLabel.getBoundingBox().width;
this.resetX(this.textLabel, totalWidth, skin);
......
......@@ -547,10 +547,7 @@ export class Label extends MySprite {
this._maxWidth = w;
this.refreshSize();
if (this.width >= w) {
this.scaleX *= w / this.width;
this.scaleY *= w / this.width;
}
setFontSize(this._maxWidth, this);
}
show(callBack = null) {
......@@ -727,10 +724,7 @@ export class Lable2 extends MySprite{
this._maxWidth = w;
this.refreshSize();
if (this.width >= w) {
this.scaleX *= w / this.width;
this.scaleY *= w / this.width;
}
setFontSize(w, this);
}
show(callBack = null) {
......@@ -1877,3 +1871,50 @@ export function shake(item, time = 0.5, callback = null, rate = 1) {
// --------------- custom class --------------------
/**
* 根据父级组件大小设置字体大小
* @param parWidth
* @param label
*/
export function setFontSize(maxWidth : number, label){
if(!label){
return;
}
label.refreshSize();
let w = label.getBoundingBox().width;
//如果宽度超过,则缩小字体
if(w > maxWidth){
shrinkFont(maxWidth, label);
}
}
export function shrinkFont(maxWidth : number, label){
if(!label){
return;
}
label.refreshSize();
let w = label.getBoundingBox().width;
//如果宽度超过,则缩小字体
if(w > maxWidth){
let fontSize = label.fontSize;
fontSize = fontSize - 1;
label.fontSize = fontSize;
label.refreshSize();
shrinkFont(maxWidth, label);
}
}
\ No newline at end of file
......@@ -611,8 +611,8 @@ export class PlayComponent implements OnInit, OnDestroy {
const s = Math.min(sx, sy);
this.mapScale = s;
this.mapScaleX = sx;
this.mapScaleY = sy;
this.mapScaleX = s;
this.mapScaleY = s;
this.renderArr = [];
......@@ -752,13 +752,19 @@ export class PlayComponent implements OnInit, OnDestroy {
let startX = 81 * this.mapScaleX;
let startY = 157 * this.mapScaleY;
let tempStartY = startY;
let midLen = this.data.exercisesArr.length / 2;
let lBgArr = [];
//如果是A皮肤,则增加长的背景信息
if (this.data.skin === 'A') {
startX = (this.canvasWidth - 1100 * this.mapScale) / 2;
let height = 3 * 80 * this.mapScale + (3-1) * 61 * this.mapScale;
startY = (this.canvasHeight - height) / 2;
for (let i = 0; i < 3; ++i) {
const lBg = new ShapeRectNew();
lBg.fillColor = "#E5E3E4";
......@@ -766,8 +772,20 @@ export class PlayComponent implements OnInit, OnDestroy {
lBg.setSize(1100 * this.mapScale, 80 * this.mapScale, 40 * this.mapScale);
this.skinRenderArr.push(lBg);
lBgArr.push(lBg);
}
}
}
else{
let width = 2 * 560 * this.mapScale + 25 * this.mapScaleX;
startX = (this.canvasWidth - width) / 2;
let height = 3 * 96 * this.mapScale + (3-1) * 78 * this.mapScale;
startY = (this.canvasHeight - height) / 2;
}
let tempStartY = startY;
let startYArr = [];
......@@ -811,7 +829,7 @@ export class PlayComponent implements OnInit, OnDestroy {
}
else {
if (this.data.skin === 'A') {
startY = startY + exercises.bg.height + 65 * this.mapScaleY;
startY = startY + exercises.bg.height + 61 * this.mapScaleY;
}
else {
startY = startY + exercises.bg.height + 78 * this.mapScaleY;
......@@ -830,24 +848,22 @@ export class PlayComponent implements OnInit, OnDestroy {
lBgArr[i].height = hight ;
}
let minScale = 1;
let minFontSize = 100;
//获取最小字体
for (let i = 0; i < this.exercisesArr.length; ++i) {
let textLabel = this.exercisesArr[i].textLabel;
if (minScale > textLabel.scaleX) {
minScale = textLabel.scaleX;
if (minFontSize > textLabel.fontSize) {
minFontSize = textLabel.fontSize;
}
}
console.log(minScale);
for (let i = 0; i < this.exercisesArr.length; ++i) {
this.exercisesArr[i].resetText(minScale, this.data.skin);
this.exercisesArr[i].resetText(minFontSize, this.data.skin);
}
const mask = new ShapeRect();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment