源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

167 行
7.0 KiB

NewMainRoleHatredView = NewMainRoleHatredView or BaseClass(BaseView)
local NewMainRoleHatredView = NewMainRoleHatredView
function NewMainRoleHatredView:__init()
self.base_file = "newMainRole"
self.layout_file = "NewMainRoleHatredView"
self.layer_name = "Activity"
self.destroy_imm = true
self.use_background = true
self.is_set_zdepth = true
self.blur_activity_bg = true
self.hatred_item = nil -- 免罪券awardItem
self.hatred_item_goodID = 102001 -- 免罪券道具id
self.change_scene_close = true --是否切换场景时关闭(弹出界面使用)
--self.append_to_ctl_queue = false --是否要添加进界面堆栈
--self.need_show_money = false --是否要显示顶部的金钱栏
self.model = NewMainRoleModel:getInstance()
self.load_callback = function ()
self:LoadSuccess()
self:AddEvent()
end
self.open_callback = function ( )
self:OpenSuccess()
end
self.destroy_callback = function ( )
self:DestroySuccess()
end
end
function NewMainRoleHatredView:Open( )
--self.data = data
BaseView.Open(self)
end
function NewMainRoleHatredView:LoadSuccess()
local nodes = {
"window:raw","window/closeBtn:obj", "window/windowTitleText:tmp", "confirmBtn:obj", "itemCon",
"cur_hatred:tmp", "item_name:tmp", "item_num:tmp",
"intro1:tmp", "intro2:tmp",
}
self:GetChildren(nodes)
self.windowTitleText_tmp.text = "罪恶值"
self.cur_hatred_tmp.text = "罪恶值:"
lua_resM:setOutsideRawImage(self, self.window_raw, GameResPath.GetViewBigBg("tips_comm_bg6"), false)
end
function NewMainRoleHatredView:AddEvent()
local function click_event(target)
if target == self.closeBtn_obj then
self:Close()
elseif target == self.confirmBtn_obj then
if RoleManager.Instance.mainRoleInfo.hatred <= 0 then
Message.show("当前善恶值为0,无需减少")
return
end
local type_id = self.hatred_item_goodID
local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(type_id)
if goods_num >= 1 then
GlobalEventSystem:Fire(EventName.REDUCE_ROLE_HATRED, 1)
else
-- 获取物品价格及类型
local buy_price, _, price_type = GoodsModel:getInstance():GetGoodsPrice(type_id)
-- 获取货币goodsid
local price_id = WordManager:GetPriceTypeId(price_type)
local goods_name = GoodsModel:getInstance():getGoodsName(type_id, true)
local price_name = GoodsModel:getInstance():getGoodsName(price_id)
local price_color = GoodsModel:getInstance():GetGoodsColor(price_id)
local price_asset, price_icon = WordManager:GetCommonMoneyIcon(price_type)
local ask_str1 = string.format("您的 %s 不足!", goods_name)
local ask_str2 = string.format("<color=%s>%s</color> 补全物品?", price_color, buy_price)
local function ok_callback()
GlobalEventSystem:Fire(EventName.REDUCE_ROLE_HATRED, 1)
end
local function rechanger_callback()
if price_type == 1 then
local function ok()
self:Close()
end
local qc_data = {
close_callback = ok,
}
GlobalEventSystem:Fire(EventName.OPEN_RECHARGE_TIP_VIEW, true, qc_data)
elseif price_type == 2 then
Message.show("您的红钻不足")
end
end
local data = {
gold_ab_res = price_asset,
gold_res = price_icon,
price = buy_price,
insufficientText = ask_str1,
priceText = ask_str2,
titleText = "购买免罪券",
ok_callback = ok_callback,
rechanger_callback = rechanger_callback,
no_need_toggle = true,
}
GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, data)
end
end
end
AddClickEvent(self.closeBtn_obj, click_event, LuaSoundManager.SOUND_UI.NONE)
AddClickEvent(self.confirmBtn_obj, click_event)
local function on_change_hatred()
self:UpdateView()
end
self.on_change_hatred_id = RoleManager.Instance.mainRoleInfo:BindOne("hatred", on_change_hatred)
--背包物品发生变动时刷新免罪券数据(特指购买)
local function refresh_hatred_item()
self:UpdateView()
end
self.refresh_hatred_item_id = GoodsModel:getInstance():Bind(GoodsModel.CHANGE_BAGLIST, refresh_hatred_item)
local function OPEN_VIP_VIEW( )
--vip界面打开了就关掉自己
self:Close()
end
self:BindEvent(GlobalEventSystem, EventName.OPEN_VIP_VIEW, OPEN_VIP_VIEW)
end
function NewMainRoleHatredView:OpenSuccess()
self:UpdateView()
end
function NewMainRoleHatredView:UpdateView()
self.intro1_tmp.text = "在野外击杀其他玩家会增加您的<color=#f558ff>善恶值</color>"
self.intro2_tmp.text = "使用<color=#f558ff>免罪券</color>可减少<color=#f558ff>10点</color>善恶值,每在线30分钟会减少<color=#f558ff>1点</color>善恶值"
local role_hatred = RoleManager.Instance.mainRoleInfo.hatred
local goods_effect = Config.Goodseffect[self.hatred_item_goodID].effect_list
local cost = stringtotable(goods_effect)[1][2]
local str_3 = HtmlColorTxt( string.format("(惩罚:罪恶值大于0时被其他玩家击杀将失去%s红钻)", cost ) , '#ff203a', 0.7)
self.cur_hatred_tmp.text = "罪恶值:" .. HtmlColorTxt( role_hatred , '#fdffc2') .. str_3
if not self.hatred_item then
self.hatred_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.itemCon)
self.hatred_item:SetAnchoredPosition(0, 0)
end
self.hatred_item:SetOpenShowGetWay(true)
self.hatred_item:SetData(self.hatred_item_goodID)
self.hatred_item:SetItemSize(78, 78)
local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(self.hatred_item_goodID)
local goods_name = GoodsModel:getInstance():getGoodsName(self.hatred_item_goodID, true)
self.item_num_tmp.text = string.format("<color=%s>%s</color>/1", goods_num>0 and ColorUtil.GREEN or ColorUtil.RED, goods_num)
self.item_name_tmp.text = goods_name
end
function NewMainRoleHatredView:DestroySuccess( )
if self.hatred_item then
UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.hatred_item)
end
self.hatred_item = nil
if self.on_change_hatred_id then
RoleManager.Instance.mainRoleInfo:UnBind(self.on_change_hatred_id)
self.on_change_hatred_id = nil
end
if self.refresh_hatred_item_id then
GoodsModel:getInstance():UnBind(self.refresh_hatred_item_id)
self.refresh_hatred_item_id = nil
end
end