| 05-22-2009, 10:26 PM | #1 |
I got tired of seeing strange, overcomplicated, hacky implementations of this simple thing. * Does anyone actually need the event to be removable? I can't think of a legit reason for so, but if you prove such need I can easily add a way for it. * It fails if you double click too fast and there are many units of the same type around (the game will consider it a select all double click) * As always, names are subject to change before approval... Example:scope OnDoubleClickDemo initializer xxx private function meh takes player p, unit u returns nothing call BJDebugMsg(GetPlayerName(p)+" double clicks "+GetUnitName(u) ) endfunction private function xxx takes nothing returns nothing call OnDoubleClick( meh ) endfunction endscope OnDoubleClick:library OnDoubleClick initializer init //****************************************************** //* OnDoubleClick //* ------------- //* Calls a function when a player does a double click //* //* Usage: //* call OnDoubleClick( function_name ) //* //* The function must take a player as first argument //* and unit as second argument, ie: //* //* function function_name takes player clickingPlayer, unit clickedUnit returns nothing //* //* //******************************************************** //==================================================================================== globals // The interval between clicks must be smaller than WAIT_TIME for them to count private constant real WAIT_TIME = 1.0 endglobals //===================================================================================== globals private constant integer HUMAN_PLAYERS = 12 private constant real EXAGGERATED_GAME_LENGTH = 1000000.0 private timer T private OnDoubleClickListener array listener private integer listeners = 0 endglobals function interface OnDoubleClickListener takes player clickingPlayer, unit clickedUnit returns nothing function OnDoubleClick takes OnDoubleClickListener od returns nothing set listener[listeners] = od set listeners = listeners + 1 endfunction private struct PlayerData extends array [HUMAN_PLAYERS] unit lastClickUnit real lastClick endstruct private function onSelected takes nothing returns nothing local player p = GetTriggerPlayer() local PlayerData d = PlayerData[GetPlayerId(p ) ] local real now= TimerGetElapsed(T) local unit u = GetTriggerUnit() local integer i if (d.lastClick + WAIT_TIME >= now) and (d.lastClickUnit == u) then // double click!!11 set i=0 loop exitwhen (i==listeners) call listener[i].evaluate(p,u) set i=i+1 endloop set d.lastClick = -WAIT_TIME else set d.lastClick = now set d.lastClickUnit = u endif set p=null set u=null endfunction private function init takes nothing returns nothing local integer i=0 local trigger tr=CreateTrigger() loop exitwhen (i==HUMAN_PLAYERS) call TriggerRegisterPlayerUnitEvent(tr, Player(i), EVENT_PLAYER_UNIT_SELECTED, null) set PlayerData[i].lastClick = -WAIT_TIME set i=i+1 endloop call TriggerAddAction(tr, function onSelected) set T=CreateTimer() call TimerStart(T, EXAGGERATED_GAME_LENGTH, false, null) set tr=null endfunction endlibrary |
| 05-23-2009, 01:34 AM | #2 |
It's... weird. Can't you at least make it behave like a standard WC3 event? It feels odd to use, right now. >I can't think of a legit reason for so, but if you prove such need I can easily add a way for it. Well, it could be used with some dynamic triggers. Or triggers that or no longer needed. I don't really need the function to stay around, getting called on each double click, slowing the game down. >strange, overcomplicated, hacky It's what I do best. JASS:TimerGetElapsed(T) JASS:local player p = GetTriggerPlayer() local PlayerData d = PlayerData[GetPlayerId(p ) ] local real now= TimerGetElapsed(T) local unit u = GetTriggerUnit() local integer i |
| 05-23-2009, 03:25 AM | #3 | ||
Quote:
Quote:
Anyway, the TimerGetElapsed call would be more accurate if you used 36000 seconds (10 hours) instead of 1000000. Not that it matters much. |
| 05-23-2009, 03:38 AM | #4 | |
36000 is good for values like 0.02, for 1.00 even 1800000 would be all right, but I guess I could use 10 hours, even 10 hours is being unrealistic... Quote:
In reality, I cannot think of a way the map is actually going to use more than two of these events. |
| 06-07-2009, 02:41 PM | #5 |
I am approving this. Because I can and couldn't see anything wrong in it. |
| 06-08-2009, 05:33 PM | #6 | |
Quote:
Can you please not do this? We have enough proof in political history of mankind that such behaviour is bad practise and inevitably leads to corruption of the whole system. (in this case forum) We have enough competent coders here so there really is no need for you to do everyones job. And the last time I checked there was a mod who resigned for exactly the same behavior. The correct course of action would be to unapprove this resource for proper validation and give yourself -10 rep (because you also can do that can't you?) |
| 06-08-2009, 08:44 PM | #7 |
This comes directly from the submission rules: A moderator / administrator cannot approve his or her own resource. It must be reviewed and approved by another qualified staff member. |
| 06-08-2009, 09:50 PM | #8 |
Who cares? Honestly. |
| 06-08-2009, 10:03 PM | #9 | |
Quote:
|
| 06-08-2009, 10:22 PM | #10 | |
Quote:
In my case it would have been as easy to nod Anitarf in IRC and make him approve this thing... it is really just relative, if I did that nobody would have known and nobody would have complained but it is not really that much different. I like this resource, and when comparing with the other attempts it is really much better, and I can't think of a way it would be better. This is just a web forum... |
| 06-08-2009, 11:00 PM | #11 |
You will now refer to him as Vexorian Caesar! Seriously though, it's not that big of a deal. |
| 06-09-2009, 12:10 AM | #12 |
Vex is the only person on this entire website that can do that and not raise a red flag in my book. He's easily the most knowledgeable on topics such as these and truth be told, when he submits something, short of the naming convention for the functions, it is always quality and worthy of our database. If you'd prefer, I could just auto-approve anything Vex submits, but really, having it open to a bit of discussion beforehand is healthy. |
| 06-09-2009, 12:23 AM | #13 |
I would do that when the resource really matters. Though honestly, all the code mods even the past ones had my trust in that I wouldn't mind if they approved their things by themselves when they consider it convenient. |
| 06-09-2009, 06:31 AM | #14 | |||
Quote:
And what makes it worse is that it already happened with a mod before and you people don't seem to get it that this thing are related and lead to each other. So please play good buddies over the IRC as much as you like, but when it comes to public display follow the fucking rules. Quote:
Quote:
========================================== I still insist that this be unapproved and approved by someone else. http://en.wikipedia.org/wiki/Cronyism |
