miduo_client/Assets/ManagedResources/~Lua/Modules/Battle/View/Unit/FloatNode.lua

203 lines
7.0 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

FloatNode = {}
local floatingEffect = "FloatingText"
local buffFloatingEffect = "BuffFloatingText"
-- 普通文字
TextFloatingColor = {
Blue = 1,
Red = 2,
Purple = 3,
Green = 4,
}
local _FloatingTypeToColor = {
[TextFloatingColor.Blue] = Color.New(31, 237, 255, 255) / 255,
[TextFloatingColor.Red] = Color.New(236, 4, 4, 255) / 255,
[TextFloatingColor.Purple] = Color.New(235, 17, 255, 255) / 255,
[TextFloatingColor.Green] = Color.New(17, 255, 17, 255) / 255,
}
-- 艺术字
ArtFloatingType = {
CritDamage = 1, -- 暴击
Damage = 2,
Treat = 3,
FireDamage = 4,
PoisonDamage = 5,
}
local ArtFloatingAnim = {
[1] = "Crit_Attack_Float",
[2] = "Normal_Attack_Float",
[3] = "floatingTextAnim",
[4] = "floatingTextAnim",
[5] = "floatingTextAnim",
}
--角色受到的暴击伤害(无论什么类型) - 红色字体 (字符顺序40-49 ,0-9)(110, -)(111, +)(33, 暴击)(35, 灼烧)
--角色造成的点击技伤害 - 白色字体 (字符顺序50-59 ,0-9)(112, -)(113, +)
--角色造成的滑动技伤害 - 黄色字体 (字符顺序60-69 ,0-9)(114, -)(115, +)
--角色恢复量 - 绿色字体 (字符顺序70-79 ,0-9)(116, -)(117, +)
--角色造成的异妖技伤害 - 紫色字体 (字符顺序80-89 ,0-9)(118, -)(119, +)(34, 中毒)
ArtFloatingColor = {
Red = 0,
White = 1,
Yellow = 2,
Green = 3,
Purple = 4,
Poison = 5,
Fire = 6,
}
function FloatNode.New(unit, root, node)
local o = {}
setmetatable(o, {__index = FloatNode})
o:ctor(unit, root, node)
return o
end
function FloatNode:ctor(unit, root, node)
self.owner = unit
self.RootPanel = root
self.GameObject = node
self.LastBuffTextTime = Time.realtimeSinceStartup
self.BuffTextCount = 0
self.LastFloatingTime = Time.realtimeSinceStartup
self.FloatingCount = 0
end
function FloatNode:TextBuffFloating(type, text)
local color = _FloatingTypeToColor[type]
local go = BattleManager.LoadAsset(buffFloatingEffect)
local baseY = 0
go.transform:SetParent(self.RootPanel.transform)
go.transform.localScale = Vector3.one
go.transform.position = self.GameObject.transform.position
go:SetActive(true)
if Time.realtimeSinceStartup - self.LastBuffTextTime < BattleLogic.GameDeltaTime then
self.BuffTextCount = self.BuffTextCount + 1
else
self.BuffTextCount = 0
end
self.LastBuffTextTime = Time.realtimeSinceStartup
local v2 = go:GetComponent("RectTransform").anchoredPosition
go:GetComponent("RectTransform").anchoredPosition = v2 + Vector2.New(0,baseY + self.BuffTextCount * 60)
local battleSorting = BattleManager.GetBattleSorting()
Util.GetGameObject(go, "anim"):GetComponent("Canvas").sortingOrder = battleSorting + 200
Util.GetGameObject(go, "anim/text"):SetActive(true)
Util.GetGameObject(go, "anim/text"):GetComponent("Text").text = text
Util.GetGameObject(go, "anim/text"):GetComponent("Text").color = color
Util.GetGameObject(go, "anim/grid"):SetActive(false)
BattleManager.AddDelayRecycleRes(buffFloatingEffect, go, 1.3)
end
--
function FloatNode:ImageBuffFloating(textImg, numImg, numTxt)
local go = BattleManager.LoadAsset(buffFloatingEffect)
local baseY = 0
go.transform:SetParent(self.RootPanel.transform)
go.transform.localScale = Vector3.one
go.transform.position = self.GameObject.transform.position
go:SetActive(true)
if Time.realtimeSinceStartup - self.LastBuffTextTime < BattleLogic.GameDeltaTime then
self.BuffTextCount = self.BuffTextCount + 1
else
self.BuffTextCount = 0
end
self.LastBuffTextTime = Time.realtimeSinceStartup
local v2 = go:GetComponent("RectTransform").anchoredPosition
go:GetComponent("RectTransform").anchoredPosition = v2 + Vector2.New(0,baseY + self.BuffTextCount * 60)
local battleSorting = BattleManager.GetBattleSorting()
Util.GetGameObject(go, "anim"):GetComponent("Canvas").sortingOrder = battleSorting + 200
Util.GetGameObject(go, "anim/text"):SetActive(false)
Util.GetGameObject(go, "anim/grid"):SetActive(true)
local img1 = Util.GetGameObject(go, "anim/grid/Image1"):GetComponent("Image")
local img2 = Util.GetGameObject(go, "anim/grid/Image2"):GetComponent("Image")
local txt3 = Util.GetGameObject(go, "anim/grid/Text"):GetComponent("Text")
if textImg then
img1.gameObject:SetActive(true)
img1.sprite = Util.LoadSprite(textImg)
img1:SetNativeSize()
else
img1.gameObject:SetActive(false)
end
if numImg then
img2.gameObject:SetActive(true)
img2.sprite = Util.LoadSprite(numImg)
img2:SetNativeSize()
else
img2.gameObject:SetActive(false)
end
if numTxt then
txt3.gameObject:SetActive(true)
txt3.text = numTxt
else
txt3.gameObject:SetActive(false)
end
BattleManager.AddDelayRecycleRes(buffFloatingEffect, go, 1.3)
end
function FloatNode:GetArtText(type, color, value)
local text = ""
if type == ArtFloatingType.CritDamage then
text = text .. string.char(33) -- 暴击文字
text = text .. string.char((color*2)+110) -- 减号
elseif type == ArtFloatingType.Damage then
text = text .. string.char((color*2)+110) -- 减号
elseif type == ArtFloatingType.Treat then
text = text..string.char((color*2)+111) -- 加号
elseif type == ArtFloatingType.FireDamage then
text = text .. string.char(35) -- 灼烧文字
text = text .. string.char((color*2)+110) -- 减号
elseif type == ArtFloatingType.PoisonDamage then
text = text .. string.char(34) -- 中毒文字
text = text .. string.char((color*2)+110) -- 减号
end
-- 数字
local str = tostring(value)
for i=1,#str do
text = text..string.char((string.byte(str,i) - 48) + color*10 + 40)
end
return text
end
function FloatNode:ArtFloating(type, color, value)
local go = BattleManager.LoadAsset(floatingEffect)
go.transform:SetParent(self.RootPanel.transform)
go.transform.localScale = Vector3.one * 0.7
go.transform.position = self.GameObject.transform.position
go:SetActive(true)
if Time.realtimeSinceStartup - self.LastFloatingTime < BattleLogic.GameDeltaTime then
self.FloatingCount = self.FloatingCount + 1
else
self.FloatingCount = 0
end
self.LastFloatingTime = Time.realtimeSinceStartup
local v2 = go:GetComponent("RectTransform").anchoredPosition
v2 = v2 + Vector2.New(0, self.owner.role.camp * 100 + 100)
go:GetComponent("RectTransform").anchoredPosition = v2 + Vector2.New(0, 50) * (self.FloatingCount+1)
local text = self:GetArtText(type, color, value)
local anim = Util.GetGameObject(go, "anim")
anim:GetComponent("Text").text = text
anim:GetComponent("Canvas").sortingOrder = BattleManager.GetBattleSorting() + 100
anim:GetComponent("Animator"):Play(ArtFloatingAnim[type])
BattleManager.AddDelayRecycleRes(floatingEffect, go, 2)
end
return FloatNode