public MenuItem(Menu parentMenu, String text, Skin skin) { this.parentMenu = parentMenu; style = skin.get(MenuItemStyle.class); labelStyle = new LabelStyle(); labelStyle.font = style.font; labelStyle.fontColor = style.fontColor; this.label = new Label(text, labelStyle); contextMenu = new ContextMenu(skin); contextMenu.setVisible(false); addActor(this.label); addActor(contextMenu); addListener( new ClickListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (contextMenu.isVisible()) { MenuItem.this.parentMenu.selected(null, true); } else { MenuItem.this.parentMenu.selected(MenuItem.this, true); } event.stop(); return false; } @Override public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) { MenuItem.this.parentMenu.selected(MenuItem.this, false); } }); }
public void setVisible(boolean visible) { contextMenu.setVisible(visible); }