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

269 rivejä
9.2 KiB

FuliAIView = FuliAIView or BaseClass(BaseItem)
local FuliAIView = FuliAIView
function FuliAIView:__init()
self.use_local_view = true
self.base_file = "fuli"
self.layout_file = "FuliAIView"
self.model = FuliModel:GetInstance()
self.item_list = {}
self.hand_anim_list = {}
self.do_not_set_progress = false
self.is_hide_delete_effect = false
self:Load()
end
function FuliAIView:Load_callback()
self.nodes = {
"item_con","time_text:tmp","effect","role_con",
}
self:GetChildren(self.nodes)
self:AddEvents()
if self.need_refreshData then
self:SetData()
end
self:AddUIEffect("ui_zaixianlibao", self.effect, "UI", Vector3(-126,48,0), 1, true, -1, nil, call_back,nil,nil, 14)
end
function FuliAIView:AddEvents( )
local function on_update_view( )
self:UpdateView()
end
self.on_update_view_id = self.model:Bind(FuliConst.UPDATE_FULI_AI_INFO, on_update_view)
end
function FuliAIView:UpdateView( )
-- if self.model:IsFuliAINeedRed() then
-- self:PlayHandEffect()
-- else
-- self:StopHandEffect()
-- end
self.data = self.model:GetFuliAIInfo()
local cfg = self.model:GetFuliAICFG(self.data.type)
local pos = {
-- {20,-252},{266,-392},{668,-377},{899,-205},{724,-21}
-- {53.8,-128.7},{244.3,-9.5},{448.6,-124.7},{450,-331},{244,-446},{15,-321.8}
{-61,-162.5},{197,-26.5},{393.5,-164},{405,-348},{184,-474},{-44.5,-340}
}
for i,v in ipairs(cfg) do
local item = self.item_list[i]
if not item then
item = FuliAIItem.New(self.item_con)
item:SetPosition(pos[i][1], pos[i][2])
self.item_list[i] = item
end
item:SetData(i,v,self.data)
end
self:UpdateOnlineTime()
-- self:UpdateProgressBar()
end
function FuliAIView:timeConvert(time)
local hoursStr = math.floor(time / 60 / 60) % 24
local minutesStr = math.floor(time / 60) % 60
local secondStr = time % 60
if tonumber(hoursStr) < 10 then hoursStr = 0 .. hoursStr end
if tonumber(minutesStr) < 10 then minutesStr = 0 .. minutesStr end
if tonumber(secondStr) < 10 then secondStr = 0 .. secondStr end
return hoursStr .. HtmlColorTxt("", "#ffffff", 0.8) .. minutesStr .. HtmlColorTxt("", "#ffffff", 0.8) .. secondStr .. HtmlColorTxt("", "#ffffff", 0.8)
end
function FuliAIView:UpdateProgressBar( )
local server_data = self.model:GetFuliAIInfo()
local cfg = self.model:GetFuliAICFG(server_data.type)
local progress_data = {
[1] = {left = 0, right = 0.055,min = 0 , max = 0, minus = 0},
[2] = {left = 0.055, right = 0.271,min = 0 , max = 0, minus = 0},
[3] = {left = 0.33, right = 0.58,min = 0 , max = 0, minus = 0},
[4] = {left = 0.655, right = 0.945,min = 0 , max = 0, minus = 0},
}
for i,v in ipairs(cfg) do
if i == 1 then
progress_data[i].min = 0
progress_data[i].max = v.duration
progress_data[i].minus = progress_data[i].max - progress_data[i].min
progress_data[i].offset = progress_data[i].right - progress_data[i].left
else
progress_data[i].min = cfg[i-1].duration
progress_data[i].max = v.duration
progress_data[i].minus = progress_data[i].max - progress_data[i].min
progress_data[i].offset = progress_data[i].right - progress_data[i].left
end
end
local find = false
if self.do_not_set_progress then--已经填满了就不用再设置了
for i,v in ipairs(progress_data) do
if server_data.duration_time <= v.max and server_data.duration_time >= v.min then
self.progress_image_img.fillAmount = v.left + (server_data.duration_time - v.min)/v.minus * v.offset
find = true
break
end
end
end
if not find and not self.do_not_set_progress then--没找到代表着已经填充完了
self.progress_image_img.fillAmount = 1
self.do_not_set_progress = true
end
local function callback( ... )
self.time_text_tmp.text = self:timeConvert(server_data.duration_time or 0)
local find = false
if self.do_not_set_progress then--已经填满了就不用再设置了
for i,v in ipairs(progress_data) do
if server_data.duration_time <= v.max and server_data.duration_time >= v.min then
self.progress_image_img.fillAmount = v.left + (server_data.duration_time - v.min)/v.minus * v.offset
find = true
break
end
end
end
if not find and not self.do_not_set_progress then--没找到代表着已经填充完了
self.progress_image_img.fillAmount = 1
self.do_not_set_progress = true
end
end
self.model:SetFuncCallBack(callback, "FuliAIView:UpdateProgressBar")
end
function FuliAIView:UpdateOnlineTime( )
local server_data = self.model:GetFuliAIInfo()
local function callback( ... )
self.time_text_tmp.text = self:timeConvert(server_data.duration_time or 0)
end
self.model:SetFuncCallBack(callback, "FuliAIView:UpdateOnlineTime")
end
function FuliAIView:UpdateRoleModel( )
local res_data = {
father_node = self,
transform = self.role_con,
fashion_type = FuncOpenModel.TypeId.FJarvis,
figure_id = 1019,
position = Vector3(-30,-70,0),
scale = 330,
ui_model_type = UIModelCommon.ModelType.BackModel,
action_name_list = {"show"},
rotate = -25,
}
FuncOpenModel:getInstance():SetModelRes(res_data)
end
function FuliAIView:SetData( data )
self.data = data
if self.is_loaded then
self.need_refreshData = false
self.model:Fire(FuliConst.AI_TALK_SHOW, FuliConst.AI_TALK_TYPE.ENTER)
self:UpdateView()
self:UpdateRoleModel()
else
self.need_refreshData = true
end
end
function FuliAIView:PlayHandEffect()
do return end --2020527废弃 防止策划吃书 先留着
if self.is_play_hand_effect then
return
end
cc.ActionManager:getInstance():removeAllActionsFromTarget(self.hand_image_obj)
self.hand_image_obj:SetActive(true)
if not self.hand_image_canvas then
self.hand_image_canvas = self.hand_image:GetComponent("CanvasGroup")
end
self.hand_image_canvas.alpha = 0
local function delayfun()
local id = TweenLite.to(self, self.hand_image_canvas,TweenLite.UiAnimationType.ALPHA, 1, 0.5)
table.insert(self.hand_anim_list, id)
end
local callfun1 = cc.CallFunc.New(delayfun)
local function delayfun2()
self.dot_image_obj:SetActive(true)
self.left_arrow_obj:SetActive(true)
self.right_arrow_obj:SetActive(true)
local time = 1.5
local id = TweenLite.to(self, self.dot_image,TweenLite.UiAnimationType.SCALE, Vector3(1.2,1.2,1.2), time,nil,nil,true)
table.insert(self.hand_anim_list, id)
id = TweenLite.to(self, self.left_arrow, TweenLite.UiAnimationType.ANCHORED_POSX, -204.5, time,nil,nil,true)
table.insert(self.hand_anim_list, id)
id = TweenLite.to(self, self.right_arrow, TweenLite.UiAnimationType.ANCHORED_POSX, 71, time,nil,nil,true)
table.insert(self.hand_anim_list, id)
end
local callfun2 = cc.CallFunc.New(delayfun2)
--再显示出来
local function delayfun3()
end
local callfun3 = cc.CallFunc.New(delayfun3)
local action = cc.Sequence.New(cc.DelayTime.New(0.5),callfun1,cc.DelayTime.New(1), callfun2, cc.DelayTime.New(0.5), callfun3)
cc.ActionManager:getInstance():addAction(action, self.hand_image_obj)
self.is_play_hand_effect = true
end
function FuliAIView:StopHandEffect( )
self.is_play_hand_effect = false
-- if self.hand_image_obj then
-- self.hand_image_obj:SetActive(false)
-- end
if self.dot_image_obj then
self.dot_image_obj:SetActive(false)
end
if self.left_arrow_obj then
self.left_arrow_obj:SetActive(false)
end
if self.right_arrow_obj then
self.right_arrow_obj:SetActive(false)
end
-- cc.ActionManager:getInstance():removeAllActionsFromTarget(self.hand_image_obj)
for i,v in ipairs(self.hand_anim_list) do
TweenLite.Stop(v)
end
self.hand_anim_list = {}
end
-- function FuliAIView:ShowTalkText( type )
-- local cfg = self.model:GetFuliAITalkCFG(type)
-- local max = #cfg
-- local random_num = math.random(1, max)
-- self.talk_text_tmp.text = Trim(cfg[random_num].content)
-- local pos_num = math.random(1,2)
-- if pos_num == 1 then
-- SetAnchoredPosition(self.talk_con, -266, 67)--位置都固定摆的
-- SetAnchoredPosition(self.talk_text, -7, 0)--位置都固定摆的
-- lua_resM:setImageSprite(self, self.talk_con_img, "fuli_asset", "fuli_item27")
-- -- self.talk_arrow.localRotation = Quaternion.Euler(0,0,180)
-- elseif pos_num == 2 then
-- SetAnchoredPosition(self.talk_con, 106, 47)--位置都固定摆的
-- SetAnchoredPosition(self.talk_text, 6, 0)--位置都固定摆的
-- lua_resM:setImageSprite(self, self.talk_con_img, "fuli_asset", "fuli_item26")
-- -- self.talk_arrow.localRotation = Quaternion.Euler(0,0,270)
-- -- elseif pos_num == 3 then
-- -- SetAnchoredPosition(self.talk_con, -413.1, 39)--位置都固定摆的
-- -- SetAnchoredPosition(self.talk_arrow, 194.1, 11.2)--位置都固定摆的
-- -- self.talk_arrow.localRotation = Quaternion.Euler(0,0,0)
-- end
-- self.talk_con_obj:SetActive(true)
-- end
function FuliAIView:__delete( )
-- self.model:DeleteFuncCallBack("FuliAIView:UpdateProgressBar")
self.model:DeleteFuncCallBack("FuliAIView:UpdateOnlineTime")
self:ClearUIEffect(self.effect)
-- self:StopHandEffect()
for i,v in ipairs(self.item_list) do
v:DeleteMe()
v = nil
end
self.item_list = {}
if self.on_update_view_id then
self.model:UnBind(self.on_update_view_id)
self.on_update_view_id = nil
end
if self.on_action_id then
self.model:UnBind(self.on_action_id)
self.on_action_id = nil
end
if self.show_talk_text_id then
self.model:UnBind(self.show_talk_text_id)
self.show_talk_text_id = nil
end
end