- Joined
- Jun 21, 2012
- Messages
- 431
JASS:
library UserCamera/*
************************************************************************************
*
* UserCamera (StaticCam)
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* v1.0.0.0
* by Trigger edge
*
* Intuitive API to apply camera for users with some additional features.
*
* API:
* ¯¯¯
* struct Camera extends array
*
* Operators:
* ¯¯¯¯¯¯¯¯¯
* static method operator [] takes player p returns thistype
*
* method operator angleOfAttack takes nothing returns real
* method operator fieldOfView takes nothing returns real
* method operator roll takes nothing returns real
* method operator rotation takes nothing returns real
* method operator targetDistance takes nothing returns real
*
* method operator angleOfAttack= takes real value returns nothing
* method operator fieldOfView= takes real value returns nothing
* method operator roll= takes real value returns nothing
* method operator rotation= takes real value returns nothing
* method operator targetDistance= takes real value returns nothing
*
* method operator locked takes nothing returns boolean
* method operator locked= takes boolean flag returns nothing
*
* Methods:
* ¯¯¯¯¯¯¯
* method setPosition takes real x, real y returns nothing
* method enableTargetController takes unit target, real x, real y returns nothing
* method disableTargetController takes nothing returns nothing
* method withDuration takes real r returns thistype
* method reset takes nothing returns nothing
*
************************************************************************************/
/*
Configuration
*/
globals
/*
Id of dummy unit to be used to lock the minimap
*/
private constant integer DUMMY_LOCKING_ID = 'hpea'
private constant real CHECKER_PERIOD = 0.020//0.03125
endglobals
/*
Endconfiguration
*/
struct Camera extends array
private static player localPlayer=null
private static thistype localPlayerId=0
private static integer size=0
private static unit minipapLockingUnit=null
private static timer coreTimer=CreateTimer()
private static trigger eventLeave=CreateTrigger()
private static unit Target=null
private static real TargetX=0
private static real TargetY=0
private static real duration=0
private static real AngleOfAttack=0
private static real FieldOfView=0
private static real Roll=0
private static real Rotation=0
private static real TargetDistance=0
private static boolean Locked=false
private static boolean EnableTargetController=false
private static method onLoop takes nothing returns nothing
if(Locked)then
call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK,AngleOfAttack,0)
call SetCameraField(CAMERA_FIELD_FIELD_OF_VIEW,FieldOfView,0)
call SetCameraField(CAMERA_FIELD_ROLL,Roll,0)
call SetCameraField(CAMERA_FIELD_ROTATION,Rotation,0)
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE,TargetDistance,0)
if(EnableTargetController)then
if(null!=Target)then
set TargetX=GetUnitX(Target)
set TargetY=GetUnitY(Target)
endif
/*
The following two functions disables mouse wheel, arrows and mini-map
drag, but one not disables mouse wheel and ther other not disables
the mini-map drag, therefore I have combined them...
Credits to Aniki by the PanCamera trick.
*/
call PanCameraToTimed(0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF)
call SetCameraTargetController(minipapLockingUnit,TargetX,TargetY,false)
endif
endif
endmethod
static method operator [] takes player p returns Camera
return GetPlayerId(p)
endmethod
method setPosition takes real x, real y returns nothing
if(localPlayerId==this)then
call PanCameraToTimed(x,y,0)
endif
endmethod
method enableTargetController takes unit target, real x, real y returns nothing
if(localPlayerId==this)then
set Target=target
set TargetX=x
set TargetY=y
set EnableTargetController=true
endif
endmethod
method disableTargetController takes nothing returns nothing
if(localPlayerId==this)then
set EnableTargetController=false
endif
endmethod
method withDuration takes real r returns thistype
if(localPlayerId==this)then
set duration=r
endif
return this
endmethod
method reset takes nothing returns nothing
if(localPlayerId==this)then
call ResetToGameCamera(0)
endif
endmethod
//! textmacro UserCamera_field_method takes METHOD_NAME,VAR_NAME,FIELD_NAME,FIX
method operator $METHOD_NAME$ takes nothing returns real
if(localPlayerId==this)then
return GetCameraField($FIELD_NAME$)$FIX$/0.0174533
else
return 0.
endif
endmethod
method operator $METHOD_NAME$= takes real value returns nothing
if(localPlayerId==this)then
set $VAR_NAME$=value
call SetCameraField($FIELD_NAME$,value,duration)
set duration=0
endif
endmethod
//! endtextmacro
//! runtextmacro UserCamera_field_method("angleOfAttack","AngleOfAttack","CAMERA_FIELD_ANGLE_OF_ATTACK","")
//! runtextmacro UserCamera_field_method("fieldOfView","FieldOfView","CAMERA_FIELD_FIELD_OF_VIEW","")
//! runtextmacro UserCamera_field_method("roll","Roll","CAMERA_FIELD_ROLL","")
//! runtextmacro UserCamera_field_method("rotation","Rotation","CAMERA_FIELD_ROTATION","")
//! runtextmacro UserCamera_field_method("targetDistance","TargetDistance","CAMERA_FIELD_TARGET_DISTANCE","//")
method operator locked takes nothing returns boolean
if(localPlayerId==this)then
return Locked
else
return false
endif
endmethod
method operator locked= takes boolean flag returns nothing
if(localPlayerId==this and PLAYER_SLOT_STATE_PLAYING==GetPlayerSlotState(localPlayer) and MAP_CONTROL_USER==GetPlayerController(localPlayer) and null!=localPlayer)then
if(flag and not Locked)then
set Locked=true
call onLoop()
call TimerStart(coreTimer,CHECKER_PERIOD,true,function thistype.onLoop)
elseif(not flag and Locked)then
set Locked=false
call ResetToGameCamera(0)
set Target=null
set EnableTargetController=false
call PauseTimer(coreTimer)
endif
endif
endmethod
private static method onPlayerLeave takes nothing returns nothing
local thistype this=GetPlayerId(GetTriggerPlayer())
if(.locked)then
set .locked=false
endif
endmethod
private static method onInit takes nothing returns nothing
set localPlayer=GetLocalPlayer()
set localPlayerId=GetPlayerId(localPlayer)
set AngleOfAttack=localPlayerId.angleOfAttack
set FieldOfView=localPlayerId.fieldOfView
set Roll=localPlayerId.roll
set Rotation=localPlayerId.rotation
set TargetDistance=localPlayerId.targetDistance
if(PLAYER_SLOT_STATE_PLAYING==GetPlayerSlotState(localPlayer) and MAP_CONTROL_USER==GetPlayerController(localPlayer))then
call TriggerRegisterPlayerEvent(eventLeave,localPlayer,EVENT_PLAYER_LEAVE)
endif
set minipapLockingUnit=CreateUnit(Player(15),DUMMY_LOCKING_ID,0,0,0)
call UnitAddAbility(minipapLockingUnit,'Aloc')
call UnitRemoveAbility(minipapLockingUnit,'Amov')
call ShowUnit(minipapLockingUnit,false)
call TriggerAddCondition(eventLeave,Filter(function thistype.onPlayerLeave))
endmethod
endstruct
endlibrary
Attachments
Last edited: