Skip to content

Commit

Permalink
Copy/paste button in processor button bar
Browse files Browse the repository at this point in the history
  • Loading branch information
BalaM314 committed Dec 21, 2024
1 parent 26708df commit 83ee4f4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ client.sortedplans = Successfully sorted build queue by distance
client.freeze = Freeze
client.confirmfreeze = Are you sure you want to freeze/thaw {0}[white]? Their current freeze state is: {1}
client.rollback.title = Do you want to rollback this player's actions?
client.processorimported = Imported from clipboard
client.banreason.title = Ban Reason
client.banreason.body = Enter a reason for this ban
client.setupcomms = Use for comms
Expand Down
45 changes: 43 additions & 2 deletions core/src/mindustry/world/blocks/logic/LogicBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import arc.graphics.g2d.Lines;
import arc.math.*;
import arc.math.geom.*;
import arc.scene.ui.TextButton.*;
import arc.scene.ui.layout.*;
import arc.struct.Bits;
import arc.struct.*;
Expand All @@ -18,6 +19,7 @@
import mindustry.client.*;
import mindustry.client.antigrief.*;
import mindustry.client.navigation.*;
import mindustry.client.ui.*;
import mindustry.client.utils.*;
import mindustry.core.*;
import mindustry.gen.*;
Expand All @@ -28,6 +30,7 @@
import mindustry.logic.LAssembler.*;
import mindustry.logic.LExecutor.*;
import mindustry.ui.*;
import mindustry.ui.dialogs.*;
import mindustry.ui.fragments.*;
import mindustry.world.*;
import mindustry.world.blocks.ConstructBlock.*;
Expand Down Expand Up @@ -667,6 +670,15 @@ this, compress("print \"code was removed\"\n", relativeConnections())
public void removeLinks(){
ClientVars.configs.add(new ConfigRequest(this, compress(code, Seq.with())));
}
public void importFromClipboard(){
try{
ClientVars.configs.add(new ConfigRequest(
this, compress(Core.app.getClipboardText().replace("\r\n", "\n"), relativeConnections())
));
}catch(Throwable e){
ui.showException(e);
}
}

@Override
public void buildConfiguration(Table table){
Expand All @@ -686,12 +698,41 @@ public void buildConfiguration(Table table){
table.button(Icon.trash, Styles.cleari, () -> {
if(Core.input.shift()) removeCode();
else ui.showConfirm("@confirm", "Are you sure you want to delete this processor's code?", this::removeCode);
}).size(40).tooltip("Remove code").disabled(b -> !ClientVars.configs.isEmpty());
}).size(40).tooltip("Remove code").disabled(b -> !accessible() || !ClientVars.configs.isEmpty());

table.button(Icon.eyeOff, Styles.cleari, () -> {
if(Core.input.shift()) removeLinks();
else ui.showConfirm("@confirm", "Are you sure you want to remove all links?", this::removeLinks);
}).size(40).tooltip("Remove all links").disabled(b -> !ClientVars.configs.isEmpty());
}).size(40).tooltip("Remove all links").disabled(b -> !accessible() || !ClientVars.configs.isEmpty());

table.button(Icon.tree, Styles.cleari, () -> {
if(Core.input.shift()){
importFromClipboard();
new Toast(2).add("@client.processorimported");
return;
}
BaseDialog dialog = new BaseDialog("@editor.export");
dialog.cont.pane(p -> {
p.margin(10f);
p.table(Tex.button, t -> {
TextButtonStyle style = Styles.flatt;
t.defaults().size(280f, 60f).left();

t.button("@schematic.copy", Icon.copy, style, () -> {
dialog.hide();
Core.app.setClipboardText(code);
}).marginLeft(12f);
t.row();
t.button("@schematic.copy.import", Icon.download, style, () -> {
dialog.hide();
importFromClipboard();
}).marginLeft(12f);
});
});

dialog.addCloseButton();
dialog.show();
}).size(40).tooltip("Copy/paste Code").disabled(b -> !accessible());
}

@Override
Expand Down

0 comments on commit 83ee4f4

Please sign in to comment.