- Joined
- Aug 28, 2015
- Messages
- 213
Hey Hivers,
after couple of days writing on this system and reading references manuals and more I still can't get my head around this.
I try to create a mouse event package that handles the newly added mouse events in a much easier way
due to this I created two packages but I get stuck somehow to get it running.
The main issue is that I don't understand the language enough and the way to imagine its processing.
The Idea is to have a system that can track
Button Click& Release Left/Right Multi clicks(double click, triple clicks...) Fires actions associated to each event and
Mouse Move saves the mouse position so it can be always looked up
and Drag Saves a 'path' array of mouse positions
(I also want to use it later for ray casting but this later when I get actually to something)
Every help is welcome.
Thank you in advance.
after couple of days writing on this system and reading references manuals and more I still can't get my head around this.
I try to create a mouse event package that handles the newly added mouse events in a much easier way
due to this I created two packages but I get stuck somehow to get it running.
The main issue is that I don't understand the language enough and the way to imagine its processing.
The Idea is to have a system that can track
Button Click& Release Left/Right Multi clicks(double click, triple clicks...) Fires actions associated to each event and
Mouse Move saves the mouse position so it can be always looked up
and Drag Saves a 'path' array of mouse positions
(I also want to use it later for ray casting but this later when I get actually to something)
JASS:
package MouseUtils
import ClosureEvents
public tuple mouseTuple(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
function onMouseEvent()
var mouseStatus = mouseStatuses[GetTriggerPlayer().getId()]
let id = GetTriggerEventId()
let mb = BlzGetTriggerPlayerMouseButton()
if id == EVENT_PLAYER_MOUSE_DOWN
if mb == MOUSE_BUTTON_TYPE_LEFT
mouseStatus.left = true
else if mb == MOUSE_BUTTON_TYPE_RIGHT
mouseStatus.right = true
else if mb == MOUSE_BUTTON_TYPE_MIDDLE
mouseStatus.middle = true
else if id == EVENT_PLAYER_MOUSE_UP
if mb == MOUSE_BUTTON_TYPE_LEFT
mouseStatus.left = false
else if mb == MOUSE_BUTTON_TYPE_RIGHT
mouseStatus.right = false
else if mb == MOUSE_BUTTON_TYPE_MIDDLE
mouseStatus.middle = false
else if id == EVENT_PLAYER_MOUSE_MOVE
mouseStatus.move = true
mouseStatus.mousePosition = vec2(BlzGetTriggerPlayerMouseX(),BlzGetTriggerPlayerMouseY())
mouseStatuses[GetTriggerPlayer().getId()] = mouseStatus
var listener = firstKeyListener
while listener != null
listener.onEvent()
listener = listener.next
init
for i = 0 to 23
mouseStatuses[i] = mouseTuple(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())
JASS:
package inputTest
import MouseUtils
import FxEntity
public class MouseEvent
EventListener klistener
function onBegin()
klistener = addMouseListener() ->
foo()
function onEnd()
if klistener != null
removeMouseListener(klistener)
function foo()
let downButtons = GetTriggerPlayer().getMouseButtons()
if downButtons.left
print("Left")
//left button is pressed
if downButtons.right
//right button is pressed
print("Right")
init
MouseEvent.onBegin() //<== Error "Cannot call dynamic function onBegin from static context (undefined)
Thank you in advance.