Added message blocks for Erekir and the editor

This commit is contained in:
Anuken
2022-10-30 09:01:42 -04:00
parent d16a11f18f
commit 76c99400a4
12 changed files with 91 additions and 12 deletions

View File

@@ -1,6 +1,8 @@
package mindustry.world.blocks.logic;
import arc.*;
import arc.Graphics.*;
import arc.Graphics.Cursor.*;
import arc.Input.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
@@ -22,6 +24,7 @@ public class MessageBlock extends Block{
//don't change this too much unless you want to run into issues with packet sizes
public int maxTextLength = 220;
public int maxNewlines = 24;
public boolean privileged = false;
public MessageBlock(String name){
super(name);
@@ -33,7 +36,7 @@ public class MessageBlock extends Block{
envEnabled = Env.any;
config(String.class, (MessageBuild tile, String text) -> {
if(text.length() > maxTextLength){
if(text.length() > maxTextLength || !accessible()){
return; //no.
}
@@ -55,6 +58,15 @@ public class MessageBlock extends Block{
});
}
public boolean accessible(){
return !privileged || state.rules.editor;
}
@Override
public boolean canBreak(Tile tile){
return accessible();
}
public class MessageBuild extends Building{
public StringBuilder message = new StringBuilder();
@@ -87,6 +99,11 @@ public class MessageBlock extends Block{
@Override
public void buildConfiguration(Table table){
if(!accessible()){
deselect();
return;
}
table.button(Icon.pencil, Styles.cleari, () -> {
if(mobile){
Core.input.getTextInput(new TextInput(){{
@@ -134,7 +151,7 @@ public class MessageBlock extends Block{
@Override
public boolean onConfigureBuildTapped(Building other){
if(this == other){
if(this == other || !accessible()){
deselect();
return false;
}
@@ -142,6 +159,32 @@ public class MessageBlock extends Block{
return true;
}
@Override
public Cursor getCursor(){
return !accessible() ? SystemCursor.arrow : super.getCursor();
}
@Override
public void damage(float damage){
if(privileged) return;
super.damage(damage);
}
@Override
public boolean canPickup(){
return false;
}
@Override
public boolean collide(Bullet other){
return !privileged;
}
@Override
public boolean displayable(){
return accessible();
}
@Override
public void handleString(Object value){
message.setLength(0);