More logic message types
This commit is contained in:
@@ -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
|
||||
public void run(LExecutor exec){
|
||||
if(headless) return;
|
||||
|
||||
//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 --;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1272,11 +1272,34 @@ public class LStatements{
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterStatement("notification")
|
||||
public static class FlushNotificationStatement extends LStatement{
|
||||
@RegisterStatement("message")
|
||||
public static class FlushMessageStatement extends LStatement{
|
||||
public MessageType type = MessageType.announce;
|
||||
public String duration = "3";
|
||||
|
||||
@Override
|
||||
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
|
||||
@@ -1291,7 +1314,7 @@ public class LStatements{
|
||||
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
Reference in New Issue
Block a user