miduo_client/Assets/ManagedResources/~Lua/Modules/Operating/GMChangePanel.lua

557 lines
22 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")
GMChangePanel = Inherit(BasePanel)
local this = GMChangePanel
local GMInfo = ConfigManager.GetConfig(ConfigName.GMInfo)
local GMMaster = ConfigManager.GetConfig(ConfigName.GMMaster)
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local rechargeCommodityConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig)
local icons = { "gm_shuachong_scGM_02_zh", "gm_shuachong_cjGM_02_zh", "gm_shuachong_sjGM_02_zh",
"gm_shuachong_wsGM_02_zh" }
local gmName = { Language[11966], Language[11967], Language[11968], Language[11969] }
local sortingOrder = 0
local isFirst = true
local curBtn = nil
local curConfig = nil
local turnsInfo = {
--[1]={name="GM商城",id=108, priId=2204,priName="天选GM"},
[1] = { name = Language[11970], id = 109, priId = 2201, priName = Language[11966] },
[2] = { name = Language[11971], id = 110, priId = 2202, priName = Language[11967] },
[3] = { name = Language[11972], id = 111, priId = 2203, priName = Language[11968] },
[4] = { name = Language[11973], id = 112, priId = 2204, priName = Language[11969] },
}
local gmTipInfo = {
--[0]={name="白嫖商城",id=102,priId=2201,priName="刷充GM"},
[1] = { name = Language[11971], id = 110, priId = 2202, priName = Language[11967] },
[2] = { name = Language[11972], id = 111, priId = 2203, priName = Language[11968] },
[3] = { name = Language[11973], id = 112, priId = 2204, priName = Language[11969] },
}
local ShopType = 0
local curShopIndex = 0
--初始化组件(用于子类重写)
function GMChangePanel:InitComponent()
this.spLoader = SpriteLoader.New()
--定义头部文字和按钮
this.curTxt = Util.GetGameObject(self.gameObject, "layout/top/value1"):GetComponent("Text")
this.addTxt = Util.GetGameObject(self.gameObject, "layout/top/value2"):GetComponent("Text")
this.btn_add = Util.GetGameObject(self.gameObject, "layout/top/btn_chong")
this.gmIcon = Util.GetGameObject(self.gameObject, "layout/top/Image"):GetComponent("Image")
this.gmName = Util.GetGameObject(self.gameObject, "layout/top/name"):GetComponent("Text")
this.btn_up = Util.GetGameObject(self.gameObject, "layout/top/btn_up")
this.progress = Util.GetGameObject(self.gameObject, "layout/top/progress")
this.progressTxt = Util.GetGameObject(self.gameObject, "layout/top/progress/value"):GetComponent("Text")
this.progressBar = Util.GetGameObject(self.gameObject, "layout/top/progress/progressBar"):GetComponent("Image")
this.progressBar.fillAmount = 0
--滚动条和预设
--self.scrollItem = Util.GetGameObject(self.gameObject, "rzyBg/scrollItem")
this.itemPre = Util.GetGameObject(self.gameObject, "layout/tabBtnPre")
this.grid = Util.GetGameObject(self.gameObject, "layout/tabScroll/grid")
this.btn_close = Util.GetGameObject(self.gameObject, "layout/backBtn")
this.selectBtn = Util.GetGameObject(self.gameObject, "layout/tabSelectBtn")
this.selectBtnText = Util.GetGameObject(self.gameObject, "layout/tabSelectBtn/Text"):GetComponent("Text")
this.shopItemPre = Util.GetGameObject(self.gameObject, "layout/shopItemPre")
this.scroll = Util.GetGameObject(self.gameObject, "layout/scroll")
this.hint = Util.GetGameObject(self.gameObject, "layout/hint"):GetComponent("Text")
this.info = Util.GetGameObject(self.gameObject, "layout/top/Text (1)"):GetComponent("Text")
this.shopInfo = Util.GetGameObject(self.gameObject, "layout/shopInfo")
this.btn_oneKey = Util.GetGameObject(self.gameObject, "layout/shopInfo/btn_oneKey")
this.gmBtns = {}
for i = 1, 4 do
this.gmBtns[i] = {}
this.gmBtns[i].btn = Util.GetGameObject(this.shopInfo, "Top/btn" .. i)
this.gmBtns[i].selectImg = Util.GetGameObject(this.shopInfo, "Top/btn" .. i .. "/SelectBG")
this.gmBtns[i].selectImg:SetActive(false)
this.gmBtns[i].nameTxt = Util.GetGameObject(this.shopInfo, "Top/btn" .. i .. "/Text"):GetComponent("Text")
this.gmBtns[i].nameTxt.text = turnsInfo[i].name
this.gmBtns[i].red = Util.GetGameObject(this.shopInfo, "Top/btn" .. i .. "/redPoint")
end
--设置滚动条
local rootHight = this.scroll.transform.rect.height
local width = this.scroll.transform.rect.width
this.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scroll.transform,
this.shopItemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 5), false)
this.scrollView.moveTween.MomentumAmount = 1
this.scrollView.moveTween.Strength = 2
for k, v in ConfigPairs(GMInfo) do
if v.IsOpen == 1 then
local tabBtn = newObjToParent(this.itemPre, this.grid)
Util.GetGameObject(tabBtn, "Text"):GetComponent("Text").text = GetLanguageStrById(v.Name)
Util.AddClick(tabBtn, function()
this.TabBtnOnClick(tabBtn, v)
end)
if isFirst then
--this.TabBtnOnClick(tabBtn,v)
curBtn = tabBtn
curConfig = v
isFirst = false
end
end
end
this.itemPre = Util.GetGameObject(self.gameObject, "layout/shopInfo/scrollroot/shopItem")
this.grid = Util.GetGameObject(self.gameObject, "layout/shopInfo/scrollroot")
local rootHight = self.grid.transform.rect.height
local width = self.grid.transform.rect.width
this.shopScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.grid.transform, this.itemPre, nil,
Vector2.New(width, rootHight), 1, 3, Vector2.New(40, 20))
this.shopScrollView.moveTween.MomentumAmount = 1
this.shopScrollView.moveTween.Strength = 2
end
-- 商店物品数据匹配
function this.ShopItemAdapter(shopItem, itemData)
-- 获取对象
local effect = Util.GetGameObject(shopItem, "Fx_SquareFlow")
effect.gameObject:SetActive(false)
Util.SetParticleSortLayer(effect, this.sortingOrder + 1)
local bg = Util.GetGameObject(shopItem, "GameObject/bg")
local item = Util.GetGameObject(bg, "item")
local itemName = Util.GetGameObject(bg, "itemName"):GetComponent("Text")
local itemDes = Util.GetGameObject(bg, "itemDes"):GetComponent("Text")
local limitBg = Util.GetGameObject(bg, "buyLimitbg")
local limitTip = Util.GetGameObject(limitBg, "tip"):GetComponent("Text")
local priceBg = Util.GetGameObject(bg, "pricebg")
local itemPrice = Util.GetGameObject(bg, "pricebg/price"):GetComponent("Text")
local costIcon = Util.GetGameObject(bg, "pricebg/costIcon"):GetComponent("Image")
local discountbg = Util.GetGameObject(bg, "discountbg")
local empty = Util.GetGameObject(shopItem, "empty")
local yihuode = Util.GetGameObject(shopItem, "yihuode")
local lock = Util.GetGameObject(shopItem, "lock")
local lockTip = Util.GetGameObject(shopItem, "lock/tip"):GetComponent("Text")
local new = Util.GetGameObject(shopItem, "GameObject/new")
new:SetActive(false)
-- 计算数据
local itemInfo = ShopManager.GetShopItemInfo(itemData.id)
local curBuyCount = itemData.buyNum
local maxLimitCount = ShopManager.GetShopItemLimitBuyCount(itemData.id)
local costId, price = ShopManager.calculateBuyCost(ShopType, itemData.id, 1)
local goods = ShopManager.GetShopItemGoodsInfo(itemData.id)
local con = ConfigManager.GetConfigData(ConfigName.ItemConfig, goods[1][1])
itemName.text = SubString2(GetLanguageStrById(con.Name), 8)
if con.ItemType == ItemType.LingShouChip then
local haveCount = BagManager.GetTotalItemNum(con.Id)
itemName.text = itemName.text ..
"\n" ..
string.format("<color=%s><size=%s>%s(%s/%s)</size></color>", UIColorStr.BLACK, "25", Language[11974],
haveCount,
con.UsePerCount)
end
if con.ItemType == ItemType.Talisman then
itemDes.gameObject:SetActive(true)
if con.ItemDescribe then
local str = string.split(GetLanguageStrById(con.ItemDescribe), '')
if str[1] then
itemDes.text = str[1]
end
else
itemDes.gameObject:SetActive(false)
end
else
itemDes.gameObject:SetActive(false)
end
--LogError("RelatedtoVIP====================="..itemInfo.RelatedtoVIP)
--itemInfo.GoodsName
-- 折扣
if price == 0 then
discountbg:SetActive(true)
discountbg:GetComponent("Image").sprite = this.spLoader:LoadSprite("s_shop_zhekou_00_zh")
else
local isDiscount = itemInfo.IsDiscount == 1
discountbg:SetActive(isDiscount)
if isDiscount then
discountbg:GetComponent("Image").sprite = this.spLoader:LoadSprite("s_shop_zhekou_0" ..
itemInfo.DiscountDegree .. "_zh")
end
end
-- 消耗物品的信息
itemPrice.text = PrintWanNum2(tonumber(price)) --tostring(price)
costIcon.sprite = SetIcon(this.spLoader, costId)
-- 判断商品栏位是否解锁
local _IsUnLock = true
if ShopType == SHOP_TYPE.GUILD_SHOP then
local isUnLock, unLockLevel = MyGuildManager.GetGuildShopSortIsUnLock(itemInfo.Sort)
if not isUnLock then
_IsUnLock = false
lockTip.text = string.format(Language[11975], unLockLevel)
end
end
lock:SetActive(not _IsUnLock)
priceBg.gameObject:SetActive(_IsUnLock)
itemName.gameObject:SetActive(_IsUnLock)
-- -- 限购
limitBg:SetActive(maxLimitCount ~= -1)
if itemInfo.RelatedtoVIP == 1 then
limitTip.text = Language[10562] .. " " .. maxLimitCount .. Language[10048]
else
limitTip.text = Language[11976] .. " " .. maxLimitCount .. Language[10048]
end
SetTextVerTial(limitTip, Vector3.New(12.65, -4.2, 0), "MiddleLeft")
-- 售空 限购次数为-1 表示不限购
--LogError("curBuyCount=============="..curBuyCount.." maxLimitCount=="..maxLimitCount)
local isEmpty = maxLimitCount ~= -1 and curBuyCount >= maxLimitCount
if curBuyCount >= maxLimitCount then
empty:SetActive(true)
else
empty:SetActive(false)
end
empty:SetActive(isEmpty)
-- 数据匹配
if not this._GoodsItemList then
this._GoodsItemList = {}
end
if not this._GoodsItemList[shopItem] then
this._GoodsItemList[shopItem] = SubUIManager.Open(SubUIConfig.ItemView, item.transform)
end
Util.SetGray(this._GoodsItemList[shopItem].gameObject, not _IsUnLock)
if isEmpty or not _IsUnLock then -- 物品空或者未解锁不现实物品特效
this._GoodsItemList[shopItem]:OnOpen(false, goods[1], 1, false, false, false)
else
this._GoodsItemList[shopItem]:OnOpen(false, goods[1], 1, false, false, false, this.sortingOrder)
end
-- 商品颜色显示
local imgColor = isEmpty and Color.New(0.5, 0.5, 0.5, 1) or Color.New(1, 1, 1, 1)
local textA = isEmpty and 0.7 or 1
Util.SetColor(bg, imgColor)
this.SetAlpha(itemName, textA)
--SetAlpha(limitTip, textA)
this.SetAlpha(itemPrice, textA)
local isshow = false
yihuode.gameObject:SetActive(false)
-- 购买事件
Util.AddOnceClick(lock, function()
PopupTipPanel.ShowTip(Language[11977])
end)
Util.AddOnceClick(empty, function()
PopupTipPanel.ShowTip(Language[11978])
end)
Util.AddOnceClick(bg, function()
-- 售空
if isEmpty then
PopupTipPanel.ShowTip(Language[11978])
return
end
if not _IsUnLock then
PopupTipPanel.ShowTip(Language[11977])
return
end
local storeConfig = ConfigManager.GetConfigData(ConfigName.StoreConfig, itemData.id)
if storeConfig and storeConfig.BuyRule then
local lv = storeConfig.BuyRule[2]
LogError("lv===========" .. lv)
if gmTipInfo[lv] then
if OperatingManager.IsBuyGift(gmTipInfo[lv].priId) == false then
PopupTipPanel.ShowTip(Language[11979] .. gmTipInfo[lv].priName .. Language[11980])
return
end
end
end
UIManager.OpenPanel(UIName.ShopBuyPopup, ShopType, itemData.id)
end)
end
-- 设置文本透明度
function this.SetAlpha(text, a)
local color = text.color
color.a = a
text.color = color
end
---重置默认
function this.ClearDefault()
for i = 1, 4 do
this.gmBtns[i].selectImg:SetActive(false)
this.gmBtns[i].nameTxt.color = Color.New(0.71, 0.64, 0.51, 1)
end
end
--刷新商店显示
local RefreshShopShow = function(self)
local num = BagManager.GetItemCountById(1367)
this.curTxt.text = num .. Language[10497]
this.SwitchShop(curShopIndex)
end
--绑定事件(用于子类重写)
function GMChangePanel:BindEvent()
Util.AddClick(this.btn_close, function()
self:ClosePanel()
end)
Util.AddClick(this.btn_add, function()
UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, 1342)
end)
Util.AddClick(this.btn_up, function()
UIManager.OpenPanel(UIName.GMShuaChongTeQuan)
end)
for i = 1, 4 do
Util.AddClick(this.gmBtns[i].btn, function()
this.SwitchShop(i)
end)
end
Util.AddClick(this.btn_oneKey, function()
if gmTipInfo[curShopIndex - 2] and OperatingManager.IsBuyGift(gmTipInfo[curShopIndex - 2].priId) == false then
PopupTipPanel.ShowTip(Language[11979] .. gmTipInfo[curShopIndex - 2].priName .. Language[11980])
return
end
local sureFunc = function()
NetManager.StoreOneClickPurchaseRequest(turnsInfo[curShopIndex].id, function()
RefreshShopShow()
end)
end
local args = {}
args[1] = Language[11981]
args[2] = Language[11939]
args[3] = Language[10685]
args[4] = sureFunc
UIManager.OpenPanel(UIName.GMCommonConfirmPanel, args)
end)
end
function this.SwitchShop(index)
this.ClearDefault()
if index == 1 then
this.btn_oneKey:SetActive(false)
else
this.btn_oneKey:SetActive(true)
end
this.gmBtns[index].selectImg:SetActive(true)
this.gmBtns[index].nameTxt.color = Color.New(1, 0.95, 0.85, 1)
ShopType = turnsInfo[index].id
curShopIndex = index
local list = ShopManager.GetShopDataByType(turnsInfo[index].id).storeItem
this.shopScrollView:SetData(list, function(index, go)
this.ShopItemAdapter(go, list[index])
end, false)
end
--添加事件监听(用于子类重写)
function GMChangePanel:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Shop.OnShopInfoChange, RefreshShopShow, self)
end
--移除事件监听(用于子类重写)
function GMChangePanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Shop.OnShopInfoChange, RefreshShopShow, self)
end
--界面打开时调用(用于子类重写)
function GMChangePanel:OnOpen(activityId)
this:ShowTopInfo()
end
function GMChangePanel:OnFocus()
this:ShowTopInfo()
end
function GMChangePanel:ShowTopInfo()
local num = BagManager.GetItemCountById(1367)
this.info.text = Language[11982]
local allTimes = PrivilegeManager.GetPrivilegeNumber(PRIVILEGE_TYPE.GM_YI_YUAN_UP_TIME)
local useTime = PrivilegeManager.GetPrivilegeUsedTimes(PRIVILEGE_TYPE.GM_YI_YUAN_UP_TIME)
local leftTimes = PrivilegeManager.GetPrivilegeRemainValue(PRIVILEGE_TYPE.GM_YI_YUAN_UP_TIME)
LogError("allTimes==" .. allTimes .. " leftTimes==" .. leftTimes .. " useTime" .. useTime)
this.curTxt.text = num .. Language[10497]
local maxnum = 100
local missions = ActivityGiftManager.GetActivityInfoByType(ActivityTypeDef.shuaChongTeQuan).mission
local index = 1
if missions then
for i = 1, #missions do
if missions[i].state ~= 0 then
index = i
end
end
end
this.gmIcon.sprite = this.spLoader:LoadSprite("r_RareItem_Recipe_0001")
this.gmName.text = gmName[index]
local privile = ConfigManager.GetConfigData(ConfigName.PrivilegeTypeConfig, 2101)
if privile then
maxnum = privile.Condition[index][2]
if maxnum ~= -1 then
this.progress:SetActive(true)
this.addTxt.text = maxnum - useTime .. Language[10497]
this.progressBar.fillAmount = useTime / maxnum
this.progressTxt.text = useTime .. "/" .. maxnum
else
this.progress:SetActive(false)
this.addTxt.text = Language[11983]
end
end
end
function this.TabBtnOnClick(btn, config)
curBtn = btn
curConfig = config
--local _level=_privilegeLv>0 and _privilegeLv or 1
--local clickBtn=this.tabGrid.transform:GetChild(_level-1)
this.selectBtn.transform:SetParent(btn.gameObject.transform)
this.selectBtn.transform.localScale = Vector3.one
this.selectBtn.transform.localPosition = Vector3.zero
this.selectBtnText.text = GetLanguageStrById(config.Name)
--this.UpdateLayout(_level)
local dataList = {}
local aa = config.Unlock[1]
local isOpen, tip = CheckGMIsOpen(aa[1], aa[2])
if config.Type == 15 then
this.shopInfo:SetActive(true)
this.scroll:SetActive(false)
this.SwitchShop(1)
else
this.shopInfo:SetActive(false)
this.scroll:SetActive(true)
end
this.hint.gameObject:SetActive(false)
this.scroll:SetActive(true)
for k, v in ConfigPairs(GMMaster) do
if v.Type == config.Type then
table.insert(dataList, v)
end
end
this.scrollView:SetData(dataList, function(index, rewardItem)
this:SingleTask(rewardItem, dataList[index], isOpen, tip)
end, not false, not false)
end
function GMChangePanel:SingleTask(go, data, isOpen, tip)
local name = Util.GetGameObject(go, "name"):GetComponent("Text")
local num = Util.GetGameObject(go, "num"):GetComponent("Text")
local itemDes = Util.GetGameObject(go, "item"):GetComponent("Text")
local btn = Util.GetGameObject(go, "btn")
local btnTxt = Util.GetGameObject(go, "btn/Text"):GetComponent("Text")
local priceTxt = Util.GetGameObject(go, "price"):GetComponent("Text")
local limitTxt = Util.GetGameObject(go, "limit"):GetComponent("Text")
local recharge = rechargeCommodityConfig[data.PackID]
local scale = 1
btn:SetActive(true)
limitTxt.gameObject:SetActive(false)
priceTxt.gameObject:SetActive(true)
if data.PackID ~= 0 and recharge then
name.text = GetLanguageStrById(recharge.Name)
priceTxt.gameObject:SetActive(isOpen)
limitTxt.gameObject:SetActive(not isOpen)
btn:SetActive(isOpen)
limitTxt.text = tip
--LogError("type=="..recharge.Type.." id=="..recharge.Id)
local leftBuyTime = OperatingManager.GetLeftBuyTime(recharge.Type, recharge.Id)
if leftBuyTime == -1 then
num.text = ""
else
num.text = "(" .. leftBuyTime .. "/" .. recharge.Limit .. ")"
end
btn:GetComponent("Button").interactable = leftBuyTime == -1 or leftBuyTime > 0
Util.SetGray(btn, leftBuyTime == 0)
if data.Type == 7 or data.Type == 8 then
btnTxt.text = Language[10019]
else
btnTxt.text = Language[11923]
end
if isOpen and leftBuyTime > 0 then
priceTxt.gameObject:SetActive(true)
else
priceTxt.gameObject:SetActive(false)
end
priceTxt.text = data.Price[1][2] .. Language[10497]
else
name.text = GetLanguageStrById(data.Name)
priceTxt.gameObject:SetActive(false)
btn:GetComponent("Button").interactable = true
Util.SetGray(btn, false)
if data.Id == 45 then
scale = BattleManager.GetTimeScale()
scale = math.floor(scale * 10 + 0.5) / 10
if scale == BATTLE_TIME_SCALE_ONE then
btnTxt.text = Language[11984]
else
btnTxt.text = Language[11985]
end
else
btnTxt.text = Language[10019]
end
end
--LogError("data.id=="..data.Id.." data.name=="..data.Type)
local des = ""
des = data.DisplayReward
itemDes.text = GetLanguageStrById(des)
Util.AddOnceClick(btn, function()
if data.PackID == 0 then
if data.Id == 45 then
scale = BattleManager.GetTimeScale()
scale = math.floor(scale * 10 + 0.5) / 10
--LogError("scale========="..scale)
if scale == BATTLE_TIME_SCALE_ONE then
BattleManager.SetTimeScale(BATTLE_TIME_SCALE_TWO)
btnTxt.text = Language[11985]
else
BattleManager.SetTimeScale(BATTLE_TIME_SCALE_ONE)
btnTxt.text = Language[11984]
end
scale = BattleManager.GetTimeScale()
scale = math.floor(scale * 10 + 0.5) / 10
else
JumpManager.GoJump(data.Jump)
end
return
else
if data.Type == 7 or data.Type == 8 then
JumpManager.GoJump(data.Jump)
return
end
local sureFunc = function()
NetManager.SendGmBuyGoodRequest(data.PackID, function()
if data.Jump ~= 0 then
self:ClosePanel()
JumpManager.GoJump(data.Jump)
return
end
local leftBuyTime = OperatingManager.GetLeftBuyTime(recharge.Type, recharge.Id)
if leftBuyTime == -1 then
num.text = ""
else
num.text = "(" .. leftBuyTime .. "/" .. recharge.Limit .. ")"
end
Util.SetGray(btn, leftBuyTime == 0)
btn:GetComponent("Button").interactable = leftBuyTime == -1 or leftBuyTime > 0
this:ShowTopInfo()
end)
end
local args = {}
args[1] = Language[11986]
args[2] = Language[11923]
args[3] = Language[10685]
args[4] = sureFunc
UIManager.OpenPanel(UIName.GMCommonConfirmPanel, args)
end
end)
end
function GMChangePanel:OnSortingOrderChange()
end
-- 打开,重新打开时回调
function GMChangePanel:OnShow(_sortingOrder)
this:ShowTopInfo()
this.TabBtnOnClick(curBtn, curConfig)
end
--界面关闭时调用(用于子类重写)
function GMChangePanel:OnClose()
isFirst = true
end
--界面销毁时调用(用于子类重写)
function GMChangePanel:OnDestroy()
this.spLoader:Destroy()
SubUIManager.Close(this.shopScrollView)
end
return GMChangePanel