Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (492)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [LibGDX]Scene2d table cell layout problem  (Read 2008 times)
0 Members and 1 Guest are viewing this topic.
Offline ado

Senior Newbie





« Posted 2013-08-19 01:44:31 »

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 Smiley
Offline Phibedy

Senior Member


Medals: 8



« Reply #1 - Posted 2013-08-19 20:19:05 »

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.
Offline ado

Senior Newbie





« Reply #2 - Posted 2013-08-19 20:59:30 »

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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
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;
   }


Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Phibedy

Senior Member


Medals: 8



« Reply #3 - Posted 2013-08-19 21:54:47 »

line 101;
1  
2  
3  
4  
5  
6  
7  
      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);
         }
      });
 


1  
2  
3  
4  
5  
      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 Smiley
Offline ado

Senior Newbie





« Reply #4 - Posted 2013-08-19 23:04:52 »

thanks for the help.
I have since changed
Quote
1  
2  
3  
4  
5  
6  
 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);
         }
      });

to
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
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
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #5 - Posted 2013-08-20 07:20:32 »

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.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (16 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (33 views)
2014-08-22 19:31:30

atombrot (42 views)
2014-08-19 09:29:53

Tekkerue (41 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (26 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (73 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!