| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- import JsbSystem from "../../../mk/system/JsbSystem";
- import { UITween } from "../../component/tween/UITween";
- import { DataEventId, ExpAddType, VideoAdType } from "../../data/GameData";
- import { GradeRewardItem } from "./GradeRewardItem";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export class GradeReward extends cc.Component {
- @property({ displayName: "进度条", type: cc.Sprite })
- private sp_slider: cc.Sprite = null;
- @property({ displayName: "内容节点", type: cc.Node })
- private node_content: cc.Node = null;
- @property(cc.Prefab)
- private node_child: cc.Prefab = null;
- @property({ displayName: '进度文本', type: cc.Label })
- private lbl_progress: cc.Label[] = [];
- private gradeExp: number[] = [];
- private curExp: number = 0;
- private gradeOffset: number[] = [0.11, 0.33, 0.56, 0.78, 1];
- private gradeItemArr: GradeRewardItem[] = [];
- onLoad(){
- }
- start(){
- if(gData.gameData.playerProp.farmGradeData)
- {
- let len = gData.gameData.playerProp.farmGradeData.farmGradeRewardList.length;
- for(let i = len; i != 0; --i)
- {
- let data = gData.gameData.playerProp.farmGradeData.farmGradeRewardList[i-1];
- let child = cc.instantiate(this.node_child);
- let item = child.getComponent(GradeRewardItem);
- item.setData(data);
- this.node_content.addChild(child);
- this.gradeItemArr.push(item);
- }
- }
- // for(let i = 5; i != 0; --i)
- // {
- // let child = cc.instantiate(this.node_child);
- // let item = child.getComponent(GradeRewardItem);
- // item.id = i;
- // item.lbl_value.string = "0.3元";
- // item.lbl_grade.string = "LV:12";
- // this.node_content.addChild(child);
- // }
- this.calulateExpAndShowUI2();
- }
- update(dt)
- {
- if(gData.farmGradeData.changeExp)
- {
- this.calulateExpAndShowUI2();
- this.freshFramGradeData();
- gData.farmGradeData.changeExp = false;
- }
- }
- private freshFramGradeData()
- {
- let len = this.gradeItemArr.length;
- for(let i = 0 ; i != len; ++i)
- {
- let data = gData.gameData.playerProp.farmGradeData.farmGradeRewardList[len-1-i];
- this.gradeItemArr[i].setData(data);
- this.gradeItemArr[i].changeBtnState();
- }
- }
- private calulateExpAndShowUI()
- {
- this.curExp = gData.gameData.playerProp.farmExpValue;
- let curIndex = -1;
- for (let i = 0; i != this.gradeExp.length; ++i) {
- if (this.curExp < this.gradeExp[i]) {
- if (curIndex == -1) {
- curIndex = i;
- } else {
- this.lbl_progress[i].string = "0%";
- }
- } else {
- this.lbl_progress[i].string = "100%";
- }
- }
- if (curIndex != -1) {
- let remainExp = this.curExp;
- for (let i = 0; i != curIndex; ++i) {
- remainExp = this.curExp - this.gradeExp[i];
- }
- let per = Math.floor(remainExp / this.gradeExp[curIndex] * 100);
- this.lbl_progress[curIndex].string = per + "%";
- let lastIndex = -1
- let lastPro = 0;
- if (curIndex > 0) {
- lastIndex = curIndex - 1;
- }
- let offset = this.gradeOffset[curIndex];
- if (lastIndex != -1) {
- offset = offset - this.gradeOffset[lastIndex];
- lastPro = this.gradeOffset[lastIndex];
- }
- let pro = offset * per / 100;
- this.sp_slider.fillRange = lastPro + pro;
- } else {
- this.sp_slider.fillRange = 1;
- }
- }
- private calulateExpAndShowUI2()
- {
- let curIndex = -1;
- let curPer = 0;
- let len = gData.gameData.playerProp.farmGradeData.farmGradeRewardList.length;
- for(let i = 0; i != len; ++i)
- {
- let per = gData.gameData.playerProp.farmGradeData.farmGradeRewardList[i].progressRate;
- this.lbl_progress[i].string = Math.round(per * 100) + '%';
- if(curIndex == -1)
- {
- if(per < 1)
- {
- curIndex = i;
- curPer = per;
- }
- }
- }
- if(curIndex != -1)
- {
- let lastIndex = -1
- let lastPro = 0;
- if(curIndex > 0)
- {
- lastIndex = curIndex-1;
- }
-
- let offset = this.gradeOffset[curIndex];
- if(lastIndex != -1)
- {
- offset = offset - this.gradeOffset[lastIndex];
- lastPro = this.gradeOffset[lastIndex];
- }
- let pro = offset * curPer;
- this.sp_slider.fillRange = lastPro + pro;
- }else
- {
- this.sp_slider.fillRange = 1;
- }
- }
- private clickVideoBtn() {
- mk.audio.playEffect("button");
- if (cc.sys.isNative && !gData.loginData.isAuth) {
- // JsbSystem.WxAuth();
- gData.gameData.authUIType = 0;
- mk.ui.openPanel('module/authUI/authUI');
- return;
- }
- mk.ad.videoAdType = VideoAdType.video_init_1;
- mk.ad.watchAd((success: boolean) => {
- mk.console.log("watchAD:" + success);
- if (success) {
- gData.adData.watchVideo(null);
- gData.farmGradeData.addGradeExp(ExpAddType.EAT_video);
- }
- });
- }
- private clickCloseBtn() {
- mk.audio.playEffect("button");
- }
- onDisable() {
- let pop = gData.adData.checkShowFullInter(4);
- if(pop){
- gData.moreGame.openType = 3;
- mk.data.sendDataEvent(DataEventId.htRedBag_scene, "关闭农场等级奖励界面");
- }
- }
- }
|