Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v7' into v7
Browse files Browse the repository at this point in the history
  • Loading branch information
buthed010203 committed Jan 30, 2024
2 parents cc451a3 + 40dc9e4 commit 39de94a
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 36 deletions.
6 changes: 4 additions & 2 deletions core/assets/features
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* Player List Assist - None (Regular), Shift (Free Move), Ctrl (Follow Cursor), Alt (BuildPath)
* Click Assist - Shift (Regular), Shift + Alt (Free Move), Ctrl (Follow Cursor), Ctrl + Alt (BuildPath)
* Shift {schematic_menu} - Schematic browser
* {force_place_modifier} {select} - Force places selection/schematics by marking overlapping buildings for deconstruction and placing overlapped plans into frozen queue.

# Commands
* If you're unfamiliar with mindustry command syntax, <name> indicates a required argument, and [name] an optional one
Expand Down Expand Up @@ -120,8 +121,9 @@
* Most settings are self-explanatory so they are not included here

# Vanilla Modifications
* Shift click up/down in schematic tag list to send to top/bottom respectively
* Shift click delete in schematic tag list to delete tag without prompt
* Shift click up/down in schematic tag list to send to top/bottom respectively
* Shift click delete in schematic tag list to delete tag without prompt
* Alt {pickupCargo} pick up buildings but not units

# Credits
* Game by anuke, client by foo, buthed010203, Zxtej, SBytes, and BalaM314
14 changes: 13 additions & 1 deletion core/src/mindustry/client/ui/SchematicBrowserDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public void showExport(Schematic s){
t.button("@schematic.copy", Icon.copy, style, () -> {
dialog.hide();
ui.showInfoFade("@copied");
Core.app.setClipboardText(schematics.writeBase64(s));
Core.app.setClipboardText(schematics.writeBase64(s, Core.settings.getBool("schematicmenuexporttags")));
}).marginLeft(12f);
t.row();
t.button("@schematic.exportfile", Icon.export, style, () -> {
Expand Down Expand Up @@ -354,6 +354,17 @@ void tagsChanged(){
Core.settings.putJson("schematic-tags", String.class, tags);
}

public void pruneTags() {
selectedTags.clear();
tags.removeAll(t -> { // Remove tags not attached to any schematics
for (var ss: loadedRepositories.values()) {
if (ss.find(s -> s.labels.contains(t)) != null) return false;
}
return true;
});
tagsChanged();
}

void showAllTags(){
var dialog = new BaseDialog("@schematic.edittags");
dialog.addCloseButton();
Expand All @@ -365,6 +376,7 @@ void showAllTags(){
p.table(t -> {
t.left().defaults().fillX().height(tagh).pad(2);
t.button("@client.schematic.cleartags", Icon.refresh, selectedTags::clear).wrapLabel(false).get().getLabelCell().padLeft(5);
t.button("@client.schematic.prunetags", Icon.trash, this::pruneTags).wrapLabel(false).get().getLabelCell().padLeft(5);
});
p.row();

Expand Down
3 changes: 2 additions & 1 deletion core/src/mindustry/content/Blocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -1803,7 +1803,8 @@ public static void load(){
}};

radar = new Radar("radar"){{
requirements(Category.effect, BuildVisibility.fogOnly, with(Items.silicon, 60, Items.graphite, 50, Items.beryllium, 10));
// requirements(Category.effect, BuildVisibility.fogOnly, with(Items.silicon, 60, Items.graphite, 50, Items.beryllium, 10));
requirements(Category.effect, with(Items.silicon, 60, Items.graphite, 50, Items.beryllium, 10));
outlineColor = Color.valueOf("4a4b53");
fogRadius = 34;
researchCost = with(Items.silicon, 70, Items.graphite, 70);
Expand Down
23 changes: 16 additions & 7 deletions core/src/mindustry/game/Schematics.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public Seq<Schematic> all(){
public void saveChanges(Schematic s){
if(s.file != null){
try{
write(s, s.file);
write(s, s.file, true);
}catch(Exception e){
ui.showException(e);
}
Expand Down Expand Up @@ -205,9 +205,10 @@ public boolean hasPreview(Schematic schematic){
public FrameBuffer getBuffer(Schematic schematic){
//dispose unneeded previews to prevent memory outage errors.
//only runs every 2 seconds
if(mobile && Time.timeSinceMillis(lastClearTime) > 1000 * 2 && previews.size > maxPreviewsMobile){
int max = Core.settings.getInt("maxschematicpreviews", mobile ? maxPreviewsMobile : 0);
if(max > 0 && Time.timeSinceMillis(lastClearTime) > 1000 * 2 && previews.size > max){
Seq<Schematic> keys = previews.orderedKeys().copy();
for(int i = 0; i < previews.size - maxPreviewsMobile; i++){
for(int i = 0; i < previews.size - max; i++){
//dispose and remove unneeded previews
previews.get(keys.get(i)).dispose();
previews.remove(keys.get(i));
Expand Down Expand Up @@ -613,11 +614,19 @@ public static Schematic read(InputStream input) throws IOException{
}
}

public static void write(Schematic schematic, Fi file) throws IOException{
write(schematic, file.write(false, 1024));
public static void write(Schematic schematic, Fi file) throws IOException {
write(schematic, file.write(false, 1024), false);
}

public static void write(Schematic schematic, OutputStream output) throws IOException{
public static void write(Schematic schematic, Fi file, boolean tags) throws IOException{
write(schematic, file.write(false, 1024), tags);
}

public static void write(Schematic schematic, OutputStream output) throws IOException {
write(schematic, output, false);
}

public static void write(Schematic schematic, OutputStream output, boolean tags) throws IOException{
output.write(header);
output.write(version);

Expand All @@ -626,7 +635,7 @@ public static void write(Schematic schematic, OutputStream output) throws IOExce
stream.writeShort(schematic.width);
stream.writeShort(schematic.height);

if (Core.settings.getBool("schematicmenuexporttags")) {
if (tags || Core.settings.getBool("schematicmenuexporttags")) {
schematic.tags.put("labels", JsonIO.write(schematic.labels.toArray(String.class)));
}

Expand Down
43 changes: 24 additions & 19 deletions core/src/mindustry/input/InputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import arc.scene.*;
import arc.scene.event.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.struct.Queue;
import arc.struct.*;
import arc.util.*;
import kotlin.Pair;
import mindustry.*;
Expand Down Expand Up @@ -1432,27 +1432,32 @@ public void flushPlans(Seq<BuildPlan> plans, boolean freeze, boolean force, bool
if(configLogic && copy.block instanceof LogicBlock && copy.config != null) { // Store the configs for logic blocks locally, they cause issues when sent to the server
copy.configLocal = net.client();
}
if (force && !valid) {
var existing = world.tiles.get(plan.x, plan.y);
var existingBuild = existing.build;
if (existingBuild != null && existing.block() == plan.block && existingBuild.tileX() == plan.x && existingBuild.tileY() == plan.y) {
var existingConfig = existingBuild.config();
boolean configEqual = (plan.config instanceof Array[] pa && existingConfig instanceof Array[] ea && Arrays.deepEquals(pa, ea)) || plan.config == existingConfig;
if (!configEqual) configs.add(new ConfigRequest(existing.build, plan.config));
}
else { // Add build plans to remove block underneath
frozenPlans.add(copy);
plan.tile().getLinkedTilesAs(plan.block, tile -> {
if (tile.build == null) return;
var bt = tile.build.tile;
if (toBreak.add(bt.pos())) player.unit().addBuild(new BuildPlan(bt.x, bt.y));
});
}
}
else {
var existing = world.tiles.get(plan.x, plan.y);
var existingBuild = existing.build;
var aligned = existingBuild != null && existingBuild.tileX() == plan.x && existingBuild.tileY() == plan.y;
var constructing = existingBuild instanceof ConstructBuild cb && cb.current == copy.block;
var built = existing.block() == plan.block;

// Freeze can ignore all validity checks
if (freeze || !(force && !valid) || (aligned && constructing)) { // If block can be placed or is already constructing
plan.block.onNewPlan(copy);
temp[added++] = copy;
}

if (!freeze && aligned && !constructing && built) { // If block already exists and is not being constructed
var existingConfig = existingBuild.config();
boolean configEqual = (plan.config instanceof Array[] pa && existingConfig instanceof Array[] ea && Arrays.deepEquals(pa, ea)) || Objects.equals(plan.config, existingConfig);
if (!configEqual) configs.add(new ConfigRequest(existing.build, plan.config));
continue; // Already built, no need to check to remove incorrect blocks
}

if (valid || !force || freeze || aligned && (built || constructing)) continue; // Whether to remove incorrect blocks underneath
frozenPlans.add(copy);
plan.tile().getLinkedTilesAs(plan.block, tile -> {
if (tile.build == null) return;
var bt = tile.build.tile;
if (toBreak.add(bt.pos())) player.unit().addBuild(new BuildPlan(bt.x, bt.y));
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion core/src/mindustry/ui/dialogs/SchematicsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public void showExport(Schematic s){
t.button("@schematic.copy", Icon.copy, style, () -> {
dialog.hide();
ui.showInfoFade("@copied");
Core.app.setClipboardText(schematics.writeBase64(s, false));
Core.app.setClipboardText(schematics.writeBase64(s, Core.settings.getBool("schematicmenuexporttags")));
}).marginLeft(12f);
t.row();
t.button("@schematic.exportfile", Icon.export, style, () -> {
Expand Down Expand Up @@ -633,7 +633,9 @@ void showAllTags(){
}

public void pruneTags() {
selectedTags.clear();
tags.removeAll(t -> schematics.all().find(s -> s.labels.contains(t)) == null);
tagsChanged();
}

void deleteTag(String tag) {
Expand Down
11 changes: 7 additions & 4 deletions core/src/mindustry/ui/fragments/ChatFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,17 +424,20 @@ public static CommandHandler.CommandResponse handleClientCommand(String message)
return handleClientCommand(message, true);
}

/** If send is false, only commands will be sent to the server */
public static CommandHandler.CommandResponse handleClientCommand(String message, boolean send){
//check if it's a command
CommandHandler.CommandResponse response = ClientVars.clientCommandHandler.handleMessage(message, player);
if(response.type == CommandHandler.ResponseType.noCommand){ //no command to handle
String msg = Main.INSTANCE.sign(message);
Events.fire(new ClientChatEvent(message));
if (send) Call.sendChatMessage(msg);
if (message.startsWith(netServer.clientCommands.getPrefix() + "sync")) { // /sync
ClientVars.syncing = true;
var prefix = netServer.clientCommands.getPrefix();
if(send || message.startsWith(prefix)){
Call.sendChatMessage(msg);
}
if (!message.startsWith(netServer.clientCommands.getPrefix())) { // Only fire when not running any command
if(message.startsWith(prefix + "sync")){ // /sync
ClientVars.syncing = true;
}else if (!message.startsWith(prefix)){ // Only fire when not running any command
Events.fire(new EventType.SendChatMessageEvent(msg));
}
}else{
Expand Down
2 changes: 1 addition & 1 deletion core/src/mindustry/world/blocks/logic/LogicBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ public void drawSelect(){
Groups.unit.each(u -> u.controller() instanceof LogicAI ai && ai.controller == this && !ClientVars.hidingUnits && !(ClientVars.hidingAirUnits && u.isFlying()), unit -> {
Drawf.square(unit.x, unit.y, unit.hitSize, unit.rotation + 45);
if (Core.settings.getBool("tracelogicunits")) {
Draw.draw((float) (Layer.overlayUI+0.01), () -> { // Taken from extended-UI
Draw.draw(Layer.overlayUI + 0.01f, () -> { // Taken from extended-UI
Lines.stroke(2, Color.purple);
Draw.alpha(0.7f);
Lines.line(unit.x, unit.y, this.x, this.y);
Expand Down
9 changes: 9 additions & 0 deletions core/src/mindustry/world/blocks/storage/Unloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ public void buildConfiguration(Table table){
ItemSelection.buildTable(Unloader.this, table, content.items(), () -> sortItem, this::configure, selectionRows, selectionColumns);
}

@Override
public void pickedUp() {
super.pickedUp();

lastDumpFrom = null;
lastDumpTo = null;
lastItem = null;
}

@Override
public Item config(){
return sortItem;
Expand Down

0 comments on commit 39de94a

Please sign in to comment.