@@ -9,20 +9,22 @@ function Scroll:Init()
99
1010 self.Enabled = false
1111 self.Lines = {}
12+ self.SoundEntry = ad.getSoundentry(10)
1213
1314end
1415
1516function Scroll:Clear()
1617
17- self.Lines = {}
1818 self.Enabled = false
19+ self.Lines = {}
20+ self.SoundEntry = nil
1921
2022end
2123
2224function Scroll:WriteFromFile(file, x, y, speed, visibletime, fadeout, sound, font, center, r, g, b)
2325
2426 local pos = file:find(".txt", -4, true)
25-
27+
2628 if not pos then
2729 file = file .. ".txt"
2830 end
@@ -43,22 +45,23 @@ function Scroll:Write(text, x, y, speed, visibletime, fadeout, sound, font, cent
4345 end
4446
4547 local t = {}
46-
48+
4749 if not text then
4850 return
4951 end
50-
52+
5153 if mn.Messages[text]:isValid() then
5254 t.Text = mn.Messages[text]:getMessage(true)
5355 else
5456 t.Text = text
5557 end
56-
58+
5759 t.X = x or 50
5860 t.X = gr.getScreenWidth() * (t.X/100)
5961 t.Y = y or 50
6062 t.Y = gr.getScreenHeight() * (t.Y/100)
6163 t.Speed = speed or 0.03
64+ t.SoundDuration = #t.Text * t.Speed
6265 t.Timestamp = mn.getMissionTime()
6366 t.Time = visibletime or 5
6467 t.FadeOut = fadeout or 0
@@ -75,63 +78,65 @@ function Scroll:Write(text, x, y, speed, visibletime, fadeout, sound, font, cent
7578 end
7679 t.Color = {r or 255, g or 255, b or 255}
7780 t.Alpha = 255
78-
79- self.Lines[#self.Lines+1] = t
81+
82+ self.Lines[#self.Lines+1] = t
8083
8184end
8285
8386function Scroll:Draw()
8487
8588 local mTime = mn.getMissionTime()
86-
89+
8790 if #self.Lines > 0 then
8891 local numLines = #self.Lines
8992 for i = 1, numLines do
9093 if self.Lines[i] then
91- local line = self.Lines[i]
92- if mTime < (line.Timestamp + line.Time + line.FadeOut) then
93- if line.Sound then
94- ad.playInterfaceSound(20)
95- line.Sound = nil
96- end
97- local toDraw = (mTime - line.Timestamp) / line.Speed
98- if toDraw > 0 then
99- local displayString = line.Text:sub(1, toDraw)
100- local lastChar = line.Text:sub(-1)
101- local x, y = line.X, line.Y
102-
103- gr.CurrentFont = gr.Fonts[line.Font]
104-
105- if mTime > (line.Timestamp + line.Time) then
106- local t = mn.getMissionTime() - (line.Timestamp + line.Time)
107- line.Alpha = self:Ease(t,255,-255,line.FadeOut)
108- end
109-
110- if lastChar == ">" then
111- line.Speed = 0.05
112- elseif lastChar == "\\n" then
113- line.Speed = 0.02
94+ local line = self.Lines[i]
95+ if mTime < (line.Timestamp + line.Time + line.FadeOut) then
96+ if line.Sound then
97+ line.Handle = ad.playLoopingSound(self.SoundEntry)
98+ line.Sound = nil
11499 end
115-
116- gr.setColor(line.Color[1], line.Color[2], line.Color[3], line.Alpha)
117-
118- if line.Center then
119- x = line.X - (gr.getStringWidth(line.Text)/2)
100+ local toDraw = (mTime - line.Timestamp) / line.Speed
101+ if toDraw > 0 then
102+ local displayString = line.Text:sub(1, toDraw)
103+ local lastChar = line.Text:sub(-1)
104+ local x, y = line.X, line.Y
105+
106+ gr.CurrentFont = gr.Fonts[line.Font]
107+
108+ if mTime > (line.Timestamp + line.SoundDuration) then
109+ if line.Handle then
110+ line.Handle:stop()
111+ line.Handle = nil
112+ end
113+ end
114+ if mTime > (line.Timestamp + line.Time) then
115+ local t = mn.getMissionTime() - (line.Timestamp + line.Time)
116+ line.Alpha = self:Ease(t,255,-255,line.FadeOut)
117+ end
118+
119+ if lastChar == ">" then
120+ line.Speed = 0.05
121+ elseif lastChar == "\\n" then
122+ line.Speed = 0.02
123+ end
124+
125+ gr.setColor(line.Color[1], line.Color[2], line.Color[3], line.Alpha)
126+
127+ if line.Center then
128+ x = line.X - (gr.getStringWidth(line.Text)/2)
129+ end
130+
131+ gr.drawString(displayString,x,y)
120132 end
121-
122- finalString = displayString
123-
124-
125- gr.drawString(finalString,x,y)
126-
127133 end
128- end
129134 else
130135 table.remove(self.Lines,i)
131136 numLines = numLines - 1
132-
137+
133138 if numLines == 0 then self.Enabled = false end
134-
139+
135140 end
136141 end
137142 end
0 commit comments