• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Convert

Status
Not open for further replies.
Level 6
Joined
Aug 1, 2009
Messages
159
Hey, I could just ask if someone can convert this to GUI? (Its vJASS)

JASS:
[HIDDEN="System"]library_once CamSystem initializer Init

    globals
        //How much higher you are.
        private constant real HEIGHT_OFFSET = 400
        //The distance you have to your unit. Negative values also work.
        private constant real DISTANCE = 300
        //The angle on which you look.
        private constant real ANGLE_OF_ATTACK = 330
        //Yeah. Dunno, don't change it.
        private constant real FIELD_OF_VIEW = 100
        //When the angle starts to change when you're walking down cliffs.
        private constant real ANGLE_CHANGE_Z = 200
        //The angle which get's applied when pressed right or left. (Facing+Angle)
        private constant real ANGLE = 30
        //Interval on how often the move timer get's executed.
        private constant real INTERVAL = 0.01
        //How long the camera functions take up to apply.
        private constant real UPDATE_TIME = 0.2
        //Should the current target should be the current selection?
        private constant boolean ON_SELECT = true
        //Disable if you do not want the key movement
        private constant boolean KEY_MOVEMENT = true
        //Default values which will apply when you switch the system off
        private constant real DEFAULT_ZOFFSET = 0
        private constant real DEFAULT_AOA = 304
        private constant real DEFAULT_DISTANCE= 1650
        private constant real DEFAULT_ROTATION= 90
        //Values used for the multiboard.
        private constant integer DEFAULT_RED = 50
        private constant integer DEFAULT_GREEN = 50
        private constant integer DEFAULT_BLUE = 50
        private constant integer SELECTED_RED = 0
        private constant integer SELECTED_GREEN = 100
        private constant integer SELECTED_BLUE = 0
        private constant string ARROW_COLOR = "|cffffffff"
    endglobals

    //This get's automaticly executed at the map initialization.
    //! textmacro CAM_INIT_TRIGGER
        call Cam.create(0)
        call Animation.create('O000', 6)
        call Animation.create('hfoo', 6)
        call Animation.create('hgry', 3)
    //! endtextmacro

    globals
        private location zloc = Location(0,0)
        private sound Error = CreateSoundFromLabel("InterfaceError", false, false, false, 10, 10)
        private multiboard array saved
        private multiboard array currentmb
        private boolean array show
    endglobals

    private function UnitCanMove takes unit u returns boolean
        return not IsUnitType(u, UNIT_TYPE_DEAD) and not IsUnitPaused(u) and not (GetUnitAbilityLevel(u, 'Bens') > 0) and not (GetUnitAbilityLevel(u, 'Bena') > 0) and not (GetUnitAbilityLevel(u, 'Beng') > 0) and not (GetUnitAbilityLevel(u, 'BSTN') > 0) and not (GetUnitAbilityLevel(u, 'BPSE') > 0)
    endfunction

    struct Cam
        integer owner
        unit current
        boolean up
        boolean down
        boolean right
        boolean left
        boolean playanim
        boolean enabled = true

        real offset = HEIGHT_OFFSET
        real distance = DISTANCE
        real aoa = ANGLE_OF_ATTACK
        real angle = 0

        static integer array TimerData
        static integer array TriggerData
        static thistype array Data

        static method create takes integer owner returns thistype
            local thistype this = thistype.allocate()
            local timer t = CreateTimer()
            local timer at = CreateTimer()
            local timer ct = CreateTimer()
            local trigger trg

            set .owner = owner
            set .current = null

            //! textmacro CAM_REGISTER_TRIGGER takes KEY, FUNCTION
            set trg = CreateTrigger()
            call TriggerRegisterPlayerEvent(trg, Player(owner), EVENT_PLAYER_ARROW_$KEY$)
            call TriggerAddAction(trg, function thistype.$FUNCTION$)
            set .TriggerData[GetHandleId(trg)-0x100000] = this
            //! endtextmacro
                //! runtextmacro CAM_REGISTER_TRIGGER("UP_DOWN", "UpButtonPress")
                //! runtextmacro CAM_REGISTER_TRIGGER("UP_UP", "UpButtonRelease")

                //! runtextmacro CAM_REGISTER_TRIGGER("DOWN_DOWN", "DownButtonPress")
                //! runtextmacro CAM_REGISTER_TRIGGER("DOWN_UP", "DownButtonRelease")

                //! runtextmacro CAM_REGISTER_TRIGGER("RIGHT_DOWN", "RightButtonPress")
                //! runtextmacro CAM_REGISTER_TRIGGER("RIGHT_UP", "RightButtonRelease")

                //! runtextmacro CAM_REGISTER_TRIGGER("LEFT_DOWN", "LeftButtonPress")
                //! runtextmacro CAM_REGISTER_TRIGGER("LEFT_UP", "LeftButtonRelease")

            set trg = CreateTrigger()
            call TriggerRegisterPlayerUnitEvent(trg, Player(owner), EVENT_PLAYER_UNIT_SELECTED, null)
            call TriggerAddAction(trg, function thistype.select)
            set .TriggerData[GetHandleId(trg)-0x100000] = this

            set .TimerData[GetHandleId(t)-0x100000] = this
            call TimerStart(t, INTERVAL, true, function thistype.move)

            set .TimerData[GetHandleId(ct)-0x100000] = this
            call TimerStart(ct, INTERVAL, true, function thistype.camera)

            set .TimerData[GetHandleId(at)-0x100000] = this
            call TimerStart(at, 0.2, true, function thistype.animation)

            set .Data[.owner] = this

            return this
        endmethod

        static method switch takes integer owner returns nothing
            local thistype this = Cam.Data[owner]
            if .enabled then
                set .enabled = false
                set .current = null
                if GetLocalPlayer() == Player(owner) then
                    call SetCameraField(CAMERA_FIELD_ZOFFSET, DEFAULT_ZOFFSET, UPDATE_TIME)
                    call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, DEFAULT_DISTANCE, UPDATE_TIME)
                    call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, DEFAULT_AOA, UPDATE_TIME)
                    call SetCameraField(CAMERA_FIELD_ROTATION, DEFAULT_ROTATION, UPDATE_TIME)
                    call SetCameraField(CAMERA_FIELD_FIELD_OF_VIEW, FIELD_OF_VIEW, UPDATE_TIME)
                    call SetCameraField(CAMERA_FIELD_FARZ, bj_CAMERA_DEFAULT_FARZ, UPDATE_TIME)
                endif
            else
                set .enabled = true
            endif
        endmethod

        private static method move takes nothing returns nothing
            local thistype this = Cam.TimerData[GetHandleId(GetExpiredTimer())-0x100000]
            local real x
            local real y
            local real ox
            local real oy
            local boolean bx
            local boolean by
            if show[.owner] and KEY_MOVEMENT then
                if .up and not .down and UnitCanMove(.current) then
                    set .playanim = true
                    set ox = GetUnitX(.current)
                    set oy = GetUnitY(.current)
                    if .right then
                        set x = GetUnitX(.current)+(GetUnitMoveSpeed(.current)*INTERVAL)*Cos((GetUnitFacing(.current)-ANGLE)*bj_DEGTORAD)
                        set y = GetUnitY(.current)+(GetUnitMoveSpeed(.current)*INTERVAL)*Sin((GetUnitFacing(.current)-ANGLE)*bj_DEGTORAD)
                    elseif .left then
                        set x = GetUnitX(.current)+(GetUnitMoveSpeed(.current)*INTERVAL)*Cos((GetUnitFacing(.current)+ANGLE)*bj_DEGTORAD)
                        set y = GetUnitY(.current)+(GetUnitMoveSpeed(.current)*INTERVAL)*Sin((GetUnitFacing(.current)+ANGLE)*bj_DEGTORAD)
                    else
                        set x = GetUnitX(.current)+(GetUnitMoveSpeed(.current)*INTERVAL)*Cos(GetUnitFacing(.current)*bj_DEGTORAD)
                        set y = GetUnitY(.current)+(GetUnitMoveSpeed(.current)*INTERVAL)*Sin(GetUnitFacing(.current)*bj_DEGTORAD)
                    endif
                    call SetUnitPosition(.current, x, y)
                    if RAbsBJ(GetUnitX(.current)-x) > 0.5 or RAbsBJ(GetUnitY(.current)-y) > 0.5 then
                        call SetUnitPosition(.current, x, oy)
                        set bx = RAbsBJ(GetUnitX(.current)-x) <= 0.5
                        call SetUnitPosition(.current, ox, y)
                        set by = RAbsBJ(GetUnitY(.current)-y) <= 0.5
                        if bx then
                            call SetUnitPosition(.current, x, oy)
                        elseif by then
                            call SetUnitPosition(.current, ox, y)
                        else
                            call SetUnitPosition(.current, x, y)
                        endif
                    endif
                elseif .up and .down then
                    if GetLocalPlayer() == Player(.owner) then
                        call StartSound(Error)
                    endif
                    if .playanim then
                        set .playanim = false
                        call SetUnitAnimationByIndex(.current, 1)
                        call IssueImmediateOrder(.current, "stop")
                    endif
                elseif not .up then
                    if .playanim then
                        set .playanim = false
                        call SetUnitAnimationByIndex(.current, 1)
                        call IssueImmediateOrder(.current, "stop")
                    endif
                endif

                if .right and not .left then
                    call SetUnitFacingTimed(.current, GetUnitFacing(.current)-ANGLE, UPDATE_TIME)
                elseif .left and not .right then
                    call SetUnitFacingTimed(.current, GetUnitFacing(.current)+ANGLE, UPDATE_TIME)
                elseif .right and .left then
                    if GetLocalPlayer() == Player(.owner) then
                        call StartSound(Error)
                    endif
                endif
            endif
        endmethod

        private static method animation takes nothing returns nothing
            local thistype this = Cam.TimerData[GetHandleId(GetExpiredTimer())-0x100000]
            if .playanim then
                call SetUnitAnimationByIndex(.current, Animation.getAnim(GetUnitTypeId(.current)))
            endif
        endmethod

        private static method camera takes nothing returns nothing
            local thistype this = Cam.TimerData[GetHandleId(GetExpiredTimer())-0x100000]
            local real z1
            local real z2
            local real angle = .aoa
            local real offset = GetCameraField(CAMERA_FIELD_ZOFFSET)+GetUnitFlyHeight(.current)+.offset-GetCameraEyePositionZ()
            if .current != null then
                call MoveLocation(zloc, GetUnitX(.current), GetUnitY(.current))
                set z1 = GetLocationZ(zloc)
                call MoveLocation(zloc, GetUnitX(.current)+.distance*Cos((GetUnitFacing(.current)-180)*bj_DEGTORAD), GetUnitY(.current)+.distance*Sin((GetUnitFacing(.current)-180)*bj_DEGTORAD))
                set z2 = GetLocationZ(zloc)

                if z1+FIELD_OF_VIEW/2 < z2 then
                    set angle = angle-20
                    set offset = offset+z2
                elseif z1+FIELD_OF_VIEW/2 > z2 then
                    set offset = offset+z1
                else
                    set offset = offset+z1
                endif

                if GetLocalPlayer() == Player(.owner) then
                    call PanCameraToTimed(GetUnitX(.current)+.distance*Cos((GetUnitFacing(.current)-180)*bj_DEGTORAD), GetUnitY(.current)+.distance*Sin((GetUnitFacing(.current)-180)*bj_DEGTORAD), UPDATE_TIME)
                    call SetCameraField(CAMERA_FIELD_ZOFFSET, offset, UPDATE_TIME)
                    call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, .distance, UPDATE_TIME)
                    call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, angle, UPDATE_TIME)
                    call SetCameraField(CAMERA_FIELD_ROTATION, GetUnitFacing(.current)+.angle, UPDATE_TIME)
                    call SetCameraField(CAMERA_FIELD_FIELD_OF_VIEW, FIELD_OF_VIEW, UPDATE_TIME)
                    call SetCameraField(CAMERA_FIELD_FARZ, bj_CAMERA_DEFAULT_FARZ, UPDATE_TIME)
                endif
            endif
        endmethod

        private static method select takes nothing returns nothing
            local thistype this = Cam.TriggerData[GetHandleId(GetTriggeringTrigger())-0x100000]
            if GetOwningPlayer(GetTriggerUnit()) == Player(.owner) and ON_SELECT and .enabled then
                call SetUnitAnimationByIndex(.current, 1)
                set .current = GetTriggerUnit()
            endif
        endmethod

        //! textmacro CAM_CREATE_TRIGGERS takes NAME, VARIABLE
        private static method $NAME$ButtonPress takes nothing returns nothing
            local thistype this = Cam.TriggerData[GetHandleId(GetTriggeringTrigger())-0x100000]
            set .$VARIABLE$ = true
        endmethod
        private static method $NAME$ButtonRelease takes nothing returns nothing
            local thistype this = Cam.TriggerData[GetHandleId(GetTriggeringTrigger())-0x100000]
            set .$VARIABLE$ = false
        endmethod
        //! endtextmacro
            //! runtextmacro CAM_CREATE_TRIGGERS("Up", "up")
            //! runtextmacro CAM_CREATE_TRIGGERS("Down", "down")
            //! runtextmacro CAM_CREATE_TRIGGERS("Right", "right")
            //! runtextmacro CAM_CREATE_TRIGGERS("Left", "left")

    endstruct

    struct Animation
        integer id
        integer anim
        static hashtable hash = InitHashtable()
        static method create takes integer id, integer anim returns thistype
            local thistype this = thistype.allocate()
            set .id = id
            set .anim = anim
            call SaveInteger(.hash, id, 0, this)
            return this
        endmethod
        static method getAnim takes integer id returns integer
            local thistype this = LoadInteger(thistype.hash, id, 0)
            return .anim
        endmethod
    endstruct

    globals
        private integer array prow
    endglobals

    private function MultiboardUp takes nothing returns nothing
        local integer id = GetPlayerId(GetTriggerPlayer())
        if prow[id] >= 3 and not show[id] then
            set prow[id] = prow[id]-1
            call MultiboardSetItemColorBJ(currentmb[id], 0, prow[id]+1, DEFAULT_RED, DEFAULT_GREEN, DEFAULT_BLUE, 100)
            call MultiboardSetItemColorBJ(currentmb[id], 0, prow[id], SELECTED_RED, SELECTED_GREEN, SELECTED_BLUE, 100)

            call MultiboardSetItemValueBJ(currentmb[id], 1, prow[id]+1, "")
            call MultiboardSetItemValueBJ(currentmb[id], 1, prow[id], ARROW_COLOR+">")
        endif
    endfunction

    private function MultiboardDown takes nothing returns nothing
        local integer id = GetPlayerId(GetTriggerPlayer())
        if prow[id] <= 4 and not show[id] then
            set prow[id] = prow[id]+1
            call MultiboardSetItemColorBJ(currentmb[id], 0, prow[id]-1, DEFAULT_RED, DEFAULT_GREEN, DEFAULT_BLUE, 100)
            call MultiboardSetItemColorBJ(currentmb[id], 0, prow[id], SELECTED_RED, SELECTED_GREEN, SELECTED_BLUE, 100)

            call MultiboardSetItemValueBJ(currentmb[id], 1, prow[id]-1, "")
            call MultiboardSetItemValueBJ(currentmb[id], 1, prow[id], ARROW_COLOR+">")
        endif
    endfunction

    private function MultiboardRight takes nothing returns nothing
        local integer id = GetPlayerId(GetTriggerPlayer())
        if not show[id] then
            if prow[id] == 2 and Cam.Data[id].aoa <= 350 then
                set Cam.Data[id].aoa = Cam.Data[id].aoa+10
                call MultiboardSetItemValueBJ(currentmb[id], 3, 2, I2S(R2I(Cam.Data[id].aoa)))
            endif
            if prow[id] == 3 then
                set Cam.Data[id].distance = Cam.Data[id].distance+20
                call MultiboardSetItemValueBJ(currentmb[id], 3, 3, I2S(R2I(Cam.Data[id].distance)))
            endif
            if prow[id] == 4 then
                set Cam.Data[id].offset = Cam.Data[id].offset+20
                call MultiboardSetItemValueBJ(currentmb[id], 3, 4, I2S(R2I(Cam.Data[id].offset)))
            endif
            if prow[id] == 5 and Cam.Data[id].angle <= 350 then
                set Cam.Data[id].angle = Cam.Data[id].angle+10
                call MultiboardSetItemValueBJ(currentmb[id], 3, 5, I2S(R2I(Cam.Data[id].angle)))
            endif
        endif
    endfunction

    private function MultiboardLeft takes nothing returns nothing
        local integer id = GetPlayerId(GetTriggerPlayer())
        if not show[id] then
            if prow[id] == 2 and Cam.Data[id].aoa >= 10 then
                set Cam.Data[id].aoa = Cam.Data[id].aoa-10
                call MultiboardSetItemValueBJ(currentmb[id], 3, 2, I2S(R2I(Cam.Data[id].aoa)))
            endif
            if prow[id] == 3 then
                set Cam.Data[id].distance = Cam.Data[id].distance-20
                call MultiboardSetItemValueBJ(currentmb[id], 3, 3, I2S(R2I(Cam.Data[id].distance)))
            endif
            if prow[id] == 4 and Cam.Data[id].offset >= 20 then
                set Cam.Data[id].offset = Cam.Data[id].offset-20
                call MultiboardSetItemValueBJ(currentmb[id], 3, 4, I2S(R2I(Cam.Data[id].offset)))
            endif
            if prow[id] == 5 and Cam.Data[id].angle >= 10 then
                set Cam.Data[id].angle = Cam.Data[id].angle-10
                call MultiboardSetItemValueBJ(currentmb[id], 3, 5, I2S(R2I(Cam.Data[id].angle)))
            endif
        endif
    endfunction

    private function MultiboardSettings takes integer id returns nothing
        if show[id] then
            if bj_lastCreatedMultiboard != null and bj_lastCreatedMultiboard != currentmb[id] then
                set saved[id] = bj_lastCreatedMultiboard
                call MultiboardDisplay(saved[id], false)
            endif

            set currentmb[id] = CreateMultiboard()
            call MultiboardSetTitleText(currentmb[id], "Change your Cam Settings")
            call MultiboardSetColumnCount(currentmb[id], 3)
            call MultiboardSetRowCount(currentmb[id], 5)
            call MultiboardSetItemsStyle(currentmb[id], true, false)

            call MultiboardSetItemWidthBJ(currentmb[id], 1, 0, 1)
            call MultiboardSetItemWidthBJ(currentmb[id], 2, 0, 8)
            call MultiboardSetItemWidthBJ(currentmb[id], 3, 0, 6)

            call MultiboardSetItemValueBJ(currentmb[id], 2, 1, "Setting")
            call MultiboardSetItemValueBJ(currentmb[id], 3, 1, "Value")
            call MultiboardSetItemValueBJ(currentmb[id], 2, 2, "Angle")
            call MultiboardSetItemValueBJ(currentmb[id], 2, 3, "Distance")
            call MultiboardSetItemValueBJ(currentmb[id], 2, 4, "Height")
            call MultiboardSetItemValueBJ(currentmb[id], 2, 5, "Rotation")

            call MultiboardSetItemValueBJ(currentmb[id], 3, 2, I2S(R2I(Cam.Data[id].aoa)))
            call MultiboardSetItemValueBJ(currentmb[id], 3, 3, I2S(R2I(Cam.Data[id].distance)))
            call MultiboardSetItemValueBJ(currentmb[id], 3, 4, I2S(R2I(Cam.Data[id].offset)))
            call MultiboardSetItemValueBJ(currentmb[id], 3, 5, I2S(R2I(Cam.Data[id].angle)))

            call MultiboardSetItemColorBJ(currentmb[id], 0, 2, DEFAULT_RED, DEFAULT_GREEN, DEFAULT_BLUE, 100)
            call MultiboardSetItemColorBJ(currentmb[id], 0, 3, DEFAULT_RED, DEFAULT_GREEN, DEFAULT_BLUE, 100)
            call MultiboardSetItemColorBJ(currentmb[id], 0, 4, DEFAULT_RED, DEFAULT_GREEN, DEFAULT_BLUE, 100)
            call MultiboardSetItemColorBJ(currentmb[id], 0, 5, DEFAULT_RED, DEFAULT_GREEN, DEFAULT_BLUE, 100)

            call MultiboardSetItemValueBJ(currentmb[id], 1, 2, ARROW_COLOR+">")
            call MultiboardSetItemColorBJ(currentmb[id], 0, 2, SELECTED_RED, SELECTED_GREEN, SELECTED_BLUE, 100)

            set prow[id] = 2

            if GetLocalPlayer() == Player(id) then
                call MultiboardDisplay(currentmb[id], true)
call MultiboardMinimize(currentmb[id], false)
            endif
            set show[id] = false
        else
if GetLocalPlayer() == Player(id) then
                call MultiboardDisplay(currentmb[id], false)
                call MultiboardDisplay(saved[id], true)
            endif
set show[id] = true
        endif
    endfunction

function CamRegisterPlayer takes integer owner returns Cam
        return Cam.create(owner)
    endfunction

function CamSwitch takes integer owner returns nothing
        call Cam.switch(owner)
    endfunction

    function CamSetTarget takes integer owner, unit target returns nothing
        set Cam.Data[owner].current = target
    endfunction

    function CamAddAnimation takes integer id, integer anim returns Animation
        return Animation.create(id, anim)
    endfunction

    function CamToggleMultiboard takes integer owner returns nothing
        call MultiboardSettings(owner)
    endfunction

    private function Init takes nothing returns nothing
        local trigger xZ44 = CreateTrigger()
        local integer z4Q = 0 //DUDE! You never know what names someone is going to use.
        //! runtextmacro CAM_INIT_TRIGGER()
        loop
            exitwhen z4Q >= 11
            set show[z4Q] = true
            set saved[z4Q] = null
            set currentmb[z4Q] = null
            set z4Q = z4Q+1
        endloop
        set z4Q = 0
        loop
            exitwhen z4Q >= 11
            set xZ44 = CreateTrigger()
            call TriggerRegisterPlayerEvent(xZ44, Player(z4Q), EVENT_PLAYER_ARROW_DOWN_DOWN)
            call TriggerAddAction(xZ44, function MultiboardDown)
            set xZ44 = CreateTrigger()
            call TriggerRegisterPlayerEvent(xZ44, Player(z4Q), EVENT_PLAYER_ARROW_UP_DOWN)
            call TriggerAddAction(xZ44, function MultiboardUp)
            set xZ44 = CreateTrigger()
            call TriggerRegisterPlayerEvent(xZ44, Player(z4Q), EVENT_PLAYER_ARROW_RIGHT_DOWN)
            call TriggerAddAction(xZ44, function MultiboardRight)
            set xZ44 = CreateTrigger()
            call TriggerRegisterPlayerEvent(xZ44, Player(z4Q), EVENT_PLAYER_ARROW_LEFT_DOWN)
            call TriggerAddAction(xZ44, function MultiboardLeft)
            set z4Q = z4Q+1
        endloop
    endfunction

endlibrary[/HIDDEN]

Thanks!
 
Status
Not open for further replies.
Top