rename package

This commit is contained in:
sharlottes
2022-05-22 23:58:18 +09:00
parent c94de34331
commit 45e7b84790
46 changed files with 272 additions and 257 deletions

View File

@@ -0,0 +1,228 @@
package informatis.core;
import arc.graphics.*;
import arc.graphics.g2d.TextureRegion;
import arc.math.*;
import arc.struct.*;
import arc.util.*;
import mindustry.ctype.*;
import mindustry.entities.*;
import mindustry.entities.abilities.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.logic.*;
import mindustry.ui.*;
import mindustry.world.blocks.*;
import mindustry.world.blocks.defense.*;
import mindustry.world.blocks.defense.turrets.*;
import mindustry.world.blocks.distribution.*;
import mindustry.world.blocks.environment.*;
import mindustry.world.blocks.power.*;
import mindustry.world.blocks.production.*;
import mindustry.world.blocks.storage.*;
import mindustry.world.blocks.units.*;
import mindustry.world.consumers.*;
import java.lang.reflect.*;
import static informatis.SUtils.*;
import static arc.Core.*;
import static mindustry.Vars.*;
import static informatis.SVars.*;
import static informatis.ui.SIcons.*;
public class BarInfo {
public static Seq<BarData> data = new Seq<>();
public static <T extends Teamc> void getInfo(T target) throws IllegalAccessException, NoSuchFieldException {
data.clear();
if(target instanceof Healthc){
Healthc healthc = (Healthc) target;
float pro = healthc.health();
data.add(new BarData(bundle.format("shar-stat.health", formatNumber(pro)), Pal.health, pro, health));
}
if(target instanceof Unit unit){
float max = ((ShieldRegenFieldAbility) content.units().copy().max(ut -> {
ShieldRegenFieldAbility ability = (ShieldRegenFieldAbility) ut.abilities.find(ab -> ab instanceof ShieldRegenFieldAbility);
if(ability == null) return 0;
return ability.max;
}).abilities.find(abil -> abil instanceof ShieldRegenFieldAbility)).max;
//float commands = Groups.unit.count(u -> u.controller() instanceof FormationAI && ((FormationAI)u.controller()).leader == target);
data.add(new BarData(bundle.format("shar-stat.shield", formatNumber(unit.shield())), Pal.surge, unit.shield() / max, shield));
data.add(new BarData(bundle.format("shar-stat.capacity", unit.stack.item.localizedName, formatNumber(unit.stack.amount), formatNumber(unit.type.itemCapacity)), unit.stack.amount > 0 && unit.stack().item != null ? unit.stack.item.color.cpy().lerp(Color.white, 0.15f) : Color.white, unit.stack.amount / (unit.type.itemCapacity * 1f), item));
//data.add(new BarData(bundle.format("shar-stat.commandUnits", formatNumber(commands), formatNumber(unit.type().commandLimit)), Pal.powerBar.cpy().lerp(Pal.surge.cpy().mul(Pal.lighterOrange), Mathf.absin(Time.time, 7f / (1f + Mathf.clamp(commands / (unit.type().commandLimit * 1f))), 1f)), commands / (unit.type().commandLimit * 1f)));
if(target instanceof Payloadc pay) data.add(new BarData(bundle.format("shar-stat.payloadCapacity", formatNumber(Mathf.round(Mathf.sqrt(pay.payloadUsed()))), formatNumber(Mathf.round(Mathf.sqrt(unit.type().payloadCapacity)))), Pal.items, pay.payloadUsed() / unit.type().payloadCapacity));
if(state.rules.unitAmmo) data.add(new BarData(bundle.format("shar-stat.ammos", formatNumber(unit.ammo()), formatNumber(unit.type().ammoCapacity)), unit.type().ammoType.color(), unit.ammof()));
}
else if(target instanceof Building build){
if(build.block.hasLiquids) data.add(new BarData(bundle.format("shar-stat.capacity", build.liquids.currentAmount() < 0.01f ? build.liquids.current().localizedName : bundle.get("bar.liquid"), formatNumber(build.liquids.currentAmount()), formatNumber(build.block.liquidCapacity)), build.liquids.current().color, build.liquids.currentAmount() / build.block.liquidCapacity, liquid));
if(build.block.hasPower && build.block.consumesPower){
ConsumePower cons = build.block.consPower;
data.add(new BarData(bundle.format("shar-stat.power", formatNumber(build.power.status * 60f * (cons.buffered ? cons.capacity : cons.usage)), formatNumber(60f * (cons.buffered ? cons.capacity : cons.usage))), Pal.powerBar, Mathf.zero(cons.requestedPower(build)) && build.power.graph.getPowerProduced() + build.power.graph.getBatteryStored() > 0f ? 1f : build.power.status, power));
}
if(build.block.hasItems) {
float value;
if (target instanceof CoreBlock.CoreBuild cb) value = cb.storageCapacity * content.items().count(UnlockableContent::unlockedNow);
else if(target instanceof StorageBlock.StorageBuild sb && !sb.canPickup() && sb.linkedCore instanceof CoreBlock.CoreBuild cb) value = cb.storageCapacity * content.items().count(UnlockableContent::unlockedNow);
else value = build.block.itemCapacity;
data.add(new BarData(bundle.format("shar-stat.capacity", bundle.get("category.items"), formatNumber(build.items.total()), value), Pal.items, build.items.total() / value, item));
}
}
if(target instanceof ReloadTurret.ReloadTurretBuild || target instanceof MassDriver.MassDriverBuild){
float pro;
if(target instanceof ReloadTurret.ReloadTurretBuild turret) pro = turret.reloadCounter / ((Turret)turret.block).reload;
else {
MassDriver.MassDriverBuild mass = (MassDriver.MassDriverBuild) target;
pro = mass.reloadCounter;
}
data.add(new BarData(bundle.format("shar-stat.reload", formatNumber(pro * 100f)), Pal.accent.cpy().lerp(Color.orange, pro), pro, reload));
}
if(target instanceof ForceProjector.ForceBuild force){
ForceProjector forceBlock = (ForceProjector) force.block;
float max = forceBlock.shieldHealth + forceBlock.phaseShieldBoost * force.phaseHeat;
data.add(new BarData(bundle.format("shar-stat.shield", formatNumber(max-force.buildup), formatNumber(max)), Pal.shield, (max-force.buildup)/max, shield));
}
if(target instanceof MendProjector.MendBuild || target instanceof OverdriveProjector.OverdriveBuild || target instanceof ConstructBlock.ConstructBuild || target instanceof Reconstructor.ReconstructorBuild || target instanceof UnitFactory.UnitFactoryBuild || target instanceof Drill.DrillBuild || target instanceof GenericCrafter.GenericCrafterBuild) {
float pro;
if(target instanceof MendProjector.MendBuild mend){
pro = (float) mend.sense(LAccess.progress);
Tmp.c1.set(Pal.heal);
}
else if(target instanceof OverdriveProjector.OverdriveBuild over){
OverdriveProjector block = (OverdriveProjector)over.block;
Field ohno = OverdriveProjector.OverdriveBuild.class.getDeclaredField("charge");
ohno.setAccessible(true);
pro = (float) ohno.get(over)/((OverdriveProjector)over.block).reload;
Tmp.c1.set(Color.valueOf("feb380"));
data.add(new BarData(bundle.format("bar.boost", (int)(over.realBoost() * 100)), Pal.accent, over.realBoost() / (block.hasBoost ? block.speedBoost + block.speedBoostPhase : block.speedBoost)));
}
else if(target instanceof ConstructBlock.ConstructBuild construct){
pro = construct.progress;
Tmp.c1.set(Pal.darkerMetal);
}
else if(target instanceof UnitFactory.UnitFactoryBuild factory){
pro = factory.fraction();
Tmp.c1.set(Pal.darkerMetal);
if(factory.unit() == null) data.add(new BarData("[lightgray]" + Iconc.cancel, Pal.power, 0f));
else {
float value = factory.team.data().countType(factory.unit());
data.add(new BarData(bundle.format("bar.unitcap", Fonts.getUnicodeStr(factory.unit().name), formatNumber(value), formatNumber(Units.getCap(factory.team))), Pal.power, value / Units.getCap(factory.team)));
}
}
else if(target instanceof Reconstructor.ReconstructorBuild reconstruct){
pro = reconstruct.fraction();
Tmp.c1.set(Pal.darkerMetal);
if(reconstruct.unit() == null) data.add(new BarData("[lightgray]" + Iconc.cancel, Pal.power, 0f));
else {
float value = reconstruct.team.data().countType(reconstruct.unit());
data.add(new BarData(bundle.format("bar.unitcap", Fonts.getUnicodeStr(reconstruct.unit().name), formatNumber(value), formatNumber(Units.getCap(reconstruct.team))), Pal.power, value / Units.getCap(reconstruct.team)));
}
}
else if(target instanceof Drill.DrillBuild drill){
pro = (float) drill.sense(LAccess.progress);
Tmp.c1.set(drill.dominantItem == null ? Pal.items : drill.dominantItem.color);
data.add(new BarData(bundle.format("bar.drillspeed", formatNumber(drill.lastDrillSpeed * 60 * drill.timeScale())), Pal.ammo, drill.warmup));
}
else {
GenericCrafter.GenericCrafterBuild crafter = (GenericCrafter.GenericCrafterBuild) target;
GenericCrafter block = (GenericCrafter) crafter.block;
pro = (float) crafter.sense(LAccess.progress);
if(block.outputItem != null) Tmp.c1.set(block.outputItem.item.color);
else if(block.outputLiquid != null) Tmp.c1.set(block.outputLiquid.liquid.color);
else Tmp.c1.set(Pal.items);
}
data.add(new BarData(bundle.format("shar-stat.progress", formatNumber(pro * 100f)), Tmp.c1, pro));
}
if(target instanceof PowerGenerator.GeneratorBuild generator){
data.add(new BarData(bundle.format("shar-stat.powerIn", formatNumber(generator.getPowerProduction() * generator.timeScale() * 60f)), Pal.powerBar, generator.productionEfficiency, power));
}
if(target instanceof PowerNode.PowerNodeBuild || target instanceof PowerTurret.PowerTurretBuild) {
float value, max;
if(target instanceof PowerNode.PowerNodeBuild node){
max = node.power.graph.getLastPowerStored();
value = node.power.graph.getLastCapacity();
data.add(new BarData(bundle.format("bar.powerlines", node.power.links.size, ((PowerNode)node.block).maxNodes), Pal.items, (float)node.power.links.size / (float)((PowerNode)node.block).maxNodes));
data.add(new BarData(bundle.format("shar-stat.powerOut", "-" + formatNumber(node.power.graph.getLastScaledPowerOut() * 60f)), Pal.powerBar, node.power.graph.getLastScaledPowerOut() / node.power.graph.getLastScaledPowerIn(), power));
data.add(new BarData(bundle.format("shar-stat.powerIn", formatNumber(node.power.graph.getLastScaledPowerIn() * 60f)), Pal.powerBar, node.power.graph.getLastScaledPowerIn() / node.power.graph.getLastScaledPowerOut(), power));
data.add(new BarData(bundle.format("bar.powerbalance", (node.power.graph.getPowerBalance() >= 0 ? "+" : "") + formatNumber(node.power.graph.getPowerBalance() * 60)), Pal.powerBar, node.power.graph.getLastPowerProduced() / node.power.graph.getLastPowerNeeded(), power));
}
else { //TODO: why is this different
PowerTurret.PowerTurretBuild turret = (PowerTurret.PowerTurretBuild) target;
max = turret.block.consPower.usage;
value = turret.power.status * turret.power.graph.getLastScaledPowerIn();
}
data.add(new BarData(bundle.format("shar-stat.power", formatNumber(Math.max(value, max) * 60), formatNumber(max * 60)), Pal.power, value / max));
}
if(target instanceof ItemTurret.ItemTurretBuild turret) {
ItemTurret block = (ItemTurret)turret.block;
data.add(new BarData(bundle.format("shar-stat.capacity", turret.hasAmmo() ? block.ammoTypes.findKey(turret.peekAmmo(), true).localizedName : bundle.get("stat.ammo"), formatNumber(turret.totalAmmo), formatNumber(block.maxAmmo)), turret.hasAmmo() ? block.ammoTypes.findKey(turret.peekAmmo(), true).color : Pal.ammo, turret.totalAmmo / (float)block.maxAmmo, ammo));
}
if(target instanceof LiquidTurret.LiquidTurretBuild turret){
data.add(new BarData(bundle.format("shar-stat.capacity", turret.liquids.currentAmount() < 0.01f ? turret.liquids.current().localizedName : bundle.get("stat.ammo"), formatNumber(turret.liquids.get(turret.liquids.current())), formatNumber(turret.block.liquidCapacity)), turret.liquids.current().color, turret.liquids.get(turret.liquids.current()) / turret.block.liquidCapacity, liquid));
}
if(target instanceof AttributeCrafter.AttributeCrafterBuild || target instanceof ThermalGenerator.ThermalGeneratorBuild || (target instanceof SolidPump.SolidPumpBuild crafter && ((SolidPump)crafter.block).attribute != null)) {
float display, pro;
if (target instanceof AttributeCrafter.AttributeCrafterBuild crafter) {
AttributeCrafter block = (AttributeCrafter) crafter.block;
display = (block.baseEfficiency + Math.min(block.maxBoost, block.boostScale * block.sumAttribute(block.attribute, crafter.tileX(), crafter.tileY()))) * 100f;
pro = block.boostScale * crafter.attrsum / block.maxBoost;
}
else if (target instanceof ThermalGenerator.ThermalGeneratorBuild thermal) {
ThermalGenerator block = (ThermalGenerator) thermal.block;
float max = content.blocks().max(b -> b instanceof Floor f && f.attributes != null ? f.attributes.get(block.attribute) : 0).asFloor().attributes.get(block.attribute);
display = block.sumAttribute(block.attribute, thermal.tileX(), thermal.tileY()) * 100;
pro = block.sumAttribute(block.attribute, thermal.tileX(), thermal.tileY()) / block.size / block.size / max;
}
else {
SolidPump.SolidPumpBuild crafter = (SolidPump.SolidPumpBuild) target;
SolidPump block = (SolidPump) crafter.block;
float fraction = Math.max(crafter.validTiles + crafter.boost + (block.attribute == null ? 0 : block.attribute.env()), 0);
float max = content.blocks().max(b -> b instanceof Floor f && f.attributes != null ? f.attributes.get(block.attribute) : 0).asFloor().attributes.get(block.attribute);
display = Math.max(block.sumAttribute(block.attribute, crafter.tileX(), crafter.tileY()) / block.size / block.size + block.baseEfficiency, 0f) * 100 * block.percentSolid(crafter.tileX(), crafter.tileY());
pro = fraction / max;
}
data.add(new BarData(bundle.format("shar-stat.attr", Mathf.round(display)), Pal.ammo, pro));
}
}
public static class BarData {
public String name;
public Color color;
public float number;
public TextureRegion icon = clear;
BarData(String name, Color color, float number) {
this.name = name;
this.color = color;
this.number = number;
}
BarData(String name, Color color, float number, TextureRegion icon) {
this(name, color, number);
this.icon = icon;
}
}
}

View File

@@ -0,0 +1,267 @@
package informatis.core;
import arc.func.Boolf;
import arc.func.Cons;
import arc.input.KeyCode;
import arc.math.Mathf;
import arc.math.geom.Bresenham2;
import arc.math.geom.Point2;
import arc.struct.IntSeq;
import arc.util.Structs;
import mindustry.content.Blocks;
import mindustry.game.Team;
import mindustry.world.Block;
import mindustry.world.Tile;
import informatis.ui.window.*;
import static informatis.ui.window.MapEditorWindow.*;
import static informatis.ui.window.Windows.editorTable;
import static mindustry.Vars.world;
public enum EditorTool{
zoom(KeyCode.v),
pick(KeyCode.i){
public void touched(int x, int y){
if(!Structs.inBounds(x, y, world.width(), world.height())) return;
Tile tile = world.tile(x, y);
drawBlock = tile.block() == Blocks.air || !tile.block().inEditor ? tile.overlay() == Blocks.air ? tile.floor() : tile.overlay() : tile.block();
}
},
line(KeyCode.l, "replace", "orthogonal"){
@Override
public void touchedLine(int x1, int y1, int x2, int y2){
//straight
if(mode == 1){
if(Math.abs(x2 - x1) > Math.abs(y2 - y1)){
y2 = y1;
}else{
x2 = x1;
}
}
Bresenham2.line(x1, y1, x2, y2, (x, y) -> {
if(mode == 0){
//replace
editorTable.drawBlocksReplace(x, y);
}else{
//normal
editorTable.drawBlocks(x, y);
}
});
}
},
pencil(KeyCode.b, "replace", "square", "drawteams"){
{
edit = true;
draggable = true;
}
@Override
public void touched(int x, int y){
if(mode == -1){
//normal mode
editorTable.drawBlocks(x, y);
}else if(mode == 0){
//replace mode
editorTable.drawBlocksReplace(x, y);
}else if(mode == 1){
//square mode
editorTable.drawBlocks(x, y, true, tile -> true);
}else if(mode == 2){
//draw teams
editorTable.drawCircle(x, y, tile -> tile.setTeam(drawTeam));
}
}
},
eraser(KeyCode.e, "eraseores"){
{
edit = true;
draggable = true;
}
@Override
public void touched(int x, int y){
editorTable.drawCircle(x, y, tile -> {
if(mode == -1){
//erase block
tile.remove();
}else if(mode == 0){
//erase ore
tile.clearOverlay();
}
});
}
},
fill(KeyCode.g, "replaceall", "fillteams"){
{
edit = true;
}
IntSeq stack = new IntSeq();
@Override
public void touched(int x, int y){
if(!Structs.inBounds(x, y, world.width(), world.height()) || world.tile(x, y).block()!=null&&world.tile(x, y).block().isMultiblock()) return;
Tile tile = world.tile(x, y);
//mode 0 or 1, fill everything with the floor/tile or replace it
if(mode == 0 || mode == -1){
if(tile.block().isMultiblock()) return;
Boolf<Tile> tester;
Cons<Tile> setter;
Block drawBlock = MapEditorWindow.drawBlock;
if(drawBlock.isOverlay()){
Block dest = tile.overlay();
if(dest == drawBlock) return;
tester = t -> t.overlay() == dest && (t.floor().hasSurface() || !t.floor().needsSurface);
setter = t -> t.setOverlay(drawBlock);
}else if(drawBlock.isFloor()){
Block dest = tile.floor();
if(dest == drawBlock) return;
tester = t -> t.floor() == dest;
setter = t -> t.setFloorUnder(drawBlock.asFloor());
}else{
Block dest = tile.block();
if(dest == drawBlock) return;
tester = t -> t.block() == dest;
setter = t -> t.setBlock(drawBlock, drawTeam);
}
//replace only when the mode is 0 using the specified functions
fill(x, y, mode == 0, tester, setter);
}else if(mode == 1){ //mode 1 is team fill
//only fill synthetic blocks, it's meaningless otherwise
if(tile.synthetic()){
Team dest = tile.team();
if(dest == drawTeam) return;
fill(x, y, false, t -> t.getTeamID() == dest.id && t.synthetic(), t -> t.setTeam(drawTeam));
}
}
}
void fill(int x, int y, boolean replace, Boolf<Tile> tester, Cons<Tile> filler){
int width = world.width(), height = world.height();
if(replace){
//just do it on everything
for(int cx = 0; cx < width; cx++){
for(int cy = 0; cy < height; cy++){
Tile tile = world.tile(cx, cy);
if(tester.get(tile)){
filler.get(tile);
}
}
}
}else{
//perform flood fill
int x1;
stack.clear();
stack.add(Point2.pack(x, y));
try{
while(stack.size > 0 && stack.size < width*height){
int popped = stack.pop();
x = Point2.x(popped);
y = Point2.y(popped);
x1 = x;
while(x1 >= 0 && tester.get(world.tile(x1, y))) x1--;
x1++;
boolean spanAbove = false, spanBelow = false;
while(x1 < width && tester.get(world.tile(x1, y))){
filler.get(world.tile(x1, y));
if(!spanAbove && y > 0 && tester.get(world.tile(x1, y - 1))){
stack.add(Point2.pack(x1, y - 1));
spanAbove = true;
}else if(spanAbove && !tester.get(world.tile(x1, y - 1))){
spanAbove = false;
}
if(!spanBelow && y < height - 1 && tester.get(world.tile(x1, y + 1))){
stack.add(Point2.pack(x1, y + 1));
spanBelow = true;
}else if(spanBelow && y < height - 1 && !tester.get(world.tile(x1, y + 1))){
spanBelow = false;
}
x1++;
}
}
stack.clear();
}catch(OutOfMemoryError e){
//hack
stack = null;
System.gc();
e.printStackTrace();
stack = new IntSeq();
}
}
}
},
spray(KeyCode.r, "replace"){
final double chance = 0.012;
{
edit = true;
draggable = true;
}
@Override
public void touched(int x, int y){
//floor spray
if(drawBlock.isFloor()){
editorTable.drawCircle(x, y, tile -> {
if(Mathf.chance(chance)){
tile.setFloor(drawBlock.asFloor());
}
});
}else if(mode == 0){ //replace-only mode, doesn't affect air
editorTable.drawBlocks(x, y, tile -> Mathf.chance(chance) && tile.block() != Blocks.air);
}else{
editorTable.drawBlocks(x, y, tile -> Mathf.chance(chance));
}
}
};
public static final EditorTool[] all = values();
/** All the internal alternate placement modes of this tool. */
public final String[] altModes;
/** Key to activate this tool. */
public KeyCode key = KeyCode.unset;
/** The current alternate placement mode. -1 is the standard mode, no changes.*/
public int mode = -1;
/** Whether this tool causes canvas changes when touched.*/
public boolean edit;
/** Whether this tool should be dragged across the canvas when the mouse moves.*/
public boolean draggable;
EditorTool(){
this(new String[]{});
}
EditorTool(KeyCode code){
this(new String[]{});
this.key = code;
}
EditorTool(String... altModes){
this.altModes = altModes;
}
EditorTool(KeyCode code, String... altModes){
this.altModes = altModes;
this.key = code;
}
public void touched(int x, int y){}
public void touchedLine(int x1, int y1, int x2, int y2){}
}

View File

@@ -0,0 +1,58 @@
package informatis.core;
import arc.input.KeyCode;
import informatis.ui.*;
import informatis.ui.draws.OverDraws;
import informatis.ui.window.*;
import arc.*;
import mindustry.*;
import mindustry.game.EventType.*;
import mindustry.mod.*;
import static informatis.SVars.*;
import static arc.Core.*;
import static informatis.SUtils.*;
import static informatis.ui.WindowManager.windows;
public class Main extends Mod {
@Override
public void init(){
Core.app.post(() -> {
Mods.ModMeta meta = Vars.mods.locateMod("informatis").meta;
meta.displayName = "[#B5FFD9]Informatis[]";
meta.author = "[#B5FFD9]Sharlotte[lightgray]#0018[][]";
meta.description = bundle.get("shar-description");
});
Events.run(Trigger.update, () -> {
try {
BarInfo.getInfo(getTarget());
} catch (IllegalAccessException | NoSuchFieldException err) {
err.printStackTrace();
}
target = getTarget();
for (Window window : windows) {
if(window instanceof Updatable u) u.update();
}
if((input.keyDown(KeyCode.shiftRight) || input.keyDown(KeyCode.shiftLeft))) {
if(input.keyTap(KeyCode.r)) {
if(target==getTarget()) locked = !locked;
target = getTarget();
}
}
});
Events.on(ClientLoadEvent.class, e -> {
Windows.load();
SettingS.init();
WindowManager.init();
DisplayManager.init();
OverDraws.init();
OverDrawer.init();
});
}
}

View File

@@ -0,0 +1,70 @@
package informatis.core;
import informatis.ui.draws.*;
import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.ui.*;
import static informatis.SVars.*;
import static arc.Core.*;
import static mindustry.Vars.*;
public class OverDrawer {
public static void init(){
Events.run(EventType.Trigger.draw, () -> {
float sin = Mathf.absin(Time.time, 6f, 1f);
Draw.z(Layer.max);
if(settings.getBool("spawnerarrow")) {
float leng = (player.unit() != null && player.unit().hitSize > 4 * 8f ? player.unit().hitSize * 1.5f : 4 * 8f) + sin;
Tmp.v1.set(camera.position);
Lines.stroke(1f + sin / 2, Pal.accent);
Lines.circle(Tmp.v1.x, Tmp.v1.y, leng - 4f);
spawner.getSpawns().each(t -> Drawf.arrow(Tmp.v1.x, Tmp.v1.y, t.worldx(), t.worldy(), leng, (Math.min(200 * 8f, Mathf.dst(Tmp.v1.x, Tmp.v1.y, t.worldx(), t.worldy())) / (200 * 8f)) * (5f + sin)));
}
if(settings.getBool("select")) {
Draw.color(Tmp.c1.set(locked ? Color.orange : Color.darkGray).lerp(locked ? Color.scarlet : Color.gray, Mathf.absin(Time.time, 3f, 1f)).a(settings.getInt("selectopacity") / 100f));
float length = (target instanceof Unit u ? u.hitSize : target instanceof Building b ? b.block.size * tilesize : 0) * 1.5f + 2.5f;
for(int i = 0; i < 4; i++){
float rot = i * 90f + 45f + (-Time.time) % 360f;
Draw.rect("select-arrow", target.x() + Angles.trnsx(rot, length), target.y() + Angles.trnsy(rot, length), length / 1.9f, length / 1.9f, rot - 135f);
}
}
if(settings.getBool("distanceLine")) {
Posc from = player;
Position to = target;
if(to == from || to == null) to = input.mouseWorld();
if(player.unit() instanceof BlockUnitUnit bu) Tmp.v1.set(bu.x() + bu.tile().block.offset, bu.y() + bu.tile().block.offset).sub(to.getX(), to.getY()).limit(bu.tile().block.size * tilesize + sin + 0.5f);
else Tmp.v1.set(from.x(), from.y()).sub(to.getX(), to.getY()).limit((player.unit()==null?0:player.unit().hitSize) + sin + 0.5f);
float x2 = from.x() - Tmp.v1.x, y2 = from.y() - Tmp.v1.y, x1 = to.getX() + Tmp.v1.x, y1 = to.getY() + Tmp.v1.y;
int segs = (int) (to.dst(from.x(), from.y()) / tilesize);
if(segs > 0){
Lines.stroke(2.5f, Pal.gray);
Lines.dashLine(x1, y1, x2, y2, segs);
Lines.stroke(1f, Pal.placing);
Lines.dashLine(x1, y1, x2, y2, segs);
Fonts.outline.draw(Strings.fixed(to.dst(from.x(), from.y()), 2) + " (" + segs + " " + bundle.get("tiles") + ")",
from.x() + Angles.trnsx(Angles.angle(from.x(), from.y(), to.getX(), to.getY()), player.unit().hitSize() + Math.min(segs, 6) * 8f),
from.y() + Angles.trnsy(Angles.angle(from.x(), from.y(), to.getX(), to.getY()), player.unit().hitSize() + Math.min(segs, 6) * 8f) - 3,
Pal.accent, 0.25f, false, Align.center);
}
}
//global drawing, which needs camera-clipping
Core.camera.bounds(Tmp.r1);
for(OverDraw drawer : OverDraws.all) drawer.draw();
});
}
}

View File

@@ -0,0 +1,154 @@
package informatis.core;
import arc.*;
import arc.func.*;
import arc.graphics.*;
import arc.scene.Group;
import arc.scene.event.*;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.scene.ui.layout.Stack;
import arc.struct.*;
import arc.util.*;
import mindustry.ui.*;
import mindustry.ui.dialogs.*;
import static arc.Core.*;
import static mindustry.Vars.*;
public class SettingS {
public static SettingsMenuDialog.SettingsTable sharset;
public static void addGraphicCheckSetting(String key, boolean def, Seq<SharSetting> list){
list.add(new SharSetting(key, def) {
@Override
public void add(Table table) {
CheckBox box = new CheckBox(title);
box.update(() -> box.setChecked(settings.getBool(name)));
box.changed(() -> settings.put(name, box.isChecked()));
box.left();
addDesc(table.add(box).left().padTop(3f).get());
table.row();
}
});
}
public static void addGraphicSlideSetting(String key, int def, int min, int max, int step, SettingsMenuDialog.StringProcessor sp, Seq<SharSetting> list){
list.add(new SharSetting(key, def) {
@Override
public void add(Table table){
Label value = new Label("", Styles.outlineLabel);
Table content = new Table();
content.add(title, Styles.outlineLabel).left().growX().wrap();
content.add(value).padLeft(10f).right();
content.margin(3f, 33f, 3f, 33f);
content.touchable = Touchable.disabled;
Slider slider = new Slider(min, max, step, false);
slider.setValue(settings.getInt(name));
slider.changed(() -> {
settings.put(name, (int)slider.getValue());
value.setText(sp.get((int)slider.getValue()));
});
slider.change();
addDesc(table.stack(slider, content).width(Math.min(Core.graphics.getWidth() / 1.2f, 460f)).left().padTop(4f).get());
table.row();
}
});
}
public static void addGraphicTypeSetting(String key, float min, float max, int def, boolean integer, Boolp condition, Func<String, String> h, Seq<SharSetting> list){
list.add(new SharSetting(key, def) {
@Override
public void add(Table table) {
final String[] str = {""};
Table table1 = new Table(t -> {
final float[] value = {def};
t.add(new Label(title + ": ")).left().padRight(5)
.update(a -> a.setColor(condition.get() ? Color.white : Color.gray));
t.field((integer ? String.valueOf(value[0]).split("[.]")[0] : value[0]) + str[0], s -> {
str[0] = h.get(s);
value[0] = s.isEmpty() ? def : Strings.parseFloat(s);
if(integer) settings.put(key, (int)value[0]);
else settings.put(key, value[0]);
}).update(a -> a.setDisabled(!condition.get()))
.valid(f -> Strings.canParsePositiveFloat(f) && Strings.parseFloat(f) >= min && Strings.parseFloat(f) <= max).width(120f).left();
});
addDesc(table.add(table1).left().padTop(4f).get());
table.row();
}
});
}
public static void init(){
BaseDialog dialog = new BaseDialog(bundle.get("setting.shar-title"));
dialog.addCloseButton();
sharset = new SettingsMenuDialog.SettingsTable();
dialog.cont.center().add(new Table(t -> t.pane(sharset).grow().row()));
ui.settings.shown(() -> {
Table settingUi = (Table)((Group)((Group)(ui.settings.getChildren().get(1))).getChildren().get(0)).getChildren().get(0); //This looks so stupid lol
settingUi.row();
settingUi.button(bundle.get("setting.shar-title"), Styles.cleart, dialog::show);
});
Seq<Seq<SharSetting>> settingSeq = new Seq<>();
Seq<SharSetting> tapSeq = new Seq<>();
addGraphicSlideSetting("barstyle", 0, 0, 5, 1, s -> s == 0 ? bundle.get("default-bar") : s + bundle.get("th-bar"), tapSeq);
addGraphicCheckSetting("schem", !mobile, tapSeq);
//TODO: remove all drawing settings
Seq<SharSetting> drawSeq = new Seq<>();
addGraphicSlideSetting("selectopacity", 50, 0, 100, 5, s -> s + "%", drawSeq);
addGraphicSlideSetting("baropacity", 50, 0, 100, 5, s -> s + "%", drawSeq);
addGraphicCheckSetting("aliceRange", false, drawSeq);
addGraphicCheckSetting("RangeShader", false, drawSeq);
addGraphicCheckSetting("select", false, drawSeq);
addGraphicCheckSetting("distanceLine", false, drawSeq);
addGraphicCheckSetting("spawnerarrow", false, drawSeq);
addGraphicCheckSetting("elementdebug", false, drawSeq);
addGraphicCheckSetting("hiddenElem", false, drawSeq);
settingSeq.add(tapSeq, drawSeq);
sharset.table(t -> {
Seq<TextButton> buttons = new Seq<>();
buttons.add(new TextButton(bundle.get("setting.shar-ui"), Styles.cleart));
buttons.add(new TextButton(bundle.get("setting.shar-draw"), Styles.cleart));
buttons.each(b -> b.clicked(() -> buttons.each(b1 -> b1.setChecked(b1 == b))));
t.table(Styles.black8, bt -> {
bt.top().align(Align.top);
buttons.each(b -> {
b.getLabel().setFontScale(0.85f);
bt.add(b).minHeight(60f * 0.85f).minWidth(150f * 0.85f).top();
});
}).grow().row();
Stack stack = new Stack();
for(int i = 0; i < settingSeq.size; i++){
int finalI = i;
stack.add(new Table(st -> {
for(SharSetting setting : settingSeq.get(finalI))
st.table(setting::add).left().row();
st.button(Core.bundle.get("settings.reset", "Reset to Defaults"), () -> {
settingSeq.get(finalI).each(s -> Core.settings.put(s.name, Core.settings.getDefault(s.name)));
}).margin(14.0f).width(240.0f).pad(6.0f);
st.visibility = () -> buttons.get(finalI).isChecked();
st.pack();
}));
}
t.add(stack);
t.fillParent = true;
});
}
}

View File

@@ -0,0 +1,26 @@
package informatis.core;
import arc.Core;
import arc.scene.ui.layout.Table;
import mindustry.ui.dialogs.SettingsMenuDialog;
public abstract class SharSetting extends SettingsMenuDialog.SettingsTable.Setting {
public SharSetting(String name) {
super(name);
}
public SharSetting(String name, Object def) {
this(name);
Core.settings.defaults(name, def);
}
public void add(Table table) {
}
@Override
public void add(SettingsMenuDialog.SettingsTable table) {
}
}