package net.mostlyoriginal.game.system.interaction;

import com.artemis.Aspect;
import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.annotations.Wire;
import com.artemis.managers.TagManager;
import com.artemis.systems.EntityProcessingSystem;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import net.mostlyoriginal.api.component.basic.Bounds;
import net.mostlyoriginal.api.system.physics.CollisionSystem;
import net.mostlyoriginal.game.component.ui.Clickable;

/**
 * Track mouse over clickables. will indicate hover or clicked.
 *
 * @author Daan van Yperen
 */
@Wire
public class MouseClickSystem extends EntityProcessingSystem {

    CollisionSystem system;
    TagManager tagManager;

    protected ComponentMapper<Clickable> mClickable;
    private boolean leftMousePressed;
    private boolean rightMousePressed;

    public MouseClickSystem() {
        super(Aspect.getAspectForAll(Clickable.class, Bounds.class));
    }

    @Override
    protected void begin() {
        super.begin();

        leftMousePressed = Gdx.input.isButtonPressed(Input.Buttons.LEFT);
        rightMousePressed = Gdx.input.isButtonPressed(Input.Buttons.RIGHT);
    }

    @Override
    protected void process(Entity e) {
        final Entity cursor = tagManager.getEntity("cursor");
        if ( cursor != null )
        {
            // update state based on cursor.
            final Clickable clickable = mClickable.get(e);
            final boolean overlapping = system.overlaps(cursor, e);
            if ( overlapping )
            {
                clickable.state =
                        rightMousePressed ? Clickable.ClickState.CLICKED_RIGHT :
                        leftMousePressed ?  Clickable.ClickState.CLICKED_LEFT : Clickable.ClickState.HOVER;
            } else {
                clickable.state = Clickable.ClickState.NONE;
            }
        }
    }
}

@@ -802,29 +802,28 @@
 an leftMouse
-Press
+Tapp
 ed;%0A    priv
@@ -844,23 +844,97 @@
 ghtMouse
-Pressed
+Tapped;%0A    private boolean leftAlreadyDown;%0A    private boolean rightAlreadyDown
 ;%0A%0A    p
@@ -1117,29 +1117,28 @@
    leftMouse
-Press
+Tapp
 ed = Gdx.inp
@@ -1179,82 +1179,339 @@
 EFT)
-;%0A        rightMousePressed = Gdx.input.isButtonPressed(Input.Buttons.RIGH
+ && !leftAlreadyDown;%0A        rightMouseTapped = Gdx.input.isButtonPressed(Input.Buttons.RIGHT) && !rightAlreadyDown;%0A    %7D%0A%0A    @Override%0A    protected void end() %7B%0A        super.end();%0A%0A        leftAlreadyDown = Gdx.input.isButtonPressed(Input.Buttons.LEFT);%0A        rightAlreadyDown = Gdx.input.isButtonPressed(Input.Buttons.LEF
 T);%0A
@@ -1953,29 +1953,28 @@
   rightMouse
-Press
+Tapp
 ed ? Clickab
@@ -2036,21 +2036,20 @@
 eftMouse
-Press
+Tapp
 ed ?  Cl

Fix clicking system from triggering on held mouse.