Commit 10ae6f6e authored by 李维's avatar 李维

Bug fix

parent c58b3a1c
...@@ -208,9 +208,9 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -208,9 +208,9 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this.refresh(); this.refresh();
/* Remove this when commit */ /* Remove this when commit */
// if(location.href.indexOf("localhost") != -1) { if(location.href.indexOf("localhost") != -1) {
// (<any> window).axios.post(`http://www.datalist.com.cn:8060/json/save/${this.KEY}`, this.item) (<any> window).axios.post(`http://www.datalist.com.cn:8060/json/save/${this.KEY}`, this.item)
// } }
/* Remove this when commit */ /* Remove this when commit */
console.log("保存", this.item) console.log("保存", this.item)
......
...@@ -275,8 +275,10 @@ export default class Cartoon { ...@@ -275,8 +275,10 @@ export default class Cartoon {
// console.log(`Get remote image from [${url}]`) // console.log(`Get remote image from [${url}]`)
return new Promise((resovle, reject) => { return new Promise((resovle, reject) => {
this.getSpriteFrimeByUrl(url).then((fr)=>{ this.getSpriteFrimeByUrl(url).then((fr)=>{
let sx = width / fr.getRect().width; let relWidth = fr.getRect().width;
let sy = height / fr.getRect().height; let relHeight = fr.getRect().height;
let sx = width / relWidth;
let sy = height / relHeight;
let s = 1; let s = 1;
if(fillType) { if(fillType) {
s = Math.max(sx, sy) s = Math.max(sx, sy)
...@@ -287,15 +289,20 @@ export default class Cartoon { ...@@ -287,15 +289,20 @@ export default class Cartoon {
// fr.width = s * fr.getRect().width; // fr.width = s * fr.getRect().width;
// fr.height = s * fr.getRect().height; // fr.height = s * fr.getRect().height;
node.getComponent(cc.Sprite).spriteFrame = fr; node.getComponent(cc.Sprite).spriteFrame = fr;
resovle() resovle([relWidth, relHeight])
}) })
}) })
} }
mountLocalImageToNode(name, node, width, height, fillType) { mountLocalImageToNode(name, node, width, height, fillType) {
// console.log(`Get local image from [Canvas/res/img/${name}]`) // console.log(`Get local image from [Canvas/res/img/${name}]`)
let relWidth = null;
let relHeight = null;
if(name) { if(name) {
const sf = cc.find('Canvas/res/img/' + name).getComponent(cc.Sprite).spriteFrame; const sf = cc.find('Canvas/res/img/' + name).getComponent(cc.Sprite).spriteFrame;
relWidth = fr.getRect().width;
relHeight = fr.getRect().height;
let sx = width / sf.getRect().width; let sx = width / sf.getRect().width;
let sy = height / sf.getRect().height; let sy = height / sf.getRect().height;
let s = 1; let s = 1;
...@@ -307,7 +314,10 @@ export default class Cartoon { ...@@ -307,7 +314,10 @@ export default class Cartoon {
node.setScale(s) node.setScale(s)
node.getComponent(cc.Sprite).spriteFrame = sf; node.getComponent(cc.Sprite).spriteFrame = sf;
} }
return node;
return new Promise((resolve, reject) => {
resovle([relWidth, relHeight])
});
} }
mountImageToNode(url, node, width, height, fillType) { mountImageToNode(url, node, width, height, fillType) {
...@@ -315,10 +325,7 @@ export default class Cartoon { ...@@ -315,10 +325,7 @@ export default class Cartoon {
if(urlreg.test(url)) { if(urlreg.test(url)) {
return this.mountRemoteImageToNode(url, node, width, height, fillType) return this.mountRemoteImageToNode(url, node, width, height, fillType)
} else { } else {
this.mountLocalImageToNode(url, node, width, height, fillType) return this.mountLocalImageToNode(url, node, width, height, fillType)
return new Promise((resolve, reject)=>{
resolve()
})
} }
} }
......
...@@ -469,7 +469,15 @@ export default class GameLogic { ...@@ -469,7 +469,15 @@ export default class GameLogic {
if(item.type == 'Image') { if(item.type == 'Image') {
let image = bubble.node.getChildByName("image_container") let image = bubble.node.getChildByName("image_container")
image.active = true; image.active = true;
this.g_cartoon.mountImageToNode(item.image_url, image, 160, 80) this.g_cartoon.mountImageToNode(item.image_url, image, 160, 80).then(([width, height]) => {
let s = width / height
let r = 165
let h = Math.floor(Math.sqrt(r*r / (s*s + 1)))
let w = s * h
image.scaleX = w / width;
image.scaleY = h / height;
})
} else { } else {
let text = bubble.node.getChildByName("text_container") let text = bubble.node.getChildByName("text_container")
text.active = true; text.active = true;
......
...@@ -110,15 +110,14 @@ cc.Class({ ...@@ -110,15 +110,14 @@ cc.Class({
}, },
getData(cb) { getData(cb) {
cb(this.getDefaultData()); // cb(this.getDefaultData());
// cc.loader.load( "http://www.datalist.com.cn:8060/json/DataKey_dfzx_ppp", function( err, res) { cc.loader.load( "http://www.datalist.com.cn:8060/json/DataKey_dfzx_ppp", function( err, res) {
// console.log(res) if(err) {
// if(err) { cb(this.getDefaultData());
// cb(this.getDefaultData()); } else {
// } else { cb(JSON.parse(res));
// cb(JSON.parse(res)); }
// } });
// });
}, },
getDefaultData() { getDefaultData() {
......
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