• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] [Wurst] Issues creating my first package (Mouse Event)

Status
Not open for further replies.
Level 6
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)

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)
Every help is welcome.
Thank you in advance.
 
Level 2
Joined
Dec 16, 2011
Messages
12
Looks like you didn't create an instance of MouseEvent. You're trying to use onBegin() like its a static function.

Probably what you want to do:
Code:
init
    MouseEvent mouseEvent = new MouseEvent()
    mouseEvent.onBegin()
 
Level 5
Joined
Mar 5, 2015
Messages
135
Another way to write it could also be like this:

Code:
new MouseEvent().onBegin()

... As the variable is redundant ;)

And btw, really cool idea ;)
 
Status
Not open for further replies.
Top