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

fix:修复各种问题

parent 1c024b1d
...@@ -5,7 +5,8 @@ import { ...@@ -5,7 +5,8 @@ import {
tweenChange, tweenChange,
ShapeRect, ShapeRect,
Lable2, Lable2,
LableText LableText,
setFontSize
} from './Unit'; } from './Unit';
import { import {
...@@ -96,7 +97,7 @@ export class Exercises { ...@@ -96,7 +97,7 @@ export class Exercises {
this.cardBg = cardBg; this.cardBg = cardBg;
const bigCard1 = new ShapeRectNew(); const bigCard1 = new ShapeRectNew();
bigCard1.setOutLine(outLineColor, 25 * scaleY); bigCard1.setOutLine(outLineColor, 20 * scaleY);
bigCard1.setSize(width, height, 25 * scaleY); bigCard1.setSize(width, height, 25 * scaleY);
bigCard1.x = -width / 2; bigCard1.x = -width / 2;
bigCard1.y = -height / 2; bigCard1.y = -height / 2;
...@@ -185,7 +186,7 @@ export class Exercises { ...@@ -185,7 +186,7 @@ export class Exercises {
fontColor = "#cc2a2e"; fontColor = "#cc2a2e";
} }
maxWidth = bg.width - 110 * (this.scaleX > 1 ? 1 : this.scaleX); maxWidth = 487 * this.scaleX;
} }
else { else {
...@@ -196,7 +197,7 @@ export class Exercises { ...@@ -196,7 +197,7 @@ export class Exercises {
fontColor = "#cc2a2e"; fontColor = "#cc2a2e";
} }
maxWidth = bg.width - 190 * (this.scaleX > 1 ? 1 : this.scaleX); maxWidth = 420 * this.scaleX;
} }
labelText.fontColor = fontColor; labelText.fontColor = fontColor;
...@@ -209,8 +210,8 @@ export class Exercises { ...@@ -209,8 +210,8 @@ export class Exercises {
text.y = bg.height / 2; text.y = bg.height / 2;
bg.addChild(text); bg.addChild(text);
console.log('bg.width', bg.width, 'maxWidth', maxWidth, 'scaleX', this.scaleX);
text.setMaxSize(maxWidth); setFontSize(maxWidth, text);
text.refreshSize(); text.refreshSize();
totalWidth = text.getBoundingBox().width; totalWidth = text.getBoundingBox().width;
this.textLabel = text; this.textLabel = text;
...@@ -436,7 +437,7 @@ export class Exercises { ...@@ -436,7 +437,7 @@ export class Exercises {
textArr.push(labelText); textArr.push(labelText);
} }
text.setScaleXY(this.scaleX); text.setScaleXY(this.scaleX);
text.setMaxSize((960 - 90) * this.scaleX); text.setMaxSize(800 * this.scaleX);
text.refreshSize(); text.refreshSize();
text.y = bg.height - text.getBoundingBox().height / 2 - 17 * this.scaleY; text.y = bg.height - text.getBoundingBox().height / 2 - 17 * this.scaleY;
let totalWidth = text.getBoundingBox().width; let totalWidth = text.getBoundingBox().width;
...@@ -484,8 +485,8 @@ export class Exercises { ...@@ -484,8 +485,8 @@ export class Exercises {
private getColsePic(parent) { private getColsePic(parent) {
const closePic = new MySprite(); const closePic = new MySprite();
closePic.init(this.images.get('close')); closePic.init(this.images.get('close'));
closePic.scaleX = parent.scaleX; closePic.scaleX = this.scaleX;
closePic.scaleY = parent.scaleY; closePic.scaleY = this.scaleY;
closePic.x = parent.width - 5 * this.scaleX; closePic.x = parent.width - 5 * this.scaleX;
...@@ -498,12 +499,12 @@ export class Exercises { ...@@ -498,12 +499,12 @@ export class Exercises {
private getOverturnPic(parent) { private getOverturnPic(parent) {
const overturnPic = new MySprite(); const overturnPic = new MySprite();
overturnPic.init(this.images.get('overturn')); overturnPic.init(this.images.get('overturn'));
overturnPic.scaleX = parent.scaleX; overturnPic.scaleX = this.scaleX;
overturnPic.scaleY = parent.scaleY; 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); parent.addChild(overturnPic);
return overturnPic; return overturnPic;
...@@ -625,13 +626,12 @@ export class Exercises { ...@@ -625,13 +626,12 @@ export class Exercises {
} }
resetText(scale, skin = 'A') { resetText(fontSize, skin = 'A') {
var totalWidth = 0 var totalWidth = 0
this.textLabel.setScaleXY(1);
this.textLabel.setScaleXY(scale); this.textLabel.fontSize = fontSize;
this.textLabel.refreshSize(); this.textLabel.refreshSize();
totalWidth = this.textLabel.getBoundingBox().width; totalWidth = this.textLabel.getBoundingBox().width;
this.resetX(this.textLabel, totalWidth, skin); this.resetX(this.textLabel, totalWidth, skin);
......
...@@ -547,10 +547,7 @@ export class Label extends MySprite { ...@@ -547,10 +547,7 @@ export class Label extends MySprite {
this._maxWidth = w; this._maxWidth = w;
this.refreshSize(); this.refreshSize();
if (this.width >= w) { setFontSize(this._maxWidth, this);
this.scaleX *= w / this.width;
this.scaleY *= w / this.width;
}
} }
show(callBack = null) { show(callBack = null) {
...@@ -727,10 +724,7 @@ export class Lable2 extends MySprite{ ...@@ -727,10 +724,7 @@ export class Lable2 extends MySprite{
this._maxWidth = w; this._maxWidth = w;
this.refreshSize(); this.refreshSize();
if (this.width >= w) { setFontSize(w, this);
this.scaleX *= w / this.width;
this.scaleY *= w / this.width;
}
} }
show(callBack = null) { show(callBack = null) {
...@@ -1877,3 +1871,50 @@ export function shake(item, time = 0.5, callback = null, rate = 1) { ...@@ -1877,3 +1871,50 @@ export function shake(item, time = 0.5, callback = null, rate = 1) {
// --------------- custom class -------------------- // --------------- 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 { ...@@ -611,8 +611,8 @@ export class PlayComponent implements OnInit, OnDestroy {
const s = Math.min(sx, sy); const s = Math.min(sx, sy);
this.mapScale = s; this.mapScale = s;
this.mapScaleX = sx; this.mapScaleX = s;
this.mapScaleY = sy; this.mapScaleY = s;
this.renderArr = []; this.renderArr = [];
...@@ -752,13 +752,19 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -752,13 +752,19 @@ export class PlayComponent implements OnInit, OnDestroy {
let startX = 81 * this.mapScaleX; let startX = 81 * this.mapScaleX;
let startY = 157 * this.mapScaleY; let startY = 157 * this.mapScaleY;
let tempStartY = startY;
let midLen = this.data.exercisesArr.length / 2;
let lBgArr = []; let lBgArr = [];
//如果是A皮肤,则增加长的背景信息 //如果是A皮肤,则增加长的背景信息
if (this.data.skin === '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) { for (let i = 0; i < 3; ++i) {
const lBg = new ShapeRectNew(); const lBg = new ShapeRectNew();
lBg.fillColor = "#E5E3E4"; lBg.fillColor = "#E5E3E4";
...@@ -766,8 +772,20 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -766,8 +772,20 @@ export class PlayComponent implements OnInit, OnDestroy {
lBg.setSize(1100 * this.mapScale, 80 * this.mapScale, 40 * this.mapScale); lBg.setSize(1100 * this.mapScale, 80 * this.mapScale, 40 * this.mapScale);
this.skinRenderArr.push(lBg); this.skinRenderArr.push(lBg);
lBgArr.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 = []; let startYArr = [];
...@@ -811,7 +829,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -811,7 +829,7 @@ export class PlayComponent implements OnInit, OnDestroy {
} }
else { else {
if (this.data.skin === 'A') { if (this.data.skin === 'A') {
startY = startY + exercises.bg.height + 65 * this.mapScaleY; startY = startY + exercises.bg.height + 61 * this.mapScaleY;
} }
else { else {
startY = startY + exercises.bg.height + 78 * this.mapScaleY; startY = startY + exercises.bg.height + 78 * this.mapScaleY;
...@@ -830,24 +848,22 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -830,24 +848,22 @@ export class PlayComponent implements OnInit, OnDestroy {
lBgArr[i].height = hight ; lBgArr[i].height = hight ;
} }
let minScale = 1; let minFontSize = 100;
//获取最小字体 //获取最小字体
for (let i = 0; i < this.exercisesArr.length; ++i) { for (let i = 0; i < this.exercisesArr.length; ++i) {
let textLabel = this.exercisesArr[i].textLabel; let textLabel = this.exercisesArr[i].textLabel;
if (minScale > textLabel.scaleX) { if (minFontSize > textLabel.fontSize) {
minScale = textLabel.scaleX; minFontSize = textLabel.fontSize;
} }
} }
console.log(minScale);
for (let i = 0; i < this.exercisesArr.length; ++i) { 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(); 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