Char tile picker support

This commit is contained in:
Anuken
2025-07-18 18:14:32 -04:00
parent 4abc2aba8c
commit fba935c527
7 changed files with 123 additions and 24 deletions
@@ -2,13 +2,16 @@ package mindustry.world.blocks.environment;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.*;
import mindustry.annotations.Annotations.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.world.*;
public class CharacterOverlay extends OverlayFloor{
/** This is a reduced character set! It is not ASCII! */
/** This is a special reduced character set that fits in 6 bits! It is not ASCII! */
public static final String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890\"!?.,;:()[]{}<>|/@\\^-%+=#_&~";
public @Load(value = "character-overlay#", length = 64) TextureRegion[] letterRegions;
@@ -20,6 +23,8 @@ public class CharacterOverlay extends OverlayFloor{
variants = 0;
rotate = true;
drawArrow = false;
saveConfig = true;
editorConfigurable = true;
}
@Override
@@ -30,6 +35,42 @@ public class CharacterOverlay extends OverlayFloor{
Draw.color();
}
@Override
public Object getConfig(Tile tile){
return (int)tile.overlayData;
}
@Override
public void drawPlanRegion(BuildPlan plan, Eachable<BuildPlan> list){
byte data = 0;
if(plan.config instanceof Integer i){
data = i.byteValue();
}
int letterChar = CharOverlayData.character(data);
TextureRegion reg = letterRegions[letterChar];
Draw.tint(color);
Draw.rect(reg, plan.drawx(), plan.drawy(), plan.rotation * 90);
Draw.tint(Color.white);
}
@Override
public void onPicked(Tile tile){
Vars.control.input.rotation = CharOverlayData.rotation(tile.overlayData);
}
@Override
public void buildEditorConfig(Table table){
char value = chars.charAt(lastConfig instanceof Integer i ? CharOverlayData.character(i.byteValue()) : 0);
table.field(value + "", val -> {
if(val.length() == 1){
lastConfig = (int)charToData(val.charAt(0));
}
}).valid(t -> t.length() == 1 && chars.indexOf(Character.toUpperCase(t.charAt(0))) != -1).maxTextLength(1);
}
@Override
public void placeEnded(Tile tile, @Nullable Unit builder, int rotation, @Nullable Object config){
byte data = 0;
@@ -3,13 +3,17 @@ package mindustry.world.blocks.environment;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.geom.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.ui.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import static mindustry.Vars.*;
public class ColoredFloor extends Floor{
/** If the alpha value of the color is set to this value, different colors are ignored and no border is drawn. */
public static final int flagIgnoreDifferentColor = 1;
@@ -24,7 +28,7 @@ public class ColoredFloor extends Floor{
public ColoredFloor(String name){
super(name);
saveData = true;
showColorEdit = true;
editorConfigurable = true;
saveConfig = true;
}
@@ -34,6 +38,34 @@ public class ColoredFloor extends Floor{
lastConfig = defaultColorRgba = defaultColor.rgba();
}
@Override
public void buildEditorConfig(Table table){
showColorEdit(table, this);
}
public static void showColorEdit(Table t, Block block){
t.button(b -> {
b.margin(4f);
b.left();
b.table(Tex.pane, in -> {
in.image(Tex.whiteui).update(i -> {
if(block.lastConfig instanceof Integer col){
i.color.set(col | 0xff);
}
}).grow();
}).margin(4).size(50f).padRight(10);
b.add("@color");
}, Styles.cleart, () ->
ui.picker.show(
block.lastConfig instanceof Integer col ? new Color(col | 0xff) : new Color(Color.white), false,
col -> block.lastConfig = col.rgba8888())).left().width(250f).pad(3f).row();
}
@Override
public Object getConfig(Tile tile){
return tile.extraData;
}
@Override
public void drawBase(Tile tile){
//make sure to mask out the alpha channel - it's generally undesirable, and leads to invisible blocks when the data is not initialized
@@ -2,6 +2,7 @@ package mindustry.world.blocks.environment;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
@@ -19,7 +20,7 @@ public class ColoredWall extends StaticWall{
public ColoredWall(String name){
super(name);
saveData = true;
showColorEdit = true;
editorConfigurable = true;
saveConfig = true;
}
@@ -29,6 +30,16 @@ public class ColoredWall extends StaticWall{
lastConfig = defaultColorRgba = defaultColor.rgba();
}
@Override
public Object getConfig(Tile tile){
return tile.extraData;
}
@Override
public void buildEditorConfig(Table table){
ColoredFloor.showColorEdit(table, this);
}
@Override
public void drawBase(Tile tile){
//make sure to mask out the alpha channel - it's generally undesirable, and leads to invisible blocks when thtoe data is not initialized