Placement toggle support
This commit is contained in:
@@ -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,149 +31,151 @@ 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));
|
||||||
|
|
||||||
//rebuilds the category table with the correct recipes
|
full.table(frame -> {
|
||||||
Runnable rebuildCategory = () -> {
|
InputHandler input = control.input(0);
|
||||||
blockTable.clear();
|
//rebuilds the category table with the correct recipes
|
||||||
blockTable.top().margin(5);
|
Runnable rebuildCategory = () -> {
|
||||||
|
blockTable.clear();
|
||||||
|
blockTable.top().margin(5);
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||||
group.setMinCheckCount(0);
|
group.setMinCheckCount(0);
|
||||||
|
|
||||||
for(Recipe recipe : recipes(currentCategory)){
|
for(Recipe recipe : recipes(currentCategory)){
|
||||||
|
|
||||||
if(index++ % rowWidth == 0){
|
if(index++ % rowWidth == 0){
|
||||||
blockTable.row();
|
blockTable.row();
|
||||||
}
|
|
||||||
|
|
||||||
boolean[] unlocked = {false};
|
|
||||||
|
|
||||||
ImageButton button = blockTable.addImageButton("icon-locked", "select", 8*4, () -> {
|
|
||||||
if(control.unlocks.isUnlocked(recipe)){
|
|
||||||
input.recipe = input.recipe == recipe ? null : recipe;
|
|
||||||
}
|
}
|
||||||
}).size(46f).group(group).get();
|
|
||||||
|
|
||||||
button.update(() -> { //color unplacable things gray
|
boolean[] unlocked = {false};
|
||||||
boolean ulock = control.unlocks.isUnlocked(recipe);
|
|
||||||
TileEntity core = players[0].getClosestCore();
|
|
||||||
Color color = core != null && core.items.has(recipe.requirements) ? Color.WHITE : ulock ? Color.GRAY : Color.WHITE;
|
|
||||||
button.forEach(elem -> elem.setColor(color));
|
|
||||||
button.setChecked(input.recipe == recipe);
|
|
||||||
|
|
||||||
if(ulock == unlocked[0]) return;
|
ImageButton button = blockTable.addImageButton("icon-locked", "select", 8*4, () -> {
|
||||||
unlocked[0] = ulock;
|
if(control.unlocks.isUnlocked(recipe)){
|
||||||
|
input.recipe = input.recipe == recipe ? null : recipe;
|
||||||
|
}
|
||||||
|
}).size(46f).group(group).get();
|
||||||
|
|
||||||
if(!ulock){
|
button.update(() -> { //color unplacable things gray
|
||||||
button.replaceImage(new Image("icon-locked"));
|
boolean ulock = control.unlocks.isUnlocked(recipe);
|
||||||
}else{
|
TileEntity core = players[0].getClosestCore();
|
||||||
button.replaceImage(new ImageStack(recipe.result.getCompactIcon()));
|
Color color = core != null && core.items.has(recipe.requirements) ? Color.WHITE : ulock ? Color.GRAY : Color.WHITE;
|
||||||
}
|
button.forEach(elem -> elem.setColor(color));
|
||||||
});
|
button.setChecked(input.recipe == recipe);
|
||||||
|
|
||||||
if(!mobile){
|
if(ulock == unlocked[0]) return;
|
||||||
button.hovered(() -> hovered = recipe.result);
|
unlocked[0] = ulock;
|
||||||
button.exited(() -> {
|
|
||||||
if(hovered == recipe.result){
|
if(!ulock){
|
||||||
hovered = null;
|
button.replaceImage(new Image("icon-locked"));
|
||||||
|
}else{
|
||||||
|
button.replaceImage(new ImageStack(recipe.result.getCompactIcon()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(!mobile){
|
||||||
|
button.hovered(() -> hovered = recipe.result);
|
||||||
|
button.exited(() -> {
|
||||||
|
if(hovered == recipe.result){
|
||||||
|
hovered = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
blockTable.act(0f);
|
blockTable.act(0f);
|
||||||
};
|
};
|
||||||
|
|
||||||
frame.bottom().right().visible(() -> !state.is(State.menu));
|
frame.table("clear", top -> {
|
||||||
|
top.add(new Table()).growX().update(topTable -> {
|
||||||
|
if((tileDisplayBlock() == null && lastDisplay == getSelected()) ||
|
||||||
|
(tileDisplayBlock() != null && lastDisplay == tileDisplayBlock())) return;
|
||||||
|
|
||||||
frame.table("clear", top -> {
|
topTable.clear();
|
||||||
top.add(new Table()).growX().update(topTable -> {
|
topTable.top().left().margin(5);
|
||||||
if((tileDisplayBlock() == null && lastDisplay == getSelected()) ||
|
|
||||||
(tileDisplayBlock() != null && lastDisplay == tileDisplayBlock())) return;
|
|
||||||
|
|
||||||
topTable.clear();
|
lastDisplay = getSelected();
|
||||||
topTable.top().left().margin(5);
|
|
||||||
|
|
||||||
lastDisplay = getSelected();
|
if(lastDisplay != null){ //show selected recipe
|
||||||
|
topTable.table(header -> {
|
||||||
if(lastDisplay != null){ //show selected recipe
|
header.left();
|
||||||
topTable.table(header -> {
|
header.add(new ImageStack(lastDisplay.getCompactIcon())).size(8*4);
|
||||||
header.left();
|
header.labelWrap(() ->
|
||||||
header.add(new ImageStack(lastDisplay.getCompactIcon())).size(8*4);
|
|
||||||
header.labelWrap(() ->
|
|
||||||
!control.unlocks.isUnlocked(Recipe.getByResult(lastDisplay)) ? Bundles.get("text.blocks.unknown") : lastDisplay.formalName)
|
!control.unlocks.isUnlocked(Recipe.getByResult(lastDisplay)) ? Bundles.get("text.blocks.unknown") : lastDisplay.formalName)
|
||||||
.left().width(190f).padLeft(5);
|
.left().width(190f).padLeft(5);
|
||||||
header.add().growX();
|
header.add().growX();
|
||||||
if(control.unlocks.isUnlocked(Recipe.getByResult(lastDisplay))){
|
if(control.unlocks.isUnlocked(Recipe.getByResult(lastDisplay))){
|
||||||
header.addButton("?", "clear-partial", () -> ui.content.show(Recipe.getByResult(lastDisplay)))
|
header.addButton("?", "clear-partial", () -> ui.content.show(Recipe.getByResult(lastDisplay)))
|
||||||
.size(8 * 5).padTop(-5).padRight(-5).right().grow();
|
.size(8 * 5).padTop(-5).padRight(-5).right().grow();
|
||||||
}
|
}
|
||||||
}).growX().left();
|
}).growX().left();
|
||||||
topTable.row();
|
topTable.row();
|
||||||
//add requirement table
|
//add requirement table
|
||||||
topTable.table(req -> {
|
topTable.table(req -> {
|
||||||
req.top().left();
|
req.top().left();
|
||||||
|
|
||||||
for(ItemStack stack : Recipe.getByResult(lastDisplay).requirements){
|
for(ItemStack stack : Recipe.getByResult(lastDisplay).requirements){
|
||||||
req.table(line -> {
|
req.table(line -> {
|
||||||
line.left();
|
line.left();
|
||||||
line.addImage(stack.item.region).size(8*2);
|
line.addImage(stack.item.region).size(8*2);
|
||||||
line.add(stack.item.localizedName()).color(Color.LIGHT_GRAY).padLeft(2).left();
|
line.add(stack.item.localizedName()).color(Color.LIGHT_GRAY).padLeft(2).left();
|
||||||
line.labelWrap(() -> {
|
line.labelWrap(() -> {
|
||||||
TileEntity core = players[0].getClosestCore();
|
TileEntity core = players[0].getClosestCore();
|
||||||
if(core == null || state.mode.infiniteResources) return "*/*";
|
if(core == null || state.mode.infiniteResources) return "*/*";
|
||||||
|
|
||||||
int amount = core.items.get(stack.item);
|
int amount = core.items.get(stack.item);
|
||||||
String color = (amount < stack.amount / 2f ? "[red]" : amount < stack.amount ? "[accent]" : "[white]");
|
String color = (amount < stack.amount / 2f ? "[red]" : amount < stack.amount ? "[accent]" : "[white]");
|
||||||
|
|
||||||
return color + ui.formatAmount(amount) + "[white]/" + stack.amount;
|
return color + ui.formatAmount(amount) + "[white]/" + stack.amount;
|
||||||
}).padLeft(5);
|
}).padLeft(5);
|
||||||
}).left();
|
}).left();
|
||||||
req.row();
|
req.row();
|
||||||
}
|
}
|
||||||
}).growX().left().margin(3);
|
}).growX().left().margin(3);
|
||||||
|
|
||||||
}else if(tileDisplayBlock() != null){ //show selected tile
|
}else if(tileDisplayBlock() != null){ //show selected tile
|
||||||
lastDisplay = tileDisplayBlock();
|
lastDisplay = tileDisplayBlock();
|
||||||
topTable.add(new ImageStack(lastDisplay.getDisplayIcon(hoverTile))).size(8*4);
|
topTable.add(new ImageStack(lastDisplay.getDisplayIcon(hoverTile))).size(8*4);
|
||||||
topTable.labelWrap(lastDisplay.getDisplayName(hoverTile)).left().width(190f).padLeft(5);
|
topTable.labelWrap(lastDisplay.getDisplayName(hoverTile)).left().width(190f).padLeft(5);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
top.row();
|
||||||
|
top.addImage("blank").growX().color(Palette.accent).height(3f);
|
||||||
|
}).colspan(3).fillX().visible(() -> getSelected() != null || tileDisplayBlock() != null).touchable(Touchable.enabled);
|
||||||
|
frame.row();
|
||||||
|
frame.table("clear", blocks -> blockTable = blocks).fillY().bottom().touchable(Touchable.enabled);
|
||||||
|
frame.addImage("blank").width(3f).fillY().color(Palette.accent);
|
||||||
|
frame.table(categories -> {
|
||||||
|
categories.defaults().size(48f);
|
||||||
|
|
||||||
|
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||||
|
|
||||||
|
for(Category cat : Category.values()){
|
||||||
|
if(recipes(cat).isEmpty()) continue;
|
||||||
|
|
||||||
|
categories.addImageButton("icon-" + cat.name(), "clear-toggle", 16*2, () -> {
|
||||||
|
currentCategory = cat;
|
||||||
|
rebuildCategory.run();
|
||||||
|
}).group(group);
|
||||||
|
|
||||||
|
if(cat.ordinal() %2 == 1) categories.row();
|
||||||
}
|
}
|
||||||
});
|
}).touchable(Touchable.enabled);
|
||||||
top.row();
|
|
||||||
top.addImage("blank").growX().color(Palette.accent).height(3f);
|
|
||||||
}).colspan(3).fillX().visible(() -> getSelected() != null || tileDisplayBlock() != null).touchable(Touchable.enabled);
|
|
||||||
frame.row();
|
|
||||||
frame.table("clear", blocks -> blockTable = blocks).fillY().bottom().touchable(Touchable.enabled);
|
|
||||||
frame.addImage("blank").width(3f).fillY().color(Palette.accent);
|
|
||||||
frame.table(categories -> {
|
|
||||||
categories.defaults().size(48f);
|
|
||||||
|
|
||||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
rebuildCategory.run();
|
||||||
|
});
|
||||||
for(Category cat : Category.values()){
|
|
||||||
if(recipes(cat).isEmpty()) continue;
|
|
||||||
|
|
||||||
categories.addImageButton("icon-" + cat.name(), "clear-toggle", 16*2, () -> {
|
|
||||||
currentCategory = cat;
|
|
||||||
rebuildCategory.run();
|
|
||||||
}).group(group);
|
|
||||||
|
|
||||||
if(cat.ordinal() %2 == 1) categories.row();
|
|
||||||
}
|
|
||||||
}).touchable(Touchable.enabled);
|
|
||||||
|
|
||||||
rebuildCategory.run();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user