mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-13 09:17:28 +07:00
More logic message types
This commit is contained in:
@ -1709,7 +1709,7 @@ lst.setblock = Set tile data at any location.
|
|||||||
lst.spawnunit = Spawn unit at a location.
|
lst.spawnunit = Spawn unit at a location.
|
||||||
lst.packcolor = Pack [0, 1] RGBA components into a single number for drawing or rule-setting.
|
lst.packcolor = Pack [0, 1] RGBA components into a single number for drawing or rule-setting.
|
||||||
lst.setrule = Set a game rule.
|
lst.setrule = Set a game rule.
|
||||||
lst.flushnotification = Display a notification at the top of the screen from the text buffer.\nWill wait until the previous message finishes.
|
lst.flushmessage = Display a message on the screen from the text buffer.\nWill wait until the previous message finishes.
|
||||||
|
|
||||||
logic.nounitbuild = [red]Unit building logic is not allowed here.
|
logic.nounitbuild = [red]Unit building logic is not allowed here.
|
||||||
|
|
||||||
|
@ -75,6 +75,8 @@ public class UI implements ApplicationListener, Loadable{
|
|||||||
|
|
||||||
public Cursor drillCursor, unloadCursor;
|
public Cursor drillCursor, unloadCursor;
|
||||||
|
|
||||||
|
private @Nullable Element lastAnnouncement;
|
||||||
|
|
||||||
public UI(){
|
public UI(){
|
||||||
Fonts.loadFonts();
|
Fonts.loadFonts();
|
||||||
}
|
}
|
||||||
@ -323,9 +325,9 @@ public class UI implements ApplicationListener, Loadable{
|
|||||||
table.actions(Actions.delay(duration * 0.9f), Actions.fadeOut(duration * 0.1f, Interp.fade), Actions.remove());
|
table.actions(Actions.delay(duration * 0.9f), Actions.fadeOut(duration * 0.1f, Interp.fade), Actions.remove());
|
||||||
table.top().table(Styles.black3, t -> t.margin(4).add(info).style(Styles.outlineLabel)).padTop(10);
|
table.top().table(Styles.black3, t -> t.margin(4).add(info).style(Styles.outlineLabel)).padTop(10);
|
||||||
Core.scene.add(table);
|
Core.scene.add(table);
|
||||||
|
lastAnnouncement = table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Shows a label at some position on the screen. Does not fade. */
|
/** Shows a label at some position on the screen. Does not fade. */
|
||||||
public void showInfoPopup(String info, float duration, int align, int top, int left, int bottom, int right){
|
public void showInfoPopup(String info, float duration, int align, int top, int left, int bottom, int right){
|
||||||
Table table = new Table();
|
Table table = new Table();
|
||||||
@ -516,6 +518,10 @@ public class UI implements ApplicationListener, Loadable{
|
|||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasAnnouncement(){
|
||||||
|
return lastAnnouncement != null && lastAnnouncement.parent != null;
|
||||||
|
}
|
||||||
|
|
||||||
/** Display text in the middle of the screen, then fade out. */
|
/** Display text in the middle of the screen, then fade out. */
|
||||||
public void announce(String text){
|
public void announce(String text){
|
||||||
announce(text, 3);
|
announce(text, 3);
|
||||||
@ -531,6 +537,7 @@ public class UI implements ApplicationListener, Loadable{
|
|||||||
t.pack();
|
t.pack();
|
||||||
t.act(0.1f);
|
t.act(0.1f);
|
||||||
Core.scene.add(t);
|
Core.scene.add(t);
|
||||||
|
lastAnnouncement = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showOkText(String title, String text, Runnable confirmed){
|
public void showOkText(String title, String text, Runnable confirmed){
|
||||||
|
@ -1288,17 +1288,39 @@ public class LExecutor{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class FlushNotificationI implements LInstruction{
|
public static class FlushMessageI implements LInstruction{
|
||||||
|
public MessageType type = MessageType.announce;
|
||||||
|
public int duration;
|
||||||
|
|
||||||
|
public FlushMessageI(MessageType type, int duration){
|
||||||
|
this.type = type;
|
||||||
|
this.duration = duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FlushMessageI(){
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(LExecutor exec){
|
public void run(LExecutor exec){
|
||||||
|
if(headless) return;
|
||||||
|
|
||||||
//skip back to self until possible
|
//skip back to self until possible
|
||||||
if(ui.hudfrag.hasToast()){
|
if(
|
||||||
|
type == MessageType.announce && ui.hudfrag.hasToast() ||
|
||||||
|
type == MessageType.notify && ui.hasAnnouncement() ||
|
||||||
|
type == MessageType.toast && ui.hasAnnouncement()
|
||||||
|
){
|
||||||
exec.var(varCounter).numval --;
|
exec.var(varCounter).numval --;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.hudfrag.showToast(Icon.info, exec.textBuffer.toString());
|
String text = exec.textBuffer.toString();
|
||||||
|
switch(type){
|
||||||
|
case notify -> ui.hudfrag.showToast(Icon.info, text);
|
||||||
|
case announce -> ui.announce(text, exec.numf(duration));
|
||||||
|
case toast -> ui.showInfoToast(text, exec.numf(duration));
|
||||||
|
}
|
||||||
|
|
||||||
exec.textBuffer.setLength(0);
|
exec.textBuffer.setLength(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1272,11 +1272,34 @@ public class LStatements{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RegisterStatement("notification")
|
@RegisterStatement("message")
|
||||||
public static class FlushNotificationStatement extends LStatement{
|
public static class FlushMessageStatement extends LStatement{
|
||||||
|
public MessageType type = MessageType.announce;
|
||||||
|
public String duration = "3";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build(Table table){
|
public void build(Table table){
|
||||||
|
rebuild(table);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rebuild(Table table){
|
||||||
|
table.clearChildren();
|
||||||
|
|
||||||
|
table.button(b -> {
|
||||||
|
b.label(() -> type.name()).growX().wrap().labelAlign(Align.center);
|
||||||
|
b.clicked(() -> showSelect(b, MessageType.all, type, o -> {
|
||||||
|
type = o;
|
||||||
|
rebuild(table);
|
||||||
|
}, 2, c -> c.width(150f)));
|
||||||
|
}, Styles.logict, () -> {}).size(160f, 40f).padLeft(2).color(table.color);
|
||||||
|
|
||||||
|
switch(type){
|
||||||
|
case announce, toast -> {
|
||||||
|
table.add(" for ");
|
||||||
|
fields(table, duration, str -> duration = str);
|
||||||
|
table.add(" secs ");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1291,7 +1314,7 @@ public class LStatements{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LInstruction build(LAssembler builder){
|
public LInstruction build(LAssembler builder){
|
||||||
return new FlushNotificationI();
|
return new FlushMessageI(type, builder.var(duration));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
core/src/mindustry/logic/MessageType.java
Normal file
9
core/src/mindustry/logic/MessageType.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package mindustry.logic;
|
||||||
|
|
||||||
|
public enum MessageType{
|
||||||
|
notify,
|
||||||
|
announce,
|
||||||
|
toast;
|
||||||
|
|
||||||
|
public static final MessageType[] all = values();
|
||||||
|
}
|
@ -17,7 +17,7 @@ public class ItemImage extends Stack{
|
|||||||
|
|
||||||
add(new Table(t -> {
|
add(new Table(t -> {
|
||||||
t.left().bottom();
|
t.left().bottom();
|
||||||
t.add(amount > 1000 ? UI.formatAmount(amount) : amount + "").style(Styles.outlineLabel);
|
t.add(amount >= 1000 ? UI.formatAmount(amount) : amount + "").style(Styles.outlineLabel);
|
||||||
t.pack();
|
t.pack();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -32,7 +32,7 @@ public class ItemImage extends Stack{
|
|||||||
if(stack.amount != 0){
|
if(stack.amount != 0){
|
||||||
add(new Table(t -> {
|
add(new Table(t -> {
|
||||||
t.left().bottom();
|
t.left().bottom();
|
||||||
t.add(stack.amount > 1000 ? UI.formatAmount(stack.amount) : stack.amount + "").style(Styles.outlineLabel);
|
t.add(stack.amount >= 1000 ? UI.formatAmount(stack.amount) : stack.amount + "").style(Styles.outlineLabel);
|
||||||
t.pack();
|
t.pack();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user