This commit is contained in:
Anuken 2019-09-21 15:54:34 -04:00
parent 0d25d83651
commit 5955ecefd3
4 changed files with 25 additions and 6 deletions

View File

@ -208,9 +208,11 @@ public class Control implements ApplicationListener, Loadable{
}
public void setInput(InputHandler newInput){
Block block = input.block;
boolean added = Core.input.getInputProcessors().contains(input);
input.remove();
this.input = newInput;
newInput.block = block;
if(added){
newInput.add();
}

View File

@ -273,10 +273,23 @@ public abstract class InputHandler implements InputProcessor{
public void remove(){
Core.input.removeProcessor(this);
frag.remove();
if(Core.scene != null){
Table table = (Table)Core.scene.find("inputTable");
if(table != null){
table.clear();
}
}
}
public void add(){
Core.input.addProcessor(this);
if(Core.scene != null){
Table table = (Table)Core.scene.find("inputTable");
if(table != null){
table.clear();
buildUI(table);
}
}
}
public boolean canShoot(){

View File

@ -291,6 +291,7 @@ public class MobileInput extends InputHandler implements GestureListener{
}).visible(() -> !selection.isEmpty()).name("confirmplace");
Core.scene.table(t -> {
t.setName("cancelMobile");
t.bottom().left().visible(() -> (player.isBuilding() || block != null || mode == breaking) && !state.is(State.menu));
t.addImageTextButton("$cancel", Icon.cancelSmall, () -> {
player.clearBuilding();
@ -442,8 +443,8 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override
public void add(){
super.add();
Core.input.addProcessor(detector = new GestureDetector(20, 0.5f, 0.4f, 0.15f, this));
super.add();
}
@Override
@ -452,6 +453,10 @@ public class MobileInput extends InputHandler implements GestureListener{
if(detector != null){
Core.input.removeProcessor(detector);
}
if(Core.scene != null && Core.scene.find("cancelMobile") != null){
Core.scene.find("cancelMobile").remove();
}
}
@Override

View File

@ -116,7 +116,6 @@ public class PlacementFragment extends Fragment{
full.bottom().right().visible(() -> ui.hudfrag.shown());
full.table(frame -> {
InputHandler input = control.input;
//rebuilds the category table with the correct recipes
Runnable rebuildCategory = () -> {
@ -140,7 +139,7 @@ public class PlacementFragment extends Fragment{
ImageButton button = blockTable.addImageButton(Icon.lockedSmall, Styles.selecti, () -> {
if(unlocked(block)){
input.block = input.block == block ? null : block;
control.input.block = control.input.block == block ? null : block;
}
}).size(46f).group(group).name("block-" + block.name).get();
@ -150,7 +149,7 @@ public class PlacementFragment extends Fragment{
TileEntity core = player.getClosestCore();
Color color = state.rules.infiniteResources || (core != null && (core.items.has(block.buildRequirements, state.rules.buildCostMultiplier) || state.rules.infiniteResources)) ? Color.white : Color.gray;
button.forEach(elem -> elem.setColor(color));
button.setChecked(input.block == block);
button.setChecked(control.input.block == block);
});
button.hovered(() -> hovered = block);
@ -250,7 +249,7 @@ public class PlacementFragment extends Fragment{
blocksSelect.margin(4).marginTop(0);
blocksSelect.table(blocks -> blockTable = blocks).grow();
blocksSelect.row();
blocksSelect.table(input::buildUI).growX();
blocksSelect.table(control.input::buildUI).name("inputTable").growX();
}).fillY().bottom().touchable(Touchable.enabled);
frame.table(categories -> {
categories.defaults().size(50f);
@ -281,7 +280,7 @@ public class PlacementFragment extends Fragment{
rebuildCategory.run();
frame.update(() -> {
if(gridUpdate(input)) rebuildCategory.run();
if(gridUpdate(control.input)) rebuildCategory.run();
});
});
});