function CinematicFadeCommonForPlayer takes player p, real red, real green, real blue, real duration, string tex, real startTrans, real endTrans returns nothing
if (duration == 0) then
set startTrans = endTrans
endif
if (GetLocalPlayer() == p) then
call EnableUserUI(false)
call SetCineFilterTexture(tex)
call SetCineFilterBlendMode(BLEND_MODE_BLEND)
call SetCineFilterTexMapFlags(TEXMAP_FLAG_NONE)
call SetCineFilterStartUV(0, 0, 1, 1)
call SetCineFilterEndUV(0, 0, 1, 1)
call SetCineFilterStartColor(PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100-startTrans))
call SetCineFilterEndColor(PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100-endTrans))
call SetCineFilterDuration(duration)
call DisplayCineFilter(true)
endif
endfunction
function FinishCinematicFadeForPlayer takes nothing returns nothing
local integer playerid
local integer index = 0
loop
exitwhen index > 11
if (GetExpiredTimer() == udg_cineFadeFinishTimer[index]) then
set playerid = index
endif
set index = index + 1
endloop
call DestroyTimer(udg_cineFadeFinishTimer[playerid])
set udg_cineFadeFinishTimer[playerid] = null
if (GetPlayerId(GetLocalPlayer()) == playerid) then
call DisplayCineFilter(false)
call EnableUserUI(true)
endif
endfunction
function FinishCinematicFadeAfterForPlayer takes integer playerid, real duration returns nothing
set udg_cineFadeFinishTimer[playerid] = CreateTimer()
call TimerStart(udg_cineFadeFinishTimer[playerid], duration, false, function FinishCinematicFadeForPlayer)
endfunction
function ContinueCinematicFadeForPlayer takes nothing returns nothing
local integer playerid
local integer index = 0
loop
exitwhen index > 11
if (GetExpiredTimer() == udg_cineFadeContinueTimer[index]) then
set playerid = index
endif
set index = index + 1
endloop
call DestroyTimer(udg_cineFadeContinueTimer[playerid])
set udg_cineFadeContinueTimer[playerid] = null
call CinematicFadeCommonForPlayer(Player(playerid), udg_cineFadeContinueRed[playerid], udg_cineFadeContinueGreen[playerid], udg_cineFadeContinueBlue[playerid], udg_cineFadeContinueDuration[playerid], udg_cineFadeContinueTex[playerid], udg_cineFadeContinueTrans[playerid], 100)
endfunction
function ContinueCinematicFadeAfterForPlayer takes integer playerid, real duration, real red, real green, real blue, real trans, string tex returns nothing
set udg_cineFadeContinueRed[playerid] = red
set udg_cineFadeContinueGreen[playerid] = green
set udg_cineFadeContinueBlue[playerid] = blue
set udg_cineFadeContinueTrans[playerid] = trans
set udg_cineFadeContinueDuration[playerid] = duration
set udg_cineFadeContinueTex[playerid] = tex
set udg_cineFadeContinueTimer[playerid] = CreateTimer()
call TimerStart(udg_cineFadeContinueTimer[playerid], duration, false, function ContinueCinematicFadeForPlayer)
endfunction
function AbortCinematicFadeForPlayer takes integer playerid returns nothing
if (udg_cineFadeContinueTimer[playerid] != null) then
call DestroyTimer(udg_cineFadeContinueTimer[playerid])
endif
if (udg_cineFadeFinishTimer[playerid] != null) then
call DestroyTimer(udg_cineFadeFinishTimer[playerid])
endif
endfunction
function CinematicFadeForPlayer takes player p, integer fadetype, real duration, string tex, real red, real green, real blue, real trans returns nothing
local integer playerid = GetPlayerId(p)
if (fadetype == bj_CINEFADETYPE_FADEOUT) then
call AbortCinematicFadeForPlayer(playerid)
call CinematicFadeCommonForPlayer(p, red, green, blue, duration, tex, 100, trans)
elseif (fadetype == bj_CINEFADETYPE_FADEIN) then
call AbortCinematicFadeForPlayer(playerid)
call CinematicFadeCommonForPlayer(p, red, green, blue, duration, tex, trans, 100)
call FinishCinematicFadeAfterForPlayer(playerid, duration)
elseif (fadetype == bj_CINEFADETYPE_FADEOUTIN) then
if (duration > 0) then
call AbortCinematicFadeForPlayer(playerid)
call CinematicFadeCommonForPlayer(p, red, green, blue, duration * 0.5, tex, 100, trans)
call ContinueCinematicFadeAfterForPlayer(playerid, duration * 0.5, red, green, blue, trans, tex)
call FinishCinematicFadeAfterForPlayer(playerid, duration)
endif
endif
endfunction