bing 2 éve
szülő
commit
8f72f13c6b

+ 2 - 1
assets/pay/script/ItemPay.ts

@@ -4,6 +4,7 @@ import { UtilsPanel } from '../../scene/script/UtilsPanel';
 import { ViewItemPro } from '../../scene/script/components/ViewItemPro';
 import { nav_info } from '../../scene/script/NavInfo';
 import { Pay, ShopData } from './Pay';
+import { UtilsFormat } from '../../scene/script/UtilsFormat';
 const { ccclass } = _decorator;
 
 @ccclass('ItemPay')
@@ -29,7 +30,7 @@ export class ItemPay extends ViewItemPro {
         else{
             this.money = p.DefaultPrice[index];
             this.gold = Pay.clacGold(this.money);
-            this.lb_count.string = "" + this.gold;
+            this.lb_count.string = UtilsFormat.formatMoney(this.gold);
         }
         if(index > 5)index = 5;
 

+ 2 - 2
assets/pay/script/Pay.ts

@@ -35,7 +35,7 @@ export class Pay extends Component {
     public static buy(price:number){
         let user_id = Pay.user_id;
         if(user_id.length == 0){
-            nav_info.scene.showTip("please input user id");
+            nav_info.scene.showTip("يرجى إدخال ال ID حقك");
             return;
         }
         let url = nav_info.is_test ? Config.url_pay_test : Config.url_pay;
@@ -78,7 +78,7 @@ export class Pay extends Component {
     }
     private onBuy(){
         if(this.select_data == 0){
-            nav_info.scene.showTip("please select product");
+            nav_info.scene.showTip("يرجى اختيار الباقة التي ترغب بشرائها");
             return;
         }
         Pay.buy(this.select_data);

+ 30 - 6
assets/pay/script/PayCustom.ts

@@ -2,6 +2,7 @@
 import { _decorator, Component, EditBox, EventHandle, EventHandler, js, Label, Node, utils } from 'cc';
 import { UtilsPanel } from '../../scene/script/UtilsPanel';
 import { Pay } from './Pay';
+import { UtilsFormat } from '../../scene/script/UtilsFormat';
 
 const { ccclass } = _decorator;
 
@@ -17,15 +18,40 @@ export class PayCustom extends Component {
         let handler = new EventHandler();
         handler.target = this.node;
         handler.component = js.getClassName(this);
-        handler.handler = "checkNum";
-        this.edit_money.textChanged.push(handler)
+        handler.handler = "onInputEnd";
+        this.edit_money.editingDidEnded.push(handler);
+        // this.edit_money.textChanged.push(handler)
 	}
     protected start(): void {
         this.money = Pay.data_shop.MinMoney;
         this.edit_money.string = this.money + "";
         this.refreshGold();
     }
-    private checkNum(text: string){
+    // private checkNum(text: string){
+    //     let index = text.indexOf(".");
+    //     let revise = false;
+    //     if(index > -1){
+    //         revise = true;
+    //         text = text.replace(".", "");
+    //     }
+    //     let num = parseInt(text);
+    //     if(num <  Pay.data_shop.MinMoney){
+    //         revise = true;
+    //         num = Pay.data_shop.MinMoney
+    //         text = "" +  num;
+    //     }
+    //     if(revise){
+    //         //@ts-ignore
+    //         this.edit_money._impl._edTxt.value = text;
+    //         this.edit_money.string = text;
+    //     }
+    //     if(num != this.money){
+    //         this.money = num;
+    //         this.refreshGold();
+    //     }
+    // }
+    private onInputEnd(){
+        let text = this.edit_money.string;
         let index = text.indexOf(".");
         let revise = false;
         if(index > -1){
@@ -39,8 +65,6 @@ export class PayCustom extends Component {
             text = "" +  num;
         }
         if(revise){
-            //@ts-ignore
-            this.edit_money._impl._edTxt.value = text;
             this.edit_money.string = text;
         }
         if(num != this.money){
@@ -49,7 +73,7 @@ export class PayCustom extends Component {
         }
     }
     private refreshGold(){
-        this.lb_gold.string = Pay.clacGold(this.money) + "";
+        this.lb_gold.string = "" + (Pay.clacGold(this.money));
     }
 	private onCloseClick(){
 		this.node.destroy();

+ 239 - 0
assets/scene/script/UtilsFormat.ts

@@ -0,0 +1,239 @@
+import { Label, tween, Tween, UITransform, Vec3, _decorator } from 'cc';
+
+const limit = [1000000000000, 1000000000, 1000000, 1000];
+const chars = ["T", "B", "M", "K"];
+export const SexKey = ["us_unspecified", "us_male", "us_female"];
+
+const Time_Desc = ["d","h","m","s"];
+
+export class UtilsFormat {
+    public static toThousands(v: number) {
+        let prefix = "";
+        if (v < 0) {
+            prefix = "-";
+            v = -v;
+        }
+        let s = "" + v;
+        let p = s.indexOf(".");
+        let i = p >= 0 ? p : s.length;
+        let str = "";
+        while (i > 0) {
+            if (!!str) {
+                str = "," + str;
+            }
+            str = s.substring(i > 3 ? i - 3 : 0, i) + str;
+            i -= 3;
+        }
+        if (p >= 0) {
+            str = str + s.substring(p, s.length);
+        }
+        return !!prefix ? prefix + str : str;
+    }
+
+    //动态字符串 需要父节点要mask
+    public static setMoveName(labelNode: Label, name: string) {
+        labelNode.string = name;
+        labelNode.updateRenderData(true);
+        let nameMoveWidth = labelNode.getComponent(UITransform).width - labelNode.node.parent.getComponent(UITransform).width;
+
+        Tween.stopAllByTarget(labelNode.node);
+        labelNode.node.setPosition(0, 0);
+
+        if (nameMoveWidth > 0) {
+            let speed = labelNode.node.parent.getComponent(UITransform).width / 3;
+            tween(labelNode.node)
+                .delay(2)
+                .to(3, { position: new Vec3(-labelNode.node.parent.getComponent(UITransform).width, 0, 0) })
+                .delay(0.5)
+                .call(() => { labelNode.node.toX(labelNode.getComponent(UITransform).width); })
+                .to(labelNode.getComponent(UITransform).width / speed, { position: new Vec3(0, 0, 0) })
+                .union()
+                .repeatForever()
+                .start()
+        }
+    }
+
+    public static getShortName(name: string, num: number = 10, isReversed = false) {
+        if (!isReversed) return name.length > num ? name.slice(0, num) + '...' : name;
+        else return name.length > num ? '...' + name.slice(name.length - num, name.length) : name;
+    }
+
+    public static formatRate(rate: number) {
+        return Math.floor(rate * 10000) / 100 + "%";
+    }
+    public static formatFlag(num:number){
+        num = Math.floor(num / 1000) * 1000;
+        let is_minus = num < 0;
+        if (is_minus) {
+            num = -num;
+        }
+        for (let i = 0; i < 4; i++) {
+            if (num >= limit[i]) {
+                num = (num * 1) / limit[i];
+                let remain = num % 1;
+                let str = "";
+                if (remain > 0) {
+                    str = remain >= 0.01 ? num.toFixed(2) : Math.floor(num) + "";
+                } else {
+                    str += num;
+                }
+                return is_minus ? "-" + str + chars[i] : str + chars[i];
+            }
+        }
+        return "" + num;
+    }
+    public static formatMoney(num: number) {
+        if(Math.abs(num) < 10000){
+            return UtilsFormat.toThousands(num);
+        }
+        return UtilsFormat.formatFlag(num);
+    }
+    public static formatByLimit(num:number, limit:number){
+        if(Math.abs(num) < limit)return UtilsFormat.toThousands(num);
+        return UtilsFormat.formatFlag(num);
+    }
+    public static formatFlagLimit(num:number, limit:number){
+        if(num < limit)return "" + num;
+        return UtilsFormat.formatFlag(num);
+    }
+    public static PrefixInteger(num, n) {
+        return (Array(n).join("0") + num).slice(-n);
+    }
+
+    public static schoolServerTime(s) {
+        return s;
+    }
+
+    public static addZero(n) {
+        if (n < 10) return "0" + n;
+        return "" + n;
+    }
+
+    public static getDateStr(date: Date, format_str:string) {
+        let str = "";
+        let temp = "";
+        for (let i = 0, len = format_str.length; i < len; i++) {
+            temp = "";
+            switch (format_str[i]) {
+                case "n":
+                    temp = date.getFullYear() + "";
+                    temp = temp.slice(2, 4);
+                    break;
+                case "N":
+                    temp = date.getFullYear() + "";
+                    break;
+                case "Y":
+                case "y":
+                    temp = UtilsFormat.addZero(date.getMonth() + 1);
+                    break;
+                case "R":
+                case "r":
+                    temp = UtilsFormat.addZero(date.getDate());
+                    break;
+                case "S":
+                case "s":
+                    temp = UtilsFormat.addZero(date.getHours());
+                    break;
+                case "F":
+                case "f":
+                    temp = UtilsFormat.addZero(date.getMinutes());
+                    break;
+                case "M":
+                case "m":
+                    temp = UtilsFormat.addZero(date.getSeconds());
+                    break;
+            }
+            if (temp != "") {
+                str = str + temp;
+            } else {
+                str = str + format_str[i];
+            }
+        }
+        return str;
+    }
+    /** !#zh isToday 判断是否为今天
+     * @param {any} timestamp 时间戳
+     */
+    public static isToday(timestamp) {
+        if (new Date(timestamp).toDateString() === new Date().toDateString()) {
+            return true;
+        }
+        return false;
+    }
+    /**几天前 */
+    public static getDaysAgo(timestamp: Date) {
+        let curStamp = new Date().getTime()
+        const aDayStamp = 1000 * 60 * 60 * 24
+        let offset = (curStamp - timestamp.getTime())
+        return Math.ceil(offset / aDayStamp)
+    }
+
+    public static getCountdown(s: number, strs: Array<string>) {
+        if (!strs) strs = ["d","h","m"];
+        if (s > 86400) {
+            let all_hour = Math.floor(s / 3600);
+            let hour = all_hour % 24;
+            let day = (all_hour - hour) / 24;
+            return `${day}${strs[0]}:${hour}${strs[1]}`;
+        } else {
+            let all_minute = Math.floor(s / 60);
+            let minute = all_minute % 60;
+            let hour = (all_minute - minute) / 60;
+            return `${hour}${strs[1]}:${minute}${strs[2]}`;
+        }
+    }
+    public static getCountdown2(s:number, format_str:string, desc:Array<string>, limit:number){
+        let str = "";
+        let suffix = "";
+        if(!desc)desc = Time_Desc;
+        let count = 0;
+        for (let i = 0, len = format_str.length; i < len; i++) {
+            switch (format_str[i]) {
+                case "R":
+                case "r":
+                    count = Math.floor(s / 86400);
+                    if(count > 0){
+                        if(format_str[i] == "R")suffix += desc[0] + count;
+                        else str += (count + desc[0]);
+                        s -= count * 86400;
+                        limit--;
+                    }
+                    break;
+                case "S":
+                case "s":
+                    count = Math.floor(s / 3600);
+                    if(count > 0){
+                        str += (count + desc[1]);
+                        s -= count * 3600;
+                        limit--;
+                    }
+                    break;
+                case "F":
+                case "f":
+                    count = Math.floor(s / 60);
+                    str += (count + desc[2]);
+                    s -= count * 60;
+                    limit--;
+                    break;
+                case "M":
+                case "m":
+                    str += (s + desc[3]);
+                    limit--;
+                    break;
+            }
+            if(limit == 0)break;
+        }
+        return str + suffix;
+    }
+    public static getCountdownSFM(s:number){
+        let second = s % 60;
+        let minute = (s - second) / 60;
+        let hour = Math.floor(minute / 60);
+        minute = minute % 60;
+        let func_add0 = UtilsFormat.addZero;
+        return func_add0(hour) + ":" + func_add0(minute) + ":" + func_add0(second);
+    }
+    public static firstUpper(str: string) {
+        return str[0].toUpperCase() + str.slice(1);
+    }
+}

+ 9 - 0
assets/scene/script/UtilsFormat.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.23",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "bf53f046-952a-4971-87f7-4779cee84138",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}