diff --git a/core/src/fr/evolving/UI/Menu.java b/core/src/fr/evolving/UI/Menu.java index 7e7fda9..cdbc2b6 100644 --- a/core/src/fr/evolving/UI/Menu.java +++ b/core/src/fr/evolving/UI/Menu.java @@ -6,6 +6,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.maps.MapLayers; +import com.badlogic.gdx.maps.MapProperties; import com.badlogic.gdx.maps.tiled.TiledMap; import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell; @@ -66,15 +67,24 @@ public void clear() layer.getCell(x, y).setTile(AssetLoader.tileSet.getTile(54)); } -public void setMenuTile(int x,int y,int tile) +public void setMenuTile(int x,int y,int tile,String title) { Cell cell=((TiledMapTileLayer)map.getLayers().get(0)).getCell(x,y); if (cell!=null) { cell.setTile(AssetLoader.tileSet.getTile(tile)); + cell.getTile().getProperties().put("name", title); Gdx.app.debug(getClass().getSimpleName(),"Tile find:"+tile+" coords"+x+","+y); } } +public int getSizeX() { + return tilesizex; +} + +public int getSizeY() { + return tilesizey; +} + public void setMenuTransmuter(int x,int y,String Name,Transmuter.Angular Angle) { Cell cell=((TiledMapTileLayer)map.getLayers().get(0)).getCell(x,y); @@ -89,23 +99,28 @@ public void setMenuTransmuter(int x,int y,String Name,Transmuter.Angular Angle) cell.setRotation(Angle.ordinal()); while(keySetIterator.hasNext()){ Vector2 key = keySetIterator.next(); - ((TiledMapTileLayer)map.getLayers().get(0)).getCell((int)(x+key.x),(int)(y+key.y)).setTile(AssetLoader.tileSet.getTile(MainTile++)); - ((TiledMapTileLayer)map.getLayers().get(0)).getCell((int)(x+key.x),(int)(y+key.y)).setRotation(Angle.ordinal()); + Cell subcell=((TiledMapTileLayer)map.getLayers().get(0)).getCell((int)(x+key.x),(int)(y+key.y)); + subcell.setTile(AssetLoader.tileSet.getTile(MainTile++)); + subcell.setRotation(Angle.ordinal()); + subcell.getTile().getProperties().put("movetox",(int) -key.x); + subcell.getTile().getProperties().put("movetoy",(int) -key.y); } } } } -public int getMenuTile(int x,int y) +public MapProperties getMenubyTile(int x,int y) { Cell cell=((TiledMapTileLayer)map.getLayers().get(0)).getCell(x,y); if (cell!=null) - return cell.getTile().getId(); + return cell.getTile().getProperties(); else - return 0; + return null; } + + public Vector2 screentoworld(float x, float y) { int xx=(int) ((x-1531f)/60f); int yy=(int) ((y-(AssetLoader.height-776f))/60f); diff --git a/core/src/fr/evolving/UI/TouchMaptiles.java b/core/src/fr/evolving/UI/TouchMaptiles.java index e028df6..67cdcf5 100644 --- a/core/src/fr/evolving/UI/TouchMaptiles.java +++ b/core/src/fr/evolving/UI/TouchMaptiles.java @@ -95,13 +95,15 @@ public void redraw(int tile) { for (int y=0;y frameTiles=new Array(maxid); for(int j=1;j<=maxid;j++) - frameTiles.add(new StaticTiledMapTile((Atlas_level.findRegion("sprite_"+id+"#"+j)))); + frameTiles.add(new StaticTiledMapTile((Atlas_level.findRegion("sprite-"+type[1]+"_"+id+"#"+j)))); AnimatedTiledMapTile atile=new AnimatedTiledMapTile(0.15f,frameTiles); Gdx.app.debug("AssetLoader","Taille:"+String.valueOf(frameTiles.size)); atile.setId(1000+id); + atile.getProperties().put("type", type[1]); tileSet.putTile(1000+id, atile); + } } } else { + String[] type=allregions.get(i).name.split("-"); StaticTiledMapTile atile= new StaticTiledMapTile(allregions.get(i)); atile.setId(allregions.get(i).index); + atile.getProperties().put("type", type[1]); tileSet.putTile(allregions.get(i).index, atile); - Gdx.app.debug("AssetLoader","Tiles N°:"+String.valueOf(allregions.get(i).index)); + Gdx.app.debug("AssetLoader","Type:"+type[1]+" Tiles N°:"+String.valueOf(allregions.get(i).index)); } } } @@ -161,7 +166,16 @@ public class AssetLoader { allTransmuter[0]=new Positiver_I(null); allTransmuter[1]=new Positiver_II(null); allTransmuter[2]=new Positiver_III(null); - } + for(int i=0;i=2) + event_coordination(x,y,button,calling.taptap,exec); + } + }); + map.addListener(new InputListener(){ @Override public boolean mouseMoved(InputEvent event,float x,float y) { String[] exec={"transmuter"}; return event_coordination(x,y,0,calling.mouseover,exec); } - @Override - public boolean scrolled(InputEvent event,float x,float y,int amount) { - String[] exec={"transmuter"}; - Gdx.app.debug(event.getListenerActor().toString(),"Coordonnées:"); - return event_coordination(x,y,amount,calling.mousescroll,exec); - } + @Override - public void clicked(InputEvent event, float x, float y) { + public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { oldx=0; oldy=0; String[] exec={"cleaner","infos","zoomp","zoomm","copper_pen","fiber_pen","copper_eraser","fiber_eraser","transmuter_eraser","all_eraser","blank","transmuter","copper_brush","fiber_brush"}; - if (this.getTapCount()>=2) - event_coordination(x,y,0,calling.mousex2click,exec); - else - event_coordination(x,y,0,calling.mouseclick,exec); + return event_coordination(x,y,button,calling.mouseclick,exec); } @Override public void touchDragged(InputEvent event, float x, float y, int pointer) { @@ -404,58 +394,39 @@ public class GameScreen implements Screen { menu=new Menu(4,8); map.addListener(new ClickListener(){ @Override - public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { + public void clicked(InputEvent event, float x, float y) { mapexit=true; Vector2 coords=menu.screentoworld(x,y); - int tile=menu.getMenuTile((int)coords.x,(int)coords.y); - Gdx.app.debug(event.getListenerActor().toString(),"Coordonnées:"+x+"x"+y+" Coordonnées deprojettée:"+coords.x+"x"+coords.y+" tile:"+tile); - if (menuactor==null) - menuactor=new Actor(); - if (tile!=54 && tile!=0) { + MapProperties tile=menu.getMenubyTile((int)coords.x,(int)coords.y); + if (tile!=null && tile.containsKey("name")) + { + Gdx.app.debug("menu","Coordonnées:"+x+"x"+y+" Coordonnées deprojettée:"+coords.x+"x"+coords.y+" type:"+tile.get("type")+" name:"+tile.get("name").toString()); + if (menuactor==null) + menuactor=new Actor(); Vector2 coords2=menu.worldtoscreen((int)coords.x,(int)coords.y); menuactor.setBounds(coords2.x, coords2.y, 60, 60); selected=menuactor; map.fillempty(60); - if (tile==71) - selected.setName("copper_pen"); - if (tile==72) - selected.setName("copper_brush"); - if (tile==73) - selected.setName("copper_eraser"); - if (tile==74) - selected.setName("fiber_pen"); - if (tile==75) - selected.setName("fiber_brush"); - if (tile==76) - selected.setName("fiber_eraser"); - if (tile==77) - selected.setName("transmuter_eraser"); - if (tile==78) - selected.setName("all_eraser"); - if (tile==79) - selected.setName("cleaner"); - else if (tile==70) - selected.setName("blank"); - else if (tile>99) { - Transmuter transmuter=AssetLoader.getTransmuter(tile); - if (transmuter!=null) { - showInfo(transmuter); - Vector2 gotomain=transmuter.getPostitionMainTile(tile); - if (gotomain!=null) { - coords2=menu.worldtoscreen((int)(coords.x+gotomain.x),(int)(coords.y+gotomain.y)); - menuactor.setPosition(coords2.x, coords2.y); - selected.setName("transmuter"); - selected_transmuter=(Transmuter) transmuter.clone(); - Gdx.app.debug(event.getListenerActor().toString(),"transmuter deplacement vers origine:"+String.valueOf(gotomain.x)+","+String.valueOf(gotomain.y)+" coords:"+coords2.x+"x"+coords2.y); + if (tile.get("type").toString().startsWith("transmuter")) + { + selected.setName("transmuter"); + selected_transmuter=(Transmuter) ((Transmuter) tile.get("transmuter")).clone(); + if (selected_transmuter!=null) { + showInfo(selected_transmuter); + if (tile.containsKey("movetox")) { + coords2=menu.worldtoscreen((int)coords.x+(Integer) tile.get("movetox"),(int)(coords.y+(Integer) tile.get("movetoy"))); + menuactor.setPosition(coords2.x, coords2.y); + Gdx.app.debug("menu","transmuter deplacement vers origine:"+tile.get("movetox").toString()+","+tile.get("movetoy").toString()+" coords:"+coords2.x+"x"+coords2.y); + } } } + else + selected.setName(tile.get("name").toString()); } - } - return false; } - }); + }); } - + boolean event_coordination(float x,float y,int button, calling call, String[] exec) { if (selected!=null) { if (Arrays.asList(exec).contains(selected.getName())) { @@ -463,7 +434,8 @@ public class GameScreen implements Screen { if (level.Grid.GetXY(coords.x,coords.y)!=null) { mapexit=false; - Gdx.app.debug("evenement","mode:"+call+" outil:"+selected.getName()+ " X: " + coords.x + " Y: " + coords.y); + if (call!=calling.mouseover) + Gdx.app.debug("evenement","mode:"+call+" outil:"+selected.getName()+ " X: " + coords.x + " Y: " + coords.y+" button:"+button); Method method; try { Class base = Class.forName("fr.evolving.screens.GameScreen"); @@ -489,7 +461,7 @@ public class GameScreen implements Screen { } void map_transmuter(float realx, float realy,int x, int y,boolean alone,int button,calling call) { - if (call==calling.mousescroll || call==calling.mousex2click) + if (call==calling.taptap && button==0 || (call==calling.mouseclick && button==1)) { Angular angle=selected_transmuter.getRotation(); if (angle==Angular.A00) @@ -515,16 +487,17 @@ public class GameScreen implements Screen { while(keySetIterator.hasNext()){ Vector2 key = keySetIterator.next(); color=63; - if (((!level.Grid.GetFiber(x+key.x, y+key.y) && !level.Grid.getCopper(x+key.x, y+key.y) && tiles.get(key)==CaseType.Rien) || (level.Grid.GetFiber(x+key.x, y+key.y) && level.Grid.getCopper(x+key.x, y+key.y) && tiles.get(key)==CaseType.Tout) || (level.Grid.GetFiber(x+key.x, y+key.y) && !level.Grid.getCopper(x+key.x, y+key.y) && tiles.get(key)==CaseType.Fibre) || (level.Grid.getCopper(x+key.x, y+key.y) && !level.Grid.GetFiber(x+key.x, y+key.y) && tiles.get(key)==CaseType.Cuivre)) && (level.Grid.getTransmutercalc(x+key.x, y+key.y)==0)) + if (((!level.Grid.getFiber(x+key.x, y+key.y) && !level.Grid.getCopper(x+key.x, y+key.y) && tiles.get(key)==CaseType.Rien) || (level.Grid.getFiber(x+key.x, y+key.y) && level.Grid.getCopper(x+key.x, y+key.y) && tiles.get(key)==CaseType.Tout) || (level.Grid.getFiber(x+key.x, y+key.y) && !level.Grid.getCopper(x+key.x, y+key.y) && tiles.get(key)==CaseType.Fibre) || (level.Grid.getCopper(x+key.x, y+key.y) && !level.Grid.getFiber(x+key.x, y+key.y) && tiles.get(key)==CaseType.Cuivre)) && (level.Grid.getTransmutercalc(x+key.x, y+key.y)==0)) color=0; else positionisgood=false; map.tempdraw(x+key.x, y+key.y, ++MainTile, selected_transmuter.getRotation().ordinal(),color); - if (call==calling.mouseclick && positionisgood && button!=1) + if ((call==calling.longpress && button==0) && positionisgood) { level.Grid.GetXY(x,y).Transmuter=(Transmuter) selected_transmuter.clone(); if (alone) level.Grid.tiling_transmuter(); - map.redraw(53); + map.redraw(60); + Gdx.input.vibrate(new long[] { 0, 400, 500, 400}, -1); } } } @@ -539,13 +512,10 @@ public class GameScreen implements Screen { if (level.Grid.GetXY(x,y).Fiber>0) Gdx.app.debug("map","*** Présence de fibre"); if (level.Grid.GetXY(x,y).Transmuter_calc>0) { - Vector2 gotomain=AssetLoader.resolveTransmuterMain(level.Grid.GetXY(x,y).Transmuter_calc); - if (gotomain!=null) { - Gdx.app.debug("map","transmuter deplacement vers origine:"+String.valueOf(gotomain.x)+","+String.valueOf(gotomain.y)+" coords:"+(x+gotomain.x)+"x"+(y+gotomain.y)); - //Gdx.app.debug("map",level.Grid.getTransmuter(x+gotomain.x,y+gotomain.y).getInformations()); - showInfo(level.Grid.getTransmuter(x+gotomain.x,y+gotomain.y)); + Gdx.app.debug("map","transmuter deplacement vers origine:"+level.Grid.GetXY(x,y).Transmuter_movex+","+level.Grid.GetXY(x,y).Transmuter_movey+" coords:"+(x+level.Grid.GetXY(x,y).Transmuter_movex)+"x"+(y+level.Grid.GetXY(x,y).Transmuter_movey)); + Gdx.app.debug("map",level.Grid.getTransmuter(x+level.Grid.GetXY(x,y).Transmuter_movex,y+level.Grid.GetXY(x,y).Transmuter_movey).getInformations()); + showInfo(level.Grid.getTransmuter(x+level.Grid.GetXY(x,y).Transmuter_movex,y+level.Grid.GetXY(x,y).Transmuter_movey)); } - } } else hideInfo(); @@ -597,17 +567,14 @@ public class GameScreen implements Screen { void map_transmuter_eraser(float realx, float realy,int x, int y,boolean alone,int button,calling call) { if (level.Grid.GetXY(x,y).Transmuter_calc!=0) { - Vector2 gotomain=AssetLoader.resolveTransmuterMain(level.Grid.GetXY(x,y).Transmuter_calc); - if (gotomain!=null) { - level.Grid.GetXY(x+gotomain.x,y+gotomain.y).Transmuter=null; - Gdx.app.debug("map","transmuter deplacement vers origine:"+String.valueOf(gotomain.x)+","+String.valueOf(gotomain.y)+" coords:"+(x+gotomain.x)+"x"+(y+gotomain.y)); + level.Grid.GetXY(x+level.Grid.GetXY(x,y).Transmuter_movex,y+level.Grid.GetXY(x,y).Transmuter_movey).Transmuter=null; + Gdx.app.debug("map","transmuter deplacement vers origine:"+level.Grid.GetXY(x,y).Transmuter_movex+","+level.Grid.GetXY(x,y).Transmuter_movey+" coords:"+(x+level.Grid.GetXY(x,y).Transmuter_movex)+"x"+(y+level.Grid.GetXY(x,y).Transmuter_movey)); } if (alone) { level.Grid.tiling_transmuter(); - map.redraw(53); + map.redraw(60); } } - } void map_fiber_eraser(float realx, float realy,int x, int y,boolean alone,int button,calling call) { level.Grid.GetXY(x,y).Fiber=0; @@ -713,8 +680,21 @@ public class GameScreen implements Screen { stage.addActor(menu); processors.add(stage); processors.add(stage_menu); + gesturedetector=new GestureDetector(null); + processors.add(gesturedetector); multiplexer.setProcessors(processors); - Gdx.input.setInputProcessor(multiplexer); + Gdx.input.setInputProcessor(multiplexer); + //Gdx.input.setInputProcessor(multiplexer); + } + + public void preparemenu(int menuitem) { + Gdx.app.debug("menu","Affichage sousmenu "+menuitem); + checkMenu(menuitem,true); + menu.clear(); + map.tempclear(); + map.fillempty(53); + selected=null; + hideInfo(); } public void showInfo(Transmuter transmuter) { @@ -751,7 +731,6 @@ public class GameScreen implements Screen { public void hideInfo() { unroll=false; - } public void checkMenu(int menu,boolean check)