wujia 6 months ago
parent
commit
9824d6fc14

+ 13 - 7
assets/script/framework/config/LayerConf.ts

@@ -3,14 +3,17 @@ import { LayerConf, LayerType } from "../layer/LayerManager";
 export enum ViewID {
     MainUI = 0,
 
-    Restart,                    //重新开始
-    MaskUI,                  //蒙板 
-    TempTipsUI,                 //提示
-    ServerList,                 //服务器列表
-    GameWind,                 // 子游戏窗口
+    Restart,                        //重新开始
+    MaskUI,                         //蒙板 
+    TempTipsUI,                     //提示
+    ServerList,                     //服务器列表
+    GameWind,                       // 子游戏窗口
 
-    TowerUI,  //塔防
-    ZombieUI,  //打僵尸
+    TowerUI,                        //塔防
+    ZombieUI,                       //打僵尸
+
+    MailMain,                       //邮箱
+    MailDetail,                     //邮件详情
 }
 
 export let Layer_Conf: { [key: number]: LayerConf } = {
@@ -24,4 +27,7 @@ export let Layer_Conf: { [key: number]: LayerConf } = {
     
     [ViewID.TowerUI]: { bundle: "package", url: "prefab/ui/tower/tower", type: LayerType.UI, anim: false },
     [ViewID.ZombieUI]: { bundle: "package", url: "prefab/ui/tower/zombie", type: LayerType.UI, anim: false },
+
+    [ViewID.MailMain]: { bundle: "sub_bundle", url: "mail/prefab/MailMain", type: LayerType.UI, anim: false },
+    [ViewID.MailDetail]: { bundle: "sub_bundle", url: "mail/prefab/MailDetail", type: LayerType.UI, anim: false },
 };

+ 41 - 0
assets/script/framework/util/StringUtil.ts

@@ -1,5 +1,6 @@
 import { JsonAsset } from "cc";
 import { MathUtil } from "./MathUtil";
+import { LanguageConf } from "../config/LanguageConf";
 
 const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
 
@@ -173,4 +174,44 @@ export class StringUtil {
             return ((value / Math.pow(k, i))).toFixed(fixed) + sizes[i];
         }
     }
+
+    /**
+     * 获取多语言数据
+     *  @param key 多语言的key
+     *  @param keyArr 替换值数组,没有则不传
+     * */
+    static getLanguageData(key, keyArr = [], translate = false) {
+        if (!key) {
+            return '未配置';
+        }
+        let getStr = (key)=>{
+            let strKey = String(key)
+            // let page = strKey.substring(0,1)
+            // let str = LanguageConf.data[strKey];
+            let str = LanguageConf.data[strKey];
+            if (str){ 
+                return str;
+            }else{
+                return key;
+            }
+        }
+        let strKey = String(key)
+        let str = getStr(strKey);
+        if (str){ 
+            for (let i = 0; i < keyArr.length; ++i) {
+                let replaceStr = keyArr[i]
+                if (translate) {
+                    replaceStr = (str.search(`${i}%]`) >= 0) ? MathUtil.accMul(Number(getStr(keyArr[i])), 100) + '%' : getStr(keyArr[i]);
+                } else {
+                    replaceStr = (str.search(`${i}%]`) >= 0) ? MathUtil.accMul(Number(getStr(keyArr[i])), 100) + '%' : replaceStr;
+                }
+                str = str.replace(`{${i}}`, replaceStr);
+                str = str.replace(`[${i}%]`, " ");
+
+            }
+            return str;
+        }else{
+            return key; 
+        }
+    }
 }

+ 12 - 0
assets/script/game/config/GlobalConf.ts

@@ -0,0 +1,12 @@
+export namespace GlobalConf {
+    export const data = {
+        "ResetHour": {
+                "Key": "ResetHour",
+                "Value": 5
+        },
+        "MailMaxCount": {
+                "Key": "MailMaxCount",
+                "Value": 100
+        }
+    };
+}

+ 9 - 0
assets/script/game/config/GlobalConf.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.24",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "f661f586-3154-4c7e-9d58-b84f6b3a5efa",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 216 - 0
assets/script/game/data/MailData.ts

@@ -0,0 +1,216 @@
+import { UserData } from "./UserData";
+
+interface Mail {
+    id: string;
+    sys: number;
+    expire: string;
+    read: string;
+    awards?: any[];
+}
+
+class Data {
+    private _mails: { [id: string]: Mail } = {};
+    private _mailMaxIdTab: { [sys: number]: number } = { 0: 0, 1: 0 };
+
+    init(): void {
+        this.reset();
+    }
+
+    reset(): void {
+        this._mails = {};
+        this._mailMaxIdTab = { 0: 0, 1: 0 };
+    }
+
+    purge(): void {
+        this.reset();
+    }
+
+    setData(data: Mail[]): void {
+        if (data) {
+            for (const v of data) {
+                this._mails[v.id] = v;
+            }
+            for (const v of data) {
+                if (parseInt(v.id, 10) > this._mailMaxIdTab[v.sys]) {
+                    this._mailMaxIdTab[v.sys] = parseInt(v.id, 10);
+                }
+            }
+        }
+    }
+
+    setMailMax(data: number[]): void {
+        for (const v of data) {
+            if (v > this._mailMaxIdTab[1]) {
+                this._mailMaxIdTab[1] = v;
+            }
+        }
+    }
+
+    setNewMail(data: Mail[]): void {
+        for (const v of data) {
+            this._mails[v.id] = v;
+        }
+        for (const v of data) {
+            if (parseInt(v.id, 10) > this._mailMaxIdTab[v.sys]) {
+                this._mailMaxIdTab[v.sys] = parseInt(v.id, 10);
+            }
+        }
+    }
+
+    getData(): { [id: string]: Mail } {
+        return this._mails;
+    }
+
+    getMaxMailId(type: number): number {
+        return this._mailMaxIdTab[type];
+    }
+
+    orderMail(): Mail[] {
+        const mailList: Mail[] = [];
+        const nowTime = UserData.getServerTime();
+
+        for (const key in this._mails) {
+            const v = this._mails[key];
+            if (parseInt(v.expire, 10) >= nowTime) {
+                mailList.push(v);
+            }
+        }
+
+        mailList.sort((a, b) => {
+            const x = parseInt(a.read, 10) === 0 ? 1 : 0;
+            const y = parseInt(b.read, 10) === 0 ? 1 : 0;
+
+            if (x > y) {
+                return -1;
+            } else if (x < y) {
+                return 1;
+            }
+            return parseInt(a.expire, 10) > parseInt(b.expire, 10) ? -1 : 1;
+        });
+
+        return mailList;
+    }
+
+    getLeftDays(time: number): number {
+        let leftTime = time - UserData.getServerTime();
+        leftTime = Math.ceil(leftTime / (24 * 60 * 60));
+        return leftTime <= 0 ? 0 : leftTime;
+    }
+
+    haveItemToGet(): boolean {
+        for (const key in this._mails) {
+            const v = this._mails[key];
+            if (v.awards && v.awards.length > 0) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    setMailReadById(id: string): void {
+        for (const key in this._mails) {
+            const v = this._mails[key];
+            if (parseInt(v.id, 10) === parseInt(id, 10)) {
+                v.read = '1';
+                break;
+            }
+        }
+    }
+
+    setMailRead(ids: string[]): void {
+        for (const k1 of ids) {
+            for (const key in this._mails) {
+                const v = this._mails[key];
+                if (parseInt(v.id, 10) === parseInt(k1, 10)) {
+                    v.read = '1';
+                }
+            }
+        }
+    }
+
+    haveMailNotRead(): boolean {
+        const nowTime = UserData.getServerTime();
+        for (const key in this._mails) {
+            const v = this._mails[key];
+            if (parseInt(v.expire, 10) >= nowTime && parseInt(v.read, 10) === 0) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    getShowAward(id: string): any {
+        for (const key in this._mails) {
+            const v = this._mails[key];
+            if (parseInt(v.id, 10) === parseInt(id, 10)) {
+                if (v.awards && v.awards.length > 0) {
+                    if (this._mails[parseInt(v.id, 10)].read === '1') {
+                        return null;
+                    } else {
+                        return v.awards[0];
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    getMailText(content: any, isTitle: boolean): string {
+        const jsonData = content;
+        let text: string;
+
+        // if (isTitle) {
+        //     if (typeof jsonData === 'number') {
+        //         text = ConfData.getMapData('maillocaltext.dat')[jsonData.toString()].Title;
+        //     } else {
+        //         text = content;
+        //     }
+        //     return Util.getString(text);
+        // } else {
+        //     if (Array.isArray(jsonData)) {
+        //         const count = jsonData.length;
+        //         text = ConfData.getMapData('maillocaltext.dat')[jsonData[0].toString()].Desc;
+
+        //         if (count === 2) {
+        //             const tcConfNew = ConfData.getMapData('manorcity.dat');
+        //             const tcsConfNew = ConfData.getMapData('manorschedule.dat');
+        //             const tcConf = ConfData.getMapData('territorycity.dat');
+        //             const tcsConf = ConfData.getMapData('territoryschedule.dat');
+
+        //             if (parseInt(jsonData[0], 10) === 14) {
+        //                 const str = ' Lv.' + tcConf[jsonData[1]].CityLevel + ' ' + Util.getString(tcConf[jsonData[1]].Name);
+        //                 text = Util.getString(text).replace('%s', str);
+        //             } else {
+
+        //             }
+        //         }
+
+                return text;
+            // } else {
+                return content;
+            // }
+        // }
+    }
+
+    removeMail(mailList: string[]): void {
+        for (const k1 of mailList) {
+            for (const key in this._mails) {
+                const v = this._mails[key];
+                if (parseInt(v.id, 10) === parseInt(k1, 10)) {
+                    delete this._mails[key];
+                }
+            }
+        }
+    }
+
+    removeMailById(id: string): void {
+        for (const key in this._mails) {
+            const v = this._mails[key];
+            if (parseInt(v.id, 10) === parseInt(id, 10)) {
+                delete this._mails[key];
+            }
+        }
+    }
+}
+
+export let MailData = new Data;

+ 9 - 0
assets/script/game/data/MailData.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.24",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "195882e6-7c6a-4199-83f4-7ca28447d26d",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 4 - 0
assets/script/game/data/UserData.ts

@@ -80,6 +80,10 @@ class Data {
         return obj;
     }
 
+    getServerTime(){
+        return  Date.now()
+    }
+
 }
 
 export let UserData = new Data;

+ 103 - 6
assets/script/game/ui/mail/MailItem.ts

@@ -1,15 +1,90 @@
-import { _decorator, Node } from 'cc';
+import { _decorator, Label, Node, Sprite, SpriteFrame } from 'cc';
 import { ResKeeper } from '../../../framework/res/ResKeeper';
+import { StringUtil } from '../../../framework/util/StringUtil';
+import { MailData } from '../../data/MailData';
+import { Framework } from '../../../framework/Framework';
+import { ViewID } from '../../../framework/config/LayerConf';
+import { LoginManager } from '../../common/LoginManager';
 const { ccclass, property } = _decorator;
 
 @ccclass('MailItem')
 export class MailItem extends ResKeeper {
-    private data = null;
-	protected onLoad() {
+	@property({ type: Node, tooltip: "邮件状态" })
+	awardBg: Node = null;
+
+	@property({ type: Node, tooltip: "奖励节点" })
+	awardNode: Node = null;
+
+	@property({ type: Label, tooltip: "邮件标题" })
+	titleTx: Label = null;
+
+	@property({ type: Label, tooltip: "邮件时间" })
+	timeTx: Label = null;
 
+	@property({ type: Node, tooltip: "已读状态" })
+	readIco: Node = null;
+	@property({ type: Label, tooltip: "已读状态文字" })
+	readIcoTx: Label = null;
+
+	@property({ type: Node, tooltip: "附件" })
+	awardTips: Node = null;
+	@property({ type: Label, tooltip: "附件文字" })
+	awardTipsTx: Label = null;
+
+	@property({ type: Node, tooltip: "已读遮罩" })
+	maskImg: Node = null;
+
+	private data = null;
+	protected onLoad() {
+		this.readIcoTx.string = StringUtil.getLanguageData('已读');
+		this.awardTipsTx.string = StringUtil.getLanguageData('附件');
 	}
-	init(data) {
+
+	refreshItem(data) {
 		this.data = data;
+
+		this.titleTx.string = data.title;
+
+		this.maskImg.active = false;
+		this.readIco.active = false;
+
+		let date = new Date(data.time);
+		let Y = date.getFullYear() + '-';
+		let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
+		let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + '';
+		this.timeTx.string = Y + M + D;
+		if (data.award && data.award.size > 0) {
+			this.awardTips.active = false;
+			let showAward = MailData.getShowAward(data.id)
+			if (showAward) {
+				this.awardBg.active = false;
+				this.awardNode.active = true;
+			} else {
+				this.awardBg.active = true;
+				this.awardNode.active = false;
+				this.load('sub_bundle', 'mail/texture/mail_3/', SpriteFrame, (res: SpriteFrame) => {
+					this.awardBg.getComponent(Sprite).spriteFrame = res;
+				})
+			}
+		} else {
+			this.awardBg.active = true;
+			this.awardNode.active = false;
+			this.awardTips.active = false;
+			this.load('sub_bundle', 'mail/texture/mail_3', SpriteFrame, (res: SpriteFrame) => {
+				this.awardBg.getComponent(Sprite).spriteFrame = res;
+			})
+		}
+
+		if (data.read == 1) {
+			this.awardBg.active = true;
+			this.awardNode.active = false;
+			this.awardTips.active = false;
+			this.readIco.active = true;
+			this.maskImg.active = true;
+			this.load('sub_bundle', 'mail/texture/mail_2', SpriteFrame, (res: SpriteFrame) => {
+				this.awardBg.getComponent(Sprite).spriteFrame = res;
+			})
+		}
 	}
 	protected onDestroy() {
 		super.onDestroy();
@@ -22,8 +97,30 @@ export class MailItem extends ResKeeper {
 	//UI事件处理
 	private onTouchButton(event: Event) {
 		let target: any = event.target;
-		if (target.name == 'join') {
-		
+		if (target.name == 'bg') {
+			if (this.data.read == 1) {
+				Framework.layer.open(ViewID.MailDetail, null, this.data);
+				return;
+			}
+			if (this.data.award && this.data.award.size > 0) {
+				Framework.layer.open(ViewID.MailDetail, null, this.data);
+			} else {
+				// LoginManager.sendPost('user', 'read_mail', (data) => {
+				// 	// console.log(data);
+				// 	if (data.awards) {
+						
+				// 	}
+				// 	if (data.equip) {
+						
+				// 	}
+				// 	if (data.gem) {
+						
+				// 	}
+				// 	MailData.setMailReadById(data.id)
+
+					Framework.layer.open(ViewID.MailDetail, null, this.data);
+				// }, { id: this.data.id })
+			}
 		}
 	}
 }

+ 73 - 4
assets/script/game/ui/mail/MailMain.ts

@@ -1,13 +1,53 @@
-import { _decorator, Component, Node } from 'cc';
+import { _decorator, Component, Label, Node } from 'cc';
 import { BaseView } from '../../../framework/layer/BaseView';
 import { MailItem } from './MailItem';
+import { StringUtil } from '../../../framework/util/StringUtil';
+import { MailData } from '../../data/MailData';
+import { GlobalConf } from '../../config/GlobalConf';
+import List from '../../../framework/list/List';
+import { Framework } from '../../../framework/Framework';
 const { ccclass, property } = _decorator;
 
 @ccclass('MailMain')
 export class MailMain extends BaseView {
-	private _mailData = [];
+	@property({ type: Label, tooltip: "关闭提示" })
+	closeTips: Label = null;
+
+	@property({ type: Label, tooltip: "标题" })
+	titlteTx: Label = null;
+
+	@property({ type: Label, tooltip: "邮件数文字" })
+	numTx: Label = null;
+
+	@property({ type: List, tooltip: "滑动容器" })
+	sv: List = null;
+
+	@property({ type: Node, tooltip: "为空提示节点" })
+	noneNode: Node = null;
+
+	@property({ type: Label, tooltip: "为空提示文字" })
+	noneTx: Label = null;
+
+	@property({ type: Node, tooltip: "一键删除按钮" })
+	delAutoBtn: Node = null;
+	@property({ type: Label, tooltip: "一键删除按钮文字" })
+	delAutoBtnTx: Label = null;
+
+	@property({ type: Node, tooltip: "一键领取按钮" })
+	getAutoBtn: Node = null;
+	@property({ type: Label, tooltip: "一键领取按钮文字" })
+	getAutoBtnTx: Label = null;
+
+	private _mailList = [];
+	private _nowMailId: number = 0;
+
 	onLoad() {
 		super.onLoad();
+		this.closeTips.string = StringUtil.getLanguageData('点击空白关闭');
+		this.titlteTx.string = StringUtil.getLanguageData('邮件');
+		this.noneTx.string = StringUtil.getLanguageData('当前空空如也哦~');
+		this.delAutoBtnTx.string = StringUtil.getLanguageData('一键删除');
+		this.getAutoBtnTx.string = StringUtil.getLanguageData('一键领取');
 	}
 
 	onDestroy() {
@@ -15,7 +55,8 @@ export class MailMain extends BaseView {
 	}
 
 	onOpen() {
-
+		this.updateMainPanel();
+		this.updateMailNum();
 	}
 
 	onClose() {
@@ -31,12 +72,40 @@ export class MailMain extends BaseView {
 	}
 
 	private onTouchButton(event: Event, customStr) {
+		let target: any = event.target;
+		if (target.name == 'mask') {
+			Framework.layer.close(this);
+		} else if (target.name == 'auto_del_btn') {
 
+		} else if (target.name == 'auto_get_btn') {
 
+		}
 	}
 
 	onEventList(item, idx) {
-		item.getComponent(MailItem).init(this._mailData[idx]);
+		item.getComponent(MailItem).refreshItem(this._mailList[idx]);
+	}
+
+	private updateMainPanel() {
+		this._mailList = MailData.orderMail();
+		this._nowMailId = this._mailList.length > 0 ? this._mailList[0].id : 0;
+
+		if (this._mailList.length == 0) {
+			this.noneNode.active = true;
+			this.delAutoBtn.active = false;
+			this.getAutoBtn.active = false;
+			this.numTx.node.active = false;
+		} else {
+			this.noneNode.active = false;
+			this.delAutoBtn.active = true;
+			this.getAutoBtn.active = true;
+			this.numTx.node.active = true;
+		}
+		this.sv.numItems = this._mailList.length;
+	}
+
+	private updateMailNum() {
+		this.numTx.string = `${StringUtil.getLanguageData('邮件数: ')}${this._mailList.length}/${GlobalConf.data.MailMaxCount.Value}`;
 	}
 }
 

File diff suppressed because it is too large
+ 409 - 157
assets/sub_bundle/mail/prefab/MailMain.prefab


+ 2 - 2
settings/v2/packages/cocos-service.json

@@ -1,7 +1,7 @@
 {
-  "__version__": "3.0.5",
+  "__version__": "3.0.7",
   "game": {
-    "name": "UNKNOW GAME",
+    "name": "未知游戏",
     "app_id": "UNKNOW",
     "c_id": "0"
   },

Some files were not shown because too many files changed in this diff