Snippet GUI-Friendly Double Click

tooltiperror

Super Moderator
Reaction score
231
GDC is a snippet for GUI-Users, and additionally mac users wishing to use the event in the editor, to register a Double Click event, when a player selects things twice. If you are using vJASS, I would recommend you seek out Azlier's DoubleClick, but it requires Event, which you may also not want to use for whatever reason. So if you're looking for lightweight, but efficient, this snippet is good for you. Special thanks to Weep for helping me with this and making it independent of GTS, which it no longer needs. It also makes sure that you selected the same unit both times. Please remember to not delete the documentation during importing.

Requirements:
-None​

JASS:
//
//
//          ___ _   _ ___        ___    _             _ _       
//         / __| | | |_ _|  __  | __| _(_)___ _ _  __| | |_  _ 
//        | (_ | |_| || |  |__| | _| '_| / -_) ' \/ _` | | || | 
//         \___|\___/|___|      |_||_| |_\___|_||_\__,_|_|\_, | 
//                         DOUBLE CLICK                     |_|
//                        by ToolTipError                  
//
//       GUI-Double Click is a snippet designed for GUI, but it works with JASS, as well.  In
//       laymens' terms, it gives the support of a Double Click event.  That's it, simple and
//       lightweight.  It no longer requires GTS.  
//
//       In order to import this system, open the demo map and copy the category "GDC" and
//       then paste it in your map.  Make sure that "Automatically create unknown variables
//       while pasting trigger data" is enabled in your preferences before you do this.
//
//       To create a Double-Click event trigger, use the event "Game - Real becomes Equal to 0.00" and
//       select GDC_Event as the real, there is an example in the "DoubleClick" trigger.
//
//       Please include this documentation inside your trigger editor, and do not delete it.
//
//       If you are using this with vJASS, you can uncomment the below lines instead of creating variables.
// 
//globals
//  real              udg_GDC_Event=0
//  unit      array   udg_GDC_CurrentUnit[11]
//  timer     array   udg_GDC_TimerArray[11]
//  boolean   array   udg_GDC_BooleanArray[11]
//endglobals

   constant function GDC_GetTime takes nothing returns real
       // You know, for reading this far, you can
       // adjust the amount of time that can pass between
       // clicks to be considered a "double click".
       return 1.00
   endfunction
   function GDC_GetTimerPlayerId takes timer t returns integer
       return GetHandleId(t)-GetHandleId(udg_GDC_TimerArray[0])
   endfunction
   function GDC_onExpire takes nothing returns nothing
       set udg_GDC_BooleanArray[GDC_GetTimerPlayerId(GetExpiredTimer())]=false
   endfunction                                              
   function GDC_SingleSelect takes nothing returns boolean
       local unit TriggerUnit=GetTriggerUnit()
       local integer index=GetPlayerId(GetTriggerPlayer())
         if udg_GDC_BooleanArray[index]==true and TriggerUnit==udg_GDC_CurrentUnit[index] then        
             set udg_GDC_Event=0            
             set udg_GDC_Event=1                                                                                                
             set udg_GDC_BooleanArray[index]=false
         else
             call PauseTimer(udg_GDC_TimerArray[index])
             set udg_GDC_BooleanArray[index]=true                                      
             set udg_GDC_CurrentUnit[index]=TriggerUnit                                
             call TimerStart(udg_GDC_TimerArray[index],GDC_GetTime(),false,function GDC_onExpire)
         endif
       set TriggerUnit=null
       return false
   endfunction
   function InitTrig_GDC takes nothing returns nothing
       local trigger t=CreateTrigger()
       local integer index=0
         loop
             set udg_GDC_TimerArray[index]=CreateTimer()
             set index=index+1
             exitwhen index==12
         endloop
         set index=0
         loop
             call TriggerRegisterPlayerUnitEvent(t,Player(index),EVENT_PLAYER_UNIT_SELECTED,null)
             set index=index+1
             exitwhen index==12
         endloop
       call TriggerAddCondition(t,Condition(function GDC_SingleSelect))
   endfunction


Example #1: GUI Double Click Trigger
Trigger:
  • DoubleClick
    • Events
      • Game - GDC_Event becomes Equal to 1.00
    • Conditions
    • Actions
      • Unit - Kill Triggering Unit

Behind the JASS, with ToolTipError

The premise of how the snippet works is fairly simple. When a player selects a unit, regardless of how many times they've selected them, it runs a function. It then sets the value of an array variable based upon player number to true, if it is false. After one second, the true is automatically set to false. See what I'm getting at here? Select it again before that one second is up, and we know you clicked it twice. The rest of the code is setting the variable to 1 to fire the event for GUI-users, and registering the selection event and getting consecutive Handle ID's for the timers to function MPI.
 

Attachments

  • GDC 1.1B.w3x
    19.6 KB · Views: 261
  • GDC 1.1C.w3x
    19.4 KB · Views: 279
  • GDC 1.1D.w3x
    19.7 KB · Views: 287
  • GDC 1.2.w3x
    19.3 KB · Views: 275

Weep

Godspeed to the sound of the pounding
Reaction score
400
Augh, you're doing things that will break GTS. I'll post about those in your other thread. Remaining are comments relevant to the rest of the system.

"MultiSelect" isn't a terribly descriptive name...I was expecting something pertaining to managing groups of units in-game. Perhaps "GUI-Friendly Double Click"?

What are variables [lJASS]boolean MS_Flag[/lJASS] and [lJASS]group array MS_GroupArray[/lJASS] for? ...and why isn't udg_MS_EventResponse listed in the pseudoglobals block? ...and why don't they have their necessary udg_ prefixes there?

You might as well provide links to the necessary systems in the code's documentation, not just the thread.

MS_GetTime might as well be a constant function. ;)

Any system that has the user implement the event "Value of real variable" should have this warning, due to potential World Editor fail:
Before you copy triggers that use [system] into a new map, you need to copy over [system] with its [system] Variable Creator trigger, or the variables won't be automatically created correctly.
If you pasted [system]-using triggers before pasting [system], to fix it, change the type of the variable [system]_Event to be a Real in the Trigger Editor's Variables window, and then find the triggers that became disabled and change their event to use the variable [system]_Event.
 

tooltiperror

Super Moderator
Reaction score
231
Augh, you're doing things that will break GTS. I'll post about those in your other thread. Remaining are comments relevant to the rest of the system.
Alright.

"MultiSelect" isn't a terribly descriptive name...I was expecting something pertaining to managing groups of units in-game. Perhaps "GUI-Friendly Double Click"?
Will do that soon, aka, when I feel like posting a VM to a mod > >

What are variables [lJASS]boolean MS_Flag[/lJASS] and [lJASS]group array MS_GroupArray[/lJASS] for? ...and why isn't udg_MS_EventResponse listed in the pseudoglobals block? ...and why don't they have their necessary udg_ prefixes there?
Updated, that was from a pre-release idea I had.

You might as well provide links to the necessary systems in the code's documentation, not just the thread.
Done.

MS_GetTime might as well be a constant function. ;)
Combo breaker. Done.

Any system that has the user implement the event "Value of real variable" should have this warning, due to potential World Editor fail:
Before you copy triggers that use [system] into a new map, you need to copy over [system] with its [system] Variable Creator trigger, or the variables won't be automatically created correctly.
If you pasted [system]-using triggers before pasting [system], to fix it, change the type of the variable [system]_Event to be a Real in the Trigger Editor's Variables window, and then find the triggers that became disabled and change their event to use the variable [system]_Event.
Done.

When I fix what I did to GTS or how I'm doing it wrong, I'll post the next version.

Edit: Updated to 1.1A.
 

Crazy_Dead

New Member
Reaction score
24
Not that i will use it, but can you explain the code, what does detect the double click?

Good Job. +rep.
 

Laiev

Hey Listen!!
Reaction score
188
this snipped detect when you select an unit, then, start a timer and when you select again the same unit (double click), it run :p

just a little combination of timer and boolean
:thup:


Just a question... why don't use private? to use in jass normal? :rolleyes:
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Just a note, [ljass]exitwhen index==11[/ljass] should be [ljass]exitwhen index==12[/ljass], or better yet [ljass]exitwhen index>=12[/ljass] ;)

I also would suggest you make a global variable, instead of the "GetTime" function, as you might want to have different "waiting-times" for different occasions...

And also, otherwise it won't be for "GUI-users" only XD :p

Just a question... why don't use private? to use in jass normal?

This is a GUI-based system, meaning that it should not require you to use anything else but the normal WE (Meaning not Newgen) and therefor, no vJASS ;)
 

tooltiperror

Super Moderator
Reaction score
231
Alright, gave the event and timers their own loops, you know, because I think I need that for consecutive handle ID's. Did what Komaqtion said and changed the loop, but kept the function because I like it.

1.1B :D
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Alright, gave the event and timers their own loops, you know, because I think I need that for consecutive handle ID's.
True, because [lJASS]TriggerRegisterPlayerUnitEvent[/lJASS] creates a handle. However, you've accidentally left the line [ljass]set udg_MS_TimerArray[index]=CreateTimer()[/ljass] in the loop with the trigger event, also. :p
 

tooltiperror

Super Moderator
Reaction score
231
Tee hee, silly me, C release.

Edit: Could a mod rename this to GUI-Friendly Double Click?​
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Good, good, but if I'm not mistaken, the instructions on how to set up the event in a trigger have disappeared?
 

tooltiperror

Super Moderator
Reaction score
231
I figured you wouldn't need it, since, you know, it has a demo-trigger in the category, but I'll add that to the script.
 

tooltiperror

Super Moderator
Reaction score
231
Every system should explain how it works

+rep for that

Thanks, I figured I should add it in case someone wants to know how.

What does this need for approval?
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
I don't think you need the event response variable at all - Triggering Unit and Triggering Player still work correctly.
Trigger:
  • DoubleClick
    • Events
      • Game - MS_Event becomes Equal to 0.00
    • Conditions
    • Actions
      • Game - Display to (All players) the text: (Name of (Triggering unit))
      • Game - Display to (All players) the text: (String((Player number of (Triggering player))))
 

tooltiperror

Super Moderator
Reaction score
231
Alright, so I'm assuming you have tested that and it's working perfectly?
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
It did in a local game with the unit still belonging to player 1, a computer as player 2, and me as player 3 (reported Paladin, 3).
 

tooltiperror

Super Moderator
Reaction score
231
Alright, well I think the reason it works is because [LJASS]unit[/LJASS] is likely a class in C++, and when the unit is clicked for the first time it sets a global variable to the triggering unit, and [LJASS]GetTriggerUnit()[/LJASS] just returns that variable. I tried to see if selecting a unit and then pressing escape to display the name of the triggering unit works, but it doesn't, so perhaps there is a time limit, that can only be achieved with code, not human reflex?

Here is the map I used to test it.
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Alright, well I think the reason it works is because [LJASS]unit[/LJASS] is likely a class in C++, and when the unit is clicked for the first time it sets a global variable to the triggering unit, and [LJASS]GetTriggerUnit()[/LJASS] just returns that variable. I tried to see if selecting a unit and then pressing escape to display the name of the triggering unit works, but it doesn't, so perhaps there is a time limit, that can only be achieved with code, not human reflex?
...what?

It's just because Triggering Unit is a local, "MUI", and inheritable event response. It seems Triggering Player is, as well. The triggers being run by the real value event inherit that event response. It's not a matter of time, it's a matter of code context - it could be used at any time, as long as the code belongs to a trigger run by the unit selection event, even if run indirectly by the real variable value event. It works in GDD, also, although Damaged Unit and Damage Source are not inherited.
 

tooltiperror

Super Moderator
Reaction score
231
Oh, alright, I figured that GetTriggerUnit() returned a global that was flushed and overwritten for events. I'll remove the variables from the script.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top