miduo_client/Assets/ManagedResources/~Lua/Modules/Map/View/IconShowView.lua

131 lines
3.8 KiB
Lua

---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by Steven Hawking.
--- DateTime: 2019/11/5 19:19
--- 遭遇不同的图标时的表现方法
require("Modules/Map/Config/MapConfig")
-- 角色当前的朝向
local FACE_DIR = {
LEFT = 1,
RIGHT = 2,
}
-- 是否已经显示了对话
local hadShowStr = false
local m_roleFaceDir = FACE_DIR.LEFT
-- 角色对话气泡位置
local m_roleTextPos = {
[3] = {pos = Vector3.New(152, 200, 0), angleOffset = 180}, -- 角色朝左, 气泡在右
[4] = {pos = Vector3.New(-157, 204, 0), angleOffset = 0} -- 反之
}
local this = {}
--- 总入口
--- @eventPoint 参数结构
--- eventPoint.cell
--- eventPoint.iconId
function this.SetIconShowByType(eventPoint, iconPos, roleView)
m_roleFaceDir = this.GetRoleFaceDir(iconPos, roleView.leaderMapData)
if eventPoint.iconId == MapIconType.ICON_BUSY_WANDER_MAN then
this.MeetBusinessMan(eventPoint, roleView)
end
end
-- 遇到一个商人
function this.MeetBusinessMan(eventPoint, roleGo)
-- 已经显示了对话,不再显示
if hadShowStr then return end
hadShowStr = true
-- 显示文字
local contents = IconShowStr[eventPoint.iconId]
local str = contents[math.random(1, #contents)]
-- 设置各自对话框的朝向
this.SetDialogueDir(true, false, eventPoint, roleGo)
-- 设置对话内容
local textGo = Util.GetGameObject(eventPoint.go, "Dialogue/Text"):GetComponent("Text")
textGo.text = ""
local tween = textGo:DOText(str, 0.5)
local timer = nil
tween:OnComplete(function ()
timer = Timer.New(function ()
timer:Stop()
eventPoint:ShowDialogue(false)
hadShowStr = false
end, 1.5)
timer:Start()
end)
end
--- 我自己在那瞎BB
function this.RoleTalk(eventPoint, roleGo)
-- 已经显示了对话,不再显示
if hadShowStr then return end
hadShowStr = true
-- 显示文字
local contents = RoleStr[eventPoint.iconId]
local str = contents[math.random(1, #contents)]
-- 设置各自对话框的朝向
this.SetDialogueDir(false, true, eventPoint, roleGo)
-- 设置对话内容
local textGo = roleGo.context
textGo.text = ""
local tween = textGo:DOText(str, 0.5)
local timer = nil
tween:OnComplete(function ()
timer = Timer.New(function ()
timer:Stop()
roleGo.dialogueRoot:SetActive(false)
hadShowStr = false
end, 1.5)
timer:Start()
end)
end
-- 封装方法
-- 获取角色朝向
function this.GetRoleFaceDir(iconPos, rolePosInfo)
local rolePos = rolePosInfo.u * 256 + rolePosInfo.v
local u0, v0 = Map_Pos2UV(rolePos)
local u, v = Map_Pos2UV(iconPos)
local faceDir = 0
if u0 > u then
-- Log("他要朝左左左左左")
faceDir = FACE_DIR.LEFT
elseif u0 < u then
-- Log("他要朝右右右右")
faceDir = FACE_DIR.RIGHT
end
return faceDir
end
--- 设置大家对话框的朝向
---@ showMonter 是否设置地图图标的对话框
function this.SetDialogueDir(showMonter, showRole, point, roleGo)
local index = m_roleFaceDir == FACE_DIR.RIGHT and 4 or 3
if showRole then
-- 设置角色,
roleGo.dialogueRoot:SetActive(true)
roleGo.dialogueRoot.transform.localEulerAngles = Vector3.New(0, m_roleTextPos[index].angleOffset, 0)
roleGo.context.transform.localEulerAngles = Vector3.New(0, m_roleTextPos[index].angleOffset, 0)
roleGo.dialogueRoot.transform.localPosition = m_roleTextPos[index].pos
end
if showMonter then
-- 设置老头
local oldManAngle = Vector3.New(0, IconTextPos[point.iconId][index].angleOffset, 0)
point:SetDialogueDir(IconTextPos[point.iconId][index].pos, oldManAngle)
point:ShowDialogue(showMonter)
end
end
return this