Fixed chat scaling for mobile

This commit is contained in:
Anuken
2018-01-07 19:46:10 -05:00
parent 37f9e1394f
commit f1fa194aa0
6 changed files with 30 additions and 30 deletions

View File

@@ -56,8 +56,8 @@ public class AndroidLauncher extends AndroidApplication{
} }
@Override @Override
public void addDialog(TextField field){ public void addDialog(TextField field, int length){
TextFieldDialogListener.add(field); TextFieldDialogListener.add(field, 0, length);
} }
@Override @Override

View File

@@ -71,13 +71,6 @@ public class UI extends SceneModule{
) )
)); ));
Mathf.each(font -> {
font.setUseIntegerPositions(false);
font.getData().setScale(Vars.fontscale);
font.getData().down += Unit.dp.scl(4f);
font.getData().lineHeight -= Unit.dp.scl(2f);
}, skin.font(), skin.getFont("default-font-chat"));
TooltipManager.getInstance().animations = false; TooltipManager.getInstance().animations = false;
Settings.setErrorHandler(()-> Timers.run(1f, ()-> showError("[crimson]Failed to access local storage.\nSettings will not be saved."))); Settings.setErrorHandler(()-> Timers.run(1f, ()-> showError("[crimson]Failed to access local storage.\nSettings will not be saved.")));
@@ -109,6 +102,12 @@ public class UI extends SceneModule{
@Override @Override
protected void loadSkin(){ protected void loadSkin(){
skin = new Skin(Gdx.files.internal("ui/uiskin.json"), Core.atlas); skin = new Skin(Gdx.files.internal("ui/uiskin.json"), Core.atlas);
Mathf.each(font -> {
font.setUseIntegerPositions(false);
font.getData().setScale(Vars.fontscale);
font.getData().down += Unit.dp.scl(4f);
font.getData().lineHeight -= Unit.dp.scl(2f);
}, skin.font(), skin.getFont("default-font-chat"));
} }
@Override @Override

View File

@@ -8,7 +8,10 @@ public abstract class PlatformFunction{
public String format(Date date){return "invalid";} public String format(Date date){return "invalid";}
public String format(int number){return "invalid";} public String format(int number){return "invalid";}
public void openLink(String link){} public void openLink(String link){}
public void addDialog(TextField field){} public void addDialog(TextField field){
addDialog(field, 16);
}
public void addDialog(TextField field, int maxLength){}
public void updateRPC(){} public void updateRPC(){}
public void onGameExit(){} public void onGameExit(){}
public void openDonations(){} public void openDonations(){}

View File

@@ -20,6 +20,7 @@ import io.anuke.ucore.scene.ui.Label;
import io.anuke.ucore.scene.ui.Label.LabelStyle; import io.anuke.ucore.scene.ui.Label.LabelStyle;
import io.anuke.ucore.scene.ui.TextField; import io.anuke.ucore.scene.ui.TextField;
import io.anuke.ucore.scene.ui.layout.Table; import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.scene.ui.layout.Unit;
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;
@@ -30,16 +31,15 @@ public class ChatFragment extends Table implements Fragment{
private final static int maxLength = 150; private final static int maxLength = 150;
private Array<ChatMessage> messages = new Array<>(); private Array<ChatMessage> messages = new Array<>();
private float fadetime; private float fadetime;
private float lastfadetime;
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 = 4, offsety = 4, fontoffsetx = 2, chatspace = 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 = 600; private float textWidth = Unit.dp.scl(600);
private Color shadowColor = new Color(0, 0, 0, 0.4f); private Color shadowColor = new Color(0, 0, 0, 0.4f);
private float textspacing = 10; private float textspacing = Unit.dp.scl(10);
public ChatFragment(){ public ChatFragment(){
super(); super();
@@ -74,8 +74,8 @@ public class ChatFragment extends Table implements Fragment{
chatfield.getStyle().background = skin.getDrawable("chatfield"); chatfield.getStyle().background = skin.getDrawable("chatfield");
chatfield.getStyle().fontColor = Color.WHITE; chatfield.getStyle().fontColor = Color.WHITE;
chatfield.getStyle().font = skin.getFont("default-font-chat"); chatfield.getStyle().font = skin.getFont("default-font-chat");
chatfield.setStyle(chatfield.getStyle());
Mindustry.platforms.addDialog(chatfield); Mindustry.platforms.addDialog(chatfield, maxLength);
bottom().left().marginBottom(offsety).marginLeft(offsetx*2).add(fieldlabel).padBottom(4f); bottom().left().marginBottom(offsety).marginLeft(offsetx*2).add(fieldlabel).padBottom(4f);
@@ -90,8 +90,8 @@ public class ChatFragment extends Table implements Fragment{
if(chatOpen) if(chatOpen)
batch.draw(skin.getRegion("white"), offsetx, chatfield.getY(), Gdx.graphics.getWidth()-offsetx*2, chatfield.getHeight()-1); batch.draw(skin.getRegion("white"), offsetx, chatfield.getY(), Gdx.graphics.getWidth()-offsetx*2, chatfield.getHeight()-1);
//font.getData().down = -21.5f; //font.getData().down = Unit.dp.scl(-21.5f);
// font.getData().lineHeight = 22f; //font.getData().lineHeight = 22f;
//chatfield.getStyle().font.getData().setScale(Vars.fontscale); //chatfield.getStyle().font.getData().setScale(Vars.fontscale);
super.draw(batch, alpha); super.draw(batch, alpha);
@@ -118,7 +118,7 @@ public class ChatFragment extends Table implements Fragment{
batch.setColor(0, 0, 0, shadowColor.a*(fadetime-i)); batch.setColor(0, 0, 0, shadowColor.a*(fadetime-i));
} }
batch.draw(skin.getRegion("white"), offsetx, theight-layout.height+1-4, textWidth, layout.height+textspacing); batch.draw(skin.getRegion("white"), offsetx, theight-layout.height+1-4, textWidth + Unit.dp.scl(4f), layout.height+textspacing);
batch.setColor(shadowColor); batch.setColor(shadowColor);
font.getCache().draw(batch); font.getCache().draw(batch);
@@ -145,7 +145,6 @@ public class ChatFragment extends Table implements Fragment{
if(!chatOpen && (scene.getKeyboardFocus() == null || !scene.getKeyboardFocus().getParent().isVisible())){ if(!chatOpen && (scene.getKeyboardFocus() == null || !scene.getKeyboardFocus().getParent().isVisible())){
scene.setKeyboardFocus(chatfield); scene.setKeyboardFocus(chatfield);
chatOpen = !chatOpen; chatOpen = !chatOpen;
lastfadetime = fadetime;
fadetime = messagesShown + 1; fadetime = messagesShown + 1;
}else if(chatOpen){ }else if(chatOpen){
scene.setKeyboardFocus(null); scene.setKeyboardFocus(null);
@@ -174,7 +173,7 @@ public class ChatFragment extends Table implements Fragment{
public ChatMessage(String message, String sender){ public ChatMessage(String message, String sender){
this.message = message; this.message = message;
this.sender = sender; this.sender = sender;
if(sender == null){ //no sender, this is a server message if(sender == null){ //no sender, this is a server message?
formattedMessage = message; formattedMessage = message;
}else{ }else{
formattedMessage = "[ROYAL]["+sender+"]: [YELLOW]"+message; formattedMessage = "[ROYAL]["+sender+"]: [YELLOW]"+message;

View File

@@ -135,8 +135,7 @@ public class HudFragment implements Fragment{
//profiling table //profiling table
if(debug){ if(debug){
new table(){{ new table(){{
abottom(); atop();
aleft();
new label("[green]density: " + Gdx.graphics.getDensity()).left(); new label("[green]density: " + Gdx.graphics.getDensity()).left();
row(); row();
new label(() -> "[blue]requests: " + renderer.getBlocks().getRequests()).left(); new label(() -> "[blue]requests: " + renderer.getBlocks().getRequests()).left();