Skip to content

Commit

Permalink
some scrollwrite changes
Browse files Browse the repository at this point in the history
This changes the sound handling so that an in-mission looping sound is played for as long as the text is scrolling, and then stops when the text finishes scrolling.  Right now beep_5.wav is used as a placeholder sound effect; textdraw.wav could also be used, but it would have to be copied into the in-mission sound section in sounds.tbl.

Also adds an important detail to sexp help, and removes trailing whitespace in the script.
  • Loading branch information
Goober5000 committed Jul 11, 2020
1 parent 321df85 commit f54dcb9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 46 deletions.
95 changes: 50 additions & 45 deletions ScrollWrite/data/tables/scrollwrite-sct.tbm
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ function Scroll:Init()

self.Enabled = false
self.Lines = {}
self.SoundEntry = ad.getSoundentry(10)

end

function Scroll:Clear()

self.Lines = {}
self.Enabled = false
self.Lines = {}
self.SoundEntry = nil

end

function Scroll:WriteFromFile(file, x, y, speed, visibletime, fadeout, sound, font, center, r, g, b)

local pos = file:find(".txt", -4, true)

if not pos then
file = file .. ".txt"
end
Expand All @@ -43,22 +45,23 @@ function Scroll:Write(text, x, y, speed, visibletime, fadeout, sound, font, cent
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
Expand All @@ -75,63 +78,65 @@ function Scroll:Write(text, x, y, speed, visibletime, fadeout, sound, font, cent
end
t.Color = {r or 255, g or 255, b or 255}
t.Alpha = 255
self.Lines[#self.Lines+1] = t

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
ad.playInterfaceSound(20)
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 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
local line = self.Lines[i]
if mTime < (line.Timestamp + line.Time + line.FadeOut) then
if line.Sound then
line.Handle = ad.playLoopingSound(self.SoundEntry)
line.Sound = nil
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)
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 mTime > (line.Timestamp + line.SoundDuration) then
if line.Handle then
line.Handle:stop()
line.Handle = nil
end
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

finalString = displayString


gr.drawString(finalString,x,y)

end
end
else
table.remove(self.Lines,i)
numLines = numLines - 1

if numLines == 0 then self.Enabled = false end

end
end
end
Expand Down
2 changes: 1 addition & 1 deletion ScrollWrite/data/tables/scrollwrite-sexp.tbm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $Maximum Arguments: 12
$Return Type: Nothing
$Description: Writes a subtitle-esque string of text but one character at a time. Use this to spruce up your cutscenes!
$Parameter:
+Description: Text to write
+Description: Text to write, or name of a message containing text
+Type: string
$Parameter:
+Description: X coordinate to begin drawing at (based on percent of the screen width, 0-100). Default is 50
Expand Down

0 comments on commit f54dcb9

Please sign in to comment.