Implement popup id system so that popups don't flicker. (#11751)
This commit is contained in:
@@ -85,6 +85,9 @@ public class UI implements ApplicationListener, Loadable{
|
||||
|
||||
private @Nullable Element lastAnnouncement;
|
||||
|
||||
/** Maps popups to ids so that they can be removed or updated by id. */
|
||||
private final ObjectMap<String, Table> popups = new ObjectMap<>();
|
||||
|
||||
public UI(){
|
||||
Fonts.loadFonts();
|
||||
}
|
||||
@@ -394,14 +397,21 @@ public class UI implements ApplicationListener, Loadable{
|
||||
}
|
||||
|
||||
/** Shows a label at some position on the screen. Does not fade. */
|
||||
public void showInfoPopup(String info, float duration, int align, int top, int left, int bottom, int right){
|
||||
public void showInfoPopup(String info, @Nullable String id, float duration, int align, int top, int left, int bottom, int right){
|
||||
Table table = new Table();
|
||||
if(id != null){
|
||||
Table old = popups.put(id, table);
|
||||
if (old != null) old.remove();
|
||||
}
|
||||
table.setFillParent(true);
|
||||
table.touchable = Touchable.disabled;
|
||||
table.update(() -> {
|
||||
if(state.isMenu()) table.remove();
|
||||
if(state.isMenu()){
|
||||
table.remove();
|
||||
if(id != null) popups.remove(id);
|
||||
}
|
||||
});
|
||||
table.actions(Actions.delay(duration), Actions.remove());
|
||||
table.actions(Actions.delay(duration), Actions.remove(), Actions.run(() -> { if(id != null) popups.remove(id); }));
|
||||
table.align(align).table(Styles.black3, t -> t.margin(4).add(info).style(Styles.outlineLabel)).pad(top, left, bottom, right);
|
||||
Core.scene.add(table);
|
||||
}
|
||||
|
||||
@@ -122,10 +122,29 @@ public class Menus{
|
||||
}
|
||||
|
||||
@Remote(variants = Variant.both, unreliable = true)
|
||||
public static void infoPopup(String message, float duration, int align, int top, int left, int bottom, int right){
|
||||
public static void infoPopup(String message, @Nullable String id, float duration, int align, int top, int left, int bottom, int right){
|
||||
if(message == null) return;
|
||||
|
||||
ui.showInfoPopup(message, duration, align, top, left, bottom, right);
|
||||
ui.showInfoPopup(message, id, duration, align, top, left, bottom, right);
|
||||
}
|
||||
|
||||
@Remote(variants = Variant.both)
|
||||
public static void infoPopupReliable(String message, @Nullable String id, float duration, int align, int top, int left, int bottom, int right){
|
||||
infoPopup(message, id, duration, align, top, left, bottom, right);
|
||||
}
|
||||
|
||||
/** @deprecated Prefer variants with ids to stop flickering popups. */
|
||||
@Deprecated
|
||||
@Remote(variants = Variant.both, unreliable = true)
|
||||
public static void infoPopup(String message, float duration, int align, int top, int left, int bottom, int right){
|
||||
infoPopup(message, null, duration, align, top, left, bottom, right);
|
||||
}
|
||||
|
||||
/** @deprecated Prefer variants with ids to stop flickering popups. */
|
||||
@Deprecated
|
||||
@Remote(variants = Variant.both)
|
||||
public static void infoPopupReliable(String message, float duration, int align, int top, int left, int bottom, int right){
|
||||
infoPopup(message, duration, align, top, left, bottom, right);
|
||||
}
|
||||
|
||||
@Remote(variants = Variant.both, unreliable = true)
|
||||
@@ -135,13 +154,6 @@ public class Menus{
|
||||
ui.showLabel(message, duration, worldx, worldy);
|
||||
}
|
||||
|
||||
@Remote(variants = Variant.both)
|
||||
public static void infoPopupReliable(String message, float duration, int align, int top, int left, int bottom, int right){
|
||||
if(message == null) return;
|
||||
|
||||
ui.showInfoPopup(message, duration, align, top, left, bottom, right);
|
||||
}
|
||||
|
||||
@Remote(variants = Variant.both)
|
||||
public static void labelReliable(String message, float duration, float worldx, float worldy){
|
||||
label(message, duration, worldx, worldy);
|
||||
|
||||
Reference in New Issue
Block a user