Fixed some NpcMenu behavior with the cancellation callback

Attempted change on cancel callback behavior -- only called when upnav
Introduced some parent functions in NpcMenu to help with determining submenus
Changed menus to NpcMenu (I don't imagine the need for the generalization right now)
This commit is contained in:
Collin Smith 2019-03-03 02:29:26 -08:00
parent 008730d2c9
commit c80a57ab09
2 changed files with 13 additions and 5 deletions

View File

@ -95,7 +95,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
MapListener mapListener;
InputProcessor inputProcessorTest;
final Array<Actor> labels = new Array<>();
Actor menu;
NpcMenu menu;
public TextArea input;
TextArea output;
@ -596,14 +596,15 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
}
}
public Actor getMenu() {
public NpcMenu getMenu() {
return menu;
}
public void setMenu(Actor menu, Entity owner) {
public void setMenu(NpcMenu menu, Entity owner) {
if (this.menu != menu) {
if (this.menu != null) {
if (this.menu instanceof NpcMenu) ((NpcMenu) this.menu).cancel();
// FIXME: Validate that cancel is only called if upnav, downnav -- looks good at a glance
if (menu == null || menu.getParent() != this.menu) this.menu.cancel();
stage.getRoot().removeActor(this.menu);
}
this.menu = menu;

View File

@ -37,6 +37,14 @@ public class NpcMenu extends Table {
add(new Label(id, Diablo.fonts.font16, Diablo.colors.gold)).space(SPACING).row();
}
public boolean hasParent() {
return parent != null;
}
public NpcMenu getParent() {
return parent;
}
public NpcMenu addItem(int id, ClickListener clickListener) {
LabelButton button = new LabelButton(id, Diablo.fonts.font16);
button.addListener(clickListener);
@ -76,7 +84,6 @@ public class NpcMenu extends Table {
public void cancel() {
if (cancellationListener != null) cancellationListener.onCancelled();
}
public interface CancellationListener {