Merge remote-tracking branch 'origin/master'

This commit is contained in:
Anuken
2023-04-01 09:55:59 -04:00

View File

@ -594,7 +594,8 @@ public class UI implements ApplicationListener, Loadable{
dialog.show(); dialog.show();
} }
public Dialog newMenuDialog(String title, String message, String[][] options, Intc buttonListener, Runnable closeOnBack){ // TODO REPLACE INTEGER WITH arc.fun.IntCons(int, T) or something like that.
public Dialog newMenuDialog(String title, String message, String[][] options, Cons2<Integer, Dialog> buttonListener){
return new Dialog(title){{ return new Dialog(title){{
setFillParent(true); setFillParent(true);
removeChild(titleTable); removeChild(titleTable);
@ -619,29 +620,30 @@ public class UI implements ApplicationListener, Loadable{
String optionName = optionsRow[i]; String optionName = optionsRow[i];
int finalOption = option; int finalOption = option;
buttonRow.button(optionName, () -> buttonListener.get(finalOption)) buttonRow.button(optionName, () -> buttonListener.get(finalOption, this))
.size(i == optionsRow.length - 1 ? lastWidth : width, 50).pad(4); .size(i == optionsRow.length - 1 ? lastWidth : width, 50).pad(4);
option++; option++;
} }
} }
}).growX(); }).growX();
closeOnBack(closeOnBack);
}}; }};
} }
/** 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){
newMenuDialog(title, message, options, option -> { Dialog dialog = newMenuDialog(title, message, options, (option, myself) -> {
callback.get(option); callback.get(option);
hide(); myself.hide();
}, () -> callback.get(-1)).show(); });
dialog.closeOnBack(() -> callback.get(-1));
dialog.show();
} }
/** Shows a menu that hides when another followUp-menu is shown or when nothing is selected. /** Shows a menu that hides when another followUp-menu is shown or when nothing is selected.
* @see UI#showMenu(String, String, String[][], Intc) */ * @see UI#showMenu(String, String, String[][], Intc) */
public void showFollowUpMenu(int menuId, String title, String message, String[][] options, Intc callback) { public void showFollowUpMenu(int menuId, String title, String message, String[][] options, Intc callback) {
Dialog dialog = newMenuDialog(title, message, options, (option, myself) -> callback.get(option));
Dialog dialog = newMenuDialog(title, message, options, callback, () -> { dialog.closeOnBack(() -> {
followUpMenus.remove(menuId); followUpMenus.remove(menuId);
callback.get(-1); callback.get(-1);
}); });