Full chat revert / Crash fixes

This commit is contained in:
Anuken 2018-08-16 10:09:22 -04:00
parent 8850a89e30
commit 1de367e89c
4 changed files with 14 additions and 52 deletions

View File

@ -3,7 +3,6 @@ package io.anuke.mindustry.ui.fragments;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
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.utils.Align;
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.state;
import static io.anuke.ucore.core.Core.font;
import static io.anuke.ucore.core.Core.scene;
import static io.anuke.ucore.core.Core.skin;
@ -36,7 +34,7 @@ public class ChatFragment extends Table{
private boolean chatOpen = false;
private TextField chatfield;
private Label fieldlabel = new Label(">");
//private BitmapFont font;
private BitmapFont font;
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 textWidth = Unit.dp.scl(600);
@ -56,7 +54,7 @@ public class ChatFragment extends Table{
super();
setFillParent(true);
//font = Core.skin.getFont("default-font");
font = Core.skin.getFont("default-font");
visible(() -> !state.is(State.menu) && Net.active());
@ -104,39 +102,15 @@ public class ChatFragment extends Table{
private void setup(){
fieldlabel.setStyle(new LabelStyle(fieldlabel.getStyle()));
//fieldlabel.getStyle().font = font;
fieldlabel.getStyle().font = font;
fieldlabel.setStyle(fieldlabel.getStyle());
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 = new TextField("", new TextField.TextFieldStyle(skin.get(TextField.TextFieldStyle.class)));
chatfield.setTextFieldFilter((field, c) -> field.getText().length() < Vars.maxTextLength);
chatfield.getStyle().background = null;
chatfield.getStyle().messageFont = null;
chatfield.getStyle().font = skin.getFont("default-font-chat");
chatfield.getStyle().fontColor = Color.WHITE;
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);
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();
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);
theight += layout.height + textspacing;
@ -199,25 +172,6 @@ public class ChatFragment extends Table{
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(){
String message = chatfield.getText();
clearChatInput();

View File

@ -84,7 +84,7 @@ public abstract class BaseBlock{
}
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){

View File

@ -53,6 +53,7 @@ public class PowerNode extends PowerBlock{
@Remote(targets = Loc.both, called = Loc.server, forward = true)
public static void linkPowerDistributors(Player player, Tile tile, Tile other){
if(!(tile.entity instanceof DistributorEntity)) return;
DistributorEntity entity = tile.entity();
@ -71,6 +72,8 @@ public class PowerNode extends PowerBlock{
@Remote(targets = Loc.both, called = Loc.server, forward = true)
public static void unlinkPowerDistributors(Player player, Tile tile, Tile other){
if(!(tile.entity instanceof DistributorEntity)) return;
DistributorEntity entity = tile.entity();
entity.links.removeValue(other.packedPosition());

View File

@ -114,6 +114,11 @@ public class GenericCrafter extends Block{
return new GenericCrafterEntity();
}
@Override
public int getMaximumAccepted(Tile tile, Item item){
return itemCapacity;
}
public static class GenericCrafterEntity extends TileEntity{
public float progress;
public float totalProgress;