public void SetData(ActivityTemplateModel model) { _accumulativeImg.texture = ResourceManager.Load <Texture>("Prop/" + model.ConsumeItemId); _haveNumIconImg.texture = ResourceManager.Load <Texture>("Prop/" + model.ConsumeItemId); _accumulativeImg.gameObject.Show(); _haveNumIconImg.gameObject.Show(); _haveNumTxt.text = I18NManager.Get("ActivityTemplate_ActivityTemplateHaveNum", model.ActivityItemNum()); _endTimeStamp = model.EndTimeStamp; _accumulativeTxt.text = "x " + model.GetUserActivityHolidayInfo().DrawCount; //_progressBar.sizeDelta =new Vector2(model.Progress(),_progressBar.sizeDelta.y); _lotteryBtnRedDot.SetActive(model.ActivityItemNum() >= model.Price * model.PlayMoreNum); SetActivityTime(); SetProgress(model); }
private void SetProgress(ActivityTemplateModel model) { //找出进度条开始的位置 int showLen = _tabBarTran.childCount; int totalLen = (model.activeHolidayAwardRules != null) ? model.activeHolidayAwardRules.Count : 0; int myCount = model.GetUserActivityHolidayInfo().DrawCount; int startIndex = 0; int index = 0; int startValue = 0; for (int i = 0; i < totalLen; ++i) { int weight = model.activeHolidayAwardRules[i].Weight; if (myCount >= weight) { bool isGet = model.GetUserActivityHolidayInfo().ActiveProgress.Contains(weight); if (!isGet) { break; } index = i + 1; if (index > totalLen - 1) { break; } if (index % showLen == 0) { startIndex = index; startValue = weight; } } } index = startIndex + showLen; if (index >= totalLen) { index = totalLen - 1; } float progress = 0f; int lastValue = startValue; for (int i = startIndex; i <= index; ++i) { int weight = model.activeHolidayAwardRules[i].Weight; if (myCount >= weight) { if (i == totalLen - 1) { progress += ((float)(myCount - lastValue) / (weight - lastValue)) * (1f / 6f); } else { progress += 1f / 6f; } lastValue = weight; //Debug.LogWarning(">= weight:" + weight + " progress:"+progress); } else { progress += ((float)(myCount - lastValue) / (weight - lastValue)) * (1f / 6f); //Debug.LogWarning("< weight:" + weight + " lastValue:" + lastValue + " progress:"+progress); break; } } if (progress > 1) { progress = 1f; } if (progress < 0) { progress = 0f; } //Debug.LogWarning("myCount:"+myCount + " startValue:"+startValue + " endValue:"+endValue); //Debug.LogWarning("progress:" + progress + " index:"+index); _progressBar.sizeDelta = new Vector2(progress * 972.92f, _progressBar.sizeDelta.y); //Debug.LogWarning("startIndex:"+startIndex); for (int i = 0; i < _tabBarTran.childCount; i++) { int weight = model.Weight(startIndex + i); //int weight = model.Weight(i); var frameBg = _tabBarTran.GetChild(i).Find("FrameBg"); var icon = frameBg.GetRawImage("Icon"); var redDot = frameBg.Find("RedDot"); var num = _tabBarTran.GetChild(i).GetText("WeightTxt"); num.text = weight.ToString(); var mask = _tabBarTran.GetChild(i).Find("Mask"); var iconNum = frameBg.GetText("IconNum"); var rewards = model.GetActiveAward(weight); PointerClickListener.Get(icon.gameObject).onClick = null; bool isGift = rewards.Count > 1; if (!isGift) { RewardVo vo = new RewardVo(rewards[0]); icon.texture = ResourceManager.Load <Texture>(vo.IconPath); icon.gameObject.Show(); icon.transform.GetChild(0).gameObject.SetActive(vo.Resource == ResourcePB.Puzzle); iconNum.text = vo.Num.ToString(); } else { string path = "Prop/GiftPack/tongyong2"; icon.texture = ResourceManager.Load <Texture>(path); icon.gameObject.Show(); iconNum.transform.gameObject.Hide(); icon.transform.GetChild(0).gameObject.Hide(); } //是否初始化 if (model.GetUserActivityHolidayInfo().ActiveProgress == null) { redDot.gameObject.Hide(); mask.gameObject.Hide(); PointerClickListener.Get(icon.gameObject).onClick = go => { if (!isGift) { FlowText.ShowMessage(ClientData.GetItemDescById(rewards[0].ResourceId, rewards[0].Resource).ItemDesc); } else { //打开奖励预览窗口 var window = PopupManager.ShowWindow <CommonAwardWindow>("GameMain/Prefabs/AwardWindow/CommonAwardWindow"); window.SetData(rewards.ToList(), true, ModuleConfig.MODULE_ACTIVITYTEMPLATE); } }; } else { //是否领取过 isGet为true领取过,false未领取 var isGet = model.GetUserActivityHolidayInfo().ActiveProgress.Contains(weight); //是否可以领取 isMayGet为true可以领,false未领取 var isMayGet = model.GetUserActivityHolidayInfo().DrawCount >= weight; if (isMayGet && !isGet) //可以领,没领过 { frameBg.gameObject.Show(); mask.gameObject.Hide(); redDot.gameObject.Show(); PointerClickListener.Get(icon.gameObject).onClick = go => { SendMessage(new Message(MessageConst.CMD_ACTIVITYTEMPLATE1_GET_ACTIVE_AWARD, Message.MessageReciverType.CONTROLLER, weight)); }; } else if (isMayGet && isGet) //可以领,领过了 { frameBg.gameObject.Hide(); mask.gameObject.Show(); } else if (!isMayGet) //不可以领 { frameBg.gameObject.Show(); redDot.gameObject.Hide(); mask.gameObject.Hide(); PointerClickListener.Get(icon.gameObject).onClick = go => { if (!isGift) { FlowText.ShowMessage(ClientData.GetItemDescById(rewards[0].ResourceId, rewards[0].Resource).ItemDesc); } else { //打开奖励预览窗口 var window = PopupManager.ShowWindow <CommonAwardWindow>("GameMain/Prefabs/AwardWindow/CommonAwardWindow"); window.SetData(rewards.ToList(), true, ModuleConfig.MODULE_ACTIVITYTEMPLATE); } }; } } } }