Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add printCaption e2functions #3172

Merged
merged 4 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lua/entities/gmod_wire_expression2/core/cl_debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ CreateClientConVar("wire_expression2_clipboard_allow", 0, true, true, "Allow E2

net.Receive("wire_expression2_set_clipboard_text", function(len, ply)
SetClipboardText(net.ReadString())
end)

net.Receive("wire_expression2_caption", function()
gui.AddCaption(net.ReadData(net.ReadUInt(16)), net.ReadDouble(), net.ReadBool())
end)
40 changes: 40 additions & 0 deletions lua/entities/gmod_wire_expression2/core/debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -514,4 +514,44 @@ e2function void setClipboardText(string text)
net.Start("wire_expression2_set_clipboard_text")
net.WriteString(text)
net.Send(self.player)
end


-- Closed Captions

util.AddNetworkString("wire_expression2_caption")

-- Maximum seconds a caption can be displayed for
local MAX_CAPTION_DURATION = 7

local function send_caption(self, text, duration, fromPlayer)
if duration < 0 then return end -- <0 duration doesn't display normally
local ply = self.player
if not checkDelay(ply) then return end

local max_len = math.min(maxLength:GetInt(), ply:GetInfoNum("wire_expression2_print_max_length", defaultMaxLength))

text = string.sub(text, 1, max_len)
duration = math.min(duration, MAX_CAPTION_DURATION)

local len = #text

self.prf = self.prf + len / 8

net.Start("wire_expression2_caption")
net.WriteUInt(len, 16)
net.WriteData(text)
net.WriteDouble(duration)
net.WriteBool(fromPlayer)
net.Send(ply)
end

__e2setcost(100)

e2function void printCaption(string text, number duration, number fromPlayer)
send_caption(self, text, duration, fromPlayer)
end

e2function void printCaption(string text, number duration)
send_caption(self, text, duration, false)
end
2 changes: 2 additions & 0 deletions lua/wire/client/e2descriptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,8 @@ E2Helper.Descriptions["printColorDriver(e:r)"] = "Like printColorDriver but take
E2Helper.Descriptions["printTable(t)"] = "Prints a table like the lua function PrintTable does, except to the chat area"
E2Helper.Descriptions["printTable(r)"] = "Prints an array like the lua function PrintTable does, except to the chat area"
E2Helper.Descriptions["setClipboardText(s)"] = "Adds the given string to the chip owners clipboard"
E2Helper.Descriptions["printCaption(snn)"] = "Emits a closed caption with the provided text and duration in seconds. The last argument is used to control the playerclr code"
E2Helper.Descriptions["printCaption(sn)"] = "Emits a closed caption with the provided text and duration in seconds"

-- Time
E2Helper.Descriptions["tickClk()"] = "DEPRECATED. Use 'event tick()' instead! Returns 1 if the current execution was caused by \"runOnTick\""
Expand Down
Loading