Commit 07252680 authored by 范雪寒's avatar 范雪寒

feat: 中间层完美适配

parent ba03f80e
...@@ -311,9 +311,6 @@ ...@@ -311,9 +311,6 @@
}, },
{ {
"__id__": 94 "__id__": 94
},
{
"__id__": 95
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -3923,32 +3920,5 @@ ...@@ -3923,32 +3920,5 @@
"_isTrimmedMode": true, "_isTrimmedMode": true,
"_atlas": null, "_atlas": null,
"_id": "77Taml+DhKYLCnxnSi08Bm" "_id": "77Taml+DhKYLCnxnSi08Bm"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 7
},
"_enabled": true,
"alignMode": 1,
"_target": null,
"_alignFlags": 45,
"_left": 0,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_verticalCenter": 0,
"_horizontalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 1280,
"_originalHeight": 720,
"_id": "b8s6BwK6JGdo9khgpExHfg"
} }
] ]
\ No newline at end of file
...@@ -80,7 +80,7 @@ cc.Class({ ...@@ -80,7 +80,7 @@ cc.Class({
start() { start() {
initAir(this); initAir(this);
this.reWriteAir(); this.reWriteAir();
this.updateWidgets(); this.updateScale();
window.courseware.getEngineInfo((dataStr) => { window.courseware.getEngineInfo((dataStr) => {
const engineInfo = JSON.parse(dataStr); const engineInfo = JSON.parse(dataStr);
...@@ -402,7 +402,7 @@ cc.Class({ ...@@ -402,7 +402,7 @@ cc.Class({
window.courseware.freeAllOcMethod(); window.courseware.freeAllOcMethod();
this.hideWaitingLetters(); this.hideWaitingLetters();
this.updateWidgets(); this.updateScale();
callback && callback(); callback && callback();
}); });
}); });
...@@ -425,34 +425,56 @@ cc.Class({ ...@@ -425,34 +425,56 @@ cc.Class({
this.loadBundleByConf(this.bundleInfoList[this.currentBundleIndex]); this.loadBundleByConf(this.bundleInfoList[this.currentBundleIndex]);
}, },
updateWidgets() {
this.updateScale();
this.node.getComponentsInChildren(cc.Widget).forEach((widget) => {
widget.updateAlignment();
});
},
updateScale() { updateScale() {
// const canvas = cc.find("Canvas"); console.log("updateScale");
// const canvasSize = cc.view.getCanvasSize(); const canvas = cc.find("Canvas");
const canvasComponent = canvas.getComponent(cc.Canvas);
const canvasSize = cc.view.getCanvasSize();
const designSize = cc.view.getDesignResolutionSize();
if (canvasComponent.fitHeight && canvasComponent.fitWidth) {
console.log("fit both");
// const designSize = cc.view.getDesignResolutionSize(); const scale = Math.max(
designSize.width / canvasSize.width,
designSize.height / canvasSize.height
);
// const scale = this.node.width = canvasSize.width;
// canvas.width / canvasSize.width / (canvas.height / canvasSize.height); this.node.height = canvasSize.height;
this.node.scale = scale;
// console.log("canvasSize:", canvasSize); const pos = this.node.parent.convertToNodeSpaceAR(
// console.log("designSize:", designSize); canvas.convertToWorldSpaceAR(cc.v2(0, 0))
);
this.node.setPosition(pos);
return;
}
// console.log({ x: canvas.x, y: canvas.y }); if (canvasComponent.fitHeight && !canvasComponent.fitWidth) {
// console.log({ width: canvas.width, height: canvas.height }); console.log("fit height");
// console.log('scale = ' + scale);
// this.node.width = canvas.width; const scale = designSize.height / canvasSize.height;
// this.node.height = canvas.height * scale; this.node.width = canvasSize.width;
this.node.height = canvasSize.height;
this.node.scale = scale;
this.node.x = (this.node.width * scale) / 2;
this.node.y = (this.node.height * scale) / 2;
return;
}
if (!canvasComponent.fitHeight && canvasComponent.fitWidth) {
console.log("fit width");
// this.node.x = this.node.width / 2; const scale = designSize.width / canvasSize.width;
// this.node.y = this.node.height / 2 - 120; this.node.width = canvasSize.width;
this.node.height = canvasSize.height;
this.node.scale = scale;
this.node.x = (this.node.width * scale) / 2;
this.node.y = (this.node.height * scale) / 2;
return;
}
}, },
exit() { exit() {
......
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