mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-22 04:28:27 +07:00
Removed unnecessary UI fragments, began work on Desktop input
This commit is contained in:
parent
1cf91c0ce3
commit
b5966afe25
@ -25,7 +25,7 @@ import java.util.Locale;
|
||||
|
||||
public class Vars{
|
||||
|
||||
public static final boolean testMobile = true;
|
||||
public static final boolean testMobile = false;
|
||||
//shorthand for whether or not this is running on android or ios
|
||||
public static boolean mobile;
|
||||
public static boolean ios;
|
||||
|
@ -59,13 +59,11 @@ public class UI extends SceneModule{
|
||||
|
||||
public final MenuFragment menufrag = new MenuFragment();
|
||||
public final HudFragment hudfrag = new HudFragment();
|
||||
public final PlacementFragment placefrag = new PlacementFragment();
|
||||
public final ChatFragment chatfrag = new ChatFragment();
|
||||
public final PlayerListFragment listfrag = new PlayerListFragment();
|
||||
public final BackgroundFragment backfrag = new BackgroundFragment();
|
||||
public final LoadingFragment loadfrag = new LoadingFragment();
|
||||
public final DebugFragment debugfrag = new DebugFragment();
|
||||
public final PlayerMenuFragment playermenufrag = new PlayerMenuFragment();
|
||||
|
||||
private Locale lastLocale;
|
||||
|
||||
@ -181,11 +179,9 @@ public class UI extends SceneModule{
|
||||
backfrag.build(group);
|
||||
hudfrag.build(group);
|
||||
menufrag.build(group);
|
||||
placefrag.build(group);
|
||||
chatfrag.build(group);
|
||||
listfrag.build(group);
|
||||
//debugfrag.build(group);
|
||||
playermenufrag.build(group);
|
||||
debugfrag.build(group);
|
||||
loadfrag.build(group);
|
||||
|
||||
build.end();
|
||||
|
@ -281,9 +281,11 @@ public class Player extends Unit implements BlockBuilder {
|
||||
request.y * tilesize + request.recipe.result.offset(),
|
||||
4, request.recipe.result.size * tilesize /2f + Mathf.absin(Timers.time(), 3f, 1f));
|
||||
|
||||
Lines.stroke((1f-request.progress)*2f);
|
||||
|
||||
Lines.poly(request.x * tilesize + request.recipe.result.offset(),
|
||||
request.y * tilesize + request.recipe.result.offset(),
|
||||
4, request.recipe.result.size * tilesize /2f + 2f, 45 + 15);
|
||||
4, request.recipe.result.size * tilesize /2f + 3f, 45 + 15);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,8 +38,6 @@ import static io.anuke.mindustry.Vars.*;
|
||||
public class AndroidInput extends InputHandler implements GestureListener{
|
||||
private static Rectangle r1 = new Rectangle(), r2 = new Rectangle();
|
||||
|
||||
/**Maximum line length.*/
|
||||
private static final int maxLength = 100;
|
||||
/**Maximum speed the player can pan.*/
|
||||
private static final float maxPanSpeed = 1.3f;
|
||||
/**Distance to edge of screen to start panning.*/
|
||||
@ -116,11 +114,6 @@ public class AndroidInput extends InputHandler implements GestureListener{
|
||||
return null;
|
||||
}
|
||||
|
||||
Tile tileAt(float x, float y){
|
||||
Vector2 vec = Graphics.world(x, y);
|
||||
return world.tileWorld(vec.x, vec.y);
|
||||
}
|
||||
|
||||
void removeRequest(PlaceRequest request){
|
||||
placement.removeValue(request, true);
|
||||
removals.add(request);
|
||||
|
@ -2,15 +2,14 @@ package io.anuke.mindustry.input;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Buttons;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.type.Weapon;
|
||||
import io.anuke.mindustry.input.PlaceUtils.NormalizeDrawResult;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Inputs.DeviceType;
|
||||
import io.anuke.ucore.core.KeyBinds;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.scene.utils.Cursors;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
@ -18,172 +17,139 @@ import io.anuke.ucore.util.Mathf;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class DesktopInput extends InputHandler{
|
||||
float mousex, mousey;
|
||||
float endx, endy;
|
||||
float prmousex, prmousey;
|
||||
//controller info
|
||||
private float controlx, controly;
|
||||
private boolean beganBreak;
|
||||
private boolean controlling;
|
||||
private final int index;
|
||||
private final String section;
|
||||
private boolean showCursor = false;
|
||||
private final String section;
|
||||
|
||||
/**Position where the player started dragging a line.*/
|
||||
private int selectX, selectY;
|
||||
/**Wehther selecting mode is active.*/
|
||||
private boolean selecting;
|
||||
/**Animation scale for line.*/
|
||||
private float selectScale;
|
||||
|
||||
public DesktopInput(Player player){
|
||||
super(player);
|
||||
this.index = player.playerIndex;
|
||||
this.section = "player_" + (player.playerIndex + 1);
|
||||
}
|
||||
|
||||
void tileTapped(Tile tile){
|
||||
|
||||
//check if tapped block is configurable
|
||||
if(tile.block().isConfigurable(tile)){
|
||||
if((!frag.config.isShown() //if the config fragment is hidden, show
|
||||
//alternatively, the current selected block can 'agree' to switch config tiles
|
||||
|| frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), tile))) {
|
||||
frag.config.showConfig(tile);
|
||||
}
|
||||
//otherwise...
|
||||
}else if(!frag.config.hasConfigMouse()){ //make sure a configuration fragment isn't on the cursor
|
||||
//then, if it's shown and the current block 'agrees' to hide, hide it.
|
||||
if(frag.config.isShown() && frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), tile)) {
|
||||
frag.config.hideConfig();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO network event!
|
||||
//call tapped event
|
||||
tile.block().tapped(tile, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBottom(){
|
||||
Tile cursor = tileAt(control.gdxInput().getX(), control.gdxInput().getY());
|
||||
|
||||
if(cursor == null) return;
|
||||
|
||||
//draw selection
|
||||
if(selecting){
|
||||
NormalizeDrawResult result = PlaceUtils.normalizeDrawArea(recipe.result, selectX, selectY, cursor.x, cursor.y, true, maxLength, selectScale);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
if(player.isDead() || state.is(State.menu) || ui.hasDialog()) return;
|
||||
|
||||
if(player.isDead()) return;
|
||||
//deslect if not placing
|
||||
if(!isPlacing()){
|
||||
selecting = false;
|
||||
}
|
||||
|
||||
if(!Inputs.keyDown(section, "select")){
|
||||
shooting = false;
|
||||
}
|
||||
|
||||
boolean canBeginShoot = Inputs.keyTap(section, "select") && canShoot();
|
||||
|
||||
if(Inputs.keyTap(section, "select") && recipe == null && player.inventory.hasItem()){
|
||||
Vector2 vec = Graphics.screen(player.x, player.y);
|
||||
if(vec.dst(getMouseX(), Gdx.graphics.getHeight() - getMouseY()) <= playerSelectRange){
|
||||
canBeginShoot = false;
|
||||
droppingItem = true;
|
||||
}
|
||||
}
|
||||
|
||||
if((Inputs.keyTap(section, "select") && recipe != null) || Inputs.keyTap(section, "break")){
|
||||
Vector2 vec = Graphics.world(getMouseX(), getMouseY());
|
||||
mousex = vec.x;
|
||||
mousey = vec.y;
|
||||
}
|
||||
|
||||
if(!Inputs.keyDown(section, "select") && !Inputs.keyDown(section, "break")){
|
||||
Vector2 vec = Graphics.world(getMouseX(), getMouseY());
|
||||
mousex = vec.x;
|
||||
mousey = vec.y;
|
||||
}
|
||||
|
||||
endx = getMouseX();
|
||||
endy = getMouseY();
|
||||
|
||||
prmousex = Graphics.screen(mousex, mousey).x;
|
||||
prmousey = Gdx.graphics.getHeight() - 1 - Graphics.screen(mousex, mousey).y;
|
||||
//update select animation
|
||||
if(selecting){
|
||||
selectScale = Mathf.lerpDelta(selectScale, 1f, 0.2f);
|
||||
}else{
|
||||
selectScale = 0f;
|
||||
}
|
||||
|
||||
boolean controller = KeyBinds.getSection(section).device.type == DeviceType.controller;
|
||||
|
||||
if(Inputs.getAxisActive("zoom") && (Inputs.keyDown(section,"zoom_hold") || controller)
|
||||
&& !state.is(State.menu) && !ui.hasDialog()){
|
||||
|
||||
//zoom and rotate things
|
||||
if(Inputs.getAxisActive("zoom") && (Inputs.keyDown(section,"zoom_hold") || controller)){
|
||||
renderer.scaleCamera((int) Inputs.getAxisTapped(section, "zoom"));
|
||||
}
|
||||
|
||||
renderer.minimap().zoomBy(-(int)Inputs.getAxisTapped(section,"zoom_minimap"));
|
||||
|
||||
rotation += Inputs.getAxisTapped(section,"rotate_alt");
|
||||
rotation += Inputs.getAxis(section,"rotate");
|
||||
|
||||
rotation = Mathf.mod(rotation, 4);
|
||||
|
||||
int keyIndex = 1;
|
||||
rotation = Mathf.mod(rotation + (int)Inputs.getAxisTapped(section,"rotate"), 4);
|
||||
|
||||
for(int i = 0; i < 6 && i < player.upgrades.size; i ++){
|
||||
if(!(player.upgrades.get(i) instanceof Weapon)){
|
||||
continue;
|
||||
}
|
||||
Tile cursor = tileAt(control.gdxInput().getX(), control.gdxInput().getY());
|
||||
|
||||
if(Inputs.keyTap("weapon_" + keyIndex)){
|
||||
player.weapon = (Weapon) player.upgrades.get(i);
|
||||
if(Net.active()) NetEvents.handleWeaponSwitch(player);
|
||||
}
|
||||
|
||||
keyIndex ++;
|
||||
}
|
||||
|
||||
Tile cursor = world.tile(tilex(), tiley());
|
||||
Tile target = cursor == null ? null : cursor.target();
|
||||
boolean showCursor = false;
|
||||
|
||||
if(droppingItem && Inputs.keyRelease(section,"select") && !player.inventory.isEmpty() && target != null){
|
||||
dropItem(target, player.inventory.getItem());
|
||||
}
|
||||
|
||||
if(droppingItem && (!Inputs.keyDown(section,"select") || player.inventory.isEmpty())){
|
||||
droppingItem = false;
|
||||
}
|
||||
|
||||
if(recipe == null && target != null && !ui.hasMouse() && target.block().isAccessible()){
|
||||
showCursor = true;
|
||||
if(Inputs.keyTap(section,"select")){
|
||||
canBeginShoot = false;
|
||||
frag.inv.showFor(target);
|
||||
Cursors.restoreCursor();
|
||||
}
|
||||
}
|
||||
|
||||
if(!ui.hasMouse() && (target == null || !target.block().isAccessible()) && Inputs.keyTap(section,"select")){
|
||||
frag.inv.hide();
|
||||
}
|
||||
|
||||
if(target != null && target.block().isConfigurable(target)){
|
||||
showCursor = true;
|
||||
if(cursor != null && cursor.block().isConfigurable(cursor)){
|
||||
showCursor = true;
|
||||
}
|
||||
|
||||
if(target != null && Inputs.keyTap(section,"select") && !ui.hasMouse()){
|
||||
if(target.block().isConfigurable(target)){
|
||||
if((!frag.config.isShown()
|
||||
|| frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), cursor))) {
|
||||
frag.config.showConfig(target);
|
||||
canBeginShoot = false;
|
||||
}
|
||||
}else if(!frag.config.hasConfigMouse()){
|
||||
if(frag.config.isShown() && frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), cursor)) {
|
||||
frag.config.hideConfig();
|
||||
canBeginShoot = false;
|
||||
}
|
||||
}
|
||||
|
||||
target.block().tapped(target, player);
|
||||
if(Net.active()) NetEvents.handleBlockTap(target);
|
||||
}
|
||||
|
||||
if(Inputs.keyTap(section,"break")){
|
||||
frag.config.hideConfig();
|
||||
}
|
||||
|
||||
if(Inputs.keyRelease(section,"break")){
|
||||
beganBreak = false;
|
||||
}
|
||||
|
||||
if(recipe != null && Inputs.keyTap(section,"break")){
|
||||
beganBreak = true;
|
||||
recipe = null;
|
||||
}
|
||||
|
||||
if(recipe != null){
|
||||
showCursor = validPlace(tilex(), tiley(), recipe.result) && cursorNear();
|
||||
}
|
||||
|
||||
if(canBeginShoot){
|
||||
shooting = true;
|
||||
}
|
||||
|
||||
if(!ui.hasMouse()) {
|
||||
if (showCursor)
|
||||
if (showCursor) {
|
||||
Cursors.setHand();
|
||||
else
|
||||
}else {
|
||||
Cursors.restoreCursor();
|
||||
}
|
||||
}
|
||||
|
||||
showCursor = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchDown (int screenX, int screenY, int pointer, int button) {
|
||||
if(player.isDead() || state.is(State.menu) || ui.hasDialog()) return false;
|
||||
|
||||
Tile cursor = tileAt(screenX, screenY);
|
||||
|
||||
if(cursor == null) return false;
|
||||
|
||||
if(isPlacing()) {
|
||||
selectX = cursor.x;
|
||||
selectY = cursor.y;
|
||||
selecting = true;
|
||||
}else {
|
||||
tileTapped(cursor);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchUp (int screenX, int screenY, int pointer, int button) {
|
||||
if(player.isDead() || state.is(State.menu) || ui.hasDialog()) return false;
|
||||
|
||||
selecting = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMouseX() {
|
||||
return controlx;
|
||||
return !controlling ? control.gdxInput().getX() : controlx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMouseY() {
|
||||
return controly;
|
||||
return !controlling ? control.gdxInput().getY() : controly;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -217,7 +183,7 @@ public class DesktopInput extends InputHandler{
|
||||
controly -= ya*baseControllerSpeed*scl;
|
||||
controlling = true;
|
||||
|
||||
if(index == 0){
|
||||
if(player.playerIndex == 0){
|
||||
Gdx.input.setCursorCatched(true);
|
||||
}
|
||||
|
||||
@ -236,16 +202,4 @@ public class DesktopInput extends InputHandler{
|
||||
controly = control.gdxInput().getY();
|
||||
}
|
||||
}
|
||||
|
||||
public int tilex(){
|
||||
return (recipe != null && recipe.result.isMultiblock() &&
|
||||
recipe.result.size % 2 == 0) ?
|
||||
Mathf.scl(Graphics.world(getMouseX(), getMouseY()).x, tilesize) : Mathf.scl2(Graphics.world(getMouseX(), getMouseY()).x, tilesize);
|
||||
}
|
||||
|
||||
public int tiley(){
|
||||
return (recipe != null && recipe.result.isMultiblock() &&
|
||||
recipe.result.size % 2 == 0) ?
|
||||
Mathf.scl(Graphics.world(getMouseX(), getMouseY()).y, tilesize) : Mathf.scl2(Graphics.world(getMouseX(), getMouseY()).y, tilesize);
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,10 @@ import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public abstract class InputHandler extends InputAdapter{
|
||||
/**Used for dropping items.*/
|
||||
float playerSelectRange = Unit.dp.scl(40f);
|
||||
Translator stackTrns = new Translator();
|
||||
final float playerSelectRange = Unit.dp.scl(40f);
|
||||
/**Maximum line length.*/
|
||||
final int maxLength = 100;
|
||||
final Translator stackTrns = new Translator();
|
||||
|
||||
public final Player player;
|
||||
public final OverlayFragment frag = new OverlayFragment(this);
|
||||
@ -81,6 +83,12 @@ public abstract class InputHandler extends InputAdapter{
|
||||
|
||||
//utility methods
|
||||
|
||||
/**Returns the tile at the specified MOUSE coordinates.*/
|
||||
Tile tileAt(float x, float y){
|
||||
Vector2 vec = Graphics.world(x, y);
|
||||
return world.tileWorld(vec.x, vec.y);
|
||||
}
|
||||
|
||||
public boolean isPlacing(){
|
||||
return recipe != null;
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import io.anuke.ucore.scene.Group;
|
||||
|
||||
public class OverlayFragment implements Fragment{
|
||||
public final BlockInventoryFragment inv;
|
||||
public final ToolFragment tool;
|
||||
public final BlockConfigFragment config;
|
||||
|
||||
private Group group = new Group();
|
||||
@ -14,7 +13,6 @@ public class OverlayFragment implements Fragment{
|
||||
public OverlayFragment(InputHandler input){
|
||||
this.input = input;
|
||||
|
||||
tool = new ToolFragment(input);
|
||||
inv = new BlockInventoryFragment(input);
|
||||
config = new BlockConfigFragment();
|
||||
}
|
||||
@ -25,7 +23,6 @@ public class OverlayFragment implements Fragment{
|
||||
parent.addChild(group);
|
||||
|
||||
inv.build(group);
|
||||
tool.build(group);
|
||||
config.build(group);
|
||||
|
||||
input.buildUI(group);
|
||||
|
@ -1,12 +0,0 @@
|
||||
package io.anuke.mindustry.ui.fragments;
|
||||
|
||||
import io.anuke.ucore.scene.Group;
|
||||
|
||||
public class PlacementFragment implements Fragment{
|
||||
|
||||
@Override
|
||||
public void build(Group parent){
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package io.anuke.mindustry.ui.fragments;
|
||||
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
public class PlayerMenuFragment implements Fragment {
|
||||
|
||||
@Override
|
||||
public void build(Group parent) {
|
||||
/*
|
||||
new table(){{
|
||||
new table("clear"){{
|
||||
ItemImage item = new ItemImage(player.inventory.item.item.region, () -> round(player.inventory.item.amount), Color.WHITE)
|
||||
.updateRegion(() -> player.inventory.item.item.region);
|
||||
|
||||
ItemImage liquid = new ItemImage(Draw.region("icon-liquid"), () -> round(player.inventory.liquid.amount), Color.WHITE)
|
||||
.updateColor(() -> player.inventory.liquid.liquid == Liquids.none ? Color.GRAY : player.inventory.liquid.liquid.color);
|
||||
ItemImage power = new ItemImage(Draw.region("icon-power"), () -> round(player.inventory.power), Colors.get("power"));
|
||||
|
||||
defaults().size(16 * 2).space(6f);
|
||||
add(item);
|
||||
add(liquid);
|
||||
add(power);
|
||||
|
||||
visible(() -> Inputs.keyDown("player_list"));
|
||||
padTop(100);
|
||||
margin(5);
|
||||
}}.end();
|
||||
}}.end();*/
|
||||
}
|
||||
|
||||
public String round(float f){
|
||||
f = (int)f;
|
||||
if(f >= 1000){
|
||||
return Strings.toFixed(f/1000, 1) + "k";
|
||||
}else{
|
||||
return (int)f+"";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package io.anuke.mindustry.ui.fragments;
|
||||
|
||||
import io.anuke.mindustry.input.InputHandler;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
|
||||
public class ToolFragment implements Fragment{
|
||||
private final InputHandler input;
|
||||
|
||||
public ToolFragment(InputHandler input){
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Group parent){
|
||||
|
||||
}
|
||||
}
|
@ -183,7 +183,7 @@ public class Block extends BaseBlock implements Content{
|
||||
/**Called when another tile is tapped while this block is selected.
|
||||
* Returns whether or not this block should be deselected.*/
|
||||
public boolean onConfigureTileTapped(Tile tile, Tile other){
|
||||
return true;
|
||||
return tile != other;
|
||||
}
|
||||
|
||||
public boolean synthetic(){
|
||||
|
Loading…
Reference in New Issue
Block a user