mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-19 20:27:44 +07:00
Full chat revert / Crash fixes
This commit is contained in:
@ -3,7 +3,6 @@ package io.anuke.mindustry.ui.fragments;
|
|||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.Glyph;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
||||||
import com.badlogic.gdx.utils.Align;
|
import com.badlogic.gdx.utils.Align;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
@ -25,7 +24,6 @@ import io.anuke.ucore.util.Mathf;
|
|||||||
|
|
||||||
import static io.anuke.mindustry.Vars.players;
|
import static io.anuke.mindustry.Vars.players;
|
||||||
import static io.anuke.mindustry.Vars.state;
|
import static io.anuke.mindustry.Vars.state;
|
||||||
import static io.anuke.ucore.core.Core.font;
|
|
||||||
import static io.anuke.ucore.core.Core.scene;
|
import static io.anuke.ucore.core.Core.scene;
|
||||||
import static io.anuke.ucore.core.Core.skin;
|
import static io.anuke.ucore.core.Core.skin;
|
||||||
|
|
||||||
@ -36,7 +34,7 @@ public class ChatFragment extends Table{
|
|||||||
private boolean chatOpen = false;
|
private boolean chatOpen = false;
|
||||||
private TextField chatfield;
|
private TextField chatfield;
|
||||||
private Label fieldlabel = new Label(">");
|
private Label fieldlabel = new Label(">");
|
||||||
//private BitmapFont font;
|
private BitmapFont font;
|
||||||
private GlyphLayout layout = new GlyphLayout();
|
private GlyphLayout layout = new GlyphLayout();
|
||||||
private float offsetx = Unit.dp.scl(4), offsety = Unit.dp.scl(4), fontoffsetx = Unit.dp.scl(2), chatspace = Unit.dp.scl(50);
|
private float offsetx = Unit.dp.scl(4), offsety = Unit.dp.scl(4), fontoffsetx = Unit.dp.scl(2), chatspace = Unit.dp.scl(50);
|
||||||
private float textWidth = Unit.dp.scl(600);
|
private float textWidth = Unit.dp.scl(600);
|
||||||
@ -56,7 +54,7 @@ public class ChatFragment extends Table{
|
|||||||
super();
|
super();
|
||||||
|
|
||||||
setFillParent(true);
|
setFillParent(true);
|
||||||
//font = Core.skin.getFont("default-font");
|
font = Core.skin.getFont("default-font");
|
||||||
|
|
||||||
visible(() -> !state.is(State.menu) && Net.active());
|
visible(() -> !state.is(State.menu) && Net.active());
|
||||||
|
|
||||||
@ -104,39 +102,15 @@ public class ChatFragment extends Table{
|
|||||||
|
|
||||||
private void setup(){
|
private void setup(){
|
||||||
fieldlabel.setStyle(new LabelStyle(fieldlabel.getStyle()));
|
fieldlabel.setStyle(new LabelStyle(fieldlabel.getStyle()));
|
||||||
//fieldlabel.getStyle().font = font;
|
fieldlabel.getStyle().font = font;
|
||||||
fieldlabel.setStyle(fieldlabel.getStyle());
|
fieldlabel.setStyle(fieldlabel.getStyle());
|
||||||
|
|
||||||
chatfield = new TextField("", new TextField.TextFieldStyle(skin.get(TextField.TextFieldStyle.class))){
|
chatfield = new TextField("", new TextField.TextFieldStyle(skin.get(TextField.TextFieldStyle.class)));
|
||||||
@Override
|
|
||||||
public void draw(Batch batch, float parentAlpha){
|
|
||||||
getStyle().font.getData().markupEnabled = false;
|
|
||||||
super.draw(batch, parentAlpha);
|
|
||||||
getStyle().font.getData().markupEnabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateDisplayText(){
|
|
||||||
getStyle().font.getData().markupEnabled = false;
|
|
||||||
super.updateDisplayText();
|
|
||||||
getStyle().font.getData().markupEnabled = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
chatfield.setTextFieldFilter((field, c) -> field.getText().length() < Vars.maxTextLength);
|
chatfield.setTextFieldFilter((field, c) -> field.getText().length() < Vars.maxTextLength);
|
||||||
chatfield.getStyle().background = null;
|
chatfield.getStyle().background = null;
|
||||||
chatfield.getStyle().messageFont = null;
|
chatfield.getStyle().font = skin.getFont("default-font-chat");
|
||||||
chatfield.getStyle().fontColor = Color.WHITE;
|
chatfield.getStyle().fontColor = Color.WHITE;
|
||||||
chatfield.setStyle(chatfield.getStyle());
|
chatfield.setStyle(chatfield.getStyle());
|
||||||
chatfield.update(() -> {
|
|
||||||
BitmapFont font = detectFont(chatfield.getText());;
|
|
||||||
if(font != chatfield.getStyle().font){
|
|
||||||
chatfield.getStyle().font = detectFont(chatfield.getText());
|
|
||||||
chatfield.setStyle(chatfield.getStyle());
|
|
||||||
String text = chatfield.getText();
|
|
||||||
chatfield.clearText();
|
|
||||||
chatfield.appendText(text);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Platform.instance.addDialog(chatfield, Vars.maxTextLength);
|
Platform.instance.addDialog(chatfield, Vars.maxTextLength);
|
||||||
|
|
||||||
bottom().left().marginBottom(offsety).marginLeft(offsetx * 2).add(fieldlabel).padBottom(4f);
|
bottom().left().marginBottom(offsety).marginLeft(offsetx * 2).add(fieldlabel).padBottom(4f);
|
||||||
@ -173,7 +147,6 @@ public class ChatFragment extends Table{
|
|||||||
|
|
||||||
float theight = offsety + spacing + getMarginBottom();
|
float theight = offsety + spacing + getMarginBottom();
|
||||||
for(int i = scrollPos; i < messages.size && i < messagesShown + scrollPos && (i < fadetime || chatOpen); i++){
|
for(int i = scrollPos; i < messages.size && i < messagesShown + scrollPos && (i < fadetime || chatOpen); i++){
|
||||||
BitmapFont font = detectFont(messages.get(i).formattedMessage);
|
|
||||||
|
|
||||||
layout.setText(font, messages.get(i).formattedMessage, Color.WHITE, textWidth, Align.bottomLeft, true);
|
layout.setText(font, messages.get(i).formattedMessage, Color.WHITE, textWidth, Align.bottomLeft, true);
|
||||||
theight += layout.height + textspacing;
|
theight += layout.height + textspacing;
|
||||||
@ -199,25 +172,6 @@ public class ChatFragment extends Table{
|
|||||||
fadetime -= Timers.delta() / 180f;
|
fadetime -= Timers.delta() / 180f;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BitmapFont detectFont(String text){
|
|
||||||
for(int i = 0; i < text.length(); i++){
|
|
||||||
if(isControl((int) text.charAt(i))) continue;
|
|
||||||
Glyph g = font.getData().getGlyph(text.charAt(i));
|
|
||||||
if(g == null || g == font.getData().missingGlyph){
|
|
||||||
for(BitmapFont font : Core.skin.getAll(BitmapFont.class).values()){
|
|
||||||
if(font.getData().getGlyph(text.charAt(i)) != null){
|
|
||||||
return font;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Core.font;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isControl(int var0){
|
|
||||||
return var0 <= 159 && (var0 >= 127 || var0 >>> 5 == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendMessage(){
|
private void sendMessage(){
|
||||||
String message = chatfield.getText();
|
String message = chatfield.getText();
|
||||||
clearChatInput();
|
clearChatInput();
|
||||||
|
@ -84,7 +84,7 @@ public abstract class BaseBlock{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||||
return tile.entity != null && consumes.has(ConsumeItem.class) && consumes.item() == item && tile.entity.items.total() < itemCapacity;
|
return tile.entity != null && consumes.has(ConsumeItem.class) && consumes.item() == item && tile.entity.items.get(item) < getMaximumAccepted(tile, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||||
|
@ -53,6 +53,7 @@ public class PowerNode extends PowerBlock{
|
|||||||
|
|
||||||
@Remote(targets = Loc.both, called = Loc.server, forward = true)
|
@Remote(targets = Loc.both, called = Loc.server, forward = true)
|
||||||
public static void linkPowerDistributors(Player player, Tile tile, Tile other){
|
public static void linkPowerDistributors(Player player, Tile tile, Tile other){
|
||||||
|
if(!(tile.entity instanceof DistributorEntity)) return;
|
||||||
|
|
||||||
DistributorEntity entity = tile.entity();
|
DistributorEntity entity = tile.entity();
|
||||||
|
|
||||||
@ -71,6 +72,8 @@ public class PowerNode extends PowerBlock{
|
|||||||
|
|
||||||
@Remote(targets = Loc.both, called = Loc.server, forward = true)
|
@Remote(targets = Loc.both, called = Loc.server, forward = true)
|
||||||
public static void unlinkPowerDistributors(Player player, Tile tile, Tile other){
|
public static void unlinkPowerDistributors(Player player, Tile tile, Tile other){
|
||||||
|
if(!(tile.entity instanceof DistributorEntity)) return;
|
||||||
|
|
||||||
DistributorEntity entity = tile.entity();
|
DistributorEntity entity = tile.entity();
|
||||||
|
|
||||||
entity.links.removeValue(other.packedPosition());
|
entity.links.removeValue(other.packedPosition());
|
||||||
|
@ -114,6 +114,11 @@ public class GenericCrafter extends Block{
|
|||||||
return new GenericCrafterEntity();
|
return new GenericCrafterEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaximumAccepted(Tile tile, Item item){
|
||||||
|
return itemCapacity;
|
||||||
|
}
|
||||||
|
|
||||||
public static class GenericCrafterEntity extends TileEntity{
|
public static class GenericCrafterEntity extends TileEntity{
|
||||||
public float progress;
|
public float progress;
|
||||||
public float totalProgress;
|
public float totalProgress;
|
||||||
|
Reference in New Issue
Block a user