Merge branch 'master' of https://github.com/Anuken/Mindustry into 7.0-features

This commit is contained in:
Anuken
2021-08-28 16:30:07 -04:00
33 changed files with 165 additions and 32 deletions

View File

@@ -83,7 +83,7 @@ public abstract class ClientLauncher extends ApplicationCore implements Platform
Fonts.loadDefaultFont();
//load fallback atlas if max texture size is below 4096
assets.load(new AssetDescriptor<>(maxTextureSize >= 4096 ? "sprites/sprites.aatls" : "sprites/fallback/sprites.aatls", TextureAtlas.class)).loaded = t -> atlas = (TextureAtlas)t;
assets.load(new AssetDescriptor<>(maxTextureSize >= 4096 ? "sprites/sprites.aatls" : "sprites/fallback/sprites.aatls", TextureAtlas.class)).loaded = t -> atlas = t;
assets.loadRun("maps", Map.class, () -> maps.loadPreviews());
Musics.load();

View File

@@ -197,6 +197,7 @@ public class WaveSpawner{
unit.add();
unit.unloaded();
Events.fire(new UnitSpawnEvent(unit));
Call.spawnEffect(unit.x, unit.y, unit.rotation, unit.type);
}

View File

@@ -27,6 +27,8 @@ public abstract class UnlockableContent extends MappableContent{
public boolean alwaysUnlocked = false;
/** Whether to show the description in the research dialog preview. */
public boolean inlineDescription = true;
/** Whether details of blocks are hidden in custom games if they haven't been unlocked in campaign mode. */
public boolean hideDetails = true;
/** Special logic icon ID. */
public int iconId = 0;
/** Icon of the content to use in UI. */

View File

@@ -1,9 +1,11 @@
package mindustry.editor;
import arc.*;
import arc.func.*;
import arc.graphics.*;
import arc.math.*;
import arc.scene.event.*;
import arc.scene.style.*;
import arc.scene.ui.*;
import arc.scene.ui.TextField.*;
import arc.scene.ui.layout.*;
@@ -29,6 +31,8 @@ public class WaveInfoDialog extends BaseDialog{
private Table table;
private int start = 0;
private UnitType lastType = UnitTypes.dagger;
private Sort sort = Sort.begin;
private boolean reverseSort = false;
private float updateTimer, updatePeriod = 1f;
private WaveGraph graph = new WaveGraph();
@@ -41,6 +45,27 @@ public class WaveInfoDialog extends BaseDialog{
addCloseListener();
onResize(this::setup);
buttons.button(Icon.filter, () -> {
BaseDialog dialog = new BaseDialog("@waves.sort");
dialog.setFillParent(false);
dialog.cont.table(Tex.button, t -> {
for(Sort s : Sort.all){
t.button("@waves.sort." + s, Styles.clearTogglet, () -> {
sort = s;
dialog.hide();
buildGroups();
}).size(150f, 60f).checked(s == sort);
}
}).row();
dialog.cont.check("@waves.sort.reverse", b -> {
reverseSort = b;
buildGroups();
}).padTop(4).checked(reverseSort).padBottom(8f);
dialog.addCloseButton();
dialog.show();
buildGroups();
}).size(60f, 64f);
addCloseButton();
buttons.button("@waves.edit", () -> {
@@ -165,7 +190,8 @@ public class WaveInfoDialog extends BaseDialog{
table.margin(10f);
if(groups != null){
groups.sort(g -> g.begin);
groups.sort(sort.sort);
if(reverseSort) groups.reverse();
for(SpawnGroup group : groups){
table.table(Tex.button, t -> {
@@ -179,6 +205,11 @@ public class WaveInfoDialog extends BaseDialog{
b.label(() -> (group.begin + 1) + "").color(Color.lightGray).minWidth(45f).labelAlign(Align.left).left();
b.button(group.effect != null && group.effect != StatusEffects.none ?
new TextureRegionDrawable(group.effect.uiIcon) :
Icon.logicSmall,
Styles.emptyi, () -> showEffect(group)).pad(-6).size(46f);
b.button(Icon.unitsSmall, Styles.emptyi, () -> showUpdate(group)).pad(-6).size(46f);
b.button(Icon.cancel, Styles.emptyi, () -> {
groups.remove(group);
@@ -269,7 +300,10 @@ public class WaveInfoDialog extends BaseDialog{
a.add("@waves.shields").padLeft(4);
}).row();
t.check("@waves.guardian", b -> group.effect = (b ? StatusEffects.boss : null)).padTop(4).update(b -> b.setChecked(group.effect == StatusEffects.boss)).padBottom(8f);
t.check("@waves.guardian", b -> {
group.effect = (b ? StatusEffects.boss : null);
buildGroups();
}).padTop(4).update(b -> b.setChecked(group.effect == StatusEffects.boss)).padBottom(8f);
}
}).width(340f).pad(8);
@@ -306,6 +340,53 @@ public class WaveInfoDialog extends BaseDialog{
dialog.show();
}
void showEffect(SpawnGroup group){
BaseDialog dialog = new BaseDialog("");
dialog.setFillParent(true);
dialog.cont.pane(p -> {
int i = 0;
for(StatusEffect effect : content.statusEffects()){
if(effect != StatusEffects.none && (effect.isHidden() || effect.reactive)) continue;
p.button(t -> {
t.left();
if(effect.uiIcon != null && effect != StatusEffects.none){
t.image(effect.uiIcon).size(8 * 4).scaling(Scaling.fit).padRight(2f);
}else{
t.image(Icon.none).size(8 * 4).scaling(Scaling.fit).padRight(2f);
}
if(effect != StatusEffects.none){
t.add(effect.localizedName);
}else{
t.add("@settings.resetKey");
}
}, () -> {
group.effect = effect;
dialog.hide();
buildGroups();
}).pad(2).margin(12f).fillX();
if(++i % 3 == 0) p.row();
}
});
dialog.addCloseButton();
dialog.show();
}
enum Sort{
begin(g -> g.begin),
health(g -> g.type.health),
type(g -> g.type.id);
static final Sort[] all = values();
final Floatf<SpawnGroup> sort;
Sort(Floatf<SpawnGroup> sort){
this.sort = sort;
}
}
void updateWaves(){
graph.groups = groups;
graph.from = start;

View File

@@ -465,8 +465,8 @@ public class Damage{
for(int dx = -trad; dx <= trad; dx++){
for(int dy = -trad; dy <= trad; dy++){
Tile tile = world.tile(Math.round(x / tilesize) + dx, Math.round(y / tilesize) + dy);
if(tile != null && tile.build != null && (team == null ||team.isEnemy(tile.team())) && Mathf.dst(dx, dy) <= trad){
tile.build.damage(damage);
if(tile != null && tile.build != null && (team == null ||team.isEnemy(tile.team())) && dx*dx + dy*dy <= trad){
tile.build.damage(team, damage);
}
}
}

View File

@@ -7,6 +7,9 @@ import mindustry.entities.*;
import mindustry.gen.*;
public class RailBulletType extends BulletType{
//for calculating the furthest point
static float furthest = 0;
public Effect pierceEffect = Fx.hitBulletSmall, updateEffect = Fx.none;
/** Multiplier of damage decreased per health pierced. */
public float pierceDamageFactor = 1f;
@@ -47,6 +50,11 @@ public class RailBulletType extends BulletType{
//subtract health from each consecutive pierce
b.damage -= Math.min(b.damage, sub);
//bullet was stopped, decrease furthest distance
if(b.damage <= 0f){
furthest = Math.min(furthest, b.dst(pos));
}
}
@Override
@@ -54,8 +62,9 @@ public class RailBulletType extends BulletType{
super.init(b);
b.fdata = length;
furthest = length;
Damage.collideLine(b, b.team, b.type.hitEffect, b.x, b.y, b.rotation(), length, false, false);
float resultLen = b.fdata;
float resultLen = furthest;
Vec2 nor = Tmp.v1.trns(b.rotation(), 1f).nor();
for(float i = 0; i <= resultLen; i += updateEffectSeg){

View File

@@ -133,8 +133,9 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
int x = x0f, dx = Math.abs(x1 - x), sx = x < x1 ? 1 : -1;
int y = y0f, dy = Math.abs(y1 - y), sy = y < y1 ? 1 : -1;
int e2, err = dx - dy;
int ww = world.width(), wh = world.height();
while(true){
while(x >= 0 && y >= 0 && x < ww && y < wh){
Building build = world.build(x, y);
if(build != null && isAdded() && build.collide(self()) && type.testCollision(self(), build)
&& !build.dead() && (type.collidesTeam || build.team != team) && !(type.pierceBuilding && hasCollided(build.id))){

View File

@@ -428,6 +428,15 @@ public class EventType{
}
}
/** Called when a unit is spawned by wave. */
public static class UnitSpawnEvent{
public final Unit unit;
public UnitSpawnEvent(Unit unit) {
this.unit = unit;
}
}
/** Called when a unit is dumped from any payload block. */
public static class UnitUnloadEvent{
public final Unit unit;

View File

@@ -116,7 +116,7 @@ public class Waves{
spacing = 5;
unitAmount = 1;
unitScaling = 3;
effect = StatusEffects.shielded;
shields = 640f;
max = 25;
}},

View File

@@ -236,7 +236,6 @@ public class PlanetRenderer implements Disposable{
Tmp.c1.set(from).lerp(to, (f+ Time.globalTime /timeScale)%1f);
batch.color(Tmp.c1);
batch.vertex(Tmp.bz3.valueAt(Tmp.v32, f));
}
batch.flush(Gl.lineStrip);
}

View File

@@ -21,6 +21,16 @@ public class FileMapGenerator implements WorldGenerator{
this.preset = preset;
}
public FileMapGenerator(Map map, SectorPreset preset){
this.map = map;
this.preset = preset;
}
/** If you use this constructor, make sure to override generate()! */
public FileMapGenerator(SectorPreset preset){
this(emptyMap, preset);
}
@Override
public void generate(Tiles tiles){
if(map == null) throw new RuntimeException("Generator has null map, cannot be used.");

View File

@@ -225,6 +225,10 @@ public class Mods implements Loadable{
var shadow = Core.atlas;
//dummy texture atlas that returns the 'shadow' regions; used for mod loading
Core.atlas = new TextureAtlas(){
{
//needed for the correct operation of the found() method in the TextureRegion
error = shadow.find("error");
}
@Override
public AtlasRegion find(String name){

View File

@@ -162,7 +162,9 @@ public class ArcNetProvider implements NetProvider{
client.connect(5000, ip, port, port);
success.run();
}catch(Exception e){
net.handleException(e);
if(netClient.isConnecting()){
net.handleException(e);
}
}
});
}

View File

@@ -39,7 +39,7 @@ public class BeControl{
public BeControl(){
if(active()){
Timer.schedule(() -> {
if(Vars.clientLoaded && checkUpdates && !mobile){
if((Vars.clientLoaded || headless) && checkUpdates && !mobile){
checkUpdate(t -> {});
}
}, updateInterval, updateInterval);

View File

@@ -196,12 +196,12 @@ public class Fonts{
size = 18;
}};
Core.assets.load("outline", Font.class, new FreeTypeFontLoaderParameter(mainFont, param)).loaded = t -> Fonts.outline = (Font)t;
Core.assets.load("outline", Font.class, new FreeTypeFontLoaderParameter(mainFont, param)).loaded = t -> Fonts.outline = t;
Core.assets.load("tech", Font.class, new FreeTypeFontLoaderParameter("fonts/tech.ttf", new FreeTypeFontParameter(){{
size = 18;
}})).loaded = f -> {
Fonts.tech = (Font)f;
Fonts.tech = f;
Fonts.tech.getData().down *= 1.5f;
};
}

View File

@@ -81,7 +81,7 @@ public class ContentInfoDialog extends BaseDialog{
}
if(content.details != null){
table.add("[gray]" + (content.unlocked() ? content.details : Iconc.lock + " " + Core.bundle.get("unlock.incampaign"))).pad(6).padTop(20).width(400f).wrap().fillX();
table.add("[gray]" + (content.unlocked() || !content.hideDetails ? content.details : Iconc.lock + " " + Core.bundle.get("unlock.incampaign"))).pad(6).padTop(20).width(400f).wrap().fillX();
table.row();
}

View File

@@ -119,7 +119,7 @@ public class JoinDialog extends BaseDialog{
refreshLocal();
refreshRemote();
refreshGlobal();
refreshCommunity();
}
void setupRemote(){
@@ -331,7 +331,7 @@ public class JoinDialog extends BaseDialog{
if(eye){
name.button(Icon.eyeSmall, Styles.emptyi, () -> {
showHidden = !showHidden;
refreshGlobal();
refreshCommunity();
}).update(i -> i.getStyle().imageUp = (showHidden ? Icon.eyeSmall : Icon.eyeOffSmall))
.size(40f).right().padRight(3).tooltip("@servers.showhidden");
}
@@ -357,7 +357,7 @@ public class JoinDialog extends BaseDialog{
net.discoverServers(this::addLocalHost, this::finishLocalHosts);
}
void refreshGlobal(){
void refreshCommunity(){
int cur = refreshes;
global.clear();

View File

@@ -375,8 +375,6 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
}
if(selectAlpha > 0.001f){
for(Sector sec : planet.sectors){
if(sec.hasBase()){
for(Sector enemy : sec.near()){

View File

@@ -83,6 +83,7 @@ public class LoadingFragment extends Fragment{
}
public void show(String text){
button.visible = false;
nameLabel.setColor(Color.white);
bar.visible = false;
table.clearActions();

View File

@@ -850,6 +850,10 @@ public class Block extends UnlockableContent{
if(!outputsPower && consumes.hasPower() && consumes.getPower().buffered){
throw new IllegalArgumentException("Consumer using buffered power: " + name);
}
if(buildVisibility == BuildVisibility.sandboxOnly){
hideDetails = false;
}
}
@Override

View File

@@ -79,7 +79,7 @@ public class PayloadBlock extends Block{
@Override
public boolean canControlSelect(Player player){
return !player.unit().spawnedByCore && this.payload == null && acceptUnitPayload(player.unit()) && player.tileOn().build == this;
return !player.unit().spawnedByCore && this.payload == null && acceptUnitPayload(player.unit()) && player.tileOn() != null && player.tileOn().build == this;
}
@Override

View File

@@ -174,9 +174,9 @@ public class PowerGraph{
return Math.min(excess, capacity);
}
public void distributePower(float needed, float produced){
public void distributePower(float needed, float produced, boolean charged){
//distribute even if not needed. this is because some might be requiring power but not using it; it updates consumers
float coverage = Mathf.zero(needed) && Mathf.zero(produced) ? 0f : Mathf.zero(needed) ? 1f : Math.min(1, produced / needed);
float coverage = Mathf.zero(needed) && Mathf.zero(produced) && !charged ? 0f : Mathf.zero(needed) ? 1f : Math.min(1, produced / needed);
for(Building consumer : consumers){
Consumers consumes = consumer.block.consumes;
if(consumes.hasPower()){
@@ -233,6 +233,7 @@ public class PowerGraph{
energyDelta = 0f;
if(!(consumers.size == 0 && producers.size == 0 && batteries.size == 0)){
boolean charged = false;
if(!Mathf.equal(powerNeeded, powerProduced)){
if(powerNeeded > powerProduced){
@@ -240,11 +241,12 @@ public class PowerGraph{
powerProduced += powerBatteryUsed;
lastPowerProduced += powerBatteryUsed;
}else if(powerProduced > powerNeeded){
charged = true;
powerProduced -= chargeBatteries(powerProduced - powerNeeded);
}
}
distributePower(powerNeeded, powerProduced);
distributePower(powerNeeded, powerProduced, charged);
}
}

View File

@@ -195,7 +195,7 @@ public class Drill extends Block{
}
public boolean canMine(Tile tile){
if(tile == null) return false;
if(tile == null || tile.block().isStatic()) return false;
Item drops = tile.drop();
return drops != null && drops.hardness <= tier;
}

View File

@@ -39,12 +39,15 @@ public class UnitFactory extends UnitBlock{
rotate = true;
config(Integer.class, (UnitFactoryBuild tile, Integer i) -> {
if(tile.currentPlan == i) return;
tile.currentPlan = i < 0 || i >= plans.size ? -1 : i;
tile.progress = 0;
});
config(UnitType.class, (UnitFactoryBuild tile, UnitType val) -> {
tile.currentPlan = plans.indexOf(p -> p.unit == val);
int next = plans.indexOf(p -> p.unit == val);
if(tile.currentPlan == next) return;
tile.currentPlan = next;
tile.progress = 0;
});

View File

@@ -9,14 +9,15 @@ import mindustry.world.blocks.production.GenericCrafter.*;
public class DrawRotator extends DrawBlock{
public TextureRegion rotator, top;
public boolean drawSpinSprite = false;
public float spinSpeed = 2f;
@Override
public void draw(GenericCrafterBuild build){
Draw.rect(build.block.region, build.x, build.y);
if(drawSpinSprite){
Drawf.spinSprite(rotator, build.x, build.y, build.totalProgress * 2f);
Drawf.spinSprite(rotator, build.x, build.y, build.totalProgress * spinSpeed);
}else{
Draw.rect(rotator, build.x, build.y, build.totalProgress * 2f);
Draw.rect(rotator, build.x, build.y, build.totalProgress * spinSpeed);
}
if(top.found()) Draw.rect(top, build.x, build.y);
}