# Conflicts:
#	core/assets/bundles/bundle.properties
#	core/src/io/anuke/mindustry/content/Blocks.java
#	core/src/io/anuke/mindustry/input/Binding.java
This commit is contained in:
Anuken
2019-11-18 19:40:45 -05:00
6 changed files with 238 additions and 80 deletions

View File

@@ -53,9 +53,9 @@ public class Blocks implements ContentList{
powerSource, powerVoid, itemSource, itemVoid, liquidSource, message, illuminator,
//defense
scrapWall, scrapWallLarge, scrapWallHuge, scrapWallGigantic, thruster, //ok, these names are getting ridiculous, but at least I don't have humongous walls yet
copperWall, copperWallLarge, titaniumWall, titaniumWallLarge, plastaniumWall, plastaniumWallLarge, thoriumWall, thoriumWallLarge, door, doorLarge,
phaseWall, phaseWallLarge, surgeWall, surgeWallLarge, mender, mendProjector, overdriveProjector, forceProjector, shockMine,
scrapWall, scrapWallLarge, scrapWallHuge, scrapWallGigantic, thruster, //ok, these names are getting ridiculous, but at least I don't have humongous walls yet
//transport
conveyor, titaniumConveyor, armoredConveyor, distributor, junction, itemBridge, phaseConveyor, sorter, invertedSorter, router, overflowGate, massDriver,
@@ -712,75 +712,11 @@ public class Blocks implements ContentList{
consumes.power(0.50f);
}};
//endregion
//region sandbox
powerSource = new PowerSource("power-source"){{
requirements(Category.power, BuildVisibility.sandboxOnly, ItemStack.with());
alwaysUnlocked = true;
}};
powerVoid = new PowerVoid("power-void"){{
requirements(Category.power, BuildVisibility.sandboxOnly, ItemStack.with());
alwaysUnlocked = true;
}};
itemSource = new ItemSource("item-source"){{
requirements(Category.distribution, BuildVisibility.sandboxOnly, ItemStack.with());
alwaysUnlocked = true;
}};
itemVoid = new ItemVoid("item-void"){{
requirements(Category.distribution, BuildVisibility.sandboxOnly, ItemStack.with());
alwaysUnlocked = true;
}};
liquidSource = new LiquidSource("liquid-source"){{
requirements(Category.liquid, BuildVisibility.sandboxOnly, ItemStack.with());
alwaysUnlocked = true;
}};
message = new MessageBlock("message"){{
requirements(Category.effect, ItemStack.with(Items.graphite, 5));
}};
illuminator = new LightBlock("illuminator"){{
requirements(Category.effect, BuildVisibility.lightingOnly, ItemStack.with(Items.graphite, 4, Items.silicon, 2));
brightness = 0.67f;
radius = 120f;
consumes.power(0.05f);
}};
//endregion
//region defense
int wallHealthMultiplier = 4;
scrapWall = new Wall("scrap-wall"){{
requirements(Category.defense, BuildVisibility.sandboxOnly, ItemStack.with());
health = 60 * wallHealthMultiplier;
variants = 5;
}};
scrapWallLarge = new Wall("scrap-wall-large"){{
requirements(Category.defense, BuildVisibility.sandboxOnly, ItemStack.with());
health = 60 * 4 * wallHealthMultiplier;
size = 2;
variants = 4;
}};
scrapWallHuge = new Wall("scrap-wall-huge"){{
requirements(Category.defense, BuildVisibility.sandboxOnly, ItemStack.with());
health = 60 * 9 * wallHealthMultiplier;
size = 3;
variants = 3;
}};
scrapWallGigantic = new Wall("scrap-wall-gigantic"){{
requirements(Category.defense, BuildVisibility.sandboxOnly, ItemStack.with());
health = 60 * 16 * wallHealthMultiplier;
size = 4;
}};
thruster = new Wall("thruster"){{
health = 55 * 16 * wallHealthMultiplier;
size = 4;
}};
copperWall = new Wall("copper-wall"){{
requirements(Category.defense, ItemStack.with(Items.copper, 6));
health = 80 * wallHealthMultiplier;
@@ -862,6 +798,37 @@ public class Blocks implements ContentList{
size = 2;
}};
scrapWall = new Wall("scrap-wall"){{
requirements(Category.defense, BuildVisibility.sandboxOnly, ItemStack.with());
health = 60 * wallHealthMultiplier;
variants = 5;
}};
scrapWallLarge = new Wall("scrap-wall-large"){{
requirements(Category.defense, BuildVisibility.sandboxOnly, ItemStack.with());
health = 60 * 4 * wallHealthMultiplier;
size = 2;
variants = 4;
}};
scrapWallHuge = new Wall("scrap-wall-huge"){{
requirements(Category.defense, BuildVisibility.sandboxOnly, ItemStack.with());
health = 60 * 9 * wallHealthMultiplier;
size = 3;
variants = 3;
}};
scrapWallGigantic = new Wall("scrap-wall-gigantic"){{
requirements(Category.defense, BuildVisibility.sandboxOnly, ItemStack.with());
health = 60 * 16 * wallHealthMultiplier;
size = 4;
}};
thruster = new Wall("thruster"){{
health = 55 * 16 * wallHealthMultiplier;
size = 4;
}};
mender = new MendProjector("mender"){{
requirements(Category.effect, ItemStack.with(Items.lead, 30, Items.copper, 25));
consumes.power(0.3f);
@@ -1825,6 +1792,45 @@ public class Blocks implements ContentList{
consumes.power(1.2f);
}};
//endregion
//region sandbox
powerSource = new PowerSource("power-source"){{
requirements(Category.power, BuildVisibility.sandboxOnly, ItemStack.with());
alwaysUnlocked = true;
}};
powerVoid = new PowerVoid("power-void"){{
requirements(Category.power, BuildVisibility.sandboxOnly, ItemStack.with());
alwaysUnlocked = true;
}};
itemSource = new ItemSource("item-source"){{
requirements(Category.distribution, BuildVisibility.sandboxOnly, ItemStack.with());
alwaysUnlocked = true;
}};
itemVoid = new ItemVoid("item-void"){{
requirements(Category.distribution, BuildVisibility.sandboxOnly, ItemStack.with());
alwaysUnlocked = true;
}};
liquidSource = new LiquidSource("liquid-source"){{
requirements(Category.liquid, BuildVisibility.sandboxOnly, ItemStack.with());
alwaysUnlocked = true;
}};
message = new MessageBlock("message"){{
requirements(Category.effect, ItemStack.with(Items.graphite, 5));
}};
illuminator = new LightBlock("illuminator"){{
requirements(Category.effect, BuildVisibility.lightingOnly, ItemStack.with(Items.graphite, 4, Items.silicon, 2));
brightness = 0.67f;
radius = 120f;
consumes.power(0.05f);
}};
//endregion
}
}

View File

@@ -24,6 +24,22 @@ public enum Binding implements KeyBind{
schematic_flip_x(KeyCode.Z),
schematic_flip_y(KeyCode.X),
schematic_menu(KeyCode.T),
category_prev(KeyCode.COMMA),
category_next(KeyCode.PERIOD),
block_select_left(KeyCode.LEFT),
block_select_right(KeyCode.RIGHT),
block_select_up(KeyCode.UP),
block_select_down(KeyCode.DOWN),
block_select_01(KeyCode.NUM_1),
block_select_02(KeyCode.NUM_2),
block_select_03(KeyCode.NUM_3),
block_select_04(KeyCode.NUM_4),
block_select_05(KeyCode.NUM_5),
block_select_06(KeyCode.NUM_6),
block_select_07(KeyCode.NUM_7),
block_select_08(KeyCode.NUM_8),
block_select_09(KeyCode.NUM_9),
block_select_10(KeyCode.NUM_0),
zoom_hold(KeyCode.CONTROL_LEFT, "view"),
zoom(new Axis(KeyCode.SCROLL)),
menu(Core.app.getType() == ApplicationType.Android ? KeyCode.BACK : KeyCode.ESCAPE),

View File

@@ -23,4 +23,12 @@ public enum Category{
effect;
public static final Category[] all = values();
public Category prev(){
return all[(this.ordinal() - 1 + all.length) % all.length];
}
public Category next(){
return all[(this.ordinal() + 1) % all.length];
}
}

View File

@@ -221,6 +221,8 @@ public class SettingsMenuDialog extends SettingsDialog{
game.sliderPref("saveinterval", 60, 10, 5 * 120, 10, i -> Core.bundle.format("setting.seconds", i));
if(!mobile){
game.sliderPref("blockselecttimeout", 750, 0, 2000, 50, i -> Core.bundle.format("setting.milliseconds", i));
game.checkPref("crashreport", true);
}
@@ -306,6 +308,9 @@ public class SettingsMenuDialog extends SettingsDialog{
graphics.checkPref("minimap", !mobile);
graphics.checkPref("position", false);
graphics.checkPref("fps", false);
if(!mobile){
graphics.checkPref("blockselectkeys", true);
}
graphics.checkPref("indicators", true);
graphics.checkPref("animatedwater", !mobile);
if(Shaders.shield != null){

View File

@@ -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,78 @@ 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 = blocks.get(j);
selectedBlocks.put(currentCategory, input.block);
break;
}
}
}else if(blockSelectEnd || Time.timeSinceMillis(blockSelectSeqMillis) > Core.settings.getInt("blockselecttimeout")){ //1st number of combo, select category
//select only visible categories
if(!getByCategory(Category.all[i]).isEmpty()){
currentCategory = Category.all[i];
if(input.block != null){
input.block = getSelectedBlock(currentCategory);
}
blockSelectEnd = false;
blockSelectSeq = 0;
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) ? 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;
}
@@ -109,11 +200,6 @@ public class PlacementFragment extends Fragment{
blockTable.row();
}
if(!unlocked(block)){
blockTable.add().size(46);
continue;
}
ImageButton button = blockTable.addImageButton(Icon.lockedSmall, Styles.selecti, () -> {
if(unlocked(block)){
control.input.block = control.input.block == block ? null : block;
@@ -170,9 +256,22 @@ public class PlacementFragment extends Fragment{
lastGround = false;
topTable.table(header -> {
String keyCombo = "";
if(!mobile && Core.settings.getBool("blockselectkeys")){
Array<Block> blocks = getByCategory(currentCategory);
for(int i = 0; i < blocks.size; i++){
if(blocks.get(i) == lastDisplay){
keyCombo = Core.bundle.format("placement.blockselectkeys", Core.keybinds.get(blockSelect[currentCategory.ordinal()]).key.toString())
+ (i < 10 ? "" : Core.keybinds.get(blockSelect[(i + 1) / 10 - 1]).key.toString() + ",")
+ Core.keybinds.get(blockSelect[i % 10]).key.toString() + "]";
break;
}
}
}
final String keyComboFinal = keyCombo;
header.left();
header.add(new Image(lastDisplay.icon(Cicon.medium))).size(8 * 4);
header.labelWrap(() -> !unlocked(lastDisplay) ? Core.bundle.get("block.unknown") : lastDisplay.localizedName)
header.labelWrap(() -> !unlocked(lastDisplay) ? Core.bundle.get("block.unknown") : lastDisplay.localizedName + keyComboFinal)
.left().width(190f).padLeft(5);
header.add().growX();
if(unlocked(lastDisplay)){
@@ -265,7 +364,7 @@ public class PlacementFragment extends Fragment{
//update category empty values
for(Category cat : Category.all){
Array<Block> blocks = getByCategory(cat);
categoryEmpty[cat.ordinal()] = blocks.isEmpty() || !unlocked(blocks.first());
categoryEmpty[cat.ordinal()] = blocks.isEmpty();
}
int f = 0;
@@ -280,10 +379,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 +404,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 +416,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);
}
@@ -359,4 +462,4 @@ public class PlacementFragment extends Fragment{
Block tileDisplayBlock(){
return hoverTile == null ? null : hoverTile.block().synthetic() ? hoverTile.block() : hoverTile.drop() != null ? hoverTile.overlay().itemDrop != null ? hoverTile.overlay() : hoverTile.floor() : null;
}
}
}