parent
fda6ca1a63
commit
f467c01c46
Before Width: | Height: | Size: 8.9 KiB After Width: | Height: | Size: 8.9 KiB |
Binary file not shown.
@ -0,0 +1,38 @@ |
||||
package mightypork.rogue.events; |
||||
|
||||
|
||||
import mightypork.gamecore.eventbus.BusEvent; |
||||
import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent; |
||||
import mightypork.rogue.screens.LoadingOverlay; |
||||
|
||||
|
||||
/** |
||||
* Request to execute a given task in a loading overlay |
||||
* |
||||
* @author MightyPork |
||||
*/ |
||||
@SingleReceiverEvent |
||||
public class LoadingOverlayRequest extends BusEvent<LoadingOverlay> { |
||||
|
||||
private final String msg; |
||||
private final Runnable task; |
||||
|
||||
|
||||
/** |
||||
* @param msg task description |
||||
* @param task task runnable |
||||
*/ |
||||
public LoadingOverlayRequest(String msg, Runnable task) |
||||
{ |
||||
this.task = task; |
||||
this.msg = msg; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void handleBy(LoadingOverlay handler) |
||||
{ |
||||
handler.show(msg, task); |
||||
} |
||||
|
||||
} |
@ -1,22 +0,0 @@ |
||||
package mightypork.rogue.screens; |
||||
|
||||
import mightypork.gamecore.eventbus.BusEvent; |
||||
|
||||
|
||||
public class LoaderRequest extends BusEvent<LoadingOverlay> { |
||||
|
||||
private final String msg; |
||||
private Runnable task; |
||||
|
||||
|
||||
public LoaderRequest(String msg, Runnable task) { |
||||
this.task = task; |
||||
this.msg = msg; |
||||
} |
||||
@Override |
||||
protected void handleBy(LoadingOverlay handler) |
||||
{ |
||||
handler.show(msg, task); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,71 @@ |
||||
package mightypork.rogue.screens; |
||||
|
||||
|
||||
import mightypork.gamecore.gui.AlignX; |
||||
import mightypork.gamecore.gui.components.ClickableComponent; |
||||
import mightypork.gamecore.gui.components.painters.TextPainter; |
||||
import mightypork.gamecore.input.InputSystem; |
||||
import mightypork.gamecore.resources.fonts.GLFont; |
||||
import mightypork.gamecore.util.math.color.Color; |
||||
import mightypork.gamecore.util.math.color.pal.RGB; |
||||
import mightypork.gamecore.util.math.constraints.vect.Vect; |
||||
import mightypork.gamecore.util.math.constraints.vect.mutable.VectVar; |
||||
|
||||
|
||||
/** |
||||
* Menu-like button with shadow and push state |
||||
* |
||||
* @author MightyPork |
||||
*/ |
||||
public class PushButton extends ClickableComponent { |
||||
|
||||
public final TextPainter textPainter; |
||||
|
||||
private final VectVar offset = Vect.makeVar(); |
||||
|
||||
public Vect offsetPassive = height().div(16).toVectXY(); |
||||
public Vect offsetOver = height().div(20).toVectXY(); |
||||
public Vect offsetUnder = height().div(32).toVectXY(); |
||||
|
||||
private final Color color; |
||||
|
||||
private boolean hoverMove = true; |
||||
|
||||
|
||||
public PushButton(GLFont font, String text, Color color) |
||||
{ |
||||
this.color = color; |
||||
|
||||
this.textPainter = new TextPainter(font, AlignX.CENTER, this.color, text); |
||||
this.textPainter.setRect(this); |
||||
this.textPainter.setShadow(RGB.BLACK_30, offset); |
||||
textPainter.setPaddingHPerc(0, 5); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void renderComponent() |
||||
{ |
||||
if (isMouseOver()) { |
||||
if (InputSystem.isMouseButtonDown(0)) { |
||||
offset.setTo(offsetUnder); |
||||
} else { |
||||
offset.setTo(hoverMove ? offsetOver : offsetPassive); |
||||
} |
||||
} else { |
||||
offset.setTo(offsetPassive); |
||||
} |
||||
|
||||
textPainter.render(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Disable offset change on hover |
||||
*/ |
||||
public void disableHover() |
||||
{ |
||||
hoverMove = false; |
||||
} |
||||
|
||||
} |
@ -1,56 +0,0 @@ |
||||
package mightypork.rogue.screens.menu; |
||||
|
||||
|
||||
import mightypork.gamecore.gui.AlignX; |
||||
import mightypork.gamecore.gui.components.ClickableComponent; |
||||
import mightypork.gamecore.gui.components.painters.TextPainter; |
||||
import mightypork.gamecore.input.InputSystem; |
||||
import mightypork.gamecore.resources.fonts.GLFont; |
||||
import mightypork.gamecore.util.math.color.Color; |
||||
import mightypork.gamecore.util.math.color.pal.RGB; |
||||
import mightypork.gamecore.util.math.constraints.vect.Vect; |
||||
import mightypork.gamecore.util.math.constraints.vect.mutable.VectVar; |
||||
import mightypork.rogue.Res; |
||||
|
||||
|
||||
class MenuButton extends ClickableComponent { |
||||
|
||||
private static GLFont font = Res.getFont("thick"); |
||||
private final TextPainter painter; |
||||
|
||||
private final VectVar offset = Vect.makeVar(); |
||||
private final Vect offsetPassive = height().div(16).toVectXY(); |
||||
private final Vect offsetPassive2 = height().div(20).toVectXY(); |
||||
private final Vect offsetUnder = height().div(32).toVectXY(); |
||||
|
||||
private final Color color; |
||||
|
||||
|
||||
public MenuButton(String text, Color color) |
||||
{ |
||||
this.color = color; |
||||
|
||||
this.painter = new TextPainter(font, AlignX.CENTER, this.color, text); |
||||
this.painter.setRect(this); |
||||
this.painter.setShadow(RGB.BLACK_30, offset); |
||||
painter.setPaddingHPerc(0, 5); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void renderComponent() |
||||
{ |
||||
if (isMouseOver()) { |
||||
if (InputSystem.isMouseButtonDown(0)) { |
||||
offset.setTo(offsetUnder); |
||||
} else { |
||||
offset.setTo(offsetPassive2); |
||||
} |
||||
} else { |
||||
offset.setTo(offsetPassive); |
||||
} |
||||
|
||||
painter.render(); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue