- Joined
- Nov 7, 2014
- Messages
- 571
LockedCamera - instantly apply a camerasetup to a player and prevent him from moving it
use cases:
use cases:
- FSG - Full Screen GUI =)
- BaD - being a d**k :/
- UU - unforeseen use case
?
JASS:
library LockedCamera initializer locked_camera_init
globals
timer array keep_locking_timers
boolean array keep_locking_timer_is_paused
integer keep_locking_timers_first_hid
camerasetup array locked_cameras
endglobals
function locked_camera_init takes nothing returns nothing
local integer i
set i = 0
loop
exitwhen i >= bj_MAX_PLAYERS
set keep_locking_timers[i] = CreateTimer()
set keep_locking_timer_is_paused[i] = true
set i = i + 1
endloop
set keep_locking_timers_first_hid = GetHandleId(keep_locking_timers[0])
endfunction
function keep_locking_player_view takes nothing returns nothing
local integer pid = GetHandleId(GetExpiredTimer()) - keep_locking_timers_first_hid
if Player(pid) == GetLocalPlayer() then
// instantly change the player's view to the one of the camera
call CameraSetupApplyForceDuration(locked_cameras[pid], true, 0)
// in order to disable the player from fidgeting the camera with the arrow,
// insert/delete and the page up/down keys, we need to enter the "panning mode"
// this mode disables those keys, although the player can "get out" of this mode
// by simple pressing the left mouse key, so that's why we need to keep locking
// the player's view to the camera, and not just once
// we also don't want the camera to move but that's what panning means, so
// that's why we use SIGNED_INT32_MAX = 0x7F_FF_FF_FF = 2147483647
call PanCameraToTimed(0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF)
endif
endfunction
function lock_player_view_to_camera takes player p, camerasetup c returns nothing
local integer pid = GetPlayerId(p)
local boolean is_timer_paused
set locked_cameras[pid] = c
if p == GetLocalPlayer() then
call CameraSetupApplyForceDuration(c, true, 0)
call PanCameraToTimed(0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF)
endif
if keep_locking_timer_is_paused[pid] then
set keep_locking_timer_is_paused[pid] = false
call TimerStart(keep_locking_timers[pid], 0.1, true, function keep_locking_player_view)
endif
endfunction
function unlock_player_view takes player p returns nothing
local integer pid = GetPlayerId(p)
set keep_locking_timer_is_paused[pid] = true
call PauseTimer(keep_locking_timers[pid])
if p == GetLocalPlayer() then
call CameraSetupApplyForceDuration(locked_cameras[pid], true, 0)
endif
endfunction
endlibrary