源战役客户端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

318 wiersze
12 KiB

SelectSysRoleHeadView = SelectSysRoleHeadView or BaseClass(BaseView)
local table_insert = table.insert
local table_sort = table.sort
function SelectSysRoleHeadView:__init()
self.base_file = "newMainRole"
self.layout_file = "SelectSysRoleHeadView"
self.layer_name = "Activity"
-- self.use_local_view = true
self.use_background = true
self.is_set_zdepth = true
self.is_delay_callback = false
self.change_scene_close = true
self.blur_activity_bg = true
self.select_photo_id = false -- 当前选中的头像图片id
self.select_can_activate = false -- 当前选中的头像是否满足激活条件(针对运营头像)
self.item_list = {}
self.cur_select_head = nil
self.mainVo = RoleManager.Instance.mainRoleInfo
self.model = NewMainRoleModel:getInstance()
self.load_callback = function()
self:LoadSuccess()
self:InitEvent()
end
self.open_callback = function()
self:UpdateView()
end
self.destroy_callback = function()
self:Remove()
end
end
function SelectSysRoleHeadView:Remove()
if self.tween_id1 then
TweenLite.Stop(self.tween_id1)
self.tween_id1 = nil
end
if self.tween_id2 then
TweenLite.Stop(self.tween_id2)
self.tween_id2 = nil
end
if self.update_view_id then
self.model:UnBind(self.update_view_id)
self.update_view_id = nil
end
if self.change_head_success_id then
RoleManager.Instance.mainRoleInfo:UnBind(self.change_head_success_id)
self.change_head_success_id = nil
end
self.select_photo_id = false
for _, v in pairs(self.item_list) do
v:DeleteMe()
end
self.item_list = {}
if self.cur_select_head then
self.cur_select_head:DeleteMe()
self.cur_select_head = nil
end
if self.cost_icon then
UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.cost_icon)
end
self.cost_icon = nil
if self.tabWindowComponent then
self.tabWindowComponent:DeleteMe()
end
self.tabWindowComponent = nil
end
function SelectSysRoleHeadView:LoadSuccess()
local node ={
"content",
-- 头像相关
"content/headScroll","content/headScroll/Viewport/headCon", "content/container_head/cur_head:raw",
"content/confirmBtn:obj:img", "content/confirmBtn/comfirmBtn_str:tmp","content/container_head",
-- 属性相关
"content/attr_1:obj","content/attr_1/attr1_val:tmp","content/attr_1/attr1_name:tmp",
"content/attr_2:obj","content/attr_2/attr2_val:tmp","content/attr_2/attr2_name:tmp",
"content/attr_3:obj","content/attr_3/attr3_val:tmp","content/attr_3/attr3_name:tmp",
-- 消耗道具相关
"content/icon_name:tmp", "content/icon_num:tmp", "content/icon_con:obj", "content/activateBtn:obj",
-- 其他
"content/unlock_bg:obj", "content/con_fight/fight_num:txt", "content/unlock_bg2:obj",
"content/unlock_bg/unlock_condition:tmp", "content/unlock_bg/unlock_condition/goto_btn:obj",
"content/head_name:tmp", "content/head_name2:tmp", "content/head_des:tmp",
}
self:GetChildren(node)
self.cost_icon = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.icon_con)
self.cost_icon:SetItemSize(78, 78)
self.cost_icon:SetPosition(0, 0)
self.icon_con_obj:SetActive(false)
SetLocalScale(self.cur_head.transform, 0.97,0.97,0.97)
local function close_callback()
self:Close()
end
self.tabWindowComponent = UITabWindow.New(self.transform, {}, nil, close_callback, self.background_wnd, self.content, UITabWindow.SizeSmallNoTab, "select_head_bg", nil, true)
self.tabWindowComponent:SetTitleText("头像选择")
self.tabWindowComponent:SetBackgroundRes("select_role_head_bg")
self:StartAction()
end
function SelectSysRoleHeadView:StartAction( )
-------------------------
SetAnchoredPositionY( self.container_head.transform, 45 )
local do_up,do_down
function do_up()
self.tween_id1 = TweenLite.to(self, self.container_head.transform,TweenLite.UiAnimationType.ANCHORED_POSY,45,2,do_down)
end
function do_down()
self.tween_id2 = TweenLite.to(self, self.container_head.transform,TweenLite.UiAnimationType.ANCHORED_POSY,32,2,do_up)
end
do_down()
end
function SelectSysRoleHeadView:Open()
BaseView.Open(self)
end
function SelectSysRoleHeadView:InitEvent()
local function btnClickFunc(target, x, y)
if target == self.confirmBtn_obj then -- 更换头像
if self.select_photo_id then
if self.select_photo_id == self.mainVo.profile_photo_id then
return
else
GlobalEventSystem:Fire(EventName.REQ_CHANGE_ROLEHEAD, self.select_photo_id)
end
end
elseif target == self.activateBtn_obj then -- 激活头像
if self.select_photo_id then
if self.select_can_activate then
GlobalEventSystem:Fire(EventName.REQ_ACTIVATE_ROLEHEAD, self.select_photo_id)
else
UIToolTipMgr:getInstance():AppendGoodsTips(self.select_photo_id, x, y, nil,nil,nil,nil,true)
end
end
elseif target == self.goto_btn_obj then
self:OnTurnGotoBtnClick()
end
end
AddClickEvent(self.confirmBtn_obj, btnClickFunc)
AddClickEvent(self.activateBtn_obj, btnClickFunc)
AddClickEvent(self.goto_btn_obj, btnClickFunc)
local function update_view()
self:UpdateView(self.mainVo.profile_photo_id)
end
self.change_head_success_id = self.mainVo:BindOne("profile_photo_id", update_view)
end
function SelectSysRoleHeadView:UpdateView(photo_id)
local list = self.model:GetRoleHeadInfo()
local function call_func(index)
self.select_photo_id = list[index].photo_id
self.head_item_creator:IterateItems(function(item, i)
item:SetSelect(item.index == index)
end)
self:UpdateCurSelectHead(list[index])
end
-- 更新当前的头像选中索引
photo_id = photo_id or self.select_photo_id or self.mainVo.profile_photo_id
local selected_index
for k, v in pairs(list) do
if v.photo_id == photo_id then
selected_index = k
break
end
end
self.head_item_creator = self.head_item_creator or self:AddUIComponent(UI.ItemListCreator)
local info = {
data_list = list,
item_con = self.headCon,
scroll_view = self.headScroll,
item_class = RoleHeadShowItem,
item_height = 119,
item_width = 119,
start_x = 15,
start_y = -10,
space_x = 5,
space_y = 7.25,
create_frequency = 0.01,
alignment = UnityEngine.TextAnchor.UpperLeft,
on_update_item = function(item, i, v)
item:SetData(i, v, call_func)
item:SetSelect(item.index == selected_index)
end,
}
self.head_item_creator:UpdateItems(info)
-- 更新选中的头像数据
if photo_id ~= 0 then
for k, v in pairs(list) do
if v.photo_id == photo_id then
call_func(k)
break
end
end
else
call_func(1)
end
end
-- 更新当前选中的头像
function SelectSysRoleHeadView:UpdateCurSelectHead(data)
self.cur_selected_data = data
-- 更换头像资源
lua_resM:setOutsideRawImage(self, self.cur_head_raw, GameResPath.GetHeadIcon(self.select_photo_id), true)
local unlock_str = ""
local career_list = stringtotable(data.career)
if data.status ~= 2 then -- 如果头像未激活
if #career_list == 1 and career_list[1] ~= 0 then -- 职业列表为1且不为0代表转职获得的头像
unlock_str = "完成第"..data.turn.."次觉醒后激活"
else
unlock_str = "运营活动获得"
end
end
self.unlock_condition_tmp.text = unlock_str
-- 激活了的头像展示替换按钮
self.confirmBtn_obj:SetActive(data.status == 2)
self.unlock_bg2_obj:SetActive(data.status == 2)
-- 拥有可激活的通用头像则显示激活
self.activateBtn_obj:SetActive(data.status ~= 2 and not data.is_rein_head)
self.unlock_bg_obj:SetActive(data.status == 0 and data.is_rein_head)
self.head_name_tmp.text = Trim(data.name)
self.head_name2_tmp.text = GoodsModel:getInstance():getGoodsName(data.photo_id, true, true)
self.head_des_tmp.text = data.desc
if data.attr_list then
local attr_list = stringtotable(data.attr_list)
for k, v in ipairs(attr_list) do
local attr_name = WordManager:GetProperties(v[1])
self["attr"..k.."_name_tmp"].text = attr_name
self["attr"..k.."_val_tmp"].text = "+" .. v[2]
end
self.attr_1_obj:SetActive(#attr_list>0)
self.attr_2_obj:SetActive(#attr_list>1)
self.attr_3_obj:SetActive(#attr_list>2)
self.fight_num_txt.text = GetFighting(attr_list,data.status == 2)
else
self.attr_1_obj:SetActive(false)
self.attr_2_obj:SetActive(false)
self.attr_3_obj:SetActive(false)
self.fight_num_txt.text = 0
end
-- 更新确认按钮
self:UpdateComfirmBtn()
-- 更新激活道具
self:UpdateActivateGoods(data)
end
-- 更新确认按钮文本内容
function SelectSysRoleHeadView:UpdateComfirmBtn( )
self.comfirmBtn_str_tmp.text = self.select_photo_id and self.select_photo_id == self.mainVo.profile_photo_id and "当前头像" or "更换"
local is_gray = self.select_photo_id and self.select_photo_id == self.mainVo.profile_photo_id
SetImageGray( self.confirmBtn_img, is_gray )
SetTMPSharedMaterial(self.comfirmBtn_str_tmp, is_gray and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn or ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn)
end
-- 前往转生任务
function SelectSysRoleHeadView:OnTurnGotoBtnClick( )
-- 当前的转职任务可以进行
local turn, lv = self.mainVo.turn, self.mainVo.level
local target_turn = self.cur_selected_data and self.cur_selected_data.turn
-- 转职数跨度超过1
if target_turn - turn > 1 then
Message.show("请完成前置觉醒任务")
return
end
-- 转职数跨度为1
local rein_model = ReincarnationModel:getInstance()
local stage_cfg = rein_model:GetReinLvStageData(target_turn)
local stage = self.mainVo.turn_stage
-- 保险起见,更新一下当前转职任务
rein_model:UpdateCurReinTask()
-- 先判断是否有进行中的转职任务否则获取可接任务
local task_vo = rein_model:GetCurTaskVo() or TaskModel:getInstance():GetTaskByType(TaskType.TRUN_LINE)
if task_vo then
TaskModel:getInstance():TaskClickFun(task_vo)
GlobalEventSystem:Fire(EventName.CLOSE_NEW_MAIN_ROLE_VIEW)
self:Close()
return
end
stage = stage == 0 and stage + 1 or stage
-- 如果当前没有任务,则进行等级提升提示
for k, v in pairs(stage_cfg) do
if v.stage == stage then
if lv < v.need_lev then -- 转职数跨度为1,但是到下一阶段任务的等级不足
local str = string.format("请提升至%s", v.need_lev .. "")
Message.show(str)
return
end
end
end
end
function SelectSysRoleHeadView:UpdateActivateGoods(data)
if data.status ~= 2 and not data.is_rein_head then
local cost_list = stringtotable(data.cost_list)[1]
self.cost_icon:SetData(cost_list[1], cost_list[2])
self.icon_con_obj:SetActive(true)
-- self.cost_icon:SetVisible(true)
self.icon_name_tmp.text = GoodsModel:getInstance():getGoodsName(data.photo_id, true, true)
local goods_num_inbag = GoodsModel:getInstance():GetTypeGoodsNum(cost_list[1])
self.select_can_activate = goods_num_inbag >= cost_list[2]
self.icon_num_tmp.text = string.format("<color=%s>%s</color>/%s",
self.select_can_activate and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK,
goods_num_inbag, cost_list[2])
else
self.icon_name_tmp.text = ""
self.icon_num_tmp.text = ""
self.icon_con_obj:SetActive(false)
-- self.cost_icon:SetVisible(false)
end
end