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:
@@ -283,9 +283,9 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
@Override
|
||||
public void drawShadow(float offsetX, float offsetY){
|
||||
float x = snappedX(), y = snappedY();
|
||||
float scl = mech.flying ? 1f : boostHeat/2f;
|
||||
float scl = mech.flying ? 1f : boostHeat / 2f;
|
||||
|
||||
Draw.rect(mech.iconRegion, x + offsetX*scl, y + offsetY*scl, rotation - 90);
|
||||
Draw.rect(mech.iconRegion, x + offsetX * scl, y + offsetY * scl, rotation - 90);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -317,9 +317,9 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
|
||||
for(int i : Mathf.signs){
|
||||
Draw.rect(mech.legRegion,
|
||||
x + Angles.trnsx(baseRotation, ft * i + boostTrnsY, -boostTrnsX * i),
|
||||
y + Angles.trnsy(baseRotation, ft * i + boostTrnsY, -boostTrnsX * i),
|
||||
mech.legRegion.getRegionWidth() * i, mech.legRegion.getRegionHeight() - Mathf.clamp(ft * i, 0, 2), baseRotation - 90 + boostAng * i);
|
||||
x + Angles.trnsx(baseRotation, ft * i + boostTrnsY, -boostTrnsX * i),
|
||||
y + Angles.trnsy(baseRotation, ft * i + boostTrnsY, -boostTrnsX * i),
|
||||
mech.legRegion.getRegionWidth() * i, mech.legRegion.getRegionHeight() - Mathf.clamp(ft * i, 0, 2), baseRotation - 90 + boostAng * i);
|
||||
}
|
||||
|
||||
Draw.rect(mech.baseRegion, x, y, baseRotation - 90);
|
||||
@@ -339,8 +339,8 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
float tra = rotation - 90, trY = -mech.weapon.getRecoil(this, i > 0) + mech.weaponOffsetY;
|
||||
float w = i > 0 ? -mech.weapon.equipRegion.getRegionWidth() : mech.weapon.equipRegion.getRegionWidth();
|
||||
Draw.rect(mech.weapon.equipRegion,
|
||||
x + Angles.trnsx(tra, (mech.weaponOffsetX + mech.spreadX(this)) * i, trY),
|
||||
y + Angles.trnsy(tra, (mech.weaponOffsetX + mech.spreadX(this)) * i, trY), w, mech.weapon.equipRegion.getRegionHeight(), rotation - 90);
|
||||
x + Angles.trnsx(tra, (mech.weaponOffsetX + mech.spreadX(this)) * i, trY),
|
||||
y + Angles.trnsy(tra, (mech.weaponOffsetX + mech.spreadX(this)) * i, trY), w, mech.weapon.equipRegion.getRegionHeight(), rotation - 90);
|
||||
}
|
||||
|
||||
float backTrns = 4f, itemSize = 5f;
|
||||
@@ -352,9 +352,9 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
float angT = i == 0 ? 0 : Mathf.randomSeedRange(i + 1, 60f);
|
||||
float lenT = i == 0 ? 0 : Mathf.randomSeedRange(i + 2, 1f) - 1f;
|
||||
Draw.rect(stack.item.region,
|
||||
x + Angles.trnsx(rotation + 180f + angT, backTrns + lenT),
|
||||
y + Angles.trnsy(rotation + 180f + angT, backTrns + lenT),
|
||||
itemSize, itemSize, rotation);
|
||||
x + Angles.trnsx(rotation + 180f + angT, backTrns + lenT),
|
||||
y + Angles.trnsy(rotation + 180f + angT, backTrns + lenT),
|
||||
itemSize, itemSize, rotation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,7 +365,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
public void drawStats(){
|
||||
float x = snappedX(), y = snappedY();
|
||||
|
||||
Draw.color(Color.BLACK, team.color, healthf() + Mathf.absin(Timers.time(), healthf()*5f, 1f - healthf()));
|
||||
Draw.color(Color.BLACK, team.color, healthf() + Mathf.absin(Timers.time(), healthf() * 5f, 1f - healthf()));
|
||||
Draw.alpha(hitTime / hitDuration);
|
||||
Draw.rect(getPowerCellRegion(), x + Angles.trnsx(rotation, mech.cellTrnsY, 0f), y + Angles.trnsy(rotation, mech.cellTrnsY, 0f), rotation - 90);
|
||||
Draw.color();
|
||||
@@ -380,7 +380,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
if(mech.flying || boostHeat > 0.001f){
|
||||
float wobblyness = 0.6f;
|
||||
if(!state.isPaused()) trail.update(x + Angles.trnsx(rotation + 180f, 5f) + Mathf.range(wobblyness),
|
||||
y + Angles.trnsy(rotation + 180f, 5f) + Mathf.range(wobblyness));
|
||||
y + Angles.trnsy(rotation + 180f, 5f) + Mathf.range(wobblyness));
|
||||
trail.draw(Hue.mix(mech.trailColor, mech.trailColorTo, mech.flying ? 0f : boostHeat, Tmp.c1), 5f * (isFlying() ? 1f : boostHeat));
|
||||
}else{
|
||||
trail.clear();
|
||||
@@ -422,7 +422,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
Core.font.setUseIntegerPositions(ints);
|
||||
}
|
||||
|
||||
/**Draw all current build requests. Does not draw the beam effect, only the positions.*/
|
||||
/** Draw all current build requests. Does not draw the beam effect, only the positions. */
|
||||
public void drawBuildRequests(){
|
||||
for(BuildRequest request : getPlaceQueue()){
|
||||
if(getCurrentRequest() == request) continue;
|
||||
@@ -438,16 +438,16 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
float rad = Mathf.absin(Timers.time(), 7f, 1f) + block.size * tilesize / 2f - 1;
|
||||
|
||||
Lines.square(
|
||||
request.x * tilesize + block.offset(),
|
||||
request.y * tilesize + block.offset() - 1,
|
||||
rad);
|
||||
request.x * tilesize + block.offset(),
|
||||
request.y * tilesize + block.offset() - 1,
|
||||
rad);
|
||||
|
||||
Draw.color(Palette.remove);
|
||||
|
||||
Lines.square(
|
||||
request.x * tilesize + block.offset(),
|
||||
request.y * tilesize + block.offset(),
|
||||
rad);
|
||||
request.x * tilesize + block.offset(),
|
||||
request.y * tilesize + block.offset(),
|
||||
rad);
|
||||
}else{
|
||||
//draw place request
|
||||
Lines.stroke(2f);
|
||||
@@ -457,16 +457,16 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
float rad = Mathf.absin(Timers.time(), 7f, 1f) - 2f + request.recipe.result.size * tilesize / 2f;
|
||||
|
||||
Lines.square(
|
||||
request.x * tilesize + request.recipe.result.offset(),
|
||||
request.y * tilesize + request.recipe.result.offset() - 1,
|
||||
rad);
|
||||
request.x * tilesize + request.recipe.result.offset(),
|
||||
request.y * tilesize + request.recipe.result.offset() - 1,
|
||||
rad);
|
||||
|
||||
Draw.color(Palette.accent);
|
||||
|
||||
Lines.square(
|
||||
request.x * tilesize + request.recipe.result.offset(),
|
||||
request.y * tilesize + request.recipe.result.offset(),
|
||||
rad);
|
||||
request.x * tilesize + request.recipe.result.offset(),
|
||||
request.y * tilesize + request.recipe.result.offset(),
|
||||
rad);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -601,9 +601,10 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
|
||||
float xa = Inputs.getAxis(section, "move_x");
|
||||
float ya = Inputs.getAxis(section, "move_y");
|
||||
|
||||
movement.y += ya * speed;
|
||||
movement.x += xa * speed;
|
||||
if(!Inputs.keyDown("gridMode")){
|
||||
movement.y += ya * speed;
|
||||
movement.x += xa * speed;
|
||||
}
|
||||
|
||||
Vector2 vec = Graphics.world(control.input(playerIndex).getMouseX(), control.input(playerIndex).getMouseY());
|
||||
pointerX = vec.x;
|
||||
@@ -695,8 +696,8 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
getHitbox(rect);
|
||||
rect.x -= expansion;
|
||||
rect.y -= expansion;
|
||||
rect.width += expansion*2f;
|
||||
rect.height += expansion*2f;
|
||||
rect.width += expansion * 2f;
|
||||
rect.height += expansion * 2f;
|
||||
|
||||
isBoosting = EntityQuery.collisions().overlapsTile(rect) || distanceTo(targetX, targetY) > 85f;
|
||||
|
||||
@@ -733,7 +734,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
if(target != null && distanceTo(target) > getWeapon().getAmmo().getRange()){
|
||||
target = null;
|
||||
}else if(target != null){
|
||||
target = ((Tile)target).entity;
|
||||
target = ((Tile) target).entity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -742,14 +743,14 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
}
|
||||
}
|
||||
}else if(target.isValid() || (target instanceof TileEntity && ((TileEntity) target).damaged() && target.getTeam() == team &&
|
||||
mech.canHeal && distanceTo(target) < getWeapon().getAmmo().getRange())){
|
||||
mech.canHeal && distanceTo(target) < getWeapon().getAmmo().getRange())){
|
||||
//rotate toward and shoot the target
|
||||
if(mech.turnCursor){
|
||||
rotation = Mathf.slerpDelta(rotation, angleTo(target), 0.2f);
|
||||
}
|
||||
|
||||
Vector2 intercept =
|
||||
Predict.intercept(x, y, target.getX(), target.getY(), target.getVelocity().x - velocity.x, target.getVelocity().y - velocity.y, getWeapon().getAmmo().bullet.speed);
|
||||
Predict.intercept(x, y, target.getX(), target.getY(), target.getVelocity().x - velocity.x, target.getVelocity().y - velocity.y, getWeapon().getAmmo().bullet.speed);
|
||||
|
||||
pointerX = intercept.x;
|
||||
pointerY = intercept.y;
|
||||
@@ -760,7 +761,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
|
||||
}else if(isShooting()){
|
||||
Vector2 vec = Graphics.world(control.input(playerIndex).getMouseX(),
|
||||
control.input(playerIndex).getMouseY());
|
||||
control.input(playerIndex).getMouseY());
|
||||
pointerX = vec.x;
|
||||
pointerY = vec.y;
|
||||
|
||||
@@ -773,7 +774,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
|
||||
//region utility methods
|
||||
|
||||
/** Resets all values of the player.*/
|
||||
/** Resets all values of the player. */
|
||||
public void reset(){
|
||||
resetNoAdd();
|
||||
|
||||
|
||||
@@ -16,50 +16,52 @@ public class DefaultKeybinds{
|
||||
for(String section : sections){
|
||||
|
||||
KeyBinds.defaultSection(section, DeviceType.keyboard,
|
||||
new Category("general"),
|
||||
"move_x", new Axis(Input.A, Input.D),
|
||||
"move_y", new Axis(Input.S, Input.W),
|
||||
"select", Input.MOUSE_LEFT,
|
||||
"deselect", Input.MOUSE_RIGHT,
|
||||
"break", Input.MOUSE_RIGHT,
|
||||
"rotate", new Axis(Input.SCROLL),
|
||||
"dash", Input.SHIFT_LEFT,
|
||||
"drop_unit", Input.SHIFT_LEFT,
|
||||
new Category("view"),
|
||||
"zoom_hold", Input.CONTROL_LEFT,
|
||||
"zoom", new Axis(Input.SCROLL),
|
||||
"zoom_minimap", new Axis(Input.MINUS, Input.PLUS),
|
||||
"menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE,
|
||||
"pause", Input.SPACE,
|
||||
"toggle_menus", Input.C,
|
||||
"screenshot", Input.P,
|
||||
new Category("multiplayer"),
|
||||
"player_list", Input.TAB,
|
||||
"chat", Input.ENTER,
|
||||
"chat_history_prev", Input.UP,
|
||||
"chat_history_next", Input.DOWN,
|
||||
"chat_scroll", new Axis(Input.SCROLL)
|
||||
new Category("general"),
|
||||
"move_x", new Axis(Input.A, Input.D),
|
||||
"move_y", new Axis(Input.S, Input.W),
|
||||
"select", Input.MOUSE_LEFT,
|
||||
"deselect", Input.MOUSE_RIGHT,
|
||||
"break", Input.MOUSE_RIGHT,
|
||||
"rotate", new Axis(Input.SCROLL),
|
||||
"dash", Input.SHIFT_LEFT,
|
||||
"drop_unit", Input.SHIFT_LEFT,
|
||||
"gridMode", Input.ALT_LEFT,
|
||||
"gridModeShift", Input.SHIFT_LEFT,
|
||||
new Category("view"),
|
||||
"zoom_hold", Input.CONTROL_LEFT,
|
||||
"zoom", new Axis(Input.SCROLL),
|
||||
"zoom_minimap", new Axis(Input.MINUS, Input.PLUS),
|
||||
"menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE,
|
||||
"pause", Input.SPACE,
|
||||
"toggle_menus", Input.C,
|
||||
"screenshot", Input.P,
|
||||
new Category("multiplayer"),
|
||||
"player_list", Input.TAB,
|
||||
"chat", Input.ENTER,
|
||||
"chat_history_prev", Input.UP,
|
||||
"chat_history_next", Input.DOWN,
|
||||
"chat_scroll", new Axis(Input.SCROLL)
|
||||
);
|
||||
|
||||
KeyBinds.defaultSection(section, DeviceType.controller,
|
||||
new Category("general"),
|
||||
"move_x", new Axis(Input.CONTROLLER_L_STICK_HORIZONTAL_AXIS),
|
||||
"move_y", new Axis(Input.CONTROLLER_L_STICK_VERTICAL_AXIS),
|
||||
"cursor_x", new Axis(Input.CONTROLLER_R_STICK_HORIZONTAL_AXIS),
|
||||
"cursor_y", new Axis(Input.CONTROLLER_R_STICK_VERTICAL_AXIS),
|
||||
//"select", Input.CONTROLLER_R_BUMPER,
|
||||
//"break", Input.CONTROLLER_L_BUMPER,
|
||||
//"shoot", Input.CONTROLLER_R_TRIGGER,
|
||||
"dash", Input.CONTROLLER_Y,
|
||||
"rotate_alt", new Axis(Input.CONTROLLER_DPAD_RIGHT, Input.CONTROLLER_DPAD_LEFT),
|
||||
"rotate", new Axis(Input.CONTROLLER_A, Input.CONTROLLER_B),
|
||||
new Category("view"),
|
||||
"zoom_hold", Input.ANY_KEY,
|
||||
"zoom", new Axis(Input.CONTROLLER_DPAD_DOWN, Input.CONTROLLER_DPAD_UP),
|
||||
"menu", Input.CONTROLLER_X,
|
||||
"pause", Input.CONTROLLER_L_TRIGGER,
|
||||
new Category("multiplayer"),
|
||||
"player_list", Input.CONTROLLER_START
|
||||
new Category("general"),
|
||||
"move_x", new Axis(Input.CONTROLLER_L_STICK_HORIZONTAL_AXIS),
|
||||
"move_y", new Axis(Input.CONTROLLER_L_STICK_VERTICAL_AXIS),
|
||||
"cursor_x", new Axis(Input.CONTROLLER_R_STICK_HORIZONTAL_AXIS),
|
||||
"cursor_y", new Axis(Input.CONTROLLER_R_STICK_VERTICAL_AXIS),
|
||||
//"select", Input.CONTROLLER_R_BUMPER,
|
||||
//"break", Input.CONTROLLER_L_BUMPER,
|
||||
//"shoot", Input.CONTROLLER_R_TRIGGER,
|
||||
"dash", Input.CONTROLLER_Y,
|
||||
"rotate_alt", new Axis(Input.CONTROLLER_DPAD_RIGHT, Input.CONTROLLER_DPAD_LEFT),
|
||||
"rotate", new Axis(Input.CONTROLLER_A, Input.CONTROLLER_B),
|
||||
new Category("view"),
|
||||
"zoom_hold", Input.ANY_KEY,
|
||||
"zoom", new Axis(Input.CONTROLLER_DPAD_DOWN, Input.CONTROLLER_DPAD_UP),
|
||||
"menu", Input.CONTROLLER_X,
|
||||
"pause", Input.CONTROLLER_L_TRIGGER,
|
||||
new Category("multiplayer"),
|
||||
"player_list", Input.CONTROLLER_START
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ public class HudFragment extends Fragment{
|
||||
}
|
||||
|
||||
cont.update(() -> {
|
||||
if(Inputs.keyTap("toggle_menus") && !ui.chatfrag.chatOpen()){
|
||||
if(!Inputs.keyDown("gridMode") && Inputs.keyTap("toggle_menus") && !ui.chatfrag.chatOpen()){
|
||||
toggleMenus();
|
||||
}
|
||||
});
|
||||
@@ -139,7 +139,7 @@ public class HudFragment extends Fragment{
|
||||
if(Net.hasClient()){
|
||||
t.label(() -> ping.get(Net.getPing())).visible(Net::client).colspan(2);
|
||||
}
|
||||
}).size(-1).visible(() -> Settings.getBool("fps")).update(t -> t.setTranslation(0, (!waves.isVisible() ? wavetable.getHeight() : Math.min(wavetable.getTranslation().y, wavetable.getHeight())) )).get();
|
||||
}).size(-1).visible(() -> Settings.getBool("fps")).update(t -> t.setTranslation(0, (!waves.isVisible() ? wavetable.getHeight() : Math.min(wavetable.getTranslation().y, wavetable.getHeight())))).get();
|
||||
|
||||
//make wave box appear below rest of menu
|
||||
if(mobile){
|
||||
@@ -149,7 +149,7 @@ public class HudFragment extends Fragment{
|
||||
|
||||
//minimap
|
||||
parent.fill(t -> t.top().right().add(new Minimap())
|
||||
.visible(() -> !state.is(State.menu) && Settings.getBool("minimap")));
|
||||
.visible(() -> !state.is(State.menu) && Settings.getBool("minimap")));
|
||||
|
||||
//paused table
|
||||
parent.fill(t -> {
|
||||
@@ -218,7 +218,7 @@ public class HudFragment extends Fragment{
|
||||
}
|
||||
});
|
||||
table.margin(12);
|
||||
table.addImage("icon-check").size(16*2).pad(3);
|
||||
table.addImage("icon-check").size(16 * 2).pad(3);
|
||||
table.add(text).wrap().width(280f).get().setAlignment(Align.center, Align.center);
|
||||
table.pack();
|
||||
|
||||
@@ -231,7 +231,7 @@ public class HudFragment extends Fragment{
|
||||
Actions.run(() -> container.actions(Actions.translateBy(0, table.getPrefHeight(), 1f, Interpolation.fade), Actions.removeActor())));
|
||||
}
|
||||
|
||||
/**Show unlock notification for a new recipe.*/
|
||||
/** Show unlock notification for a new recipe. */
|
||||
public void showUnlock(Recipe recipe){
|
||||
|
||||
//if there's currently no unlock notification...
|
||||
@@ -268,11 +268,11 @@ public class HudFragment extends Fragment{
|
||||
container.top().add(table);
|
||||
container.setTranslation(0, table.getPrefHeight());
|
||||
container.actions(Actions.translateBy(0, -table.getPrefHeight(), 1f, Interpolation.fade), Actions.delay(4f),
|
||||
//nesting actions() calls is necessary so the right prefHeight() is used
|
||||
Actions.run(() -> container.actions(Actions.translateBy(0, table.getPrefHeight(), 1f, Interpolation.fade), Actions.run(() -> {
|
||||
lastUnlockTable = null;
|
||||
lastUnlockLayout = null;
|
||||
}), Actions.removeActor())));
|
||||
//nesting actions() calls is necessary so the right prefHeight() is used
|
||||
Actions.run(() -> container.actions(Actions.translateBy(0, table.getPrefHeight(), 1f, Interpolation.fade), Actions.run(() -> {
|
||||
lastUnlockTable = null;
|
||||
lastUnlockLayout = null;
|
||||
}), Actions.removeActor())));
|
||||
|
||||
lastUnlockTable = container;
|
||||
lastUnlockLayout = in;
|
||||
@@ -371,16 +371,16 @@ public class HudFragment extends Fragment{
|
||||
table.setTouchable(Touchable.enabled);
|
||||
|
||||
table.labelWrap(() ->
|
||||
world.getSector() == null ?
|
||||
(state.enemies() > 0 && state.mode.disableWaveTimer ?
|
||||
wavef.get(state.wave) + "\n" + (state.enemies() == 1 ?
|
||||
enemyf.get(state.enemies()) :
|
||||
enemiesf.get(state.enemies())) :
|
||||
wavef.get(state.wave) + "\n" +
|
||||
(!state.mode.disableWaveTimer ?
|
||||
Bundles.format("text.wave.waiting", (int)(state.wavetime/60)) :
|
||||
Bundles.get("text.waiting"))) :
|
||||
Bundles.format("text.mission.display", world.getSector().currentMission().displayString())).growX().pad(8f);
|
||||
world.getSector() == null ?
|
||||
(state.enemies() > 0 && state.mode.disableWaveTimer ?
|
||||
wavef.get(state.wave) + "\n" + (state.enemies() == 1 ?
|
||||
enemyf.get(state.enemies()) :
|
||||
enemiesf.get(state.enemies())) :
|
||||
wavef.get(state.wave) + "\n" +
|
||||
(!state.mode.disableWaveTimer ?
|
||||
Bundles.format("text.wave.waiting", (int) (state.wavetime / 60)) :
|
||||
Bundles.get("text.waiting"))) :
|
||||
Bundles.format("text.mission.display", world.getSector().currentMission().displayString())).growX().pad(8f);
|
||||
|
||||
table.clicked(() -> {
|
||||
if(world.getSector() != null && world.getSector().currentMission().hasMessage()){
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.anuke.mindustry.ui.fragments;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.Interpolation;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
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.ucore.core.Events;
|
||||
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.actions.Actions;
|
||||
import io.anuke.ucore.scene.event.Touchable;
|
||||
@@ -38,6 +41,18 @@ public class PlacementFragment extends Fragment{
|
||||
boolean shown = true;
|
||||
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(){
|
||||
Events.on(WorldLoadGraphicsEvent.class, event -> {
|
||||
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
|
||||
public void build(Group parent){
|
||||
parent.fill(full -> {
|
||||
@@ -74,7 +123,7 @@ public class PlacementFragment extends Fragment{
|
||||
|
||||
boolean[] unlocked = {false};
|
||||
|
||||
ImageButton button = blockTable.addImageButton("icon-locked", "select", 8*4, () -> {
|
||||
ImageButton button = blockTable.addImageButton("icon-locked", "select", 8 * 4, () -> {
|
||||
if(control.unlocks.isUnlocked(recipe)){
|
||||
input.recipe = input.recipe == recipe ? null : recipe;
|
||||
}
|
||||
@@ -111,8 +160,8 @@ public class PlacementFragment extends Fragment{
|
||||
frame.table("button-edge-2", top -> {
|
||||
topTable = top;
|
||||
top.add(new Table()).growX().update(topTable -> {
|
||||
if((tileDisplayBlock() == null && lastDisplay == getSelected() && !lastGround) ||
|
||||
(tileDisplayBlock() != null && lastDisplay == tileDisplayBlock() && lastGround)) return;
|
||||
if((tileDisplayBlock() == null && lastDisplay == getSelected() && !lastGround) || (tileDisplayBlock() != null && lastDisplay == tileDisplayBlock() && lastGround))
|
||||
return;
|
||||
|
||||
topTable.clear();
|
||||
topTable.top().left().margin(5);
|
||||
@@ -123,14 +172,14 @@ public class PlacementFragment extends Fragment{
|
||||
if(lastDisplay != null){ //show selected recipe
|
||||
topTable.table(header -> {
|
||||
header.left();
|
||||
header.add(new ImageStack(lastDisplay.getCompactIcon())).size(8*4);
|
||||
header.add(new ImageStack(lastDisplay.getCompactIcon())).size(8 * 4);
|
||||
header.labelWrap(() ->
|
||||
!control.unlocks.isUnlocked(Recipe.getByResult(lastDisplay)) ? Bundles.get("text.blocks.unknown") : lastDisplay.formalName)
|
||||
.left().width(190f).padLeft(5);
|
||||
!control.unlocks.isUnlocked(Recipe.getByResult(lastDisplay)) ? Bundles.get("text.blocks.unknown") : lastDisplay.formalName)
|
||||
.left().width(190f).padLeft(5);
|
||||
header.add().growX();
|
||||
if(control.unlocks.isUnlocked(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();
|
||||
topTable.row();
|
||||
@@ -141,7 +190,7 @@ public class PlacementFragment extends Fragment{
|
||||
for(ItemStack stack : Recipe.getByResult(lastDisplay).requirements){
|
||||
req.table(line -> {
|
||||
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.labelWrap(() -> {
|
||||
TileEntity core = players[0].getClosestCore();
|
||||
@@ -159,13 +208,13 @@ public class PlacementFragment extends Fragment{
|
||||
|
||||
}else if(tileDisplayBlock() != null){ //show selected tile
|
||||
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);
|
||||
}
|
||||
});
|
||||
}).colspan(3).fillX().visible(() -> getSelected() != null || tileDisplayBlock() != null).touchable(Touchable.enabled);
|
||||
frame.row();
|
||||
frame.addImage("blank").color(Palette.accent).colspan(3).height(3*2).growX();
|
||||
frame.addImage("blank").color(Palette.accent).colspan(3).height(3 * 2).growX();
|
||||
frame.row();
|
||||
frame.table("pane-2", blocksSelect -> {
|
||||
blocksSelect.margin(4).marginTop(0);
|
||||
@@ -181,21 +230,24 @@ public class PlacementFragment extends Fragment{
|
||||
for(Category cat : Category.values()){
|
||||
if(Recipe.getByCategory(cat).isEmpty()) continue;
|
||||
|
||||
categories.addImageButton("icon-" + cat.name(), "clear-toggle", 16*2, () -> {
|
||||
categories.addImageButton("icon-" + cat.name(), "clear-toggle", 16 * 2, () -> {
|
||||
currentCategory = cat;
|
||||
rebuildCategory.run();
|
||||
}).group(group).update(i -> i.setChecked(currentCategory == cat));
|
||||
|
||||
if(cat.ordinal() %2 == 1) categories.row();
|
||||
if(cat.ordinal() % 2 == 1) categories.row();
|
||||
}
|
||||
}).touchable(Touchable.enabled);
|
||||
|
||||
rebuildCategory.run();
|
||||
frame.update(() -> {
|
||||
if(gridUpdate(input)) rebuildCategory.run();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**Returns the currently displayed block in the top box.*/
|
||||
/** Returns the currently displayed block in the top box. */
|
||||
Block getSelected(){
|
||||
Block toDisplay = null;
|
||||
|
||||
@@ -226,12 +278,12 @@ public class PlacementFragment extends Fragment{
|
||||
return toDisplay;
|
||||
}
|
||||
|
||||
/**Returns the block currently being hovered over in the world.*/
|
||||
/** Returns the block currently being hovered over in the world. */
|
||||
Block tileDisplayBlock(){
|
||||
return hoverTile == null ? null : hoverTile.block().synthetic() ? hoverTile.block() : hoverTile.floor() instanceof OreBlock ? hoverTile.floor() : null;
|
||||
}
|
||||
|
||||
/**Show or hide the placement menu.*/
|
||||
/** Show or hide the placement menu. */
|
||||
void toggle(float t, Interpolation ip){
|
||||
toggler.clearActions();
|
||||
if(shown){
|
||||
|
||||
Reference in New Issue
Block a user