3087 Posts in 570 Topics - by 2220 Members - Latest Member: keistoni

Warcraft III: MapsModelsSkinsIconsSpellsToolsTutorials
WC3 JASS: Code SnippetsJASS and vJASS Spells and SystemsJass Tutorials
Chat @Discord

vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

* Random Spells & Systems

Double Spinning Blade v1.1.1

Views: 12485
Replies: 8
Posted by NocturnX
September 09, 2013, 01:07:44 AM

Dummy Caster 1.4

Views: 7764
Replies: 3
Posted by radamantus
June 27, 2013, 03:13:03 PM

Advanced Streak System v5.1.1.0

Views: 7958
Replies: 2
Posted by Magtheridon96
June 25, 2013, 07:11:38 PM

Author Topic: Window Interface  (Read 426 times)

Rating
Average Score
« Created: December 12, 2017, 12:38:56 PM by moyack »

  • Lurker - level 1
  • *
  • Posts: 1
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 0
  • User
    • View Profile
    • MANGBROSS
Window Interface
« on: May 02, 2011, 09:32:32 PM »
Categories: System, vJASS
Rating: 5
Image/screenshot:
Warcraft III Spell resource
« Created: December 12, 2017, 12:41:04 PM by moyack »
« Last Edit: January 28, 2018, 09:13:13 AM by moyack »

Related Topics or Resources



by

by

by

by
Based in the library DGUI it does pretty much the same but works for multiplayer.
(requires vJass)   More scripts: http://wc3jass.com/codes-snippets/
Requires JNGP (Check related links)

Uses the library Math by Ashujon   
Uses the library Camera by Ashujon
Uses the library TimerUtils
(Check the related resources)

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).

Code: jass  [Select]
  1. library WindowInterface initializer Init requires Math, Camera, TimerUtils
  2. //* ===================================================================================================== *
  3. //* by Galled                                                                                             *
  4. //* based in DGUI by Ashujon:  [url]http://www.wc3c.net/showthread.php?t=102351[/url]                                *
  5. //*                                                                                                       *
  6. //* (requires vJass)   More scripts: htt://www.wc3c.net                                                   *
  7. //* (requires jassnewgenpack5b+)                                                                          *
  8. //*                                                                                                       *
  9. //* Uses the library Math by Ashujon                                                                                              *
  10. //* [url]http://www.wc3c.net/showthread.php?t=102351[/url]                                                                                                                    *
  11. //* Uses the library Camera by Ashujon                                                                                            *
  12. //* [url]http://www.wc3c.net/showthread.php?t=102351[/url]                                                                                                                *
  13. //* Uses the library TimerUtils by Vexorian (only tested with Blue Flavor):                               *
  14. //* [url]http://www.wc3c.net/showthread.php?t=101322[/url]                                                           *
  15. //*                                                                                                       *
  16. //* This library consists of three structs (BUTTON, PICTURE and TEXT), the struct BUTTON draws heavily on *
  17. //* the PICTURE struct, while the struct TEXT uses TextTags to show for different players. For BUTTON and *
  18. //* PICTURE are required Dummys units that are nearly invisible to any player (at least in the minimap),  *
  19. //* so that the PICTURE structs are multiplayer only playing with the VertexColor.                        *
  20. //* ===================================================================================================== *
  21. globals
  22.     private constant integer TypeUnit = 'dgui' //Dummy unit masquerading as a button
  23.     private integer TypeSkinChanger = 'A000' //Ability that changes the textures of the units posing as buttons or images
  24.     private location GL4DGUI = Location(0,0)
  25.         private trigger trigLclick  //Trigger that detects when a player make a left click in a button.
  26.         private trigger trigLclickControl  //Trigger that detects when a player make a left click in a not-button unit.
  27.         private trigger trigRclick  //Trigger that detects when a player make a left click in a button.
  28.         private timer PeriodicControl  //Timer that controls the selected buttons
  29.         private real TimeControl = 0.03 //Interval in wich the timer review if a button has been selected
  30.         private unit array LastSelectedUnit //Save the last unit for every player to prevent the timer PeriodicControl leave the selection of an unit blank.
  31.         private boolean array ClearLastSelected //To lock the save the last unit for every player.
  32. endglobals
  33.  
  34. //Function that you will use with the actions in the left or right click
  35. function GetTriggerButton takes nothing returns BUTTON
  36.         if ( BUTTON.IsRightClicked() ) then
  37.                 return GetUnitUserData(GetOrderTargetUnit())
  38.         elseif ( BUTTON.IsLeftClicked() ) then
  39.                 return GetUnitUserData(GetTriggerUnit())
  40.         endif
  41.     return 0
  42. endfunction
  43.  
  44. //Function extracted from DGUI by Ashujon. Allows you to locate the coordinate Z. Very useful for camera views.
  45. private function GetZ4DGUI takes real X, real Y returns real
  46.     call MoveLocation(GL4DGUI, X, Y)
  47.     return GetLocationZ(GL4DGUI)
  48. endfunction
  49.  
  50. private function FineIndexAnimModel takes real w, real h, real z returns integer
  51.     local real W = w*WidthScreen*z  //WidthScreen variable from Camera library
  52.     local real H = h*HeightScreen*z //HeightScreen variable from Camera library
  53.     local real anim
  54.     if (H<W) then
  55.         set anim = 10*(W/H-1)
  56.         return R2I_n(anim)
  57.     else
  58.         set anim = 10*(H/W-1)
  59.         if anim >= 0.5 then
  60.             return 100+R2I_n(anim)
  61.         endif
  62.     endif
  63.     return 0
  64. endfunction
  65.  
  66. private function FineSizeModel takes real w, real h, real z returns real
  67.     local real W = w*WidthScreen*z  //WidthScreen variable from Camera library
  68.     local real H = h*HeightScreen*z //HeightScreen variable from Camera library
  69.     if (H<W) then
  70.         return 0.5*H
  71.     else
  72.         return 0.5*W
  73.     endif
  74. endfunction
  75.  
  76. struct BUTTON
  77.     static BUTTON array AllShow
  78.     static integer CountShow = 0
  79.     private integer index
  80.     private CAMERA Camera
  81.    
  82.     private real centerx
  83.     private real centery
  84.     private real minx
  85.     private real maxx
  86.     private real miny
  87.     private real maxy
  88.     private real width
  89.     private real height
  90.     private real z
  91.     unit picture
  92.     private integer indexanim
  93.     private effect model
  94.     boolean show
  95.     integer CostumValue
  96.  
  97.     static method New takes real minx, real maxy, real W, real H, real z, integer texture returns BUTTON
  98.         local BUTTON this = BUTTON.create()
  99.         local destructable tree
  100.         set .CostumValue = 0
  101.         set .Camera = 0
  102.         set .width = W
  103.         set .height = H
  104.         set .minx = minx
  105.         set .maxx = minx+W
  106.         set .maxy = maxy
  107.         set .miny = maxy-H
  108.         set .z = 100.2+z
  109.         set .centerx = minx+W/2.0
  110.         set .centery = maxy-H/2.0
  111.         set .show = false
  112.         set .picture = CreateUnit(Player(15), TypeUnit, 0, 0, 0)
  113.         call UnitAddAbility(.picture, TypeSkinChanger)
  114.         if (texture != 0) then
  115.             set tree = CreateDestructable(texture,0,0,0,0,1)
  116.             call IssueTargetOrder(.picture, "grabtree", tree)
  117.             call RemoveDestructable(tree)
  118.             set tree = null
  119.         endif
  120.         set .indexanim = FineIndexAnimModel(W, H, .z)
  121.         call SetUnitAnimationByIndex(.picture, .indexanim)
  122.         call SetUnitScale(.picture, FineSizeModel(W, H, .z), 0, 0)
  123.         call UnitAddAbility(.picture, 'Aave')
  124.         call UnitRemoveAbility(.picture, 'Aave')
  125.         call ShowUnit(.picture, false)
  126.         call SetUnitUserData(.picture, this)
  127.         return this
  128.     endmethod
  129.        
  130.         static method LockLastSelectedUnitForPlayer takes player p, boolean lock returns nothing
  131.                 set ClearLastSelected[GetPlayerId(p)] = lock
  132.         endmethod
  133.        
  134.         static method ClearLastSelectedUnitForPlayer takes player p returns nothing
  135.                 call .LockLastSelectedUnitForPlayer(p,true)
  136.                 set LastSelectedUnit[GetPlayerId(p)] = null
  137.         endmethod
  138.        
  139.         static method GetLastSelectedUnitForPlayer takes player p returns unit
  140.                 return LastSelectedUnit[GetPlayerId(p)]
  141.         endmethod
  142.        
  143.         static method SaveLastSelectedUnitForPlayer takes unit u, player p returns nothing
  144.                 if( LastSelectedUnit[GetPlayerId(p)] != u) then
  145.                         set LastSelectedUnit[GetPlayerId(p)] = u
  146.                 endif
  147.         endmethod
  148.                
  149.         static method SaveLastSelectedUnit takes nothing returns nothing
  150.         local player p = GetTriggerPlayer()
  151.         local unit u = GetTriggerUnit()
  152.                 if ( ClearLastSelected[GetPlayerId(p)] == false) then
  153.                         if( LastSelectedUnit[GetPlayerId(p)] != u) then
  154.                                 set LastSelectedUnit[GetPlayerId(p)] = u
  155.                         endif
  156.                 endif
  157.         set u = null
  158.         set p = null
  159.         endmethod
  160.  
  161.     static method AddActionL takes code func returns triggeraction
  162.         return TriggerAddAction(trigLclick, func)
  163.     endmethod
  164.    
  165.     static method RemoveActionL takes triggeraction action returns nothing
  166.         call TriggerRemoveAction(trigLclick, action)
  167.     endmethod
  168.    
  169.     static method AddActionR takes code func returns triggeraction
  170.         return TriggerAddAction(trigRclick, func)
  171.     endmethod
  172.    
  173.     static method RemoveActionR takes triggeraction action returns nothing
  174.         call TriggerRemoveAction(trigRclick, action)
  175.     endmethod
  176.    
  177.     method Delete takes nothing returns nothing
  178.         call RemoveUnit(.picture)
  179.         if .show then
  180.             set .AllShow[.index] = .AllShow[.CountShow]
  181.             set .AllShow[.index].index = .index
  182.             set .CountShow = .CountShow - 1
  183.         endif
  184.     endmethod
  185.        
  186.     //Method that updates the position of the buttons so that they appear properly on screen.
  187.     method Update takes nothing returns nothing
  188.         local VECTOR3 Pos = .Camera.Win2World(.centerx, .centery, .z)
  189.         call SetUnitX(.picture, Pos.x)
  190.         call SetUnitY(.picture, Pos.y)
  191.         call MoveLocation(GL4DGUI, Pos.x, Pos.y)
  192.         call SetUnitFlyHeight(.picture, Pos.z-GetLocationZ(GL4DGUI), 0)
  193.         call Pos.destroy()
  194.     endmethod
  195.    
  196.     method Show takes boolean show, CAMERA Cam returns nothing
  197.         if Cam != -1 then
  198.             set .Camera = Cam
  199.         endif
  200.         call ShowUnit(.picture, show)
  201.         if show != .show then
  202.             if show then
  203.                 set .AllShow[.CountShow] = this
  204.                 set .index = .CountShow
  205.                 set .CountShow = .CountShow + 1
  206.                 call .Update()
  207.                 call SetUnitAnimationByIndex(.picture, .indexanim)
  208.             else
  209.                 set .CountShow = .CountShow - 1
  210.                 set .AllShow[.index] = .AllShow[.CountShow]
  211.                 set .AllShow[.index].index = .index
  212.             endif
  213.         endif
  214.         set .show = show
  215.     endmethod
  216.    
  217.         static method IsLeftClicked takes nothing returns boolean
  218.         local unit isLeftButton = GetTriggerUnit()
  219.         local boolean isLeft = false
  220.        
  221.                 if(isLeftButton!=null)then
  222.                         set isLeft = GetUnitAbilityLevel(isLeftButton, TypeSkinChanger)>0 //Selected unit
  223.                         set isLeftButton = null
  224.                 endif
  225.  
  226.                 return isLeft
  227.         endmethod
  228.        
  229.         static method IsRightClicked takes nothing returns boolean
  230.         local unit isRightButton = GetOrderTargetUnit()
  231.         local boolean isRight = false
  232.        
  233.                 if(isRightButton!=null)then
  234.                         set isRight = (GetUnitAbilityLevel(isRightButton, TypeSkinChanger)>0) //Target order with "smart" order
  235.                 endif
  236.  
  237.                 if(isRight)then
  238.                         call PauseUnit(GetTriggerUnit(), true)
  239.                         call IssueImmediateOrder(GetTriggerUnit(), "stop")
  240.                         call PauseUnit(GetTriggerUnit(), false)
  241.                 endif
  242.                
  243.                 set isRightButton = null
  244.                
  245.                 return isRight
  246.         endmethod
  247.        
  248.         static method IsClicked takes nothing returns boolean
  249.         local boolean isRight = .IsRightClicked()
  250.         local boolean isLeft = false
  251.        
  252.                 if isRight==false then
  253.                         set isLeft = .IsLeftClicked()
  254.                 endif
  255.                
  256.                 return isLeft or isRight
  257.         endmethod
  258.            
  259.     method SetPosition takes real minx, real maxy returns nothing
  260.         set .minx = minx
  261.         set .maxx = minx+.width
  262.         set .maxy = maxy
  263.         set .miny = maxy-.height
  264.         set .centerx = minx+.width/2.0
  265.         set .centery = maxy-.height/2.0
  266.         if .show then
  267.             call .Update()
  268.         endif
  269.     endmethod
  270.    
  271.     method SetTexture takes integer texture returns nothing
  272.         local destructable tree = CreateDestructable(texture,0,0,0,0,1)
  273.         call ShowUnit(.picture, true)
  274.         call SetUnitX(.picture, 0)
  275.         call SetUnitY(.picture, 0)
  276.         call IssueTargetOrder(.picture,"grabtree",tree)
  277.         call ShowUnit(.picture, .show)
  278.         call RemoveDestructable(tree)
  279.         if .show then
  280.             call .Update()
  281.         endif
  282.         set tree = null
  283.     endmethod
  284.    
  285.     static method AllUpdate takes nothing returns nothing
  286.         local integer i = .CountShow
  287.         loop
  288.             exitwhen i < 0
  289.             call .AllShow[i].Update()
  290.             set i = i - 1
  291.         endloop
  292.     endmethod
  293.        
  294.     static method ClickPeriodicSelect takes player p returns unit
  295.         local integer i = .CountShow
  296.         loop
  297.             exitwhen i < 0
  298.             if IsUnitSelected(.AllShow[i].picture, p) then
  299.                 return .AllShow[i].picture
  300.             endif
  301.             set i = i - 1
  302.         endloop
  303.         return null
  304.     endmethod
  305.  
  306. endstruct
  307.  
  308. struct PICTURE
  309.     private static PICTURE array AllShow
  310.     private static integer CountShow = 0
  311.     private integer index
  312.     private CAMERA Camera
  313.    
  314.     private real centerx
  315.     private real centery
  316.     private real width
  317.     private real height
  318.     private real z
  319.     unit picture
  320.     private integer indexanim
  321.         boolean array show2Player[12]
  322.     integer CostumValue
  323.    
  324.     static method New takes real minx, real maxy, real W, real H, real z, integer texture returns PICTURE
  325.         local PICTURE this = PICTURE.create()
  326.         local destructable tree
  327.                 local integer i = 0
  328.                 loop
  329.                         set .show2Player[i]=false
  330.                         set i = i + 1
  331.                         exitwhen i>=bj_MAX_PLAYERS
  332.                 endloop
  333.         set .CostumValue = 0
  334.         set .Camera = 0
  335.         set .width = W
  336.         set .height = H
  337.         set .centerx = minx+W/2.0
  338.         set .centery = maxy-H/2.0
  339.         set .z = 100.2+z
  340.         set .picture = CreateUnit(Player(15), TypeUnit, 0, 0, 0)
  341.                 call SetUnitVertexColor(.picture,255,255,255,0)
  342.         call UnitAddAbility(.picture, TypeSkinChanger)
  343.         if (texture != 0) then
  344.             set tree = CreateDestructable(texture,0,0,0,0,1)
  345.             call IssueTargetOrder(.picture, "grabtree", tree)
  346.             call RemoveDestructable(tree)
  347.             set tree = null
  348.         endif
  349.         set .indexanim = FineIndexAnimModel(W, H, .z)
  350.         call SetUnitAnimationByIndex(.picture, .indexanim)
  351.         call SetUnitScale(.picture, FineSizeModel(W, H, .z), 0, 0)
  352.         call UnitAddAbility(.picture, 'Aave')
  353.         call UnitRemoveAbility(.picture, 'Aave')
  354.         call UnitAddAbility(.picture, 'Aloc')
  355.         call UnitRemoveAbility(.picture, 'Aloc')
  356.         return this
  357.     endmethod
  358.    
  359.     static method NewCostumModel takes real minx, real maxy, real z, real size, integer typeunit, real WidthModel, real HeightModel, integer texture returns PICTURE
  360.         local PICTURE this = PICTURE.create()
  361.         local destructable tree
  362.                 local integer i = 0
  363.                 loop
  364.                         set .show2Player[i]=false
  365.                         set i = i + 1
  366.                         exitwhen i>=bj_MAX_PLAYERS
  367.                 endloop
  368.         set .CostumValue = 0
  369.         set .Camera = 0
  370.         set .z = 100.2+z
  371.         set .width = (WidthModel*size)/(WidthScreen*.z)
  372.         set .height = (HeightModel*size)/(HeightScreen*.z)
  373.         set .centerx = minx+.width/2.0
  374.         set .centery = maxy-.height/2.0
  375.         set .picture = CreateUnit(Player(15), typeunit, 0, 0, 0)
  376.                 call SetUnitVertexColor(.picture,255,255,255,0)
  377.         call UnitAddAbility(.picture, TypeSkinChanger)
  378.         if (texture != 0) then
  379.             set tree = CreateDestructable(texture,0,0,0,0,1)
  380.             call IssueTargetOrder(.picture, "grabtree", tree)
  381.             call RemoveDestructable(tree)
  382.             set tree = null
  383.         endif
  384.         call SetUnitScale(.picture, size, 0, 0)
  385.         call UnitAddAbility(.picture, 'Aave')
  386.         call UnitRemoveAbility(.picture, 'Aave')
  387.         call UnitAddAbility(.picture, 'Aloc')
  388.         call UnitRemoveAbility(.picture, 'Aloc')
  389.         return this
  390.     endmethod
  391.        
  392.         private method IsShowedToAnybody takes nothing returns boolean
  393.         local integer i = 0
  394.         local boolean b = false
  395.                 loop
  396.                         set b = b or .show2Player[i]
  397.                         set i = i + 1
  398.                         exitwhen i>=bj_MAX_PLAYERS
  399.                 endloop
  400.                
  401.                 return b
  402.         endmethod
  403.        
  404.     method Delete takes nothing returns nothing
  405.         call RemoveUnit(.picture)
  406.         if .IsShowedToAnybody() then
  407.             set .AllShow[.index] = .AllShow[.CountShow]
  408.             set .AllShow[.index].index = .index
  409.             set .CountShow = .CountShow - 1
  410.         endif
  411.     endmethod
  412.    
  413.     method Update takes nothing returns nothing
  414.         local VECTOR3 Pos = .Camera.Win2World(.centerx, .centery, .z)
  415.         call SetUnitX(.picture, Pos.x)
  416.         call SetUnitY(.picture, Pos.y)
  417.         call MoveLocation(GL4DGUI, Pos.x, Pos.y)
  418.         call SetUnitFlyHeight(.picture, Pos.z-GetLocationZ(GL4DGUI), 0)
  419.         call Pos.destroy()
  420.     endmethod
  421.    
  422.     method ShowAll takes boolean show, CAMERA Cam, boolean showUnit returns nothing
  423.         local integer i = 0
  424.        
  425.                 if(showUnit)then
  426.                         call ShowUnit(.picture, show)
  427.                 endif
  428.                 loop
  429.                         call .ShowToPlayer(show,Cam,Player(i))
  430.                         set i = i + 1
  431.                         exitwhen i>=bj_MAX_PLAYERS
  432.                 endloop
  433.     endmethod
  434.        
  435.     method ShowToPlayer takes boolean show, CAMERA Cam, player p returns nothing
  436.         if Cam != -1 then
  437.             set .Camera = Cam
  438.         endif
  439.         if (show != .show2Player[GetPlayerId(p)]) then
  440.             if show then
  441.                 set .AllShow[.CountShow] = this
  442.                 set .index = .CountShow
  443.                 set .CountShow = .CountShow + 1
  444.                 call .Update()
  445.                                 if(GetLocalPlayer()==p)then
  446.                                         call SetUnitVertexColor(.picture,255,255,255,255)
  447.                                 endif
  448.             else
  449.                                 if(GetLocalPlayer()==p)then
  450.                                         call SetUnitVertexColor(.picture,255,255,255,0)
  451.                                 endif
  452.                 set .CountShow = .CountShow - 1
  453.                 set .AllShow[.index] = .AllShow[.CountShow]
  454.                 set .AllShow[.index].index = .index
  455.             endif
  456.         endif
  457.         set .show2Player[GetPlayerId(p)] = show
  458.  
  459.     endmethod
  460.    
  461.     method SetPosition takes real minx, real maxy returns nothing
  462.         set .centerx = minx+.width/2.0
  463.         set .centery = maxy-.height/2.0
  464.                 if .IsShowedToAnybody() then
  465.             call .Update()
  466.         endif
  467.     endmethod
  468.    
  469.     method SetTexture takes integer texture returns nothing
  470.         local destructable tree = CreateDestructable(texture,0,0,0,0,1)
  471.         local integer i = 0
  472.         local boolean b = false
  473.        
  474.         call ShowUnit(.picture, true)
  475.         call SetUnitX(.picture, 0)
  476.         call SetUnitY(.picture, 0)
  477.         call IssueTargetOrder(.picture,"grabtree",tree)
  478.         call RemoveDestructable(tree)
  479.                 loop
  480.                         set b = b or .show2Player[i]
  481.                         set i = i + 1
  482.                         exitwhen i>=bj_MAX_PLAYERS
  483.                 endloop                
  484.                 if b then
  485.             call .Update()
  486.         endif
  487.         set tree = null
  488.     endmethod
  489.    
  490.     static method AllUpdate takes nothing returns nothing
  491.         local integer i = .CountShow
  492.         loop
  493.             exitwhen i < 0
  494.             call .AllShow[i].Update()
  495.             set i = i - 1
  496.         endloop
  497.     endmethod
  498.  
  499. endstruct //PICTURE
  500.  
  501. struct TEXT
  502.     private static TEXT array AllShow
  503.     private static integer CountShow = 0
  504.     private integer index
  505.     private CAMERA Camera
  506.    
  507.     private real minx
  508.     private real maxy
  509.     private real z
  510.     texttag textInScreen
  511.         string textString
  512.         boolean array show2Player[12]
  513.     integer CostumValue
  514.    
  515.     static method New takes real minx, real maxy, real z returns TEXT
  516.         local TEXT this = TEXT.create()
  517.                 local integer i = 0
  518.                 loop
  519.                         set .show2Player[i]=false
  520.                         set i = i + 1
  521.                         exitwhen i>=bj_MAX_PLAYERS
  522.                 endloop
  523.         set .CostumValue = 0
  524.         set .Camera = 0
  525.         set .minx = minx
  526.         set .maxy = maxy
  527.         set .z = 100+z
  528.                 set .textInScreen = null
  529.                 set .textString = ""
  530.         return this
  531.     endmethod
  532.    
  533.         method SetText takes string text returns nothing
  534.                 set .textString = text
  535.         endmethod
  536.        
  537.         private method IsShowedToAnybody takes nothing returns boolean
  538.         local integer i = 0
  539.         local boolean b = false
  540.                 loop
  541.                         set b = b or .show2Player[i]
  542.                         set i = i + 1
  543.                         exitwhen i>=bj_MAX_PLAYERS
  544.                 endloop
  545.                
  546.                 return b
  547.         endmethod
  548.        
  549.     method Delete takes nothing returns nothing
  550.                 if(.textInScreen!=null)then
  551.                         call DestroyTextTag(.textInScreen)
  552.                 endif
  553.         if .IsShowedToAnybody() then
  554.             set .AllShow[.index] = .AllShow[.CountShow]
  555.             set .AllShow[.index].index = .index
  556.             set .CountShow = .CountShow - 1
  557.         endif
  558.     endmethod
  559.    
  560.     method Update takes nothing returns nothing
  561.         local VECTOR3 Pos = .Camera.Win2World(.minx, .maxy, .z)
  562.                 if(.textInScreen != null)then
  563.                         call SetTextTagPos(.textInScreen, Pos.x, Pos.y, Pos.z-GetZ4DGUI(Pos.x,Pos.y))
  564.                 endif
  565.         call Pos.destroy()
  566.     endmethod
  567.    
  568.     method SetPosition takes real minx, real maxy returns nothing
  569.         set .minx = minx
  570.         set .maxy = maxy
  571.         if .IsShowedToAnybody() then
  572.             call .Update()
  573.         endif
  574.     endmethod
  575.    
  576.     method ShowAll takes boolean show, CAMERA Cam returns nothing
  577.         local integer i = 0
  578.                 loop
  579.                         call .ShowToPlayer(show,Cam,Player(i))
  580.                         set i = i + 1
  581.                         exitwhen i>=bj_MAX_PLAYERS
  582.                 endloop
  583.     endmethod
  584.        
  585.     method ShowToPlayer takes boolean show, CAMERA Cam, player p returns nothing
  586.         local boolean state = .show2Player[GetPlayerId(p)] != show
  587.                 set .show2Player[GetPlayerId(p)] = show
  588.                
  589.                 if show then
  590.                         if(.textInScreen!=null)then
  591.                                 call DestroyTextTag(.textInScreen)
  592.                                 set .textInScreen = null
  593.                         endif
  594.                         set .textInScreen = CreateTextTag()
  595.                         call SetTextTagText(.textInScreen, .textString, 8 * 0.0023)
  596.                         call SetTextTagVisibility(.textInScreen, false)
  597.                         call .Update()         
  598.                         if (GetLocalPlayer()==p) then
  599.                                 call SetTextTagVisibility(.textInScreen, true)
  600.                         endif
  601.                 else                   
  602.                         if (.IsShowedToAnybody()==false) then
  603.                                 call DestroyTextTag(.textInScreen)
  604.                                 set .textInScreen = null
  605.                         endif
  606.                 endif
  607.                 if Cam != -1 then
  608.                         set .Camera = Cam
  609.                 endif
  610.                 if (state) then
  611.                         if show then
  612.                                 set .AllShow[.CountShow] = this
  613.                                 set .index = .CountShow
  614.                                 set .CountShow = .CountShow + 1
  615.                                 call .Update()
  616.                                 if (GetLocalPlayer()==p) then
  617.                                         call SetTextTagVisibility(.textInScreen, true)
  618.                                 endif
  619.                         else
  620.                                 if (GetLocalPlayer()==p) then
  621.                                         if(.textInScreen!=null)then
  622.                                                 call SetTextTagVisibility(.textInScreen, false)
  623.                                         endif
  624.                                 endif
  625.                                 set .CountShow = .CountShow - 1
  626.                                 set .AllShow[.index] = .AllShow[.CountShow]
  627.                                 set .AllShow[.index].index = .index
  628.                         endif
  629.                 endif
  630.                
  631.     endmethod
  632.    
  633.     static method AllUpdate takes nothing returns nothing
  634.         local integer i = .CountShow
  635.         loop
  636.             exitwhen i < 0
  637.             call .AllShow[i].Update()
  638.             set i = i - 1
  639.         endloop
  640.     endmethod
  641.  
  642. endstruct
  643.  
  644. private function PeriodicClearSelect takes nothing returns nothing
  645. local integer i = 0
  646. local unit check = null
  647.  
  648.     loop
  649.                 set check = BUTTON.ClickPeriodicSelect(Player(i))
  650.         if check != null then
  651.                         if (LastSelectedUnit[i] != null) then
  652.                                 if(IsUnitSelected(LastSelectedUnit[i],Player(i))==false)then
  653.                                         if (GetLocalPlayer() == Player(i)) then
  654.                                                 call ClearSelection()
  655.                                                 call SelectUnit(LastSelectedUnit[i], true)
  656.                                         endif
  657.                                 endif
  658.                         else
  659.                                 if (GetLocalPlayer()==Player(i)) then
  660.                                         call ClearSelection()
  661.                                 endif
  662.                         endif
  663.                         set check = null
  664.         endif
  665.         set i = i + 1
  666.                 exitwhen i>=bj_MAX_PLAYERS
  667.     endloop
  668.        
  669. set check = null
  670. endfunction
  671.  
  672. public function Update takes boolean but, boolean pic, boolean tex returns nothing
  673.     if but then
  674.         call BUTTON.AllUpdate()
  675.     endif
  676.     if pic then
  677.         call PICTURE.AllUpdate()
  678.     endif
  679.     if tex then
  680.         call TEXT.AllUpdate()
  681.     endif
  682. endfunction
  683.  
  684. private function Init takes nothing returns nothing
  685. local integer i = 0
  686.  
  687.         set trigLclick = CreateTrigger()
  688.         set trigLclickControl = CreateTrigger()
  689.         set trigRclick = CreateTrigger()
  690.         set PeriodicControl = NewTimer()
  691.     call TimerStart(PeriodicControl, TimeControl, true, function PeriodicClearSelect)
  692.         loop
  693.                 call TriggerRegisterPlayerUnitEvent(trigLclick, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
  694.                 call TriggerRegisterPlayerUnitEvent(trigLclickControl, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
  695.                 call TriggerRegisterPlayerUnitEvent(trigRclick, Player(i), EVENT_PLAYER_UNIT_ISSUED_UNIT_ORDER, null)
  696.                 set ClearLastSelected[i] = false
  697.                 set LastSelectedUnit[i] = null
  698.                 set i = i + 1
  699.                 exitwhen i>=bj_MAX_PLAYER_SLOTS
  700.         endloop
  701.         call TriggerAddAction(trigLclickControl, function BUTTON.SaveLastSelectedUnit)
  702.         call TriggerAddCondition(trigLclickControl, Not(Condition( function BUTTON.IsClicked)))
  703.        
  704.         call TriggerAddCondition(trigLclick,Condition( function BUTTON.IsClicked))
  705.         call TriggerAddCondition(trigRclick,Condition( function BUTTON.IsClicked))
  706. endfunction
  707.  
  708. endlibrary
  709.  

There are the test in the map:
Code: jass  [Select]
  1. scope Test
  2.  
  3. globals
  4.  
  5.     constant real WidthSlot = 0.08              //                                                       |
  6.     constant real HeightSlot = 0.08*AspectRatio //AspectRatio is a variable from Camera library
  7.     integer TypeTextureBlank = 'dbnk'
  8.     private code FuncLClickSlot = null
  9.     private code FuncRClickSlot = null
  10.         PICTURE array pict
  11.         TEXT array text
  12. endglobals
  13.  
  14. private function RaceToInt takes race raza returns integer
  15.         if raza == RACE_HUMAN then
  16.                 return 0
  17.         elseif raza == RACE_ORC then
  18.                 return 1
  19.         elseif raza == RACE_UNDEAD then
  20.                 return 2
  21.         elseif raza == RACE_NIGHTELF then
  22.                 return 3
  23.         endif
  24.  
  25.         return 0
  26. endfunction
  27.  
  28. private function WhenLeftClick takes nothing returns nothing
  29. local BUTTON but = GetTriggerButton()
  30. local player p = GetTriggerPlayer()
  31.  
  32.         debug call BJDebugMsg("Player "+GetPlayerName(p)+" is left clicked in the button with the value: "+I2S(but.CostumValue))
  33.        
  34.         call pict[GetPlayerId(p)].ShowToPlayer(true, GameCamera, p)
  35.         call text[GetPlayerId(p)].SetText("Player "+GetPlayerName(p)+" is left clicked in the button with the value: "+I2S(but.CostumValue))
  36.         call text[GetPlayerId(p)].ShowToPlayer(true, GameCamera, p)
  37.        
  38. set p = null
  39. endfunction
  40.  
  41. private function WhenRightClick takes nothing returns nothing
  42. local BUTTON but = GetTriggerButton()
  43. local player p = GetTriggerPlayer()
  44.        
  45.         debug call BJDebugMsg("Player "+GetPlayerName(p)+" is right clicked in the button with the value: "+I2S(but.CostumValue))
  46.                
  47.         call pict[GetPlayerId(p)].ShowToPlayer(false, GameCamera, p)
  48.         call text[GetPlayerId(p)].ShowToPlayer(false, GameCamera, p)
  49.        
  50. set p = null
  51. endfunction
  52.  
  53. //===========================================================================
  54. public function InitTrig takes nothing returns nothing
  55. //Create three buttons
  56. local BUTTON test1 = BUTTON.New(0, 0, WidthSlot, HeightSlot, 0.5, TypeTextureBlank)
  57. local BUTTON test2 = BUTTON.New(0, 0, WidthSlot, HeightSlot, 0.5, TypeTextureBlank)
  58. local BUTTON test3 = BUTTON.New(0, 0, WidthSlot, HeightSlot, 0.5, TypeTextureBlank)
  59. local integer i = 0
  60. local unit u
  61.        
  62.         //Create the camera. That is very important!!!
  63.     set GameCamera = CAMERA.New()
  64.        
  65.         //... , one in the center of the screen
  66.         set test1.CostumValue = 11
  67.         call test1.SetPosition(0,0) //Coordenates in the screen, not in the map.
  68.         call test1.Show(true, GameCamera)
  69.        
  70.         //... , one on the top right
  71.         set test2.CostumValue = 22
  72.         call test2.SetPosition(0.8,0.8) //Coordenates in the screen, not in the map.
  73.         call test2.Show(true, GameCamera)      
  74.        
  75.         //... and the last one on the bottom left
  76.         set test3.CostumValue = 33
  77.         call test3.SetPosition(-0.8,-0.8) //Coordenates in the screen, not in the map.
  78.         call test3.Show(true, GameCamera)
  79.        
  80.         set u = CreateUnit(Player(0), 'Hpal', 0,0, 180)
  81.         call SelectUnitForPlayerSingle(u,Player(0))
  82.         set u = CreateUnit(Player(1), 'Obla', 0,0, 180)
  83.         call SelectUnitForPlayerSingle(u,Player(1))
  84.        
  85.         loop
  86.                 //Create a picture and text to each player
  87.                 //PICTURE method NewCostumModel takes real minx, real maxy, real z, real size, integer typeunit, real WidthModel, real HeightModel, integer texture                                
  88.                 set pict[i] = PICTURE.NewCostumModel(-0.99, 0.95, 1, 0.26, 'dwin', 140.002, 122.646, 'D201'+RaceToInt(GetPlayerRace(Player(i))))
  89.                 //TEXT method New takes real minx, real maxy, real z returns TEXT
  90.                 set text[i] = TEXT.New(-0.9, 0.76, 1)
  91.                 set i = i + 1
  92.                 exitwhen i>=bj_MAX_PLAYER_SLOTS
  93.         endloop
  94.        
  95.         set FuncLClickSlot = function WhenLeftClick
  96.         set FuncRClickSlot = function WhenRightClick
  97.        
  98.         call BUTTON.AddActionL(FuncLClickSlot)
  99.         call BUTTON.AddActionR(FuncRClickSlot)
  100.        
  101.        
  102. endfunction
  103. endscope
« Last Edit: January 28, 2018, 09:14:46 AM by moyack »

 

Blizzard Modding Information Center Wacraft III Modding Information Center WC3JASS.com - The JASS Vault Chronicles of Darkness - A Warcraft III mod Jetcraft - A Starcraft II mod Troll Smash - A Warcraft III Arena Starcraft II Modding Information Center
  Mod DB - Change the Game Power of Corruption - A Warcraft III altered melee map Chaos Realm - The world of Game modders and wc3 addicts Follow us on Facebook!!