Canvas block blending
This commit is contained in:
BIN
core/assets-raw/sprites/blocks/logic/canvas-corner1.png
Normal file
BIN
core/assets-raw/sprites/blocks/logic/canvas-corner1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 174 B |
BIN
core/assets-raw/sprites/blocks/logic/canvas-corner2.png
Normal file
BIN
core/assets-raw/sprites/blocks/logic/canvas-corner2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 174 B |
BIN
core/assets-raw/sprites/blocks/logic/canvas-side1.png
Normal file
BIN
core/assets-raw/sprites/blocks/logic/canvas-side1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 366 B |
BIN
core/assets-raw/sprites/blocks/logic/canvas-side2.png
Normal file
BIN
core/assets-raw/sprites/blocks/logic/canvas-side2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 395 B |
@@ -5,6 +5,7 @@ import arc.util.*;
|
|||||||
import mindustry.*;
|
import mindustry.*;
|
||||||
|
|
||||||
public abstract class Mod{
|
public abstract class Mod{
|
||||||
|
|
||||||
/** @return the config file for this plugin, as the file 'mods/[plugin-name]/config.json'.*/
|
/** @return the config file for this plugin, as the file 'mods/[plugin-name]/config.json'.*/
|
||||||
public Fi getConfig(){
|
public Fi getConfig(){
|
||||||
return Vars.mods.getConfig(this);
|
return Vars.mods.getConfig(this);
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ public class Planet extends UnlockableContent{
|
|||||||
return (orbitOffset + universe.secondsf() / (orbitTime / 360f)) % 360f;
|
return (orbitOffset + universe.secondsf() / (orbitTime / 360f)) % 360f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Calulates rotation on own axis based on universe time.*/
|
/** Calculates rotation on own axis based on universe time.*/
|
||||||
public float getRotation(){
|
public float getRotation(){
|
||||||
//tidally locked planets always face toward parents
|
//tidally locked planets always face toward parents
|
||||||
if(tidalLock){
|
if(tidalLock){
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import arc.scene.ui.layout.*;
|
|||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import arc.util.io.*;
|
import arc.util.io.*;
|
||||||
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
@@ -26,6 +27,12 @@ public class CanvasBlock extends Block{
|
|||||||
public int bitsPerPixel;
|
public int bitsPerPixel;
|
||||||
public IntIntMap colorToIndex = new IntIntMap();
|
public IntIntMap colorToIndex = new IntIntMap();
|
||||||
|
|
||||||
|
public @Load("@-side1") TextureRegion side1;
|
||||||
|
public @Load("@-side2") TextureRegion side2;
|
||||||
|
|
||||||
|
public @Load("@-corner1") TextureRegion corner1;
|
||||||
|
public @Load("@-corner2") TextureRegion corner2;
|
||||||
|
|
||||||
public CanvasBlock(String name){
|
public CanvasBlock(String name){
|
||||||
super(name);
|
super(name);
|
||||||
|
|
||||||
@@ -55,6 +62,7 @@ public class CanvasBlock extends Block{
|
|||||||
public class CanvasBuild extends Building{
|
public class CanvasBuild extends Building{
|
||||||
public @Nullable Texture texture;
|
public @Nullable Texture texture;
|
||||||
public byte[] data = new byte[Mathf.ceil(canvasSize * canvasSize * bitsPerPixel / 8f)];
|
public byte[] data = new byte[Mathf.ceil(canvasSize * canvasSize * bitsPerPixel / 8f)];
|
||||||
|
public int blending;
|
||||||
|
|
||||||
public void updateTexture(){
|
public void updateTexture(){
|
||||||
if(headless) return;
|
if(headless) return;
|
||||||
@@ -113,15 +121,48 @@ public class CanvasBlock extends Block{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProximityUpdate(){
|
||||||
|
super.onProximityUpdate();
|
||||||
|
|
||||||
|
blending = 0;
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
if(blends(world.tile(tile.x + Geometry.d4[i].x * size, tile.y + Geometry.d4[i].y * size))) blending |= (1 << i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean blends(Tile other){
|
||||||
|
return other != null && other.build != null && other.build.block == block && other.build.tileX() == other.x && other.build.tileY() == other.y;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(){
|
public void draw(){
|
||||||
|
if(blending == 0){
|
||||||
super.draw();
|
super.draw();
|
||||||
|
}
|
||||||
|
|
||||||
if(texture == null){
|
if(texture == null){
|
||||||
updateTexture();
|
updateTexture();
|
||||||
}
|
}
|
||||||
Tmp.tr1.set(texture);
|
Tmp.tr1.set(texture);
|
||||||
Draw.rect(Tmp.tr1, x, y, size * tilesize - padding, size * tilesize - padding);
|
float pad = blending == 0 ? padding : 0f;
|
||||||
|
|
||||||
|
Draw.rect(Tmp.tr1, x, y, size * tilesize - pad, size * tilesize - pad);
|
||||||
|
for(int i = 0; i < 4; i ++){
|
||||||
|
if((blending & (1 << i)) == 0){
|
||||||
|
Draw.rect(i >= 2 ? side2 : side1, x, y, i * 90);
|
||||||
|
|
||||||
|
if((blending & (1 << ((i + 1) % 4))) != 0){
|
||||||
|
Draw.rect(i >= 2 ? corner2 : corner1, x, y, i * 90);
|
||||||
|
}
|
||||||
|
|
||||||
|
if((blending & (1 << (Mathf.mod(i - 1, 4)))) != 0){
|
||||||
|
Draw.yscl = -1f;
|
||||||
|
Draw.rect(i >= 2 ? corner2 : corner1, x, y, i * 90);
|
||||||
|
Draw.yscl = 1f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -143,9 +184,7 @@ public class CanvasBlock extends Block{
|
|||||||
int[] curColor = {palette[0]};
|
int[] curColor = {palette[0]};
|
||||||
boolean[] modified = {false};
|
boolean[] modified = {false};
|
||||||
|
|
||||||
dialog.resized(() -> {
|
dialog.resized(dialog::hide);
|
||||||
dialog.hide();
|
|
||||||
});
|
|
||||||
|
|
||||||
dialog.cont.table(Tex.pane, body -> {
|
dialog.cont.table(Tex.pane, body -> {
|
||||||
body.stack(new Element(){
|
body.stack(new Element(){
|
||||||
|
|||||||
Reference in New Issue
Block a user