- Joined
- Aug 28, 2015
- Messages
- 213
Hey working on this system for a while and got to a point I'm starting to like it,
now I would also to like to add the function to create a line(vec2 array + Player Id) that follows your mouse cursor when a button is pressed and will be returned on the release and can be destroyed after it is used in another function.
This is what I had in mind: vec2 array dragLine, mouseButtonType wichButtonPressed, integer playerId
I thought about something that periodically checks the distance between the last coordination of the last added point in the array and the current mouse position.
If it is over a buffer range a new point with the position of the mouse cursor will be added and used as the reference point.
This is my package atm. I will split it in two different ones to make it easier to use but wanted to have something before I start polishing.
now I would also to like to add the function to create a line(vec2 array + Player Id) that follows your mouse cursor when a button is pressed and will be returned on the release and can be destroyed after it is used in another function.
This is what I had in mind: vec2 array dragLine, mouseButtonType wichButtonPressed, integer playerId
I thought about something that periodically checks the distance between the last coordination of the last added point in the array and the current mouse position.
If it is over a buffer range a new point with the position of the mouse cursor will be added and used as the reference point.
This is my package atm. I will split it in two different ones to make it easier to use but wanted to have something before I start polishing.
JASS:
package MouseUtils
import ClosureEvents
import ClosureTimers
/*
add drag line vec2 2darray
seperate in two different packages
*/
enum MouseCurrentEvent
MOUSE_PRESED_LEFT
MOUSE_RELEASED_LEFT
MOUSE_PRESED_RIGHT
MOUSE_RELEASED_RIGHT
MOUSE_PRESED_MIDDLE
MOUSE_RELEASED_MIDDLE
MOUSE_MOVED
MOUSE_STOPPED
public timer array mouseTimerLeft
public timer array mouseTimerRight
public timer array mouseTimerMiddle
public timer array mouseTimerMove
public integer array mouseClickCounterLeft
public integer array mouseClickCounterRight
public integer array mouseClickCounterMiddle
public tuple mouseTuple(MouseCurrentEvent currentEvent, boolean left, boolean right, boolean middle, boolean move, vec2 mousePosition)
mouseTuple array mouseStatuses
public function player.getMouseButtons() returns mouseTuple
return mouseStatuses[this.getId()]
EventListener firstKeyListener = null
public function addMouseListener(EventListener listener) returns EventListener
if firstKeyListener != null
firstKeyListener.prev = listener
listener.next = firstKeyListener
firstKeyListener = listener
return listener
public function removeMouseListener(EventListener listener)
if firstKeyListener == listener
firstKeyListener = null
destroy listener
public function setClickCounter(mousebuttontype mb, integer playerId, integer count)
if mb == MOUSE_BUTTON_TYPE_LEFT
mouseClickCounterLeft[playerId] = count
else if mb == MOUSE_BUTTON_TYPE_RIGHT
mouseClickCounterRight[playerId] = count
else if mb == MOUSE_BUTTON_TYPE_MIDDLE
mouseClickCounterMiddle[playerId] = count
public function getClickCounter(mousebuttontype mb, integer playerId) returns int
if mb == MOUSE_BUTTON_TYPE_LEFT
return mouseClickCounterLeft[playerId]
else if mb == MOUSE_BUTTON_TYPE_RIGHT
return mouseClickCounterRight[playerId]
else if mb == MOUSE_BUTTON_TYPE_MIDDLE
return mouseClickCounterMiddle[playerId]
return 0
public function resetClickCounter(mousebuttontype mb, integer playerId)
if mb == MOUSE_BUTTON_TYPE_LEFT
mouseClickCounterLeft[playerId] = 0
else if mb == MOUSE_BUTTON_TYPE_RIGHT
mouseClickCounterRight[playerId] = 0
else if mb == MOUSE_BUTTON_TYPE_MIDDLE
mouseClickCounterMiddle[playerId] = 0
function onMouseStopMove(integer playerId)
mouseStatuses[playerId].move = false
mouseStatuses[playerId].currentEvent = MOUSE_STOPPED
function onMouseEvent()
let playerId = GetTriggerPlayer().getId()
var mouseStatus = mouseStatuses[playerId]
let resetTime = 1.00 / 30
let id = GetTriggerEventId()
let mb = BlzGetTriggerPlayerMouseButton()
if id == EVENT_PLAYER_MOUSE_DOWN
if mb == MOUSE_BUTTON_TYPE_LEFT
mouseStatus.left = true
mouseStatus.currentEvent = MOUSE_PRESED_LEFT
else if mb == MOUSE_BUTTON_TYPE_RIGHT
mouseStatus.right = true
mouseStatus.currentEvent = MOUSE_PRESED_RIGHT
else if mb == MOUSE_BUTTON_TYPE_MIDDLE
mouseStatus.middle = true
mouseStatus.currentEvent = MOUSE_PRESED_MIDDLE
setClickCounter(mb, playerId, getClickCounter(mb, playerId) + 1)
else if id == EVENT_PLAYER_MOUSE_UP
// reset timer that sets the multible click counter to 0 after resetTime
timer resetTimer = null
if mb == MOUSE_BUTTON_TYPE_LEFT
mouseStatus.left = false
mouseStatus.currentEvent = MOUSE_RELEASED_LEFT
resetTimer = mouseTimerLeft[playerId]
else if mb == MOUSE_BUTTON_TYPE_RIGHT
mouseStatus.right = false
mouseStatus.currentEvent = MOUSE_RELEASED_RIGHT
resetTimer = mouseTimerRight[playerId]
else if mb == MOUSE_BUTTON_TYPE_MIDDLE
mouseStatus.middle = false
mouseStatus.currentEvent = MOUSE_RELEASED_MIDDLE
resetTimer = mouseTimerMiddle[playerId]
resetTimer.doAfter(resetTime) ->
resetClickCounter(mb, playerId)
else if id == EVENT_PLAYER_MOUSE_MOVE
mouseStatus.move = true
mouseStatus.currentEvent = MOUSE_MOVED
mouseTimerMove[playerId].doAfter(resetTime) ->
onMouseStopMove(playerId)
mouseStatus.mousePosition = vec2(BlzGetTriggerPlayerMouseX(),BlzGetTriggerPlayerMouseY())
mouseStatuses[playerId] = mouseStatus
var listener = firstKeyListener
while listener != null
listener.onEvent()
listener = listener.next
init
for i = 0 to 23
mouseStatuses[i] = mouseTuple(MouseCurrentEvent.MOUSE_STOPPED, false, false, false, false, vec2(0., 0.))
EventListener.add(EVENT_PLAYER_MOUSE_DOWN, () -> onMouseEvent())
EventListener.add(EVENT_PLAYER_MOUSE_UP, () -> onMouseEvent())
EventListener.add(EVENT_PLAYER_MOUSE_MOVE, () -> onMouseEvent())