You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.2 KiB
90 lines
2.2 KiB
10 years ago
|
package mightypork.rogue.screens.game;
|
||
10 years ago
|
|
||
|
|
||
10 years ago
|
import mightypork.gamecore.eventbus.events.Updateable;
|
||
10 years ago
|
import mightypork.gamecore.gui.components.ClickableComponent;
|
||
10 years ago
|
import mightypork.gamecore.input.events.MouseMotionEvent;
|
||
|
import mightypork.gamecore.input.events.MouseMotionListener;
|
||
10 years ago
|
import mightypork.gamecore.render.Render;
|
||
10 years ago
|
import mightypork.gamecore.resources.textures.TxQuad;
|
||
|
import mightypork.gamecore.util.math.Easing;
|
||
|
import mightypork.gamecore.util.math.constraints.num.Num;
|
||
|
import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated;
|
||
|
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
||
|
import mightypork.gamecore.util.math.constraints.rect.caching.RectCache;
|
||
|
import mightypork.gamecore.util.math.constraints.vect.Vect;
|
||
10 years ago
|
import mightypork.rogue.Res;
|
||
|
|
||
|
|
||
10 years ago
|
public class NavItemSlot extends ClickableComponent implements MouseMotionListener, Updateable {
|
||
10 years ago
|
|
||
10 years ago
|
private final TxQuad image;
|
||
|
private final TxQuad frame;
|
||
|
private final RectCache paintBox;
|
||
|
private final NumAnimated yOffset;
|
||
10 years ago
|
private boolean wasInside = false;
|
||
|
|
||
|
|
||
10 years ago
|
public NavItemSlot(TxQuad image)
|
||
|
{
|
||
10 years ago
|
this.image = image;
|
||
|
this.frame = Res.getTxQuad("item_frame");
|
||
|
|
||
10 years ago
|
final Rect ref = shrink(height().perc(8));
|
||
10 years ago
|
yOffset = new NumAnimated(0, Easing.LINEAR);
|
||
|
yOffset.setDefaultDuration(0.05);
|
||
|
|
||
10 years ago
|
final Num h = ref.width().min(ref.height());
|
||
10 years ago
|
this.paintBox = ref.bottomLeft().startRect().grow(Num.ZERO, h, h, Num.ZERO).moveY(yOffset.mul(h.perc(-5))).cached();
|
||
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
protected void renderComponent()
|
||
|
{
|
||
|
Render.quadTextured(paintBox, frame);
|
||
|
|
||
|
Render.pushMatrix();
|
||
|
Render.translateXY(paintBox.center());
|
||
|
Render.scaleXY(0.7);
|
||
|
Render.rotateZ(45);
|
||
|
Render.quadTextured(Rect.make(paintBox.height()).centerTo(Vect.ZERO), image);
|
||
|
Render.popMatrix();
|
||
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public void updateLayout()
|
||
|
{
|
||
|
paintBox.poll();
|
||
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public void receive(MouseMotionEvent event)
|
||
10 years ago
|
{
|
||
10 years ago
|
if (event.getPos().isInside(this) != wasInside) {
|
||
|
if (wasInside) {
|
||
|
// left
|
||
|
yOffset.fadeOut();
|
||
|
} else {
|
||
|
// entered
|
||
|
yOffset.fadeIn();
|
||
|
}
|
||
|
|
||
|
wasInside = !wasInside;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public void update(double delta)
|
||
|
{
|
||
|
if (yOffset.isInProgress()) {
|
||
|
yOffset.update(delta);
|
||
|
paintBox.poll();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|