Skip to content

Commit

Permalink
Implement changing speed
Browse files Browse the repository at this point in the history
  • Loading branch information
marchc1 committed Dec 27, 2024
1 parent 07804a5 commit 32b2caa
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
1 change: 1 addition & 0 deletions lua/ponder/classes_cl/playback.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,6 @@ function Ponder.Playback:SeekChapter(chapterIndex)
self:SetChapter(chapterIndex)
local seekChapter = self.Storyboard.Chapters[chapterIndex]
self.Time = seekChapter.StartTime

self.Seeking = false
end
88 changes: 87 additions & 1 deletion lua/vgui/ponder_controls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,79 @@ end

derma.DefineControl("Ponder.Progress", "Ponder progress bar", PROGRESSPANEL, "DProgress")

local SPEEDPANEL = {}

function SPEEDPANEL:Init()
self.Buttons = {}

self:AddSpeed("0.25", .25)
self:AddSpeed("0.5", .5)
self:AddSpeed("0.75", .75)
self:AddSpeed("1", 1)
self:AddSpeed("1.25", 1.25)
self:AddSpeed("1.5", 1.5)
self:AddSpeed("1.75", 1.75)
self:AddSpeed("2", 2)
self:AddSpeed("4", 4)

self:SetSize(96, 26 * #self.Buttons)
end

function SPEEDPANEL:Paint() end

function SPEEDPANEL:AddSpeed(speedText, speedMult)
local b = self:Add("DButton")
b:SetText(speedText .. "x")
b:SetSize(128, 20)
b:DockMargin(2, 2, 2, 2)
b:Dock(TOP)

b.SpeedMod = speedMult

local spInst = self
function b:DoClick()
spInst.UI.Playback.Speed = speedMult
for _, v in ipairs(spInst.Buttons) do
v.Active = false
end
self.Active = true
end
function b:Paint(w, h)
local skin = self:GetSkin()

if self.Depressed or self:IsSelected() or self:GetToggle() then
return skin.tex.Button_Down(0, 0, w, h)
end

if self:GetDisabled() then
return skin.tex.Button_Dead(0, 0, w, h)
end

if self.Hovered then
return skin.tex.Button_Hovered(0, 0, w, h)
end

if self.Active then
local s = (math.sin(CurTime() * 7) + 1) / 2
local r, g, b = 190 + (65 * s), 200 + (55 * s), 255
skin.tex.Button(0, 0, w, h, Color(r, g, b))
else
skin.tex.Button(0, 0, w, h)
end
end
self.Buttons[#self.Buttons + 1] = b
end

function SPEEDPANEL:LinkTo(ui)
self.UI = ui
for _, v in ipairs(self.Buttons) do
v.Active = v.SpeedMod == ui.Playback.Speed
end
end

derma.DefineControl("Ponder.SpeedPanel", "Ponder speed panel", SPEEDPANEL, "DPanel")


local TOOLTIP = {}
AccessorFunc(TOOLTIP, "_text", "Text", FORCE_STRING)
AccessorFunc(TOOLTIP, "_font", "Font", FORCE_STRING)
Expand Down Expand Up @@ -243,7 +316,20 @@ function PANEL:Init()
btn:SetImage(self.UI.Playback.Paused and "ponder/ui/icon64/play.png" or "ponder/ui/icon64/stop.png")
end)
local replay = self:AddButton("ponder/ui/icon64/replay.png", "Replay")
local time = self:AddButton("icon16/clock_play.png", "Set Speed")
local time = self:AddButton("ponder/ui/icon64/fast.png", "Set Speed", function(btn)
if IsValid(self.SpeedController) then
self.SpeedController:Remove()
return
end
local speed = self:Add "Ponder.SpeedPanel"
local pX, pY = btn:LocalToScreen(0, 0)
pY = (pY + (btn:GetTall() / 2)) - (speed:GetTall() / 2)
pX, pY = self:ScreenToLocal(pX, pY)
speed:LinkTo(self.UI)
speed:SetPos(pX - speed:GetWide() - 0, pY)

self.SpeedController = speed
end)
-- Shut up linter I'm not ready yet
identify = identify
pauseplay = pauseplay
Expand Down

0 comments on commit 32b2caa

Please sign in to comment.