Placement toggle support

This commit is contained in:
Anuken
2018-11-19 12:27:42 -05:00
parent ba01ed0153
commit c75cdc6d28

View File

@@ -16,6 +16,7 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.OreBlock; import io.anuke.mindustry.world.blocks.OreBlock;
import io.anuke.ucore.core.Graphics; import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.scene.Group; import io.anuke.ucore.scene.Group;
import io.anuke.ucore.scene.actions.Actions;
import io.anuke.ucore.scene.event.Touchable; import io.anuke.ucore.scene.event.Touchable;
import io.anuke.ucore.scene.ui.ButtonGroup; import io.anuke.ucore.scene.ui.ButtonGroup;
import io.anuke.ucore.scene.ui.Image; import io.anuke.ucore.scene.ui.Image;
@@ -30,16 +31,19 @@ public class PlacementFragment extends Fragment{
Array<Recipe> returned = new Array<>(); Array<Recipe> returned = new Array<>();
Category currentCategory = Category.turret; Category currentCategory = Category.turret;
Block hovered; Block hovered, lastDisplay;
Block lastDisplay;
Tile hoverTile; Tile hoverTile;
Table blockTable; Table blockTable, toggler;
boolean shown = true;
@Override @Override
public void build(Group parent){ public void build(Group parent){
parent.fill(frame -> { parent.fill(full -> {
InputHandler input = control.input(0); toggler = full;
full.bottom().right().visible(() -> !state.is(State.menu));
full.table(frame -> {
InputHandler input = control.input(0);
//rebuilds the category table with the correct recipes //rebuilds the category table with the correct recipes
Runnable rebuildCategory = () -> { Runnable rebuildCategory = () -> {
blockTable.clear(); blockTable.clear();
@@ -94,8 +98,6 @@ public class PlacementFragment extends Fragment{
blockTable.act(0f); blockTable.act(0f);
}; };
frame.bottom().right().visible(() -> !state.is(State.menu));
frame.table("clear", top -> { frame.table("clear", top -> {
top.add(new Table()).growX().update(topTable -> { top.add(new Table()).growX().update(topTable -> {
if((tileDisplayBlock() == null && lastDisplay == getSelected()) || if((tileDisplayBlock() == null && lastDisplay == getSelected()) ||
@@ -174,6 +176,7 @@ public class PlacementFragment extends Fragment{
rebuildCategory.run(); rebuildCategory.run();
}); });
});
} }
/**Returns the currently displayed block in the top box.*/ /**Returns the currently displayed block in the top box.*/
@@ -220,6 +223,12 @@ public class PlacementFragment extends Fragment{
} }
void toggle(float t, Interpolation ip){ void toggle(float t, Interpolation ip){
if(shown){
shown = false;
toggler.actions(Actions.translateBy(toggler.getTranslation().x + toggler.getWidth(), 0, t, ip));
}else{
shown = true;
toggler.actions(Actions.translateBy(-toggler.getTranslation().x, 0, t, ip));
}
} }
} }