WardrobeViewFix.ts 1.9 KB
import { DummyNode } from "../../common/CCDummyObjects";

const { ccclass, property } = cc._decorator;

@ccclass
export default class WardrobeViewFix extends cc.Component {
    
    @property({ type: cc.Node, displayName: "Title node" })
    titleNode: cc.Node = DummyNode;
    @property({ type: cc.Node, displayName: "Wardrobe root node" })
    wardrobeRootNode: cc.Node = DummyNode;
    @property({ type: cc.Node, displayName: "Suit tab root node" })
    suitTabRootNode: cc.Node = DummyNode;
    @property({ type: cc.Node, displayName: "Introduction node" })
    introductionNode: cc.Node = DummyNode;

    onLoad() {
        //界面设计尺寸为720*1080
        let originalWigth = 720;
        let originalHeight = 1080;
        let originalProportion = originalHeight / originalWigth;
        let actualWidth = cc.winSize.width;
        let actualHeight = cc.winSize.height;
        let actualProportion = actualHeight / actualWidth;
        let titleNodeWidget = this.titleNode.getComponent(cc.Widget);
        let suitTabRootNodeWidget = this.suitTabRootNode.getComponent(cc.Widget);
        let introductionNodeWidget = this.introductionNode.getComponent(cc.Widget);
        if (actualProportion >= 1.9) {
            titleNodeWidget.verticalCenter = 590;
            titleNodeWidget.updateAlignment();
            suitTabRootNodeWidget.verticalCenter = -600;
            suitTabRootNodeWidget.updateAlignment();
            introductionNodeWidget.top = 200;
            introductionNodeWidget.updateAlignment();
        }
        if (actualProportion <= 1.5) {
            titleNodeWidget.verticalCenter = 370;
            titleNodeWidget.updateAlignment();
            suitTabRootNodeWidget.verticalCenter = -390;
            suitTabRootNodeWidget.updateAlignment();
            introductionNodeWidget.top = 100;
            introductionNodeWidget.updateAlignment();
            this.wardrobeRootNode.scale = 0.7;
        }
    }
}