Configurable lights
This commit is contained in:
@@ -742,8 +742,8 @@ public class Blocks implements ContentList{
|
|||||||
//disabled until implemented properly
|
//disabled until implemented properly
|
||||||
requirements(Category.effect, BuildVisibility.lightingOnly, ItemStack.with(Items.graphite, 5));
|
requirements(Category.effect, BuildVisibility.lightingOnly, ItemStack.with(Items.graphite, 5));
|
||||||
color = Color.valueOf("7d93ff");
|
color = Color.valueOf("7d93ff");
|
||||||
brightness = 0.6f;
|
brightness = 0.67f;
|
||||||
radius = 80f;
|
radius = 120f;
|
||||||
consumes.power(0.05f);
|
consumes.power(0.05f);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
|||||||
@@ -12,16 +12,17 @@ public class ColorPicker extends FloatingDialog{
|
|||||||
|
|
||||||
public ColorPicker(){
|
public ColorPicker(){
|
||||||
super("$pickcolor");
|
super("$pickcolor");
|
||||||
shown(this::setup);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show(Color color, Cons<Color> consumer){
|
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.current.set(color);
|
||||||
this.cons = consumer;
|
this.cons = consumer;
|
||||||
show();
|
show();
|
||||||
}
|
|
||||||
|
|
||||||
void setup(){
|
|
||||||
cont.clear();
|
cont.clear();
|
||||||
cont.pane(t -> {
|
cont.pane(t -> {
|
||||||
t.table(Tex.pane, i -> {
|
t.table(Tex.pane, i -> {
|
||||||
@@ -45,13 +46,13 @@ public class ColorPicker extends FloatingDialog{
|
|||||||
t.add("B").color(Color.royal);
|
t.add("B").color(Color.royal);
|
||||||
t.addSlider(0f, 1f, 0.01f, current.b, current::b).width(w);
|
t.addSlider(0f, 1f, 0.01f, current.b, current::b).width(w);
|
||||||
t.row();
|
t.row();
|
||||||
|
if(alpha){
|
||||||
t.add("A");
|
t.add("A");
|
||||||
t.addSlider(0f, 1f, 0.01f, current.a, current::a).width(w);
|
t.addSlider(0f, 1f, 0.01f, current.a, current::a).width(w);
|
||||||
t.row();
|
t.row();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
buttons.clear();
|
buttons.clear();
|
||||||
addCloseButton();
|
addCloseButton();
|
||||||
buttons.addImageTextButton("$ok", Icon.checkSmall, () -> {
|
buttons.addImageTextButton("$ok", Icon.checkSmall, () -> {
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ public class MessageBlock extends Block{
|
|||||||
public void buildTable(Tile tile, Table table){
|
public void buildTable(Tile tile, Table table){
|
||||||
MessageBlockEntity entity = tile.entity();
|
MessageBlockEntity entity = tile.entity();
|
||||||
|
|
||||||
table.addImageButton(io.anuke.mindustry.gen.Icon.pencilSmall, () -> {
|
table.addImageButton(Icon.pencilSmall, () -> {
|
||||||
if(mobile){
|
if(mobile){
|
||||||
Core.input.getTextInput(new TextInput(){{
|
Core.input.getTextInput(new TextInput(){{
|
||||||
text = entity.message;
|
text = entity.message;
|
||||||
|
|||||||
@@ -2,14 +2,21 @@ package io.anuke.mindustry.world.blocks.power;
|
|||||||
|
|
||||||
import io.anuke.arc.graphics.*;
|
import io.anuke.arc.graphics.*;
|
||||||
import io.anuke.arc.graphics.g2d.*;
|
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.entities.type.*;
|
||||||
|
import io.anuke.mindustry.gen.*;
|
||||||
|
import io.anuke.mindustry.graphics.*;
|
||||||
import io.anuke.mindustry.world.*;
|
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{
|
public class LightBlock extends Block{
|
||||||
protected Color color = Color.royal;
|
private static int lastColor = 0;
|
||||||
protected float brightness = 0.5f;
|
|
||||||
|
protected float brightness = 0.9f;
|
||||||
protected float radius = 200f;
|
protected float radius = 200f;
|
||||||
protected int topRegion;
|
protected int topRegion;
|
||||||
|
|
||||||
@@ -22,16 +29,38 @@ public class LightBlock extends Block{
|
|||||||
entityType = LightEntity::new;
|
entityType = LightEntity::new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void playerPlaced(Tile tile){
|
||||||
|
if(lastColor != 0){
|
||||||
|
tile.configure(lastColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Tile tile){
|
public void draw(Tile tile){
|
||||||
super.draw(tile);
|
super.draw(tile);
|
||||||
|
LightEntity entity = tile.entity();
|
||||||
|
|
||||||
Draw.blend(Blending.additive);
|
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.rect(reg(topRegion), tile.drawx(), tile.drawy());
|
||||||
Draw.color();
|
Draw.color();
|
||||||
Draw.blend();
|
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
|
@Override
|
||||||
public void configured(Tile tile, Player player, int value){
|
public void configured(Tile tile, Player player, int value){
|
||||||
tile.<LightEntity>entity().color = value;
|
tile.<LightEntity>entity().color = value;
|
||||||
@@ -39,10 +68,23 @@ public class LightBlock extends Block{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawLight(Tile tile){
|
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 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user