Better utilization of JoinDialog UI space

This commit is contained in:
Anuken 2023-05-11 12:52:32 -04:00
parent 38de095a2e
commit 9745c2b7fd
3 changed files with 35 additions and 30 deletions

View File

@ -42,6 +42,14 @@ public class BaseDialog extends Dialog{
this(title, Core.scene.getStyle(DialogStyle.class));
}
/** Places the buttons as an overlay on top of the content. Used when the content can be scrolled through.*/
protected void makeButtonOverlay(){
clearChildren();
add(titleTable).growX().row();
stack(cont, buttons).grow();
buttons.bottom();
}
protected void onResize(Runnable run){
Events.on(ResizeEvent.class, event -> {
if(isShown() && Core.scene.getDialog() == this){
@ -55,11 +63,15 @@ public class BaseDialog extends Dialog{
closeOnBack();
}
@Override
public void addCloseButton(){
buttons.defaults().size(210f, 64f);
buttons.button("@back", Icon.left, this::hide).size(210f, 64f);
public void addCloseButton(float width){
buttons.defaults().size(width, 64f);
buttons.button("@back", Icon.left, this::hide).size(width, 64f);
addCloseListener();
}
@Override
public void addCloseButton(){
addCloseButton(210f);
}
}

View File

@ -45,6 +45,8 @@ public class JoinDialog extends BaseDialog{
public JoinDialog(){
super("@joingame");
makeButtonOverlay();
style = new TextButtonStyle(){{
over = Styles.flatOver;
font = Fonts.def;
@ -56,13 +58,21 @@ public class JoinDialog extends BaseDialog{
loadServers();
if(!steam) buttons.add().width(60f);
//mobile players don't get information >:(
boolean infoButton = !steam && !Core.app.isMobile();
if(infoButton) buttons.add().width(60f);
buttons.add().growX().width(-1);
addCloseButton();
addCloseButton(Core.app.isMobile() ? 190f : 210f);
buttons.button("@server.add", Icon.add, () -> {
renaming = null;
add.show();
});
buttons.add().growX().width(-1);
if(!steam) buttons.button("?", () -> ui.showInfo("@join.info")).size(60f, 64f);
if(infoButton) buttons.button("?", () -> ui.showInfo("@join.info")).size(60f, 64f);
add = new BaseDialog("@joingame.title");
add.cont.add("@joingame.ip").padRight(5f).left();
@ -314,6 +324,8 @@ public class JoinDialog extends BaseDialog{
float w = targetWidth();
hosts.clear();
//since the buttons are an overlay, make room for that
hosts.marginBottom(70f);
section(steam ? "@servers.local.steam" : "@servers.local", local, false);
section("@servers.remote", remote, false);
@ -344,25 +356,6 @@ public class JoinDialog extends BaseDialog{
cont.row();
cont.add(pane).width((w + 5) * columns() + 33).pad(0);
cont.row();
cont.buttonCenter("@server.add", Icon.add, () -> {
renaming = null;
add.show();
}).marginLeft(10).width(w).height(80f).update(button -> {
float pw = w;
float pad = 0f;
if(pane.getChildren().first().getPrefHeight() > pane.getHeight()){
pw = w + 30;
pad = 6;
}
var cell = ((Table)pane.parent).getCell(button);
if(!Mathf.equal(cell.minWidth(), pw)){
cell.width(pw);
cell.padLeft(pad);
pane.parent.invalidateHierarchy();
}
});
}
void section(String label, Table servers, boolean eye){

View File

@ -54,6 +54,8 @@ public abstract class MapListDialog extends BaseDialog{
abstract void showMap(Map map);
void setup(){
makeButtonOverlay();
buttons.clearChildren();
searchString = null;
@ -86,15 +88,13 @@ public abstract class MapListDialog extends BaseDialog{
cont.add(search).growX();
cont.row();
cont.add(pane).uniformX().growY();
cont.row();
cont.add(buttons).growX();
cont.add(pane).padLeft(36f).uniformX().growY();
}
void rebuildMaps(){
mapTable.clear();
mapTable.marginRight(24);
mapTable.marginRight(18f);
int maxwidth = Math.max((int)(Core.graphics.getWidth() / Scl.scl(230)), 1);
float mapsize = 200f;