Added scroll pane for server menu (#6451)
* Added scroll pane for server menu * Fixed title problems in menus * Removed useless import
This commit is contained in:
@@ -562,31 +562,37 @@ public class UI implements ApplicationListener, Loadable{
|
|||||||
/** Shows a menu that fires a callback when an option is selected. If nothing is selected, -1 is returned. */
|
/** Shows a menu that fires a callback when an option is selected. If nothing is selected, -1 is returned. */
|
||||||
public void showMenu(String title, String message, String[][] options, Intc callback){
|
public void showMenu(String title, String message, String[][] options, Intc callback){
|
||||||
new Dialog(title){{
|
new Dialog(title){{
|
||||||
cont.row();
|
setFillParent(true);
|
||||||
cont.image().width(400f).pad(2).colspan(2).height(4f).color(Pal.accent);
|
removeChild(titleTable);
|
||||||
cont.row();
|
cont.add(titleTable).width(400f);
|
||||||
cont.add(message).width(400f).wrap().get().setAlignment(Align.center);
|
|
||||||
cont.row();
|
|
||||||
|
|
||||||
int option = 0;
|
cont.row();
|
||||||
for(var optionsRow : options){
|
cont.image().width(400f).pad(2).colspan(2).height(4f).color(Pal.accent).bottom();
|
||||||
Table buttonRow = buttons.row().table().get().row();
|
cont.row();
|
||||||
int fullWidth = 400 - (optionsRow.length - 1) * 8; // adjust to count padding as well
|
cont.pane(table -> {
|
||||||
int width = fullWidth / optionsRow.length;
|
table.add(message).width(400f).wrap().get().setAlignment(Align.center);
|
||||||
int lastWidth = fullWidth - width * (optionsRow.length - 1); // take the rest of space for uneven table
|
table.row();
|
||||||
|
|
||||||
for(int i = 0; i < optionsRow.length; i++){
|
int option = 0;
|
||||||
if(optionsRow[i] == null) continue;
|
for(var optionsRow : options){
|
||||||
|
Table buttonRow = table.row().table().get().row();
|
||||||
|
int fullWidth = 400 - (optionsRow.length - 1) * 8; // adjust to count padding as well
|
||||||
|
int width = fullWidth / optionsRow.length;
|
||||||
|
int lastWidth = fullWidth - width * (optionsRow.length - 1); // take the rest of space for uneven table
|
||||||
|
|
||||||
String optionName = optionsRow[i];
|
for(int i = 0; i < optionsRow.length; i++){
|
||||||
int finalOption = option;
|
if(optionsRow[i] == null) continue;
|
||||||
buttonRow.button(optionName, () -> {
|
|
||||||
callback.get(finalOption);
|
String optionName = optionsRow[i];
|
||||||
hide();
|
int finalOption = option;
|
||||||
}).size(i == optionsRow.length - 1 ? lastWidth : width, 50).pad(4);
|
buttonRow.button(optionName, () -> {
|
||||||
option++;
|
callback.get(finalOption);
|
||||||
|
hide();
|
||||||
|
}).size(i == optionsRow.length - 1 ? lastWidth : width, 50).pad(4);
|
||||||
|
option++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}).growX();
|
||||||
closeOnBack(() -> callback.get(-1));
|
closeOnBack(() -> callback.get(-1));
|
||||||
}}.show();
|
}}.show();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user