-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathscrollwrite-sct.tbm
More file actions
207 lines (167 loc) · 4.37 KB
/
scrollwrite-sct.tbm
File metadata and controls
207 lines (167 loc) · 4.37 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#Conditional Hooks
$Application: FS2_Open
$On Game Init:
[
Scroll = {}
function Scroll:Init()
self.Enabled = false
self.Lines = {}
self.InterfaceSound = 20
self.GameSound = ad.getSoundentry(10)
end
function Scroll:Clear()
self.Enabled = false
self.Lines = {}
end
function Scroll:WriteFromFile(file, x, y, speed, visibletime, fadeout, sound, font, center, r, g, b, loop)
local pos = file:find(".txt", -4, true)
if not pos then
file = file .. ".txt"
end
if cf.fileExists(file, "data/fiction", true) then
local f = cf.openFile(file,"rb","data/fiction")
local data = f:read("*a")
self:Write(data, x, y, speed, visibletime, fadeout, sound, font, center, r, g, b, loop)
f:close()
end
end
function Scroll:Write(text, x, y, speed, visibletime, fadeout, sound, font, center, r, g, b, loop)
if not self.Enabled then
self.Enabled = true
end
local t = {}
if not text then
return
end
if mn.Messages[text]:isValid() then
t.Text = mn.Messages[text]:getMessage(true)
else
t.Text = text
end
t.X = x or 50
t.X = gr.getScreenWidth() * (t.X/100)
t.Y = y or 50
t.Y = gr.getScreenHeight() * (t.Y/100)
t.Speed = speed or 0.03
t.SoundDuration = #t.Text * t.Speed
t.Timestamp = mn.getMissionTime()
t.Time = visibletime or 5
t.FadeOut = fadeout or 0
t.Font = font or 1
if sound == false then
t.Sound = false
else
t.Sound = true
end
if center == false then
t.Center = false
else
t.Center = true
end
t.Color = {r or 255, g or 255, b or 255}
t.Alpha = 255
if loop == true then
t.Loop = true
else
t.Loop = false
end
self.Lines[#self.Lines+1] = t
end
function Scroll:Draw()
local mTime = mn.getMissionTime()
if #self.Lines > 0 then
local numLines = #self.Lines
for i = 1, numLines do
if self.Lines[i] then
local line = self.Lines[i]
if mTime < (line.Timestamp + line.Time + line.FadeOut) then
if line.Sound then
if line.Loop then
line.Handle = ad.playLoopingSound(self.GameSound)
else
ad.playInterfaceSound(self.InterfaceSound)
end
line.Sound = nil
end
local toDraw = (mTime - line.Timestamp) / line.Speed
if toDraw > 0 then
local displayString = line.Text:sub(1, toDraw)
local lastChar = line.Text:sub(-1)
local x, y = line.X, line.Y
gr.CurrentFont = gr.Fonts[line.Font]
if line.Handle and mTime > (line.Timestamp + line.SoundDuration) then
line.Handle:stop()
line.Handle = nil
end
if mTime > (line.Timestamp + line.Time) then
local t = mn.getMissionTime() - (line.Timestamp + line.Time)
line.Alpha = self:Ease(t,255,-255,line.FadeOut)
end
if lastChar == ">" then
line.Speed = 0.05
elseif lastChar == "\\n" then
line.Speed = 0.02
end
gr.setColor(line.Color[1], line.Color[2], line.Color[3], line.Alpha)
if line.Center then
x = line.X - (gr.getStringWidth(line.Text)/2)
end
gr.drawString(displayString,x,y)
end
end
else
table.remove(self.Lines,i)
numLines = numLines - 1
if numLines == 0 then self.Enabled = false end
end
end
end
end
function Scroll:Ease(t,b,c,d)
t = t / d
return -c * t * (t - 2) + b
end
function Scroll:SetInterfaceSound(idx)
if idx then
self.InterfaceSound = idx
end
end
-- this function accepts strings or soundentry types
function Scroll:SetGameSound(entry)
if entry then
if type(entry) == "string" then
entry = ad.getSoundentry(entry)
end
if entry:isValid() then
self.GameSound = entry
end
end
end
mn.LuaSEXPs["lua-scroll-write"].Action = function(text, x, y, speed, visibletime, fadeout, sound, font, center, r, g, b, loop)
Scroll:Write(text, x, y, speed/1000, visibletime/1000, fadeout/1000, sound, font, center, r, g, b, loop)
end
mn.LuaSEXPs["lua-scroll-write-file"].Action = function(file, x, y, speed, visibletime, fadeout, sound, font, center, r, g, b, loop)
Scroll:WriteFromFile(file, x, y, speed/1000, visibletime/1000, fadeout/1000, sound, font, center, r, g, b, loop)
end
mn.LuaSEXPs["lua-scroll-write-clear"].Action = function()
Scroll:Clear()
end
mn.LuaSEXPs["lua-scroll-write-set-iface-snd"].Action = function(idx)
Scroll:SetInterfaceSound(idx)
end
mn.LuaSEXPs["lua-scroll-write-set-game-snd"].Action = function(entry)
Scroll:SetGameSound(entry)
end
]
$State: GS_STATE_GAME_PLAY
$On Gameplay Start:
[
Scroll:Init()
]
$On Frame:
[
if Scroll.Enabled then
Scroll:Draw()
end
]
#End