Implement number and directional category/block selection hotkeys
This commit is contained in:
@@ -221,6 +221,8 @@ public class SettingsMenuDialog extends SettingsDialog{
|
||||
game.sliderPref("saveinterval", 60, 10, 5 * 120, i -> Core.bundle.format("setting.seconds", i));
|
||||
|
||||
if(!mobile){
|
||||
game.sliderPref("blockselecttimeout", 750, 0, 2000, i -> Core.bundle.format("setting.milliseconds", i));
|
||||
|
||||
game.checkPref("crashreport", true);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import static io.anuke.mindustry.Vars.*;
|
||||
public class PlacementFragment extends Fragment{
|
||||
final int rowWidth = 4;
|
||||
|
||||
public Category currentCategory = Category.distribution;
|
||||
public Category currentCategory = Category.turret;
|
||||
Array<Block> returnArray = new Array<>();
|
||||
Array<Category> returnCatArray = new Array<>();
|
||||
boolean[] categoryEmpty = new boolean[Category.all.length];
|
||||
@@ -36,6 +36,25 @@ public class PlacementFragment extends Fragment{
|
||||
Tile hoverTile;
|
||||
Table blockTable, toggler, topTable;
|
||||
boolean lastGround;
|
||||
boolean blockSelectEnd;
|
||||
int blockSelectSeq;
|
||||
long blockSelectSeqMillis;
|
||||
Binding[] blockSelect = {
|
||||
Binding.block_select_01,
|
||||
Binding.block_select_02,
|
||||
Binding.block_select_03,
|
||||
Binding.block_select_04,
|
||||
Binding.block_select_05,
|
||||
Binding.block_select_06,
|
||||
Binding.block_select_07,
|
||||
Binding.block_select_08,
|
||||
Binding.block_select_09,
|
||||
Binding.block_select_10,
|
||||
Binding.block_select_left,
|
||||
Binding.block_select_right,
|
||||
Binding.block_select_up,
|
||||
Binding.block_select_down
|
||||
};
|
||||
|
||||
public PlacementFragment(){
|
||||
Events.on(WorldLoadEvent.class, event -> {
|
||||
@@ -83,6 +102,75 @@ public class PlacementFragment extends Fragment{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(ui.chatfrag.chatOpen()) return false;
|
||||
for(int i = 0; i < blockSelect.length; i++){
|
||||
if(Core.input.keyTap(blockSelect[i])){
|
||||
if(i > 9) { //select block directionally
|
||||
Array<Block> blocks = getByCategory(currentCategory);
|
||||
Block currentBlock = getSelectedBlock(currentCategory);
|
||||
for(int j = 0; j < blocks.size; j++){
|
||||
if(blocks.get(j) == currentBlock){
|
||||
switch(i){
|
||||
case 10: //left
|
||||
j = (j - 1 + blocks.size) % blocks.size;
|
||||
break;
|
||||
case 11: //right
|
||||
j = (j + 1) % blocks.size;
|
||||
break;
|
||||
case 12: //up
|
||||
j = (j > 3 ? j - 4 : blocks.size - blocks.size % 4 + j);
|
||||
j -= (j < blocks.size ? 0 : 4);
|
||||
break;
|
||||
case 13: //down
|
||||
j = (j < blocks.size - 4 ? j + 4 : j % 4);
|
||||
}
|
||||
input.block = (unlocked(blocks.get(j))) ? blocks.get(j) : null;
|
||||
selectedBlocks.put(currentCategory, input.block);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else if(blockSelectEnd || Time.timeSinceMillis(blockSelectSeqMillis) > Core.settings.getInt("blockselecttimeout")){ //1st number of combo, select category
|
||||
currentCategory = Category.all[i];
|
||||
if(input.block != null){
|
||||
input.block = getSelectedBlock(currentCategory);
|
||||
}
|
||||
blockSelectSeq = 0;
|
||||
blockSelectEnd = false;
|
||||
blockSelectSeqMillis = Time.millis();
|
||||
}else{ //select block
|
||||
if(blockSelectSeq == 0){ //2nd number of combo
|
||||
blockSelectSeq = i + 1;
|
||||
}else{ //3rd number of combo
|
||||
//entering "X,1,0" selects the same block as "X,0"
|
||||
i += (blockSelectSeq - (i != 9 ? 0 : 1)) * 10;
|
||||
blockSelectEnd = true;
|
||||
}
|
||||
Array<Block> blocks = getByCategory(currentCategory);
|
||||
input.block = (i < blocks.size && unlocked(blocks.get(i))) ? blocks.get(i) : null;
|
||||
selectedBlocks.put(currentCategory, input.block);
|
||||
blockSelectSeqMillis = Time.millis();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(Core.input.keyTap(Binding.category_prev)){
|
||||
do{
|
||||
currentCategory = currentCategory.prev();
|
||||
}while(categoryEmpty[currentCategory.ordinal()]);
|
||||
input.block = getSelectedBlock(currentCategory);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(Core.input.keyTap(Binding.category_next)){
|
||||
do{
|
||||
currentCategory = currentCategory.next();
|
||||
}while(categoryEmpty[currentCategory.ordinal()]);
|
||||
input.block = getSelectedBlock(currentCategory);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -280,10 +368,7 @@ public class PlacementFragment extends Fragment{
|
||||
categories.addImageButton(Core.atlas.drawable("icon-" + cat.name() + "-smaller"), Styles.clearToggleTransi, () -> {
|
||||
currentCategory = cat;
|
||||
if(control.input.block != null){
|
||||
if(selectedBlocks.get(currentCategory) == null){
|
||||
selectedBlocks.put(currentCategory, getByCategory(currentCategory).find(this::unlocked));
|
||||
}
|
||||
control.input.block = selectedBlocks.get(currentCategory);
|
||||
control.input.block = getSelectedBlock(currentCategory);
|
||||
}
|
||||
rebuildCategory.run();
|
||||
}).group(group).update(i -> i.setChecked(currentCategory == cat)).name("category-" + cat.name());
|
||||
@@ -308,7 +393,7 @@ public class PlacementFragment extends Fragment{
|
||||
Array<Block> getByCategory(Category cat){
|
||||
returnArray.clear();
|
||||
for(Block block : content.blocks()){
|
||||
if(block.category == cat && block.isVisible()){
|
||||
if(block.category == cat && block.isVisible() && unlocked(block)){
|
||||
returnArray.add(block);
|
||||
}
|
||||
}
|
||||
@@ -320,6 +405,13 @@ public class PlacementFragment extends Fragment{
|
||||
return returnArray;
|
||||
}
|
||||
|
||||
Block getSelectedBlock(Category cat){
|
||||
if(selectedBlocks.get(cat) == null){
|
||||
selectedBlocks.put(cat, getByCategory(cat).find(this::unlocked));
|
||||
}
|
||||
return selectedBlocks.get(cat);
|
||||
}
|
||||
|
||||
boolean unlocked(Block block){
|
||||
return !world.isZone() || data.isUnlocked(block);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user