Massive amount of refactoring for local multiplayer, annotations
This commit is contained in:
@@ -27,8 +27,6 @@ public class BlockRenderer{
|
||||
private int requestidx = 0;
|
||||
private int iterateidx = 0;
|
||||
|
||||
private float storeX, storeY;
|
||||
|
||||
public BlockRenderer(){
|
||||
floorRenderer = new FloorRenderer();
|
||||
|
||||
@@ -205,40 +203,4 @@ public class BlockRenderer{
|
||||
r.layer = layer;
|
||||
requestidx ++;
|
||||
}
|
||||
|
||||
public void drawPreview(Block block, float drawx, float drawy, float rotation, float opacity) {
|
||||
Draw.alpha(opacity);
|
||||
Draw.rect(block.name(), drawx, drawy, rotation);
|
||||
}
|
||||
|
||||
public void handlePreview(Block block, float rotation, float drawx, float drawy, int tilex, int tiley) {
|
||||
|
||||
if(control.input().recipe != null && state.inventory.hasItems(control.input().recipe.requirements)
|
||||
&& control.input().validPlace(tilex, tiley, block) && (mobile || control.input().cursorNear())) {
|
||||
|
||||
if(block.isMultiblock()) {
|
||||
float halfBlockWidth = (block.size * tilesize) / 2;
|
||||
float halfBlockHeight = (block.size * tilesize) / 2;
|
||||
if((storeX == 0 && storeY == 0)) {
|
||||
storeX = drawx;
|
||||
storeY = drawy;
|
||||
}
|
||||
if((storeX == drawx - halfBlockWidth || storeX == drawx + halfBlockWidth || storeY == drawy - halfBlockHeight || storeY == drawy + halfBlockHeight) &&
|
||||
((tiley - control.input().getBlockY()) % block.size != 0 || (tilex - control.input().getBlockX()) % block.size != 0)) {
|
||||
return;
|
||||
}else{
|
||||
storeX = drawx;
|
||||
storeY = drawy;
|
||||
}
|
||||
}
|
||||
|
||||
float opacity = (float) Settings.getInt("previewopacity") / 100f;
|
||||
Draw.color(Color.WHITE);
|
||||
Draw.alpha(opacity);
|
||||
|
||||
drawPreview(block, drawx, drawy, rotation, opacity);
|
||||
|
||||
Draw.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package io.anuke.mindustry.graphics;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Colors;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.game.TeamInfo.TeamData;
|
||||
import io.anuke.mindustry.input.InputHandler;
|
||||
@@ -31,127 +31,125 @@ public class OverlayRenderer {
|
||||
|
||||
public void draw(){
|
||||
|
||||
//draw config selected block
|
||||
if(ui.configfrag.isShown()){
|
||||
Tile tile = ui.configfrag.getSelectedTile();
|
||||
tile.block().drawConfigure(tile);
|
||||
}
|
||||
for(Player player : players) {
|
||||
|
||||
int tilex = control.input().getBlockX();
|
||||
int tiley = control.input().getBlockY();
|
||||
InputHandler input = control.input(player.playerIndex);
|
||||
|
||||
if(mobile){
|
||||
Vector2 vec = Graphics.world(Gdx.input.getX(0), Gdx.input.getY(0));
|
||||
tilex = Mathf.scl2(vec.x, tilesize);
|
||||
tiley = Mathf.scl2(vec.y, tilesize);
|
||||
}
|
||||
|
||||
InputHandler input = control.input();
|
||||
|
||||
//draw placement box
|
||||
if((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) && (!ui.hasMouse() || mobile)
|
||||
&& control.input().drawPlace())){
|
||||
|
||||
input.placeMode.draw(control.input().getBlockX(), control.input().getBlockY(),
|
||||
control.input().getBlockEndX(), control.input().getBlockEndY());
|
||||
|
||||
if(input.breakMode == PlaceMode.holdDelete)
|
||||
input.breakMode.draw(tilex, tiley, 0, 0);
|
||||
|
||||
}else if(input.breakMode.delete && control.input().drawPlace()
|
||||
&& (input.recipe == null || !state.inventory.hasItems(input.recipe.requirements))
|
||||
&& (input.placeMode.delete || input.breakMode.both || !mobile)){
|
||||
|
||||
if(input.breakMode == PlaceMode.holdDelete)
|
||||
input.breakMode.draw(tilex, tiley, 0, 0);
|
||||
else
|
||||
input.breakMode.draw(control.input().getBlockX(), control.input().getBlockY(),
|
||||
control.input().getBlockEndX(), control.input().getBlockEndY());
|
||||
}
|
||||
|
||||
if(ui.toolfrag.confirming){
|
||||
ToolFragment t = ui.toolfrag;
|
||||
PlaceMode.areaDelete.draw(t.px, t.py, t.px2, t.py2);
|
||||
}
|
||||
|
||||
Draw.reset();
|
||||
|
||||
//draw selected block bars and info
|
||||
if(input.recipe == null && !ui.hasMouse() && !ui.configfrag.isShown()){
|
||||
Tile tile = world.tileWorld(Graphics.mouseWorld().x, Graphics.mouseWorld().y);
|
||||
|
||||
if(tile != null && tile.block() != Blocks.air){
|
||||
Tile target = tile;
|
||||
if(tile.isLinked())
|
||||
target = tile.getLinked();
|
||||
|
||||
if(showBlockDebug && target.entity != null){
|
||||
Draw.color(Color.RED);
|
||||
Lines.crect(target.drawx(), target.drawy(), target.block().size * tilesize, target.block().size * tilesize);
|
||||
Vector2 v = new Vector2();
|
||||
|
||||
Draw.tcolor(Color.YELLOW);
|
||||
Draw.tscl(0.25f);
|
||||
Array<Object> arr = target.block().getDebugInfo(target);
|
||||
StringBuilder result = new StringBuilder();
|
||||
for(int i = 0; i < arr.size/2; i ++){
|
||||
result.append(arr.get(i*2));
|
||||
result.append(": ");
|
||||
result.append(arr.get(i*2 + 1));
|
||||
result.append("\n");
|
||||
}
|
||||
Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
|
||||
Draw.color(0f, 0f, 0f, 0.5f);
|
||||
Fill.rect(target.drawx(), target.drawy(), v.x, v.y);
|
||||
Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
|
||||
Draw.tscl(fontscale);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
if(Inputs.keyDown("block_info") && target.block().isAccessible()){
|
||||
Draw.color(Colors.get("accent"));
|
||||
Lines.crect(target.drawx(), target.drawy(), target.block().size * tilesize, target.block().size * tilesize);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
if(target.entity != null) {
|
||||
int bot = 0, top = 0;
|
||||
for (BlockBar bar : target.block().bars.list()) {
|
||||
float offset = Mathf.sign(bar.top) * (target.block().size / 2f * tilesize + 3f + 4f * ((bar.top ? top : bot))) +
|
||||
(bar.top ? -1f : 0f);
|
||||
|
||||
float value = bar.value.get(target);
|
||||
|
||||
if(MathUtils.isEqual(value, -1f)) continue;
|
||||
|
||||
drawBar(bar.type.color, target.drawx(), target.drawy() + offset, value);
|
||||
|
||||
if (bar.top)
|
||||
top++;
|
||||
else
|
||||
bot++;
|
||||
}
|
||||
}
|
||||
|
||||
target.block().drawSelect(target);
|
||||
//draw config selected block
|
||||
if(input.frag.config.isShown()){
|
||||
Tile tile = input.frag.config.getSelectedTile();
|
||||
tile.block().drawConfigure(tile);
|
||||
}
|
||||
|
||||
int tilex = input.getBlockX();
|
||||
int tiley = input.getBlockY();
|
||||
|
||||
//draw placement box
|
||||
if ((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) && (!ui.hasMouse() || mobile)
|
||||
&& input.drawPlace())) {
|
||||
|
||||
input.placeMode.draw(input, input.getBlockX(),
|
||||
input.getBlockY(), input.getBlockEndX(), input.getBlockEndY());
|
||||
|
||||
if (input.breakMode == PlaceMode.holdDelete)
|
||||
input.breakMode.draw(input, tilex, tiley, 0, 0);
|
||||
|
||||
} else if (input.breakMode.delete && input.drawPlace()
|
||||
&& (input.recipe == null || !state.inventory.hasItems(input.recipe.requirements))
|
||||
&& (input.placeMode.delete || input.breakMode.both || !mobile)) {
|
||||
|
||||
if (input.breakMode == PlaceMode.holdDelete)
|
||||
input.breakMode.draw(input, tilex, tiley, 0, 0);
|
||||
else
|
||||
input.breakMode.draw(input, input.getBlockX(),
|
||||
input.getBlockY(), input.getBlockEndX(), input.getBlockEndY());
|
||||
}
|
||||
|
||||
if (input.frag.tool.confirming) {
|
||||
ToolFragment t = input.frag.tool;
|
||||
PlaceMode.areaDelete.draw(input, t.px, t.py, t.px2, t.py2);
|
||||
}
|
||||
}
|
||||
|
||||
if(control.input().isDroppingItem()){
|
||||
Vector2 v = Graphics.mouseWorld();
|
||||
float size = 8;
|
||||
Draw.rect(player.inventory.getItem().item.region, v.x, v.y, size, size);
|
||||
Draw.color("accent");
|
||||
Lines.circle(v.x, v.y, 6 + Mathf.absin(Timers.time(), 5f, 1f));
|
||||
Draw.reset();
|
||||
|
||||
Tile tile = world.tileWorld(v.x, v.y);
|
||||
if(tile != null) tile = tile.target();
|
||||
if(tile != null && tile.block().acceptStack(player.inventory.getItem().item, player.inventory.getItem().amount, tile, player) > 0){
|
||||
Draw.color("place");
|
||||
Lines.square(tile.drawx(), tile.drawy(), tile.block().size*tilesize/2f + 1 + Mathf.absin(Timers.time(), 5f, 1f));
|
||||
Draw.color();
|
||||
//draw selected block bars and info
|
||||
if (input.recipe == null && !ui.hasMouse() && !input.frag.config.isShown()) {
|
||||
Tile tile = world.tileWorld(Graphics.mouseWorld().x, Graphics.mouseWorld().y);
|
||||
|
||||
if (tile != null && tile.block() != Blocks.air) {
|
||||
Tile target = tile;
|
||||
if (tile.isLinked())
|
||||
target = tile.getLinked();
|
||||
|
||||
if (showBlockDebug && target.entity != null) {
|
||||
Draw.color(Color.RED);
|
||||
Lines.crect(target.drawx(), target.drawy(), target.block().size * tilesize, target.block().size * tilesize);
|
||||
Vector2 v = new Vector2();
|
||||
|
||||
Draw.tcolor(Color.YELLOW);
|
||||
Draw.tscl(0.25f);
|
||||
Array<Object> arr = target.block().getDebugInfo(target);
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < arr.size / 2; i++) {
|
||||
result.append(arr.get(i * 2));
|
||||
result.append(": ");
|
||||
result.append(arr.get(i * 2 + 1));
|
||||
result.append("\n");
|
||||
}
|
||||
Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
|
||||
Draw.color(0f, 0f, 0f, 0.5f);
|
||||
Fill.rect(target.drawx(), target.drawy(), v.x, v.y);
|
||||
Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
|
||||
Draw.tscl(fontscale);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
if (Inputs.keyDown("block_info") && target.block().isAccessible()) {
|
||||
Draw.color(Colors.get("accent"));
|
||||
Lines.crect(target.drawx(), target.drawy(), target.block().size * tilesize, target.block().size * tilesize);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
if (target.entity != null) {
|
||||
int bot = 0, top = 0;
|
||||
for (BlockBar bar : target.block().bars.list()) {
|
||||
float offset = Mathf.sign(bar.top) * (target.block().size / 2f * tilesize + 3f + 4f * ((bar.top ? top : bot))) +
|
||||
(bar.top ? -1f : 0f);
|
||||
|
||||
float value = bar.value.get(target);
|
||||
|
||||
if (MathUtils.isEqual(value, -1f)) continue;
|
||||
|
||||
drawBar(bar.type.color, target.drawx(), target.drawy() + offset, value);
|
||||
|
||||
if (bar.top)
|
||||
top++;
|
||||
else
|
||||
bot++;
|
||||
}
|
||||
}
|
||||
|
||||
target.block().drawSelect(target);
|
||||
}
|
||||
}
|
||||
|
||||
if (input.isDroppingItem()) {
|
||||
Vector2 v = Graphics.mouseWorld();
|
||||
float size = 8;
|
||||
Draw.rect(player.inventory.getItem().item.region, v.x, v.y, size, size);
|
||||
Draw.color("accent");
|
||||
Lines.circle(v.x, v.y, 6 + Mathf.absin(Timers.time(), 5f, 1f));
|
||||
Draw.reset();
|
||||
|
||||
Tile tile = world.tileWorld(v.x, v.y);
|
||||
if (tile != null) tile = tile.target();
|
||||
if (tile != null && tile.block().acceptStack(player.inventory.getItem().item, player.inventory.getItem().amount, tile, player) > 0) {
|
||||
Draw.color("place");
|
||||
Lines.square(tile.drawx(), tile.drawy(), tile.block().size * tilesize / 2f + 1 + Mathf.absin(Timers.time(), 5f, 1f));
|
||||
Draw.color();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if((!debug || showUI) && Settings.getBool("healthbars")){
|
||||
|
||||
Reference in New Issue
Block a user