forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunittext.lua
More file actions
141 lines (136 loc) · 5.33 KB
/
unittext.lua
File metadata and controls
141 lines (136 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#*****************************************************************************
#* File: lua/ui/game/unittext.lua
#* Summary: Floating text above a unit
#*
#* Copyright © 2008 Gas Powered Games, Inc. All rights reserved.
#*****************************************************************************
local UIUtil = import('/lua/ui/uiutil.lua')
local LayoutHelpers = import('/lua/maui/layouthelpers.lua')
function FloatingEntityText(entryData)
local views = import('/lua/ui/game/worldview.lua').GetWorldViews()
for _, viewControl in views do
local view = viewControl
local text = UIUtil.CreateText(view, entryData.text, 18, UIUtil.bodyFont)
text:SetDropShadow(true)
text:SetColor('ffff7f00')
text:DisableHitTest()
text.coords = GetUnitById(entryData.entity):GetPosition()
text.time = 0
text:SetAlpha(1)
text:SetNeedsFrameUpdate(true)
text.UpdatePosition = function(self)
local coords = view:Project(self.coords)
self.Left:Set(function() return coords[1] - (self.Width() / 2) end)
self.Top:Set(function() return coords[2] - (32*self.time) end)
end
text.OnFrame = function(self, delta)
self.time = self.time + delta
if GetUnitById(entryData.entity) then
if GetCamera(view._cameraName):GetTargetZoom() > 130 then
self:Hide()
else
self:Show()
end
self:UpdatePosition()
local newAlpha = self:GetAlpha() - (delta * .7)
if newAlpha < 0 then
text:Destroy()
newAlpha = 0
end
self:SetAlpha(newAlpha)
else
self:Destroy()
end
end
text:UpdatePosition()
end
end
local timers = {}
function StartCountdown(entryData)
cdDuration = entryData['duration'] or 5
local views = import('/lua/ui/game/worldview.lua').GetWorldViews()
for _, viewControl in views do
local view = viewControl
if not timers[view._cameraName] then
timers[view._cameraName] = {}
end
if timers[view._cameraName][entryData.entity] then
timers[view._cameraName][entryData.entity]:Destroy()
end
timers[view._cameraName][entryData.entity] = UIUtil.CreateText(view, tostring(cdDuration), 18, UIUtil.bodyFont)
local text = timers[view._cameraName][entryData.entity]
text:SetDropShadow(true)
text:SetColor('ffff7f00')
text:DisableHitTest()
text.userEntity = GetUnitById(entryData.entity)
text.position = text.userEntity:GetPosition()
text.time = 0
text.curTime = cdDuration
text.startTime = GetGameTimeSeconds()
text:SetAlpha(1)
text:SetNeedsFrameUpdate(true)
text.UpdateTick = function(self)
if self.userEntity and not self.userEntity:IsDead() then
self.position = self.userEntity:GetPosition()
self:SetAlpha(1)
self:SetText(self.curTime)
else
self:Destroy()
timers[view._cameraName][entryData.entity] = nil
end
end
text.UpdatePosition = function(self)
local coords = view:Project(self.position)
self.Left:Set(function() return view.Left() + coords[1] - (self.Width() / 2) end)
self.Top:Set(function() return view.Top() + coords[2] - 30 end)
end
text.OnFrame = function(self, delta)
self.time = self.time + delta
if not self.userEntity or self.time > cdDuration then
self:Destroy()
timers[view._cameraName][entryData.entity] = nil
end
if GetCamera(view._cameraName):GetTargetZoom() > 130 then
self:Hide()
elseif self.Right() > view.Right() then
self:Hide()
elseif self.Left() < view.Left() then
self:Hide()
elseif self.Bottom() > view.Bottom() then
self:Hide()
elseif self.Top() < view.Top() then
self:Hide()
else
self:Show()
end
if GetGameTimeSeconds() - self.startTime > 1 then
self.curTime = self.curTime - 1
self.startTime = GetGameTimeSeconds()
self:UpdateTick()
end
self:SetAlpha(math.max(self:GetAlpha() - delta, 0))
self:UpdatePosition()
end
text:UpdatePosition()
end
end
function CancelCountdown(entryData)
local views = import('/lua/ui/game/worldview.lua').GetWorldViews()
for _, viewControl in views do
local view = viewControl
if timers[view._cameraName][entryData.entity] then
local timer = timers[view._cameraName][entryData.entity]
timer:SetText(LOC("<LOC Cancelled>Cancelled"))
timer:SetAlpha(1)
timer.OnFrame = function(self, delta)
local newAlpha = self:GetAlpha() - delta
if newAlpha < 0 then
newAlpha = 0
self:Destroy()
timers[view._cameraName][entryData.entity] = nil
end
self:SetAlpha(newAlpha)
end
end
end
end