[LibGDX]Scene2d table cell layout problem

hey all

I’m having a problem with this set of tables I’m using as a right click menu in my game. I have virtually everything finished with this part of the gui and I’m stuck on it now so a fresh set of eyes would be appreciated.

You can see in the screenshot and in the game if you download it how I would like the right click menu to layout the terrain tile menu to the right of the main right click menu by adding it to a cell in the right click ‘master’ table. The blue outline of the right click ‘master’ table shows where I would like the terrain menu.
Jar: http://www.mediafire.com/download/9wrrws8y6grrq6y/testGame.jar Source: http://www.mediafire.com/download/hi93aqocpnd8lff/testGame.7z
Entities can be selected via keys 1-3 and placed

Any help on how to re-align the cell to the right would be appreciated, thanks :slight_smile:

create one “main-table”,
create one “button-table”,
create one “tile-table”,
-> add the button-table to the main-table
-> add the tile-table to the maintable when you need it.
it’s often easier to use more tables.

I am using multiple tables. I have:

one root/master menu table
the main right click menu table .add’ed to the master
a button in the main right click menu should toggle master.add(terrainTable) and master.removeActor(terrainTable)

all of the above works, except for the fact it adds the terrain menu cell to a new row underneath the main right click menu where I want it to be added to the right of the main right click menu:

Here’s the relevant code section:

public Gui(GameScreen game) {
		this.game = game;
		stage = new Stage();
		stage.setCamera(game.getRenderer().getCamera());
		font = game.getRenderer().getFont();
		//font.setUseIntegerPositions(false); 
		skin = new Skin();
		skin.addRegions(game.getAtlas());
		lStyle = new LabelStyle();
		
		stage.addActor(terrainMenu());
		stage.addActor(infoMenu());
		stage.addActor(mainMenu());
		stage.addActor(bottomBar());
		stage.addActor(rightClickMenu());
		
		
//		rClick.add(terrainMenu);
//		rClick.add(infoMenu);
		
		rClick.debug();
	}
	
	//Base Right click menu
	public Table rightClickMenu() {

		rClick = new Table();
		rClick.setFillParent(false);
		rClick.left().top();
		rClick.setWidth(120);
		rClick.setHeight(60);
		
		rClick.add(mainMenu);
		
		return rClick;
	}
	
	public Table mainMenu(){
		
		mainMenu = new Table();
		mainMenu.defaults().width(45).height(15);

		mainMenu.setFillParent(false);
		//mainTable.setX(game.getInput().getVec2Clicked().x);
		//mainTable.setY(game.getInput().getVec2Clicked().y);

		lStyle.font = font;
		setButtonStyle("gui/menuItem_up");
		
		b = new Button(style);
		b.add(new Label("Info",lStyle));
		b.left();
		b.addListener(new ChangeListener() {
			public void changed(ChangeEvent event, Actor actor) {
				if(infoMenu.isVisible()){
					infoMenu.setVisible(false);
				}else{
					infoMenu.setVisible(true);
				}
			}
		});
		mainMenu.add(b).row();
		
		b = new Button(style);
		b.add(new Label("Terrain",lStyle));
		b.left();
		b.addListener(new ChangeListener() {
			public void changed(ChangeEvent event, Actor actor) {
				if(terrainMenu.isVisible()){
					rClick.removeActor(terrainMenu);
					terrainMenu.setVisible(false);
				}else{
					rClick.add(terrainMenu);
					terrainMenu.setVisible(true);
				}
			}
		});
		mainMenu.add(b).row();

		// Make a bunch of filler buttons
		for (int i = 0; i < 2; i++) {
			b = new Button(style);
			b.add(new Label("[EMPTY]",lStyle));
			b.left();
			b.addListener(new ChangeListener() {
				public void changed(ChangeEvent event, Actor actor) {
					//System.out.println("Wait");
				}
			});
			mainMenu.add(b).row();
		}
		mainMenu.left().bottom();
		mainMenu.setVisible(false);
		return mainMenu;
	}

//Terrain/Map tiles
	public Table terrainMenu(){
		terrainMenu = new Table();
		terrainMenu.setFillParent(false);
		terrainMenu.defaults().width(game.getAtlas().findRegion("terrain/grass").packedWidth+game.getAtlas().findRegion("terrain/grass").packedWidth*.25f).height(game.getAtlas().findRegion("terrain/grass").packedHeight+game.getAtlas().findRegion("terrain/grass").packedHeight*.25f);
		//terrainMenu.left();
		
		ImageButtonStyle style = new ImageButtonStyle();
		style.imageUp = skin.getDrawable("terrain/grass");
		style.up = skin.getDrawable("gui/menuItem_up");
		ImageButton imgb = new ImageButton(style);
		imgb.addListener(new ChangeListener() {
			public void changed(ChangeEvent event, Actor actor) {
				game.setBuildSelection(game.getBaseTiles().getBaseTile("grass"));
				System.out.println("Build selection set to grass... " + game.getBuildSelection());
			}
		});
		terrainMenu.add(imgb);
		
		style = new ImageButtonStyle();
		style.imageUp = skin.getDrawable("terrain/water");
		style.up = skin.getDrawable("gui/menuItem_up");
		imgb = new ImageButton(style);
		imgb.addListener(new ChangeListener() {
			public void changed(ChangeEvent event, Actor actor) {
				game.setBuildSelection(game.getBaseTiles().getBaseTile("water"));
				System.out.println("Build selection set to Water... " + game.getBuildSelection());
			}
		});
		terrainMenu.add(imgb).row();
		
		style = new ImageButtonStyle();
		style.imageUp = skin.getDrawable("terrain/road");
		style.up = skin.getDrawable("gui/menuItem_up");
		imgb = new ImageButton(style);
		imgb.addListener(new ChangeListener() {
			public void changed(ChangeEvent event, Actor actor) {
				game.setBuildSelection(game.getBaseTiles().getBaseTile("road"));
				System.out.println("Build selection set to road... " + game.getBuildSelection());
			}
		});
		terrainMenu.add(imgb).row();
		
		style = new ImageButtonStyle();
		style.imageUp = skin.getDrawable("terrain/markerTile");
		style.up = skin.getDrawable("gui/menuItem_up");
		imgb = new ImageButton(style);
		imgb.addListener(new ChangeListener() {
			public void changed(ChangeEvent event, Actor actor) {
				game.setBuildSelection(game.getBaseTiles().getBaseTile("markerTile"));
				System.out.println("Build selection set to markerTile... " + game.getBuildSelection());
			}
		});
		terrainMenu.add(imgb).row();
		
		terrainMenu.setVisible(false);
		return terrainMenu;
	}

line 101;


		b.addListener(new ChangeListener() {
			public void changed(ChangeEvent event, Actor actor) {
				rClick.add(terrainMenu).row(); //why do you create a new row?
				terrainMenu.setVisible(true);
			}
		});
 

		stage.addActor(bottomBar());
		stage.addActor(rightClickMenu());
		stage.addActor(mainMenu());
		stage.addActor(infoMenu());
		stage.addActor(terrainMenu());

Is there a reason why you add everything to the stage?

I think removing “row()” should fix it, but I can’t test it because the grahics aren’t inside the src :slight_smile:

thanks for the help.
I have since changed [quote]

 b.addListener(new ChangeListener() {
         public void changed(ChangeEvent event, Actor actor) {
            rClick.add(terrainMenu).row(); //why do you create a new row?
            terrainMenu.setVisible(true);
         }
      });

[/quote]
to

b.addListener(new ChangeListener() {
			public void changed(ChangeEvent event, Actor actor) {
				if(terrainMenu.isVisible()){
					rClick.removeActor(terrainMenu);
					terrainMenu.setVisible(false);
				}else{
					rClick.add(terrainMenu);
					terrainMenu.setVisible(true);
				}
			}

but still no joy. I was toying around with that .row() and moving it around to see if I could effect anything but even with it removed entirely and only using .addActor() the cell was on a new row.
I added everything to stage because thats how the tutorial I was following did it, though I have had to correct a few things already after looking at the official libGDX wiki. Should I only worry about adding the tables(other than the master table) to the main right click menu?
I’ll remove that code adding everything to stage.

EDIT: the images and package file are in rts-desktop/bin/img

It’s too much to go thru when you post all your code. You should do as much as possible to make it easy to get help.

It’s hard to tell from your first post what you want. I guess you have a list of menu items and you want a submenu to appear to the right of a menu item when it is clicked? If so then layout your menu items using a table. Create another table for the submenu. When the menu item is clicked, add the submenu table to the stage. Because it is added last, it will be on top of everything else. Next, position the submenu table to the right of the menu item. The submenu table’s parent is the stage root, so you need to use localToStageCoordinates on the menu item to get the stage location of the menu item, then add the menu item width to position the submenu table to the right of it.

To hide the submenu, remove it from the stage. To have it hide when anything that is not the submenu is clicked, add an InputListener to the stage when you show the submenu that hides the submenu and removes the listener on any touchDown. Next, add an InputListener to the submenu that calls event.stop() in touchDown. This prevents events that occur on the submenu from bubbling up to the stage and closing the submenu.