parent
56494e04f9
commit
b2cf0d14a0
After Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 320 KiB |
Binary file not shown.
@ -0,0 +1,77 @@ |
||||
package mightypork.rogue.screens; |
||||
|
||||
|
||||
import mightypork.gamecore.control.AppAccess; |
||||
import mightypork.gamecore.control.events.ScreenRequestEvent; |
||||
import mightypork.gamecore.gui.components.painters.QuadPainter; |
||||
import mightypork.gamecore.gui.screens.Overlay; |
||||
import mightypork.util.constraints.num.mutable.NumAnimated; |
||||
import mightypork.util.control.timing.TimedTask; |
||||
import mightypork.util.math.Easing; |
||||
import mightypork.util.math.color.Color; |
||||
|
||||
|
||||
public class CrossfadeOverlay extends Overlay implements CrossfadeRequest.Listener { |
||||
|
||||
private static final double T_IN = 0.5; |
||||
private static final double T_OUT = 0.7; |
||||
|
||||
NumAnimated level = new NumAnimated(0); |
||||
|
||||
Color color = Color.dark(level); |
||||
String requestedScreenName; |
||||
|
||||
TimedTask tt = new TimedTask() { |
||||
|
||||
@Override |
||||
public void run() |
||||
{ |
||||
if(requestedScreenName == null) shutdown(); |
||||
getEventBus().send(new ScreenRequestEvent(requestedScreenName)); |
||||
} |
||||
}; |
||||
|
||||
TimedTask tt2 = new TimedTask() { |
||||
|
||||
@Override |
||||
public void run() |
||||
{ |
||||
level.setEasing(Easing.SINE_OUT); |
||||
level.fadeOut(T_OUT); |
||||
} |
||||
}; |
||||
|
||||
|
||||
public CrossfadeOverlay(AppAccess app) { |
||||
super(app); |
||||
|
||||
QuadPainter qp = new QuadPainter(color); |
||||
qp.setRect(root); |
||||
root.add(qp); |
||||
|
||||
updated.add(level); |
||||
updated.add(tt); |
||||
updated.add(tt2); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public int getPriority() |
||||
{ |
||||
return Integer.MAX_VALUE - 1; // let FPS go on top
|
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void goToScreen(String screen) |
||||
{ |
||||
tt.start(T_IN); |
||||
tt2.start(T_IN); |
||||
|
||||
level.setEasing(Easing.SINE_IN); |
||||
level.fadeIn(T_IN); |
||||
|
||||
requestedScreenName = screen; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,35 @@ |
||||
package mightypork.rogue.screens; |
||||
|
||||
|
||||
import mightypork.util.control.eventbus.events.Event; |
||||
|
||||
|
||||
/** |
||||
* @author MightyPork |
||||
*/ |
||||
public class CrossfadeRequest implements Event<CrossfadeRequest.Listener> { |
||||
|
||||
private String screen; |
||||
|
||||
|
||||
/** |
||||
* @param screen screen key to show. Null = exit the app. |
||||
*/ |
||||
public CrossfadeRequest(String screen) { |
||||
super(); |
||||
this.screen = screen; |
||||
} |
||||
|
||||
public interface Listener { |
||||
|
||||
void goToScreen(String screen); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void handleBy(Listener handler) |
||||
{ |
||||
handler.goToScreen(screen); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,62 @@ |
||||
package mightypork.rogue.screens.ingame; |
||||
|
||||
|
||||
import mightypork.gamecore.gui.AlignX; |
||||
import mightypork.gamecore.gui.components.Component; |
||||
import mightypork.gamecore.gui.components.layout.HorizontalFixedFlowLayout; |
||||
import mightypork.gamecore.gui.components.painters.ImagePainter; |
||||
import mightypork.gamecore.gui.components.painters.QuadPainter; |
||||
import mightypork.gamecore.gui.screens.Screen; |
||||
import mightypork.gamecore.gui.screens.ScreenLayer; |
||||
import mightypork.rogue.Res; |
||||
import mightypork.util.constraints.num.Num; |
||||
import mightypork.util.constraints.rect.Rect; |
||||
import mightypork.util.math.color.PAL16; |
||||
|
||||
|
||||
public class GameGui extends ScreenLayer { |
||||
|
||||
public GameGui(Screen screen) { |
||||
super(screen); |
||||
|
||||
Num h = root.height(); |
||||
Num w = root.width(); |
||||
Num minWH = w.min(h).max(700); // avoid too small shrinking
|
||||
|
||||
Component qp = new QuadPainter(PAL16.VOID); |
||||
qp.setRect(root); |
||||
root.add(qp); |
||||
|
||||
ImagePainter nav = new ImagePainter(Res.getTxQuad("panel")); |
||||
nav.setRect(root.bottomEdge().growUp(minWH.perc(7))); |
||||
root.add(nav); |
||||
|
||||
HorizontalFixedFlowLayout itemSlots = new HorizontalFixedFlowLayout(root, nav.height().mul(1.8), AlignX.LEFT); |
||||
itemSlots.setRect(nav.growUp(nav.height()).move(nav.height().mul(0.2), nav.height().mul(-0.2))); |
||||
root.add(itemSlots); |
||||
|
||||
itemSlots.add(new NavItemSlot(Res.getTxQuad("meat"))); |
||||
itemSlots.add(new NavItemSlot(Res.getTxQuad("sword"))); |
||||
|
||||
Rect shrunk = root.shrink(minWH.perc(3)); |
||||
Num displays_height = minWH.perc(6); |
||||
|
||||
HeartBar hearts = new HeartBar(6, 3, Res.getTxQuad("heart_on"), Res.getTxQuad("heart_off"), AlignX.LEFT); |
||||
Rect hearts_box = shrunk.topLeft().startRect().growDown(displays_height); |
||||
hearts.setRect(hearts_box); |
||||
root.add(hearts); |
||||
|
||||
HeartBar experience = new HeartBar(6, 2, Res.getTxQuad("xp_on"), Res.getTxQuad("xp_off"), AlignX.RIGHT); |
||||
Rect xp_box = shrunk.topRight().startRect().growDown(displays_height); |
||||
experience.setRect(xp_box); |
||||
root.add(experience); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public int getPriority() |
||||
{ |
||||
return 100; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,66 @@ |
||||
package mightypork.rogue.screens.ingame; |
||||
|
||||
|
||||
import mightypork.gamecore.gui.AlignX; |
||||
import mightypork.gamecore.gui.components.VisualComponent; |
||||
import mightypork.gamecore.render.Render; |
||||
import mightypork.gamecore.render.textures.TxQuad; |
||||
import mightypork.util.constraints.num.Num; |
||||
import mightypork.util.constraints.num.mutable.NumVar; |
||||
import mightypork.util.constraints.rect.Rect; |
||||
|
||||
|
||||
public class HeartBar extends VisualComponent { |
||||
|
||||
private TxQuad img_on; |
||||
private TxQuad img_off; |
||||
private int total; |
||||
private int active; |
||||
|
||||
NumVar index = new NumVar(0); |
||||
Rect heart; |
||||
|
||||
|
||||
/** |
||||
* @param total |
||||
* @param active |
||||
* @param img_on |
||||
* @param img_off |
||||
* @param align |
||||
*/ |
||||
public HeartBar(int total, int active, TxQuad img_on, TxQuad img_off, AlignX align) { |
||||
super(); |
||||
this.total = total; |
||||
this.active = active; |
||||
this.img_on = img_on; |
||||
this.img_off = img_off; |
||||
|
||||
Num h = height(); |
||||
Num w = width(); |
||||
|
||||
switch (align) { |
||||
case LEFT: |
||||
heart = leftEdge().growRight(h).moveX(index.mul(h)); |
||||
break; |
||||
case RIGHT: |
||||
heart = rightEdge().growLeft(h).moveX(h.mul(-total+1).add(index.mul(h))); |
||||
break; |
||||
case CENTER: |
||||
heart = leftEdge().moveX(w.half().add(h.mul(-total/2D))).growRight(h).moveX(index.mul(h)); |
||||
break; |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void renderComponent() |
||||
{ |
||||
for (int i = 0; i < total; i++) { |
||||
index.setTo(i); |
||||
|
||||
Render.quadTextured(heart, (i < active ? img_on : img_off)); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,88 @@ |
||||
package mightypork.rogue.screens.ingame; |
||||
|
||||
|
||||
import mightypork.gamecore.gui.components.ClickableComponent; |
||||
import mightypork.gamecore.gui.components.InputComponent; |
||||
import mightypork.gamecore.render.Render; |
||||
import mightypork.gamecore.render.textures.TxQuad; |
||||
import mightypork.rogue.Res; |
||||
import mightypork.util.constraints.num.Num; |
||||
import mightypork.util.constraints.num.mutable.NumAnimated; |
||||
import mightypork.util.constraints.rect.Rect; |
||||
import mightypork.util.constraints.rect.caching.RectCache; |
||||
import mightypork.util.constraints.vect.Vect; |
||||
import mightypork.util.control.timing.Updateable; |
||||
import mightypork.util.math.Easing; |
||||
import mightypork.gamecore.control.events.MouseMotionEvent; |
||||
|
||||
|
||||
public class NavItemSlot extends ClickableComponent implements MouseMotionEvent.Listener, Updateable { |
||||
|
||||
private TxQuad image; |
||||
private TxQuad frame; |
||||
private RectCache paintBox; |
||||
private NumAnimated yOffset; |
||||
private boolean wasInside = false; |
||||
|
||||
|
||||
public NavItemSlot(TxQuad image) { |
||||
this.image = image; |
||||
this.frame = Res.getTxQuad("item_frame"); |
||||
|
||||
Rect ref = shrink(height().perc(8)); |
||||
yOffset = new NumAnimated(0, Easing.LINEAR); |
||||
yOffset.setDefaultDuration(0.05); |
||||
|
||||
Num h = ref.width().min(ref.height()); |
||||
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) |
||||
{ |
||||
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(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,21 @@ |
||||
package mightypork.rogue.screens.ingame; |
||||
|
||||
import mightypork.gamecore.control.AppAccess; |
||||
import mightypork.gamecore.gui.screens.LayeredScreen; |
||||
|
||||
|
||||
public class ScreenGame extends LayeredScreen { |
||||
|
||||
public ScreenGame(AppAccess app) { |
||||
super(app); |
||||
|
||||
addLayer(new GameGui(this)); |
||||
} |
||||
|
||||
@Override |
||||
public String getName() |
||||
{ |
||||
return "game_screen"; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,34 @@ |
||||
package mightypork.util.control.timing; |
||||
|
||||
import mightypork.util.constraints.num.mutable.NumAnimated; |
||||
|
||||
|
||||
public abstract class TimedTask implements Runnable, Updateable { |
||||
|
||||
private NumAnimated timer = new NumAnimated(0); |
||||
private boolean running = false; |
||||
|
||||
@Override |
||||
public void update(double delta) |
||||
{ |
||||
if(running) { |
||||
timer.update(delta); |
||||
if(timer.isFinished()) { |
||||
running = false; |
||||
run(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void start(double seconds) { |
||||
timer.reset(); |
||||
timer.animate(1, seconds); |
||||
running = true; |
||||
} |
||||
|
||||
public void stop() { |
||||
running = false; |
||||
timer.reset(); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue