Canvas block blending

This commit is contained in:
Anuken 2022-11-08 16:52:12 -05:00
parent 381197d58f
commit ddadbab74d
7 changed files with 46 additions and 6 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 395 B

View File

@ -5,6 +5,7 @@ import arc.util.*;
import mindustry.*;
public abstract class Mod{
/** @return the config file for this plugin, as the file 'mods/[plugin-name]/config.json'.*/
public Fi getConfig(){
return Vars.mods.getConfig(this);

View File

@ -234,7 +234,7 @@ public class Planet extends UnlockableContent{
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(){
//tidally locked planets always face toward parents
if(tidalLock){

View File

@ -13,6 +13,7 @@ import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.annotations.Annotations.*;
import mindustry.gen.*;
import mindustry.ui.*;
import mindustry.world.*;
@ -26,6 +27,12 @@ public class CanvasBlock extends Block{
public int bitsPerPixel;
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){
super(name);
@ -55,6 +62,7 @@ public class CanvasBlock extends Block{
public class CanvasBuild extends Building{
public @Nullable Texture texture;
public byte[] data = new byte[Mathf.ceil(canvasSize * canvasSize * bitsPerPixel / 8f)];
public int blending;
public void updateTexture(){
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
public void draw(){
super.draw();
if(blending == 0){
super.draw();
}
if(texture == null){
updateTexture();
}
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
@ -143,9 +184,7 @@ public class CanvasBlock extends Block{
int[] curColor = {palette[0]};
boolean[] modified = {false};
dialog.resized(() -> {
dialog.hide();
});
dialog.resized(dialog::hide);
dialog.cont.table(Tex.pane, body -> {
body.stack(new Element(){