Skip to content

Commit

Permalink
Added basic card hover listener
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorGester committed Jul 30, 2015
1 parent 0a17d85 commit 29c0074
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
45 changes: 45 additions & 0 deletions mmo-client/src/core/ui/deck/CardHoverListener.java
@@ -0,0 +1,45 @@
package core.ui.deck;

import com.jme3.scene.Spatial;
import com.simsilica.lemur.event.CursorButtonEvent;
import com.simsilica.lemur.event.CursorListener;
import com.simsilica.lemur.event.CursorMotionEvent;

/**
* @author doc
*/
public class CardHoverListener implements CursorListener {
private DeckElement deckElement;
private boolean isHovered = false;

public CardHoverListener(DeckElement deckElement) {
this.deckElement = deckElement;
}

@Override
public void cursorButtonEvent(CursorButtonEvent cursorButtonEvent, Spatial target, Spatial capture) {
}

@Override
public void cursorEntered(CursorMotionEvent cursorMotionEvent, Spatial target, Spatial capture) {
cursorMotionEvent.setConsumed();

isHovered = true;
}

@Override
public void cursorExited(CursorMotionEvent cursorMotionEvent, Spatial target, Spatial capture) {
cursorMotionEvent.setConsumed();

isHovered = false;
}

@Override
public void cursorMoved(CursorMotionEvent cursorMotionEvent, Spatial target, Spatial capture) {

}

public boolean isHovered() {
return isHovered;
}
}
21 changes: 21 additions & 0 deletions mmo-client/src/core/ui/deck/DeckControl.java
Expand Up @@ -10,6 +10,7 @@
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.control.CameraControl;
import com.simsilica.lemur.event.CursorEventControl;
import shared.items.Item;

import java.util.ArrayList;
Expand All @@ -24,6 +25,8 @@ public class DeckControl extends AbstractControl {
private List<DeckElement> deckCards = new ArrayList<DeckElement>();
private List<DeckElement> freeCards = new ArrayList<DeckElement>();

private boolean hoverEnabled = false;

private ControlPoint[] innerCurve = new ControlPoint[]{
new ControlPoint(new Vector3f(1.2f, 0, 2f), FastMath.PI),
new ControlPoint(new Vector3f(0.75f, 0, 1.5f), 0f),
Expand Down Expand Up @@ -100,6 +103,15 @@ public void spin(float value) {
card.setProgressTarget(card.getProgressTarget() + value);
}

public void enableElementHover(){
hoverEnabled = true;

for (DeckElement element: freeCards) {
element.registerHoverListener();
}
}


@Override
protected void controlUpdate(float tpf) {
int index = 0;
Expand Down Expand Up @@ -150,6 +162,9 @@ protected void controlUpdate(float tpf) {
addedCard.setProgressTarget(lastFreeCard.getProgressTarget() - space);

freeCards.add(addedCard);

if (hoverEnabled)
addedCard.registerHoverListener();
} else {
break;
}
Expand All @@ -160,6 +175,9 @@ protected void controlUpdate(float tpf) {
freeCards.remove(card);
deckCards.add(card);

if (hoverEnabled)
card.removeHoverListener();

card.setProgressCurrent(0.0f);
card.setProgressTarget(0.0f);
}
Expand All @@ -168,6 +186,9 @@ protected void controlUpdate(float tpf) {
freeCards.remove(card);
deckCards.add(0, card);

if (hoverEnabled)
card.removeHoverListener();

card.setProgressCurrent(0.0f);
card.setProgressTarget(0.0f);
}
Expand Down
21 changes: 21 additions & 0 deletions mmo-client/src/core/ui/deck/DeckElement.java
Expand Up @@ -2,6 +2,7 @@

import com.jme3.math.FastMath;
import com.jme3.scene.Spatial;
import com.simsilica.lemur.event.CursorEventControl;

/**
* @author doc
Expand All @@ -11,8 +12,11 @@ public class DeckElement {
private float progressCurrent;
private float progressTarget;
private float floatingStep;
private float hoverStep;
private int floatDirection = 1;

private CardHoverListener hoverListener;

public DeckElement(Spatial model) {
this.model = model;
floatingStep = FastMath.nextRandomFloat() * 2f - 1f;
Expand Down Expand Up @@ -42,6 +46,18 @@ public float getFloatingStep() {
return floatingStep;
}

public void registerHoverListener(){
hoverListener = new CardHoverListener(this);

CursorEventControl.addListenersToSpatial(model, hoverListener);
}

public void removeHoverListener(){
CursorEventControl.removeListenersFromSpatial(model, hoverListener);

hoverListener = null;
}

/**
*
* @return sign Movement direction
Expand All @@ -63,6 +79,11 @@ public float updateMovement(float speed){
floatDirection *= -1;
}

if (hoverListener != null) {
int direction = hoverListener.isHovered() ? 1 : -1;
hoverStep = FastMath.clamp(hoverStep + direction * speed, -1, 1);
}

return sign;
}
}
1 change: 1 addition & 0 deletions mmo-client/src/program/main/Cheats.java
Expand Up @@ -69,6 +69,7 @@ public void onAction(String name, boolean isPressed, float tpf) {
Node root = program.getMainFrame().getRootNode();
deckControl = new DeckControl(program.getMainFrame());
deckControl.setDeck(deck);
deckControl.enableElementHover();
root.addControl(deckControl);
}
}, "card_control");
Expand Down

0 comments on commit 29c0074

Please sign in to comment.