sk-client/Assets/ManagedResources/~Lua/Modules/FormationCenter/FormationCenterPanel.lua

330 lines
12 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

require("Base/BasePanel")
FormationCenterPanel = Inherit(BasePanel)
local this = FormationCenterPanel
local propertyConfig = ConfigManager.GetConfig(ConfigName.PropertyConfig)
local investigateConfig = ConfigManager.GetConfig(ConfigName.InvestigateConfig)
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local lv = 1
local isCanUp = true
this.costItem = {}
local itemList = {}
local proList = {}
--初始化组件(用于子类重写)
function FormationCenterPanel:InitComponent()
this.btnBack = Util.GetGameObject(self.gameObject, "btnBack")
this.btnHelp = Util.GetGameObject(self.gameObject, "btnHelp")
this.btnShop = Util.GetGameObject(self.gameObject, "btnShop")
this.btnUp = Util.GetGameObject(self.gameObject, "btnUp")
this.cost = Util.GetGameObject(self.gameObject, "cost")
this.reward = Util.GetGameObject(self.gameObject, "reward")
this.upLvPanel = Util.GetGameObject(self.gameObject, "upLvPanel")
this.upLvInfo = Util.GetGameObject(self.gameObject, "upLvInfo")
this.renovationPanel = Util.GetGameObject(self.gameObject, "renovationPanel")
this.renovationInfo = Util.GetGameObject(self.gameObject, "renovationInfo")
this.tip = Util.GetGameObject(self.gameObject, "tip/Text"):GetComponent("Text")
this.posList = {}
for i = 1, 5 do
this.posList[i] = Util.GetGameObject(self.gameObject, "renovationPanel/renovation/pos"..i)
end
-- this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.transform)
end
--绑定事件(用于子类重写)
function FormationCenterPanel:BindEvent()
Util.AddClick(this.btnBack,function ()
self:ClosePanel()
end)
Util.AddClick(this.btnUp,function ()
local oldPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
NetManager.FormationCenterActiveRequest(function (msg)
local index
local type = investigateConfig[lv].Type
if type == 1 then
if msg.success then
index = 1
else
index = 2
end
elseif type == 2 then
if msg.success then
index = 3
else
index = 4
end
end
FormationCenterManager.SetInvestigateLevel(msg, function ()
if index == 4 then
PopupTipPanel.ShowTipByLanguageId(50404)
else
UIManager.OpenPanel(UIName.FormationCenterUpPanel, index, lv)
end
this:OnShow()
FormationManager.FlutterPower(oldPower)
end)
end)
end)
Util.AddClick(this.btnShop,function ()
UIManager.OpenPanel(UIName.MapShopPanel, FormationCenterManager.GetStoreId())
end)
Util.AddClick(this.btnHelp,function ()
local pos = this.btnHelp:GetComponent("RectTransform").localPosition
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.Investigate, pos.x, pos.y)
end)
end
--添加事件监听(用于子类重写)
function FormationCenterPanel:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.FormationCenter.OnFormationCenterLevelChange, this.OnShow)
end
--移除事件监听(用于子类重写)
function FormationCenterPanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.FormationCenter.OnFormationCenterLevelChange, this.OnShow)
end
--界面打开时调用(用于子类重写)
function FormationCenterPanel:OnOpen()
end
local btnImg = {
GetPictureFont("X1_bt_qimingxing_bt_02"),
GetPictureFont("X1_bt_qimingxing_bt_01"),
}
function FormationCenterPanel:OnShow()
-- this.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.Main })
lv = FormationCenterManager.GetInvestigateLevel()
--LogError("启明星等级4"..tostring(lv))
local type = investigateConfig[lv].Type
isCanUp = investigateConfig[lv].NextLevel > 0
this.SetBasicInfo(type)
this.SetReward()
this.SetProInfo(type)
this.SetCost()
this.cost:SetActive(isCanUp)
this.btnUp:SetActive(isCanUp)
Util.GetGameObject(self.gameObject, "tip"):SetActive(isCanUp)
Util.GetGameObject(this.renovationInfo, "canUp"):SetActive(isCanUp)
Util.GetGameObject(this.renovationInfo, "proScroll"):GetComponent("RectMask2D").enabled = isCanUp
Util.GetGameObject(this.renovationInfo, "scrollMask"):SetActive(not isCanUp)
--LogError(type)
if isCanUp then
if type == 1 then
this.tip.text = string.format(GetLanguageStrById(50402), investigateConfig[lv].FallbackId)
elseif type == 2 then
this.tip.text = string.format(GetLanguageStrById(50403), tostring(investigateConfig[lv].ExtraRules[2]/100).."%")
end
this.btnUp:GetComponent("Image").sprite = Util.LoadSprite(btnImg[type])
end
end
--界面关闭时调用(用于子类重写)
function FormationCenterPanel:OnClose()
end
--界面销毁时调用(用于子类重写)
function FormationCenterPanel:OnDestroy()
this.costItem = {}
-- SubUIManager.Close(this.UpView)
itemList = {}
proList = {}
end
function this.SetUpLvInfo()
end
function this.SetBasicInfo(type)
local go
if type == 1 then
go = this.upLvPanel
elseif type == 2 then
go = this.renovationPanel
end
this.upLvPanel:SetActive(type == 1)
this.renovationPanel:SetActive(type == 2)
local icon = Util.GetGameObject(go, "icon"):GetComponent("Image")
local name = Util.GetGameObject(go, "name"):GetComponent("Text")
local star = Util.GetGameObject(go, "star")
local btnPreview = Util.GetGameObject(go, "btnPreview")
icon.sprite = Util.LoadSprite(GetResourcePath(investigateConfig[lv].ArtResourcesId))
name.text = GetLanguageStrById(investigateConfig[lv].Name)
SetHeroStars(star, investigateConfig[lv].StarShow, 1.2)
Util.AddOnceClick(btnPreview, function ()
UIManager.OpenPanel(UIName.FormationCenterTipPanel)
end)
end
function this.SetReward()
local icon = Util.GetGameObject(this.reward, "icon"):GetComponent("Image")
local num = Util.GetGameObject(this.reward, "num"):GetComponent("Text")
local rewardConfig = investigateConfig[lv].DailyReward
icon.sprite = Util.LoadSprite(GetResourcePath(itemConfig[rewardConfig[1][1]].ResourceID))
num.text = rewardConfig[1][2]
Util.AddOnceClick(icon.gameObject, function ()
UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, rewardConfig[1][1])
end)
end
function this.SetProInfo(type)
local go
if type == 1 then
go = this.upLvInfo
elseif type == 2 then
go = this.renovationInfo
end
this.upLvInfo:SetActive(type == 1)
this.renovationInfo:SetActive(type == 2)
local cur = Util.GetGameObject(go, "cur")
local next = Util.GetGameObject(go, "next")
local gird = Util.GetGameObject(go, "scroll/grid")
local pre = Util.GetGameObject(go, "scroll/grid/pre")
if isCanUp then
this.SetPro(go, gird, pre)
end
if type == 1 then
SetHeroStars(cur, investigateConfig[lv].StarShow, 1.2)
if isCanUp then
SetHeroStars(next, investigateConfig[investigateConfig[lv].NextLevel].StarShow, 1.2)
end
elseif type == 2 then
cur:GetComponent("Text").text = string.format(GetLanguageStrById(50401), lv-9)
next:GetComponent("Text").text = string.format(GetLanguageStrById(50401), lv-8)
this.SetAllPro()
Util.GetGameObject(go, "icon"):GetComponent("Image").sprite = Util.LoadSprite(GetResourcePath(investigateConfig[lv].ArtResourcesIconId))
for i = 1, 5 do
if isCanUp then
local stage = (lv-10)%5
if i <= stage then
Util.GetGameObject(this.posList[i], "lv"):GetComponent("Text").text = Mathf.Floor((lv-10)/5)+1
else
Util.GetGameObject(this.posList[i], "lv"):GetComponent("Text").text = Mathf.Floor((lv-10)/5)
end
Util.GetGameObject(this.posList[i], "select"):SetActive(i == stage+1)
else
Util.GetGameObject(this.posList[i], "select"):SetActive(true)
end
end
end
end
function this.SetCost()
if not isCanUp then
return
end
local pos = Util.GetGameObject(this.cost, "pos")
local probability = Util.GetGameObject(this.cost, "probability"):GetComponent("Text")
local costConfig = investigateConfig[lv].Consume
for i = 1, #this.costItem do
this.costItem[i].gameObject:SetActive(false)
end
for i = 1, #costConfig do
if not this.costItem[i] then
this.costItem[i] = SubUIManager.Open(SubUIConfig.ItemView, pos.transform)
end
this.costItem[i]:OnOpen(false, {costConfig[i][1], costConfig[i][2]}, 0.6)
this.costItem[i]:SetColorNum(costConfig[i][1], costConfig[i][2])
this.costItem[i].gameObject:SetActive(true)
end
local failTime = FormationCenterManager.GetFailTimes()
local ExtraRules = investigateConfig[lv].ExtraRules
local rate = tostring(investigateConfig[lv].RateShow/100).."%"
if ExtraRules[1] == 1 then
if failTime >= ExtraRules[2] then
probability.text = tostring(ExtraRules[3]/100).."%"
else
probability.text = rate
end
elseif ExtraRules[1] == 2 then
if failTime > 0 then
local p = failTime*ExtraRules[2]/100
probability.text = rate.."<color=#ffd12b>+"..p.."%</color>"
else
probability.text = rate
end
end
end
function this.SetPro(go, grid, pre)
if not isCanUp then
return
end
if not itemList[go] then
itemList[go] = {}
end
for i = 1, #itemList[go] do
itemList[go][i]:SetActive(false)
end
local curData = investigateConfig[lv].PropertyAdd
local nextData = investigateConfig[investigateConfig[lv].NextLevel].PropertyAdd
for i = 1, #nextData do
if not itemList[go][i] then
itemList[go][i] = newObjToParent(pre, grid.transform)
end
local icon = Util.GetGameObject(itemList[go][i], "icon/Image"):GetComponent("Image")
local name = Util.GetGameObject(itemList[go][i], "icon/Text"):GetComponent("Text")
local cur = Util.GetGameObject(itemList[go][i], "cur/Text"):GetComponent("Text")
local next = Util.GetGameObject(itemList[go][i], "next/Text"):GetComponent("Text")
local bg = Util.GetGameObject(itemList[go][i], "bg")
if go == this.renovationInfo then
bg:SetActive(false)
else
bg:SetActive(i%2 == 0)
end
icon.sprite = Util.LoadSprite(propertyConfig[nextData[i][1]].Icon)
name.text = GetLanguageStrById(propertyConfig[nextData[i][1]].Info)
local p
for k = 1, #curData do
if curData[k][1] == nextData[i][1] then
p = curData[k]
break
end
end
if p then
cur.text = "+"..GetPropertyFormatStr(propertyConfig[p[1]].Style, p[2])
else
cur.text = ""
end
local str = "+"..GetPropertyFormatStr(propertyConfig[nextData[i][1]].Style, nextData[i][2])
if p and nextData[i][2] == p[2] then
next.text = "<color=#ffffff>"..str.."</color>"
if go == this.renovationInfo then
itemList[go][i]:SetActive(false)
else
itemList[go][i]:SetActive(true)
end
else
next.text = "<color=#ffd12b>"..str.."</color>"
itemList[go][i]:SetActive(true)
end
end
end
function this.SetAllPro()
local gird = Util.GetGameObject(this.renovationInfo, "proScroll/pro")
local pre = Util.GetGameObject(this.renovationInfo, "proScroll/pro/pre")
local curData = investigateConfig[lv].PropertyAdd
for i = 1, #curData do
if not proList[i] then
proList[i] = newObjToParent(pre, gird.transform)
end
local icon = Util.GetGameObject(proList[i], "icon"):GetComponent("Image")
local name = Util.GetGameObject(proList[i], "name"):GetComponent("Text")
local value = Util.GetGameObject(proList[i], "value"):GetComponent("Text")
icon.sprite = Util.LoadSprite(propertyConfig[curData[i][1]].Icon)
name.text = GetLanguageStrById(propertyConfig[curData[i][1]].Info)
value.text = "+"..GetPropertyFormatStr(propertyConfig[curData[i][1]].Style, curData[i][2])
proList[i]:SetActive(true)
end
end
return FormationCenterPanel