|
|
- HeadRoleItem = HeadRoleItem or BaseClass(BaseItem)
-
- function HeadRoleItem:__init(parent_wnd, prefab_asset, layer_name)
- self.base_file = "uiComponent"
- self.layout_file = "HeadRoleItem"
- self.is_delay_callback = true
- -- self.use_local_view = true
- self.vo = nil
- self.parent = parent_wnd
- self.layer_name = layer_name
-
- self.gray_mat = ShaderTools.gray_mat
- self.show_sex = false
- self.show_sex_type = 1 -- 性别展示类型 1:左下角带底图 2:左上角无底图
- -- 不同背景图片下的背景坐标
- self.bg_offsets = {
- [1] = {x = 0, y = 0},
- [2] = {x = 2, y = -2.5},
- [3] = {x = 0, y = 0},
- }
- self.bg_sizeDelta = {
- [1] = {x = 165, y = 165},
- [2] = {x = 176, y = 176},
- [3] = {x = 165, y = 165},
- }
- self.duration = 0.1
- self.long_click_time = 1500 -- 长按判定时间(毫秒)
- self:Load()
- end
-
- function HeadRoleItem:__delete( )
- if self.bind_wait_for_protocal then
- GlobalEventSystem:UnBind(self.bind_wait_for_protocal)
- self.bind_wait_for_protocal = nil
- end
-
- if self.long_click_timer_id then
- GlobalTimerQuest:CancelQuest(self.long_click_timer_id)
- self.long_click_timer_id = nil
- end
- end
-
- function HeadRoleItem:Load_callback()
- local node = {
- "head",
- "head/bg:obj:imgex",
- "head/dressBoard:img:obj",
- "head/icon:raw", "head/effect", "head/sex_bg:obj",
- "head/sex_icon:obj:img",
- "head/lv_bg:obj:img", "head/lv_bg/lv:tmp",
- "head/career_icon:obj:img",--职业图标
- }
- self:GetChildren(node)
-
- self.head_size_x = self.head.sizeDelta.x
- self.head_size_y = self.head.sizeDelta.y
-
- local function onClickBtnHandler(target, x, y)
- if self.vo and not self.long_click_call_back then
- self:OnClickFunc( x, y )
- end
- end
- AddClickEvent(self.gameObject, onClickBtnHandler, nil, false)
-
- local function touch_end_func(target,x,y)
- if not self.long_click_call_back then return end
- local cur_time = TimeUtil:getClientTimeMs( )
-
- if self.vo and cur_time - self.click_start_time <= self.long_click_time then
- self:OnClickFunc( x, y )
- end
- if self.long_click_timer_id then
- GlobalTimerQuest:CancelQuest(self.long_click_timer_id)
- self.long_click_timer_id = nil
- end
- end
-
- local function touch_begin_func(target,x,y)
- if not self.long_click_call_back then return end
- self.click_start_time = TimeUtil:getClientTimeMs( )
- local function clockFun()
- local cur_time = TimeUtil:getClientTimeMs( )
- if cur_time - self.click_start_time > self.long_click_time then
- if self.long_click_call_back then
- self.long_click_call_back(self.vo)
- end
- if self.long_click_timer_id then
- GlobalTimerQuest:CancelQuest(self.long_click_timer_id)
- self.long_click_timer_id = nil
- end
- end
- end
- if not self.long_click_timer_id then
- self.long_click_timer_id = GlobalTimerQuest:AddPeriodQuest(clockFun, self.duration, -1)
- end
- clockFun()
- end
- AddDownEvent(self.gameObject, touch_begin_func)
- AddUpEvent(self.gameObject, touch_end_func)
-
- if self.need_refresh then
- self:UpdateView()
- end
- if self.gray_cache ~= nil then
- self:SetGray(self.gray_cache)
- end
- if self.need_effect then
- self:SetEffect(self.effect_name, self.eff_layer_name, self.eff_scale, self.mask_id)
- end
- if self.career_icon_cache ~= nil then
- self:SetCareerIconVisible(self.career_icon_cache)
- end
- end
-
- --[[
- 2019年11月29日修改 : 通用头像的参数改为一个table,参数名不变
- data = {
- vo, -- 玩家头像的具体参数
- show_tip, -- 是否可以查看玩家数据,默认可以
- custom_callback, -- 自己传callback
- use_bg, -- 使用的背景图片的类型,如果自己加了新样式在记得上面的self.bg_offsets中添加自己的新背景图片坐标
- }
- vo范例
- vo = {
- id = RoleManager.Instance.mainRoleInfo.role_id,
- server_id = RoleManager.Instance.mainRoleInfo.server_id,
- career = RoleManager.Instance.mainRoleInfo.career,
- sex = RoleManager.Instance.mainRoleInfo.sex,
- turn = RoleManager.Instance.mainRoleInfo.turn,
- picture_ver = RoleManager.Instance.mainRoleInfo.picture_ver, --不支持自定义头像,此字段废弃
- picture = RoleManager.Instance.mainRoleInfo.picture, --不支持自定义头像,此字段废弃
- profile_photo_id = RoleManager.Instance.mainRoleInfo.profile_photo_id,
- dress_board_id = ChatDressModel:getInstance().use_dress_list[2],--头像框id,默认为0(无头像框)
- level = RoleManager.Instance.mainRoleInfo.level,
- do_not_click = true,--不可点击
- empty_head = false, -- 是否是空数据头像
- not_show_level = true
- }
- ]]
- function HeadRoleItem:SetData(data)
- -- data.vo = data.vo
- -- data.vo.turn = data.vo.turn or 0
- local temp_vo = {}
- if data and data.vo then
- temp_vo = data.vo
- elseif data then
- temp_vo = data
- end
- self.vo = temp_vo
- -- self.vo.turn = data.vo and data.vo.turn or 0
- -- 这两个暂时废弃
- self:SetSomeInfo(data)
- self:UpdateView()
- end
-
- --[[
- 通过角色id展示头像,数据格式和SetData一样,module_id填自己的标记id,防混
- --]]
- function HeadRoleItem:SetShowByRoleId( data )
- local temp_vo = {}
- if data and data.vo then
- temp_vo = data.vo
- elseif data then
- temp_vo = data
- end
- self.vo = temp_vo
- self.module_id = data.module_id or 0
- -------------------------
- self:SetSomeInfo(data)
- if (self.vo.role_id or self.vo.id) then
- self.wait_for_protocal = true
- -------------------------
- if not self.bind_wait_for_protocal then
- local function ANS_OTHER_HEAD_INFO( head_data )
- if self._use_delete_method then return end
- if head_data.mod ~= self.module_id then return end
- -------------------------
- self.vo = self.vo or {}
- for k,v in pairs(head_data) do
- self.vo[k] = v
- end
- self:UpdateView()
- -------------------------
- if self.bind_wait_for_protocal then
- GlobalEventSystem:UnBind(self.bind_wait_for_protocal)
- self.bind_wait_for_protocal = nil
- end
- self.wait_for_protocal = nil
- end
- self.bind_wait_for_protocal = GlobalEventSystem:Bind(EventName.ANS_OTHER_HEAD_INFO,ANS_OTHER_HEAD_INFO)
- GlobalEventSystem:Fire( EventName.REQ_OTHER_HEAD_INFO, self.module_id, (self.vo.role_id or self.vo.id) )
- end
- else
- Message.show("缺少角色信息~")
- end
- end
-
- function HeadRoleItem:SetSomeInfo( data )
- self.bg_size = data.bg_size
- self.icon_size = data.icon_size
- ----------------
- self.show_tip = data.show_tip == nil and true or data.show_tip --默认弹提示
- self.not_show_level = data.not_show_level
- self.do_not_click = data.do_not_click or (self.vo and self.vo.do_not_click)
- self.custom_callback = data.custom_callback
- -- self.use_bg = data.use_bg or (self.vo and self.vo.use_bg) or 1 -- 使用的背景样式(1为白底渐变外框正方形)
- self.use_bg = 3--20201026头像背景写死为3
- end
-
- function HeadRoleItem:UpdateView()
- if not self.vo then return end
- if not self.is_loaded then
- self.need_refresh = true
- return
- end
- local vo = self.vo
- self.bg_imgex.raycastTarget = not self.do_not_click and true or false
- -- 选择好需要使用的背景图
- lua_resM:setImageSprite(self, self.bg_imgex, "uiComponent_asset", "pw_ckxx_0"..self.use_bg)
- SetAnchoredPosition(self.bg, self.bg_offsets[self.use_bg].x, self.bg_offsets[self.use_bg].y)
- SetSizeDeltaX(self.bg, self.bg_sizeDelta[self.use_bg].x)
- SetSizeDeltaY(self.bg, self.bg_sizeDelta[self.use_bg].y)
- -- 暂时废弃这段逻辑
- -- if self.bg_size then
- -- if self.use_bg == 1 then
- -- self.bg.sizeDelta = self.bg_size
- -- elseif self.use_bg == 2 then
- -- self.bg2.sizeDelta = self.bg_size
- -- end
- -- end
- -- if self.icon_size then
- -- self.icon.sizeDelta = self.icon_size
- -- end
- ------------------
- -- print("Saber:HeadRoleItem [start:127] vo ------------------------------------------")
- -- PrintTable(vo)
- --头像
- if self.vo.empty_head then
- self.icon.gameObject:SetActive(false)
- self.dressBoard_obj:SetActive(false)
- else
- self.icon.gameObject:SetActive(true)
- -- if vo.career and vo.sex and vo.turn and vo.career ~= 0 and vo.sex ~= 0 then
- CustomRoleHead:getInstance():Create(self, self.icon_raw, vo.id or vo.role_id, vo.career, vo.sex, vo.turn, nil, vo.picture_ver, vo.picture, false, vo.profile_photo_id)
- -- end
-
- --头像框
- if (vo.dress_board_id and vo.dress_board_id ~=0 and vo.dress_board_id ~= 420001) or
- (vo.dress_id and vo.dress_id ~=0 and vo.dress_id ~= 420001) then
- local id = vo.dress_board_id or vo.dress_id
- lua_resM:setOutsideImageSprite(self,self.dressBoard_img,GameResPath.GetChatDressIcon(id),false)
- self.dressBoard_obj:SetActive(true)
- else
- -- lua_resM:setImageSprite(self, self.dressBoard_img, "uiComponent_asset","com_empty", false)
- self.dressBoard_obj:SetActive(false)
- end
-
- --职业 (策划说先屏蔽了 2020.10.21 by msh)
- self.career_icon_obj:SetActive(false)
- -- if vo.career and vo.career ~= 0 then
- -- self.career_icon_obj:SetActive(true)
- -- lua_resM:setImageSprite(self, self.career_icon_img, "common_asset","common_career_"..vo.career)
- -- else
- -- self.career_icon_obj:SetActive(false)
- -- end
-
- if self.custom_callback then
- self.custom_callback()
- end
- end
-
-
- --设置大小
- self:SetItemSize()
- self:SetSexConShow(self.show_sex, self.show_sex_type)
-
- if RoleManager and RoleManager.Instance and RoleManager.Instance.mainRoleInfo.level < Config.Modulesub["110@2"].open_lv then
- if self.lv_bg_obj.activeSelf then
- self.lv_bg_obj:SetActive(false)
- end
- self.lv_tmp.text = ""
- else
- self.lv_bg_obj:SetActive(vo.level and vo.level~=0 and true or false)
- self.lv_tmp.text = vo.level or ""
- end
-
- --AI管家:不显示AI管家的等级
- if vo.id == 1 then
- self.lv_tmp.text = ""
- end
- if self.not_show_level then
- self.lv_tmp.text = ""
- self.lv_bg_obj:SetActive(false)
- end
- end
-
- function HeadRoleItem:SetGray(bool)
- if self.is_loaded then
- local mat = bool and self.gray_mat or nil
- self.icon_raw.material = mat
- self.dressBoard_img.material = mat
- SetImageGray(self.lv_bg_img,bool)
- SetImageGray(self.career_icon_img,bool)
- SetImageGray(self.bg_imgex,bool)
- else
- self.gray_cache = bool
- end
- end
-
- function HeadRoleItem:SetItemSize(x, y)
- self.now_size_x = tonumber(x) or self.now_size_x or self.head_size_x
- self.now_size_y = tonumber(y) or self.now_size_y or self.head_size_y
- if self.is_loaded then
- local x_ratio = self.now_size_x / self.head_size_x
- local y_ratio = self.now_size_y / self.head_size_y
- self.head.localScale = Vector2(x_ratio, y_ratio)
- end
- end
-
- function HeadRoleItem:SetSexConShow(show, show_type)
- self.show_sex = show or self.show_sex
- self.show_sex_type = show_type or self.show_sex_type
- if self.is_loaded then
- if show then
- self.sex_icon_obj:SetActive(true)
- if self.show_sex_type == 1 then
- self.sex_bg_obj:SetActive(true)
- SetAnchoredPositionY(self.sex_icon, -55)
- elseif self.show_sex_type == 2 then
- self.sex_bg_obj:SetActive(false)
- SetAnchoredPositionY(self.sex_icon, 58)
- SetLocalScale(self.sex_icon, 0.8, 0.8, 0.8)
- end
- lua_resM:setImageSprite(self, self.sex_icon_img, "uiComponent_asset", "headrole_sex_"..(self.vo and self.vo.sex or 1), true)
- else
- self.sex_icon_obj:SetActive(false)
- self.sex_bg_obj:SetActive(false)
- end
- end
- end
- function HeadRoleItem:SetEffect(effect_name, layer_name, scale, mask_id)
- self.effect_name = effect_name
- self.eff_layer_name = layer_name
- self.eff_scale = scale
- self.mask_id = mask_id
- if self.is_loaded then
- local function load_end_func()
- end
- --没有传mask_id而且要显示特效的情况才去获取mask_id
- if not self.mask_id then
- local p_wnd = self.parent
- repeat
- p_wnd = p_wnd.parent
- if p_wnd and p_wnd.parent then
- local rect = p_wnd.parent:GetComponent(typeof(UnityEngine.UI.ScrollRect))
- if rect then
- if p_wnd:GetComponent("EffectMask") then
- self.mask_id = 1
- else
- local image = p_wnd:GetComponent("Image")
- if image then
- self.mask_id = self:RegisterMask(image)
- end
- end
- end
- end
- until not p_wnd or self.mask_id
- end
- self:AddUIEffect(effect_name, self.effect, layer_name or "UI", nil, scale or 1, true, nil, self.mask_id, nil, load_end_func)
- self.need_effect = false
- else
- self.need_effect = true
- end
-
- end
-
- function HeadRoleItem:SetCareerIconVisible( flag )
- if not self.is_loaded then
- self.career_icon_cache = flag
- return
- end
- if self.career_icon_obj then
- self.career_icon_obj:SetActive(flag)
- end
- end
-
- function HeadRoleItem:SetClickCall( call_back )
- self.call_back = call_back
- end
-
- -- 设置长按事件
- function HeadRoleItem:SetLongClickCall( call_back )
- self.long_click_call_back = call_back
- end
-
- -- 单击轻点
- function HeadRoleItem:OnClickFunc( x, y )
- if self.do_not_click then
- return
- end
- if self.call_back then
- self.call_back(self.vo)
- return
- end
- local role_id = self.vo.id or self.vo.role_id
- --AI管家:role_id==1是AI管家的情况,这种情况不能打开交互面板
- if self.show_tip and role_id ~= RoleManager.Instance.mainRoleInfo.role_id and role_id ~= 1 then
- -- print("-------self.vo.server_id ~= RoleManager.Instance.mainRoleInfo.server_id",role_id , RoleManager.Instance.mainRoleInfo.server_id)
- -- if self.vo.server_id and self.vo.server_id ~= RoleManager.Instance.mainRoleInfo.server_id then
- -- Message.show("无法查看跨服玩家信息")
- -- return
- -- end
- if RoleManager.Instance.mainRoleInfo.level < Config.Modulesub["110@2"].open_lv then
- Message.show("查看功能未开放")
- return
- end
- --请求协议获取对方信息
- if role_id then
- SocialityModel:getInstance():Fire(SocialityModel.REQUEST_OTHER_INFO, role_id, x, y, self.vo.info)
- end
- end
- end
|