WardrobeViewPresenter.ts 10.3 KB
import { ResUtils } from "simba-cc-resutils";
import { Presenter } from "../../../../common/classbase/PresenterBase";
import { GameConstData } from "../../../../common/gameplay/gamedata/GameConstData";
import { UIManager } from "../../../../common/gameplay/managers/UIManager";
import { channel } from "../../../../GameConfig";
import { BedRoomCatModelManager, SuitStatus } from "../../../model/BedRoomCatModelManager";
import { GameModelManager } from "../../../model/GameModelManager";
import { RegPresenter } from "../../PresenterCCViewFactory";
import SuitItem from "../../SuitItem";
import { AlertDialogViewProps } from "../../view/type/AlertDialogView";
import { WardrobeViewType, WardrobeViewProps, WardrobeView } from "../../view/type/WardrobeView";
import AlertDialogViewPresenter from "../AlertDialogViewPresenter";

@RegPresenter(WardrobeViewType)
export default class WardrobeViewPresenter extends Presenter<WardrobeViewProps, WardrobeView>{
    static uuid = "WardrobeViewPresenter";
    private _viewProps: WardrobeViewProps;
    private _suitId = 0;
    private _nextStep = -1;
    private _wardrobeIntroductionString = "通过完成任务,收集碎片,收集完所有碎片就可以解锁梵优的新衣服啦!";

    constructor() {
        super();
    }

    onOpen(props: WardrobeViewProps) {
        super.onOpen(props);
        this._viewProps = props;
        this._viewProps.onWearBtnClickCallBack = this.onWearBtnClickCallBack;
        this._viewProps.onShareBtnClickCallBack = this.onShareBtnClickCallBack;
        this._viewProps.onTabBtnClickCallBack = this.onTabBtnClickCallBack;
        this._viewProps.onBackBtnClickCallBack = this.onBackBtnClickCallBack;
        this.view.setProps(this._viewProps);
        this.onShow();
    }

    onShow() {
        super.onShow();
        this.setIntroductionIconTouchEvent();
        this.onTabBtnClickCallBack(1);
    }

    onClose() {
        super.onClose();
    }

    onEnterBackground() {
        super.onEnterBackground();
    }

    onEnterForeground() {
        super.onEnterForeground();
    }

    setIntroductionIconTouchEvent() {
        let introductionIconNode = this.view.getIntroductionIconNode();
        let introductionNode = this.view.getIntroductionNode();
        introductionIconNode.on(cc.Node.EventType.TOUCH_START, function (event) {
            introductionNode.active = true;
        }, this);
        introductionIconNode.on(cc.Node.EventType.TOUCH_END, function (event) {
            introductionNode.active = false;
        }, this);
        introductionIconNode.on(cc.Node.EventType.TOUCH_CANCEL, function (event) {
            introductionNode.active = false;
        }, this);
    }

    updateRedDot() {
        for (let i = 1; i < 4; i++) {
            let suitStatus = BedRoomCatModelManager.checkSuitStatus(i);
            let suitIsClicked = BedRoomCatModelManager.getSuitIsClicked(i);
            if (suitStatus !== SuitStatus.Lock && !suitIsClicked) {
                this.view.getRedDotNodes()[i - 1].active = true;
            } else {
                this.view.getRedDotNodes()[i - 1].active = false;
            }
        }
    }

    async checkWearBtnStatus(suitId: number) {
        let suitStatus = BedRoomCatModelManager.checkSuitStatus(suitId);
        if (suitStatus !== SuitStatus.Lock) {
            BedRoomCatModelManager.saveSuitIsClicked(suitId);
        }
        switch (suitStatus) {
            case SuitStatus.Lock:
                this.view.getWearBtn().node.active = false;
                this.view.getRolePortrait().node.active = false;
                this.view.getRolePortraitLock().node.active = true;
                this.view.getRolePortraitLockLabel().string = "收集完所有碎片才可解锁哦";
                this.view.getRolePortrait().spriteFrame = undefined as unknown as cc.SpriteFrame;
                this.view.getRolePortraitLock().spriteFrame = await ResUtils.loadRes(GameConstData.GAME_CONST_BEDROOMCAT_SUIT_SPR_DIR + suitId + "lock", cc.SpriteFrame);
                break;
            case SuitStatus.Unlock:
                this.view.getWearBtn().node.active = true;
                this.view.getWearBtn().interactable = true;
                this.view.getRolePortrait().node.active = true;
                this.view.getRolePortraitLock().node.active = false;
                this.view.getRolePortrait().spriteFrame = await ResUtils.loadRes(GameConstData.GAME_CONST_BEDROOMCAT_SUIT_SPR_DIR + suitId, cc.SpriteFrame);
                this.view.getRolePortraitLock().spriteFrame = undefined as unknown as cc.SpriteFrame;
                this.view.getWearBtn().getComponentInChildren(cc.Sprite).spriteFrame = await ResUtils.loadRes(GameConstData.GAME_CONST_BEDROOMCAT_SPR_DIR + "wearBtn", cc.SpriteFrame);
                break;
            case SuitStatus.Wear:
                this.view.getWearBtn().node.active = true;
                this.view.getWearBtn().interactable = false;
                this.view.getRolePortrait().node.active = true;
                this.view.getRolePortraitLock().node.active = false;
                this.view.getRolePortrait().spriteFrame = await ResUtils.loadRes(GameConstData.GAME_CONST_BEDROOMCAT_SUIT_SPR_DIR + suitId, cc.SpriteFrame);
                this.view.getRolePortraitLock().spriteFrame = undefined as unknown as cc.SpriteFrame;
                this.view.getWearBtn().getComponentInChildren(cc.Sprite).spriteFrame = await ResUtils.loadRes(GameConstData.GAME_CONST_BEDROOMCAT_SPR_DIR + "wearedBtn", cc.SpriteFrame);
                break;
            default:
                break;
        }
    }

    checkShareBtnStatus(suitId: number) {
        let isShow = BedRoomCatModelManager.checkIsShowSuitShareBtnBySuitId(suitId);
        this.view.getShareBtn().node.active = isShow;
    }

    onWearBtnClickCallBack = () => {
        BedRoomCatModelManager.changeUsingSuitId(this._suitId);
        this.checkWearBtnStatus(this._suitId);
        UIManager.showSceneToast("已穿戴当前套装,约会人物立绘将替换为当前套装!", 0.5);
        let isShow = BedRoomCatModelManager.checkIsShowSuitShareBtnBySuitId(this._suitId);
        if (isShow) {
            this.onShareBtnClickCallBack();
        }
    }

    onShareBtnClickCallBack = () => {
        let temp: AlertDialogViewProps = {
            dataptr: { bgPath: GameConstData.GAME_CONST_BEDROOMCAT_SPR_DIR + "wardrobeBg", rolePath: GameConstData.GAME_CONST_BEDROOMCAT_SUIT_SPR_DIR + this._suitId },
            titlecontent: "提示",
            content: "小主穿戴了服装,快去分享给小伙伴吧,分享可得4个猫粮哦~",
            ishasad: false,
            istwobtn: true,
            adconfig: "default",
            hasBanner: false,
            callback: (type, ret) => {
                if (ret || channel === "dummy") {
                    //保存分享存档
                    BedRoomCatModelManager.saveSuitShareStatusBySuitId(this._suitId);
                    this.checkShareBtnStatus(this._suitId)
                    //分享奖励
                    BedRoomCatModelManager.addCatFoodNumberByFoodId(1, 4)
                    UIManager.showSceneToast("猫粮数量+4");
                }
            },
            isShareScreen: true
        };
        UIManager.pushPresenter(AlertDialogViewPresenter, temp);
    }

    onTabBtnClickCallBack = async (suitId: number) => {
        this._suitId = suitId;
        this.view.getStayTunedNode().active = false;
        this.view.getScrollViewContentNode().removeAllChildren();
        let suitButtons = this.view.getSuitButtons();
        for (let i = 0; i < suitButtons.length; i++) {
            if (i == suitId - 1) {
                suitButtons[i].normalSprite = this.view.getSuitButtonSprites()[1];
            } else {
                suitButtons[i].normalSprite = this.view.getSuitButtonSprites()[0];
            }
        }
        for (let i = 0; i < suitButtons.length; i++) {
            if (i == suitId - 1) {
                suitButtons[i].getComponentInChildren(cc.Sprite).spriteFrame = await ResUtils.loadRes(GameConstData.GAME_CONST_BEDROOMCAT_SPR_DIR + "tabBtn", cc.SpriteFrame);
            } else {
                suitButtons[i].getComponentInChildren(cc.Sprite).spriteFrame = await ResUtils.loadRes(GameConstData.GAME_CONST_BEDROOMCAT_SPR_DIR + "tabBtnGray", cc.SpriteFrame);
            }
        }
        //套装3为未开发套装,暂时特殊处理
        if (suitId == 3) {
            this.view.getStayTunedNode().active = true;
            this.view.getWearBtn().node.active = false;
            this.view.getShareBtn().node.active = false;
            this.view.getRolePortrait().node.active = false;
            this.view.getRolePortraitLock().node.active = true;
            this.view.getRolePortraitLockLabel().string = "敬请期待";
            this.view.getRolePortrait().spriteFrame = undefined as unknown as cc.SpriteFrame;
            this.view.getRolePortraitLock().spriteFrame = await ResUtils.loadRes(GameConstData.GAME_CONST_BEDROOMCAT_SUIT_SPR_DIR + "3lock", cc.SpriteFrame);
            return;
        }
        //套装1居中适配,在前后各加一个空的预制体
        if (suitId == 1) {
            let item = cc.instantiate(this.view.getSuitItemNull());
            item.parent = this.view.getScrollViewContentNode();
        }
        let suitConfigs = BedRoomCatModelManager.getSuitConfigBySuitId(suitId);
        for (let i = 0; i < suitConfigs.length; i++) {
            let item = cc.instantiate(this.view.getSuitItem());
            if (suitConfigs[i].isUnlock) {
                BedRoomCatModelManager.saveUnlockClothingBySuitId(suitConfigs[i].suitId, suitConfigs[i].clothingId);
            }
            let unlockClothing = BedRoomCatModelManager.getUnlockClothingBySuitId(suitId);
            let showLockRootNode = unlockClothing.indexOf(suitConfigs[i].clothingId) == -1;
            item.getComponent(SuitItem).setData(suitConfigs[i], showLockRootNode);
            item.parent = this.view.getScrollViewContentNode();
        }
        //套装1居中适配,在前后各加一个空的预制体
        if (suitId == 1) {
            let item = cc.instantiate(this.view.getSuitItemNull());
            item.parent = this.view.getScrollViewContentNode();
        }
        this.checkWearBtnStatus(suitId);
        this.checkShareBtnStatus(suitId);
        this.updateRedDot();
    }

    onBackBtnClickCallBack = () => {
        this.view.close();
    }
}