源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

162 lines
5.0 KiB

CSGWarCityItem = CSGWarCityItem or BaseClass(BaseItem)
local CSGWarCityItem = CSGWarCityItem
local math_floor = math.floor
function CSGWarCityItem:__init()
self.base_file = "CSGWar"
self.layout_file = "CSGWarCityItem"
self.model = CSGWarModel:GetInstance()
self.gray_mat = ShaderTools.gray_mat
self:Load()
self.is_selected = false
end
function CSGWarCityItem:Load_callback()
self.nodes = {
"city_image:imgex", "bg:obj:imgex", "name_text:tmp", "progress_text:tmp", "progress_image:img", "click_con:obj",
"near_image:obj", "pic_select:obj",
}
self:GetChildren(self.nodes)
self.country = KfWorldModel:GetInstance():GetMyCountryId()
self:AddEvents()
if self.need_refreshData then
self:UpdateView()
end
end
function CSGWarCityItem:AddEvents( )
function on_click( )
-- if self.call_back then
-- self.call_back(self.data, self.index)
-- end
if not self.has_city and self.index == 1 then
Message.show("必须占领据点才能抢夺主城")
return
end
if self.cfg then
local city_pos = self.cfg.city_pos
if not city_pos then
city_pos = stringtotable(self.cfg.flag)
end
local function call_back( ... )
GlobalEventSystem:Fire(EventName.STARTAUTOFIGHT)
end
local findVo = FindVo.New()
findVo.sceneId = SceneManager.Instance:GetSceneId()
findVo.type = FindVo.POINT
findVo.x = city_pos[2]/ SceneObj.LogicRealRatio.x
findVo.y = city_pos[3]/ SceneObj.LogicRealRatio.y
findVo.call_back = call_back
GlobalEventSystem:Fire(EventName.FIND,findVo)
if self.select_callback then
self.select_callback(self.index)
end
end
end
AddClickEvent(self.click_con_obj, on_click)
end
function CSGWarCityItem:UpdateView( )
self.bg_obj:SetActive(self.index == 1)
if not self.cfg then
self.cfg = Config.Crossguildwarscene[self.index]
end
self.has_central = false--是否占据中心城
self.bg_imgex.gray = false
self.city_image_imgex.gray = false
if self.data then
local color = ColorUtil.WHITE_DARK
if tonumber(self.country) == tonumber(self.data.group) and self.data.group ~= 0 then
color = ColorUtil.GREEN_DARK
lua_resM:setImageSprite(self, self.progress_image_img, "CSGWar_asset", "CSGWar_item19")
elseif self.data.guild_id ~= 0 then
color = ColorUtil.RED_DARK
lua_resM:setImageSprite(self, self.progress_image_img, "CSGWar_asset", "CSGWar_item14")
else
lua_resM:setImageSprite(self, self.progress_image_img, "CSGWar_asset", "CSGWar_item14")
end
if self.data.guild_id ~= 0 then
self.name_text_tmp.text = string.format("%s %s", self.cfg.name, HtmlColorTxt(self.data.guild_name, color))
else
self.name_text_tmp.text = HtmlColorTxt(string.format("%s <u>【点击前往】</u>", self.cfg.name), color)
end
local precent = self.data.blood/self.data.max_blood
self.progress_image_img.fillAmount = precent
self.progress_text_tmp.text = string.format("%s/100", math_floor(precent*100))
if not self.has_city and self.index == 1 then
self.name_text_tmp.text = HtmlColorTxt("(请先占领一个据点)", color)
self.bg_imgex.gray = true
self.city_image_imgex.gray = true
self.progress_image_img.material = self.gray_mat
else
self.progress_image_img.material = nil
end
else
local color = ColorUtil.WHITE_DARK
self.progress_image_img.fillAmount = 1
self.progress_text_tmp.text = "100/100"
self.name_text_tmp.text = HtmlColorTxt(string.format("%s <u>【点击前往】</u>", self.cfg.name), color)
if not self.has_city and self.index == 1 then
self.name_text_tmp.text = HtmlColorTxt("(请先占领一个据点)", color)
self.bg_imgex.gray = true
self.city_image_imgex.gray = true
self.progress_image_img.material = self.gray_mat
else
self.progress_image_img.material = nil
end
end
lua_resM:setImageSprite(self, self.city_image_imgex, "CSGWar_asset", "CSGWar_city"..self.index)
if self.near_index == self.index then
self.near_image_obj:SetActive(true)
self:StartNearImageShowTime(30)
self.near_index = nil
end
-- 选中
self:SetSelected(self.is_selected)
end
function CSGWarCityItem:SetCallBackFunc( func )
self.call_back = func
end
function CSGWarCityItem:StartNearImageShowTime( time )
local function on_show_time()
time = time - 1
if time > 0 then
else
self.near_image_obj:SetActive(false)
GlobalTimerQuest:CancelQuest(self.show_timer_id)
self.show_timer_id = nil
end
end
self.show_timer_id = GlobalTimerQuest:AddPeriodQuest(on_show_time, 1, -1)
end
function CSGWarCityItem:SetData( data, index, has_city, near_index, select_callback)
self.data = data
self.index = index
self.has_city = has_city
self.near_index = self.near_index or near_index
self.select_callback = select_callback
if self.is_loaded then
self.need_refreshData = false
self:UpdateView()
else
self.need_refreshData = true
end
end
function CSGWarCityItem:SetSelected(is_selected)
self.is_selected = is_selected
if self.is_loaded then
self.pic_select_obj:SetActive(self.is_selected)
end
end
function CSGWarCityItem:__delete( )
if self.show_timer_id then
GlobalTimerQuest:CancelQuest(self.show_timer_id)
self.show_timer_id = nil
end
end