源战役客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

162 rindas
5.0 KiB

pirms 4 nedēļām
  1. CSGWarCityItem = CSGWarCityItem or BaseClass(BaseItem)
  2. local CSGWarCityItem = CSGWarCityItem
  3. local math_floor = math.floor
  4. function CSGWarCityItem:__init()
  5. self.base_file = "CSGWar"
  6. self.layout_file = "CSGWarCityItem"
  7. self.model = CSGWarModel:GetInstance()
  8. self.gray_mat = ShaderTools.gray_mat
  9. self:Load()
  10. self.is_selected = false
  11. end
  12. function CSGWarCityItem:Load_callback()
  13. self.nodes = {
  14. "city_image:imgex", "bg:obj:imgex", "name_text:tmp", "progress_text:tmp", "progress_image:img", "click_con:obj",
  15. "near_image:obj", "pic_select:obj",
  16. }
  17. self:GetChildren(self.nodes)
  18. self.country = KfWorldModel:GetInstance():GetMyCountryId()
  19. self:AddEvents()
  20. if self.need_refreshData then
  21. self:UpdateView()
  22. end
  23. end
  24. function CSGWarCityItem:AddEvents( )
  25. function on_click( )
  26. -- if self.call_back then
  27. -- self.call_back(self.data, self.index)
  28. -- end
  29. if not self.has_city and self.index == 1 then
  30. Message.show("必须占领据点才能抢夺主城")
  31. return
  32. end
  33. if self.cfg then
  34. local city_pos = self.cfg.city_pos
  35. if not city_pos then
  36. city_pos = stringtotable(self.cfg.flag)
  37. end
  38. local function call_back( ... )
  39. GlobalEventSystem:Fire(EventName.STARTAUTOFIGHT)
  40. end
  41. local findVo = FindVo.New()
  42. findVo.sceneId = SceneManager.Instance:GetSceneId()
  43. findVo.type = FindVo.POINT
  44. findVo.x = city_pos[2]/ SceneObj.LogicRealRatio.x
  45. findVo.y = city_pos[3]/ SceneObj.LogicRealRatio.y
  46. findVo.call_back = call_back
  47. GlobalEventSystem:Fire(EventName.FIND,findVo)
  48. if self.select_callback then
  49. self.select_callback(self.index)
  50. end
  51. end
  52. end
  53. AddClickEvent(self.click_con_obj, on_click)
  54. end
  55. function CSGWarCityItem:UpdateView( )
  56. self.bg_obj:SetActive(self.index == 1)
  57. if not self.cfg then
  58. self.cfg = Config.Crossguildwarscene[self.index]
  59. end
  60. self.has_central = false--是否占据中心城
  61. self.bg_imgex.gray = false
  62. self.city_image_imgex.gray = false
  63. if self.data then
  64. local color = ColorUtil.WHITE_DARK
  65. if tonumber(self.country) == tonumber(self.data.group) and self.data.group ~= 0 then
  66. color = ColorUtil.GREEN_DARK
  67. lua_resM:setImageSprite(self, self.progress_image_img, "CSGWar_asset", "CSGWar_item19")
  68. elseif self.data.guild_id ~= 0 then
  69. color = ColorUtil.RED_DARK
  70. lua_resM:setImageSprite(self, self.progress_image_img, "CSGWar_asset", "CSGWar_item14")
  71. else
  72. lua_resM:setImageSprite(self, self.progress_image_img, "CSGWar_asset", "CSGWar_item14")
  73. end
  74. if self.data.guild_id ~= 0 then
  75. self.name_text_tmp.text = string.format("%s %s", self.cfg.name, HtmlColorTxt(self.data.guild_name, color))
  76. else
  77. self.name_text_tmp.text = HtmlColorTxt(string.format("%s <u>【点击前往】</u>", self.cfg.name), color)
  78. end
  79. local precent = self.data.blood/self.data.max_blood
  80. self.progress_image_img.fillAmount = precent
  81. self.progress_text_tmp.text = string.format("%s/100", math_floor(precent*100))
  82. if not self.has_city and self.index == 1 then
  83. self.name_text_tmp.text = HtmlColorTxt("(请先占领一个据点)", color)
  84. self.bg_imgex.gray = true
  85. self.city_image_imgex.gray = true
  86. self.progress_image_img.material = self.gray_mat
  87. else
  88. self.progress_image_img.material = nil
  89. end
  90. else
  91. local color = ColorUtil.WHITE_DARK
  92. self.progress_image_img.fillAmount = 1
  93. self.progress_text_tmp.text = "100/100"
  94. self.name_text_tmp.text = HtmlColorTxt(string.format("%s <u>【点击前往】</u>", self.cfg.name), color)
  95. if not self.has_city and self.index == 1 then
  96. self.name_text_tmp.text = HtmlColorTxt("(请先占领一个据点)", color)
  97. self.bg_imgex.gray = true
  98. self.city_image_imgex.gray = true
  99. self.progress_image_img.material = self.gray_mat
  100. else
  101. self.progress_image_img.material = nil
  102. end
  103. end
  104. lua_resM:setImageSprite(self, self.city_image_imgex, "CSGWar_asset", "CSGWar_city"..self.index)
  105. if self.near_index == self.index then
  106. self.near_image_obj:SetActive(true)
  107. self:StartNearImageShowTime(30)
  108. self.near_index = nil
  109. end
  110. -- 选中
  111. self:SetSelected(self.is_selected)
  112. end
  113. function CSGWarCityItem:SetCallBackFunc( func )
  114. self.call_back = func
  115. end
  116. function CSGWarCityItem:StartNearImageShowTime( time )
  117. local function on_show_time()
  118. time = time - 1
  119. if time > 0 then
  120. else
  121. self.near_image_obj:SetActive(false)
  122. GlobalTimerQuest:CancelQuest(self.show_timer_id)
  123. self.show_timer_id = nil
  124. end
  125. end
  126. self.show_timer_id = GlobalTimerQuest:AddPeriodQuest(on_show_time, 1, -1)
  127. end
  128. function CSGWarCityItem:SetData( data, index, has_city, near_index, select_callback)
  129. self.data = data
  130. self.index = index
  131. self.has_city = has_city
  132. self.near_index = self.near_index or near_index
  133. self.select_callback = select_callback
  134. if self.is_loaded then
  135. self.need_refreshData = false
  136. self:UpdateView()
  137. else
  138. self.need_refreshData = true
  139. end
  140. end
  141. function CSGWarCityItem:SetSelected(is_selected)
  142. self.is_selected = is_selected
  143. if self.is_loaded then
  144. self.pic_select_obj:SetActive(self.is_selected)
  145. end
  146. end
  147. function CSGWarCityItem:__delete( )
  148. if self.show_timer_id then
  149. GlobalTimerQuest:CancelQuest(self.show_timer_id)
  150. self.show_timer_id = nil
  151. end
  152. end