Skip to content

Commit

Permalink
Implement lookaround
Browse files Browse the repository at this point in the history
  • Loading branch information
NotMyWing committed Jun 12, 2021
1 parent f8dfed5 commit 57a10c3
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/gamemodes/amongus/gamemode/cl_init.moon
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ GM.ClientSideConVars = {
DrawVersion: CreateConVar "au_debug_drawversion" , 0 , flags , "", 0, 1
MaxChatMessages: CreateConVar "au_meeting_max_messages", 100, flags , "", 0, 200
SpectatorMode: CreateConVar "au_spectator_mode" , 0 , flagsUInfo, "", 0, 1
LookAround: CreateConVar "au_vgui_lookaround" , 1 , flags , "", 0, 1
}

hook.Add "InitPostEntity", "NMW AU Flash", ->
Expand Down
1 change: 1 addition & 0 deletions src/gamemodes/amongus/gamemode/lang/au_default.moon
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ with GM.Lang\Get "en"
settingsCvars = {
"au_spectator_mode": "Spectator mode"
"au_debug_drawversion": "Display the current version"
"au_vgui_lookaround": "Enable lookaround in task UIs"
}

for key, value in pairs settingsCvars
Expand Down
1 change: 1 addition & 0 deletions src/gamemodes/amongus/gamemode/lang/au_default_ru.moon
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ with GM.Lang\Get "ru"
settingsCvars = {
"au_spectator_mode": "Режим наблюдателя"
"au_debug_drawversion": "Отображать версию в правом углу"
"au_vgui_lookaround": "Разрешить оглядывание по сторонам в тасках"
}

for key, value in pairs settingsCvars
Expand Down
7 changes: 6 additions & 1 deletion src/gamemodes/amongus/gamemode/vgui/vgui_showhelp.moon
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,12 @@ return vgui.RegisterTable {
separatorWidth, separatorWidth

with \GetCanvas!
cvars = { "au_spectator_mode", "au_debug_drawversion" }
cvars = {
"au_spectator_mode"
"au_debug_drawversion"
"au_vgui_lookaround"
}

for cvar in *cvars
with \Add "DCheckBoxLabel"
\Dock TOP
Expand Down
39 changes: 38 additions & 1 deletion src/gamemodes/amongus/gamemode/vgui/vgui_ui_bases.moon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@ ASSETS = {
close: Material "au/gui/closebutton.png", "smooth"
}

LOOKAROUND_BUF = 0
LOOKAROUND_LASTPOS = Vector!

sign = (x) -> x > 0 and 1 or (x < 0 and -1 or 0)

-- Parabola with points Y=1 in X=-max and X=max, and Y=0 in X=0.
curvify = (x, max) -> math.Clamp (1 / (max * max) * x * x * sign x), -1, 1

hook.Add "CalcView", "GMAU VGUI LookAround", (ply, _, angles) ->
return if LOOKAROUND_BUF <= 0

buf = math.EaseInOut LOOKAROUND_BUF, 0.8, 0
LOOKAROUND_BUF = math.max 0, LOOKAROUND_BUF - FrameTime! * 6

return if not GAMEMODE.ClientSideConVars.LookAround\GetBool!
return if ply ~= LocalPlayer!

if vgui.CursorVisible!
LOOKAROUND_LASTPOS.x, LOOKAROUND_LASTPOS.y = input.GetCursorPos!

scrw05 = ScrW! / 2
scrh05 = ScrH! / 2
max = math.max scrw05, scrh05

angles.yaw += 12.5 * buf * curvify scrw05 - LOOKAROUND_LASTPOS.x, max
angles.pitch += 16 * buf * curvify LOOKAROUND_LASTPOS.y - scrh05, max

return
angles: angles

-----------------------------
-- GENERAL-USE VGUI BASE --
-----------------------------
Expand Down Expand Up @@ -107,8 +137,11 @@ vgui.Register "AmongUsVGUIBase", {
--- Handles mouse clicks 3.
OnCursorExited: => @wasPressed = false

--- Closes the UI when Escape is pressed.
--- Closes the UI when Escape is pressed and resets the lookaround buffer.
Think: =>
if @__isOpened and (@__lookAround or @__lookAround == nil)
LOOKAROUND_BUF = 1

if @__isOpened and gui.IsGameUIVisible!
gui.HideGameUI!
@Close true
Expand All @@ -133,6 +166,10 @@ vgui.Register "AmongUsVGUIBase", {
SetDeleteOnClose: (value) => @__deleteOnClose = value
GetDeleteOnClose: => @__deleteOnClose or false

--- Sets whether the panel should or shouldn't be contributing to the lookaround buffer.
SetLookAroundEnabled: (value) => @__lookAround = value
GetLookAroundEnabled: => if @__lookAround == nil then true else @__lookAround

Paint: =>

}, "Panel"
Expand Down

0 comments on commit 57a10c3

Please sign in to comment.