Adding a new menu type. (#8449)
* Added a new type of menu. * Renamed the methods and fixed buttons not selecting. * Fixed followUpMenu and menu having different dialogs. * Applying review changes. - Refactored the menu dialog instantiation. - Fixed the single-line else statement.
This commit is contained in:
@@ -75,6 +75,8 @@ public class UI implements ApplicationListener, Loadable{
|
|||||||
public FullTextDialog fullText;
|
public FullTextDialog fullText;
|
||||||
public CampaignCompleteDialog campaignComplete;
|
public CampaignCompleteDialog campaignComplete;
|
||||||
|
|
||||||
|
public IntMap<Dialog> followUpMenus;
|
||||||
|
|
||||||
public Cursor drillCursor, unloadCursor, targetCursor;
|
public Cursor drillCursor, unloadCursor, targetCursor;
|
||||||
|
|
||||||
private @Nullable Element lastAnnouncement;
|
private @Nullable Element lastAnnouncement;
|
||||||
@@ -202,6 +204,7 @@ public class UI implements ApplicationListener, Loadable{
|
|||||||
logic = new LogicDialog();
|
logic = new LogicDialog();
|
||||||
fullText = new FullTextDialog();
|
fullText = new FullTextDialog();
|
||||||
campaignComplete = new CampaignCompleteDialog();
|
campaignComplete = new CampaignCompleteDialog();
|
||||||
|
followUpMenus = new IntMap<>();
|
||||||
|
|
||||||
Group group = Core.scene.root;
|
Group group = Core.scene.root;
|
||||||
|
|
||||||
@@ -591,9 +594,8 @@ public class UI implements ApplicationListener, Loadable{
|
|||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Shows a menu that fires a callback when an option is selected. If nothing is selected, -1 is returned. */
|
public Dialog newMenuDialog(String title, String message, String[][] options, Intc buttonListener, Runnable closeOnBack){
|
||||||
public void showMenu(String title, String message, String[][] options, Intc callback){
|
return new Dialog(title){{
|
||||||
new Dialog(title){{
|
|
||||||
setFillParent(true);
|
setFillParent(true);
|
||||||
removeChild(titleTable);
|
removeChild(titleTable);
|
||||||
cont.add(titleTable).width(400f);
|
cont.add(titleTable).width(400f);
|
||||||
@@ -617,16 +619,46 @@ public class UI implements ApplicationListener, Loadable{
|
|||||||
|
|
||||||
String optionName = optionsRow[i];
|
String optionName = optionsRow[i];
|
||||||
int finalOption = option;
|
int finalOption = option;
|
||||||
buttonRow.button(optionName, () -> {
|
buttonRow.button(optionName, () -> buttonListener.get(finalOption))
|
||||||
callback.get(finalOption);
|
.size(i == optionsRow.length - 1 ? lastWidth : width, 50).pad(4);
|
||||||
hide();
|
|
||||||
}).size(i == optionsRow.length - 1 ? lastWidth : width, 50).pad(4);
|
|
||||||
option++;
|
option++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).growX();
|
}).growX();
|
||||||
closeOnBack(() -> callback.get(-1));
|
closeOnBack(closeOnBack);
|
||||||
}}.show();
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 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){
|
||||||
|
newMenuDialog(title, message, options, option -> {
|
||||||
|
callback.get(option);
|
||||||
|
hide();
|
||||||
|
}, () -> callback.get(-1)).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Shows a menu that hides when another followUp-menu is shown or when nothing is selected.
|
||||||
|
* @see UI#showMenu(String, String, String[][], Intc) */
|
||||||
|
public void showFollowUpMenu(int menuId, String title, String message, String[][] options, Intc callback) {
|
||||||
|
|
||||||
|
Dialog dialog = newMenuDialog(title, message, options, callback, () -> {
|
||||||
|
followUpMenus.remove(menuId);
|
||||||
|
callback.get(-1);
|
||||||
|
});
|
||||||
|
|
||||||
|
Dialog oldDialog = followUpMenus.remove(menuId);
|
||||||
|
if(oldDialog != null){
|
||||||
|
dialog.show(Core.scene, null);
|
||||||
|
oldDialog.hide(null);
|
||||||
|
}else{
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
followUpMenus.put(menuId, dialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hideFollowUpMenu(int menuId) {
|
||||||
|
if(!followUpMenus.containsKey(menuId)) return;
|
||||||
|
followUpMenus.remove(menuId).hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Formats time with hours:minutes:seconds. */
|
/** Formats time with hours:minutes:seconds. */
|
||||||
|
|||||||
@@ -36,6 +36,19 @@ public class Menus{
|
|||||||
ui.showMenu(title, message, options, (option) -> Call.menuChoose(player, menuId, option));
|
ui.showMenu(title, message, options, (option) -> Call.menuChoose(player, menuId, option));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remote(variants = Variant.both)
|
||||||
|
public static void followUpMenu(int menuId, String title, String message, String[][] options){
|
||||||
|
if(title == null) title = "";
|
||||||
|
if(options == null) options = new String[0][0];
|
||||||
|
|
||||||
|
ui.showFollowUpMenu(menuId, title, message, options, (option) -> Call.menuChoose(player, menuId, option));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Remote(variants = Variant.both)
|
||||||
|
public static void hideFollowUpMenu(int menuId) {
|
||||||
|
ui.hideFollowUpMenu(menuId);
|
||||||
|
}
|
||||||
|
|
||||||
@Remote(targets = Loc.both, called = Loc.both)
|
@Remote(targets = Loc.both, called = Loc.both)
|
||||||
public static void menuChoose(@Nullable Player player, int menuId, int option){
|
public static void menuChoose(@Nullable Player player, int menuId, int option){
|
||||||
if(player != null){
|
if(player != null){
|
||||||
|
|||||||
Reference in New Issue
Block a user