mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-10 18:57:39 +07:00
Canvas block blending
This commit is contained in:
parent
381197d58f
commit
ddadbab74d
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.*;
|
||||
|
||||
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);
|
||||
|
@ -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){
|
||||
|
@ -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(){
|
||||
|
Loading…
Reference in New Issue
Block a user