|
CSMainMilitaryRanksDetailsView = CSMainMilitaryRanksDetailsView or BaseClass(BaseItem)
|
|
local CSMainMilitaryRanksDetailsView = CSMainMilitaryRanksDetailsView
|
|
|
|
function CSMainMilitaryRanksDetailsView:__init()
|
|
self.base_file = "csMain"
|
|
self.layout_file = "CSMainMilitaryRanksDetailsView"
|
|
self.model = CSMainModel:getInstance()
|
|
|
|
self.is_show_next = false
|
|
|
|
self:Load()
|
|
end
|
|
|
|
function CSMainMilitaryRanksDetailsView:Load_callback()
|
|
self.nodes = {
|
|
"advanceBtn:obj:img", "advanceBtn/advanceRed:obj", "advanceBtn/advanceText:tmp",
|
|
"awardCon:obj", "conditionCon1:obj",
|
|
"noneTip:tmp",
|
|
"conditionCon1/conditionDes1:tmp", "conditionCon1/conditionDot1:img",
|
|
"conditionCon2/conditionDes2:tmp", "conditionCon2:obj", "conditionCon2/conditionDot2:obj:img",
|
|
"militaryCon1/militaryRanksIcon1:img", "militaryCon1/fight1:txt",
|
|
"militaryCon1/attrScrollView1/Viewport/attrContent1", "militaryCon1/attrScrollView1",
|
|
"militaryCon2/militaryRanksIcon2:img", "militaryCon2/fight2:txt",
|
|
"militaryCon2/attrScrollView2/Viewport/attrContent2", "militaryCon2/attrScrollView2",
|
|
}
|
|
self:GetChildren(self.nodes)
|
|
|
|
self.cost_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.awardCon)
|
|
self.cost_item:SetItemSize(78,78)
|
|
self.cost_item:SetAnchoredPosition(0,0)
|
|
|
|
|
|
self:AddEvents()
|
|
if self.need_refreshData then
|
|
self:UpdateView()
|
|
end
|
|
end
|
|
|
|
function CSMainMilitaryRanksDetailsView:AddEvents( )
|
|
local on_click = function ( click_obj )
|
|
if self.advanceBtn_obj == click_obj then
|
|
if self.can_evolve_state then
|
|
self.model:Fire(CSMainConst.REQUEST_CCMD_EVENT,60305)
|
|
else
|
|
if self.is_show_next then
|
|
Message.show("条件未达成")
|
|
else
|
|
Message.show("已升至满阶")
|
|
end
|
|
end
|
|
end
|
|
end
|
|
AddClickEvent(self.advanceBtn_obj, on_click)
|
|
|
|
--军衔进阶成功
|
|
local function on_update_military_details()
|
|
self:UpdateView()
|
|
end
|
|
self:BindEvent(self.model, CSMainConst.CS_MAIN_MILITARY_ADVANCE_SUCCESE, on_update_military_details)
|
|
|
|
--晋升令刷新
|
|
local function update_cs_main_goods_num()
|
|
local military_ranks = self.model:GetCSMainMilitaryRanks()
|
|
local next_military_cfg = self.model:GetCSMainLegionMilitaryRanksCfg(military_ranks+1)
|
|
if next_military_cfg then
|
|
self:UpdateEvolveState()
|
|
end
|
|
end
|
|
self:BindEvent(self.model, CSMainConst.UPDATE_CS_MAIN_GOODS_NUM,update_cs_main_goods_num)
|
|
|
|
local function update_power_change()
|
|
self:UpdateEvolveState()
|
|
end
|
|
self.update_power_change_id = RoleManager.Instance.mainRoleInfo:BindOne("fighting", update_power_change)
|
|
end
|
|
|
|
function CSMainMilitaryRanksDetailsView:UpdateView( )
|
|
local military_ranks = self.model:GetCSMainMilitaryRanks()
|
|
local next_military_ranks = military_ranks + 1
|
|
local now_military_cfg = self.model:GetCSMainLegionMilitaryRanksCfg(military_ranks)
|
|
if not now_military_cfg then return end
|
|
|
|
local next_military_cfg = self.model:GetCSMainLegionMilitaryRanksCfg(military_ranks+1)
|
|
local have_next = next_military_cfg and true or false
|
|
--左侧
|
|
lua_resM:setOutsideImageSprite(self, self.militaryRanksIcon1_img, GameResPath.GetMilitaryImage("military_ranks_"..military_ranks), true)
|
|
local attr_data_left = stringtotable(now_military_cfg.attr)
|
|
self.fight1_txt.text = "f"..GetFighting(attr_data_left)
|
|
|
|
if not self.item_list_com_1 then
|
|
self.item_list_com_1 = self:AddUIComponent(UI.ItemListCreator)
|
|
end
|
|
local info = {
|
|
data_list = attr_data_left,
|
|
item_con = self.attrContent1,
|
|
item_class = CSMainMilitaryRanksAttrItem,
|
|
item_width = 160,
|
|
item_height = 30,
|
|
-- space_x = 0,
|
|
-- space_y = 0,
|
|
start_x = 6,
|
|
start_y = -5,
|
|
scroll_view = self.attrScrollView1,
|
|
create_frequency = 0.01,
|
|
on_update_item = function(item, i, v)
|
|
item:SetData(v)
|
|
end,
|
|
}
|
|
self.item_list_com_1:UpdateItems(info)
|
|
|
|
|
|
--右侧
|
|
if not next_military_cfg then--表示满级了,右侧也显示成当前军衔
|
|
next_military_cfg = now_military_cfg
|
|
next_military_ranks = military_ranks
|
|
self.is_show_next = false
|
|
else
|
|
self.is_show_next = true
|
|
end
|
|
lua_resM:setOutsideImageSprite(self, self.militaryRanksIcon2_img, GameResPath.GetMilitaryImage("military_ranks_"..next_military_ranks), true)
|
|
local attr_data_right = stringtotable(next_military_cfg.attr)
|
|
self.fight2_txt.text = "f"..GetFighting(attr_data_right)
|
|
|
|
if not self.item_list_com_2 then
|
|
self.item_list_com_2 = self:AddUIComponent(UI.ItemListCreator)
|
|
end
|
|
local info = {
|
|
data_list = attr_data_right,
|
|
item_con = self.attrContent2,
|
|
item_class = CSMainMilitaryRanksAttrItem,
|
|
item_width = 160,
|
|
item_height = 30,
|
|
-- space_x = 0,
|
|
-- space_y = 0,
|
|
start_x = 6,
|
|
start_y = -5,
|
|
scroll_view = self.attrScrollView2,
|
|
create_frequency = 0.01,
|
|
on_update_item = function(item, i, v)
|
|
item:SetData(v,self.is_show_next)
|
|
end,
|
|
}
|
|
self.item_list_com_2:UpdateItems(info)
|
|
|
|
if have_next then
|
|
self.conditionCon1_obj:SetActive(true)
|
|
self.conditionCon2_obj:SetActive(true)
|
|
self.noneTip_tmp.text = ""
|
|
self.awardCon_obj:SetActive(true)
|
|
self:UpdateEvolveState()
|
|
else
|
|
self.conditionCon1_obj:SetActive(false)
|
|
self.conditionCon2_obj:SetActive(false)
|
|
self.noneTip_tmp.text = "已升至满阶\n后续敬请期待"
|
|
self.awardCon_obj:SetActive(false)
|
|
SetImageGray(self.advanceBtn_img,true)
|
|
SetTMPSharedMaterial(self.advanceText_tmp, ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
|
|
self.advanceRed_obj:SetActive(false)
|
|
end
|
|
end
|
|
|
|
function CSMainMilitaryRanksDetailsView:UpdateEvolveState( )
|
|
local military_ranks = self.model:GetCSMainMilitaryRanks()
|
|
local now_military_cfg = self.model:GetCSMainLegionMilitaryRanksCfg(military_ranks)
|
|
if not now_military_cfg then return end
|
|
|
|
--战力需达标
|
|
local enough_power = RoleManager.Instance.mainRoleInfo.fighting >= now_military_cfg.need
|
|
if enough_power then
|
|
lua_resM:setImageSprite(self, self.conditionDot2_img, "csMain_asset", "cs_main_condition_dot_true")
|
|
self.conditionDes2_tmp.text = string.format("战力达到 <#2CF86F>%s</color><#a9c1e1>/</color><#fdffc2>%s</color>", CalUnitNumWithMaxNum(RoleManager.Instance.mainRoleInfo.fighting), CalUnitNumWithMaxNum(now_military_cfg.need))
|
|
else
|
|
lua_resM:setImageSprite(self, self.conditionDot2_img, "csMain_asset", "cs_main_condition_dot_false")
|
|
self.conditionDes2_tmp.text = string.format("战力达到 <#ff203a>%s</color><#a9c1e1>/</color><#fdffc2>%s</color>", CalUnitNumWithMaxNum(RoleManager.Instance.mainRoleInfo.fighting), CalUnitNumWithMaxNum(now_military_cfg.need))
|
|
end
|
|
|
|
--晋升令
|
|
local cost_goods_data = stringtotable(now_military_cfg.cost)
|
|
local no_need_cost = false
|
|
if not cost_goods_data[1] or (cost_goods_data[1] and cost_goods_data[1][3] == 0)then
|
|
cost_goods_data[1] = {0,100019,0}
|
|
no_need_cost = true
|
|
end
|
|
|
|
if no_need_cost then
|
|
self.conditionCon1_obj:SetActive(false)
|
|
self.awardCon_obj:SetActive(false)
|
|
else
|
|
self.conditionCon1_obj:SetActive(true)
|
|
self.awardCon_obj:SetActive(true)
|
|
end
|
|
|
|
local goods_type_id = cost_goods_data[1][2]
|
|
local cost_need_num = cost_goods_data[1][3]
|
|
local cost_have_num = GoodsModel:getInstance():GetTypeGoodsNum(goods_type_id)
|
|
local enough_cost = cost_have_num >= cost_need_num
|
|
local cost_color = enough_cost and ColorUtil.GREEN_TIPS or ColorUtil.RED_DARK
|
|
self.conditionDes1_tmp.text = string.format("持有晋升指令%s个<#a9c1e1>(<%s>%s</color>/%s)</color>",cost_need_num,cost_color,cost_have_num,cost_need_num)
|
|
local cost_dot_res = enough_cost and "cs_main_condition_dot_true" or "cs_main_condition_dot_false"
|
|
lua_resM:setImageSprite(self, self.conditionDot1_img, "csMain_asset",cost_dot_res)
|
|
|
|
self.can_evolve_state = enough_power and enough_cost
|
|
|
|
if self.cost_item then
|
|
self.cost_item:SetData(goods_type_id)
|
|
local num_str = HtmlColorTxt(cost_have_num, cost_have_num < cost_need_num and ColorUtil.RED_DARK or ColorUtil.GREEN_TIPS).."/".. cost_need_num
|
|
self.cost_item:IsGetGoods(true,num_str,false)
|
|
end
|
|
|
|
if self.can_evolve_state then
|
|
SetImageGray(self.advanceBtn_img,false)
|
|
self.advanceRed_obj:SetActive(true)
|
|
SetTMPSharedMaterial(self.advanceText_tmp, ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn)
|
|
else
|
|
SetImageGray(self.advanceBtn_img,true)
|
|
self.advanceRed_obj:SetActive(false)
|
|
SetTMPSharedMaterial(self.advanceText_tmp, ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
|
|
end
|
|
end
|
|
|
|
function CSMainMilitaryRanksDetailsView:SetData( data )
|
|
self.data = data
|
|
if self.is_loaded then
|
|
self.need_refreshData = false
|
|
self:UpdateView()
|
|
else
|
|
self.need_refreshData = true
|
|
end
|
|
end
|
|
|
|
function CSMainMilitaryRanksDetailsView:__delete( )
|
|
if self.cost_item then
|
|
UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem,self.cost_item)
|
|
self.cost_item = nil
|
|
end
|
|
|
|
if self.update_power_change_id then
|
|
RoleManager.Instance.mainRoleInfo:UnBind(self.update_power_change_id)
|
|
self.update_power_change_id = nil
|
|
end
|
|
end
|