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.
Example #1: GUI Double Click Trigger
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.
Requirements:
-None
-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
- Events
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.