|
|
-
- SocialityFlowerView = SocialityFlowerView or BaseClass(BaseView)
-
- function SocialityFlowerView:__init()
- self.base_file = "sociality"
- self.layout_file = "SocialityFlowerView"
- self.layer_name = "Activity"
- self.destroy_imm = true
- self.use_background = true
- self.hide_maincancas = false
- self.change_scene_close = true
- -- self.append_to_ctl_queue = true
- self.model = SocialityModel:getInstance()
-
- self.blur_activity_bg = true
- self.use_show_anim = true
- self.use_hide_anim = true
-
- self.is_set_zdepth = true
- self.item_list = {}
-
- --预加载的Item
- self:AddPreLoadList("sociality", {"SocialityFlowerItem"})
-
- --回调方法
- self.load_callback = function()
- self:LoadSuccess()
- self:InitEvent()
- end
-
- self.open_callback = function()
- self:UpdateView()
- end
-
- self.close_callback = function()
- --刷新好友亲密度
- -- self.model:Fire(SocialityModel.REQUEST_CCMD_EVENT, 14000, 1)
- self:Clear()
- end
-
- self.destroy_callback = function()
-
- end
- end
-
- function SocialityFlowerView:LoadSuccess()
- self.ScrollView,--礼品容器
- self.ScrollViewViewport,--礼品容器
- self.ScrollViewCon,--礼品容器
- self.fameName_trans,--花香
- self.fameLabel_tmp_trans--花香值
- = GetChildTransforms(self.transform,
- {
- "ScrollView",
- "ScrollView/Viewport",
- "ScrollView/Viewport/Content",
- "fameName",
- "fameLabel",
- })
-
- self.sendBtn,--立即赠送
- self.selectBtn,--选择好友
- self.heartLvObj,--亲密阶段(陌生人隐藏)
- self.heartNumObj,--亲密值(陌生人隐藏)
- self.questionBtn,
- self.weekCharmNameObj,
- self.grayBg_obj
- = GetChildGameObjects(self.transform,
- {
- "sendBtn",
- "selectBtn",
- "heartLvLabel",
- "heartNumLabel",
- "questionBtn",
- "weekCharmName",
- "grayBg",
- })
-
- self.nodes = {
- "heart:img:obj",
- "name_con",
- "name_con/name:tmp",
- "name_con/sex:img:obj",
- "heartLabel:tmp",
- "fameLabel:tmp",
- "charmLabel:tmp",
- "weekCharmLabel:tmp",
- "heartLvLabel:tmp",
- "heartNumLabel:tmp",
- "headCon:obj",
- "price:tmp",
- "vipCon",
- "specialGiftCon:obj",
- "tips1:obj", --"tips2:obj",
- "tipCon/tip4:obj", --"tipCon/tip5:obj",
- "specialGiftCon/myReward", "specialGiftCon/friendReward",
- "specialGiftCon/friendTips:tmp",
- "specialGiftCon/myTips:tmp",
- "specialGiftCon/limitBuyTip:tmp",
- "selectRoleLabel:tmp",
- }
- self:GetChildren(self.nodes)
-
- local close_callback = function()
- self:Close()
- end
- self.tabWindowComponent = UITabWindow.New(self.transform, nil, nil, close_callback, self.background_wnd,
- self.transform,UITabWindow.SizeSmallNoTab,nil,nil,true)
- self.tabWindowComponent:SetBackgroundRes("sociality_bg1")
- self.tabWindowComponent:SetTitleText("送礼")
- -- self.tabWindowComponent:ChangeShowFlag("FriendShip")
-
- self.vipItem = RoleVipItem.New(self.vipCon)
-
- self.roleItem = HeadRoleItem.New(self.headCon)
- self.roleItem:SetItemSize(70,70)
-
- self.my_reward = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.myReward)
- self.my_reward:SetItemSize(80,80)
-
- self.friend_reward = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.friendReward)
- self.friend_reward:SetItemSize(80,80)
-
- end
-
- function SocialityFlowerView:Open(roleVo, select_goods_id)
- self.roleVo = roleVo
- self.select_goods_id = select_goods_id
- BaseView.Open(self)
- end
-
- function SocialityFlowerView:InitEvent( )
- local function onClickBtnHandler(target)
- if target == self.sendBtn then
- self:SendFlower()
- elseif target == self.selectBtn then--打开选择好友界面
- GlobalEventSystem:Fire(EventName.OPEN_SOCIAL_FRIEND_SEL_VIEW, true)
- elseif target == self.questionBtn then
- GlobalEventSystem:Fire(EventName.OPEN_INSTRUCTION_VIEW, 22301)
- end
- end
- AddClickEvent(self.sendBtn,onClickBtnHandler,LuaSoundManager.SOUND_UI.NONE)
- AddClickEvent(self.selectBtn,onClickBtnHandler,LuaSoundManager.SOUND_UI.NONE)
- AddClickEvent(self.questionBtn,onClickBtnHandler,LuaSoundManager.SOUND_UI.NONE)
-
- --选中好友之后刷新界面
- local onSel = function( vo )
- self.roleVo = vo
- self:UpdateView()
- end
- self.event_id = self.model:Bind(SocialityModel.SELECT_FIREND, onSel)
-
- --背包数目变化时刷新scrollview
- local function onUpdateBagList()
- if self._use_delete_method then return end
- self:UpdateView()
- end
- self.bag_num_id = GoodsModel:getInstance():Bind(GoodsModel.CHANGE_BAGLIST,onUpdateBagList)
-
- --刷新亲密度和人气
- local function onUpdateInIntimacy(role_id,week_charm,intimacy)
- if role_id ~= self.roleVo.role_id then return end
- self.roleVo.week_charm = week_charm
- self.roleVo.intimacy = intimacy
- self:UpdateView()
- end
- self:BindEvent(self.model,SocialityModel.UPDATE_FLOWER_NUM,onUpdateInIntimacy)
-
- --刷新显示人物形象
- local function on_update_vo( vo )
- self.roleVo = vo
- self:UpdateView()
- end
- self:BindEvent(self.model,SocialityModel.ANS_FRIEND_SHOW_DATA,on_update_vo)
-
- local function on_update_sp_gift_limit()
- self:SelectItem(self.vo)
- end
- self:BindEvent(self.model,SocialityModel.REFRESH_SOCIALITY_SP_GIFT_LIMIT,on_update_sp_gift_limit)
- end
-
- function SocialityFlowerView:Clear( )
- for k,v in pairs(self.item_list) do
- v:DeleteMe()
- end
- self.item_list = {}
- if self.event_id then
- self.model:UnBind(self.event_id)
- self.event_id = nil
- end
- if self.bag_num_id then
- GoodsModel:getInstance():UnBind(self.bag_num_id)
- self.bag_num_id = nil
- end
- if self.tabWindowComponent then
- self.tabWindowComponent:DeleteMe()
- self.tabWindowComponent = nil
- end
- if self.vipItem then
- self.vipItem:DeleteMe()
- self.vipItem = nil
- end
- if self.roleItem then
- self.roleItem:DeleteMe()
- self.roleItem = nil
- end
- if self.my_reward then
- UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem,self.my_reward)
- self.my_reward = nil
- end
- if self.friend_reward then
- UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem,self.friend_reward)
- self.friend_reward = nil
- end
- end
-
-
- function SocialityFlowerView:SendFlower( )
- if self.roleVo then--选中赠礼对象
- -- local isOn = self.toggle.isOn and 1 or 0 --是否匿名
- local isOn = 0 --暂时不要匿名的逻辑
- --是否是双向好友,非好友以及单向好友可送礼,但加成不会生效,也不能羁绊,需要提醒玩家
- local not_true_friend = not self.model:IsRelaviveType(self.roleVo.role_id, Config.ConfigSocial.RelativeType.friend) or self.model:IsOneWayToFriend(self.roleVo.role_id)
-
- if self.select_goods_id and self.roleVo.role_id then--是否选中礼物
- if self.vo then
- --先判断特殊礼物的限购次数
- local is_special = false
- local special_data = {}
- for k,v in pairs(Config.Flowerspgift) do
- if v.goods_id == self.vo.goods_id then
- is_special = true
- special_data = v
- end
- end
- if is_special then
- local sp_gift_limit_data = self.model:GetSpGiftLimitData()
- local max_times = special_data.limit_count
- local left_times = 0
- for k,v in pairs(sp_gift_limit_data) do
- if v.goods_id == self.vo.goods_id then
- left_times = max_times - v.num
- end
- end
- if left_times <= 0 then
- Message.show("已达到限购次数")
- return
- end
- end
-
- local num = GoodsModel:getInstance():GetTypeGoodsNum(self.select_goods_id)--获取背包中该物品的数目
- if num and num > 0 then --判断背包中是否有物品,有物品可以直接发22301协议送礼
- local ok_callback_4 = function()
- if num > 1 and not is_special then--如果数量大于1可以选择批量赠送
- local goods_vo = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.vo.goods_id)
- goods_vo.goods_num = num
- local extra_param_list = {gift_have_num = num, send_role_id = self.roleVo.role_id}
- BagModel:getInstance():Fire(BagModel.OPEN_BATHANDLE_VIEW, goods_vo, SplitView.TYPE.BAT_SEND_FLOWER, extra_param_list)
- else
- self.model:Fire(SocialityModel.REQUEST_CCMD_EVENT, 22301, self.roleVo.role_id, self.select_goods_id, 1, isOn)
- end
- end
- if not_true_friend then
- if not self.model:IsRelaviveType(self.roleVo.role_id, Config.ConfigSocial.RelativeType.friend) and not self.model:IsOneWayToFriend(self.roleVo.role_id) then
- Alert.show("你与对方不是好友关系,需要添加为<#2CF86F>永久好友</color>后<#2CF86F>亲密度关系才会生效</color> ,确认继续赠送吗?\n(亲密度数值会<#2CF86F>有效增加</color>,转变为 <#2CF86F>永久好友 后 <#2CF86F>100%继承</color>)", Alert.Type.Two, ok_callback_4, nil, "确定", "取消")
- else
- Alert.show("你与对方只是<#2CF86F>临时好友</color>,需要添加为<#2CF86F>永久好友</color>后<#2CF86F>亲密度关系才会生效</color> ,确认继续赠送吗?\n(亲密度数值会<#2CF86F>有效增加</color>,转变为 <#2CF86F>永久好友 后 <#2CF86F>100%继承</color>)", Alert.Type.Two, ok_callback_4, nil, "确定", "取消")
- end
- else
- ok_callback_4()
- end
- else
- local ok_callback_5 = function()
- local cfg = Config.Goodsprice[self.vo.goods_id]
- local price = cfg.price
- local function ok_callback( ... )
- self.model:Fire(SocialityModel.REQUEST_CCMD_EVENT, 22301, self.roleVo.role_id, self.select_goods_id, 1, isOn)
- end
- local function toggle_function( flag )
- self.model._buy_gift_no_double_check = flag
- end
- local function use_function( toggle_tip_data,call_fun_sum )
- if not self.model._buy_gift_no_double_check and price ~= 0 then
- GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
- else
- call_fun_sum()
- end
- end
- local buy_tip_data = {
- gold_type = cfg.price_type,--货币类型
- cost_price = price,--消耗金额
- ok_callback = ok_callback,--成功
- toggle_function = toggle_function,--多选
- togglePriceStr = string.format("<color=#fdffc2>%s</color> 进行购买?",price),--提示语
- use_function = use_function,--最终调用
- recharge_open_call_back = function()
- self:Close()
- end,
- invest_call_back = function()
- self:Close()
- end,
- }
- CustomActivityModel:getInstance():BuyTips(buy_tip_data)
- end
- if not_true_friend then
- if not self.model:IsRelaviveType(self.roleVo.role_id, Config.ConfigSocial.RelativeType.friend) and not self.model:IsOneWayToFriend(self.roleVo.role_id) then
- Alert.show("你与对方不是好友关系,需要添加为<#2CF86F>永久好友</color>后<#2CF86F>亲密度关系才会生效</color> ,确认继续赠送吗?\n(亲密度数值会<#2CF86F>有效增加</color>,转变为 <#2CF86F>永久好友 后 <#2CF86F>100%继承</color>)", Alert.Type.Two, ok_callback_5, nil, "确定", "取消")
- else
- Alert.show("你与对方只是<#2CF86F>临时好友</color>,需要添加为<#2CF86F>永久好友</color>后<#2CF86F>亲密度关系才会生效</color> ,确认继续赠送吗?\n(亲密度数值会<#2CF86F>有效增加</color>,转变为 <#2CF86F>永久好友 后 <#2CF86F>100%继承</color>)", Alert.Type.Two, ok_callback_5, nil, "确定", "取消")
- end
- else
- ok_callback_5()
- end
- end
- end
- else
- Message.show("请选择一个礼物")
- end
- else
- Message.show("请选择一个玩家")
- end
- end
-
-
- function SocialityFlowerView:UpdateView( )
-
- self.selectRoleLabel_tmp.text = ""
-
- local vo = self.roleVo--拿到选中的礼品数据
- if vo then
- self.name_tmp.text = vo.name or vo.role_name
- local sex_res = vo.sex == 1 and "com_boy" or "com_girl"
- lua_resM:setImageSprite(self, self.sex_img, "common_asset", sex_res, true)
- SetAnchoredPositionX(self.sex,self.name_tmp.preferredWidth+4)
- self.vipItem:SetData(vo.vip_flag,vo.sup_vip_type)
-
- if self.roleVo.vip_flag and tonumber(self.roleVo.vip_flag) > 0 then
- SetAnchoredPositionX(self.name_con,309)
- else
- SetAnchoredPositionX(self.name_con,270)
- end
- end
-
- if self.roleVo then
- --设置亲密度
- if self.model:IsRelaviveType(self.roleVo.role_id, Config.ConfigSocial.RelativeType.friend) then
- local temp_intimacy = vo.intimacy or 0
- self.heartLvObj:SetActive(true)
- self.heartNumObj:SetActive(true)
- local lv = self.model:GetLvByIntimacy(temp_intimacy)
- local intimacy_cfg = Config.Intimacylv[lv]
- lua_resM:setImageSprite(self, self.heart_img, "sociality_asset","sociality_intimacy_"..lv,true)
- if not self.model:IsOneWayToFriend(self.roleVo.role_id) then
- self.heartLvLabel_tmp.text = temp_intimacy.."("..Trim(intimacy_cfg.name)..")"
- else
- self.heartLvLabel_tmp.text = temp_intimacy.."(临时好友)"
- end
- else
- lua_resM:setImageSprite(self, self.heart_img, "sociality_asset","sociality_intimacy_0",true)
- self.heartLvObj:SetActive(true)
- self.heartNumObj:SetActive(false)
- self.heartLvLabel_tmp.text = "(陌生人)"
- end
-
- local head_data = {
- vo = {
- id = self.roleVo.role_id,
- server_id = self.roleVo.ser_id,
- career = self.roleVo.career,
- sex = self.roleVo.sex,
- turn = self.roleVo.turn,
- picture_ver = self.roleVo.picture_ver,
- picture = self.roleVo.picture,
- profile_photo_id = self.roleVo.profile_photo_id,
- dress_board_id = self.roleVo.dress_board,
- level = self.roleVo.lv,
- empty_head = false, -- 是否是空数据头像
- }
- }
- self.roleItem:SetData(head_data)
- self.headCon_obj:SetActive(true)
-
- self.weekCharmLabel_tmp.text = vo.week_charm
-
- self.weekCharmNameObj:SetActive(true)
-
- self.sex_obj:SetActive(true)
- self.heart_obj:SetActive(true)
-
- self.grayBg_obj:SetActive(false)
- else
- self.headCon_obj:SetActive(false)
-
- self.heartLvObj:SetActive(false)
- self.heartNumObj:SetActive(false)
- self.weekCharmNameObj:SetActive(false)
-
- self.name_tmp.text = ""
- self.selectRoleLabel_tmp.text = "请选择一个好友"
- self.sex_obj:SetActive(false)
- self.heart_obj:SetActive(false)
-
- self.grayBg_obj:SetActive(true)
-
- self.vipItem:SetData(0,0)
- end
-
- --处理鲜花配置
- local cfg = Config.Flowertools
- local price_cfg = Config.Goodsprice
- local list = {}
- for k,v in pairs(cfg) do
- --不可购买的物品,如果数量为0则不插入列表
- local num = GoodsModel:getInstance():GetTypeGoodsNum(v.goods_id)
- v.num = num or 0
- v.price = price_cfg[v.goods_id].price or 0
- if v.is_sell==0 then
- if num>0 then
- table.insert(list, v)
- end
- else
- table.insert(list, v)
- end
- end
- --排序
- -- local arg = {"num", "price"}
- -- local condition = {Array.UPPER, Array.UPPER}
- local arg = {"index"}
- local condition = {Array.LOWER}
- SortTools.MoreKeysSorter(list, arg, condition)
-
- local call_back = function( vo )
- self:SelectItem(vo)
- end
-
-
- local delta_x1 = 15
- local delta_y1 = 20
- local item_size_x = 263+11 --单个item的大小
- local item_size_y = 102+6 --
- local line_y = -36
- local len = #list
- local num = 0
- if len > 0 then
- if len%2 > 0 then
- num = num + 1
- end
- local three_multiple = math.modf(len/2)
- num = num + three_multiple
- end
- self.ScrollViewCon.sizeDelta = co.TableXY(self.ScrollViewCon.sizeDelta.x, num * item_size_y)
-
- local count = 0
- local x = 0
- for i,v in ipairs(list) do
- count = count + 1
- local item = self.item_list[i]
- if not item then
- item = SocialityFlowerItem.New(self.ScrollViewCon)
- self.item_list[i] = item
- end
- item:SetVisible(true)
- item:SetData(v, call_back)
- local y = math.modf((i-1)/2)
- if count == 1 then
- x = delta_x1
- else
- x = x + item_size_x
- end
- item:SetPosition(x, -y * item_size_y - 5)
-
- if count == 2 then
- count = 0
- x = 0
- end
- end
-
- for i=#list+1, #self.item_list do
- self.item_list[i]:SetVisible(false)
- end
-
- if self.select_goods_id then
- local index = nil
- for k,v in pairs(list) do
- if v.goods_id == self.select_goods_id then
- index = k
- end
- end
- if not index then
- --选中第一个
- self.item_list[1]:CallBack()
- else
- self.item_list[index]:CallBack()
- end
- else
- self.item_list[1]:CallBack()
- end
-
-
- end
-
- --选中礼品
- function SocialityFlowerView:SelectItem( vo )
- self.vo = vo--立即记录self.vo为当前选中的礼品数据
- self.select_goods_id = vo.goods_id--记录礼品id
- for k,v in pairs(self.item_list) do
- v:SetSelected(v.vo.goods_id == vo.goods_id)
- end
- local goodsBasic = GoodsModel:getInstance():GetGoodsBasicByTypeId(vo.goods_id)
- -- self.flowerName.text = goodsBasic.goods_name--礼品名
- local str = ""
- if vo.intimacy~=0 then
- self.heartLabel_tmp.text = string.format("双方亲密度+%d ", vo.intimacy)
- end
- if vo.fame~=0 then
- self.fameLabel_tmp.text = string.format("自己壕气值+%d", vo.fame)
- end
- if vo.charm~=0 then
- self.charmLabel_tmp.text = string.format("对方人气值+%d", vo.charm)
- end
-
- local num = GoodsModel:getInstance():GetTypeGoodsNum(vo.goods_id)--获取物品数目
- if num > 0 then
- self.price_tmp.text = string.format( "当前拥有:%s", HtmlColorTxt( num , '#2cf89a') )
- else
- local vo_price = Config.Goodsprice[vo.goods_id].price
- self.price_tmp.text = WordManager:GetMoneyFaceStr( 1 ) .. vo_price
- end
-
- --判断是否特殊礼品
- local is_special = false
- local special_data = {}
- for k,v in pairs(Config.Flowerspgift) do
- if v.goods_id == vo.goods_id then
- is_special = true
- special_data = v
- end
- end
- if is_special then
- local my_reward_data = stringtotable(special_data.my_back_reward)[1]
- local friend_reward_data = stringtotable(special_data.friend_back_reward)[1]
- self.my_reward:SetDataWithMapId(my_reward_data[2],my_reward_data[3],my_reward_data[1])
- self.friend_reward:SetDataWithMapId(friend_reward_data[2],friend_reward_data[3],friend_reward_data[1])
- self.friendTips_tmp.text = string.format("赠送后对方<color=#2cf89a>连续%s天</color>\n每日<color=#2cf89a>邮件发放</color>",special_data.friend_day)
- self.myTips_tmp.text = string.format("赠送后自己<color=#2cf89a>连续%s天</color>\n每日<color=#2cf89a>邮件发放</color>",special_data.my_day)
- local sp_gift_limit_data = self.model:GetSpGiftLimitData()
- local max_times = special_data.limit_count
- local left_times = 0
- for k,v in pairs(sp_gift_limit_data) do
- if v.goods_id == vo.goods_id then
- left_times = max_times - v.num
- end
- end
- local color_str = left_times>0 and "#2CF86F" or "#ff203a"
- self.limitBuyTip_tmp.text = string.format("每日限购:<%s>%s</color>/%s",color_str,left_times,max_times)
-
- self.tip4_obj:SetActive(false)
- -- self.tip5_obj:SetActive(false)
- self.tips1_obj:SetActive(false)
- -- self.tips2_obj:SetActive(false)
- self.specialGiftCon_obj:SetActive(true)
- else
-
-
- self.tip4_obj:SetActive(true)
- -- self.tip5_obj:SetActive(true)
- self.tips1_obj:SetActive(true)
- -- self.tips2_obj:SetActive(true)
- self.specialGiftCon_obj:SetActive(false)
- end
- end
-
-
-
-
-
- function SocialityFlowerView:UpdateRoleModel( )
- --此处必须有figure数据
- if not self.roleVo then return end
-
- local res_data = {
- father_node = self,
- transform = self.roleCon,
- fashion_type = FuncOpenModel.TypeId.Clothes,
- scale = 160,
- role_vo = self.roleVo,
- size = Vector2(720,720),
- -- position = Vector3(0,-260,-300),
- layer_name = self.layer_name,
- ui_model_type = UIModelCommon.ModelType.BackModel,
- }
- FuncOpenModel:getInstance():SetModelRes(res_data)
- end
|