b3b4451d-4077-4e86-8252-7ae8b694d4e1.js 13.6 KB
"use strict";
cc._RF.push(module, 'b3b44UdQHdOhoJSeui2lNTh', 'NewNoticeViewPresenter');
// script/game/ui/presenter/notice/NewNoticeViewPresenter.ts

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const simba_config_manager_1 = require("simba-config-manager");
const simba_sdk_1 = require("simba-sdk");
const EditorEnums_1 = require("../../../../avg/EditorEnums");
const PresenterBase_1 = require("../../../../common/classbase/PresenterBase");
const UIManager_1 = require("../../../../common/gameplay/managers/UIManager");
const TaoBaoShopUrlConfig_1 = require("../../../../config/TaoBaoShopUrlConfig");
const GameConfig_1 = require("../../../../GameConfig");
const ActivitiesItemModelManager_1 = require("../../../model/ActivitiesItemModelManager");
const GameModelManager_1 = require("../../../model/GameModelManager");
const HttpRequests_1 = require("../../../network/HttpRequests");
const ActivitiesNoticeItem_1 = require("../../ActivitiesNoticeItem");
const PresenterCCViewFactory_1 = require("../../PresenterCCViewFactory");
const NewNoticeView_1 = require("../../view/type/notice/NewNoticeView");
let NewNoticeViewPresenter = /** @class */ (() => {
    let NewNoticeViewPresenter = class NewNoticeViewPresenter extends PresenterBase_1.Presenter {
        constructor() {
            super();
            this._noticeType = NewNoticeView_1.NoticeType.SystemNotice;
            this._delayTime = 0;
            this._closeTimeTicker = -1;
            this._canClose = false;
            /**
             * 公告按钮的点击事件
             * @param index 系统公告和活动公告的Index
             */
            this.onNoticeButtonClickCallback = (index) => {
                if (this._noticeType !== index) {
                    this._noticeType = index;
                    this.setNoticeState();
                    this.setNoticeContent();
                }
            };
            /**
             * 关闭按钮的点击事件
             */
            this.onCloseButtonClickCalback = () => {
                if (this._canClose) {
                    this.checkTipsToggleState();
                    GameModelManager_1.GameModelManager.setNoticeReaded(true);
                    clearTimeout(this._closeTimeTicker);
                    this.view.close();
                }
            };
            this._viewProps = {
                sourceView: NewNoticeView_1.SourceView.MessageView,
                onNoticeButtonClickCallback: this.onNoticeButtonClickCallback,
                onCloseButtonClickCalback: this.onCloseButtonClickCalback,
            };
        }
        onOpen(source) {
            super.onOpen(source);
            this._viewProps.sourceView = source;
            this.view.setProps(this._viewProps);
            this.onShow();
        }
        onShow() {
            super.onShow();
            this.initView();
        }
        onEnterBackground() {
            super.onEnterBackground();
        }
        onEnterForeground() {
            super.onEnterForeground();
        }
        onClose() {
            super.onClose();
        }
        initView() {
            //重置可关闭状态为false
            this._canClose = false;
            //根据是否是第一次弹起紧急公告判断延迟时间
            //this._delayTime = GameModelManager.getNoticeReaded() ? 0 : 3;
            this._delayTime = 0;
            //重置提示文本状态
            this.view.getCloseTipsLabel().string = "";
            //初始化公告类型
            if (GameConfig_1.channel == "android") {
                this._noticeType = NewNoticeView_1.NoticeType.ActvitiesNotice;
            }
            else {
                this._noticeType = NewNoticeView_1.NoticeType.SystemNotice;
            }
            //根据存档初始化“今日不再提示”的选择框
            let autoShow = GameModelManager_1.GameModelManager.getAutoShowNotice();
            this.view.getTipsToggle().isChecked = !autoShow;
            //初始化公告按钮状态和公告内容
            this.setNoticeState();
            this.setNoticeContent();
            //刷新活动公告按钮的红点状态
            this.refreshActivitiesButtonRedDot();
            //开启关闭倒计时
            this.startTimeTicker();
        }
        /**
         * 设置公告按钮状态和公告内容显隐
         */
        setNoticeState() {
            let nodes = this.view.getNoticeNodes();
            let buttons = this.view.getNoticeButtons();
            switch (this._noticeType) {
                case NewNoticeView_1.NoticeType.SystemNotice: //系统公告
                    nodes[NewNoticeView_1.NoticeType.SystemNotice].active = true;
                    nodes[NewNoticeView_1.NoticeType.ActvitiesNotice].active = false;
                    buttons[NewNoticeView_1.NoticeType.SystemNotice].node.getChildByName("Background").getComponent(cc.Sprite).spriteFrame = this.view.getButtonSpriteFrames()[1];
                    buttons[NewNoticeView_1.NoticeType.ActvitiesNotice].node.getChildByName("Background").getComponent(cc.Sprite).spriteFrame = this.view.getButtonSpriteFrames()[2];
                    break;
                case NewNoticeView_1.NoticeType.ActvitiesNotice: //活动公告
                    nodes[NewNoticeView_1.NoticeType.SystemNotice].active = false;
                    nodes[NewNoticeView_1.NoticeType.ActvitiesNotice].active = true;
                    buttons[NewNoticeView_1.NoticeType.SystemNotice].node.getChildByName("Background").getComponent(cc.Sprite).spriteFrame = this.view.getButtonSpriteFrames()[0];
                    buttons[NewNoticeView_1.NoticeType.ActvitiesNotice].node.getChildByName("Background").getComponent(cc.Sprite).spriteFrame = this.view.getButtonSpriteFrames()[3];
                    break;
                default:
                    break;
            }
        }
        /**
         * 设置公告内容
         */
        async setNoticeContent() {
            switch (this._noticeType) {
                case NewNoticeView_1.NoticeType.SystemNotice: //系统公告
                    HttpRequests_1.HttpRequests.getNewNotice().then((res) => {
                        if (res != null && res.length > 0) {
                            this.view.getContentRichText().string = res[0].msg;
                        }
                        else {
                            this.view.getContentRichText().string = "<color=#FF0000>公告获取失败,请检查网络或稍后重试<color/>";
                        }
                    });
                    break;
                case NewNoticeView_1.NoticeType.ActvitiesNotice: //活动公告
                    this.view.getActivitiesContentNode().removeAllChildren();
                    let configs = ActivitiesItemModelManager_1.ActivitiesItemModelManager.getValidActivitiesConfigs();
                    for (let i = 0; i < configs.length; i++) {
                        if (!configs[i].canClick) {
                            ActivitiesItemModelManager_1.ActivitiesItemModelManager.setActivitiesReaded(configs[i].activityId);
                            this.refreshActivitiesButtonRedDot();
                        }
                        let item = cc.instantiate(this.view.getActivitiesItemPrefab());
                        item.getComponent(ActivitiesNoticeItem_1.default).setData(configs[i].activityId, configs[i].canClick, configs[i].describe, () => {
                            //刷新活动列表和“活动公告”按钮的红点
                            ActivitiesItemModelManager_1.ActivitiesItemModelManager.setActivitiesReaded(configs[i].activityId);
                            item.getComponent(ActivitiesNoticeItem_1.default).refreshRedDot();
                            this.refreshActivitiesButtonRedDot();
                            //执行活动逻辑
                            this.executeActivitiesEvent(configs[i], this._viewProps.sourceView);
                        });
                        item.parent = this.view.getActivitiesContentNode();
                    }
                    break;
                default:
                    break;
            }
        }
        /**
         * 检查“今日不再提示”单选框的选择状态
         */
        checkTipsToggleState() {
            let isChecked = this.view.getTipsToggle().isChecked;
            let autoShow = GameModelManager_1.GameModelManager.getAutoShowNotice();
            if (autoShow !== !isChecked) {
                GameModelManager_1.GameModelManager.setAutoShowNotice(!isChecked);
            }
        }
        /**
         * 刷新“活动公告”按钮的红点状态
         */
        refreshActivitiesButtonRedDot() {
            let buttons = this.view.getNoticeButtons();
            let configs = ActivitiesItemModelManager_1.ActivitiesItemModelManager.getValidActivitiesConfigs();
            for (let i = 0; i < configs.length; i++) {
                let isReaded = ActivitiesItemModelManager_1.ActivitiesItemModelManager.getActivitiesReaded(configs[i].activityId);
                if (!isReaded) {
                    buttons[NewNoticeView_1.NoticeType.ActvitiesNotice].node.getChildByName("RedDot").active = true;
                    return;
                }
                else {
                    buttons[NewNoticeView_1.NoticeType.ActvitiesNotice].node.getChildByName("RedDot").active = false;
                }
            }
        }
        /**
         * 根据活动配置处理活动事件
         * @param config 活动配置
         */
        executeActivitiesEvent(config, source) {
            switch (config.activityTypeConfig.activityType) {
                case EditorEnums_1.ActicityType.JumpToTaoBao:
                    if (GameConfig_1.channel == "wechat") {
                        // GameCenter.getInstance().openSubProgram(GameConfig.youZanShopAppId);
                        if (config.activityTypeConfig.taobaoTempId) {
                            let taobaoConfig = simba_config_manager_1.ConfigManager.getConfig(TaoBaoShopUrlConfig_1.taoBaoShopUrlConfig, config.activityTypeConfig.taobaoTempId);
                            simba_sdk_1.SDK.openProgramV2(GameConfig_1.GameConfig.youZanShopAppId, taobaoConfig.youZanUrl);
                        }
                        else {
                            console.error("The taobaoTempId is undefined.");
                        }
                    }
                    else if (GameConfig_1.channel == "android") {
                        if (config.activityTypeConfig.taobaoTempId) {
                            let taobaoConfig = simba_config_manager_1.ConfigManager.getConfig(TaoBaoShopUrlConfig_1.taoBaoShopUrlConfig, config.activityTypeConfig.taobaoTempId);
                            GameModelManager_1.GameModelManager.jumpToTaobaoShop(taobaoConfig.websiteUrl);
                        }
                        else {
                            console.error("The taobaoTempId is undefined.");
                        }
                    }
                    else {
                        UIManager_1.UIManager.showToast("该功能在当前平台不可使用");
                    }
                    break;
                case EditorEnums_1.ActicityType.PageInGame:
                    let pageIndex = config.activityTypeConfig.pageIndex;
                    if (pageIndex) {
                        this.executePageInGameEvent(pageIndex, source);
                    }
                    else {
                        console.error("The pageIndex is undefined.");
                    }
                    break;
                default:
                    break;
            }
        }
        /**
         * 处理游戏内的活动事件
         * @param activityId 活动ID
         */
        executePageInGameEvent(pageIndex, source) {
            switch (source) {
                case NewNoticeView_1.SourceView.MessageView:
                    this.onCloseButtonClickCalback();
                    GameModelManager_1.GameModelManager.JumpToViewInGame.emit(pageIndex);
                    break;
                case NewNoticeView_1.SourceView.SettingView:
                    this.onCloseButtonClickCalback();
                    GameModelManager_1.GameModelManager.CloseSettingView.emit(pageIndex);
                default:
                    break;
            }
        }
        /**
         * 开启可关闭定时器
         */
        startTimeTicker() {
            if (this._delayTime == 0) {
                this._canClose = true;
                this.view.getCloseTipsLabel().string = "点击空白区域可关闭";
            }
            else {
                this.view.getCloseTipsLabel().string = this._delayTime + "秒后可关闭";
                this._closeTimeTicker = window.setTimeout(() => {
                    this._delayTime -= 1;
                    this.startTimeTicker();
                }, 1000);
            }
        }
    };
    NewNoticeViewPresenter.uuid = "NewNoticeViewPresenter";
    NewNoticeViewPresenter = __decorate([
        PresenterCCViewFactory_1.RegPresenter(NewNoticeView_1.NewNoticeViewType)
    ], NewNoticeViewPresenter);
    return NewNoticeViewPresenter;
})();
exports.default = NewNoticeViewPresenter;

cc._RF.pop();