HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

WindowInterface

02-03-2010, 03:21 AM#1
GALLED
Based in the library DGUI it does pretty much the same but works for multiplayer.
(requires vJass) More scripts: htt://www.wc3c.net
(requires jassnewgenpack5b+)

Uses the library Math by Ashujon
http://www.wc3c.net/showthread.php?t=102351
Uses the library Camera by Ashujon
http://www.wc3c.net/showthread.php?t=102351
Uses the library TimerUtils by Vexorian (only tested with Blue Flavor):
http://www.wc3c.net/showthread.php?t=101322

This library consists of three structs (BUTTON, PICTURE and TEXT), the struct BUTTON draws heavily on the PICTURE struct, while the struct TEXT uses TextTags to show for different players. For BUTTON and PICTURE are required Dummys units that are nearly invisible to any player (at least in the minimap), so that the PICTURE structs are multiplayer only playing with the VertexColor.

I attach a map as an example (not as elaborate as that of Ashujon but only to illustrate how the system works, the coordinates on the screen and the detection of each player, as well as the button).

Collapse JASS:
library WindowInterface initializer Init requires Math, Camera, TimerUtils
//* ===================================================================================================== *
//* by Galled                                                                                             *
//* based in DGUI by Ashujon:  [url]http://www.wc3c.net/showthread.php?t=102351[/url]                                *
//*                                                                                                       *
//* (requires vJass)   More scripts: htt://www.wc3c.net                                                   *
//* (requires jassnewgenpack5b+)                                                                          *
//*                                                                                                       *
//* Uses the library Math by Ashujon							                                          * 
//* [url]http://www.wc3c.net/showthread.php?t=102351[/url]														      *
//* Uses the library Camera by Ashujon							                                          *
//* [url]http://www.wc3c.net/showthread.php?t=102351[/url] 														  * 
//* Uses the library TimerUtils by Vexorian (only tested with Blue Flavor):                               *
//* [url]http://www.wc3c.net/showthread.php?t=101322[/url]                                                           *
//*                                                                                                       *
//* This library consists of three structs (BUTTON, PICTURE and TEXT), the struct BUTTON draws heavily on *
//* the PICTURE struct, while the struct TEXT uses TextTags to show for different players. For BUTTON and *
//* PICTURE are required Dummys units that are nearly invisible to any player (at least in the minimap),  *
//* so that the PICTURE structs are multiplayer only playing with the VertexColor.                        *
//* ===================================================================================================== *
globals
    private constant integer TypeUnit = 'dgui' //Dummy unit masquerading as a button
    private integer TypeSkinChanger = 'A000' //Ability that changes the textures of the units posing as buttons or images 
    private location GL4DGUI = Location(0,0)
    private trigger trigLclick  //Trigger that detects when a player make a left click in a button.
    private trigger trigLclickControl  //Trigger that detects when a player make a left click in a not-button unit.
    private trigger trigRclick  //Trigger that detects when a player make a left click in a button.
    private timer PeriodicControl  //Timer that controls the selected buttons
    private real TimeControl = 0.03 //Interval in wich the timer review if a button has been selected
    private unit array LastSelectedUnit //Save the last unit for every player to prevent the timer PeriodicControl leave the selection of an unit blank.
    private boolean array ClearLastSelected //To lock the save the last unit for every player.
endglobals

//Function that you will use with the actions in the left or right click
function GetTriggerButton takes nothing returns BUTTON
    if ( BUTTON.IsRightClicked() ) then
        return GetUnitUserData(GetOrderTargetUnit())
    elseif ( BUTTON.IsLeftClicked() ) then
        return GetUnitUserData(GetTriggerUnit())
    endif
    return 0
endfunction

//Function extracted from DGUI by Ashujon. Allows you to locate the coordinate Z. Very useful for camera views.
private function GetZ4DGUI takes real X, real Y returns real
    call MoveLocation(GL4DGUI, X, Y)
    return GetLocationZ(GL4DGUI)
endfunction

private function FineIndexAnimModel takes real w, real h, real z returns integer
    local real W = w*WidthScreen*z  //WidthScreen variable from Camera library
    local real H = h*HeightScreen*z //HeightScreen variable from Camera library 
    local real anim
    if (H<W) then
        set anim = 10*(W/H-1)
        return R2I_n(anim)
    else
        set anim = 10*(H/W-1)
        if anim >= 0.5 then
            return 100+R2I_n(anim)
        endif
    endif
    return 0
endfunction

private function FineSizeModel takes real w, real h, real z returns real
    local real W = w*WidthScreen*z  //WidthScreen variable from Camera library
    local real H = h*HeightScreen*z //HeightScreen variable from Camera library 
    if (H<W) then
        return 0.5*H
    else
        return 0.5*W
    endif
endfunction

struct BUTTON
    static BUTTON array AllShow
    static integer CountShow = 0
    private integer index
    private CAMERA Camera
    
    private real centerx
    private real centery
    private real minx
    private real maxx
    private real miny
    private real maxy
    private real width
    private real height
    private real z
    unit picture
    private integer indexanim
    private effect model
    boolean show
    integer CostumValue
 
    static method New takes real minx, real maxy, real W, real H, real z, integer texture returns BUTTON
    local BUTTON this = BUTTON.create()
    local destructable tree    
        set .CostumValue = 0
        set .Camera = 0
        set .width = W
        set .height = H
        set .minx = minx
        set .maxx = minx+W
        set .maxy = maxy
        set .miny = maxy-H
        set .z = 100.2+z
        set .centerx = minx+W/2.0
        set .centery = maxy-H/2.0
        set .show = false
        set .picture = CreateUnit(Player(15), TypeUnit, 0, 0, 0)
        call UnitAddAbility(.picture, TypeSkinChanger)
        if (texture != 0) then
            set tree = CreateDestructable(texture,0,0,0,0,1)
            call IssueTargetOrder(.picture, "grabtree", tree)
            call RemoveDestructable(tree)
            set tree = null
        endif
        set .indexanim = FineIndexAnimModel(W, H, .z)
        call SetUnitAnimationByIndex(.picture, .indexanim)
        call SetUnitScale(.picture, FineSizeModel(W, H, .z), 0, 0)
        call UnitAddAbility(.picture, 'Aave')
        call UnitRemoveAbility(.picture, 'Aave')
        call ShowUnit(.picture, false)
        call SetUnitUserData(.picture, this)
        return this
    endmethod
    
    static method LockLastSelectedUnitForPlayer takes player p, boolean lock returns nothing
        set ClearLastSelected[GetPlayerId(p)] = lock
    endmethod
    
    static method ClearLastSelectedUnitForPlayer takes player p returns nothing
        call .LockLastSelectedUnitForPlayer(p,true)
        set LastSelectedUnit[GetPlayerId(p)] = null
    endmethod
    
    static method GetLastSelectedUnitForPlayer takes player p returns unit
        return LastSelectedUnit[GetPlayerId(p)]
    endmethod
    
    static method SaveLastSelectedUnitForPlayer takes unit u, player p returns nothing
        if( LastSelectedUnit[GetPlayerId(p)] != u) then    
            set LastSelectedUnit[GetPlayerId(p)] = u
        endif
    endmethod
        
    static method SaveLastSelectedUnit takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local unit u = GetTriggerUnit()
        if ( ClearLastSelected[GetPlayerId(p)] == false) then
            if( LastSelectedUnit[GetPlayerId(p)] != u) then
                set LastSelectedUnit[GetPlayerId(p)] = u
            endif
        endif
    set u = null
    set p = null
    endmethod

    static method AddActionL takes code func returns triggeraction
        return TriggerAddAction(trigLclick, func)
    endmethod
    
    static method RemoveActionL takes triggeraction action returns nothing
        call TriggerRemoveAction(trigLclick, action)
    endmethod
    
    static method AddActionR takes code func returns triggeraction
        return TriggerAddAction(trigRclick, func)
    endmethod
    
    static method RemoveActionR takes triggeraction action returns nothing
        call TriggerRemoveAction(trigRclick, action)
    endmethod
    
    method Delete takes nothing returns nothing
        call RemoveUnit(.picture)
        if .show then
            set .AllShow[.index] = .AllShow[.CountShow]
            set .AllShow[.index].index = .index
            set .CountShow = .CountShow - 1
        endif
    endmethod
    
    //Method that updates the position of the buttons so that they appear properly on screen.
    method Update takes nothing returns nothing
        local VECTOR3 Pos = .Camera.Win2World(.centerx, .centery, .z)
        call SetUnitX(.picture, Pos.x)
        call SetUnitY(.picture, Pos.y)
        call MoveLocation(GL4DGUI, Pos.x, Pos.y)
        call SetUnitFlyHeight(.picture, Pos.z-GetLocationZ(GL4DGUI), 0)
        call Pos.destroy()
    endmethod
    
    method Show takes boolean show, CAMERA Cam returns nothing
        if Cam != -1 then
            set .Camera = Cam
        endif
        call ShowUnit(.picture, show)
        if show != .show then
            if show then
                set .AllShow[.CountShow] = this
                set .index = .CountShow
                set .CountShow = .CountShow + 1
                call .Update()
                call SetUnitAnimationByIndex(.picture, .indexanim)
            else
                set .CountShow = .CountShow - 1
                set .AllShow[.index] = .AllShow[.CountShow]
                set .AllShow[.index].index = .index
            endif
        endif
        set .show = show
    endmethod
    
    static method IsLeftClicked takes nothing returns boolean
    local unit isLeftButton = GetTriggerUnit()
    local boolean isLeft = false
    
        if(isLeftButton!=null)then
            set isLeft = GetUnitAbilityLevel(isLeftButton, TypeSkinChanger)>0 //Selected unit
            set isLeftButton = null
        endif

        return isLeft
    endmethod
    
    static method IsRightClicked takes nothing returns boolean
    local unit isRightButton = GetOrderTargetUnit()
    local boolean isRight = false
    
        if(isRightButton!=null)then
            set isRight = (GetUnitAbilityLevel(isRightButton, TypeSkinChanger)>0) //Target order with "smart" order
        endif

        if(isRight)then
            call PauseUnit(GetTriggerUnit(), true)
            call IssueImmediateOrder(GetTriggerUnit(), "stop")
            call PauseUnit(GetTriggerUnit(), false)
        endif
        
        set isRightButton = null
        
        return isRight
    endmethod
    
    static method IsClicked takes nothing returns boolean
    local boolean isRight = .IsRightClicked()
    local boolean isLeft = false
    
        if isRight==false then
            set isLeft = .IsLeftClicked()
        endif
        
        return isLeft or isRight
    endmethod
        
    method SetPosition takes real minx, real maxy returns nothing
        set .minx = minx
        set .maxx = minx+.width
        set .maxy = maxy
        set .miny = maxy-.height
        set .centerx = minx+.width/2.0
        set .centery = maxy-.height/2.0
        if .show then
            call .Update()
        endif
    endmethod
    
    method SetTexture takes integer texture returns nothing
    local destructable tree = CreateDestructable(texture,0,0,0,0,1)
        call ShowUnit(.picture, true)
        call SetUnitX(.picture, 0)
        call SetUnitY(.picture, 0)
        call IssueTargetOrder(.picture,"grabtree",tree)
        call ShowUnit(.picture, .show)
        call RemoveDestructable(tree)
        if .show then
            call .Update()
        endif
        set tree = null
    endmethod
    
    static method AllUpdate takes nothing returns nothing
        local integer i = .CountShow
        loop
            exitwhen i < 0
            call .AllShow[i].Update()
            set i = i - 1
        endloop
    endmethod
        
    static method ClickPeriodicSelect takes player p returns unit
        local integer i = .CountShow
        loop
            exitwhen i < 0
            if IsUnitSelected(.AllShow[i].picture, p) then
                return .AllShow[i].picture
            endif
            set i = i - 1
        endloop
        return null
    endmethod

endstruct

struct PICTURE
    private static PICTURE array AllShow
    private static integer CountShow = 0
    private integer index
    private CAMERA Camera
    
    private real centerx
    private real centery
    private real width
    private real height
    private real z
    unit picture
    private integer indexanim
    boolean array show2Player[12]
    integer CostumValue
    
    static method New takes real minx, real maxy, real W, real H, real z, integer texture returns PICTURE
        local PICTURE this = PICTURE.create()
        local destructable tree
        local integer i = 0
        loop
            set .show2Player[i]=false
            set i = i + 1
            exitwhen i>=bj_MAX_PLAYERS
        endloop
        set .CostumValue = 0
        set .Camera = 0
        set .width = W
        set .height = H
        set .centerx = minx+W/2.0
        set .centery = maxy-H/2.0
        set .z = 100.2+z
        set .picture = CreateUnit(Player(15), TypeUnit, 0, 0, 0)
        call SetUnitVertexColor(.picture,255,255,255,0)
        call UnitAddAbility(.picture, TypeSkinChanger)
        if (texture != 0) then
            set tree = CreateDestructable(texture,0,0,0,0,1)
            call IssueTargetOrder(.picture, "grabtree", tree)
            call RemoveDestructable(tree)
            set tree = null
        endif
        set .indexanim = FineIndexAnimModel(W, H, .z)
        call SetUnitAnimationByIndex(.picture, .indexanim)
        call SetUnitScale(.picture, FineSizeModel(W, H, .z), 0, 0)
        call UnitAddAbility(.picture, 'Aave')
        call UnitRemoveAbility(.picture, 'Aave')
        call UnitAddAbility(.picture, 'Aloc')
        call UnitRemoveAbility(.picture, 'Aloc')
        return this
    endmethod
    
    static method NewCostumModel takes real minx, real maxy, real z, real size, integer typeunit, real WidthModel, real HeightModel, integer texture returns PICTURE
        local PICTURE this = PICTURE.create()
        local destructable tree    
        local integer i = 0
        loop
            set .show2Player[i]=false
            set i = i + 1
            exitwhen i>=bj_MAX_PLAYERS
        endloop
        set .CostumValue = 0
        set .Camera = 0
        set .z = 100.2+z
        set .width = (WidthModel*size)/(WidthScreen*.z)
        set .height = (HeightModel*size)/(HeightScreen*.z)
        set .centerx = minx+.width/2.0
        set .centery = maxy-.height/2.0
        set .picture = CreateUnit(Player(15), typeunit, 0, 0, 0)
        call SetUnitVertexColor(.picture,255,255,255,0)
        call UnitAddAbility(.picture, TypeSkinChanger)
        if (texture != 0) then
            set tree = CreateDestructable(texture,0,0,0,0,1)
            call IssueTargetOrder(.picture, "grabtree", tree)
            call RemoveDestructable(tree)
            set tree = null
        endif
        call SetUnitScale(.picture, size, 0, 0)
        call UnitAddAbility(.picture, 'Aave')
        call UnitRemoveAbility(.picture, 'Aave')
        call UnitAddAbility(.picture, 'Aloc')
        call UnitRemoveAbility(.picture, 'Aloc')
        return this
    endmethod
        
    private method IsShowedToAnybody takes nothing returns boolean
    local integer i = 0
    local boolean b = false
        loop
            set b = b or .show2Player[i]
            set i = i + 1
            exitwhen i>=bj_MAX_PLAYERS
        endloop
        
        return b
    endmethod
    
    method Delete takes nothing returns nothing
        call RemoveUnit(.picture)
        if .IsShowedToAnybody() then
            set .AllShow[.index] = .AllShow[.CountShow]
            set .AllShow[.index].index = .index
            set .CountShow = .CountShow - 1
        endif
    endmethod
    
    method Update takes nothing returns nothing
        local VECTOR3 Pos = .Camera.Win2World(.centerx, .centery, .z)
        call SetUnitX(.picture, Pos.x)
        call SetUnitY(.picture, Pos.y)
        call MoveLocation(GL4DGUI, Pos.x, Pos.y)
        call SetUnitFlyHeight(.picture, Pos.z-GetLocationZ(GL4DGUI), 0)
        call Pos.destroy()
    endmethod
    
    method ShowAll takes boolean show, CAMERA Cam, boolean showUnit returns nothing
    local integer i = 0
    
        if(showUnit)then
            call ShowUnit(.picture, show)
        endif
        loop
            call .ShowToPlayer(show,Cam,Player(i))
            set i = i + 1
            exitwhen i>=bj_MAX_PLAYERS
        endloop
    endmethod
    
    method ShowToPlayer takes boolean show, CAMERA Cam, player p returns nothing
        if Cam != -1 then
            set .Camera = Cam
        endif
        if (show != .show2Player[GetPlayerId(p)]) then
            if show then
                set .AllShow[.CountShow] = this
                set .index = .CountShow
                set .CountShow = .CountShow + 1
                call .Update()
                if(GetLocalPlayer()==p)then
                    call SetUnitVertexColor(.picture,255,255,255,255)
                endif
            else
                if(GetLocalPlayer()==p)then
                    call SetUnitVertexColor(.picture,255,255,255,0)
                endif
                set .CountShow = .CountShow - 1
                set .AllShow[.index] = .AllShow[.CountShow]
                set .AllShow[.index].index = .index
            endif
        endif
        set .show2Player[GetPlayerId(p)] = show

    endmethod
    
    method SetPosition takes real minx, real maxy returns nothing
        set .centerx = minx+.width/2.0
        set .centery = maxy-.height/2.0
        if .IsShowedToAnybody() then
            call .Update()
        endif
    endmethod
    
    method SetTexture takes integer texture returns nothing
    local destructable tree = CreateDestructable(texture,0,0,0,0,1)
    local integer i = 0
    local boolean b = false
    
        call ShowUnit(.picture, true)
        call SetUnitX(.picture, 0)
        call SetUnitY(.picture, 0)
        call IssueTargetOrder(.picture,"grabtree",tree)
        call RemoveDestructable(tree)
        loop
            set b = b or .show2Player[i]
            set i = i + 1
            exitwhen i>=bj_MAX_PLAYERS
        endloop            
        if b then
            call .Update()
        endif
        set tree = null
    endmethod
    
    static method AllUpdate takes nothing returns nothing
        local integer i = .CountShow
        loop
            exitwhen i < 0
            call .AllShow[i].Update()
            set i = i - 1
        endloop
    endmethod

endstruct //PICTURE

struct TEXT
    private static TEXT array AllShow
    private static integer CountShow = 0
    private integer index
    private CAMERA Camera
    
    private real minx
    private real maxy
    private real z
    texttag textInScreen
    string textString
    boolean array show2Player[12]
    integer CostumValue
    
    static method New takes real minx, real maxy, real z returns TEXT
        local TEXT this = TEXT.create()
        local integer i = 0
        loop
            set .show2Player[i]=false
            set i = i + 1
            exitwhen i>=bj_MAX_PLAYERS
        endloop
        set .CostumValue = 0
        set .Camera = 0
        set .minx = minx
        set .maxy = maxy
        set .z = 100+z
        set .textInScreen = null
        set .textString = ""
        return this
    endmethod
    
    method SetText takes string text returns nothing
        set .textString = text
    endmethod
    
    private method IsShowedToAnybody takes nothing returns boolean
    local integer i = 0
    local boolean b = false
        loop
            set b = b or .show2Player[i]
            set i = i + 1
            exitwhen i>=bj_MAX_PLAYERS
        endloop
        
        return b
    endmethod
    
    method Delete takes nothing returns nothing
        if(.textInScreen!=null)then
            call DestroyTextTag(.textInScreen)
        endif
        if .IsShowedToAnybody() then
            set .AllShow[.index] = .AllShow[.CountShow]
            set .AllShow[.index].index = .index
            set .CountShow = .CountShow - 1
        endif
    endmethod
    
    method Update takes nothing returns nothing
        local VECTOR3 Pos = .Camera.Win2World(.minx, .maxy, .z)
        if(.textInScreen != null)then
            call SetTextTagPos(.textInScreen, Pos.x, Pos.y, Pos.z-GetZ4DGUI(Pos.x,Pos.y))
        endif
        call Pos.destroy()
    endmethod
    
    method SetPosition takes real minx, real maxy returns nothing
        set .minx = minx
        set .maxy = maxy
        if .IsShowedToAnybody() then
            call .Update()
        endif
    endmethod
    
    method ShowAll takes boolean show, CAMERA Cam returns nothing
    local integer i = 0
        loop
            call .ShowToPlayer(show,Cam,Player(i))
            set i = i + 1
            exitwhen i>=bj_MAX_PLAYERS
        endloop
    endmethod
    
    method ShowToPlayer takes boolean show, CAMERA Cam, player p returns nothing
    local boolean state = .show2Player[GetPlayerId(p)] != show
        set .show2Player[GetPlayerId(p)] = show
        
        if show then
            if(.textInScreen!=null)then
                call DestroyTextTag(.textInScreen)
                set .textInScreen = null
            endif
            set .textInScreen = CreateTextTag()
            call SetTextTagText(.textInScreen, .textString, 8 * 0.0023)
            call SetTextTagVisibility(.textInScreen, false)
            call .Update()        
            if (GetLocalPlayer()==p) then
                call SetTextTagVisibility(.textInScreen, true)
            endif
        else            
            if (.IsShowedToAnybody()==false) then
                call DestroyTextTag(.textInScreen)
                set .textInScreen = null
            endif
        endif
        if Cam != -1 then
            set .Camera = Cam
        endif
        if (state) then
            if show then
                set .AllShow[.CountShow] = this
                set .index = .CountShow
                set .CountShow = .CountShow + 1
                call .Update()
                if (GetLocalPlayer()==p) then
                    call SetTextTagVisibility(.textInScreen, true)
                endif
            else
                if (GetLocalPlayer()==p) then
                    if(.textInScreen!=null)then
                        call SetTextTagVisibility(.textInScreen, false)
                    endif
                endif
                set .CountShow = .CountShow - 1
                set .AllShow[.index] = .AllShow[.CountShow]
                set .AllShow[.index].index = .index
            endif
        endif
        
    endmethod
    
    static method AllUpdate takes nothing returns nothing
        local integer i = .CountShow
        loop
            exitwhen i < 0
            call .AllShow[i].Update()
            set i = i - 1
        endloop
    endmethod

endstruct

private function PeriodicClearSelect takes nothing returns nothing
local integer i = 0
local unit check = null

    loop
        set check = BUTTON.ClickPeriodicSelect(Player(i))
        if check != null then
            if (LastSelectedUnit[i] != null) then
                if(IsUnitSelected(LastSelectedUnit[i],Player(i))==false)then
                    if (GetLocalPlayer() == Player(i)) then
                        call ClearSelection()
                        call SelectUnit(LastSelectedUnit[i], true)
                    endif
                endif
            else
                if (GetLocalPlayer()==Player(i)) then
                    call ClearSelection()
                endif
            endif
            set check = null
        endif
        set i = i + 1
        exitwhen i>=bj_MAX_PLAYERS
    endloop
    
set check = null
endfunction

public function Update takes boolean but, boolean pic, boolean tex returns nothing
    if but then
        call BUTTON.AllUpdate()
    endif
    if pic then
        call PICTURE.AllUpdate()
    endif
    if tex then
        call TEXT.AllUpdate()
    endif
endfunction

private function Init takes nothing returns nothing
local integer i = 0

    set trigLclick = CreateTrigger()
    set trigLclickControl = CreateTrigger()
    set trigRclick = CreateTrigger()
    set PeriodicControl = NewTimer()
    call TimerStart(PeriodicControl, TimeControl, true, function PeriodicClearSelect)
    loop
        call TriggerRegisterPlayerUnitEvent(trigLclick, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
        call TriggerRegisterPlayerUnitEvent(trigLclickControl, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
        call TriggerRegisterPlayerUnitEvent(trigRclick, Player(i), EVENT_PLAYER_UNIT_ISSUED_UNIT_ORDER, null)
        set ClearLastSelected[i] = false
        set LastSelectedUnit[i] = null
        set i = i + 1
        exitwhen i>=bj_MAX_PLAYER_SLOTS
    endloop
    call TriggerAddAction(trigLclickControl, function BUTTON.SaveLastSelectedUnit)
    call TriggerAddCondition(trigLclickControl, Not(Condition( function BUTTON.IsClicked)))
    
    call TriggerAddCondition(trigLclick,Condition( function BUTTON.IsClicked))
    call TriggerAddCondition(trigRclick,Condition( function BUTTON.IsClicked))
endfunction

endlibrary

There are the test in the map:
Collapse JASS:
scope Test

globals

    constant real WidthSlot = 0.08              //                                             		 |
    constant real HeightSlot = 0.08*AspectRatio //AspectRatio is a variable from Camera library 
    integer TypeTextureBlank = 'dbnk'
    private code FuncLClickSlot = null
    private code FuncRClickSlot = null
    PICTURE array pict
    TEXT array text    
endglobals

private function RaceToInt takes race raza returns integer
    if raza == RACE_HUMAN then
        return 0
    elseif raza == RACE_ORC then 
        return 1
    elseif raza == RACE_UNDEAD then
        return 2
    elseif raza == RACE_NIGHTELF then
        return 3
    endif

    return 0
endfunction

private function WhenLeftClick takes nothing returns nothing
local BUTTON but = GetTriggerButton()
local player p = GetTriggerPlayer()

    debug call BJDebugMsg("Player "+GetPlayerName(p)+" is left clicked in the button with the value: "+I2S(but.CostumValue))
    
    call pict[GetPlayerId(p)].ShowToPlayer(true, GameCamera, p)
    call text[GetPlayerId(p)].SetText("Player "+GetPlayerName(p)+" is left clicked in the button with the value: "+I2S(but.CostumValue))
    call text[GetPlayerId(p)].ShowToPlayer(true, GameCamera, p)
    
set p = null
endfunction

private function WhenRightClick takes nothing returns nothing
local BUTTON but = GetTriggerButton()
local player p = GetTriggerPlayer()
    
    debug call BJDebugMsg("Player "+GetPlayerName(p)+" is right clicked in the button with the value: "+I2S(but.CostumValue))
        
    call pict[GetPlayerId(p)].ShowToPlayer(false, GameCamera, p)
    call text[GetPlayerId(p)].ShowToPlayer(false, GameCamera, p)
    
set p = null
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
//Create three buttons
local BUTTON test1 = BUTTON.New(0, 0, WidthSlot, HeightSlot, 0.5, TypeTextureBlank)
local BUTTON test2 = BUTTON.New(0, 0, WidthSlot, HeightSlot, 0.5, TypeTextureBlank)
local BUTTON test3 = BUTTON.New(0, 0, WidthSlot, HeightSlot, 0.5, TypeTextureBlank)
local integer i = 0
local unit u 
    
    //Create the camera. That is very important!!! 
    set GameCamera = CAMERA.New()
    
    //... , one in the center of the screen
    set test1.CostumValue = 11
    call test1.SetPosition(0,0) //Coordenates in the screen, not in the map.
    call test1.Show(true, GameCamera)
    
    //... , one on the top right
    set test2.CostumValue = 22
    call test2.SetPosition(0.8,0.8) //Coordenates in the screen, not in the map.
    call test2.Show(true, GameCamera)    
    
    //... and the last one on the bottom left
    set test3.CostumValue = 33
    call test3.SetPosition(-0.8,-0.8) //Coordenates in the screen, not in the map.
    call test3.Show(true, GameCamera)
    
    set u = CreateUnit(Player(0), 'Hpal', 0,0, 180)
    call SelectUnitForPlayerSingle(u,Player(0))
    set u = CreateUnit(Player(1), 'Obla', 0,0, 180)
    call SelectUnitForPlayerSingle(u,Player(1))
    
    loop
        //Create a picture and text to each player
        //PICTURE method NewCostumModel takes real minx, real maxy, real z, real size, integer typeunit, real WidthModel, real HeightModel, integer texture                                 
        set pict[i] = PICTURE.NewCostumModel(-0.99, 0.95, 1, 0.26, 'dwin', 140.002, 122.646, 'D201'+RaceToInt(GetPlayerRace(Player(i))))
        //TEXT method New takes real minx, real maxy, real z returns TEXT
        set text[i] = TEXT.New(-0.9, 0.76, 1)
        set i = i + 1
        exitwhen i>=bj_MAX_PLAYER_SLOTS
    endloop    
    
    set FuncLClickSlot = function WhenLeftClick
    set FuncRClickSlot = function WhenRightClick
    
    call BUTTON.AddActionL(FuncLClickSlot)
    call BUTTON.AddActionR(FuncRClickSlot)
    
    
endfunction
endscope
Attached Images
File type: pngWC3ScrnShot_030910_205059_01.png (1.4 MB)
Attached Files
File type: w3xWindow Interface.w3x (70.9 KB)
02-03-2010, 08:24 AM#2
Anachron
Did you test this in multiplayer?
02-03-2010, 02:21 PM#3
Tot
Is it possible to use this and "normal" ingame view?
02-03-2010, 02:56 PM#4
GALLED
Quote:
Originally Posted by Anachron
Did you test this in multiplayer?
Yep. It's works :D

Quote:
Originally Posted by Tot
Is it possible to use this and "normal" ingame view?
No, as far as I tested, only be used with the Camera of Ashujon. This is what happens by using units posing as images. I guess I should get a little more complex calculation for the units are seen in perspective with the normal view.
02-03-2010, 02:57 PM#5
Anachron
Quote:
No, as far as I tested, only be used with the Camera of Ashujon. This is what happens by using units posing as images. I guess I should get a little more complex calculation for the units are seen in perspective with the normal view.
So that's the negative side.

Isn't it damn laggy in multiplayer in larger maps?
I mean you move units...
02-03-2010, 03:30 PM#6
GALLED
Quote:
Originally Posted by Anachron
So that's the negative side.

Isn't it damn laggy in multiplayer in larger maps?
I mean you move units...

Yes, that's the downside. In fact, if I guess if you have many units on a large map may slow your game, although I have not test in large maps. After all now depends on how you use the system.
02-04-2010, 11:47 AM#7
Tot
Quote:
Originally Posted by GALLED
No, as far as I tested, only be used with the Camera of Ashujon. This is what happens by using units posing as images. I guess I should get a little more complex calculation for the units are seen in perspective with the normal view.

maybe by using images/oversplats instead of units and some adjusted calculation it might be possible without locking the camera...(just thinking out loud)
02-04-2010, 01:31 PM#8
GALLED
Quote:
Originally Posted by Tot
maybe by using images/oversplats instead of units and some adjusted calculation it might be possible without locking the camera...(just thinking out loud)
Yes, but the bad part of use images are they are flat. You couldn´t use them in conjunction with the Ashujon´s camera.

Only a couple of things I forgot: This interface is for my Hero Selection System, so that only the PICTURE and TEXT can be seen in different locations for each player. The BUTTONs, are displayed for all players in the same position.
02-05-2010, 05:56 PM#9
Tot
started to do something similiar, only with images (atm) and an more flexible camera
03-02-2010, 03:21 PM#10
Rising_Dusk
Can you post a screenshot in the first post? It's a submission requirement.
03-10-2010, 12:55 AM#11
GALLED
Ok. I've added an image.
03-21-2010, 03:43 PM#12
mattstheman
How do I create more than 1 window per player?
04-06-2010, 03:14 PM#13
Slaydon
Would you or someone else make the math for all kinds of cameras, the camera is simply ruining abit, awesome that you get the values tho, +rep
04-16-2010, 03:42 PM#14
Rising_Dusk
You need to link to all required libraries in the first post, not just in the comments of the script.
04-17-2010, 08:41 AM#15
Slaydon
Why arent i aviable to set the Buttons location to the GameCameras location but only in the center? i managed to get the camera to work but i cant get the buttons to move

EDIT: I managed to merge DGUI cam with this, but when i import it to another map i cant press the buttons and get the actions, I had to seperate StartGame and "Test" (SpellCast on my map)

Collapse JASS:
scope SpellCast initializer SpellCast

globals
    BUTTON array DGUIBUTTONS
    integer array TEXTUREUSING
    boolean array ISSLOTEMPTY
    constant real WidthSlot = 0.10              //                                             		 |
    constant real HeightSlot = 0.10*AspectRatio //AspectRatio is a variable from Camera library 
    integer TypeTextureBlank = 'dbnk'
    private code FuncLClickSlot = null
    private code FuncRClickSlot = null
    PICTURE array pict
    TEXT array text    
    boolean bdebug = false
    integer BUTTONCOUNT
    unit DGUIUNIT
    TEXT array SPELLCOOLDOWNTEXT
    unit u
endglobals

private function RaceToInt takes race raza returns integer
    if raza == RACE_HUMAN then
        return 0
    elseif raza == RACE_ORC then 
        return 1
    elseif raza == RACE_UNDEAD then
        return 2
    elseif raza == RACE_NIGHTELF then
        return 3
    endif

    return 0
endfunction

private function WhenLeftClick takes nothing returns nothing
local BUTTON but = GetTriggerButton()
local player p = GetTriggerPlayer()
local integer i = 1
local integer ii = 0
local integer iii = 0

    set bdebug = false
    call BJDebugMsg("Player "+GetPlayerName(p)+" is left clicked in the button with the value: "+I2S(but.CostumValue))
    
    call pict[GetPlayerId(p)].ShowToPlayer(true, GameCamera, p)
    call text[GetPlayerId(p)].SetText("Player "+GetPlayerName(p)+" is left clicked in the button with the value: "+I2S(but.CostumValue) + " With the Texture ID: " + I2S(TEXTUREUSING[but.CostumValue]))
    call text[GetPlayerId(p)].ShowToPlayer(true, GameCamera, p)
    
    loop
        exitwhen i > SPELLCOUNT
            if (( TEXTUREUSING[but.CostumValue] == SDESTTYPE[i] )) then
            set iii = i
            if (( COOLDOWNS[iii] > 0 )) then
                call SimError(Player(0), "Spell is not ready yet.")
            endif
            if (( IsCooldownOn[i] == false )) then
                if (( GetUnitState(DGUIUNIT, UNIT_STATE_MANA) < MANACOST[i] )) then
                    call SimError(Player(0), "Not enough mana.")
                endif
            if (( GetUnitState(DGUIUNIT, UNIT_STATE_MANA) >= MANACOST[i] )) then
                call UnitAddAbility(DGUIUNIT, SPELLTYPE[i])
                call SetUnitState(DGUIUNIT, UNIT_STATE_MANA, GetUnitState(DGUIUNIT, UNIT_STATE_MANA) - MANACOST[1])
                
                //
                if (( STARGET[i] == "null" )) then
                    call IssueImmediateOrder(DGUIUNIT, ORDERSTRING[i])
                endif
                //
                
                if (( STARGET[i] == "self" )) then
                    call IssueTargetOrder(DGUIUNIT, ORDERSTRING[i], DGUIUNIT)
                endif
                //
                
                set IsCooldownOn[i] = true
                set COOLDOWNS[i] = SCOOLDOWN[i]
                set ii = i
                call Cooldown()
            endif 
            endif
            endif
        set i = i + 1
    endloop
    call TriggerSleepAction(.25)
    call UnitRemoveAbility(DGUIUNIT, SPELLTYPE[ii])
set p = null
endfunction

private function WhenRightClick takes nothing returns nothing
local BUTTON but = GetTriggerButton()
local player p = GetTriggerPlayer()
    
    call BJDebugMsg("Player "+GetPlayerName(p)+" is right clicked in the button with the value: "+I2S(but.CostumValue))
        
    call pict[GetPlayerId(p)].ShowToPlayer(false, GameCamera, p)
    call text[GetPlayerId(p)].ShowToPlayer(false, GameCamera, p)
    
set p = null
endfunction

//===========================================================================
function SpellCast takes nothing returns nothing
//Create three buttons
local integer i = 0
local integer a = 1
local integer b = 1
local integer ar = 0
local integer ii = 1

set GameCamera = CAMERA.New()
    
    loop
     exitwhen a > 10
            set DGUIBUTTONS[a] = BUTTON.New(0, 0, WidthSlot, HeightSlot, 0.5, TypeTextureBlank)
            set DGUIBUTTONS[a].CostumValue = a
            call DGUIBUTTONS[a].SetPosition(-.60+.10*a, -.805)
            call DGUIBUTTONS[a].Show(true, GameCamera)
            set SPELLCOOLDOWNTEXT[a] = TEXT.New(-.59+.10*a, -.884, 1)
            call SPELLCOOLDOWNTEXT[a].ShowToPlayer(true, GameCamera, Player(0))
     set a = a + 1
    endloop
    
    
    loop
        //Create a picture and text to each player
        //PICTURE method NewCostumModel takes real minx, real maxy, real z, real size, integer typeunit, real WidthModel, real HeightModel, integer texture                                 
        set pict[i] = PICTURE.NewCostumModel(-0.99, 0.95, 1, 0.26, 'dwin', 140.002, 122.646, 'D201'+RaceToInt(GetPlayerRace(Player(i))))
        //TEXT method New takes real minx, real maxy, real z returns TEXT
        set text[i] = TEXT.New(-0.9, 0.70, 1)
        set i = i + 1
        exitwhen i>=bj_MAX_PLAYER_SLOTS
    endloop   
    
    
set u = CreateUnit(Player(0), 'hfoo', 0,0, 180)
call SelectUnitForPlayerSingle(u,Player(0))
set DGUIUNIT = u

    set FuncLClickSlot = function WhenLeftClick
    set FuncRClickSlot = function WhenRightClick
    
    call BUTTON.AddActionL(FuncLClickSlot)
    call BUTTON.AddActionR(FuncRClickSlot)
    

    set TEXTUREUSING[5] = SDESTTYPE[1]
    call DGUIBUTTONS[5].SetTexture(SDESTTYPE[1])
    
    set TEXTUREUSING[2] = SDESTTYPE[2]
    call DGUIBUTTONS[2].SetTexture(SDESTTYPE[2])
    
    set TEXTUREUSING[9] = SDESTTYPE[3]
    call DGUIBUTTONS[9].SetTexture(SDESTTYPE[3])
    
    set TEXTUREUSING[10] = SDESTTYPE[3]
    call DGUIBUTTONS[10].SetTexture(SDESTTYPE[3])
    
    set TEXTUREUSING[8] = SDESTTYPE[3]
    call DGUIBUTTONS[8].SetTexture(SDESTTYPE[3])
    

endfunction
endscope

Collapse JASS:
globals
    constant real GamePeriod = 0.04
    trigger GameTimer = null
    CAMERA GameCamera = NULL
    unit GameUnit = null
    player GamePlayer = null
endglobals


function Approximately takes real v1, real v2, real s returns boolean
    return v2-s < v1 and v1 < v2+s
endfunction

function GameUpdate takes nothing returns nothing
    local real ang = GetUnitFacing(GameUnit)*bj_DEGTORAD
    local real tx = GetUnitX(GameUnit)
    local real ty = GetUnitY(GameUnit)
    local real tz = GetTerrainZ(tx, ty)+GetUnitDefaultFlyHeight(GameUnit)+150
    local real dex = (tx-550*Cos(ang))-GameCamera.Eye.x
    local real dey = (ty-550*Sin(ang))-GameCamera.Eye.y
    local real dez = (tz+100)-GameCamera.Eye.z
    local real X = GameCamera.Eye.x+dex*0.07
    local real Y = GameCamera.Eye.y+dey*0.07
    local real Z = GameCamera.Eye.z+dez*0.07
    set ang = GetTerrainZ(X, Y)+170
    if Z < ang then
        set Z = ang
    endif
    if not(Approximately(X, GameCamera.Eye.x, 1) and Approximately(Y, GameCamera.Eye.y, 1) and Approximately(Z, GameCamera.Eye.z, 1) and Approximately(tx, GameCamera.At.x, 1) and Approximately(ty, GameCamera.At.y, 1) and Approximately(tz, GameCamera.At.z, 1)) then
        call GameCamera.SetEyeAndAt(X, Y, Z, tx, ty, tz)
    endif
endfunction

function GamePostUpdate takes nothing returns nothing
    if GameCamera.ApplyCameraForPlayer(Player(0), false) then
        call Update(true, true, true)
    endif
    //call UpdateFigure(GameCamera)
endfunction

function InitTrig_StartGame takes nothing returns nothing
    set GameUnit = u
    set GameTimer = CreateTrigger()
    call TriggerRegisterTimerEvent(GameTimer, GamePeriod, true)
    call TriggerAddAction(GameTimer, function GameUpdate)
    call TriggerAddAction(GameTimer, function GamePostUpdate)
    call DestroyTimer(GetExpiredTimer())
endfunction 

BUT it doesnt work properly by placing the textures nor the pressing