源战役客户端
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.
 
 
 
 
 

183 lines
4.8 KiB

GuideIntroduceView = GuideIntroduceView or BaseClass(BaseView)
local GuideIntroduceView = GuideIntroduceView
function GuideIntroduceView:__init()
self.base_file = "guide"
self.layout_file = "GuideIntroduceView"
self.layer_name = "Top"
self.destroy_imm = true
self.use_background = true
self.is_set_order_sorting = false
self.is_set_zdepth = true
self.model = GuideModel:getInstance()
self.load_callback = function ()
self:LoadSuccess()
self:InitEvent()
end
self.open_callback = function ()
self:InitView()
end
self.close_callback = function ()
GlobalEventSystem:Fire(EventName.START_AUTO_DO_TASK)
end
self.destroy_callback = function ()
self:Clear()
end
end
function GuideIntroduceView:Open(helpVo)
self.helpVo = helpVo
BaseView.Open(self)
end
function GuideIntroduceView:Clear()
self:CancelTimer()
end
function GuideIntroduceView:Close()
BaseView.Close(self)
end
function GuideIntroduceView:LoadSuccess()
self.black_bg,
self.nameCon = self:GetChildTransforms({
"Mask",
"nameCon",
})
self.chapter_name_txt,
self.sub_chapter_name_txt,
self.content_txt,
self.time = self:GetChildTexts({
"Name",
"SubName",
"Content",
"time",
})
self.jumpBtn
= GetChildGameObjects(self.transform,
{
"jumpBtn",
})
self.black_bg.sizeDelta = Vector2(ScreenWidth,ScreenHeight)
self.black_bg.gameObject:SetActive(false)
end
function GuideIntroduceView:InitEvent()
local function onClickHandler(target)
if target == self.jumpBtn then
self:Close()
end
end
AddClickEvent(self.jumpBtn, onClickHandler, 2)
end
function GuideIntroduceView:InitView()
if not self.helpVo then
return
end
self:SetNameImage()
-- self.chapter_name_txt.text = self.helpVo.chapter or ""
self.sub_chapter_name_txt.text = self.helpVo.sub_chapter or ""
self.content_txt.text = Trim(self.helpVo.saying) or ""
self.time_num = 5
self.time.text = "("..self.time_num.."秒后自动关闭)"
-- local func = function ()
-- if self._use_delete_method then
-- return
-- end
-- self:CancelTimer()
-- self:FinishHelp()
-- self:Close()
-- end
-- self.timer_id = TimerQuest.AddDelayQuest(GlobalTimerQuest, func, self.time_num)
local function onTimer()
self.time_num = self.time_num - 1
self.time.text = "("..self.time_num.."秒后自动关闭)"
if self.time_num <= 0 then
self:CancelTimer()
self:FinishHelp()
self:Close()
end
end
self.timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer, 1, -1)
end
function GuideIntroduceView:CancelTimer()
if self.timer_id then
TimerQuest.CancelQuest(GlobalTimerQuest, self.timer_id)
self.timer_id = nil
end
end
function GuideIntroduceView:FinishHelp( )
--结束引导
local helpVo = GuideModel:getInstance():GetHelpVo(HelpType.SHOW_CHAPTER,1)
if helpVo then
GlobalEventSystem:Fire(EventName.FINISH_CURRENT_HELP_STEP,helpVo)
end
end
--设置名字图片
function GuideIntroduceView:SetNameImage()
if not self.helpVo then return end
-- 这里的chapter默认是 1,2..21..33等罗马数字的这种格式
if self.helpVo.chapter then
local vo = self.helpVo.chapter
-- local vo = "31"
local num_table = self:GetNumber(vo)
-- local num_len = string.len(vo)
local num_len = #num_table
self.nameCon.sizeDelta = co.TableXY((num_len + 2)*52, self.nameCon.sizeDelta.y)
local image_root
local image_icon
local res = "icon_zj_"
local first_pos
image_root = UiFactory.createChild(self.nameCon, UIType.ImageExtend) --先创建 "第" 字
image_icon = image_root:GetComponent("ImageExtend")
SetAnchoredPosition(image_root.transform, -(num_len + 2)*52/2 + 26, 0)
lua_resM:setImageSprite(self, image_icon, "guide_asset", res.."0", true)
first_pos = -(num_len + 2)*52/2 + 26
if num_table then
for k,v in pairs(num_table) do
image_root = UiFactory.createChild(self.nameCon, UIType.ImageExtend) --再创建 中间的数字
image_icon = image_root:GetComponent("ImageExtend")
first_pos = first_pos + 52
SetAnchoredPosition(image_root.transform, first_pos, 0)
lua_resM:setImageSprite(self, image_icon, "guide_asset", res..v, true)
end
end
image_root = UiFactory.createChild(self.nameCon, UIType.ImageExtend) --最后创建 "章" 字
image_icon = image_root:GetComponent("ImageExtend")
SetAnchoredPosition(image_root.transform, (num_len + 2)*52/2 - 26, 0)
lua_resM:setImageSprite(self, image_icon, "guide_asset", res.."11", true)
end
end
function GuideIntroduceView:GetNumber(num)
local num_table = {}
local num = tonumber(num)
if num >= 1 and num <= 10 then
table.insert(num_table, num)
elseif num > 10 and num <= 19 then
table.insert(num_table, 10)
table.insert(num_table, num - 10)
elseif num > 10 and num <= 99 then
local ten, unit = math.modf(num/10)
table.insert(num_table, ten)
table.insert(num_table, 10)
table.insert(num_table, unit * 10)
end
return num_table
end