Configurable lights

This commit is contained in:
Anuken
2019-11-18 16:58:39 -05:00
parent 5e2dd89d3b
commit 6bc98bbe67
4 changed files with 60 additions and 17 deletions

View File

@@ -742,8 +742,8 @@ public class Blocks implements ContentList{
//disabled until implemented properly
requirements(Category.effect, BuildVisibility.lightingOnly, ItemStack.with(Items.graphite, 5));
color = Color.valueOf("7d93ff");
brightness = 0.6f;
radius = 80f;
brightness = 0.67f;
radius = 120f;
consumes.power(0.05f);
}};

View File

@@ -12,16 +12,17 @@ public class ColorPicker extends FloatingDialog{
public ColorPicker(){
super("$pickcolor");
shown(this::setup);
}
public void show(Color color, Cons<Color> consumer){
show(color, true, consumer);
}
public void show(Color color, boolean alpha, Cons<Color> consumer){
this.current.set(color);
this.cons = consumer;
show();
}
void setup(){
cont.clear();
cont.pane(t -> {
t.table(Tex.pane, i -> {
@@ -45,13 +46,13 @@ public class ColorPicker extends FloatingDialog{
t.add("B").color(Color.royal);
t.addSlider(0f, 1f, 0.01f, current.b, current::b).width(w);
t.row();
t.add("A");
t.addSlider(0f, 1f, 0.01f, current.a, current::a).width(w);
t.row();
if(alpha){
t.add("A");
t.addSlider(0f, 1f, 0.01f, current.a, current::a).width(w);
t.row();
}
});
buttons.clear();
addCloseButton();
buttons.addImageTextButton("$ok", Icon.checkSmall, () -> {

View File

@@ -98,7 +98,7 @@ public class MessageBlock extends Block{
public void buildTable(Tile tile, Table table){
MessageBlockEntity entity = tile.entity();
table.addImageButton(io.anuke.mindustry.gen.Icon.pencilSmall, () -> {
table.addImageButton(Icon.pencilSmall, () -> {
if(mobile){
Core.input.getTextInput(new TextInput(){{
text = entity.message;

View File

@@ -2,14 +2,21 @@ package io.anuke.mindustry.world.blocks.power;
import io.anuke.arc.graphics.*;
import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.scene.ui.layout.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.entities.type.*;
import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.world.*;
import static io.anuke.mindustry.Vars.renderer;
import java.io.*;
import static io.anuke.mindustry.Vars.*;
public class LightBlock extends Block{
protected Color color = Color.royal;
protected float brightness = 0.5f;
private static int lastColor = 0;
protected float brightness = 0.9f;
protected float radius = 200f;
protected int topRegion;
@@ -22,16 +29,38 @@ public class LightBlock extends Block{
entityType = LightEntity::new;
}
@Override
public void playerPlaced(Tile tile){
if(lastColor != 0){
tile.configure(lastColor);
}
}
@Override
public void draw(Tile tile){
super.draw(tile);
LightEntity entity = tile.entity();
Draw.blend(Blending.additive);
Draw.color(color, tile.entity.efficiency() * 0.3f);
Draw.color(Tmp.c1.set(entity.color), entity.efficiency() * 0.3f);
Draw.rect(reg(topRegion), tile.drawx(), tile.drawy());
Draw.color();
Draw.blend();
}
@Override
public void buildTable(Tile tile, Table table){
LightEntity entity = tile.entity();
table.addImageButton(Icon.pencilSmall, () -> {
ui.picker.show(Tmp.c1.set(entity.color).a(0.5f), false, res -> {
entity.color = res.rgba();
lastColor = entity.color;
});
control.input.frag.config.hideConfig();
}).size(40f);
}
@Override
public void configured(Tile tile, Player player, int value){
tile.<LightEntity>entity().color = value;
@@ -39,10 +68,23 @@ public class LightBlock extends Block{
@Override
public void drawLight(Tile tile){
renderer.lights.add(tile.drawx(), tile.drawy(), radius, color, brightness * tile.entity.efficiency());
LightEntity entity = tile.entity();
renderer.lights.add(tile.drawx(), tile.drawy(), radius, Tmp.c1.set(entity.color), brightness * tile.entity.efficiency());
}
public class LightEntity extends TileEntity{
public int color;
public int color = Pal.accent.rgba();
@Override
public void write(DataOutput stream) throws IOException{
super.write(stream);
stream.writeInt(color);
}
@Override
public void read(DataInput stream, byte revision) throws IOException{
super.read(stream, revision);
color = stream.readInt();
}
}
}