123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- import i18n from "../i18n/i18n";
- import ViewManage, { AudioMgr, GameViewType } from "./ViewManage";
- import Player, { UserData } from "../game/data/udata/Player";
- import SManage, { RewardData } from "../game/data/sdata/SManage";
- import CHttp, { ReveData } from "../util/CHttp";
- import Profile from "../util/Profile";
- import ViewObject from "./ViewObject";
- import Tips from "../util/Tips";
- import RewardView from "../game/common/RewardView";
- import Home from "../game/home/Home";
- import GuideMask from "../plot/GuideMask";
- import AdminLogin from "../login/AdminLogin";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class Main extends cc.Component {
-
- public viewManage: ViewManage;
-
- @property(cc.Camera)
- mMapCamera: cc.Camera = null;
- @property(cc.Node)
- mLoading: cc.Node = null;
- @property(cc.Prefab)
- mTips: cc.Prefab = null;
- @property(GuideMask)
- mGuideMask: GuideMask = null;
- @property(i18n)
- mI18n: i18n = null;
- @property(cc.SpriteFrame)
- RED_POINT: cc.SpriteFrame = null;
- @property(cc.Node)
- topNode: cc.Node = null;
-
- public home: Home;
-
- public sManage: SManage;
-
- public userData: UserData;
-
- public player: Player;
-
- public profile: Profile = null;
-
- public loginHttp: CHttp;
-
- public gameHttp: CHttp;
- onLoad() {
-
-
-
-
-
-
-
-
- this.viewManage = this.node.getComponent(ViewManage);
- cc.view.resizeWithBrowserSize(true);
- this.resizeView();
- cc.view.setResizeCallback(() => {
- cc.log('view resize callback');
- this.resizeView();
- });
- this.profile = this.node.getComponent(Profile);
- this.loginHttp = new CHttp(this.profile.url);
- }
- start() {
- this.mI18n.__init(() => {
-
- cc.log('语言测试 rabbit:', i18n.t('rabbit'));
- this.toHotUpdate();
- });
- }
- private resizeView() {
- let winsize = cc.winSize;
- let dt = winsize.width / winsize.height;
- if (dt > 1.78) {
- cc.Canvas.instance.fitWidth = false;
- cc.Canvas.instance.fitHeight = true;
- } else {
- cc.Canvas.instance.fitWidth = true;
- cc.Canvas.instance.fitHeight = false;
- }
- cc.log('屏幕尺寸:', winsize.width, winsize.height);
- cc.log('canvas尺寸:', cc.Canvas.instance.node.width, cc.Canvas.instance.node.height);
- cc.log('屏幕比例:', dt);
- }
-
- public get i18n() {
- return i18n;
- }
- public startLoad() {
- this.mLoading.active = true;
- }
- public stopLoad() {
- this.mLoading.active = false;
- }
- public showTips(msg) {
- let node = cc.instantiate(this.mTips);
- let tips = node.getComponent(Tips);
- tips.setLabel(i18n.t(msg))
- let winsize = cc.winSize;
- node.y += winsize.height / 5;
- node.parent = this.node;
- }
- public showTips1(reve: ReveData) {
- let list: Array<RewardData> = this.sManage.getRewards(reve)
- if (list.length <= 0) {
- return
- }
- let str = '<color=#FFFFFF>' + i18n.t('获得道具') + ':</c><color=#0fffff>'
- for (let i = 0; i < list.length; i++) {
- const element = list[i];
- str += element.name + 'x' + element.count + ';'
- }
- str += '</c>'
- this.showTips(str)
- }
-
- public showReward(reve: ReveData, callback?: () => void, title?: string, about?: string) {
- let list = this.sManage.getRewards(reve)
- this.showRewardList(list, callback, title, about)
- }
- public showRewardList(list, callback?: () => void, title?: string, about?: string) {
- if (list.length > 0) {
- this.viewManage.loadFunc(GameViewType.reward, (viewObject: ViewObject) => {
- let rewardView = viewObject as RewardView;
- rewardView.init(list)
- if (title) {
- rewardView.mTitle.string = i18n.t(title)
- }
- if (about) {
- rewardView.mAbout.string = i18n.t(about)
- } else {
- rewardView.mAbout.string = ''
- }
- if (callback) {
- rewardView.setCloseCallback(() => {
- callback()
- })
- }
- viewObject.show();
- this.playerEffectByPath(AudioMgr.award);
- });
- } else {
- if (callback) {
- callback()
- }
- }
- }
-
- public toHotUpdate() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- this.viewManage.loadFunc(GameViewType.login,(viewObject:ViewObject)=>{
- viewObject.show();
- });
-
-
-
-
-
-
-
-
-
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public bgmId: number = -1;
- public effectId: number = -1;
- public effectList: number[] = [];
-
- playMusicByClip(clip: cc.AudioClip) {
- let setting = this.player.setting;
- if (this.bgmId != -1) {
- cc.audioEngine.stopMusic();
- this.bgmId = -1;
- }
- if (setting.music_ON_OFF_1) {
- cc.audioEngine.setMusicVolume(setting.music_Slider_1);
- } else {
- cc.audioEngine.setMusicVolume(0);
- }
- this.bgmId = cc.audioEngine.playMusic(clip, true);
- }
-
- playMusicByPath(path: string) {
- if (path == "") return
- cc.resources.load(path, cc.AudioClip, (err, mp3: cc.AudioClip) => {
- if (err) {
- console.log("===播放背景音乐 err===", err)
- } else {
- this.playMusicByClip(mp3);
- }
- });
- }
-
- playerEffectByClip(clip: cc.AudioClip) {
- let setting = this.player.setting;
- if (setting.music_ON_OFF_2) {
- if (this.effectId != -1) {
- cc.audioEngine.stopEffect(this.effectId);
- this.effectId = -1;
- }
- this.effectId = cc.audioEngine.playEffect(clip, false);
- cc.audioEngine.setEffectsVolume(setting.music_Slider_2);
- }
- }
-
- playerEffectByPath(path: string) {
- if (path == "") return
- let setting = this.player.setting;
- if (setting.music_ON_OFF_2) {
- cc.resources.load(path, cc.AudioClip, (err, mp3: cc.AudioClip) => {
- if (err) {
- console.log("===播放背景音效 err===", err)
- } else {
- this.playerEffectByClip(mp3);
- }
- });
- }
- }
-
- public pauseMusic() {
- let setting = this.player.setting;
- if (!setting.music_ON_OFF_1) {
- if (this.bgmId != -1) {
- cc.audioEngine.pauseMusic();
- }
- }
- }
-
- public resumeMusic() {
- let setting = this.player.setting;
- if (setting.music_ON_OFF_1) {
- if (this.bgmId != -1) {
- cc.audioEngine.resumeMusic();
- cc.audioEngine.setMusicVolume(setting.music_Slider_1);
- }
- }
- }
- public stopAll() {
- this.effectList = [];
- cc.audioEngine.stopAll();
- }
- }
|