Gridmode and eyedropper select (#372)
* Gridmode Adds keybindings to category and block selection * bugfixes and comments * more keybind * Update PlacementFragment.java * Update PlacementFragment.java * eyedropper crashfix * formatted with default.xml
This commit is contained in:
@@ -601,9 +601,10 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
|||||||
|
|
||||||
float xa = Inputs.getAxis(section, "move_x");
|
float xa = Inputs.getAxis(section, "move_x");
|
||||||
float ya = Inputs.getAxis(section, "move_y");
|
float ya = Inputs.getAxis(section, "move_y");
|
||||||
|
if(!Inputs.keyDown("gridMode")){
|
||||||
movement.y += ya * speed;
|
movement.y += ya * speed;
|
||||||
movement.x += xa * speed;
|
movement.x += xa * speed;
|
||||||
|
}
|
||||||
|
|
||||||
Vector2 vec = Graphics.world(control.input(playerIndex).getMouseX(), control.input(playerIndex).getMouseY());
|
Vector2 vec = Graphics.world(control.input(playerIndex).getMouseX(), control.input(playerIndex).getMouseY());
|
||||||
pointerX = vec.x;
|
pointerX = vec.x;
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ public class DefaultKeybinds{
|
|||||||
"rotate", new Axis(Input.SCROLL),
|
"rotate", new Axis(Input.SCROLL),
|
||||||
"dash", Input.SHIFT_LEFT,
|
"dash", Input.SHIFT_LEFT,
|
||||||
"drop_unit", Input.SHIFT_LEFT,
|
"drop_unit", Input.SHIFT_LEFT,
|
||||||
|
"gridMode", Input.ALT_LEFT,
|
||||||
|
"gridModeShift", Input.SHIFT_LEFT,
|
||||||
new Category("view"),
|
new Category("view"),
|
||||||
"zoom_hold", Input.CONTROL_LEFT,
|
"zoom_hold", Input.CONTROL_LEFT,
|
||||||
"zoom", new Axis(Input.SCROLL),
|
"zoom", new Axis(Input.SCROLL),
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ public class HudFragment extends Fragment{
|
|||||||
}
|
}
|
||||||
|
|
||||||
cont.update(() -> {
|
cont.update(() -> {
|
||||||
if(Inputs.keyTap("toggle_menus") && !ui.chatfrag.chatOpen()){
|
if(!Inputs.keyDown("gridMode") && Inputs.keyTap("toggle_menus") && !ui.chatfrag.chatOpen()){
|
||||||
toggleMenus();
|
toggleMenus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package io.anuke.mindustry.ui.fragments;
|
|||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.math.Interpolation;
|
import com.badlogic.gdx.math.Interpolation;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
import com.badlogic.gdx.utils.Array;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.game.EventType.WorldLoadGraphicsEvent;
|
import io.anuke.mindustry.game.EventType.WorldLoadGraphicsEvent;
|
||||||
@@ -17,6 +18,8 @@ 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.Events;
|
import io.anuke.ucore.core.Events;
|
||||||
import io.anuke.ucore.core.Graphics;
|
import io.anuke.ucore.core.Graphics;
|
||||||
|
import io.anuke.ucore.core.Inputs;
|
||||||
|
import io.anuke.ucore.input.Input;
|
||||||
import io.anuke.ucore.scene.Group;
|
import io.anuke.ucore.scene.Group;
|
||||||
import io.anuke.ucore.scene.actions.Actions;
|
import io.anuke.ucore.scene.actions.Actions;
|
||||||
import io.anuke.ucore.scene.event.Touchable;
|
import io.anuke.ucore.scene.event.Touchable;
|
||||||
@@ -38,6 +41,18 @@ public class PlacementFragment extends Fragment{
|
|||||||
boolean shown = true;
|
boolean shown = true;
|
||||||
boolean lastGround;
|
boolean lastGround;
|
||||||
|
|
||||||
|
final Input[] inputGrid = {
|
||||||
|
Input.NUM_1, Input.NUM_2, Input.NUM_3, Input.NUM_4,
|
||||||
|
Input.Q, Input.W, Input.E, Input.R,
|
||||||
|
Input.A, Input.S, Input.D, Input.F,
|
||||||
|
Input.Z, Input.X, Input.C, Input.V
|
||||||
|
}, inputCatGrid = {
|
||||||
|
Input.NUM_1, Input.NUM_2,
|
||||||
|
Input.Q, Input.W,
|
||||||
|
Input.A, Input.S,
|
||||||
|
Input.Z, Input.X, Input.C, Input.V
|
||||||
|
};
|
||||||
|
|
||||||
public PlacementFragment(){
|
public PlacementFragment(){
|
||||||
Events.on(WorldLoadGraphicsEvent.class, event -> {
|
Events.on(WorldLoadGraphicsEvent.class, event -> {
|
||||||
currentCategory = Category.turret;
|
currentCategory = Category.turret;
|
||||||
@@ -47,6 +62,40 @@ public class PlacementFragment extends Fragment{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean gridUpdate(InputHandler input){
|
||||||
|
if(!Inputs.keyDown("gridMode")) return false;
|
||||||
|
if(Inputs.keyDown("gridModeShift")){ // Select Category
|
||||||
|
int i = 0;
|
||||||
|
for(Input key : inputCatGrid){
|
||||||
|
if(Inputs.keyDown(key)){
|
||||||
|
input.recipe = Recipe.getByCategory(Category.values()[i]).first();
|
||||||
|
currentCategory = input.recipe.category;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}else if(Inputs.keyDown("select")){ // Mouse eyedropper select
|
||||||
|
Tile tile = world.tileWorld(Graphics.mouseWorld().x, Graphics.mouseWorld().y).target();
|
||||||
|
if(tile.block() != null){
|
||||||
|
Recipe tryRecipe = Recipe.getByResult(tile.block());
|
||||||
|
if((tryRecipe != null) && control.unlocks.isUnlocked(tryRecipe)){
|
||||||
|
input.recipe = tryRecipe;
|
||||||
|
currentCategory = input.recipe.category;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{ // Select block
|
||||||
|
int i = 0;
|
||||||
|
Array<Recipe> recipes = Recipe.getByCategory(currentCategory);
|
||||||
|
for(Input key : inputGrid){
|
||||||
|
if(Inputs.keyDown(key))
|
||||||
|
input.recipe = (i < recipes.size && control.unlocks.isUnlocked(recipes.get(i))) ? recipes.get(i) : null;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build(Group parent){
|
public void build(Group parent){
|
||||||
parent.fill(full -> {
|
parent.fill(full -> {
|
||||||
@@ -111,8 +160,8 @@ public class PlacementFragment extends Fragment{
|
|||||||
frame.table("button-edge-2", top -> {
|
frame.table("button-edge-2", top -> {
|
||||||
topTable = top;
|
topTable = top;
|
||||||
top.add(new Table()).growX().update(topTable -> {
|
top.add(new Table()).growX().update(topTable -> {
|
||||||
if((tileDisplayBlock() == null && lastDisplay == getSelected() && !lastGround) ||
|
if((tileDisplayBlock() == null && lastDisplay == getSelected() && !lastGround) || (tileDisplayBlock() != null && lastDisplay == tileDisplayBlock() && lastGround))
|
||||||
(tileDisplayBlock() != null && lastDisplay == tileDisplayBlock() && lastGround)) return;
|
return;
|
||||||
|
|
||||||
topTable.clear();
|
topTable.clear();
|
||||||
topTable.top().left().margin(5);
|
topTable.top().left().margin(5);
|
||||||
@@ -191,6 +240,9 @@ public class PlacementFragment extends Fragment{
|
|||||||
}).touchable(Touchable.enabled);
|
}).touchable(Touchable.enabled);
|
||||||
|
|
||||||
rebuildCategory.run();
|
rebuildCategory.run();
|
||||||
|
frame.update(() -> {
|
||||||
|
if(gridUpdate(input)) rebuildCategory.run();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user