----- 神将置换 ----- local this = {} local sortingOrder=0 local tabs={} local curIndex = 0 local curSelectHero = {} local curSelectHeroConfig = {} local heroSelectBtn = {} local heroDatas local HeroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig) function this:InitComponent(gameObject) this.gameObject = gameObject this.heroPre = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/item") this.replaceBtn = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/btns/replaceBtn") this.saveBtn = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/btns/saveBtn") this.cancelBtn = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/btns/cancelBtn") for i = 1, 5 do tabs[i] = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/Tabs/Grid/Btn" .. i) end this.selectBtn=Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/Tabs/SelectBtn") this.selectBtn:SetActive(true) this.ScrollBar=Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/Scrollbar"):GetComponent("Scrollbar") local v2 = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/scroll"):GetComponent("RectTransform").rect this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/scroll").transform, this.heroPre, this.ScrollBar, Vector2.New(-v2.x*2, -v2.y*2), 1, 5, Vector2.New(50,15)) this.ScrollView.moveTween.MomentumAmount = 1 this.ScrollView.moveTween.Strength = 1 --need -> replaceHero Info this.needHero = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/heros/needHero") this.replaceHero = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/heros/replacedHero") this.needBg = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/bg/heroPlace1") this.replaceBg = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/bg/heroPlace2") this.text = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/heros/content/Text") this.cost = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/heros/content/cost") this.costText = Util.GetGameObject(this.cost,"Text"):GetComponent("Text") end function this:BindEvent() --置换 Util.AddClick(this.replaceBtn,function() if not not curSelectHero.id then NetManager.SaveHeroChangeRequest(curSelectHero.dynamicId,function (msg) HeroManager.ResetHeroChangeId(curSelectHero.dynamicId,msg.heroTempId)--改变英雄changeId this.replaceHero:SetActive(true) this.cancelBtn:SetActive(true) this.replaceBtn:SetActive(false) this.saveBtn:SetActive(true) this.needBg:SetActive(false) this.replaceBg:SetActive(false) this.text:SetActive(false) this.cost:SetActive(false) local value = this.RebuildData(msg.heroTempId) this.SetHero(this.replaceHero,value) end) else PopupTipPanel.ShowTip("请选择想要置换的神将!") end end) --取消 Util.AddClick(this.cancelBtn,function() NetManager.CancelHeroChangeRequest(curSelectHero.dynamicId,function (msg) HeroManager.ResetHeroChangeId(curSelectHero.dynamicId)--改变英雄changeId this.replaceHero:SetActive(false) this.needHero:SetActive(false) this.cancelBtn:SetActive(false) this.replaceBtn:SetActive(true) this.saveBtn:SetActive(false) this.needBg:SetActive(true) this.replaceBg:SetActive(true) this.text:SetActive(true) this.cost:SetActive(false) curSelectHero = {} for i = 1, #heroDatas do heroSelectBtn[i]:SetActive(heroDatas[i].dynamicId == curSelectHero.dynamicId) end end) end) --保存置换 Util.AddClick(this.saveBtn,function() NetManager.DoHeroChangeRequest(curSelectHero.dynamicId,function (msg) this.replaceHero:SetActive(false) this.needHero:SetActive(false) this.needBg:SetActive(true) this.replaceBg:SetActive(true) this.text:SetActive(true) this.cost:SetActive(false) HeroManager.DeleteHeroDatas({curSelectHero.dynamicId}) UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop,1,function() this.ShowCurrPosHeroReplace(curIndex) end) end) end) end --通过Id 重新组成数据 function this.RebuildData(id) local herodata = {} herodata.id = HeroConfig[id].Id herodata.name = HeroConfig[id].ReadingName herodata.live = GetResourcePath(HeroConfig[id].Live) herodata.star = HeroConfig[id].Star herodata.lv = 1 herodata.quality = HeroConfig[id].Quality herodata.profession = HeroConfig[id].Profession herodata.scale = HeroConfig[id].Scale herodata.position = HeroConfig[id].Position herodata.property = HeroConfig[id].PropertyName return herodata end function this:AddListener() end function this:RemoveListener() end function this:OnSortingOrderChange(_sortingOrder) sortingOrder = _sortingOrder end function this:OnShow(...) curIndex = 0 sortingOrder =0 for i = 0,#tabs - 1 do local index=i Util.GetGameObject(tabs[i + 1], "Image"):GetComponent("Image").sprite=Util.LoadSprite(GetProStrImageByProNum(index)) Util.AddOnceClick(tabs[i + 1], function() curSelectHero = {} if index == curIndex then curIndex=0 this.HeroReplaceBtnClick(tabs[1],curIndex) else this.HeroReplaceBtnClick(tabs[i + 1],index) end end) end this.HeroReplaceBtnClick(tabs[1],curIndex) end --英雄类型按钮点击事件 function this.HeroReplaceBtnClick(_btn,_curIndex) curIndex = _curIndex this.SetBtnSelect(_btn) this.ShowCurrPosHeroReplace(_curIndex) end --显示当前阵营的英雄 function this.ShowCurrPosHeroReplace(_curIndex) this.replaceHero:SetActive(false) this.needHero:SetActive(false) heroDatas = this.GetHeroDataByPosition(_curIndex) this.ScrollView:SetData(heroDatas, function (index, go) heroSelectBtn[index] = Util.GetGameObject(go.transform, "choosed") this.SingleHeroDataShow(go, heroDatas[index]) end) end --通过职业筛选英雄 function this.GetHeroDataByPosition(_position) local heros = {} local index = 1 for i, v in pairs(HeroManager.ByReplaceHeroGetAllHeros()) do if HeroConfig[v.id].PropertyName == _position or _position == 0 then --0 全职业 heros[index] = v index = index + 1 end end return heros end --数据显示 function this.SingleHeroDataShow(_go,_heroData) local go = _go local heroData = _heroData Util.GetGameObject(go.transform, "frame"):GetComponent("Image").sprite = Util.LoadSprite(GetHeroQuantityImageByquality(HeroConfig[heroData.id].Quality,heroData.star)) Util.GetGameObject(go.transform, "lv/Text"):GetComponent("Text").text = heroData.lv Util.GetGameObject(go.transform, "icon"):GetComponent("Image").sprite = Util.LoadSprite(heroData.icon) Util.GetGameObject(go.transform, "posIcon"):SetActive(false) Util.GetGameObject(go.transform, "proIcon"):GetComponent("Image").sprite = Util.LoadSprite(GetProStrImageByProNum(HeroConfig[heroData.id].PropertyName)) Util.GetGameObject(go.transform, "Text"):GetComponent("Text").text = heroData.name local formationMask = Util.GetGameObject(go.transform, "formationMask") local formationImage = Util.GetGameObject(go.transform, "formationMask/formationImage/upImage"):GetComponent("Image") if #heroData.formationList ~= 0 then formationMask:SetActive(true) formationImage.sprite = Util.LoadSprite("t_tongyong-yishangzheng") elseif heroData.lockState == 1 then formationMask:SetActive(true) formationImage.sprite = Util.LoadSprite("r_hero_suodi_yisuoding") else formationMask:SetActive(false) end local starGrid = Util.GetGameObject(go.transform, "star") SetHeroStars(starGrid, heroData.star,1,nil,nil,Vector2.New(0,1)) local cardBtn = Util.GetGameObject(go.transform, "icon") local choosed = Util.GetGameObject(go.transform, "choosed") choosed:SetActive(false) this.replaceBtn:SetActive(true) this.cancelBtn:SetActive(false) this.saveBtn:SetActive(false) this.needBg:SetActive(true) this.replaceBg:SetActive(true) this.text:SetActive(true) this.cost:SetActive(false) Util.AddOnceClick(cardBtn, function() if heroData.dynamicId == curSelectHero.dynamicId then choosed:SetActive(false) curSelectHero = {} this.needHero:SetActive(false) this.replaceHero:SetActive(false) this.cancelBtn:SetActive(false) this.saveBtn:SetActive(false) this.replaceBtn:SetActive(true) this.needBg:SetActive(true) this.replaceBg:SetActive(true) this.text:SetActive(true) this.cost:SetActive(false) else choosed:SetActive(true) curSelectHero = heroData this.ShowCostInfo() this.needHero:SetActive(true) this.replaceHero:SetActive(false) this.needBg:SetActive(false) this.replaceBg:SetActive(true) this.text:SetActive(false) this.cost:SetActive(true) this.SetHero(this.needHero,curSelectHero) --如果已经有了置换Id if curSelectHero.changeId ~=0 then this.cancelBtn:SetActive(true) this.replaceBtn:SetActive(false) this.saveBtn:SetActive(true) this.replaceHero:SetActive(true) this.needBg:SetActive(false) this.replaceBg:SetActive(false) this.text:SetActive(false) this.cost:SetActive(false) local data = this.RebuildData(curSelectHero.changeId) this.SetHero(this.replaceHero,data) else this.cancelBtn:SetActive(false) this.replaceBtn:SetActive(true) this.saveBtn:SetActive(false) this.replaceHero:SetActive(false) this.needBg:SetActive(false) this.replaceBg:SetActive(true) this.text:SetActive(false) this.cost:SetActive(true) end end for i = 1, #heroDatas do if heroSelectBtn[i] and heroDatas[i] then heroSelectBtn[i]:SetActive(heroDatas[i].dynamicId == curSelectHero.dynamicId) end end end) Util.AddOnceClick(formationMask, function() if #heroData.formationList ~= 0 then local text = "" for index, value in ipairs(heroData.formationList) do text = HeroManager.GetHeroFormationStr(index) end PopupTipPanel.ShowTip(text) return end if heroData.lockState == 1 then PopupTipPanel.ShowTip("目标神将已被锁定,无法置换!") return end end) Util.AddLongPressClick(cardBtn, function() UIManager.OpenPanel(UIName.RoleInfoPopup, heroData) end, 0.5) end --刷新中间按钮和显示 function this.refresh() -- body end --设置两个英雄,左右不确定 function this.SetHero(go,heroData) local hero = Util.GetGameObject(go, "Hero1") local herobg=Util.GetGameObject(hero,"Bg1"):GetComponent("Image") local herolv=Util.GetGameObject(hero,"lv/Text"):GetComponent("Text") local herofg=Util.GetGameObject(hero,"Bg2"):GetComponent("Image") local heropro=Util.GetGameObject(hero,"Pro/Image"):GetComponent("Image") local herostarGrid=Util.GetGameObject(hero,"StarGrid") local heroname=Util.GetGameObject(hero,"Name/Text"):GetComponent("Text") local heroyuanImage=Util.GetGameObject(hero,"yuanImage") local herolive = Util.GetGameObject(hero, "Mask/icon"):GetComponent("RawImage") local herozs = Util.GetGameObject(hero, "zs") Util.GetGameObject(hero,"hpProgress").gameObject:SetActive(false) Util.GetGameObject(hero,"rageProgress").gameObject:SetActive(false) Util.GetGameObject(hero,"UI_Effect_jinkuang_KaPai").gameObject:SetActive(false) herobg.sprite = Util.LoadSprite(GetHeroCardStarBg[heroData.star]) local roleConfig = ConfigManager.GetConfigData(ConfigName.RoleConfig, heroData.id) local scale = roleConfig.play_liveScale local livePos = Vector3.New(roleConfig.offset[1], roleConfig.offset[2], 0) if go == this.needHero then herolive.texture = CardRendererManager.GetSpineTexture(1, heroData.live, Vector3.one * scale, livePos, true) else herolive.texture = CardRendererManager.GetSpineTexture(2, heroData.live, Vector3.one * scale, livePos, true) end herolive.transform.localScale = Vector3.one herolive.transform.localPosition = Vector3.zero local zsName = GetHeroCardStarZs[heroData.star] if zsName == "" then herozs:SetActive(false) else herozs:SetActive(true) herozs:GetComponent("Image").sprite = Util.LoadSprite(zsName) end heroyuanImage:SetActive(heroData.createtype == 1) herolv.text=heroData.lv herofg.sprite = Util.LoadSprite(GetHeroCardStarFg[heroData.star]) heropro.sprite=Util.LoadSprite(GetProStrImageByProNum(heroData.property)) SetCardStars(herostarGrid,heroData.star) if heroData.star > 9 then Util.GetGameObject(go,"UI_Effect_jinkuang_KaPai").gameObject:SetActive(true) else Util.GetGameObject(go,"UI_Effect_jinkuang_KaPai").gameObject:SetActive(false) end heroname.text=heroData.name end --设置阵营按钮选中 function this.SetBtnSelect(_parObj) this.selectBtn.transform:SetParent(_parObj.transform) this.selectBtn.transform.localScale = Vector3.one this.selectBtn.transform.localPosition=Vector3.zero end function this.ShowCostInfo() local replaceItemIdConfig = ConfigManager.GetConfigData(ConfigName.SpecialConfig,68) local replaceCostConfig = ConfigManager.GetConfigData(ConfigName.SpecialConfig,69) if replaceItemIdConfig then this.text:GetComponent("Text").text = BagManager.GetItemCountById(tonumber(replaceItemIdConfig.Value)) end if curSelectHero and replaceCostConfig then local getCostByStar = string.split(replaceCostConfig.Value,"|") if curSelectHero.star == 4 then this.costText.text = string.split(getCostByStar[1],"#")[2] elseif curSelectHero.star == 5 then this.costText.text = string.split(getCostByStar[2],"#")[2] end end end function this:OnClose() curSelectHero = {} curSelectHeroConfig = {} this.replaceHero:SetActive(false) this.needHero:SetActive(false) end function this:OnDestroy() end return this