scope CameraScrollDistance initializer onInit
globals
// Config
// Default camera distance value
private constant real CAMERA_DISTANCE_DEFAULT = 1650.0
// Time to set the new camera distance value.
private constant real CAMERA_UPDATE_DURATION = 1.0
// Default camera zoom value is set at 120/-120 (see BlzGetTriggerFrameValue() below).
// This multiplier will increase/decrease the amount of camera distance on scroll.
private constant real CAMERA_DISTANCE_MULTIPLIER = 1.0
// Min/Max Camera distance values
private constant real CAMERA_DISTANCE_MIN = 1200.0
private constant real CAMERA_DISTANCE_MAX = 2500.0
// System Variables
private real array CSDPlayerCameraDistance
endglobals
private function Clamp takes real r, real min, real max returns real
if (r < min) then
return min
elseif (r > max) then
return max
endif
return r
endfunction
private function OnMouseWheelScroll takes nothing returns boolean
local integer playerIndex = GetPlayerId(GetTriggerPlayer())
// BlzGetTriggerFrameValue() returns +120.0 on scroll up and -120.0 on scroll down
set CSDPlayerCameraDistance[playerIndex] = Clamp(CSDPlayerCameraDistance[playerIndex] - (BlzGetTriggerFrameValue() * CAMERA_DISTANCE_MULTIPLIER), CAMERA_DISTANCE_MIN, CAMERA_DISTANCE_MAX)
if (GetLocalPlayer() == GetTriggerPlayer()) then
// Use only local code (no net traffic) within this block to avoid desyncs.
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, CSDPlayerCameraDistance[playerIndex], CAMERA_UPDATE_DURATION)
endif
return false
endfunction
private function onInit takes nothing returns nothing
local integer i = 0
local trigger t = CreateTrigger()
local framehandle fh1 = BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0)
local framehandle fh2 = BlzCreateFrameByType("TEXT", "frameScrollArea", fh1, "", 0)
call BlzFrameSetAllPoints(fh2, fh1)
call BlzTriggerRegisterFrameEvent(t, fh2, FRAMEEVENT_MOUSE_WHEEL)
call TriggerAddCondition(t, Filter(function OnMouseWheelScroll))
loop
set CSDPlayerCameraDistance[i] = CAMERA_DISTANCE_DEFAULT
set i = i + 1
exitwhen (i >= bj_MAX_PLAYERS)
endloop
set t = null
set fh1 = null
set fh2 = null
endfunction
endscope